diff --git a/README.md b/README.md index 0d58750..50d2df0 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Done * New command system, internally we handle commands a lot better * Delete commands are now remove * Language system (adding language strings as I use them, be patient with me) +* Handcuffs are now implemented * Config value ``jailing.jail.defaultJail`` is now used * Config value ``jailing.jail.defaultTime`` is now used * The time passed can be represented by time shorthand, aka "3hours" or "15minutes" or etc (defaults to minutes) diff --git a/src/main/java/com/graywolf336/jail/HandCuffManager.java b/src/main/java/com/graywolf336/jail/HandCuffManager.java new file mode 100644 index 0000000..50e206c --- /dev/null +++ b/src/main/java/com/graywolf336/jail/HandCuffManager.java @@ -0,0 +1,82 @@ +package com.graywolf336.jail; + +import java.util.HashMap; + +import org.bukkit.Location; + +/** + * + * @author graywolf336 + * @since 2.6.3 + * @version 1.0.1 + */ +public class HandCuffManager { + 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(); + } + + /** + * Adds handcuffs to a player. + * + * @param name 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); + } + + /** + * Removes the handcuffs from the given player. + * + * @param name of the person to remove the handcuffs from + */ + public void removeHandCuffs(String name) { + this.handcuffed.remove(name.toLowerCase()); + this.locs.remove(name.toLowerCase()); + } + + /** + * Gets if the player is handcuffed or not. + * + * @param name 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()); + } + + /** + * 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 + * @return long value of the system time in milliseconds + */ + public Long getNextMessageTime(String name) { + return this.handcuffed.get(name.toLowerCase()); + } + + /** + * 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 + */ + public void updateNextTime(String name) { + this.handcuffed.put(name.toLowerCase(), System.currentTimeMillis() + 10000); + } + + /** + * Gets the location where the given player was handcuffed at. + * + * @param name 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()); + } +} diff --git a/src/main/java/com/graywolf336/jail/JailMain.java b/src/main/java/com/graywolf336/jail/JailMain.java index 472d9b9..21edd89 100644 --- a/src/main/java/com/graywolf336/jail/JailMain.java +++ b/src/main/java/com/graywolf336/jail/JailMain.java @@ -21,6 +21,7 @@ import com.graywolf336.jail.listeners.PlayerListener; */ public class JailMain extends JavaPlugin { private CommandHandler cmdHand; + private HandCuffManager hcm; private JailIO io; private JailManager jm; private PrisonerManager pm; @@ -29,6 +30,7 @@ public class JailMain extends JavaPlugin { public void onEnable() { loadConfig(); + hcm = new HandCuffManager(); jm = new JailManager(this); io = new JailIO(this); io.loadLanguage(); @@ -93,6 +95,11 @@ public class JailMain extends JavaPlugin { return true;//Always return true here, that way we can handle the help and command usage ourself. } + /** Gets the {@link HandCuffManager} instance. */ + public HandCuffManager getHandCuffManager() { + return this.hcm; + } + /** Gets the {@link JailIO} instance. */ public JailIO getJailIO() { return this.io; diff --git a/src/main/java/com/graywolf336/jail/PrisonerManager.java b/src/main/java/com/graywolf336/jail/PrisonerManager.java index d8111bd..4b6356d 100644 --- a/src/main/java/com/graywolf336/jail/PrisonerManager.java +++ b/src/main/java/com/graywolf336/jail/PrisonerManager.java @@ -119,6 +119,12 @@ public class PrisonerManager { * @param prisoner data containing everything pertaining to them */ 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()); + } + //They are no longer offline, so set that. prisoner.setOfflinePending(false); diff --git a/src/main/java/com/graywolf336/jail/command/CommandHandler.java b/src/main/java/com/graywolf336/jail/command/CommandHandler.java index 90d9a4d..520c55a 100644 --- a/src/main/java/com/graywolf336/jail/command/CommandHandler.java +++ b/src/main/java/com/graywolf336/jail/command/CommandHandler.java @@ -12,6 +12,7 @@ import com.graywolf336.jail.JailMain; import com.graywolf336.jail.JailManager; import com.graywolf336.jail.command.commands.CellCreateCommand; +import com.graywolf336.jail.command.commands.HandCuffCommand; import com.graywolf336.jail.command.commands.JailCheckCommand; import com.graywolf336.jail.command.commands.JailClearCommand; import com.graywolf336.jail.command.commands.JailCommand; @@ -21,6 +22,7 @@ import com.graywolf336.jail.command.commands.JailListCommand; import com.graywolf336.jail.command.commands.JailRemoveCellCommand; import com.graywolf336.jail.command.commands.JailStopCommand; import com.graywolf336.jail.command.commands.JailVersionCommand; +import com.graywolf336.jail.command.commands.UnHandCuffCommand; import com.graywolf336.jail.command.commands.UnjailCommand; /** @@ -139,6 +141,7 @@ public class CommandHandler { /** Loads all the commands into the hashmap. */ private void loadCommands() { load(CellCreateCommand.class); + load(HandCuffCommand.class); load(JailCheckCommand.class); load(JailClearCommand.class); load(JailCommand.class); @@ -148,6 +151,7 @@ public class CommandHandler { load(JailRemoveCellCommand.class); load(JailStopCommand.class); load(JailVersionCommand.class); + load(UnHandCuffCommand.class); load(UnjailCommand.class); } diff --git a/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java b/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java new file mode 100644 index 0000000..dd8c577 --- /dev/null +++ b/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java @@ -0,0 +1,41 @@ +package com.graywolf336.jail.command.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.graywolf336.jail.JailManager; +import com.graywolf336.jail.command.Command; +import com.graywolf336.jail.command.CommandInfo; + +@CommandInfo( + maxArgs = 1, + minimumArgs = 1, + needsPlayer = false, + pattern = "handcuff|hc", + permission = "jail.command.handcuff", + usage = "/handcuff [player]" + ) +public class HandCuffCommand implements Command { + public boolean execute(JailManager jm, CommandSender sender, String... args) { + Player player = jm.getPlugin().getServer().getPlayer(args[0]); + + if(player == null) { + sender.sendMessage(ChatColor.RED + "That player is not online!"); + }else if(player.hasPermission("jail.cantbehandcuffed")) { + sender.sendMessage(ChatColor.RED + "That player can't be handcuffed."); + }else if(jm.isPlayerJailed(player.getName())) { + sender.sendMessage(ChatColor.RED + "That player is currently jailed, you can't handcuff a prisoner."); + }else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getName())) { + sender.sendMessage(ChatColor.GREEN + "That player is already handcuffed, releasing them now!"); + jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getName()); + player.sendMessage(ChatColor.GREEN + "Your handcuffs have been rmeoved."); + }else { + jm.getPlugin().getHandCuffManager().addHandCuffs(player.getName(), player.getLocation()); + sender.sendMessage(ChatColor.BLUE + args[0] + ChatColor.GREEN + " has been handcuffed!"); + player.sendMessage(ChatColor.RED + "You've been handcuffed."); + } + + return true; + } +} diff --git a/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java b/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java new file mode 100644 index 0000000..6065f71 --- /dev/null +++ b/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java @@ -0,0 +1,35 @@ +package com.graywolf336.jail.command.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.graywolf336.jail.JailManager; +import com.graywolf336.jail.command.Command; +import com.graywolf336.jail.command.CommandInfo; + +@CommandInfo( + maxArgs = 1, + minimumArgs = 1, + needsPlayer = false, + pattern = "unhandcuff|uhc", + permission = "jail.command.handcuff", + usage = "/unhandcuff [player]" + ) +public class UnHandCuffCommand implements Command { + public boolean execute(JailManager jm, CommandSender sender, String... args) { + Player player = jm.getPlugin().getServer().getPlayerExact(args[0]); + + if(player == null) { + sender.sendMessage(ChatColor.RED + "That player is not online!"); + }else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getName())) { + sender.sendMessage(ChatColor.GREEN + "Releasing them now!"); + jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getName()); + player.sendMessage(ChatColor.GREEN + "Your handcuffs have been rmeoved."); + }else { + sender.sendMessage(ChatColor.BLUE + player.getName() + ChatColor.RED + " doesn't have any handcuffs to remove!"); + } + + return true; + } +}