Add handcuffing, next commit will be handcuff listeners.

This commit is contained in:
graywolf336 2014-01-01 16:19:04 -06:00
parent d49d2243d8
commit 9b534b2abc
7 changed files with 176 additions and 0 deletions

View File

@ -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)

View 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());
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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;
}
}