Fix the spacing and clean it up.
This commit is contained in:
@ -1,31 +1,31 @@
|
||||
package com.graywolf336.jail.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
|
||||
/**
|
||||
* The base of all the commands.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public interface Command {
|
||||
/**
|
||||
* Execute the command given the arguments, returning whether the command handled it or not.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* When the method returns false, the usage message is printed to the sender. If the method
|
||||
* handles the command in any way, such as sending a message to the sender or actually doing
|
||||
* something, then it should return true so that the sender of the command doesn't get the
|
||||
* usage message.
|
||||
*
|
||||
* @param jm An instance of the {@link JailManager}
|
||||
* @param sender The {@link CommandSender sender} of the command
|
||||
* @param args The args, in an array
|
||||
* @return True if the method handled it in any way, false if we should send the usage message.
|
||||
*/
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception;
|
||||
}
|
||||
package com.graywolf336.jail.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
|
||||
/**
|
||||
* The base of all the commands.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public interface Command {
|
||||
/**
|
||||
* Execute the command given the arguments, returning whether the command handled it or not.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* When the method returns false, the usage message is printed to the sender. If the method
|
||||
* handles the command in any way, such as sending a message to the sender or actually doing
|
||||
* something, then it should return true so that the sender of the command doesn't get the
|
||||
* usage message.
|
||||
*
|
||||
* @param jm An instance of the {@link JailManager}
|
||||
* @param sender The {@link CommandSender sender} of the command
|
||||
* @param args The args, in an array
|
||||
* @return True if the method handled it in any way, false if we should send the usage message.
|
||||
*/
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception;
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.commands.HandCuffCommand;
|
||||
import com.graywolf336.jail.command.commands.ToggleJailDebugCommand;
|
||||
import com.graywolf336.jail.command.commands.UnHandCuffCommand;
|
||||
import com.graywolf336.jail.command.commands.UnJailForceCommand;
|
||||
import com.graywolf336.jail.command.commands.UnJailCommand;
|
||||
import com.graywolf336.jail.command.commands.UnJailForceCommand;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
/**
|
||||
@ -26,148 +26,148 @@ import com.graywolf336.jail.enums.Lang;
|
||||
*
|
||||
*/
|
||||
public class CommandHandler {
|
||||
private LinkedHashMap<String, Command> commands;
|
||||
|
||||
public CommandHandler(JailMain plugin) {
|
||||
commands = new LinkedHashMap<String, Command>();
|
||||
loadCommands();
|
||||
|
||||
plugin.debug("Loaded " + commands.size() + " commands.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given command and checks that the command is in valid form.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* It checks in the following order:
|
||||
* <ol>
|
||||
* <li>If the command is registered or not.</li>
|
||||
* <li>If more than one command matches the command's name and sends the usage for each one.</li>
|
||||
* <li>If they have permission for it, if they don't then we send them a message stating so.</li>
|
||||
* <li>If the command needs a player instance, if so we send a message stating that.</li>
|
||||
* <li>If the required minimum arguments have been passed, if not sends the usage.</li>
|
||||
* <li>If the required maximum arguments have been passed (if there is a max, -1 if no max), if not sends the usage.</li>
|
||||
* <li>Then executes, upon failed execution it sends the usage command.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param jailmanager The instance of {@link JailManager}.
|
||||
* @param sender The sender of the command.
|
||||
* @param commandLine The name of the command.
|
||||
* @param args The arguments passed to the command.
|
||||
*/
|
||||
public void handleCommand(JailManager jailmanager, CommandSender sender, String commandLine, String[] args) {
|
||||
List<Command> matches = getMatches(commandLine);
|
||||
|
||||
//If no matches were found, send them the unknown command message.
|
||||
if(matches.size() == 0) {
|
||||
if(commandLine.startsWith("jail")) {
|
||||
String j = commandLine.substring(0, 4);
|
||||
String a0 = commandLine.substring(4, commandLine.length());
|
||||
|
||||
ArrayList<String> args2 = new ArrayList<String>();
|
||||
for(String s : args)
|
||||
args2.add(s);
|
||||
args2.add(a0);
|
||||
|
||||
if(jailmanager.getPlugin().onCommand(sender, null, j, args2.toArray(new String[args2.size()])))
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(Lang.UNKNOWNCOMMAND.get(commandLine));
|
||||
return;
|
||||
}
|
||||
|
||||
//If more than one command was found, send them each command's help message.
|
||||
if(matches.size() > 1) {
|
||||
for(Command c : matches)
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
Command c = matches.get(0);
|
||||
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
|
||||
|
||||
// First, let's check if the sender has permission for the command.
|
||||
if(!sender.hasPermission(i.permission())) {
|
||||
sender.sendMessage(Lang.NOPERMISSION.get());
|
||||
return;
|
||||
}
|
||||
|
||||
// Next, let's check if we need a player and then if the sender is actually a player
|
||||
if(i.needsPlayer() && !(sender instanceof Player)) {
|
||||
sender.sendMessage(Lang.PLAYERCONTEXTREQUIRED.get());
|
||||
return;
|
||||
}
|
||||
|
||||
// Now, let's check the size of the arguments passed. If it is shorter than the minimum required args, let's show the usage.
|
||||
if(args.length < i.minimumArgs()) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
// Then, if the maximumArgs doesn't equal -1, we need to check if the size of the arguments passed is greater than the maximum args.
|
||||
if(i.maxArgs() != -1 && i.maxArgs() < args.length) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
// Since everything has been checked and we're all clear, let's execute it.
|
||||
// But if get back false, let's show the usage message.
|
||||
try {
|
||||
if(!c.execute(jailmanager, sender, args)) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
showUsage(sender, c);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Command> getMatches(String command) {
|
||||
List<Command> result = new ArrayList<Command>();
|
||||
|
||||
for(Entry<String, Command> entry : commands.entrySet()) {
|
||||
if(command.matches(entry.getKey())) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the usage information to the sender, if they have permission.
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param command The command to send usage of.
|
||||
*/
|
||||
private void showUsage(CommandSender sender, Command command) {
|
||||
CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);
|
||||
if(!sender.hasPermission(info.permission())) return;
|
||||
|
||||
sender.sendMessage(info.usage());
|
||||
}
|
||||
|
||||
/** Loads all the commands into the hashmap. */
|
||||
private void loadCommands() {
|
||||
load(HandCuffCommand.class);
|
||||
load(ToggleJailDebugCommand.class);
|
||||
load(UnHandCuffCommand.class);
|
||||
load(UnJailCommand.class);
|
||||
load(UnJailForceCommand.class);
|
||||
}
|
||||
private LinkedHashMap<String, Command> commands;
|
||||
|
||||
private void load(Class<? extends Command> c) {
|
||||
CommandInfo info = c.getAnnotation(CommandInfo.class);
|
||||
if(info == null) return;
|
||||
|
||||
try {
|
||||
commands.put(info.pattern(), c.newInstance());
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public CommandHandler(JailMain plugin) {
|
||||
commands = new LinkedHashMap<String, Command>();
|
||||
loadCommands();
|
||||
|
||||
plugin.debug("Loaded " + commands.size() + " commands.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given command and checks that the command is in valid form.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* It checks in the following order:
|
||||
* <ol>
|
||||
* <li>If the command is registered or not.</li>
|
||||
* <li>If more than one command matches the command's name and sends the usage for each one.</li>
|
||||
* <li>If they have permission for it, if they don't then we send them a message stating so.</li>
|
||||
* <li>If the command needs a player instance, if so we send a message stating that.</li>
|
||||
* <li>If the required minimum arguments have been passed, if not sends the usage.</li>
|
||||
* <li>If the required maximum arguments have been passed (if there is a max, -1 if no max), if not sends the usage.</li>
|
||||
* <li>Then executes, upon failed execution it sends the usage command.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param jailmanager The instance of {@link JailManager}.
|
||||
* @param sender The sender of the command.
|
||||
* @param commandLine The name of the command.
|
||||
* @param args The arguments passed to the command.
|
||||
*/
|
||||
public void handleCommand(JailManager jailmanager, CommandSender sender, String commandLine, String[] args) {
|
||||
List<Command> matches = getMatches(commandLine);
|
||||
|
||||
//If no matches were found, send them the unknown command message.
|
||||
if(matches.size() == 0) {
|
||||
if(commandLine.startsWith("jail")) {
|
||||
String j = commandLine.substring(0, 4);
|
||||
String a0 = commandLine.substring(4, commandLine.length());
|
||||
|
||||
ArrayList<String> args2 = new ArrayList<String>();
|
||||
for(String s : args)
|
||||
args2.add(s);
|
||||
args2.add(a0);
|
||||
|
||||
if(jailmanager.getPlugin().onCommand(sender, null, j, args2.toArray(new String[args2.size()])))
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(Lang.UNKNOWNCOMMAND.get(commandLine));
|
||||
return;
|
||||
}
|
||||
|
||||
//If more than one command was found, send them each command's help message.
|
||||
if(matches.size() > 1) {
|
||||
for(Command c : matches)
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
Command c = matches.get(0);
|
||||
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
|
||||
|
||||
// First, let's check if the sender has permission for the command.
|
||||
if(!sender.hasPermission(i.permission())) {
|
||||
sender.sendMessage(Lang.NOPERMISSION.get());
|
||||
return;
|
||||
}
|
||||
|
||||
// Next, let's check if we need a player and then if the sender is actually a player
|
||||
if(i.needsPlayer() && !(sender instanceof Player)) {
|
||||
sender.sendMessage(Lang.PLAYERCONTEXTREQUIRED.get());
|
||||
return;
|
||||
}
|
||||
|
||||
// Now, let's check the size of the arguments passed. If it is shorter than the minimum required args, let's show the usage.
|
||||
if(args.length < i.minimumArgs()) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
// Then, if the maximumArgs doesn't equal -1, we need to check if the size of the arguments passed is greater than the maximum args.
|
||||
if(i.maxArgs() != -1 && i.maxArgs() < args.length) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
// Since everything has been checked and we're all clear, let's execute it.
|
||||
// But if get back false, let's show the usage message.
|
||||
try {
|
||||
if(!c.execute(jailmanager, sender, args)) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
showUsage(sender, c);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Command> getMatches(String command) {
|
||||
List<Command> result = new ArrayList<Command>();
|
||||
|
||||
for(Entry<String, Command> entry : commands.entrySet()) {
|
||||
if(command.matches(entry.getKey())) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the usage information to the sender, if they have permission.
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param command The command to send usage of.
|
||||
*/
|
||||
private void showUsage(CommandSender sender, Command command) {
|
||||
CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);
|
||||
if(!sender.hasPermission(info.permission())) return;
|
||||
|
||||
sender.sendMessage(info.usage());
|
||||
}
|
||||
|
||||
/** Loads all the commands into the hashmap. */
|
||||
private void loadCommands() {
|
||||
load(HandCuffCommand.class);
|
||||
load(ToggleJailDebugCommand.class);
|
||||
load(UnHandCuffCommand.class);
|
||||
load(UnJailCommand.class);
|
||||
load(UnJailForceCommand.class);
|
||||
}
|
||||
|
||||
private void load(Class<? extends Command> c) {
|
||||
CommandInfo info = c.getAnnotation(CommandInfo.class);
|
||||
if(info == null) return;
|
||||
|
||||
try {
|
||||
commands.put(info.pattern(), c.newInstance());
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,53 +23,53 @@ import java.lang.annotation.RetentionPolicy;
|
||||
* for that command. Finally we have the usage string, which is sent
|
||||
* when the sender of the command sends an incorrectly formatted
|
||||
* command. The order of checking is as defined in {@link CommandHandler#handleCommand(com.graywolf336.jail.JailManager, org.bukkit.command.CommandSender, String, String[]) CommandHandler.handleCommand}.
|
||||
*
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
@Retention (RetentionPolicy.RUNTIME)
|
||||
public @interface CommandInfo {
|
||||
/**
|
||||
* Gets the maximum amount of arguments required, -1 if no maximum (ex: Jailing someone with a reason or editing a reason).
|
||||
*
|
||||
* @return The maximum number of arguments required, -1 if no maximum.
|
||||
*/
|
||||
public int maxArgs();
|
||||
|
||||
/**
|
||||
* Gets the minimum amount of arguments required.
|
||||
*
|
||||
* @return The minimum number of arguments required.
|
||||
*/
|
||||
public int minimumArgs();
|
||||
|
||||
/**
|
||||
* Whether the command needs a player context or not.
|
||||
*
|
||||
* @return True if requires a player, false if not.
|
||||
*/
|
||||
public boolean needsPlayer();
|
||||
|
||||
/**
|
||||
* A regex pattern that allows for alternatives to the command (ex: /jail or /j, /jailstatus or /js).
|
||||
*
|
||||
* @return The regex pattern to match.
|
||||
*/
|
||||
public String pattern();
|
||||
|
||||
/**
|
||||
* Gets the permission required to execute this command.
|
||||
*
|
||||
* @return The permission required.
|
||||
*/
|
||||
public String permission();
|
||||
|
||||
/**
|
||||
* Gets the usage message for this command.
|
||||
*
|
||||
* @return The usage message.
|
||||
*/
|
||||
public String usage();
|
||||
public @interface CommandInfo {
|
||||
/**
|
||||
* Gets the maximum amount of arguments required, -1 if no maximum (ex: Jailing someone with a reason or editing a reason).
|
||||
*
|
||||
* @return The maximum number of arguments required, -1 if no maximum.
|
||||
*/
|
||||
public int maxArgs();
|
||||
|
||||
/**
|
||||
* Gets the minimum amount of arguments required.
|
||||
*
|
||||
* @return The minimum number of arguments required.
|
||||
*/
|
||||
public int minimumArgs();
|
||||
|
||||
/**
|
||||
* Whether the command needs a player context or not.
|
||||
*
|
||||
* @return True if requires a player, false if not.
|
||||
*/
|
||||
public boolean needsPlayer();
|
||||
|
||||
/**
|
||||
* A regex pattern that allows for alternatives to the command (ex: /jail or /j, /jailstatus or /js).
|
||||
*
|
||||
* @return The regex pattern to match.
|
||||
*/
|
||||
public String pattern();
|
||||
|
||||
/**
|
||||
* Gets the permission required to execute this command.
|
||||
*
|
||||
* @return The permission required.
|
||||
*/
|
||||
public String permission();
|
||||
|
||||
/**
|
||||
* Gets the usage message for this command.
|
||||
*
|
||||
* @return The usage message.
|
||||
*/
|
||||
public String usage();
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.subcommands.JailCreateCellCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCheckCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailClearCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailConfirmCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCreateCellCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCreateCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellsCommand;
|
||||
@ -37,176 +37,176 @@ import com.graywolf336.jail.command.subcommands.JailVersionCommand;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
public class JailHandler {
|
||||
private LinkedHashMap<String, Command> commands;
|
||||
|
||||
public JailHandler(JailMain plugin) {
|
||||
commands = new LinkedHashMap<String, Command>();
|
||||
loadCommands();
|
||||
|
||||
plugin.debug("Loaded " + commands.size() + " sub-commands of /jail.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given command and checks that the command is in valid form.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* It checks in the following order:
|
||||
* <ol>
|
||||
* <li>If they have permission for it, if they don't then we send them a message stating so.</li>
|
||||
* <li>If the command needs a player instance, if so we send a message stating that.</li>
|
||||
* <li>If the required minimum arguments have been passed, if not sends the usage.</li>
|
||||
* <li>If the required maximum arguments have been passed (if there is a max, -1 if no max), if not sends the usage.</li>
|
||||
* <li>Then executes, upon failed execution it sends the usage command.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param jailmanager The instance of {@link JailManager}.
|
||||
* @param sender The sender of the command.
|
||||
* @param args The arguments passed to the command.
|
||||
*/
|
||||
public boolean parseCommand(JailManager jailmanager, CommandSender sender, String[] args) {
|
||||
Command c = null;
|
||||
|
||||
//If they didn't provide any arguments (aka just: /jail) then we will need to send them some help
|
||||
if(args.length == 0) {
|
||||
//TODO: Create the help page(s)
|
||||
c = getMatches("jail").get(0);
|
||||
|
||||
}else {
|
||||
//Get the matches from the first argument passed
|
||||
List<Command> matches = getMatches(args[0]);
|
||||
|
||||
if(matches.size() == 0) {
|
||||
//No matches found, thus it is more likely than not they are trying to jail someone
|
||||
c = getMatches("jail").get(0);
|
||||
|
||||
} else if(matches.size() > 1) {
|
||||
//If there was found more than one match
|
||||
//then let's send the usage of each match to the sender
|
||||
for(Command cmd : matches)
|
||||
showUsage(sender, cmd);
|
||||
return true;
|
||||
|
||||
}else {
|
||||
//Only one match was found, so let's continue
|
||||
c = matches.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
|
||||
|
||||
// First, let's check if the sender has permission for the command.
|
||||
if(!i.permission().isEmpty()) {
|
||||
if(!sender.hasPermission(i.permission())) {
|
||||
jailmanager.getPlugin().debug("Sender has no permission.");
|
||||
sender.sendMessage(Lang.NOPERMISSION.get());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Next, let's check if we need a player and then if the sender is actually a player
|
||||
if(i.needsPlayer() && !(sender instanceof Player)) {
|
||||
jailmanager.getPlugin().debug("Sender is not a player.");
|
||||
sender.sendMessage(Lang.PLAYERCONTEXTREQUIRED.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Now, let's check the size of the arguments passed. If it is shorter than the minimum required args, let's show the usage.
|
||||
// The reason we are subtracting one is because the command is now `/jail <subcommand>` and the subcommand is viewed as an argument
|
||||
if(args.length - 1 < i.minimumArgs()) {
|
||||
jailmanager.getPlugin().debug("Sender didn't provide enough arguments.");
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Then, if the maximumArgs doesn't equal -1, we need to check if the size of the arguments passed is greater than the maximum args.
|
||||
// The reason we are subtracting one is because the command is now `/jail <subcommand>` and the subcommand is viewed as an argument
|
||||
if(i.maxArgs() != -1 && i.maxArgs() < args.length - 1) {
|
||||
jailmanager.getPlugin().debug("Sender provided too many arguments.");
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Since everything has been checked and we're all clear, let's execute it.
|
||||
// But if get back false, let's show the usage message.
|
||||
try {
|
||||
if(!c.execute(jailmanager, sender, args)) {
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if(jailmanager.getPlugin().inDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Command> getMatches(String command) {
|
||||
List<Command> result = new ArrayList<Command>();
|
||||
|
||||
for(Entry<String, Command> entry : commands.entrySet()) {
|
||||
if(command.matches(entry.getKey())) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the usage information to the sender, if they have permission.
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param command The command to send usage of.
|
||||
*/
|
||||
private void showUsage(CommandSender sender, Command command) {
|
||||
CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);
|
||||
if(!sender.hasPermission(info.permission())) return;
|
||||
|
||||
sender.sendMessage(info.usage());
|
||||
}
|
||||
|
||||
private void loadCommands() {
|
||||
load(JailCreateCellCommand.class);
|
||||
load(JailCheckCommand.class);
|
||||
load(JailClearCommand.class);
|
||||
load(JailCommand.class);
|
||||
load(JailConfirmCommand.class);
|
||||
load(JailCreateCommand.class);
|
||||
load(JailDeleteCellCommand.class);
|
||||
load(JailDeleteCellsCommand.class);
|
||||
load(JailDeleteCommand.class);
|
||||
load(JailListCellsCommand.class);
|
||||
load(JailListCommand.class);
|
||||
load(JailMuteCommand.class);
|
||||
load(JailPayCommand.class);
|
||||
load(JailRecordCommand.class);
|
||||
load(JailReloadCommand.class);
|
||||
load(JailStatusCommand.class);
|
||||
load(JailStickCommand.class);
|
||||
load(JailStopCommand.class);
|
||||
load(JailTeleInCommand.class);
|
||||
load(JailTeleOutCommand.class);
|
||||
load(JailTimeCommand.class);
|
||||
load(JailTransferAllCommand.class);
|
||||
load(JailTransferCommand.class);
|
||||
load(JailVersionCommand.class);
|
||||
}
|
||||
|
||||
private void load(Class<? extends Command> c) {
|
||||
CommandInfo info = c.getAnnotation(CommandInfo.class);
|
||||
if(info == null) return;
|
||||
|
||||
try {
|
||||
commands.put(info.pattern(), c.newInstance());
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private LinkedHashMap<String, Command> commands;
|
||||
|
||||
public JailHandler(JailMain plugin) {
|
||||
commands = new LinkedHashMap<String, Command>();
|
||||
loadCommands();
|
||||
|
||||
plugin.debug("Loaded " + commands.size() + " sub-commands of /jail.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given command and checks that the command is in valid form.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* It checks in the following order:
|
||||
* <ol>
|
||||
* <li>If they have permission for it, if they don't then we send them a message stating so.</li>
|
||||
* <li>If the command needs a player instance, if so we send a message stating that.</li>
|
||||
* <li>If the required minimum arguments have been passed, if not sends the usage.</li>
|
||||
* <li>If the required maximum arguments have been passed (if there is a max, -1 if no max), if not sends the usage.</li>
|
||||
* <li>Then executes, upon failed execution it sends the usage command.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param jailmanager The instance of {@link JailManager}.
|
||||
* @param sender The sender of the command.
|
||||
* @param args The arguments passed to the command.
|
||||
*/
|
||||
public boolean parseCommand(JailManager jailmanager, CommandSender sender, String[] args) {
|
||||
Command c = null;
|
||||
|
||||
//If they didn't provide any arguments (aka just: /jail) then we will need to send them some help
|
||||
if(args.length == 0) {
|
||||
//TODO: Create the help page(s)
|
||||
c = getMatches("jail").get(0);
|
||||
|
||||
}else {
|
||||
//Get the matches from the first argument passed
|
||||
List<Command> matches = getMatches(args[0]);
|
||||
|
||||
if(matches.size() == 0) {
|
||||
//No matches found, thus it is more likely than not they are trying to jail someone
|
||||
c = getMatches("jail").get(0);
|
||||
|
||||
} else if(matches.size() > 1) {
|
||||
//If there was found more than one match
|
||||
//then let's send the usage of each match to the sender
|
||||
for(Command cmd : matches)
|
||||
showUsage(sender, cmd);
|
||||
return true;
|
||||
|
||||
}else {
|
||||
//Only one match was found, so let's continue
|
||||
c = matches.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
|
||||
|
||||
// First, let's check if the sender has permission for the command.
|
||||
if(!i.permission().isEmpty()) {
|
||||
if(!sender.hasPermission(i.permission())) {
|
||||
jailmanager.getPlugin().debug("Sender has no permission.");
|
||||
sender.sendMessage(Lang.NOPERMISSION.get());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Next, let's check if we need a player and then if the sender is actually a player
|
||||
if(i.needsPlayer() && !(sender instanceof Player)) {
|
||||
jailmanager.getPlugin().debug("Sender is not a player.");
|
||||
sender.sendMessage(Lang.PLAYERCONTEXTREQUIRED.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Now, let's check the size of the arguments passed. If it is shorter than the minimum required args, let's show the usage.
|
||||
// The reason we are subtracting one is because the command is now `/jail <subcommand>` and the subcommand is viewed as an argument
|
||||
if(args.length - 1 < i.minimumArgs()) {
|
||||
jailmanager.getPlugin().debug("Sender didn't provide enough arguments.");
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Then, if the maximumArgs doesn't equal -1, we need to check if the size of the arguments passed is greater than the maximum args.
|
||||
// The reason we are subtracting one is because the command is now `/jail <subcommand>` and the subcommand is viewed as an argument
|
||||
if(i.maxArgs() != -1 && i.maxArgs() < args.length - 1) {
|
||||
jailmanager.getPlugin().debug("Sender provided too many arguments.");
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Since everything has been checked and we're all clear, let's execute it.
|
||||
// But if get back false, let's show the usage message.
|
||||
try {
|
||||
if(!c.execute(jailmanager, sender, args)) {
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if(jailmanager.getPlugin().inDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Command> getMatches(String command) {
|
||||
List<Command> result = new ArrayList<Command>();
|
||||
|
||||
for(Entry<String, Command> entry : commands.entrySet()) {
|
||||
if(command.matches(entry.getKey())) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the usage information to the sender, if they have permission.
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param command The command to send usage of.
|
||||
*/
|
||||
private void showUsage(CommandSender sender, Command command) {
|
||||
CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);
|
||||
if(!sender.hasPermission(info.permission())) return;
|
||||
|
||||
sender.sendMessage(info.usage());
|
||||
}
|
||||
|
||||
private void loadCommands() {
|
||||
load(JailCreateCellCommand.class);
|
||||
load(JailCheckCommand.class);
|
||||
load(JailClearCommand.class);
|
||||
load(JailCommand.class);
|
||||
load(JailConfirmCommand.class);
|
||||
load(JailCreateCommand.class);
|
||||
load(JailDeleteCellCommand.class);
|
||||
load(JailDeleteCellsCommand.class);
|
||||
load(JailDeleteCommand.class);
|
||||
load(JailListCellsCommand.class);
|
||||
load(JailListCommand.class);
|
||||
load(JailMuteCommand.class);
|
||||
load(JailPayCommand.class);
|
||||
load(JailRecordCommand.class);
|
||||
load(JailReloadCommand.class);
|
||||
load(JailStatusCommand.class);
|
||||
load(JailStickCommand.class);
|
||||
load(JailStopCommand.class);
|
||||
load(JailTeleInCommand.class);
|
||||
load(JailTeleOutCommand.class);
|
||||
load(JailTimeCommand.class);
|
||||
load(JailTransferAllCommand.class);
|
||||
load(JailTransferCommand.class);
|
||||
load(JailVersionCommand.class);
|
||||
}
|
||||
|
||||
private void load(Class<? extends Command> c) {
|
||||
CommandInfo info = c.getAnnotation(CommandInfo.class);
|
||||
if(info == null) return;
|
||||
|
||||
try {
|
||||
commands.put(info.pattern(), c.newInstance());
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,33 +9,33 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "handcuff|hc",
|
||||
permission = "jail.command.handcuff",
|
||||
usage = "/handcuff [player]"
|
||||
)
|
||||
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(Lang.PLAYERNOTONLINE.get());
|
||||
}else if(player.hasPermission("jail.cantbehandcuffed")) {
|
||||
sender.sendMessage(Lang.CANTBEHANDCUFFED.get(player.getName()));
|
||||
}else if(jm.isPlayerJailed(player.getUniqueId())) {
|
||||
sender.sendMessage(Lang.CURRENTLYJAILEDHANDCUFF.get(player.getName()));
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(Lang.HANDCUFFSRELEASED.get(player.getName()));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(Lang.UNHANDCUFFED.get());
|
||||
}else {
|
||||
jm.getPlugin().getHandCuffManager().addHandCuffs(player.getUniqueId(), player.getLocation());
|
||||
sender.sendMessage(Lang.HANDCUFFSON.get(player.getName()));
|
||||
player.sendMessage(Lang.HANDCUFFED.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = jm.getPlugin().getServer().getPlayer(args[0]);
|
||||
|
||||
if(player == null) {
|
||||
sender.sendMessage(Lang.PLAYERNOTONLINE.get());
|
||||
}else if(player.hasPermission("jail.cantbehandcuffed")) {
|
||||
sender.sendMessage(Lang.CANTBEHANDCUFFED.get(player.getName()));
|
||||
}else if(jm.isPlayerJailed(player.getUniqueId())) {
|
||||
sender.sendMessage(Lang.CURRENTLYJAILEDHANDCUFF.get(player.getName()));
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(Lang.HANDCUFFSRELEASED.get(player.getName()));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(Lang.UNHANDCUFFED.get());
|
||||
}else {
|
||||
jm.getPlugin().getHandCuffManager().addHandCuffs(player.getUniqueId(), player.getLocation());
|
||||
sender.sendMessage(Lang.HANDCUFFSON.get(player.getName()));
|
||||
player.sendMessage(Lang.HANDCUFFED.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -8,17 +8,17 @@ import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "togglejaildebug|tjd",
|
||||
permission = "jail.command.toggledebug",
|
||||
usage = "/togglejaildebug"
|
||||
)
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "togglejaildebug|tjd",
|
||||
permission = "jail.command.toggledebug",
|
||||
usage = "/togglejaildebug"
|
||||
)
|
||||
public class ToggleJailDebugCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
boolean debug = jm.getPlugin().setDebugging(!jm.getPlugin().inDebug());
|
||||
sender.sendMessage("Jail debugging is now: " + (debug ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled"));
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
boolean debug = jm.getPlugin().setDebugging(!jm.getPlugin().inDebug());
|
||||
sender.sendMessage("Jail debugging is now: " + (debug ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -9,27 +9,27 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unhandcuff|uhc",
|
||||
permission = "jail.command.handcuff",
|
||||
usage = "/unhandcuff [player]"
|
||||
)
|
||||
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(Lang.PLAYERNOTONLINE.get());
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(Lang.HANDCUFFSRELEASED.get(player.getName()));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(Lang.UNHANDCUFFED.get());
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOTHANDCUFFED.get(player.getName()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = jm.getPlugin().getServer().getPlayerExact(args[0]);
|
||||
|
||||
if(player == null) {
|
||||
sender.sendMessage(Lang.PLAYERNOTONLINE.get());
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(Lang.HANDCUFFSRELEASED.get(player.getName()));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(Lang.UNHANDCUFFED.get());
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOTHANDCUFFED.get(player.getName()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -13,51 +13,51 @@ import com.graywolf336.jail.enums.Lang;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unjail|uj",
|
||||
permission = "jail.command.unjail",
|
||||
usage = "/unjail [player]"
|
||||
)
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unjail|uj",
|
||||
permission = "jail.command.unjail",
|
||||
usage = "/unjail [player]"
|
||||
)
|
||||
public class UnJailCommand implements Command {
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Check if the player is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[0])) {
|
||||
Jail j = jm.getJailPlayerIsInByLastKnownName(args[0]);
|
||||
Prisoner pris = j.getPrisonerByLastKnownName(args[0]);
|
||||
Player p = jm.getPlugin().getServer().getPlayer(pris.getUUID());
|
||||
|
||||
//Check if the player is on the server or not
|
||||
if(p == null) {
|
||||
//Check if the player has offline pending and their remaining time is above 0, if so then
|
||||
//forceably unjail them
|
||||
if(pris.isOfflinePending() && pris.getRemainingTime() != 0L) {
|
||||
jm.getPlugin().getPrisonerManager().forceUnJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris, sender);
|
||||
}else {
|
||||
//The player is not, so we'll set the remaining time to zero and do it when they login next
|
||||
pris.setRemainingTime(0L);
|
||||
pris.setOfflinePending(true);
|
||||
sender.sendMessage(Lang.WILLBEUNJAILED.get(args[0]));
|
||||
}
|
||||
}else {
|
||||
//Player is online, so let's try unjailing them
|
||||
try {
|
||||
jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris, sender);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(Lang.BROADCASTUNJAILING.get(new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Check if the player is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[0])) {
|
||||
Jail j = jm.getJailPlayerIsInByLastKnownName(args[0]);
|
||||
Prisoner pris = j.getPrisonerByLastKnownName(args[0]);
|
||||
Player p = jm.getPlugin().getServer().getPlayer(pris.getUUID());
|
||||
|
||||
//Check if the player is on the server or not
|
||||
if(p == null) {
|
||||
//Check if the player has offline pending and their remaining time is above 0, if so then
|
||||
//forceably unjail them
|
||||
if(pris.isOfflinePending() && pris.getRemainingTime() != 0L) {
|
||||
jm.getPlugin().getPrisonerManager().forceUnJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris, sender);
|
||||
}else {
|
||||
//The player is not, so we'll set the remaining time to zero and do it when they login next
|
||||
pris.setRemainingTime(0L);
|
||||
pris.setOfflinePending(true);
|
||||
sender.sendMessage(Lang.WILLBEUNJAILED.get(args[0]));
|
||||
}
|
||||
}else {
|
||||
//Player is online, so let's try unjailing them
|
||||
try {
|
||||
jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris, sender);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(Lang.BROADCASTUNJAILING.get(new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -10,28 +10,28 @@ import com.graywolf336.jail.enums.Lang;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unjailforce|ujf",
|
||||
permission = "jail.command.unjailforce",
|
||||
usage = "/unjailforce [player]"
|
||||
)
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unjailforce|ujf",
|
||||
permission = "jail.command.unjailforce",
|
||||
usage = "/unjailforce [player]"
|
||||
)
|
||||
public class UnJailForceCommand implements Command {
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Check if the player is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[0])) {
|
||||
jm.getPlugin().getPrisonerManager().forceRelease(jm.getPrisonerByLastKnownName(args[0]), sender);
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(Lang.BROADCASTUNJAILING.get(new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Check if the player is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[0])) {
|
||||
jm.getPlugin().getPrisonerManager().forceRelease(jm.getPrisonerByLastKnownName(args[0]), sender);
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(Lang.BROADCASTUNJAILING.get(new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -5,32 +5,32 @@ import java.util.List;
|
||||
import com.lexicalscope.jewel.cli.Option;
|
||||
|
||||
public interface Jailing {
|
||||
|
||||
@Option(longName={"player", "pl"}, shortName="p", description = "the player's name")
|
||||
public String getPlayer();
|
||||
|
||||
@Option(longName={"time", "length"}, shortName="t", description = "the amount of time")
|
||||
public String getTime();
|
||||
|
||||
@Option(longName={"jail", "prison"}, shortName="j", description = "the jail")
|
||||
public String getJail();
|
||||
|
||||
@Option(longName={"cell"}, shortName="c", description = "the cell")
|
||||
public String getCell();
|
||||
|
||||
@Option(longName={"anycell"}, shortName="a", description = "decides whether the plugin will pick any open cell")
|
||||
public boolean getAnyCell();
|
||||
|
||||
@Option(longName={"muted", "canttalk"}, shortName="m", description = "whether the prisoner is muted or not")
|
||||
public boolean getMuted();
|
||||
|
||||
@Option(longName={"reason"}, shortName="r", description = "the reason this player is being jailed")
|
||||
public List<String> getReason();
|
||||
|
||||
public boolean isTime();
|
||||
public boolean isJail();
|
||||
public boolean isCell();
|
||||
public boolean isAnyCell();
|
||||
public boolean isMuted();
|
||||
public boolean isReason();
|
||||
|
||||
@Option(longName={"player", "pl"}, shortName="p", description = "the player's name")
|
||||
public String getPlayer();
|
||||
|
||||
@Option(longName={"time", "length"}, shortName="t", description = "the amount of time")
|
||||
public String getTime();
|
||||
|
||||
@Option(longName={"jail", "prison"}, shortName="j", description = "the jail")
|
||||
public String getJail();
|
||||
|
||||
@Option(longName={"cell"}, shortName="c", description = "the cell")
|
||||
public String getCell();
|
||||
|
||||
@Option(longName={"anycell"}, shortName="a", description = "decides whether the plugin will pick any open cell")
|
||||
public boolean getAnyCell();
|
||||
|
||||
@Option(longName={"muted", "canttalk"}, shortName="m", description = "whether the prisoner is muted or not")
|
||||
public boolean getMuted();
|
||||
|
||||
@Option(longName={"reason"}, shortName="r", description = "the reason this player is being jailed")
|
||||
public List<String> getReason();
|
||||
|
||||
public boolean isTime();
|
||||
public boolean isJail();
|
||||
public boolean isCell();
|
||||
public boolean isAnyCell();
|
||||
public boolean isMuted();
|
||||
public boolean isReason();
|
||||
}
|
||||
|
@ -3,17 +3,17 @@ package com.graywolf336.jail.command.commands.jewels;
|
||||
import com.lexicalscope.jewel.cli.Option;
|
||||
|
||||
public interface Transfer {
|
||||
|
||||
@Option(longName={"player", "pl"}, shortName="p", description = "the player's name")
|
||||
public String getPlayer();
|
||||
|
||||
@Option(longName={"jail", "prison"}, shortName="j", description = "the jail")
|
||||
public String getJail();
|
||||
|
||||
@Option(longName={"cell"}, shortName="c", description = "the cell")
|
||||
public String getCell();
|
||||
|
||||
public boolean isPlayer();
|
||||
public boolean isJail();
|
||||
public boolean isCell();
|
||||
|
||||
@Option(longName={"player", "pl"}, shortName="p", description = "the player's name")
|
||||
public String getPlayer();
|
||||
|
||||
@Option(longName={"jail", "prison"}, shortName="j", description = "the jail")
|
||||
public String getJail();
|
||||
|
||||
@Option(longName={"cell"}, shortName="c", description = "the cell")
|
||||
public String getCell();
|
||||
|
||||
public boolean isPlayer();
|
||||
public boolean isJail();
|
||||
public boolean isCell();
|
||||
}
|
||||
|
@ -10,29 +10,29 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "check",
|
||||
permission = "jail.command.jailcheck",
|
||||
usage = "/jail check [name]"
|
||||
)
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "check",
|
||||
permission = "jail.command.jailcheck",
|
||||
usage = "/jail check [name]"
|
||||
)
|
||||
public class JailCheckCommand implements Command{
|
||||
|
||||
// Checks the status of the specified prisoner
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Otherwise let's check the first argument
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[1])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[1]);
|
||||
|
||||
//graywolf663: Being gray's evil twin; CONSOLE (10)
|
||||
//prisoner: reason; jailer (time in minutes)
|
||||
sender.sendMessage(ChatColor.BLUE + " " + p.getLastKnownName() + ": " + p.getReason() + "; " + p.getJailer() + " (" + p.getRemainingTimeInMinutes() + " mins)");
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[1]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// Checks the status of the specified prisoner
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Otherwise let's check the first argument
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[1])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[1]);
|
||||
|
||||
//graywolf663: Being gray's evil twin; CONSOLE (10)
|
||||
//prisoner: reason; jailer (time in minutes)
|
||||
sender.sendMessage(ChatColor.BLUE + " " + p.getLastKnownName() + ": " + p.getReason() + "; " + p.getJailer() + " (" + p.getRemainingTimeInMinutes() + " mins)");
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[1]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,32 +10,32 @@ import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "clear|clearforce",
|
||||
permission = "jail.command.jailclear",
|
||||
usage = "/jail clear (-f) (jail)"
|
||||
)
|
||||
maxArgs = 2,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "clear|clearforce",
|
||||
permission = "jail.command.jailclear",
|
||||
usage = "/jail clear (-f) (jail)"
|
||||
)
|
||||
public class JailClearCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
boolean force = false;
|
||||
|
||||
//Check if we need to forcefully clear something
|
||||
for(String s : args)
|
||||
if(s.equalsIgnoreCase("-f") || s.equalsIgnoreCase("-force"))
|
||||
force = true;
|
||||
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(Lang.ALREADY.get());
|
||||
}else if(force && sender.hasPermission("jail.command.jailclearforce")) {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.CLEARFORCE));
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
boolean force = false;
|
||||
|
||||
//Check if we need to forcefully clear something
|
||||
for(String s : args)
|
||||
if(s.equalsIgnoreCase("-f") || s.equalsIgnoreCase("-force"))
|
||||
force = true;
|
||||
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(Lang.ALREADY.get());
|
||||
}else if(force && sender.hasPermission("jail.command.jailclearforce")) {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.CLEARFORCE));
|
||||
sender.sendMessage(Lang.START.get());
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.CLEAR));
|
||||
sender.sendMessage(Lang.START.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.CLEAR));
|
||||
sender.sendMessage(Lang.START.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -23,213 +23,213 @@ import com.lexicalscope.jewel.cli.ArgumentValidationException;
|
||||
import com.lexicalscope.jewel.cli.CliFactory;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = -1,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "jail|j",
|
||||
permission = "jail.command.jail",
|
||||
usage = "/jail [name] (-t time) (-j JailName) (-c CellName) (-a AnyCell) (-m Muted) (-r A reason for jailing)"
|
||||
)
|
||||
maxArgs = -1,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "jail|j",
|
||||
permission = "jail.command.jail",
|
||||
usage = "/jail [name] (-t time) (-j JailName) (-c CellName) (-a AnyCell) (-m Muted) (-r A reason for jailing)"
|
||||
)
|
||||
public class JailCommand implements Command {
|
||||
|
||||
/*
|
||||
* Executes the command. Checks the following:
|
||||
*
|
||||
* - If there are any jails.
|
||||
* - If the command can be parsed correctly.
|
||||
* - If the player is already jailed.
|
||||
* - If the given time can be parsed correctly, defaults to what is defined in the config
|
||||
* - If the jail is reasonable or not, else sets the one from the config
|
||||
* - If the cell is not empty then checks to be sure that cell exists
|
||||
* - If the prisoner is online or not.
|
||||
*/
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(Lang.NOJAILS.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
//This is just to add the -p param so CliFactory doesn't blow up
|
||||
List<String> arguments = new LinkedList<String>(Arrays.asList(args));
|
||||
//Only add the "-p" if it doesn't already contain it, this way people can do `/jail -p check` in the event someone
|
||||
//has a name which is one of our subcommands
|
||||
if(!arguments.contains("-p")) arguments.add(0, "-p");
|
||||
|
||||
Jailing params = null;
|
||||
|
||||
try {
|
||||
params = CliFactory.parseArguments(Jailing.class, arguments.toArray(new String[arguments.size()]));
|
||||
}catch(ArgumentValidationException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check if they've actually given us a player to jail
|
||||
if(params.getPlayer() == null) {
|
||||
sender.sendMessage(Lang.PROVIDEAPLAYER.get(Lang.JAILING));
|
||||
return true;
|
||||
}else {
|
||||
jm.getPlugin().debug("We are getting ready to handle jailing: " + params.getPlayer());
|
||||
}
|
||||
|
||||
//Check if the given player is already jailed or not
|
||||
if(jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) {
|
||||
sender.sendMessage(Lang.ALREADYJAILED.get(params.getPlayer()));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Try to parse the time, if they give us nothing in the time parameter then we get the default time
|
||||
//from the config and if that isn't there then we default to thirty minutes.
|
||||
Long time = 10L;
|
||||
try {
|
||||
if(!params.isTime()) {
|
||||
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.DEFAULTTIME.getPath(), "30m"));
|
||||
}else if(params.getTime() == String.valueOf(-1)) {
|
||||
time = -1L;
|
||||
}else {
|
||||
time = Util.getTime(params.getTime());
|
||||
}
|
||||
}catch(Exception e) {
|
||||
sender.sendMessage(Lang.NUMBERFORMATINCORRECT.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check the jail params. If it is empty, let's get the default jail
|
||||
//from the config. If that is nearest, let's make a call to getting the nearest jail to
|
||||
//the sender but otherwise if it isn't nearest then let's set it to the default jail
|
||||
//which is defined in the config.
|
||||
String jailName = "";
|
||||
if(!params.isJail()) {
|
||||
String dJail = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
|
||||
|
||||
if(dJail.equalsIgnoreCase("nearest")) {
|
||||
jailName = jm.getNearestJail(sender).getName();
|
||||
}else {
|
||||
jailName = dJail;
|
||||
}
|
||||
}else if(!jm.isValidJail(params.getJail())) {
|
||||
sender.sendMessage(Lang.NOJAIL.get(params.getJail()));
|
||||
return true;
|
||||
}else {
|
||||
jailName = params.getJail();
|
||||
}
|
||||
|
||||
//Get the jail instance from the name of jail in the params.
|
||||
|
||||
/*
|
||||
* Executes the command. Checks the following:
|
||||
*
|
||||
* - If there are any jails.
|
||||
* - If the command can be parsed correctly.
|
||||
* - If the player is already jailed.
|
||||
* - If the given time can be parsed correctly, defaults to what is defined in the config
|
||||
* - If the jail is reasonable or not, else sets the one from the config
|
||||
* - If the cell is not empty then checks to be sure that cell exists
|
||||
* - If the prisoner is online or not.
|
||||
*/
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(Lang.NOJAILS.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
//This is just to add the -p param so CliFactory doesn't blow up
|
||||
List<String> arguments = new LinkedList<String>(Arrays.asList(args));
|
||||
//Only add the "-p" if it doesn't already contain it, this way people can do `/jail -p check` in the event someone
|
||||
//has a name which is one of our subcommands
|
||||
if(!arguments.contains("-p")) arguments.add(0, "-p");
|
||||
|
||||
Jailing params = null;
|
||||
|
||||
try {
|
||||
params = CliFactory.parseArguments(Jailing.class, arguments.toArray(new String[arguments.size()]));
|
||||
}catch(ArgumentValidationException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check if they've actually given us a player to jail
|
||||
if(params.getPlayer() == null) {
|
||||
sender.sendMessage(Lang.PROVIDEAPLAYER.get(Lang.JAILING));
|
||||
return true;
|
||||
}else {
|
||||
jm.getPlugin().debug("We are getting ready to handle jailing: " + params.getPlayer());
|
||||
}
|
||||
|
||||
//Check if the given player is already jailed or not
|
||||
if(jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) {
|
||||
sender.sendMessage(Lang.ALREADYJAILED.get(params.getPlayer()));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Try to parse the time, if they give us nothing in the time parameter then we get the default time
|
||||
//from the config and if that isn't there then we default to thirty minutes.
|
||||
Long time = 10L;
|
||||
try {
|
||||
if(!params.isTime()) {
|
||||
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.DEFAULTTIME.getPath(), "30m"));
|
||||
}else if(params.getTime() == String.valueOf(-1)) {
|
||||
time = -1L;
|
||||
}else {
|
||||
time = Util.getTime(params.getTime());
|
||||
}
|
||||
}catch(Exception e) {
|
||||
sender.sendMessage(Lang.NUMBERFORMATINCORRECT.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check the jail params. If it is empty, let's get the default jail
|
||||
//from the config. If that is nearest, let's make a call to getting the nearest jail to
|
||||
//the sender but otherwise if it isn't nearest then let's set it to the default jail
|
||||
//which is defined in the config.
|
||||
String jailName = "";
|
||||
if(!params.isJail()) {
|
||||
String dJail = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
|
||||
|
||||
if(dJail.equalsIgnoreCase("nearest")) {
|
||||
jailName = jm.getNearestJail(sender).getName();
|
||||
}else {
|
||||
jailName = dJail;
|
||||
}
|
||||
}else if(!jm.isValidJail(params.getJail())) {
|
||||
sender.sendMessage(Lang.NOJAIL.get(params.getJail()));
|
||||
return true;
|
||||
}else {
|
||||
jailName = params.getJail();
|
||||
}
|
||||
|
||||
//Get the jail instance from the name of jail in the params.
|
||||
Jail j = jm.getJail(jailName);
|
||||
if(!j.isEnabled()) {
|
||||
sender.sendMessage(Lang.WORLDUNLOADED.get(j.getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
Cell c = null;
|
||||
//Check if the cell is defined
|
||||
if(params.isCell()) {
|
||||
//Check if it is a valid cell
|
||||
if(!jm.getJail(jailName).isValidCell(params.getCell())) {
|
||||
//There is no cell by that name
|
||||
sender.sendMessage(Lang.NOCELL.get(new String[] { params.getCell(), jailName }));
|
||||
return true;
|
||||
}else if(jm.getJail(jailName).getCell(params.getCell()).hasPrisoner()) {
|
||||
//If the cell has a prisoner, don't allow jailing them to that particular cell but suggest another one
|
||||
sender.sendMessage(Lang.CELLNOTEMPTY.get(params.getCell()));
|
||||
Cell suggestedCell = jm.getJail(jailName).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(Lang.SUGGESTEDCELL.get(new String[] { jailName, suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOEMPTYCELLS.get(jailName));
|
||||
}
|
||||
|
||||
return true;
|
||||
}else {
|
||||
c = jm.getJail(jailName).getCell(params.getCell());
|
||||
}
|
||||
}
|
||||
|
||||
//If they want just any open cell, then let's find the first empty one
|
||||
if(params.isAnyCell()) {
|
||||
c = jm.getJail(jailName).getFirstEmptyCell();
|
||||
if(c == null) {
|
||||
//If there wasn't an empty cell, then tell them so.
|
||||
sender.sendMessage(Lang.NOEMPTYCELLS.get(jailName));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//If the jailer gave no reason, then let's get the default reason
|
||||
String reason = "";
|
||||
if(!params.isReason()) {
|
||||
reason = Lang.DEFAULTJAILEDREASON.get();
|
||||
}else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(String s : params.getReason()) {
|
||||
sb.append(s).append(' ');
|
||||
}
|
||||
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
reason = sb.toString();
|
||||
}
|
||||
|
||||
//If the config has automatic muting, then let's set them as muted
|
||||
boolean muted = params.getMuted();
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath())) {
|
||||
muted = true;
|
||||
}
|
||||
|
||||
Player p = jm.getPlugin().getServer().getPlayer(params.getPlayer());
|
||||
|
||||
//If the player instance is not null and the player has the permission
|
||||
//'jail.cantbejailed' then don't allow this to happen
|
||||
if(p != null && p.hasPermission("jail.cantbejailed")) {
|
||||
sender.sendMessage(Lang.CANTBEJAILED.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
String uuid = "";
|
||||
if(p == null) {
|
||||
//TODO: Make this whole jail command non-blocking
|
||||
uuid = jm.getPlugin().getServer().getOfflinePlayer(params.getPlayer()).getUniqueId().toString();
|
||||
}else {
|
||||
uuid = p.getUniqueId().toString();
|
||||
}
|
||||
|
||||
Prisoner pris = new Prisoner(uuid, params.getPlayer(), muted, time, sender.getName(), reason);
|
||||
|
||||
//call the event
|
||||
PrePrisonerJailedEvent event = new PrePrisonerJailedEvent(j, c, pris, p, p == null, pris.getJailer());
|
||||
jm.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
//check if the event is cancelled
|
||||
if(event.isCancelled()) {
|
||||
if(event.getCancelledMessage().isEmpty())
|
||||
sender.sendMessage(Lang.CANCELLEDBYANOTHERPLUGIN.get(params.getPlayer()));
|
||||
else
|
||||
sender.sendMessage(event.getCancelledMessage());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//recall data from the event
|
||||
j = event.getJail();
|
||||
c = event.getCell();
|
||||
pris = event.getPrisoner();
|
||||
p = event.getPlayer();
|
||||
|
||||
//Player is not online
|
||||
if(p == null) {
|
||||
sender.sendMessage(Lang.OFFLINEJAIL.get(new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
//Player *is* online
|
||||
sender.sendMessage(Lang.ONLINEJAIL.get(new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
|
||||
}
|
||||
|
||||
try {
|
||||
jm.getPlugin().getPrisonerManager().prepareJail(j, c, p, pris);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Cell c = null;
|
||||
//Check if the cell is defined
|
||||
if(params.isCell()) {
|
||||
//Check if it is a valid cell
|
||||
if(!jm.getJail(jailName).isValidCell(params.getCell())) {
|
||||
//There is no cell by that name
|
||||
sender.sendMessage(Lang.NOCELL.get(new String[] { params.getCell(), jailName }));
|
||||
return true;
|
||||
}else if(jm.getJail(jailName).getCell(params.getCell()).hasPrisoner()) {
|
||||
//If the cell has a prisoner, don't allow jailing them to that particular cell but suggest another one
|
||||
sender.sendMessage(Lang.CELLNOTEMPTY.get(params.getCell()));
|
||||
Cell suggestedCell = jm.getJail(jailName).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(Lang.SUGGESTEDCELL.get(new String[] { jailName, suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOEMPTYCELLS.get(jailName));
|
||||
}
|
||||
|
||||
return true;
|
||||
}else {
|
||||
c = jm.getJail(jailName).getCell(params.getCell());
|
||||
}
|
||||
}
|
||||
|
||||
//If they want just any open cell, then let's find the first empty one
|
||||
if(params.isAnyCell()) {
|
||||
c = jm.getJail(jailName).getFirstEmptyCell();
|
||||
if(c == null) {
|
||||
//If there wasn't an empty cell, then tell them so.
|
||||
sender.sendMessage(Lang.NOEMPTYCELLS.get(jailName));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//If the jailer gave no reason, then let's get the default reason
|
||||
String reason = "";
|
||||
if(!params.isReason()) {
|
||||
reason = Lang.DEFAULTJAILEDREASON.get();
|
||||
}else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(String s : params.getReason()) {
|
||||
sb.append(s).append(' ');
|
||||
}
|
||||
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
reason = sb.toString();
|
||||
}
|
||||
|
||||
//If the config has automatic muting, then let's set them as muted
|
||||
boolean muted = params.getMuted();
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath())) {
|
||||
muted = true;
|
||||
}
|
||||
|
||||
Player p = jm.getPlugin().getServer().getPlayer(params.getPlayer());
|
||||
|
||||
//If the player instance is not null and the player has the permission
|
||||
//'jail.cantbejailed' then don't allow this to happen
|
||||
if(p != null && p.hasPermission("jail.cantbejailed")) {
|
||||
sender.sendMessage(Lang.CANTBEJAILED.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
String uuid = "";
|
||||
if(p == null) {
|
||||
//TODO: Make this whole jail command non-blocking
|
||||
uuid = jm.getPlugin().getServer().getOfflinePlayer(params.getPlayer()).getUniqueId().toString();
|
||||
}else {
|
||||
uuid = p.getUniqueId().toString();
|
||||
}
|
||||
|
||||
Prisoner pris = new Prisoner(uuid, params.getPlayer(), muted, time, sender.getName(), reason);
|
||||
|
||||
//call the event
|
||||
PrePrisonerJailedEvent event = new PrePrisonerJailedEvent(j, c, pris, p, p == null, pris.getJailer());
|
||||
jm.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
//check if the event is cancelled
|
||||
if(event.isCancelled()) {
|
||||
if(event.getCancelledMessage().isEmpty())
|
||||
sender.sendMessage(Lang.CANCELLEDBYANOTHERPLUGIN.get(params.getPlayer()));
|
||||
else
|
||||
sender.sendMessage(event.getCancelledMessage());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//recall data from the event
|
||||
j = event.getJail();
|
||||
c = event.getCell();
|
||||
pris = event.getPrisoner();
|
||||
p = event.getPlayer();
|
||||
|
||||
//Player is not online
|
||||
if(p == null) {
|
||||
sender.sendMessage(Lang.OFFLINEJAIL.get(new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
//Player *is* online
|
||||
sender.sendMessage(Lang.ONLINEJAIL.get(new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
|
||||
}
|
||||
|
||||
try {
|
||||
jm.getPlugin().getPrisonerManager().prepareJail(j, c, p, pris);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -8,84 +8,84 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "confirm|con",
|
||||
permission = "",
|
||||
usage = "/jail confirm"
|
||||
)
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "confirm|con",
|
||||
permission = "",
|
||||
usage = "/jail confirm"
|
||||
)
|
||||
public class JailConfirmCommand implements Command{
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Check if the sender is actually confirming something.
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
if(jm.confirmingHasExpired(sender.getName())) {
|
||||
//Their confirmation time frame has closed
|
||||
sender.sendMessage(Lang.EXPIRED.get());
|
||||
}else {
|
||||
switch(jm.getWhatIsConfirming(sender.getName())) {
|
||||
case CLEAR:
|
||||
//Copy the original arguments for easy access
|
||||
String[] cArgs = jm.getOriginalArgs(sender.getName());
|
||||
//Clear a jail if the args length is two, else send null
|
||||
String msg = jm.clearJailOfPrisoners(cArgs.length == 2 ? cArgs[1] : null);
|
||||
//Send the message we got back
|
||||
sender.sendMessage(msg);
|
||||
//Remove them from confirming so they can't do it again
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
case CLEARFORCE:
|
||||
//Copy the original arguments for easy access
|
||||
String[] cArgs2 = jm.getOriginalArgs(sender.getName());
|
||||
//Forcefully clear a jail if the args length is two, else send null to clear all
|
||||
String msg2 = jm.forcefullyClearJailOrJails(cArgs2.length == 2 ? cArgs2[1] : null);
|
||||
//Send the message we got back
|
||||
sender.sendMessage(msg2);
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
case DELETECELL:
|
||||
//Copy the original arguments for easy access
|
||||
String[] cArgs3 = jm.getOriginalArgs(sender.getName());
|
||||
//delete a cell from a jail with the given arguments
|
||||
String msg3 = jm.deleteJailCell(cArgs3[1], cArgs3[2]);
|
||||
//Send the message we got back
|
||||
sender.sendMessage(msg3);
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
case DELETECELLS:
|
||||
//Copy the original arguments for easy access
|
||||
String[] cArgs4 = jm.getOriginalArgs(sender.getName());
|
||||
//delete a cell from a jail with the given arguments
|
||||
String[] msgs4 = jm.deleteAllJailCells(cArgs4[1]);
|
||||
//Send the messages we got back
|
||||
for(String s : msgs4) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
case DELETE:
|
||||
//Copy the original arguments for easy access
|
||||
String[] cArgs5 = jm.getOriginalArgs(sender.getName());
|
||||
//delete a cell from a jail with the given arguments
|
||||
String msg5 = jm.deleteJail(cArgs5[1]);
|
||||
//Send the message we got back
|
||||
sender.sendMessage(msg5);
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(Lang.NOTHING.get());
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//They aren't confirming anything right now.
|
||||
sender.sendMessage(Lang.NOTHING.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Check if the sender is actually confirming something.
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
if(jm.confirmingHasExpired(sender.getName())) {
|
||||
//Their confirmation time frame has closed
|
||||
sender.sendMessage(Lang.EXPIRED.get());
|
||||
}else {
|
||||
switch(jm.getWhatIsConfirming(sender.getName())) {
|
||||
case CLEAR:
|
||||
//Copy the original arguments for easy access
|
||||
String[] cArgs = jm.getOriginalArgs(sender.getName());
|
||||
//Clear a jail if the args length is two, else send null
|
||||
String msg = jm.clearJailOfPrisoners(cArgs.length == 2 ? cArgs[1] : null);
|
||||
//Send the message we got back
|
||||
sender.sendMessage(msg);
|
||||
//Remove them from confirming so they can't do it again
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
case CLEARFORCE:
|
||||
//Copy the original arguments for easy access
|
||||
String[] cArgs2 = jm.getOriginalArgs(sender.getName());
|
||||
//Forcefully clear a jail if the args length is two, else send null to clear all
|
||||
String msg2 = jm.forcefullyClearJailOrJails(cArgs2.length == 2 ? cArgs2[1] : null);
|
||||
//Send the message we got back
|
||||
sender.sendMessage(msg2);
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
case DELETECELL:
|
||||
//Copy the original arguments for easy access
|
||||
String[] cArgs3 = jm.getOriginalArgs(sender.getName());
|
||||
//delete a cell from a jail with the given arguments
|
||||
String msg3 = jm.deleteJailCell(cArgs3[1], cArgs3[2]);
|
||||
//Send the message we got back
|
||||
sender.sendMessage(msg3);
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
case DELETECELLS:
|
||||
//Copy the original arguments for easy access
|
||||
String[] cArgs4 = jm.getOriginalArgs(sender.getName());
|
||||
//delete a cell from a jail with the given arguments
|
||||
String[] msgs4 = jm.deleteAllJailCells(cArgs4[1]);
|
||||
//Send the messages we got back
|
||||
for(String s : msgs4) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
case DELETE:
|
||||
//Copy the original arguments for easy access
|
||||
String[] cArgs5 = jm.getOriginalArgs(sender.getName());
|
||||
//delete a cell from a jail with the given arguments
|
||||
String msg5 = jm.deleteJail(cArgs5[1]);
|
||||
//Send the message we got back
|
||||
sender.sendMessage(msg5);
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(Lang.NOTHING.get());
|
||||
jm.removeConfirming(sender.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//They aren't confirming anything right now.
|
||||
sender.sendMessage(Lang.NOTHING.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,57 +10,57 @@ import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = true,
|
||||
pattern = "createcell|createcells|cellcreate|cellscreate|cc",
|
||||
permission = "jail.command.jailcreatecells",
|
||||
usage = "/jail createcell [jail] (cellname)"
|
||||
)
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = true,
|
||||
pattern = "createcell|createcells|cellcreate|cellscreate|cc",
|
||||
permission = "jail.command.jailcreatecells",
|
||||
usage = "/jail createcell [jail] (cellname)"
|
||||
)
|
||||
public class JailCreateCellCommand implements Command {
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
String name = player.getName();
|
||||
String jail = args[1].toLowerCase();
|
||||
String cell = "";
|
||||
|
||||
//Only get the cell name they provide if they provide it
|
||||
if(args.length >= 3) {
|
||||
cell = args[2];
|
||||
}
|
||||
|
||||
//Check if the player is currently creating something else
|
||||
if(jm.isCreatingSomething(name)) {
|
||||
String message = jm.getStepMessage(name);
|
||||
if(!message.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + message);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "You're already creating something else, please finish it or cancel.");
|
||||
}
|
||||
}else {
|
||||
//Not creating anything, so let them create some cells.
|
||||
if(jm.isValidJail(jail)) {
|
||||
Jail j = jm.getJail(jail);
|
||||
|
||||
//If they didn't provide a cell name, let's provide one ourself.
|
||||
if(cell.isEmpty()) cell = "cell_n" + (j.getCellCount() + 1);
|
||||
|
||||
if(j.getCell(cell) == null) {
|
||||
if(jm.addCreatingCell(name, jail, cell)) {
|
||||
jm.getCellCreationSteps().startStepping(player);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "Appears you're creating a cell or something went wrong on our side.");
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "There's already a cell with the name '" + cell + "', please pick a new one or remove that cell.");
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "No such jail found by the name of '" + jail + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
String name = player.getName();
|
||||
String jail = args[1].toLowerCase();
|
||||
String cell = "";
|
||||
|
||||
//Only get the cell name they provide if they provide it
|
||||
if(args.length >= 3) {
|
||||
cell = args[2];
|
||||
}
|
||||
|
||||
//Check if the player is currently creating something else
|
||||
if(jm.isCreatingSomething(name)) {
|
||||
String message = jm.getStepMessage(name);
|
||||
if(!message.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + message);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "You're already creating something else, please finish it or cancel.");
|
||||
}
|
||||
}else {
|
||||
//Not creating anything, so let them create some cells.
|
||||
if(jm.isValidJail(jail)) {
|
||||
Jail j = jm.getJail(jail);
|
||||
|
||||
//If they didn't provide a cell name, let's provide one ourself.
|
||||
if(cell.isEmpty()) cell = "cell_n" + (j.getCellCount() + 1);
|
||||
|
||||
if(j.getCell(cell) == null) {
|
||||
if(jm.addCreatingCell(name, jail, cell)) {
|
||||
jm.getCellCreationSteps().startStepping(player);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "Appears you're creating a cell or something went wrong on our side.");
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "There's already a cell with the name '" + cell + "', please pick a new one or remove that cell.");
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "No such jail found by the name of '" + jail + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,40 +9,40 @@ import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = true,
|
||||
pattern = "create",
|
||||
permission = "jail.command.jailcreate",
|
||||
usage = "/jail create [name]"
|
||||
)
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = true,
|
||||
pattern = "create",
|
||||
permission = "jail.command.jailcreate",
|
||||
usage = "/jail create [name]"
|
||||
)
|
||||
public class JailCreateCommand implements Command {
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
String name = player.getName();
|
||||
String jail = args[1];
|
||||
|
||||
//Check if the player is currently creating something else
|
||||
if(jm.isCreatingSomething(name)) {
|
||||
String message = jm.getStepMessage(name);
|
||||
if(!message.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + message);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "You're already creating something else, please finish it or cancel.");
|
||||
}
|
||||
}else {
|
||||
if(jm.isValidJail(jail)) {
|
||||
player.sendMessage(ChatColor.RED + "Jail by the name of '" + jail + "' already exist!");
|
||||
}else {
|
||||
if(jm.addCreatingJail(name, jail)) {
|
||||
jm.getJailCreationSteps().startStepping(player);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "Seems like you're already creating a Jail or something went wrong on our side.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
String name = player.getName();
|
||||
String jail = args[1];
|
||||
|
||||
//Check if the player is currently creating something else
|
||||
if(jm.isCreatingSomething(name)) {
|
||||
String message = jm.getStepMessage(name);
|
||||
if(!message.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + message);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "You're already creating something else, please finish it or cancel.");
|
||||
}
|
||||
}else {
|
||||
if(jm.isValidJail(jail)) {
|
||||
player.sendMessage(ChatColor.RED + "Jail by the name of '" + jail + "' already exist!");
|
||||
}else {
|
||||
if(jm.addCreatingJail(name, jail)) {
|
||||
jm.getJailCreationSteps().startStepping(player);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "Seems like you're already creating a Jail or something went wrong on our side.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -10,22 +10,22 @@ import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "deletecell|dc",
|
||||
permission = "jail.command.jaildeletecell",
|
||||
usage = "/jail deletecell [jail] [cell]"
|
||||
)
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "deletecell|dc",
|
||||
permission = "jail.command.jaildeletecell",
|
||||
usage = "/jail deletecell [jail] [cell]"
|
||||
)
|
||||
public class JailDeleteCellCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(Lang.ALREADY.get());
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELL));
|
||||
sender.sendMessage(Lang.START.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(Lang.ALREADY.get());
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELL));
|
||||
sender.sendMessage(Lang.START.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -10,22 +10,22 @@ import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "deletecells|dcs",
|
||||
permission = "jail.command.jaildeletecell",
|
||||
usage = "/jail deletecells [jail]"
|
||||
)
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "deletecells|dcs",
|
||||
permission = "jail.command.jaildeletecell",
|
||||
usage = "/jail deletecells [jail]"
|
||||
)
|
||||
public class JailDeleteCellsCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(Lang.ALREADY.get());
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELLS));
|
||||
sender.sendMessage(Lang.START.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(Lang.ALREADY.get());
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELLS));
|
||||
sender.sendMessage(Lang.START.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -10,22 +10,22 @@ import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "delete|d",
|
||||
permission = "jail.command.jaildelete",
|
||||
usage = "/jail delete [jail]"
|
||||
)
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "delete|d",
|
||||
permission = "jail.command.jaildelete",
|
||||
usage = "/jail delete [jail]"
|
||||
)
|
||||
public class JailDeleteCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(Lang.ALREADY.get());
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETE));
|
||||
sender.sendMessage(Lang.START.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(Lang.ALREADY.get());
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETE));
|
||||
sender.sendMessage(Lang.START.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -11,44 +11,44 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "listcells|lc",
|
||||
permission = "jail.command.jaillistcell",
|
||||
usage = "/jail listcells [jail]"
|
||||
)
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "listcells|lc",
|
||||
permission = "jail.command.jaillistcell",
|
||||
usage = "/jail listcells [jail]"
|
||||
)
|
||||
public class JailListCellsCommand implements Command {
|
||||
@Override
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
sender.sendMessage(ChatColor.AQUA + "----------Cells----------");
|
||||
|
||||
if(!jm.getJails().isEmpty()) {
|
||||
if(jm.getJail(args[1]) != null) {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
String message = "";
|
||||
for(Cell c : j.getCells()) {
|
||||
if(message.isEmpty()) {
|
||||
message = c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getLastKnownName() + ")");
|
||||
}else {
|
||||
message += ", " + c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getLastKnownName() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
if(message.isEmpty()) {
|
||||
sender.sendMessage(Lang.NOCELLS.get(j.getName()));
|
||||
}else {
|
||||
sender.sendMessage(ChatColor.GREEN + message);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOJAIL.get(args[1]));
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOJAILS.get());
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "-------------------------");
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
sender.sendMessage(ChatColor.AQUA + "----------Cells----------");
|
||||
|
||||
if(!jm.getJails().isEmpty()) {
|
||||
if(jm.getJail(args[1]) != null) {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
String message = "";
|
||||
for(Cell c : j.getCells()) {
|
||||
if(message.isEmpty()) {
|
||||
message = c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getLastKnownName() + ")");
|
||||
}else {
|
||||
message += ", " + c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getLastKnownName() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
if(message.isEmpty()) {
|
||||
sender.sendMessage(Lang.NOCELLS.get(j.getName()));
|
||||
}else {
|
||||
sender.sendMessage(ChatColor.GREEN + message);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOJAIL.get(args[1]));
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOJAILS.get());
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "-------------------------");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -13,52 +13,52 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "list|l",
|
||||
permission = "jail.command.jaillist",
|
||||
usage = "/jail list (jail)"
|
||||
)
|
||||
maxArgs = 1,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "list|l",
|
||||
permission = "jail.command.jaillist",
|
||||
usage = "/jail list (jail)"
|
||||
)
|
||||
public class JailListCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
sender.sendMessage(ChatColor.AQUA + "----------" + (args.length == 1 ? "Jails" : "Prisoners") + "----------");
|
||||
|
||||
//Check if there are any jails
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(" " + Lang.NOJAILS.get());
|
||||
}else {
|
||||
//Check if they have provided a jail to list or not
|
||||
if(args.length == 1) {
|
||||
//No jail provided, so give them a list of the jails
|
||||
for(Jail j : jm.getJails()) {
|
||||
if(j.isEnabled()) sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")");
|
||||
else sender.sendMessage(ChatColor.RED + " " + j.getName() + " (" + j.getAllPrisoners().size() + ") - WORLD UNLOADED");
|
||||
}
|
||||
}else {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
if(j == null) {
|
||||
//No jail was found
|
||||
sender.sendMessage(" " + Lang.NOJAIL.get(args[1]));
|
||||
}else {
|
||||
Collection<Prisoner> pris = j.getAllPrisoners().values();
|
||||
|
||||
if(pris.isEmpty()) {
|
||||
//If there are no prisoners, then send that message
|
||||
sender.sendMessage(" " + Lang.NOPRISONERS.get(j.getName()));
|
||||
}else {
|
||||
for(Prisoner p : pris) {
|
||||
//graywolf663: Being gray's evil twin; CONSOLE (10)
|
||||
//prisoner: reason; jailer (time in minutes)
|
||||
sender.sendMessage(ChatColor.BLUE + " " + p.getLastKnownName() + ": " + p.getReason() + "; " + p.getJailer() + " (" + p.getRemainingTimeInMinutes() + " mins)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "-------------------------");
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
sender.sendMessage(ChatColor.AQUA + "----------" + (args.length == 1 ? "Jails" : "Prisoners") + "----------");
|
||||
|
||||
//Check if there are any jails
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(" " + Lang.NOJAILS.get());
|
||||
}else {
|
||||
//Check if they have provided a jail to list or not
|
||||
if(args.length == 1) {
|
||||
//No jail provided, so give them a list of the jails
|
||||
for(Jail j : jm.getJails()) {
|
||||
if(j.isEnabled()) sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")");
|
||||
else sender.sendMessage(ChatColor.RED + " " + j.getName() + " (" + j.getAllPrisoners().size() + ") - WORLD UNLOADED");
|
||||
}
|
||||
}else {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
if(j == null) {
|
||||
//No jail was found
|
||||
sender.sendMessage(" " + Lang.NOJAIL.get(args[1]));
|
||||
}else {
|
||||
Collection<Prisoner> pris = j.getAllPrisoners().values();
|
||||
|
||||
if(pris.isEmpty()) {
|
||||
//If there are no prisoners, then send that message
|
||||
sender.sendMessage(" " + Lang.NOPRISONERS.get(j.getName()));
|
||||
}else {
|
||||
for(Prisoner p : pris) {
|
||||
//graywolf663: Being gray's evil twin; CONSOLE (10)
|
||||
//prisoner: reason; jailer (time in minutes)
|
||||
sender.sendMessage(ChatColor.BLUE + " " + p.getLastKnownName() + ": " + p.getReason() + "; " + p.getJailer() + " (" + p.getRemainingTimeInMinutes() + " mins)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "-------------------------");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -8,31 +8,31 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "mute|m",
|
||||
permission = "jail.command.jailmute",
|
||||
usage = "/jail mute [name]"
|
||||
)
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "mute|m",
|
||||
permission = "jail.command.jailmute",
|
||||
usage = "/jail mute [name]"
|
||||
)
|
||||
public class JailMuteCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
//Let's check if the player they're sending us is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[1])) {
|
||||
//They are, so let's toggle whether they are muted or not
|
||||
boolean muted = !jm.getPrisonerByLastKnownName(args[1]).isMuted();
|
||||
jm.getPrisonerByLastKnownName(args[1]).setMuted(muted);
|
||||
|
||||
//Send the message to the sender based upon whether they are muted or unmuted
|
||||
if(muted)
|
||||
sender.sendMessage(Lang.NOWMUTED.get(args[1]));
|
||||
else
|
||||
sender.sendMessage(Lang.NOWUNMUTED.get(args[1]));
|
||||
}else {
|
||||
//The player provided is not jailed, so let's tell the sender that
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[1]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
//Let's check if the player they're sending us is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[1])) {
|
||||
//They are, so let's toggle whether they are muted or not
|
||||
boolean muted = !jm.getPrisonerByLastKnownName(args[1]).isMuted();
|
||||
jm.getPrisonerByLastKnownName(args[1]).setMuted(muted);
|
||||
|
||||
//Send the message to the sender based upon whether they are muted or unmuted
|
||||
if(muted)
|
||||
sender.sendMessage(Lang.NOWMUTED.get(args[1]));
|
||||
else
|
||||
sender.sendMessage(Lang.NOWUNMUTED.get(args[1]));
|
||||
}else {
|
||||
//The player provided is not jailed, so let's tell the sender that
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[1]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -15,195 +15,195 @@ import com.graywolf336.jail.enums.Lang;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "pay",
|
||||
permission = "jail.usercmd.jailpay",
|
||||
usage = "/jail pay (amount) (name)"
|
||||
)
|
||||
maxArgs = 2,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "pay",
|
||||
permission = "jail.usercmd.jailpay",
|
||||
usage = "/jail pay (amount) (name)"
|
||||
)
|
||||
public class JailPayCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.JAILPAYENABLED.getPath())) {
|
||||
JailPayManager pm = jm.getPlugin().getJailPayManager();
|
||||
|
||||
switch(args.length) {
|
||||
case 1:
|
||||
// `/jail pay`
|
||||
//send how much it costs to get out
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(sender.getName());
|
||||
String amt = "";
|
||||
|
||||
if(pm.usingItemsForPayment()) {
|
||||
amt = String.valueOf((int) Math.ceil(pm.calculateBill(p)));
|
||||
}else {
|
||||
amt = String.valueOf(pm.calculateBill(p));
|
||||
}
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(pm.isTimedEnabled()) {
|
||||
sender.sendMessage(Lang.PAYCOST.get(new String[] { pm.getCostPerMinute(), pm.getCurrencyName(), amt }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
jm.getPlugin().debug("Jail pay 'timed' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}else {
|
||||
if(pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(Lang.PAYCOST.get(new String[] { amt, pm.getCurrencyName() }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
jm.getPlugin().debug("Jail pay 'infinite' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.YOUARENOTJAILED.get());
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
// `/jail pay <amount>`
|
||||
//They are trying to pay for their self
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(sender.getName());
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(!pm.isTimedEnabled()) {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(Lang.PAYNONEGATIVEAMOUNTS.get());
|
||||
}else {
|
||||
double amt = 0;
|
||||
|
||||
try {
|
||||
amt = Double.parseDouble(args[1]);
|
||||
}catch(NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "<amount> must be a number.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
if(pm.hasEnoughToPay((Player) sender, amt)) {
|
||||
double bill = pm.calculateBill(p);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
//timed sentence
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(Lang.PAYPAIDRELEASED.get(String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().schedulePrisonerRelease(p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(Lang.PAYPAIDLOWEREDTIME.get(new String[] { String.valueOf(amt), String.valueOf(TimeUnit.MINUTES.convert(remain, TimeUnit.MILLISECONDS)) }));
|
||||
}
|
||||
}else {
|
||||
//infinite jailing
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(Lang.PAYPAIDRELEASED.get(String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().schedulePrisonerRelease(p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(Lang.PAYNOTENOUGHMONEYPROVIDED.get());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.PAYNOTENOUGHMONEY.get());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.YOUARENOTJAILED.get());
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// `/jail pay <amount> <person>
|
||||
//they are trying to pay for someone else
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
//When they are jailed they can not pay for someone else
|
||||
sender.sendMessage(Lang.PAYCANTPAYWHILEJAILED.get());
|
||||
}else {
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[2])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[2]);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(!pm.isTimedEnabled()) {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(Lang.PAYNONEGATIVEAMOUNTS.get());
|
||||
}else {
|
||||
double amt = 0;
|
||||
|
||||
try {
|
||||
amt = Double.parseDouble(args[1]);
|
||||
}catch(NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "<amount> must be a number.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
if(pm.hasEnoughToPay((Player) sender, amt)) {
|
||||
double bill = pm.calculateBill(p);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
//timed sentence
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(Lang.PAYPAIDRELEASEDELSE.get(new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().schedulePrisonerRelease(p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(Lang.PAYPAIDLOWEREDTIMEELSE.get(new String[] { String.valueOf(amt), p.getLastKnownName(), String.valueOf(TimeUnit.MINUTES.convert(remain, TimeUnit.MILLISECONDS)) }));
|
||||
}
|
||||
}else {
|
||||
//infinite jailing
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(Lang.PAYPAIDRELEASEDELSE.get(new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().schedulePrisonerRelease(p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(Lang.PAYNOTENOUGHMONEYPROVIDED.get());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.PAYNOTENOUGHMONEY.get());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//Person they're trying to pay for is not jailed
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[2]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
jm.getPlugin().debug("Jail pay not enabled.");
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.JAILPAYENABLED.getPath())) {
|
||||
JailPayManager pm = jm.getPlugin().getJailPayManager();
|
||||
|
||||
switch(args.length) {
|
||||
case 1:
|
||||
// `/jail pay`
|
||||
//send how much it costs to get out
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(sender.getName());
|
||||
String amt = "";
|
||||
|
||||
if(pm.usingItemsForPayment()) {
|
||||
amt = String.valueOf((int) Math.ceil(pm.calculateBill(p)));
|
||||
}else {
|
||||
amt = String.valueOf(pm.calculateBill(p));
|
||||
}
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(pm.isTimedEnabled()) {
|
||||
sender.sendMessage(Lang.PAYCOST.get(new String[] { pm.getCostPerMinute(), pm.getCurrencyName(), amt }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
jm.getPlugin().debug("Jail pay 'timed' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}else {
|
||||
if(pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(Lang.PAYCOST.get(new String[] { amt, pm.getCurrencyName() }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
jm.getPlugin().debug("Jail pay 'infinite' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.YOUARENOTJAILED.get());
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
// `/jail pay <amount>`
|
||||
//They are trying to pay for their self
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(sender.getName());
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(!pm.isTimedEnabled()) {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(Lang.PAYNONEGATIVEAMOUNTS.get());
|
||||
}else {
|
||||
double amt = 0;
|
||||
|
||||
try {
|
||||
amt = Double.parseDouble(args[1]);
|
||||
}catch(NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "<amount> must be a number.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
if(pm.hasEnoughToPay((Player) sender, amt)) {
|
||||
double bill = pm.calculateBill(p);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
//timed sentence
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(Lang.PAYPAIDRELEASED.get(String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().schedulePrisonerRelease(p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(Lang.PAYPAIDLOWEREDTIME.get(new String[] { String.valueOf(amt), String.valueOf(TimeUnit.MINUTES.convert(remain, TimeUnit.MILLISECONDS)) }));
|
||||
}
|
||||
}else {
|
||||
//infinite jailing
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(Lang.PAYPAIDRELEASED.get(String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().schedulePrisonerRelease(p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(Lang.PAYNOTENOUGHMONEYPROVIDED.get());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.PAYNOTENOUGHMONEY.get());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.YOUARENOTJAILED.get());
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// `/jail pay <amount> <person>
|
||||
//they are trying to pay for someone else
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
//When they are jailed they can not pay for someone else
|
||||
sender.sendMessage(Lang.PAYCANTPAYWHILEJAILED.get());
|
||||
}else {
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[2])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[2]);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(!pm.isTimedEnabled()) {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(Lang.PAYNONEGATIVEAMOUNTS.get());
|
||||
}else {
|
||||
double amt = 0;
|
||||
|
||||
try {
|
||||
amt = Double.parseDouble(args[1]);
|
||||
}catch(NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "<amount> must be a number.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
if(pm.hasEnoughToPay((Player) sender, amt)) {
|
||||
double bill = pm.calculateBill(p);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
//timed sentence
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(Lang.PAYPAIDRELEASEDELSE.get(new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().schedulePrisonerRelease(p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(Lang.PAYPAIDLOWEREDTIMEELSE.get(new String[] { String.valueOf(amt), p.getLastKnownName(), String.valueOf(TimeUnit.MINUTES.convert(remain, TimeUnit.MILLISECONDS)) }));
|
||||
}
|
||||
}else {
|
||||
//infinite jailing
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(Lang.PAYPAIDRELEASEDELSE.get(new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().schedulePrisonerRelease(p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(Lang.PAYNOTENOUGHMONEYPROVIDED.get());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.PAYNOTENOUGHMONEY.get());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//Person they're trying to pay for is not jailed
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[2]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
jm.getPlugin().debug("Jail pay not enabled.");
|
||||
sender.sendMessage(Lang.PAYNOTENABLED.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -10,36 +10,36 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "record|r",
|
||||
permission = "jail.command.jailrecord",
|
||||
usage = "/jail record [name] (display)"
|
||||
)
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "record|r",
|
||||
permission = "jail.command.jailrecord",
|
||||
usage = "/jail record [name] (display)"
|
||||
)
|
||||
public class JailRecordCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
if(args.length == 2) {
|
||||
// /jail record <username>
|
||||
List<String> entries = jm.getPlugin().getJailIO().getRecordEntries(args[1]);
|
||||
|
||||
sender.sendMessage(Lang.RECORDTIMESJAILED.get(new String[] { args[1], String.valueOf(entries.size()) }));
|
||||
}else if(args.length == 3) {
|
||||
// /jail record <username> something
|
||||
List<String> entries = jm.getPlugin().getJailIO().getRecordEntries(args[1]);
|
||||
|
||||
//Send all the record entries
|
||||
for(String s : entries) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
sender.sendMessage(Lang.RECORDTIMESJAILED.get(new String[] { args[1], String.valueOf(entries.size()) }));
|
||||
}else {
|
||||
//They didn't do the command right
|
||||
//send them back to get the usage
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
if(args.length == 2) {
|
||||
// /jail record <username>
|
||||
List<String> entries = jm.getPlugin().getJailIO().getRecordEntries(args[1]);
|
||||
|
||||
sender.sendMessage(Lang.RECORDTIMESJAILED.get(new String[] { args[1], String.valueOf(entries.size()) }));
|
||||
}else if(args.length == 3) {
|
||||
// /jail record <username> something
|
||||
List<String> entries = jm.getPlugin().getJailIO().getRecordEntries(args[1]);
|
||||
|
||||
//Send all the record entries
|
||||
for(String s : entries) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
sender.sendMessage(Lang.RECORDTIMESJAILED.get(new String[] { args[1], String.valueOf(entries.size()) }));
|
||||
}else {
|
||||
//They didn't do the command right
|
||||
//send them back to get the usage
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -9,29 +9,29 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "reload",
|
||||
permission = "jail.command.jailreload",
|
||||
usage = "/jail reload"
|
||||
)
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "reload",
|
||||
permission = "jail.command.jailreload",
|
||||
usage = "/jail reload"
|
||||
)
|
||||
public class JailReloadCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
try {
|
||||
jm.getPlugin().reloadConfig();
|
||||
jm.getPlugin().getJailIO().loadLanguage();
|
||||
jm.getPlugin().getJailIO().loadJails();
|
||||
jm.getPlugin().reloadScoreBoardManager();
|
||||
jm.getPlugin().reloadJailSticks();
|
||||
jm.getPlugin().reloadJailPayManager();
|
||||
jm.getPlugin().reloadUpdateCheck();
|
||||
|
||||
sender.sendMessage(Lang.PLUGINRELOADED.get());
|
||||
}catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + "Failed to reload due to: " + e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
try {
|
||||
jm.getPlugin().reloadConfig();
|
||||
jm.getPlugin().getJailIO().loadLanguage();
|
||||
jm.getPlugin().getJailIO().loadJails();
|
||||
jm.getPlugin().reloadScoreBoardManager();
|
||||
jm.getPlugin().reloadJailSticks();
|
||||
jm.getPlugin().reloadJailPayManager();
|
||||
jm.getPlugin().reloadUpdateCheck();
|
||||
|
||||
sender.sendMessage(Lang.PLUGINRELOADED.get());
|
||||
}catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + "Failed to reload due to: " + e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -10,28 +10,28 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "status|s",
|
||||
permission = "jail.usercmd.jailstatus",
|
||||
usage = "/jail status"
|
||||
)
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "status|s",
|
||||
permission = "jail.usercmd.jailstatus",
|
||||
usage = "/jail status"
|
||||
)
|
||||
public class JailStatusCommand implements Command{
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player pl = (Player) sender;
|
||||
|
||||
if(jm.isPlayerJailed(pl.getUniqueId())) {
|
||||
Prisoner p = jm.getPrisoner(pl.getUniqueId());
|
||||
//They are jailed, so let's tell them some information
|
||||
sender.sendMessage(Lang.STATUS.get(new String[] { p.getReason(), p.getJailer(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
//the sender of the command is not jailed, tell them that
|
||||
sender.sendMessage(Lang.YOUARENOTJAILED.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player pl = (Player) sender;
|
||||
|
||||
if(jm.isPlayerJailed(pl.getUniqueId())) {
|
||||
Prisoner p = jm.getPrisoner(pl.getUniqueId());
|
||||
//They are jailed, so let's tell them some information
|
||||
sender.sendMessage(Lang.STATUS.get(new String[] { p.getReason(), p.getJailer(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
//the sender of the command is not jailed, tell them that
|
||||
sender.sendMessage(Lang.YOUARENOTJAILED.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,27 +10,27 @@ import com.graywolf336.jail.enums.Lang;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "stick",
|
||||
permission = "jail.usercmd.jailstick",
|
||||
usage = "/jail stick"
|
||||
)
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "stick",
|
||||
permission = "jail.usercmd.jailstick",
|
||||
usage = "/jail stick"
|
||||
)
|
||||
public class JailStickCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath())) {
|
||||
boolean using = jm.getPlugin().getJailStickManager().toggleUsingStick(((Player) sender).getUniqueId());
|
||||
|
||||
if(using) {
|
||||
sender.sendMessage(Lang.JAILSTICKENABLED.get());
|
||||
}else {
|
||||
sender.sendMessage(Lang.JAILSTICKDISABLED.get());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.JAILSTICKUSAGEDISABLED.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath())) {
|
||||
boolean using = jm.getPlugin().getJailStickManager().toggleUsingStick(((Player) sender).getUniqueId());
|
||||
|
||||
if(using) {
|
||||
sender.sendMessage(Lang.JAILSTICKENABLED.get());
|
||||
}else {
|
||||
sender.sendMessage(Lang.JAILSTICKDISABLED.get());
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.JAILSTICKUSAGEDISABLED.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -8,33 +8,33 @@ import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "stop",
|
||||
permission = "jail.command.jailstop",
|
||||
usage = "/jail stop"
|
||||
)
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "stop",
|
||||
permission = "jail.command.jailstop",
|
||||
usage = "/jail stop"
|
||||
)
|
||||
public class JailStopCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
boolean nothing = true;
|
||||
|
||||
if(jm.isCreatingACell(sender.getName())) {
|
||||
jm.removeCellCreationPlayer(sender.getName());
|
||||
sender.sendMessage(ChatColor.RED + "You have stopped creating cells.");
|
||||
nothing = false;
|
||||
}
|
||||
|
||||
if(jm.isCreatingAJail(sender.getName())) {
|
||||
jm.removeJailCreationPlayer(sender.getName());
|
||||
sender.sendMessage(ChatColor.RED + "You have stopped creating a jail.");
|
||||
nothing = false;
|
||||
}
|
||||
|
||||
if(nothing) {
|
||||
sender.sendMessage(ChatColor.RED + "You've stopped creating....nothing.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
boolean nothing = true;
|
||||
|
||||
if(jm.isCreatingACell(sender.getName())) {
|
||||
jm.removeCellCreationPlayer(sender.getName());
|
||||
sender.sendMessage(ChatColor.RED + "You have stopped creating cells.");
|
||||
nothing = false;
|
||||
}
|
||||
|
||||
if(jm.isCreatingAJail(sender.getName())) {
|
||||
jm.removeJailCreationPlayer(sender.getName());
|
||||
sender.sendMessage(ChatColor.RED + "You have stopped creating a jail.");
|
||||
nothing = false;
|
||||
}
|
||||
|
||||
if(nothing) {
|
||||
sender.sendMessage(ChatColor.RED + "You've stopped creating....nothing.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -10,45 +10,45 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "telein|teleportin",
|
||||
permission = "jail.command.jailtelein",
|
||||
usage = "/jail telein [jail] (name)"
|
||||
)
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "telein|teleportin",
|
||||
permission = "jail.command.jailtelein",
|
||||
usage = "/jail telein [jail] (name)"
|
||||
)
|
||||
public class JailTeleInCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
//The jail doesn't exist
|
||||
if(j == null) {
|
||||
sender.sendMessage(Lang.NOJAIL.get(args[1]));
|
||||
}else {
|
||||
//The jail does exist
|
||||
//now let's check the size of the command
|
||||
//if it has two args then someone is sending someone else in
|
||||
//otherwise it is just the sender going in
|
||||
if(args.length == 3) {
|
||||
Player p = jm.getPlugin().getServer().getPlayer(args[2]);
|
||||
|
||||
//If the player they're trying to send is offline, don't do anything
|
||||
if(p == null) {
|
||||
sender.sendMessage(Lang.PLAYERNOTONLINE.get(args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportIn());
|
||||
sender.sendMessage(Lang.TELEIN.get(new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportIn());
|
||||
sender.sendMessage(Lang.TELEIN.get(new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.PLAYERCONTEXTREQUIRED.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
//The jail doesn't exist
|
||||
if(j == null) {
|
||||
sender.sendMessage(Lang.NOJAIL.get(args[1]));
|
||||
}else {
|
||||
//The jail does exist
|
||||
//now let's check the size of the command
|
||||
//if it has two args then someone is sending someone else in
|
||||
//otherwise it is just the sender going in
|
||||
if(args.length == 3) {
|
||||
Player p = jm.getPlugin().getServer().getPlayer(args[2]);
|
||||
|
||||
//If the player they're trying to send is offline, don't do anything
|
||||
if(p == null) {
|
||||
sender.sendMessage(Lang.PLAYERNOTONLINE.get(args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportIn());
|
||||
sender.sendMessage(Lang.TELEIN.get(new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportIn());
|
||||
sender.sendMessage(Lang.TELEIN.get(new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.PLAYERCONTEXTREQUIRED.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -10,45 +10,45 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "teleout|teleportout",
|
||||
permission = "jail.command.jailteleout",
|
||||
usage = "/jail teleout [jail] (name)"
|
||||
)
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "teleout|teleportout",
|
||||
permission = "jail.command.jailteleout",
|
||||
usage = "/jail teleout [jail] (name)"
|
||||
)
|
||||
public class JailTeleOutCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
//The jail doesn't exist
|
||||
if(j == null) {
|
||||
sender.sendMessage(Lang.NOJAIL.get(args[1]));
|
||||
}else {
|
||||
//The jail does exist
|
||||
//now let's check the size of the command
|
||||
//if it has two args then someone is sending someone else in
|
||||
//otherwise it is just the sender going in
|
||||
if(args.length == 3) {
|
||||
Player p = jm.getPlugin().getServer().getPlayer(args[2]);
|
||||
|
||||
//If the player they're trying to send is offline, don't do anything
|
||||
if(p == null) {
|
||||
sender.sendMessage(Lang.PLAYERNOTONLINE.get(args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportFree());
|
||||
sender.sendMessage(Lang.TELEOUT.get(new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportFree());
|
||||
sender.sendMessage(Lang.TELEOUT.get(new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.PLAYERCONTEXTREQUIRED.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
//The jail doesn't exist
|
||||
if(j == null) {
|
||||
sender.sendMessage(Lang.NOJAIL.get(args[1]));
|
||||
}else {
|
||||
//The jail does exist
|
||||
//now let's check the size of the command
|
||||
//if it has two args then someone is sending someone else in
|
||||
//otherwise it is just the sender going in
|
||||
if(args.length == 3) {
|
||||
Player p = jm.getPlugin().getServer().getPlayer(args[2]);
|
||||
|
||||
//If the player they're trying to send is offline, don't do anything
|
||||
if(p == null) {
|
||||
sender.sendMessage(Lang.PLAYERNOTONLINE.get(args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportFree());
|
||||
sender.sendMessage(Lang.TELEOUT.get(new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportFree());
|
||||
sender.sendMessage(Lang.TELEOUT.get(new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.PLAYERCONTEXTREQUIRED.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -10,44 +10,44 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 3,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "time|t",
|
||||
permission = "jail.command.jailtime",
|
||||
usage = "/jail time [add|remove|show] [name] <time>"
|
||||
)
|
||||
maxArgs = 3,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "time|t",
|
||||
permission = "jail.command.jailtime",
|
||||
usage = "/jail time [add|remove|show] [name] <time>"
|
||||
)
|
||||
public class JailTimeCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[2])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[2]);
|
||||
|
||||
switch(args.length) {
|
||||
case 3:
|
||||
if(args[1].equalsIgnoreCase("show")) {
|
||||
sender.sendMessage(Lang.PRISONERSTIME.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(args[1].equalsIgnoreCase("add")) {
|
||||
p.addTime(Util.getTime(args[3]));
|
||||
}else if(args[1].equalsIgnoreCase("remove")) {
|
||||
p.subtractTime(Util.getTime(args[3]));
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.sendMessage(Lang.PRISONERSTIME.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[2]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[2])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[2]);
|
||||
|
||||
switch(args.length) {
|
||||
case 3:
|
||||
if(args[1].equalsIgnoreCase("show")) {
|
||||
sender.sendMessage(Lang.PRISONERSTIME.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(args[1].equalsIgnoreCase("add")) {
|
||||
p.addTime(Util.getTime(args[3]));
|
||||
}else if(args[1].equalsIgnoreCase("remove")) {
|
||||
p.subtractTime(Util.getTime(args[3]));
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.sendMessage(Lang.PRISONERSTIME.get(new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[2]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -12,45 +12,45 @@ import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "transferall|transall",
|
||||
permission = "jail.command.jailtransferall",
|
||||
usage = "/jail transferall [current] [target]"
|
||||
)
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "transferall|transall",
|
||||
permission = "jail.command.jailtransferall",
|
||||
usage = "/jail transferall [current] [target]"
|
||||
)
|
||||
public class JailTransferAllCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(Lang.NOJAILS.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Starting to transfer everyone from '" + args[1] + "' into '" + args[2] + "'.");
|
||||
|
||||
//Check if the oldjail is not a valid jail
|
||||
if(!jm.isValidJail(args[1])) {
|
||||
sender.sendMessage(Lang.NOJAIL.get(args[1]));
|
||||
return true;
|
||||
}else if(!jm.isValidJail(args[2])) {
|
||||
//Check if the targetjail is a valid jail as well
|
||||
sender.sendMessage(Lang.NOJAIL.get(args[2]));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Sending the transferring off, jail checks all came clean.");
|
||||
|
||||
Jail old = jm.getJail(args[1]);
|
||||
HashSet<Prisoner> oldPrisoners = new HashSet<Prisoner>(old.getAllPrisoners().values());
|
||||
|
||||
//Transfer all the prisoners
|
||||
for(Prisoner p : oldPrisoners) {
|
||||
jm.getPlugin().getPrisonerManager().transferPrisoner(old, old.getCellPrisonerIsIn(p.getUUID()), jm.getJail(args[2]), null, p);
|
||||
}
|
||||
|
||||
//Send the messages to the sender when completed
|
||||
sender.sendMessage(Lang.TRANSFERALLCOMPLETE.get(new String[] { old.getName(), args[2] }));
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(Lang.NOJAILS.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Starting to transfer everyone from '" + args[1] + "' into '" + args[2] + "'.");
|
||||
|
||||
//Check if the oldjail is not a valid jail
|
||||
if(!jm.isValidJail(args[1])) {
|
||||
sender.sendMessage(Lang.NOJAIL.get(args[1]));
|
||||
return true;
|
||||
}else if(!jm.isValidJail(args[2])) {
|
||||
//Check if the targetjail is a valid jail as well
|
||||
sender.sendMessage(Lang.NOJAIL.get(args[2]));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Sending the transferring off, jail checks all came clean.");
|
||||
|
||||
Jail old = jm.getJail(args[1]);
|
||||
HashSet<Prisoner> oldPrisoners = new HashSet<Prisoner>(old.getAllPrisoners().values());
|
||||
|
||||
//Transfer all the prisoners
|
||||
for(Prisoner p : oldPrisoners) {
|
||||
jm.getPlugin().getPrisonerManager().transferPrisoner(old, old.getCellPrisonerIsIn(p.getUUID()), jm.getJail(args[2]), null, p);
|
||||
}
|
||||
|
||||
//Send the messages to the sender when completed
|
||||
sender.sendMessage(Lang.TRANSFERALLCOMPLETE.get(new String[] { old.getName(), args[2] }));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -20,120 +20,120 @@ import com.lexicalscope.jewel.cli.ArgumentValidationException;
|
||||
import com.lexicalscope.jewel.cli.CliFactory;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 6,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "transfer|trans",
|
||||
permission = "jail.command.jailtransfer",
|
||||
usage = "/jail transfer [-p player] (-j jail) (-c cell)"
|
||||
)
|
||||
maxArgs = 6,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "transfer|trans",
|
||||
permission = "jail.command.jailtransfer",
|
||||
usage = "/jail transfer [-p player] (-j jail) (-c cell)"
|
||||
)
|
||||
public class JailTransferCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(Lang.NOJAILS.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Convert to a List<String> so we can edit the list
|
||||
List<String> arguments = new LinkedList<String>(Arrays.asList(args));
|
||||
//remove the first argument of "transfer"
|
||||
arguments.remove(0);
|
||||
|
||||
//Parse the command
|
||||
Transfer params = null;
|
||||
|
||||
try {
|
||||
params = CliFactory.parseArguments(Transfer.class, arguments.toArray(new String[arguments.size()]));
|
||||
}catch(ArgumentValidationException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Verify they gave us a player and if so check if they're jailed
|
||||
if(params.getPlayer() == null) {
|
||||
sender.sendMessage(Lang.PROVIDEAPLAYER.get(Lang.TRANSFERRING));
|
||||
return true;
|
||||
}else if(!jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) {
|
||||
sender.sendMessage(Lang.NOTJAILED.get(params.getPlayer()));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Checking everything before we transfer: " + params.getPlayer());
|
||||
|
||||
//If they didn't provide a jail, tell them we need one
|
||||
if(params.getJail() == null) {
|
||||
sender.sendMessage(Lang.PROVIDEAJAIL.get(Lang.TRANSFERRING));
|
||||
return true;
|
||||
}else {
|
||||
//Check if the jail they did provided is not a valid jail
|
||||
if(!jm.isValidJail(params.getJail())) {
|
||||
sender.sendMessage(Lang.NOJAIL.get(params.getJail()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("They provided a valid jail, so let's check the target cell.");
|
||||
|
||||
Jail target = jm.getJail(params.getJail());
|
||||
Cell targetCell = null;
|
||||
|
||||
//Check if they provided a cell and if so does it exist
|
||||
if(params.getCell() != null) {
|
||||
if(target.getCell(params.getCell()) == null) {
|
||||
sender.sendMessage(Lang.NOCELL.get(new String[] { params.getCell(), params.getJail() }));
|
||||
return true;
|
||||
}else {
|
||||
//Store the cell for easy of access and also check if it already is full
|
||||
targetCell = target.getCell(params.getCell());
|
||||
if(targetCell.hasPrisoner()) {
|
||||
//If the cell has a prisoner, don't allow jailing them to that particular cell
|
||||
sender.sendMessage(Lang.CELLNOTEMPTY.get(params.getCell()));
|
||||
|
||||
//But suggest the first empty cell we find
|
||||
Cell suggestedCell = jm.getJail(params.getCell()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(Lang.SUGGESTEDCELL.get(new String[] { params.getCell(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOEMPTYCELLS.get(params.getCell()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Calling the PrePrisonerTransferredEvent, jail and cell check all came out clean.");
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(params.getPlayer());
|
||||
|
||||
//Throw the custom event before transferring them, allowing another plugin to cancel it.
|
||||
PrePrisonerTransferredEvent event = new PrePrisonerTransferredEvent(jm.getJailPlayerIsIn(p.getUUID()),
|
||||
jm.getJailPlayerIsIn(p.getUUID()).getCellPrisonerIsIn(p.getUUID()),
|
||||
target, targetCell, p, jm.getPlugin().getServer().getPlayer(p.getUUID()), sender.getName());
|
||||
jm.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if(event.isCancelled()) {
|
||||
if(event.getCancelledMessage().isEmpty()) {
|
||||
//The plugin didn't provide a cancel message/reason so send the default one
|
||||
sender.sendMessage(Lang.TRANSFERCANCELLEDBYANOTHERPLUGIN.get(params.getPlayer()));
|
||||
}else {
|
||||
sender.sendMessage(event.getCancelledMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Start the transferring of the prisoner
|
||||
jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(p.getUUID()),
|
||||
jm.getJailPlayerIsIn(p.getUUID()).getCellPrisonerIsIn(p.getUUID()),
|
||||
target, targetCell, p);
|
||||
|
||||
//Send the messages to the sender, if no cell then say that but if cell send that as well
|
||||
if(targetCell == null) {
|
||||
sender.sendMessage(Lang.TRANSFERCOMPLETENOCELL.get(new String[] { params.getPlayer(), target.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.TRANSFERCOMPLETECELL.get(new String[] { params.getPlayer(), target.getName(), targetCell.getName() }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(Lang.NOJAILS.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Convert to a List<String> so we can edit the list
|
||||
List<String> arguments = new LinkedList<String>(Arrays.asList(args));
|
||||
//remove the first argument of "transfer"
|
||||
arguments.remove(0);
|
||||
|
||||
//Parse the command
|
||||
Transfer params = null;
|
||||
|
||||
try {
|
||||
params = CliFactory.parseArguments(Transfer.class, arguments.toArray(new String[arguments.size()]));
|
||||
}catch(ArgumentValidationException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Verify they gave us a player and if so check if they're jailed
|
||||
if(params.getPlayer() == null) {
|
||||
sender.sendMessage(Lang.PROVIDEAPLAYER.get(Lang.TRANSFERRING));
|
||||
return true;
|
||||
}else if(!jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) {
|
||||
sender.sendMessage(Lang.NOTJAILED.get(params.getPlayer()));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Checking everything before we transfer: " + params.getPlayer());
|
||||
|
||||
//If they didn't provide a jail, tell them we need one
|
||||
if(params.getJail() == null) {
|
||||
sender.sendMessage(Lang.PROVIDEAJAIL.get(Lang.TRANSFERRING));
|
||||
return true;
|
||||
}else {
|
||||
//Check if the jail they did provided is not a valid jail
|
||||
if(!jm.isValidJail(params.getJail())) {
|
||||
sender.sendMessage(Lang.NOJAIL.get(params.getJail()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("They provided a valid jail, so let's check the target cell.");
|
||||
|
||||
Jail target = jm.getJail(params.getJail());
|
||||
Cell targetCell = null;
|
||||
|
||||
//Check if they provided a cell and if so does it exist
|
||||
if(params.getCell() != null) {
|
||||
if(target.getCell(params.getCell()) == null) {
|
||||
sender.sendMessage(Lang.NOCELL.get(new String[] { params.getCell(), params.getJail() }));
|
||||
return true;
|
||||
}else {
|
||||
//Store the cell for easy of access and also check if it already is full
|
||||
targetCell = target.getCell(params.getCell());
|
||||
if(targetCell.hasPrisoner()) {
|
||||
//If the cell has a prisoner, don't allow jailing them to that particular cell
|
||||
sender.sendMessage(Lang.CELLNOTEMPTY.get(params.getCell()));
|
||||
|
||||
//But suggest the first empty cell we find
|
||||
Cell suggestedCell = jm.getJail(params.getCell()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(Lang.SUGGESTEDCELL.get(new String[] { params.getCell(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.NOEMPTYCELLS.get(params.getCell()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Calling the PrePrisonerTransferredEvent, jail and cell check all came out clean.");
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(params.getPlayer());
|
||||
|
||||
//Throw the custom event before transferring them, allowing another plugin to cancel it.
|
||||
PrePrisonerTransferredEvent event = new PrePrisonerTransferredEvent(jm.getJailPlayerIsIn(p.getUUID()),
|
||||
jm.getJailPlayerIsIn(p.getUUID()).getCellPrisonerIsIn(p.getUUID()),
|
||||
target, targetCell, p, jm.getPlugin().getServer().getPlayer(p.getUUID()), sender.getName());
|
||||
jm.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if(event.isCancelled()) {
|
||||
if(event.getCancelledMessage().isEmpty()) {
|
||||
//The plugin didn't provide a cancel message/reason so send the default one
|
||||
sender.sendMessage(Lang.TRANSFERCANCELLEDBYANOTHERPLUGIN.get(params.getPlayer()));
|
||||
}else {
|
||||
sender.sendMessage(event.getCancelledMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Start the transferring of the prisoner
|
||||
jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(p.getUUID()),
|
||||
jm.getJailPlayerIsIn(p.getUUID()).getCellPrisonerIsIn(p.getUUID()),
|
||||
target, targetCell, p);
|
||||
|
||||
//Send the messages to the sender, if no cell then say that but if cell send that as well
|
||||
if(targetCell == null) {
|
||||
sender.sendMessage(Lang.TRANSFERCOMPLETENOCELL.get(new String[] { params.getPlayer(), target.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(Lang.TRANSFERCOMPLETECELL.get(new String[] { params.getPlayer(), target.getName(), targetCell.getName() }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -7,20 +7,20 @@ import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "version|ver|v",
|
||||
permission = "jail.command.jailversion",
|
||||
usage = "/jail version"
|
||||
)
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "version|ver|v",
|
||||
permission = "jail.command.jailversion",
|
||||
usage = "/jail version"
|
||||
)
|
||||
public class JailVersionCommand implements Command{
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
// Sends the version number to the sender
|
||||
sender.sendMessage("Jail Version: " + jm.getPlugin().getDescription().getVersion());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
// Sends the version number to the sender
|
||||
sender.sendMessage("Jail Version: " + jm.getPlugin().getDescription().getVersion());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user