From 3f27410a7a0f6face00c15009d648bfc3650a382 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Wed, 1 Jan 2014 17:39:21 -0600 Subject: [PATCH] Handcuffing messages are now fully customizable via the language file --- .../java/com/graywolf336/jail/JailIO.java | 2 +- .../java/com/graywolf336/jail/JailMain.java | 2 +- .../command/commands/HandCuffCommand.java | 16 ++--- .../command/commands/UnHandCuffCommand.java | 10 ++-- .../graywolf336/jail/enums/LangString.java | 58 ++++++++++++++++--- src/main/resources/en.yml | 25 +++++--- 6 files changed, 84 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/JailIO.java b/src/main/java/com/graywolf336/jail/JailIO.java index 933c3ac..e21eb28 100644 --- a/src/main/java/com/graywolf336/jail/JailIO.java +++ b/src/main/java/com/graywolf336/jail/JailIO.java @@ -91,7 +91,7 @@ public class JailIO { * @return The message as a colorful message or an empty message if that isn't defined in the language file. */ public String getLanguageString(LangString langString, String... variables) { - String message = lang.getString("language." + langString.toString().toLowerCase()); + String message = lang.getString("language." + langString.getSection() + langString.getName()); if(message == null) return ""; diff --git a/src/main/java/com/graywolf336/jail/JailMain.java b/src/main/java/com/graywolf336/jail/JailMain.java index 46469f9..ae6eb93 100644 --- a/src/main/java/com/graywolf336/jail/JailMain.java +++ b/src/main/java/com/graywolf336/jail/JailMain.java @@ -42,9 +42,9 @@ public class JailMain extends JavaPlugin { pm = new PrisonerManager(this); PluginManager plm = this.getServer().getPluginManager(); - plm.registerEvents(new HandCuffListener(this), this); plm.registerEvents(new BlockListener(), this); plm.registerEvents(new EntityListener(), this); + plm.registerEvents(new HandCuffListener(this), this); plm.registerEvents(new PlayerListener(this), this); debug = getConfig().getBoolean(Settings.DEBUG.getPath()); diff --git a/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java b/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java index dd8c577..1feb7b3 100644 --- a/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java +++ b/src/main/java/com/graywolf336/jail/command/commands/HandCuffCommand.java @@ -1,12 +1,12 @@ package com.graywolf336.jail.command.commands; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.graywolf336.jail.JailManager; import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.CommandInfo; +import com.graywolf336.jail.enums.LangString; @CommandInfo( maxArgs = 1, @@ -21,19 +21,19 @@ public class HandCuffCommand implements Command { Player player = jm.getPlugin().getServer().getPlayer(args[0]); if(player == null) { - sender.sendMessage(ChatColor.RED + "That player is not online!"); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE)); }else if(player.hasPermission("jail.cantbehandcuffed")) { - sender.sendMessage(ChatColor.RED + "That player can't be handcuffed."); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEHANDCUFFED, new String[] { player.getName() })); }else if(jm.isPlayerJailed(player.getName())) { - sender.sendMessage(ChatColor.RED + "That player is currently jailed, you can't handcuff a prisoner."); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CURRENTLYJAILEDHANDCUFF, new String[] { player.getName() })); }else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getName())) { - sender.sendMessage(ChatColor.GREEN + "That player is already handcuffed, releasing them now!"); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() })); jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getName()); - player.sendMessage(ChatColor.GREEN + "Your handcuffs have been rmeoved."); + player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED)); }else { jm.getPlugin().getHandCuffManager().addHandCuffs(player.getName(), player.getLocation()); - sender.sendMessage(ChatColor.BLUE + args[0] + ChatColor.GREEN + " has been handcuffed!"); - player.sendMessage(ChatColor.RED + "You've been handcuffed."); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSON, new String[] { player.getName() })); + player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFED)); } return true; diff --git a/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java b/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java index 6065f71..4c5b468 100644 --- a/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java +++ b/src/main/java/com/graywolf336/jail/command/commands/UnHandCuffCommand.java @@ -1,12 +1,12 @@ package com.graywolf336.jail.command.commands; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.graywolf336.jail.JailManager; import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.CommandInfo; +import com.graywolf336.jail.enums.LangString; @CommandInfo( maxArgs = 1, @@ -21,13 +21,13 @@ public class UnHandCuffCommand implements Command { Player player = jm.getPlugin().getServer().getPlayerExact(args[0]); if(player == null) { - sender.sendMessage(ChatColor.RED + "That player is not online!"); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE)); }else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getName())) { - sender.sendMessage(ChatColor.GREEN + "Releasing them now!"); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() })); jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getName()); - player.sendMessage(ChatColor.GREEN + "Your handcuffs have been rmeoved."); + player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED)); }else { - sender.sendMessage(ChatColor.BLUE + player.getName() + ChatColor.RED + " doesn't have any handcuffs to remove!"); + sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTHANDCUFFED, new String[] { player.getName() })); } return true; diff --git a/src/main/java/com/graywolf336/jail/enums/LangString.java b/src/main/java/com/graywolf336/jail/enums/LangString.java index 99079e7..555d782 100644 --- a/src/main/java/com/graywolf336/jail/enums/LangString.java +++ b/src/main/java/com/graywolf336/jail/enums/LangString.java @@ -1,18 +1,62 @@ package com.graywolf336.jail.enums; public enum LangString { + //Jailing section + /** The message sent when we broadcast/log the message for time below -1. */ - BROADCASTMESSAGEFOREVER, + BROADCASTMESSAGEFOREVER ("jailing"), /** The message sent when we broadcast/log the message for any time above -1. */ - BROADCASTMESSAGEFORMINUTES, + BROADCASTMESSAGEFORMINUTES ("jailing"), /** The message sent when trying to jail someone who can't be jailed by permission. */ - CANTBEJAILED, + CANTBEJAILED ("jailing"), /** The message sent when someone is jailed without a reason. */ - DEFAULTJAILEDREASON, + DEFAULTJAILEDREASON ("jailing"), /** The message sent when players are jailed without a reason. */ - JAILED, + JAILED ("jailing"), /** The message sent when players are jailed with a reason. */ - JAILEDWITHREASON, + JAILEDWITHREASON ("jailing"), /** The message sent when players are released from jail. */ - UNJAILED; + UNJAILED ("jailing"), + + //Handcuffing section + + /** The message setnt to the sender when trying to handcuff someone who can't be. */ + CANTBEHANDCUFFED ("handcuffing"), + CURRENTLYJAILEDHANDCUFF ("handcuffing", "currentlyjailed"), + /** The message sent to the sender when the player doesn't have any handcuffs. */ + NOTHANDCUFFED ("handcuffing"), + /** The message sent to the handcuff on a successful handcuffing. */ + HANDCUFFSON ("handcuffing"), + /** The message sent when players are handcuffed. */ + HANDCUFFED ("handcuffing"), + /** The message sent to the player who has release handcuffs. */ + HANDCUFFSRELEASED ("handcuffing"), + /** The message sent when the player has his/her handcuffs removed. */ + UNHANDCUFFED ("handcuffing"), + + //General section, used by different parts + + /** The message sent whenever an online player is required but not found. */ + PLAYERNOTONLINE ("general"); + + private String section, name; + + LangString(String section) { + this.section = section; + } + + LangString(String section, String name) { + this.section = section; + this.name = name; + } + + /** Gets the section in the language file this is located at. */ + public String getSection() { + return this.section; + } + + /** Returns the name of this enum if a custom one isn't present. */ + public String getName() { + return (name == null ? this.toString().toLowerCase() : name); + } } diff --git a/src/main/resources/en.yml b/src/main/resources/en.yml index 36b1326..ad2a353 100644 --- a/src/main/resources/en.yml +++ b/src/main/resources/en.yml @@ -1,8 +1,19 @@ language: - jailed: "&cYou have been jailed!" - jailedwithreason: "&cYou have been jailed for: %0%" - unjailed: "&2You have been released! Please respect the server rules." - broadcastmessageforever: "&9%0% has been jailed forever." - broadcastmessageforminutes: "&9%0% has been jailed for %1% minutes." - cantbejailed: "&cThat player can't be jailed, due to permissions." - defaultjailedreason: "Breaking the rules." \ No newline at end of file + general: + playernotonline: '&cThat player is not online!' + jailing: + broadcastmessageforever: '&9%0% has been jailed forever.' + broadcastmessageforminutes: '&9%0% has been jailed for %1% minutes.' + cantbejailed: '&cThat player can not be jailed.' + defaultjailedreason: Breaking the rules. + jailed: '&cYou have been jailed!' + jailedwithreason: '&cYou have been jailed for: %0%' + unjailed: '&2You have been released! Please respect the server rules.' + handcuffing: + cantbehandcuffed: '&9%0% &ccan not be handcuffed.' + currentlyjailed: '&9%0% &cis currently jailed, you can not handcuff a prisoner.' + nothandcuffed: '&9%0% &cdoes not have any handcuffs to remove!' + handcuffson: '&9%0% &ahas been handcuffed!' + handcuffed: '&cYou have been handcuffed.' + handcuffsreleased: '&9%0% &ahas been released from their handcuffs.' + unhandcuffed: '&aYour handcuffs have been removed.' \ No newline at end of file