Finally get all the messages on the jail command to come from the

language system. :)
This commit is contained in:
graywolf336 2014-01-21 19:56:14 -06:00
parent 9a9a75dc1e
commit 06aa6629b7
6 changed files with 47 additions and 19 deletions

View File

@ -215,6 +215,7 @@ public class JailIO {
flat.set(cNode + "prisoner.muted", p.isMuted()); flat.set(cNode + "prisoner.muted", p.isMuted());
flat.set(cNode + "prisoner.time", p.getRemainingTime()); flat.set(cNode + "prisoner.time", p.getRemainingTime());
flat.set(cNode + "prisoner.offlinePending", p.isOfflinePending()); flat.set(cNode + "prisoner.offlinePending", p.isOfflinePending());
flat.set(cNode + "prisoner.jailer", p.getJailer());
flat.set(cNode + "prisoner.reason", p.getReason()); flat.set(cNode + "prisoner.reason", p.getReason());
flat.set(cNode + "prisoner.inventory", p.getInventory()); flat.set(cNode + "prisoner.inventory", p.getInventory());
flat.set(cNode + "prisoner.armor", p.getArmor()); flat.set(cNode + "prisoner.armor", p.getArmor());
@ -232,6 +233,7 @@ public class JailIO {
flat.set(pNode + "muted", p.isMuted()); flat.set(pNode + "muted", p.isMuted());
flat.set(pNode + "time", p.getRemainingTime()); flat.set(pNode + "time", p.getRemainingTime());
flat.set(pNode + "offlinePending", p.isOfflinePending()); flat.set(pNode + "offlinePending", p.isOfflinePending());
flat.set(pNode + "jailer", p.getJailer());
flat.set(pNode + "reason", p.getReason()); flat.set(pNode + "reason", p.getReason());
flat.set(pNode + "inventory", p.getInventory()); flat.set(pNode + "inventory", p.getInventory());
flat.set(pNode + "armor", p.getArmor()); flat.set(pNode + "armor", p.getArmor());
@ -314,6 +316,7 @@ public class JailIO {
Prisoner p = new Prisoner(flat.getString(cellNode + "prisoner.name"), Prisoner p = new Prisoner(flat.getString(cellNode + "prisoner.name"),
flat.getBoolean(cellNode + "prisoner.muted"), flat.getBoolean(cellNode + "prisoner.muted"),
flat.getLong(cellNode + "prisoner.time"), flat.getLong(cellNode + "prisoner.time"),
flat.getString(cellNode + "prisoner.jailer"),
flat.getString(cellNode + "prisoner.reason")); flat.getString(cellNode + "prisoner.reason"));
p.setOfflinePending(flat.getBoolean(cellNode + "prisoner.offlinePending")); p.setOfflinePending(flat.getBoolean(cellNode + "prisoner.offlinePending"));
p.setPreviousPosition(flat.getString(cellNode + "prisoner.previousLocation")); p.setPreviousPosition(flat.getString(cellNode + "prisoner.previousLocation"));
@ -333,7 +336,11 @@ public class JailIO {
if(!prisoners.isEmpty()) { if(!prisoners.isEmpty()) {
for(String prisoner : prisoners) { for(String prisoner : prisoners) {
String pNode = node + "prisoners." + prisoner + "."; String pNode = node + "prisoners." + prisoner + ".";
Prisoner pris = new Prisoner(prisoner, flat.getBoolean(pNode + "muted"), flat.getLong(pNode + "time"), flat.getString(pNode + "reason")); Prisoner pris = new Prisoner(prisoner,
flat.getBoolean(pNode + "muted"),
flat.getLong(pNode + "time"),
flat.getString(pNode + "jailer"),
flat.getString(pNode + "reason"));
pris.setOfflinePending(flat.getBoolean(pNode + "offlinePending")); pris.setOfflinePending(flat.getBoolean(pNode + "offlinePending"));
pris.setPreviousPosition(flat.getString(pNode + "previousLocation")); pris.setPreviousPosition(flat.getString(pNode + "previousLocation"));
pris.setPreviousGameMode(flat.getString(pNode + "previousGameMode")); pris.setPreviousGameMode(flat.getString(pNode + "previousGameMode"));

View File

@ -14,7 +14,7 @@ import org.bukkit.Location;
* @version 3.0.0 * @version 3.0.0
*/ */
public class Prisoner { public class Prisoner {
private String name, reason, inventory, armor; private String name, jailer, reason, inventory, armor;
private boolean muted, offlinePending, teleporting; private boolean muted, offlinePending, teleporting;
private long time, afk; private long time, afk;
private Location previousPosition; private Location previousPosition;
@ -26,11 +26,14 @@ public class Prisoner {
* @param name The name of the prisoner * @param name The name of the prisoner
* @param muted Whether the prisoner is muted or not * @param muted Whether the prisoner is muted or not
* @param time The amount of remaining time the prisoner has * @param time The amount of remaining time the prisoner has
* @param jailer The name of the person who jailed this prisoner
* @param reason The reason why this prisoner is in jail
*/ */
public Prisoner(String name, boolean muted, long time, String reason) { public Prisoner(String name, boolean muted, long time, String jailer, String reason) {
this.name = name; this.name = name;
this.muted = muted; this.muted = muted;
this.time = time; this.time = time;
this.jailer = jailer;
this.reason = reason; this.reason = reason;
this.offlinePending = false; this.offlinePending = false;
this.teleporting = false; this.teleporting = false;
@ -56,6 +59,16 @@ public class Prisoner {
this.reason = reason; this.reason = reason;
} }
/** Gets the person who jailed this prisoner. */
public String getJailer() {
return this.jailer;
}
/** Sets the person who jailed this prisoner. */
public void setJailer(String jailer) {
this.jailer = jailer;
}
/** Gets whether the prisoner is muted or not. */ /** Gets whether the prisoner is muted or not. */
public boolean isMuted() { public boolean isMuted() {
return this.muted; return this.muted;

View File

@ -1,7 +1,5 @@
package com.graywolf336.jail.command.commands; package com.graywolf336.jail.command.commands;
import java.util.concurrent.TimeUnit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -43,7 +41,7 @@ public class JailCommand implements Command {
*/ */
public boolean execute(JailManager jm, CommandSender sender, String... args) { public boolean execute(JailManager jm, CommandSender sender, String... args) {
if(jm.getJails().size() == 0) { if(jm.getJails().isEmpty()) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS)); sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
return true; return true;
} }
@ -117,10 +115,16 @@ public class JailCommand implements Command {
} }
} }
//If the jailer gave no reason, then let's get the default reason
if(params.reason().isEmpty()) { if(params.reason().isEmpty()) {
params.setReason(jm.getPlugin().getJailIO().getLanguageString(LangString.DEFAULTJAILEDREASON)); params.setReason(jm.getPlugin().getJailIO().getLanguageString(LangString.DEFAULTJAILEDREASON));
} }
//If the config has automatic muting, then let's set them as muted
if(jm.getPlugin().getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath())) {
params.setMuted(true);
}
Player p = jm.getPlugin().getServer().getPlayer(params.player()); Player p = jm.getPlugin().getServer().getPlayer(params.player());
//If the player instance is not null and the player has the permission //If the player instance is not null and the player has the permission
@ -133,10 +137,10 @@ public class JailCommand implements Command {
//Get the jail instance from the name of jail in the params. //Get the jail instance from the name of jail in the params.
Jail j = jm.getJail(params.jail()); Jail j = jm.getJail(params.jail());
Cell c = j.getCell(params.cell()); Cell c = j.getCell(params.cell());
Prisoner pris = new Prisoner(params.player(), params.muted(), time, params.reason()); Prisoner pris = new Prisoner(params.player(), params.muted(), time, sender.getName(), params.reason());
//call the event //call the event
PrePrisonerJailedEvent event = new PrePrisonerJailedEvent(j, c, pris, p, p == null, sender.getName()); PrePrisonerJailedEvent event = new PrePrisonerJailedEvent(j, c, pris, p, p == null, pris.getJailer());
jm.getPlugin().getServer().getPluginManager().callEvent(event); jm.getPlugin().getServer().getPluginManager().callEvent(event);
//check if the event is cancelled //check if the event is cancelled
@ -154,7 +158,14 @@ public class JailCommand implements Command {
c = event.getCell(); c = event.getCell();
pris = event.getPrisoner(); pris = event.getPrisoner();
p = event.getPlayer(); p = event.getPlayer();
String jailer = event.getJailer();
//Player is not online
if(p == null) {
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.OFFLINEJAIL, new String[] { pris.getName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
}else {
//Player *is* online
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ONLINEJAIL, new String[] { pris.getName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
}
try { try {
jm.getPlugin().getPrisonerManager().prepareJail(j, c, p, pris); jm.getPlugin().getPrisonerManager().prepareJail(j, c, p, pris);
@ -163,16 +174,6 @@ public class JailCommand implements Command {
return true; return true;
} }
//Player is not online
if(p == null) {
sender.sendMessage(pris.getName() + " is offline and will be jailed for " + pris.getRemainingTime() + " milliseconds in the jail " + params.jail() + " in the cell " + params.cell() + " and will be muted: " + pris.isMuted() + ".");
sender.sendMessage(pris.getName() + " will be jailed for " + TimeUnit.MINUTES.convert(pris.getRemainingTime(), TimeUnit.MILLISECONDS) + " minutes by " + jailer + ".");
}else {
//Player *is* online
sender.sendMessage(pris.getName() + " is online and will be jailed for " + pris.getRemainingTime() + " milliseconds in the jail " + params.jail() + " in the cell " + params.cell() + " and will be muted: " + pris.isMuted() + ".");
sender.sendMessage(pris.getName() + " will be jailed for " + TimeUnit.MINUTES.convert(pris.getRemainingTime(), TimeUnit.MILLISECONDS) + " minutes by " + jailer + ".");
}
return true; return true;
} }
} }

View File

@ -38,6 +38,10 @@ public enum LangString {
NOEMPTYCELLS ("jailing"), NOEMPTYCELLS ("jailing"),
/** The message sent when a player is not jailed and the sender is trying to see/do something about it. */ /** The message sent when a player is not jailed and the sender is trying to see/do something about it. */
NOTJAILED ("jailing"), NOTJAILED ("jailing"),
/** The message sent to the jailer when they jail someone offline. */
OFFLINEJAIL ("jailing"),
/** The message sent to the jailer when they jail someone who is online. */
ONLINEJAIL ("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. */

View File

@ -1,6 +1,7 @@
package com.graywolf336.jail.enums; package com.graywolf336.jail.enums;
public enum Settings { public enum Settings {
AUTOMATICMUTE("jailing.jail.automaticMute"),
BROADCASTJAILING("jailing.jail.broadcastJailing"), BROADCASTJAILING("jailing.jail.broadcastJailing"),
BLOCKBREAKPENALTY("jailing.during.blockBreakPenalty"), BLOCKBREAKPENALTY("jailing.during.blockBreakPenalty"),
BLOCKBREAKPROTECTION("jailing.during.blockBreakProtection"), BLOCKBREAKPROTECTION("jailing.during.blockBreakProtection"),

View File

@ -31,6 +31,8 @@ language:
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.' noemptycells: '&cNo empty cells were found for %0%, all them appear to be full.'
notjailed: '&c%0% is not jailed.' notjailed: '&c%0% is not jailed.'
offlinejail: '&2%0% is offline and will be jailed when they next come online for %1% minutes.'
onlinejail: '&2%0% was jailed for %1% minutes.'
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%' suggestedcell: '&cAn empty cell in the same jail, %0%, was found: %1%'