Add handcuffing, next commit will be handcuff listeners.
This commit is contained in:
		@@ -14,6 +14,7 @@ Done
 | 
				
			|||||||
* New command system, internally we handle commands a lot better
 | 
					* New command system, internally we handle commands a lot better
 | 
				
			||||||
* Delete commands are now remove
 | 
					* Delete commands are now remove
 | 
				
			||||||
* Language system (adding language strings as I use them, be patient with me)
 | 
					* 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.defaultJail`` is now used
 | 
				
			||||||
* Config value ``jailing.jail.defaultTime`` 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)
 | 
					* The time passed can be represented by time shorthand, aka "3hours" or "15minutes" or etc (defaults to minutes)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										82
									
								
								src/main/java/com/graywolf336/jail/HandCuffManager.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								src/main/java/com/graywolf336/jail/HandCuffManager.java
									
									
									
									
									
										Normal file
									
								
							@@ -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<String, Long> handcuffed;
 | 
				
			||||||
 | 
						private HashMap<String, Location> locs;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Constructs a new HandCuff Manager, for handling all the handcuffing. */
 | 
				
			||||||
 | 
						public HandCuffManager() {
 | 
				
			||||||
 | 
							this.handcuffed = new HashMap<String, Long>();
 | 
				
			||||||
 | 
							this.locs = new HashMap<String, Location>();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * 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());
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -21,6 +21,7 @@ import com.graywolf336.jail.listeners.PlayerListener;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
public class JailMain extends JavaPlugin {
 | 
					public class JailMain extends JavaPlugin {
 | 
				
			||||||
	private CommandHandler cmdHand;
 | 
						private CommandHandler cmdHand;
 | 
				
			||||||
 | 
						private HandCuffManager hcm;
 | 
				
			||||||
	private JailIO io;
 | 
						private JailIO io;
 | 
				
			||||||
	private JailManager jm;
 | 
						private JailManager jm;
 | 
				
			||||||
	private PrisonerManager pm;
 | 
						private PrisonerManager pm;
 | 
				
			||||||
@@ -29,6 +30,7 @@ public class JailMain extends JavaPlugin {
 | 
				
			|||||||
	public void onEnable() {
 | 
						public void onEnable() {
 | 
				
			||||||
		loadConfig();
 | 
							loadConfig();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							hcm = new HandCuffManager();
 | 
				
			||||||
		jm = new JailManager(this);
 | 
							jm = new JailManager(this);
 | 
				
			||||||
		io = new JailIO(this);
 | 
							io = new JailIO(this);
 | 
				
			||||||
		io.loadLanguage();
 | 
							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.
 | 
							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. */
 | 
						/** Gets the {@link JailIO} instance. */
 | 
				
			||||||
	public JailIO getJailIO() {
 | 
						public JailIO getJailIO() {
 | 
				
			||||||
		return this.io;
 | 
							return this.io;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -119,6 +119,12 @@ public class PrisonerManager {
 | 
				
			|||||||
	 * @param prisoner data containing everything pertaining to them
 | 
						 * @param prisoner data containing everything pertaining to them
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	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
 | 
				
			||||||
 | 
							//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.
 | 
							//They are no longer offline, so set that.
 | 
				
			||||||
		prisoner.setOfflinePending(false);
 | 
							prisoner.setOfflinePending(false);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,7 @@ import com.graywolf336.jail.JailMain;
 | 
				
			|||||||
import com.graywolf336.jail.JailManager;
 | 
					import com.graywolf336.jail.JailManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.graywolf336.jail.command.commands.CellCreateCommand;
 | 
					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.JailCheckCommand;
 | 
				
			||||||
import com.graywolf336.jail.command.commands.JailClearCommand;
 | 
					import com.graywolf336.jail.command.commands.JailClearCommand;
 | 
				
			||||||
import com.graywolf336.jail.command.commands.JailCommand;
 | 
					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.JailRemoveCellCommand;
 | 
				
			||||||
import com.graywolf336.jail.command.commands.JailStopCommand;
 | 
					import com.graywolf336.jail.command.commands.JailStopCommand;
 | 
				
			||||||
import com.graywolf336.jail.command.commands.JailVersionCommand;
 | 
					import com.graywolf336.jail.command.commands.JailVersionCommand;
 | 
				
			||||||
 | 
					import com.graywolf336.jail.command.commands.UnHandCuffCommand;
 | 
				
			||||||
import com.graywolf336.jail.command.commands.UnjailCommand;
 | 
					import com.graywolf336.jail.command.commands.UnjailCommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@@ -139,6 +141,7 @@ public class CommandHandler {
 | 
				
			|||||||
	/** Loads all the commands into the hashmap. */
 | 
						/** Loads all the commands into the hashmap. */
 | 
				
			||||||
	private void loadCommands() {
 | 
						private void loadCommands() {
 | 
				
			||||||
		load(CellCreateCommand.class);
 | 
							load(CellCreateCommand.class);
 | 
				
			||||||
 | 
							load(HandCuffCommand.class);
 | 
				
			||||||
		load(JailCheckCommand.class);
 | 
							load(JailCheckCommand.class);
 | 
				
			||||||
		load(JailClearCommand.class);
 | 
							load(JailClearCommand.class);
 | 
				
			||||||
		load(JailCommand.class);
 | 
							load(JailCommand.class);
 | 
				
			||||||
@@ -148,6 +151,7 @@ public class CommandHandler {
 | 
				
			|||||||
		load(JailRemoveCellCommand.class);
 | 
							load(JailRemoveCellCommand.class);
 | 
				
			||||||
		load(JailStopCommand.class);
 | 
							load(JailStopCommand.class);
 | 
				
			||||||
		load(JailVersionCommand.class);
 | 
							load(JailVersionCommand.class);
 | 
				
			||||||
 | 
							load(UnHandCuffCommand.class);
 | 
				
			||||||
		load(UnjailCommand.class);
 | 
							load(UnjailCommand.class);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -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;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user