Add .gitattributes
This commit is contained in:
@ -1,173 +1,173 @@
|
||||
package com.graywolf336.jail.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
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.enums.LangString;
|
||||
|
||||
/**
|
||||
* Where all the commands are registered at and handled, processed, at.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.2
|
||||
*
|
||||
*/
|
||||
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(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.UNKNOWNCOMMAND, 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(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.NOPERMISSION));
|
||||
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(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
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.enums.LangString;
|
||||
|
||||
/**
|
||||
* Where all the commands are registered at and handled, processed, at.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.2
|
||||
*
|
||||
*/
|
||||
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(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.UNKNOWNCOMMAND, 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(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.NOPERMISSION));
|
||||
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(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,212 +1,212 @@
|
||||
package com.graywolf336.jail.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.subcommands.JailCellCreateCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCheckCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailClearCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailClearForceCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailConfirmCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCreateCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellsCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailListCellsCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailListCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailMuteCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailPayCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailRecordCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailReloadCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailStatusCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailStopCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTeleInCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTeleOutCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTimeCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTransferAllCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTransferCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailVersionCommand;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
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(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.NOPERMISSION));
|
||||
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(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
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(JailCellCreateCommand.class);
|
||||
load(JailCheckCommand.class);
|
||||
load(JailClearCommand.class);
|
||||
load(JailClearForceCommand.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(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.subcommands.JailCellCreateCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCheckCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailClearCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailClearForceCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailConfirmCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCreateCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellsCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailListCellsCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailListCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailMuteCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailPayCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailRecordCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailReloadCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailStatusCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailStopCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTeleInCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTeleOutCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTimeCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTransferAllCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTransferCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailVersionCommand;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
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(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.NOPERMISSION));
|
||||
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(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
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(JailCellCreateCommand.class);
|
||||
load(JailCheckCommand.class);
|
||||
load(JailClearCommand.class);
|
||||
load(JailClearForceCommand.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(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +1,41 @@
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "handcuff|hc",
|
||||
permission = "jail.command.handcuff",
|
||||
usage = "/handcuff [player]"
|
||||
)
|
||||
public class HandCuffCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = jm.getPlugin().getServer().getPlayer(args[0]);
|
||||
|
||||
if(player == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE));
|
||||
}else if(player.hasPermission("jail.cantbehandcuffed")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEHANDCUFFED, new String[] { player.getName() }));
|
||||
}else if(jm.isPlayerJailed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CURRENTLYJAILEDHANDCUFF, new String[] { player.getName() }));
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() }));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED));
|
||||
}else {
|
||||
jm.getPlugin().getHandCuffManager().addHandCuffs(player.getUniqueId(), player.getLocation());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSON, new String[] { player.getName() }));
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "handcuff|hc",
|
||||
permission = "jail.command.handcuff",
|
||||
usage = "/handcuff [player]"
|
||||
)
|
||||
public class HandCuffCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = jm.getPlugin().getServer().getPlayer(args[0]);
|
||||
|
||||
if(player == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE));
|
||||
}else if(player.hasPermission("jail.cantbehandcuffed")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEHANDCUFFED, new String[] { player.getName() }));
|
||||
}else if(jm.isPlayerJailed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CURRENTLYJAILEDHANDCUFF, new String[] { player.getName() }));
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() }));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED));
|
||||
}else {
|
||||
jm.getPlugin().getHandCuffManager().addHandCuffs(player.getUniqueId(), player.getLocation());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSON, new String[] { player.getName() }));
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
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"
|
||||
)
|
||||
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;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
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"
|
||||
)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unhandcuff|uhc",
|
||||
permission = "jail.command.handcuff",
|
||||
usage = "/unhandcuff [player]"
|
||||
)
|
||||
public class UnHandCuffCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = jm.getPlugin().getServer().getPlayerExact(args[0]);
|
||||
|
||||
if(player == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE));
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() }));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTHANDCUFFED, new String[] { player.getName() }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unhandcuff|uhc",
|
||||
permission = "jail.command.handcuff",
|
||||
usage = "/unhandcuff [player]"
|
||||
)
|
||||
public class UnHandCuffCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = jm.getPlugin().getServer().getPlayerExact(args[0]);
|
||||
|
||||
if(player == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE));
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() }));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTHANDCUFFED, new String[] { player.getName() }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +1,64 @@
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
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.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0]));
|
||||
}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(jm.getPlugin().getJailIO().getLanguageString(LangString.WILLBEUNJAILED, args[0]));
|
||||
}
|
||||
}else {
|
||||
//Player is online, so let's try unjailing them
|
||||
try {
|
||||
jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(jm.getPlugin().getJailIO().getLanguageString(LangString.BROADCASTUNJAILING, new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
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.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0]));
|
||||
}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(jm.getPlugin().getJailIO().getLanguageString(LangString.WILLBEUNJAILED, args[0]));
|
||||
}
|
||||
}else {
|
||||
//Player is online, so let's try unjailing them
|
||||
try {
|
||||
jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(jm.getPlugin().getJailIO().getLanguageString(LangString.BROADCASTUNJAILING, new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,38 @@
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
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.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0]));
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(jm.getPlugin().getJailIO().getLanguageString(LangString.BROADCASTUNJAILING, new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
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.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0]));
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(jm.getPlugin().getJailIO().getLanguageString(LangString.BROADCASTUNJAILING, new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
package com.graywolf336.jail.command.commands.jewels;
|
||||
|
||||
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={"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 isMuted();
|
||||
public boolean isReason();
|
||||
}
|
||||
package com.graywolf336.jail.command.commands.jewels;
|
||||
|
||||
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={"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 isMuted();
|
||||
public boolean isReason();
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
@ -1,66 +1,66 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = true,
|
||||
pattern = "createcell|cc",
|
||||
permission = "jail.command.jailcreatecells",
|
||||
usage = "/jail cellcreate [jail] (cellname)"
|
||||
)
|
||||
public class JailCellCreateCommand 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;
|
||||
}
|
||||
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = true,
|
||||
pattern = "createcell|cc",
|
||||
permission = "jail.command.jailcreatecells",
|
||||
usage = "/jail cellcreate [jail] (cellname)"
|
||||
)
|
||||
public class JailCellCreateCommand 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,217 +1,217 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.command.commands.jewels.Jailing;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
|
||||
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) (-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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.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(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADYJAILED, 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.getTime() == null) {
|
||||
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.JAILDEFAULTTIME.getPath(), "30m"));
|
||||
}else if(params.getTime() == String.valueOf(-1)) {
|
||||
time = -1L;
|
||||
}else {
|
||||
time = Util.getTime(params.getTime());
|
||||
}
|
||||
}catch(Exception e) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NUMBERFORMATINCORRECT));
|
||||
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.getJail() == null) {
|
||||
String dJail = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
|
||||
|
||||
if(dJail.equalsIgnoreCase("nearest")) {
|
||||
jailName = jm.getNearestJail(sender).getName();
|
||||
}else {
|
||||
jailName = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
|
||||
}
|
||||
}else if(jm.getJail(params.getJail()) == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.getJail()));
|
||||
return true;
|
||||
}else {
|
||||
jailName = params.getJail();
|
||||
}
|
||||
|
||||
//Check if the cell is defined, and if so check to be sure it exists.
|
||||
if(params.getCell() != null) {
|
||||
if(jm.getJail(params.getJail()).getCell(params.getCell()) == null) {
|
||||
//There is no cell by that name
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { params.getCell(), params.getJail() }));
|
||||
return true;
|
||||
}else if(jm.getJail(params.getJail()).getCell(params.getCell()).hasPrisoner()) {
|
||||
//If the cell has a prisoner, don't allow jailing them to that particular cell
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell()));
|
||||
Cell suggestedCell = jm.getJail(params.getJail()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getJail(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.getJail()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//If the jailer gave no reason, then let's get the default reason
|
||||
String reason = "";
|
||||
if(params.getReason() == null) {
|
||||
reason = jm.getPlugin().getJailIO().getLanguageString(LangString.DEFAULTJAILEDREASON);
|
||||
}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(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEJAILED));
|
||||
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();
|
||||
}
|
||||
|
||||
//Get the jail instance from the name of jail in the params.
|
||||
Jail j = jm.getJail(jailName);
|
||||
Cell c = j.getCell(params.getCell());
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.OFFLINEJAIL, new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
//Player *is* online
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ONLINEJAIL, 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;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.command.commands.jewels.Jailing;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
|
||||
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) (-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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.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(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADYJAILED, 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.getTime() == null) {
|
||||
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.JAILDEFAULTTIME.getPath(), "30m"));
|
||||
}else if(params.getTime() == String.valueOf(-1)) {
|
||||
time = -1L;
|
||||
}else {
|
||||
time = Util.getTime(params.getTime());
|
||||
}
|
||||
}catch(Exception e) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NUMBERFORMATINCORRECT));
|
||||
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.getJail() == null) {
|
||||
String dJail = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
|
||||
|
||||
if(dJail.equalsIgnoreCase("nearest")) {
|
||||
jailName = jm.getNearestJail(sender).getName();
|
||||
}else {
|
||||
jailName = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
|
||||
}
|
||||
}else if(jm.getJail(params.getJail()) == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.getJail()));
|
||||
return true;
|
||||
}else {
|
||||
jailName = params.getJail();
|
||||
}
|
||||
|
||||
//Check if the cell is defined, and if so check to be sure it exists.
|
||||
if(params.getCell() != null) {
|
||||
if(jm.getJail(params.getJail()).getCell(params.getCell()) == null) {
|
||||
//There is no cell by that name
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { params.getCell(), params.getJail() }));
|
||||
return true;
|
||||
}else if(jm.getJail(params.getJail()).getCell(params.getCell()).hasPrisoner()) {
|
||||
//If the cell has a prisoner, don't allow jailing them to that particular cell
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell()));
|
||||
Cell suggestedCell = jm.getJail(params.getJail()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getJail(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.getJail()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//If the jailer gave no reason, then let's get the default reason
|
||||
String reason = "";
|
||||
if(params.getReason() == null) {
|
||||
reason = jm.getPlugin().getJailIO().getLanguageString(LangString.DEFAULTJAILEDREASON);
|
||||
}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(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEJAILED));
|
||||
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();
|
||||
}
|
||||
|
||||
//Get the jail instance from the name of jail in the params.
|
||||
Jail j = jm.getJail(jailName);
|
||||
Cell c = j.getCell(params.getCell());
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.OFFLINEJAIL, new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
//Player *is* online
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ONLINEJAIL, 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;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELL));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELL));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELLS));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELLS));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETE));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETE));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELLS, j.getName()));
|
||||
}else {
|
||||
sender.sendMessage(ChatColor.GREEN + message);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "-------------------------");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELLS, j.getName()));
|
||||
}else {
|
||||
sender.sendMessage(ChatColor.GREEN + message);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "-------------------------");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,63 +1,63 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
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(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
}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()) {
|
||||
sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")");
|
||||
}
|
||||
}else {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
if(j == null) {
|
||||
//No jail was found
|
||||
sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}else {
|
||||
Collection<Prisoner> pris = j.getAllPrisoners().values();
|
||||
|
||||
if(pris.isEmpty()) {
|
||||
//If there are no prisoners, then send that message
|
||||
sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOPRISONERS, 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;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
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(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
}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()) {
|
||||
sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")");
|
||||
}
|
||||
}else {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
if(j == null) {
|
||||
//No jail was found
|
||||
sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}else {
|
||||
Collection<Prisoner> pris = j.getAllPrisoners().values();
|
||||
|
||||
if(pris.isEmpty()) {
|
||||
//If there are no prisoners, then send that message
|
||||
sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOPRISONERS, 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;
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,38 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "mute|m",
|
||||
permission = "jail.command.jailmute",
|
||||
usage = "/jail mute <player>"
|
||||
)
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOWMUTED, args[1]));
|
||||
else
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOWUNMUTED, args[1]));
|
||||
}else {
|
||||
//The player provided is not jailed, so let's tell the sender that
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[1]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "mute|m",
|
||||
permission = "jail.command.jailmute",
|
||||
usage = "/jail mute <player>"
|
||||
)
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOWMUTED, args[1]));
|
||||
else
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOWUNMUTED, args[1]));
|
||||
}else {
|
||||
//The player provided is not jailed, so let's tell the sender that
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[1]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,229 +1,229 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.JailPayManager;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "pay",
|
||||
permission = "jail.usercmd.jailpay",
|
||||
usage = "/jail pay <amount> <player>"
|
||||
)
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCOST, new String[] { pm.getCostPerMinute(), pm.getCurrencyName(), amt }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
jm.getPlugin().debug("Jail pay 'timed' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}else {
|
||||
if(pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCOST, new String[] { amt, pm.getCurrencyName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
jm.getPlugin().debug("Jail pay 'infinite' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.YOUARENOTJAILED));
|
||||
}
|
||||
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNONEGATIVEAMOUNTS));
|
||||
}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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASED, String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner((Player) sender, p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDLOWEREDTIME,
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASED, String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner((Player) sender, p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEYPROVIDED));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEY));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.YOUARENOTJAILED));
|
||||
}
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCANTPAYWHILEJAILED));
|
||||
}else {
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[2])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[2]);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(!pm.isTimedEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNONEGATIVEAMOUNTS));
|
||||
}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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayer(p.getUUID()), p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDLOWEREDTIMEELSE,
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayer(p.getUUID()), p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEYPROVIDED));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEY));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//Person they're trying to pay for is not jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[2]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
jm.getPlugin().debug("Jail pay not enabled.");
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
Messages:
|
||||
MessageJailPayAmountForever: To get out of this mess, you will have to pay <Amount>.
|
||||
JailPayCannotPay: Sorry, money won't help you this time.
|
||||
JailPayCannotPayHim: Sorry, money won't help him this time.
|
||||
JailPayNotEnoughMoney: You don't have that much money!
|
||||
JailPayCost: 1 minute of your sentence will cost you <MinutePrice>. That means that cost for releasing you out of the jail is <WholePrice>.
|
||||
JailPayPaidReleased: You have just payed <Amount> and saved yourself from the jail!
|
||||
JailPayPaidReleasedHim: You have just payed <Amount> and saved <Prisoner> from the jail!
|
||||
JailPayLoweredTime: You have just payed <Amount> and lowered your sentence to <NewTime> minutes!
|
||||
JailPayLoweredTimeHim: You have just payed <Amount> and lowered <Prisoner>'s sentence to <NewTime> minutes!
|
||||
JailPay:
|
||||
PricePerMinute: 10
|
||||
PriceForInfiniteJail: 9999
|
||||
Currency: 0
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.JailPayManager;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "pay",
|
||||
permission = "jail.usercmd.jailpay",
|
||||
usage = "/jail pay <amount> <player>"
|
||||
)
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCOST, new String[] { pm.getCostPerMinute(), pm.getCurrencyName(), amt }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
jm.getPlugin().debug("Jail pay 'timed' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}else {
|
||||
if(pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCOST, new String[] { amt, pm.getCurrencyName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
jm.getPlugin().debug("Jail pay 'infinite' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.YOUARENOTJAILED));
|
||||
}
|
||||
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNONEGATIVEAMOUNTS));
|
||||
}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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASED, String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner((Player) sender, p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDLOWEREDTIME,
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASED, String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner((Player) sender, p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEYPROVIDED));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEY));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.YOUARENOTJAILED));
|
||||
}
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCANTPAYWHILEJAILED));
|
||||
}else {
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[2])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[2]);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(!pm.isTimedEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNONEGATIVEAMOUNTS));
|
||||
}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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayer(p.getUUID()), p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDLOWEREDTIMEELSE,
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayer(p.getUUID()), p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEYPROVIDED));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEY));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//Person they're trying to pay for is not jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[2]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
jm.getPlugin().debug("Jail pay not enabled.");
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
Messages:
|
||||
MessageJailPayAmountForever: To get out of this mess, you will have to pay <Amount>.
|
||||
JailPayCannotPay: Sorry, money won't help you this time.
|
||||
JailPayCannotPayHim: Sorry, money won't help him this time.
|
||||
JailPayNotEnoughMoney: You don't have that much money!
|
||||
JailPayCost: 1 minute of your sentence will cost you <MinutePrice>. That means that cost for releasing you out of the jail is <WholePrice>.
|
||||
JailPayPaidReleased: You have just payed <Amount> and saved yourself from the jail!
|
||||
JailPayPaidReleasedHim: You have just payed <Amount> and saved <Prisoner> from the jail!
|
||||
JailPayLoweredTime: You have just payed <Amount> and lowered your sentence to <NewTime> minutes!
|
||||
JailPayLoweredTimeHim: You have just payed <Amount> and lowered <Prisoner>'s sentence to <NewTime> minutes!
|
||||
JailPay:
|
||||
PricePerMinute: 10
|
||||
PriceForInfiniteJail: 9999
|
||||
Currency: 0
|
||||
*/
|
@ -1,45 +1,45 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "reload|r",
|
||||
permission = "jail.command.jailrecord",
|
||||
usage = "/jail record <username> <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(jm.getPlugin().getJailIO().getLanguageString(LangString.RECORDTIMESJAILED, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.RECORDTIMESJAILED, 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;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "reload|r",
|
||||
permission = "jail.command.jailrecord",
|
||||
usage = "/jail record <username> <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(jm.getPlugin().getJailIO().getLanguageString(LangString.RECORDTIMESJAILED, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.RECORDTIMESJAILED, 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;
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "reload|r",
|
||||
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();
|
||||
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLUGINRELOADED));
|
||||
}catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "reload|r",
|
||||
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();
|
||||
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLUGINRELOADED));
|
||||
}catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
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(sender.getName());
|
||||
|
||||
if(using) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKENABLED));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKDISABLED));
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKUSAGEDISABLED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
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(sender.getName());
|
||||
|
||||
if(using) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKENABLED));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKDISABLED));
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKUSAGEDISABLED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "telein|teleportin",
|
||||
permission = "jail.command.jailtelein",
|
||||
usage = "/jail telein <jailname> (player)"
|
||||
)
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE, args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportIn());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEIN, new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportIn());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEIN, new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "telein|teleportin",
|
||||
permission = "jail.command.jailtelein",
|
||||
usage = "/jail telein <jailname> (player)"
|
||||
)
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE, args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportIn());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEIN, new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportIn());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEIN, new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "teleout|teleportout",
|
||||
permission = "jail.command.jailteleout",
|
||||
usage = "/jail teleout <jailname> (player)"
|
||||
)
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE, args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportFree());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEOUT, new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportFree());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEOUT, new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "teleout|teleportout",
|
||||
permission = "jail.command.jailteleout",
|
||||
usage = "/jail teleout <jailname> (player)"
|
||||
)
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE, args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportFree());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEOUT, new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportFree());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEOUT, new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,55 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 3,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "time|t",
|
||||
permission = "jail.command.jailtime",
|
||||
usage = "/jail time <add|remove|show> <player> <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(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME,
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME,
|
||||
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[2]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 3,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "time|t",
|
||||
permission = "jail.command.jailtime",
|
||||
usage = "/jail time <add|remove|show> <player> <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(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME,
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME,
|
||||
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[2]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,56 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "transferall|transall",
|
||||
permission = "jail.command.jailtransferall",
|
||||
usage = "/jail transferall oldjail targetjail"
|
||||
)
|
||||
public class JailTransferAllCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
return true;
|
||||
}else if(!jm.isValidJail(args[2])) {
|
||||
//Check if the targetjail is a valid jail as well
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERALLCOMPLETE, new String[] { old.getName(), args[2] }));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "transferall|transall",
|
||||
permission = "jail.command.jailtransferall",
|
||||
usage = "/jail transferall oldjail targetjail"
|
||||
)
|
||||
public class JailTransferAllCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
return true;
|
||||
}else if(!jm.isValidJail(args[2])) {
|
||||
//Check if the targetjail is a valid jail as well
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERALLCOMPLETE, new String[] { old.getName(), args[2] }));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,139 +1,139 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.command.commands.jewels.Transfer;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.events.PrePrisonerTransferredEvent;
|
||||
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"
|
||||
)
|
||||
public class JailTransferCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.TRANSFERRING));
|
||||
return true;
|
||||
}else if(!jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAJAIL, LangString.TRANSFERRING));
|
||||
return true;
|
||||
}else {
|
||||
//Check if the jail they did provided is not a valid jail
|
||||
if(!jm.isValidJail(params.getJail())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell()));
|
||||
|
||||
//But suggest the first empty cell we find
|
||||
Cell suggestedCell = jm.getJail(params.getCell()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getCell(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCANCELLEDBYANOTHERPLUGIN, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCOMPLETENOCELL, new String[] { params.getPlayer(), target.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCOMPLETECELL, new String[] { params.getPlayer(), target.getName(), targetCell.getName() }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.command.commands.jewels.Transfer;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.events.PrePrisonerTransferredEvent;
|
||||
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"
|
||||
)
|
||||
public class JailTransferCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
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(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.TRANSFERRING));
|
||||
return true;
|
||||
}else if(!jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAJAIL, LangString.TRANSFERRING));
|
||||
return true;
|
||||
}else {
|
||||
//Check if the jail they did provided is not a valid jail
|
||||
if(!jm.isValidJail(params.getJail())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell()));
|
||||
|
||||
//But suggest the first empty cell we find
|
||||
Cell suggestedCell = jm.getJail(params.getCell()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getCell(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCANCELLEDBYANOTHERPLUGIN, 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(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCOMPLETENOCELL, new String[] { params.getPlayer(), target.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCOMPLETECELL, new String[] { params.getPlayer(), target.getName(), targetCell.getName() }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user