More command workings and using the custom languages.

This commit is contained in:
graywolf336 2014-01-21 18:09:47 -06:00
parent 3ab751baa8
commit 34ac65565c
9 changed files with 88 additions and 17 deletions

View File

@ -150,6 +150,11 @@ public class Jail {
return this.cells.get(name); return this.cells.get(name);
} }
/** Removes the cell from the jail. */
public void removeCell(String name) {
this.cells.remove(name);
}
/** Returns the cell which the given player name is jailed in, null if not. */ /** Returns the cell which the given player name is jailed in, null if not. */
public Cell getCellPrisonerIsIn(String name) { public Cell getCellPrisonerIsIn(String name) {
for(Cell c : cells.values()) for(Cell c : cells.values())

View File

@ -9,7 +9,7 @@ import com.graywolf336.jail.command.CommandInfo;
@CommandInfo( @CommandInfo(
maxArgs = 1, maxArgs = 1,
minimumArgs = 0, minimumArgs = 0,
needsPlayer = true, needsPlayer = false,
pattern = "jailcheck|jcheck", pattern = "jailcheck|jcheck",
permission = "jail.command.jailcheck", permission = "jail.command.jailcheck",
usage = "/jailcheck (Player name)" usage = "/jailcheck (Player name)"

View File

@ -100,16 +100,17 @@ public class JailCommand implements Command {
//Check if the cell is defined, and if so check to be sure it exists. //Check if the cell is defined, and if so check to be sure it exists.
if(!params.cell().isEmpty()) { if(!params.cell().isEmpty()) {
if(jm.getJail(params.jail()).getCell(params.cell()) == null) { if(jm.getJail(params.jail()).getCell(params.cell()) == null) {
sender.sendMessage(ChatColor.RED + "The cell provided does not exist."); //There is cell by that name
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { params.cell(), params.jail() }));
return true; return true;
}else if(jm.getJail(params.jail()).getCell(params.cell()).hasPrisoner()) { }else if(jm.getJail(params.jail()).getCell(params.cell()).hasPrisoner()) {
//If the cell has a prisoner, don't allow jailing them to that particular cell //If the cell has a prisoner, don't allow jailing them to that particular cell
sender.sendMessage(ChatColor.RED + "The destination cell already has a prisoner in it."); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.cell()));
Cell suggestedCell = jm.getJail(params.jail()).getFirstEmptyCell(); Cell suggestedCell = jm.getJail(params.jail()).getFirstEmptyCell();
if(suggestedCell != null) { if(suggestedCell != null) {
sender.sendMessage(ChatColor.RED + "We found an empty cell in the same jail (" + params.jail() + ") with the name: " + suggestedCell.getName()); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.jail(), suggestedCell.getName() }));
}else { }else {
sender.sendMessage(ChatColor.RED + "We didn't find any empty cells, this jail's (" + params.jail() + ") cells appear to be full"); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.jail()));
} }
return true; return true;
@ -141,7 +142,7 @@ public class JailCommand implements Command {
//check if the event is cancelled //check if the event is cancelled
if(event.isCancelled()) { if(event.isCancelled()) {
if(event.getCancelledMessage().isEmpty()) if(event.getCancelledMessage().isEmpty())
sender.sendMessage(ChatColor.RED + "Jailing " + params.player() + " was cancelled by another plugin and they didn't leave you a message."); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, params.player()));
else else
sender.sendMessage(event.getCancelledMessage()); sender.sendMessage(event.getCancelledMessage());

View File

@ -8,6 +8,7 @@ import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo; import com.graywolf336.jail.command.CommandInfo;
import com.graywolf336.jail.enums.LangString;
@CommandInfo( @CommandInfo(
maxArgs = 1, maxArgs = 1,
@ -36,15 +37,15 @@ public class JailListCellsCommand implements Command {
} }
if(message.isEmpty()) { if(message.isEmpty()) {
sender.sendMessage(ChatColor.RED + "There are no cells for the jail '" + args[0] + "'."); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELLS, j.getName()));
}else { }else {
sender.sendMessage(ChatColor.GREEN + message); sender.sendMessage(ChatColor.GREEN + message);
} }
}else { }else {
sender.sendMessage(ChatColor.RED + "No jail by the name of '" + args[0] + "'."); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[0]));
} }
}else { }else {
sender.sendMessage(ChatColor.RED + " There are no jails."); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
} }
sender.sendMessage(ChatColor.AQUA + "-------------------------"); sender.sendMessage(ChatColor.AQUA + "-------------------------");

View File

@ -7,6 +7,7 @@ import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo; import com.graywolf336.jail.command.CommandInfo;
import com.graywolf336.jail.enums.LangString;
@CommandInfo( @CommandInfo(
maxArgs = 0, maxArgs = 0,
@ -27,7 +28,7 @@ public class JailListCommand implements Command {
sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")"); sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")");
} }
}else { }else {
sender.sendMessage(ChatColor.RED + " There are no jails."); sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
} }
sender.sendMessage(ChatColor.AQUA + "-------------------------"); sender.sendMessage(ChatColor.AQUA + "-------------------------");

View File

@ -3,23 +3,47 @@ package com.graywolf336.jail.command.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager; import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo; import com.graywolf336.jail.command.CommandInfo;
import com.graywolf336.jail.enums.LangString;
@CommandInfo( @CommandInfo(
maxArgs = 2, maxArgs = 2,
minimumArgs = 1, minimumArgs = 2,
needsPlayer = true, needsPlayer = false,
pattern = "jailremovecell|jrcell", pattern = "jailremovecell|jrcell",
permission = "jail.command.jailremovecell", permission = "jail.command.jailremovecell",
usage = "/jailremovecell [Jail Name] (Cell Name)" usage = "/jailremovecell [Jail Name] (Cell Name)"
) )
public class JailRemoveCellCommand implements Command{ public class JailRemoveCellCommand implements Command{
// Remove the specified Cell from the Specified Jail, if no cell specified will delete nearest cell // Remove the specified Cell from the Specified Jail
public boolean execute(JailManager jm, CommandSender sender, String... args) { public boolean execute(JailManager jm, CommandSender sender, String... args) {
return true; //If they made it this far, the command is intact and ready to be processed. :) Jail j = jm.getJail(args[0]);
if(j != null) {
if(!j.getCells().isEmpty()) {
if(j.getCell(args[1]) != null) {
//remove it!
j.removeCell(args[1]);
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLREMOVED,
new String[] { args[1], args[0] }));
}else {
//No cell by that name
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL,
new String[] { args[1], args[0] }));
}
}else {
//No cells in this jail
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELLS, args[0]));
}
}else {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[0]));
}
return true;
} }
} }

View File

@ -8,6 +8,7 @@ import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo; import com.graywolf336.jail.command.CommandInfo;
import com.graywolf336.jail.enums.LangString;
@CommandInfo( @CommandInfo(
maxArgs = 1, maxArgs = 1,
@ -20,12 +21,19 @@ import com.graywolf336.jail.command.CommandInfo;
public class UnjailCommand implements Command { public class UnjailCommand implements Command {
public boolean execute(JailManager jm, CommandSender sender, String... args) { public boolean execute(JailManager jm, CommandSender sender, String... args) {
//Check if the player is jailed
if(jm.isPlayerJailed(args[0])) { if(jm.isPlayerJailed(args[0])) {
Jail j = jm.getJailPlayerIsIn(args[0]);
Player p = jm.getPlugin().getServer().getPlayerExact(args[0]); Player p = jm.getPlugin().getServer().getPlayerExact(args[0]);
//Check if the player is on the server or not
if(p == null) { if(p == null) {
sender.sendMessage(ChatColor.RED + "Offline unjailing is not implemented yet."); //The player is not, so we'll set the remaining time to zero and do it when they login next
j.getPrisoner(args[0]).setRemainingTime(0L);
j.getPrisoner(args[0]).setOfflinePending(true);
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.WILLBEUNJAILED, args[0]));
}else { }else {
Jail j = jm.getJailPlayerIsIn(args[0]); //Player is online, so let's try unjailing them
try { try {
jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(args[0]), p, j.getPrisoner(args[0])); jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(args[0]), p, j.getPrisoner(args[0]));
} catch (Exception e) { } catch (Exception e) {
@ -33,7 +41,8 @@ public class UnjailCommand implements Command {
} }
} }
}else { }else {
sender.sendMessage(ChatColor.RED + "That player is not jailed."); //The player is not currently jailed
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[0]));
} }
return true; return true;

View File

@ -20,8 +20,12 @@ public enum LangString {
BROADCASTMESSAGEFOREVER ("jailing"), BROADCASTMESSAGEFOREVER ("jailing"),
/** The message sent when we broadcast/log the message for any time above -1. */ /** The message sent when we broadcast/log the message for any time above -1. */
BROADCASTMESSAGEFORMINUTES ("jailing"), BROADCASTMESSAGEFORMINUTES ("jailing"),
/** The message sent to the sender when trying to jail someone and a plugin cancels it but doesn't leave a message why. */
CANCELLEDBYANOTHERPLUGIN ("jailing"),
/** The message sent when trying to jail someone who can't be jailed by permission. */ /** The message sent when trying to jail someone who can't be jailed by permission. */
CANTBEJAILED ("jailing"), CANTBEJAILED ("jailing"),
/** The message sent to the sender when they are trying to jail into a cell which is not empty. */
CELLNOTEMPTY ("jailing"),
/** The message sent when someone is jailed without a reason. */ /** The message sent when someone is jailed without a reason. */
DEFAULTJAILEDREASON ("jailing"), DEFAULTJAILEDREASON ("jailing"),
/** The message sent when players are jailed without a reason. */ /** The message sent when players are jailed without a reason. */
@ -30,12 +34,20 @@ public enum LangString {
JAILEDWITHREASON ("jailing"), JAILEDWITHREASON ("jailing"),
/** The message sent when players are jailed and they try to talk. */ /** The message sent when players are jailed and they try to talk. */
MUTED ("jailing"), MUTED ("jailing"),
/** The message sent when the sender tries to jail someone in a cell and there aren't any cells to suggest. */
NOEMPTYCELLS ("jailing"),
/** The message sent when a player is not jailed and the sender is trying to see/do something about it. */
NOTJAILED ("jailing"),
/** The message sent to the prisoner when they try to do something but it is protected. */ /** The message sent to the prisoner when they try to do something but it is protected. */
PROTECTIONMESSAGE ("jailing"), PROTECTIONMESSAGE ("jailing"),
/** The message sent to the prisoner when they try to do something and it is protected, but no penalty. */ /** The message sent to the prisoner when they try to do something and it is protected, but no penalty. */
PROTECTIONMESSAGENOPENALTY ("jailing"), PROTECTIONMESSAGENOPENALTY ("jailing"),
/** The message sent to the sender of a command when suggesting a cell. */
SUGGESTEDCELL ("jailing"),
/** The message sent when players are released from jail. */ /** The message sent when players are released from jail. */
UNJAILED ("jailing"), UNJAILED ("jailing"),
/** The message went when an offline player is unjailed. */
WILLBEUNJAILED ("jailing"),
//Handcuffing section //Handcuffing section
@ -58,6 +70,14 @@ public enum LangString {
/** Part message of any messages which require 'all the jails' or such. */ /** Part message of any messages which require 'all the jails' or such. */
ALLJAILS ("general"), ALLJAILS ("general"),
/** The message sent whenever a cell is successfully removed. */
CELLREMOVED ("general"),
/** The message sent whenever a jail is successfully removed. */
JAILREMOVED ("general"),
/** Message sent when doing something that requires a cell but the given name of a cell doesn't exist. */
NOCELL ("general"),
/** Message sent when needing a cell or something and there are no cells. */
NOCELLS ("general"),
/** The message sent whenever the sender does something which the jail does not found. */ /** The message sent whenever the sender does something which the jail does not found. */
NOJAIL ("general"), NOJAIL ("general"),
/** The message sent whenever the sender does something and there are no jails. */ /** The message sent whenever the sender does something and there are no jails. */

View File

@ -5,6 +5,10 @@ language:
command: 'trying to use a command' command: 'trying to use a command'
general: general:
alljails: 'all the jails' alljails: 'all the jails'
cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.'
jailremoved: '&9Jail %0% has been successfully removed.'
nocell: '&cNo cell found by the name of &0& in the jail %1%.'
nocells: '&cNo cells found in the jail %0%.'
nojail: '&cNo jail found by the name of %0%.' nojail: '&cNo jail found by the name of %0%.'
nojails: '&cThere are currently no jails.' nojails: '&cThere are currently no jails.'
nopermission: '&cInsufficient permission.' nopermission: '&cInsufficient permission.'
@ -18,14 +22,20 @@ language:
alreadyjailed: '&cThat player is already jailed.' alreadyjailed: '&cThat player is already jailed.'
broadcastmessageforever: '&9%0% has been jailed forever.' broadcastmessageforever: '&9%0% has been jailed forever.'
broadcastmessageforminutes: '&9%0% has been jailed for %1% minutes.' broadcastmessageforminutes: '&9%0% has been jailed for %1% minutes.'
cancelledbyanotherplugin: '&cJailing %0% was cancelled by another plugin and they did not leave you a message.'
cantbejailed: '&cThat player can not be jailed.' cantbejailed: '&cThat player can not be jailed.'
cellnotempty: '&cThe destination cell, %0%, already has a prisoner in it.'
defaultjailedreason: 'Breaking the rules.' defaultjailedreason: 'Breaking the rules.'
jailed: '&cYou have been jailed!' jailed: '&cYou have been jailed!'
jailedwithreason: '&cYou have been jailed for: %0%' jailedwithreason: '&cYou have been jailed for: %0%'
muted: '&cStop talking, you are in jail.' muted: '&cStop talking, you are in jail.'
noemptycells: '&cNo empty cells were found for %0%, all them appear to be full.'
notjailed: '&c%0% is not jailed.'
protectionmessage: '&c%0% minutes has been added to your time for %1%.' protectionmessage: '&c%0% minutes has been added to your time for %1%.'
protectionmessagenopenalty: '&cProtection enabled for %0%, do not do it again.' protectionmessagenopenalty: '&cProtection enabled for %0%, do not do it again.'
suggestedcell: '&cAn empty cell in the same jail, %0%, was found: %1%'
unjailed: '&2You have been released! Please respect the server rules.' unjailed: '&2You have been released! Please respect the server rules.'
willbeunjailed: '&2%0% will be released the next time they log on.'
handcuffing: handcuffing:
cantbehandcuffed: '&9%0% &ccan not be handcuffed.' cantbehandcuffed: '&9%0% &ccan not be handcuffed.'
currentlyjailed: '&9%0% &cis currently jailed, you can not handcuff a prisoner.' currentlyjailed: '&9%0% &cis currently jailed, you can not handcuff a prisoner.'