diff --git a/src/main/java/com/graywolf336/jail/HandCuffManager.java b/src/main/java/com/graywolf336/jail/HandCuffManager.java index 50e206c..d235c02 100644 --- a/src/main/java/com/graywolf336/jail/HandCuffManager.java +++ b/src/main/java/com/graywolf336/jail/HandCuffManager.java @@ -1,6 +1,7 @@ package com.graywolf336.jail; import java.util.HashMap; +import java.util.UUID; import org.bukkit.Location; @@ -8,75 +9,75 @@ import org.bukkit.Location; * * @author graywolf336 * @since 2.6.3 - * @version 1.0.1 + * @version 1.0.2 */ public class HandCuffManager { - private HashMap handcuffed; - private HashMap locs; + private HashMap handcuffed; + private HashMap locs; /** Constructs a new HandCuff Manager, for handling all the handcuffing. */ public HandCuffManager() { - this.handcuffed = new HashMap(); - this.locs = new HashMap(); + this.handcuffed = new HashMap(); + this.locs = new HashMap(); } /** * Adds handcuffs to a player. * - * @param name of the player + * @param uuid of the player * @param location where the player was handcuffed, so they can't move */ - public void addHandCuffs(String name, Location location) { - this.handcuffed.put(name.toLowerCase(), System.currentTimeMillis()); - this.locs.put(name.toLowerCase(), location); + public void addHandCuffs(UUID uuid, Location location) { + this.handcuffed.put(uuid, System.currentTimeMillis()); + this.locs.put(uuid, location); } /** * Removes the handcuffs from the given player. * - * @param name of the person to remove the handcuffs from + * @param uuid of the person to remove the handcuffs from */ - public void removeHandCuffs(String name) { - this.handcuffed.remove(name.toLowerCase()); - this.locs.remove(name.toLowerCase()); + public void removeHandCuffs(UUID uuid) { + this.handcuffed.remove(uuid); + this.locs.remove(uuid); } /** * Gets if the player is handcuffed or not. * - * @param name of the player to check + * @param uuid of the player to check * @return true if they are handcuffed, false if not */ - public boolean isHandCuffed(String name) { - return this.handcuffed.containsKey(name.toLowerCase()); + public boolean isHandCuffed(UUID uuid) { + return this.handcuffed.containsKey(uuid); } /** * Gets the next Long time we should send a message to the player. * - * @param name of the player to get the name we're supposed to message them next + * @param uuid of the player to get the name we're supposed to message them next * @return long value of the system time in milliseconds */ - public Long getNextMessageTime(String name) { - return this.handcuffed.get(name.toLowerCase()); + public Long getNextMessageTime(UUID uuid) { + return this.handcuffed.get(uuid); } /** * Updates the time to the next 10 seconds from now to when we should send them a message. * - * @param name of the player we're setting the message time to + * @param uuid of the player we're setting the message time to */ - public void updateNextTime(String name) { - this.handcuffed.put(name.toLowerCase(), System.currentTimeMillis() + 10000); + public void updateNextTime(UUID uuid) { + this.handcuffed.put(uuid, System.currentTimeMillis() + 10000); } /** * Gets the location where the given player was handcuffed at. * - * @param name of the player get the location for + * @param uuid of the player get the location for * @return the location where the player was handcuffed at */ - public Location getLocation(String name) { - return this.locs.get(name.toLowerCase()); + public Location getLocation(UUID uuid) { + return this.locs.get(uuid); } } diff --git a/src/main/java/com/graywolf336/jail/PrisonerManager.java b/src/main/java/com/graywolf336/jail/PrisonerManager.java index 597fce8..a2b71c1 100644 --- a/src/main/java/com/graywolf336/jail/PrisonerManager.java +++ b/src/main/java/com/graywolf336/jail/PrisonerManager.java @@ -119,8 +119,8 @@ public class PrisonerManager { public void jailPrisoner(Jail jail, Cell cell, Player player, Prisoner prisoner) { //If they have handcuffs on them, then let's remove them before we continue //this way the handcuff listeners and this aren't battleing each other - if(pl.getHandCuffManager().isHandCuffed(player.getName())) { - pl.getHandCuffManager().removeHandCuffs(player.getName()); + if(pl.getHandCuffManager().isHandCuffed(player.getUniqueId())) { + pl.getHandCuffManager().removeHandCuffs(player.getUniqueId()); } //They are no longer offline, so set that. diff --git a/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java b/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java index 232bc1e..9336800 100644 --- a/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java +++ b/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java @@ -26,12 +26,12 @@ public class HandCuffCommand implements Command { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEHANDCUFFED, new String[] { player.getName() })); }else if(jm.isPlayerJailed(player.getUniqueId())) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CURRENTLYJAILEDHANDCUFF, new String[] { player.getName() })); - }else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getName())) { + }else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() })); - jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getName()); + jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId()); player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED)); }else { - jm.getPlugin().getHandCuffManager().addHandCuffs(player.getName(), player.getLocation()); + jm.getPlugin().getHandCuffManager().addHandCuffs(player.getUniqueId(), player.getLocation()); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSON, new String[] { player.getName() })); player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFED)); } diff --git a/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java b/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java index 4c5b468..78d3af5 100644 --- a/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java +++ b/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java @@ -22,9 +22,9 @@ public class UnHandCuffCommand implements Command { if(player == null) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE)); - }else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getName())) { + }else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() })); - jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getName()); + jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId()); player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED)); }else { sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTHANDCUFFED, new String[] { player.getName() })); diff --git a/src/main/java/com/graywolf336/jail/listeners/HandCuffListener.java b/src/main/java/com/graywolf336/jail/listeners/HandCuffListener.java index fa24321..a35385d 100644 --- a/src/main/java/com/graywolf336/jail/listeners/HandCuffListener.java +++ b/src/main/java/com/graywolf336/jail/listeners/HandCuffListener.java @@ -28,17 +28,17 @@ public class HandCuffListener implements Listener { public void onPlayerMove(PlayerMoveEvent event) { if(event.isCancelled()) return; - if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getName())) { - Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getName()); + if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) { + Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId()); to.setPitch(event.getTo().getPitch()); to.setYaw(event.getTo().getYaw()); tos.put(event.getPlayer().getName(), to); event.getPlayer().teleport(to); - if(System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getName())) { + if(System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) { event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and cant move!"); - pl.getHandCuffManager().updateNextTime(event.getPlayer().getName()); + pl.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId()); } } } @@ -47,18 +47,18 @@ public class HandCuffListener implements Listener { public void onPlayerTeleport(PlayerTeleportEvent event) { if(event.isCancelled()) return; - if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getName())) { + if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) { if(event.getTo() != tos.get(event.getPlayer().getName())) { - Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getName()); + Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId()); to.setPitch(event.getTo().getPitch()); to.setYaw(event.getTo().getYaw()); tos.put(event.getPlayer().getName(), to); event.getPlayer().teleport(to); - if(System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getName())) { + if(System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) { event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and cant move!"); - pl.getHandCuffManager().updateNextTime(event.getPlayer().getName()); + pl.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId()); } } } @@ -68,7 +68,7 @@ public class HandCuffListener implements Listener { public void playerChat(AsyncPlayerChatEvent event) { if(event.isCancelled()) return; - if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getName())) { + if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) { if(!event.getPlayer().hasPermission("jail.command.handcuff")) { event.setCancelled(true); event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to talk!"); @@ -80,7 +80,7 @@ public class HandCuffListener implements Listener { public void blockBreak(BlockBreakEvent event) { if(event.isCancelled()) return; - if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getName())) { + if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) { event.setCancelled(true); event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to break blocks!"); } @@ -90,7 +90,7 @@ public class HandCuffListener implements Listener { public void blockPlace(BlockPlaceEvent event) { if(event.isCancelled()) return; - if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getName())) { + if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) { event.setCancelled(true); event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to place blocks!"); } @@ -100,7 +100,7 @@ public class HandCuffListener implements Listener { public void preCommands(PlayerCommandPreprocessEvent event) { if(event.isCancelled()) return; - if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getName())) { + if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) { if(!event.getPlayer().hasPermission("jail.command.handcuff")) { if(!event.getMessage().startsWith("/r") || !event.getMessage().startsWith("/reply")) { event.setCancelled(true);