diff --git a/com/gaetan/staffpin/StaffPlugin.java b/com/gaetan/staffpin/StaffPlugin.java index f0667d9..757b95e 100644 --- a/com/gaetan/staffpin/StaffPlugin.java +++ b/com/gaetan/staffpin/StaffPlugin.java @@ -9,15 +9,15 @@ import com.gaetan.staffpin.runnable.MoveRunnable; import com.google.common.collect.Maps; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; import java.util.Map; +import java.util.UUID; public final class StaffPlugin extends GCore { /** * Map to stock the PayerData */ - private final Map players = Maps.newConcurrentMap(); + private final Map players = Maps.newConcurrentMap(); /** * Reference to the ConfigManager @@ -59,22 +59,22 @@ protected void registerListener() { } /** - * Getter to get the PlayerData of a specific player. + * Getter to get the PlayerData of a specific player with his UUID. * Note: The player must have the pin permission. * - * @param player player The choosen player - * @return The PlayerData of the choosen player + * @param uuid The choosen UUID + * @return The PlayerData of the choosen UUID */ - public PlayerData getPlayer(final Player player) { - return this.players.get(player); + public PlayerData getPlayer(final UUID uuid) { + return this.players.get(uuid); } /** * Getter to get the Map of all PlayerData. * - * @return The map containing all the players and PlayerData with the pin permission + * @return The map containing all the UUID and PlayerData with the pin permission */ - public Map getPlayers() { + public Map getPlayers() { return this.players; } } diff --git a/com/gaetan/staffpin/command/PinCommand.java b/com/gaetan/staffpin/command/PinCommand.java index cd9ec44..3c33948 100644 --- a/com/gaetan/staffpin/command/PinCommand.java +++ b/com/gaetan/staffpin/command/PinCommand.java @@ -56,7 +56,7 @@ public void handleCommand_Set(final Context context, final final Player player = (Player) context.getSender(); if (player.hasPermission(this.configManager.getPinPermission())) { - this.staffPlugin.getPlayer(player).setPin(pin); + this.staffPlugin.getPlayer(player.getUniqueId()).setPin(pin); Message.tell(player, this.configManager.getPinSet()); } } diff --git a/com/gaetan/staffpin/listener/PlayerListener.java b/com/gaetan/staffpin/listener/PlayerListener.java index ea28aef..eddbdad 100644 --- a/com/gaetan/staffpin/listener/PlayerListener.java +++ b/com/gaetan/staffpin/listener/PlayerListener.java @@ -14,6 +14,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import java.util.UUID; + public final class PlayerListener implements Listener { /** * Reference to the main class @@ -46,7 +48,7 @@ public void onJoin(final PlayerJoinEvent event) { if (player.hasPermission(this.configManager.getPinPermission())) { final PlayerData playerData = new PlayerData(player, this.staffPlugin, this.configManager); - this.staffPlugin.getPlayers().put(player, playerData); + this.staffPlugin.getPlayers().put(player.getUniqueId(), playerData); playerData.join(); } @@ -57,10 +59,10 @@ public void onJoin(final PlayerJoinEvent event) { */ @EventHandler public void onQuit(final PlayerQuitEvent event) { - final Player player = event.getPlayer(); + final UUID uuid = event.getPlayer().getUniqueId(); - if (player.hasPermission(this.configManager.getPinPermission()) && this.staffPlugin.getPlayers().containsKey(player)) - this.staffPlugin.getPlayers().remove(player).leave(); + if (event.getPlayer().hasPermission(this.configManager.getPinPermission()) && this.staffPlugin.getPlayers().containsKey(uuid)) + this.staffPlugin.getPlayers().remove(uuid).leave(); } /** @@ -70,11 +72,12 @@ public void onQuit(final PlayerQuitEvent event) { @EventHandler public void onChat(final AsyncPlayerChatEvent event) { final Player player = event.getPlayer(); + final UUID uuid = event.getPlayer().getUniqueId(); if (player.hasPermission(this.configManager.getPinPermission())) { - final PlayerData playerData = this.staffPlugin.getPlayer(player); + final PlayerData playerData = this.staffPlugin.getPlayer(uuid); - if (this.staffPlugin.getPlayers().containsKey(player) && !playerData.isLogin()) { + if (this.staffPlugin.getPlayers().containsKey(uuid) && !playerData.isLogin()) { event.setCancelled(true); if (event.getMessage().equals(playerData.getPin())) { @@ -93,9 +96,10 @@ public void onChat(final AsyncPlayerChatEvent event) { @EventHandler public void onCommand(final PlayerCommandPreprocessEvent event) { final Player player = event.getPlayer(); + final UUID uuid = event.getPlayer().getUniqueId(); if (player.hasPermission(this.configManager.getPinPermission())) { - if (this.staffPlugin.getPlayers().containsKey(player) && !this.staffPlugin.getPlayer(player).isLogin()) { + if (this.staffPlugin.getPlayers().containsKey(uuid) && !this.staffPlugin.getPlayer(uuid).isLogin()) { Message.tell(player, this.configManager.getEnterPin()); event.setCancelled(true); } diff --git a/com/gaetan/staffpin/runnable/LoadPlayerConfig.java b/com/gaetan/staffpin/runnable/LoadPlayerConfig.java index 3988b18..ab8e5dc 100644 --- a/com/gaetan/staffpin/runnable/LoadPlayerConfig.java +++ b/com/gaetan/staffpin/runnable/LoadPlayerConfig.java @@ -39,7 +39,7 @@ public LoadPlayerConfig(final StaffPlugin staffPlugin, final PlayerData playerDa } /** - * Loading the playerdata from a config + * Loading the pin from a config * Note: This must be executed in async */ @Override diff --git a/com/gaetan/staffpin/runnable/MoveRunnable.java b/com/gaetan/staffpin/runnable/MoveRunnable.java index 9c5167f..0c19e4a 100644 --- a/com/gaetan/staffpin/runnable/MoveRunnable.java +++ b/com/gaetan/staffpin/runnable/MoveRunnable.java @@ -1,6 +1,7 @@ package com.gaetan.staffpin.runnable; import com.gaetan.api.message.Message; +import com.gaetan.api.runnable.TaskUtil; import com.gaetan.staffpin.StaffPlugin; import com.gaetan.staffpin.config.ConfigManager; import com.gaetan.staffpin.data.PlayerData; @@ -27,20 +28,22 @@ public final class MoveRunnable extends BukkitRunnable { public MoveRunnable(final StaffPlugin staffPlugin, final ConfigManager configManager) { this.staffPlugin = staffPlugin; this.configManager = configManager; - this.runTaskTimer(this.staffPlugin, 0L, 40L); + this.runTaskTimerAsynchronously(this.staffPlugin, 0L, 40L); } /** * Teleport player to the waiting pin location - * Note: This will be executed every 2 seconds + * Note: This will be executed async every 2 seconds */ @Override public void run() { - this.staffPlugin.getPlayers().keySet().forEach(player -> { - final PlayerData playerData = this.staffPlugin.getPlayer(player); + this.staffPlugin.getPlayers().keySet().forEach(uuid -> { + final PlayerData playerData = this.staffPlugin.getPlayer(uuid); if (!playerData.isLogin() && playerData.getPin() != null) { - Message.tell(player, this.configManager.getEnterPin()); - player.teleport(playerData.getLocation()); + TaskUtil.run(() -> { + Message.tell(playerData.getPlayer(), this.configManager.getEnterPin()); + playerData.getPlayer().teleport(playerData.getLocation()); + }); } }); } diff --git a/com/gaetan/staffpin/runnable/SavePlayerConfig.java b/com/gaetan/staffpin/runnable/SavePlayerConfig.java index e1f7b86..08036d4 100644 --- a/com/gaetan/staffpin/runnable/SavePlayerConfig.java +++ b/com/gaetan/staffpin/runnable/SavePlayerConfig.java @@ -27,7 +27,7 @@ public SavePlayerConfig(final StaffPlugin staffPlugin, final PlayerData playerDa } /** - * Saving the playerdata to a config + * Saving the pin to a config * Note: This must be executed in async */ @Override diff --git a/plugin.yml b/plugin.yml index aef289f..bfba9bb 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,4 +1,4 @@ name: StaffPin author: Gaetan_Off -version: 0.4-SNAPSHOT +version: 0.5-SNAPSHOT main: com.gaetan.staffpin.StaffPlugin