Move the handcuffing to store data per uuid.
This commit is contained in:
parent
084e8bea01
commit
c5720ec84d
@ -1,6 +1,7 @@
|
|||||||
package com.graywolf336.jail;
|
package com.graywolf336.jail;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
@ -8,75 +9,75 @@ import org.bukkit.Location;
|
|||||||
*
|
*
|
||||||
* @author graywolf336
|
* @author graywolf336
|
||||||
* @since 2.6.3
|
* @since 2.6.3
|
||||||
* @version 1.0.1
|
* @version 1.0.2
|
||||||
*/
|
*/
|
||||||
public class HandCuffManager {
|
public class HandCuffManager {
|
||||||
private HashMap<String, Long> handcuffed;
|
private HashMap<UUID, Long> handcuffed;
|
||||||
private HashMap<String, Location> locs;
|
private HashMap<UUID, Location> locs;
|
||||||
|
|
||||||
/** Constructs a new HandCuff Manager, for handling all the handcuffing. */
|
/** Constructs a new HandCuff Manager, for handling all the handcuffing. */
|
||||||
public HandCuffManager() {
|
public HandCuffManager() {
|
||||||
this.handcuffed = new HashMap<String, Long>();
|
this.handcuffed = new HashMap<UUID, Long>();
|
||||||
this.locs = new HashMap<String, Location>();
|
this.locs = new HashMap<UUID, Location>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds handcuffs to a player.
|
* 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
|
* @param location where the player was handcuffed, so they can't move
|
||||||
*/
|
*/
|
||||||
public void addHandCuffs(String name, Location location) {
|
public void addHandCuffs(UUID uuid, Location location) {
|
||||||
this.handcuffed.put(name.toLowerCase(), System.currentTimeMillis());
|
this.handcuffed.put(uuid, System.currentTimeMillis());
|
||||||
this.locs.put(name.toLowerCase(), location);
|
this.locs.put(uuid, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the handcuffs from the given player.
|
* 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) {
|
public void removeHandCuffs(UUID uuid) {
|
||||||
this.handcuffed.remove(name.toLowerCase());
|
this.handcuffed.remove(uuid);
|
||||||
this.locs.remove(name.toLowerCase());
|
this.locs.remove(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets if the player is handcuffed or not.
|
* 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
|
* @return true if they are handcuffed, false if not
|
||||||
*/
|
*/
|
||||||
public boolean isHandCuffed(String name) {
|
public boolean isHandCuffed(UUID uuid) {
|
||||||
return this.handcuffed.containsKey(name.toLowerCase());
|
return this.handcuffed.containsKey(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the next Long time we should send a message to the player.
|
* 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
|
* @return long value of the system time in milliseconds
|
||||||
*/
|
*/
|
||||||
public Long getNextMessageTime(String name) {
|
public Long getNextMessageTime(UUID uuid) {
|
||||||
return this.handcuffed.get(name.toLowerCase());
|
return this.handcuffed.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the time to the next 10 seconds from now to when we should send them a message.
|
* 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) {
|
public void updateNextTime(UUID uuid) {
|
||||||
this.handcuffed.put(name.toLowerCase(), System.currentTimeMillis() + 10000);
|
this.handcuffed.put(uuid, System.currentTimeMillis() + 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the location where the given player was handcuffed at.
|
* 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
|
* @return the location where the player was handcuffed at
|
||||||
*/
|
*/
|
||||||
public Location getLocation(String name) {
|
public Location getLocation(UUID uuid) {
|
||||||
return this.locs.get(name.toLowerCase());
|
return this.locs.get(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,8 +119,8 @@ public class PrisonerManager {
|
|||||||
public void jailPrisoner(Jail jail, Cell cell, Player player, Prisoner prisoner) {
|
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
|
//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
|
//this way the handcuff listeners and this aren't battleing each other
|
||||||
if(pl.getHandCuffManager().isHandCuffed(player.getName())) {
|
if(pl.getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||||
pl.getHandCuffManager().removeHandCuffs(player.getName());
|
pl.getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
//They are no longer offline, so set that.
|
//They are no longer offline, so set that.
|
||||||
|
@ -26,12 +26,12 @@ public class HandCuffCommand implements Command {
|
|||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEHANDCUFFED, new String[] { player.getName() }));
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEHANDCUFFED, new String[] { player.getName() }));
|
||||||
}else if(jm.isPlayerJailed(player.getUniqueId())) {
|
}else if(jm.isPlayerJailed(player.getUniqueId())) {
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CURRENTLYJAILEDHANDCUFF, new String[] { player.getName() }));
|
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() }));
|
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));
|
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED));
|
||||||
}else {
|
}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() }));
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSON, new String[] { player.getName() }));
|
||||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFED));
|
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFED));
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ public class UnHandCuffCommand implements Command {
|
|||||||
|
|
||||||
if(player == null) {
|
if(player == null) {
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE));
|
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() }));
|
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));
|
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED));
|
||||||
}else {
|
}else {
|
||||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTHANDCUFFED, new String[] { player.getName() }));
|
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTHANDCUFFED, new String[] { player.getName() }));
|
||||||
|
@ -28,17 +28,17 @@ public class HandCuffListener implements Listener {
|
|||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
if(event.isCancelled()) return;
|
if(event.isCancelled()) return;
|
||||||
|
|
||||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getName())) {
|
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||||
Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getName());
|
Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId());
|
||||||
to.setPitch(event.getTo().getPitch());
|
to.setPitch(event.getTo().getPitch());
|
||||||
to.setYaw(event.getTo().getYaw());
|
to.setYaw(event.getTo().getYaw());
|
||||||
|
|
||||||
tos.put(event.getPlayer().getName(), to);
|
tos.put(event.getPlayer().getName(), to);
|
||||||
event.getPlayer().teleport(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!");
|
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) {
|
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||||
if(event.isCancelled()) return;
|
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())) {
|
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.setPitch(event.getTo().getPitch());
|
||||||
to.setYaw(event.getTo().getYaw());
|
to.setYaw(event.getTo().getYaw());
|
||||||
|
|
||||||
tos.put(event.getPlayer().getName(), to);
|
tos.put(event.getPlayer().getName(), to);
|
||||||
event.getPlayer().teleport(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!");
|
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) {
|
public void playerChat(AsyncPlayerChatEvent event) {
|
||||||
if(event.isCancelled()) return;
|
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.getPlayer().hasPermission("jail.command.handcuff")) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to talk!");
|
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) {
|
public void blockBreak(BlockBreakEvent event) {
|
||||||
if(event.isCancelled()) return;
|
if(event.isCancelled()) return;
|
||||||
|
|
||||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getName())) {
|
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to break blocks!");
|
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) {
|
public void blockPlace(BlockPlaceEvent event) {
|
||||||
if(event.isCancelled()) return;
|
if(event.isCancelled()) return;
|
||||||
|
|
||||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getName())) {
|
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to place blocks!");
|
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) {
|
public void preCommands(PlayerCommandPreprocessEvent event) {
|
||||||
if(event.isCancelled()) return;
|
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.getPlayer().hasPermission("jail.command.handcuff")) {
|
||||||
if(!event.getMessage().startsWith("/r") || !event.getMessage().startsWith("/reply")) {
|
if(!event.getMessage().startsWith("/r") || !event.getMessage().startsWith("/reply")) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user