From e402797c54d073d8aecf03178090afec2c1c6b84 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 10 Oct 2011 01:59:36 +0200 Subject: [PATCH] Removing the small ugly language file --- src/com/massivecraft/factions/zcore/Lang.java | 11 +++++++++++ .../massivecraft/factions/zcore/MCommand.java | 6 +++--- .../massivecraft/factions/zcore/MPlugin.java | 17 +---------------- .../factions/zcore/util/PermUtil.java | 5 +++-- .../factions/zcore/util/TextUtil.java | 17 +++-------------- 5 files changed, 21 insertions(+), 35 deletions(-) create mode 100644 src/com/massivecraft/factions/zcore/Lang.java diff --git a/src/com/massivecraft/factions/zcore/Lang.java b/src/com/massivecraft/factions/zcore/Lang.java new file mode 100644 index 00000000..86ef5c09 --- /dev/null +++ b/src/com/massivecraft/factions/zcore/Lang.java @@ -0,0 +1,11 @@ +package com.massivecraft.factions.zcore; + +public class Lang +{ + public static final String permForbidden = "You don't have permission to %s."; + public static final String permDoThat = "do that"; + + public static final String commandSenderMustBePlayer = "This command can only be used by ingame players."; + public static final String commandToFewArgs = "To few arguments. Use like this:"; + public static final String commandToManyArgs = "Strange argument \"

%s\". Use the command like this:"; +} diff --git a/src/com/massivecraft/factions/zcore/MCommand.java b/src/com/massivecraft/factions/zcore/MCommand.java index 1f978ec6..a2c30aeb 100644 --- a/src/com/massivecraft/factions/zcore/MCommand.java +++ b/src/com/massivecraft/factions/zcore/MCommand.java @@ -173,7 +173,7 @@ public abstract class MCommand { if (informSenderIfNot) { - sender.sendMessage(p.txt.get("command.sender_must_me_player")); + sendMessageParsed(Lang.commandSenderMustBePlayer); } return false; } @@ -192,7 +192,7 @@ public abstract class MCommand { if (sender != null) { - sender.sendMessage(p.txt.get("command.to_few_args")); + sendMessageParsed(Lang.commandToFewArgs); sender.sendMessage(this.getUseageTemplate()); } return false; @@ -204,7 +204,7 @@ public abstract class MCommand { // Get the to many string slice List theToMany = args.subList(this.requiredArgs.size() + this.optionalArgs.size(), args.size()); - sender.sendMessage(String.format(p.txt.get("command.to_many_args"), TextUtil.implode(theToMany, " "))); + sendMessageParsed(Lang.commandToManyArgs, TextUtil.implode(theToMany, " ")); sender.sendMessage(this.getUseageTemplate()); } return false; diff --git a/src/com/massivecraft/factions/zcore/MPlugin.java b/src/com/massivecraft/factions/zcore/MPlugin.java index 00ffd938..34ed9fd5 100644 --- a/src/com/massivecraft/factions/zcore/MPlugin.java +++ b/src/com/massivecraft/factions/zcore/MPlugin.java @@ -132,16 +132,6 @@ public abstract class MPlugin extends JavaPlugin // These are not supposed to be used directly. // They are loaded and used through the TextUtil instance for the plugin. public Map tags = new LinkedHashMap(); - public Map lang = new LinkedHashMap(); - - public void addLang() - { - this.lang.put("perm.forbidden", "You don't have permission to %s."); - this.lang.put("perm.dothat", "do that"); - this.lang.put("command.sender_must_me_player", "This command can only be used by ingame players."); - this.lang.put("command.to_few_args", "To few arguments. Use like this:"); - this.lang.put("command.to_many_args", "Strange argument \"

%s\". Use the command like this:"); - } public void addTags() { @@ -175,20 +165,15 @@ public abstract class MPlugin extends JavaPlugin public void initTXT() { - this.addLang(); this.addTags(); Type type = new TypeToken>(){}.getType(); - Map langFromFile = this.persist.load(type, "lang"); - if (langFromFile != null) this.lang.putAll(langFromFile); - this.persist.save(this.lang, "lang"); - Map tagsFromFile = this.persist.load(type, "tags"); if (tagsFromFile != null) this.tags.putAll(tagsFromFile); this.persist.save(this.tags, "tags"); - this.txt = new TextUtil(this.tags, this.lang); + this.txt = new TextUtil(this.tags); } diff --git a/src/com/massivecraft/factions/zcore/util/PermUtil.java b/src/com/massivecraft/factions/zcore/util/PermUtil.java index b5e0fe5f..2853d2ae 100644 --- a/src/com/massivecraft/factions/zcore/util/PermUtil.java +++ b/src/com/massivecraft/factions/zcore/util/PermUtil.java @@ -12,6 +12,7 @@ import org.bukkit.plugin.Plugin; import ru.tehkode.permissions.PermissionManager; import ru.tehkode.permissions.bukkit.PermissionsEx; +import com.massivecraft.factions.zcore.Lang; import com.massivecraft.factions.zcore.MPlugin; import com.nijiko.permissions.PermissionHandler; import com.nijikokun.bukkit.Permissions.Permissions; @@ -33,7 +34,7 @@ public class PermUtil { public String getForbiddenMessage(String perm) { - return p.txt.get("perm.forbidden", getPermissionDescription(perm)); + return p.txt.parse(Lang.permForbidden, getPermissionDescription(perm)); } /** @@ -69,7 +70,7 @@ public class PermUtil { String desc = permissionDescriptions.get(perm); if (desc == null) { - return p.txt.get("perm.dothat"); + return Lang.permDoThat; } return desc; } diff --git a/src/com/massivecraft/factions/zcore/util/TextUtil.java b/src/com/massivecraft/factions/zcore/util/TextUtil.java index 6707ec84..39be5c98 100644 --- a/src/com/massivecraft/factions/zcore/util/TextUtil.java +++ b/src/com/massivecraft/factions/zcore/util/TextUtil.java @@ -10,24 +10,18 @@ import org.bukkit.Material; public class TextUtil { private Map tags = new HashMap(); - private Map lang = new HashMap(); - public TextUtil(Map tags, Map lang) + public TextUtil(Map tags) { if (tags != null) { this.tags.putAll(tags); } - - if (lang != null) - { - this.lang.putAll(lang); - } } // Get is supposed to be the way we reach registered lang // TODO: Is the parse - public String get(String name) + /*public String get(String name) { String str = lang.get(name); if (str == null) str = name; @@ -41,7 +35,7 @@ public class TextUtil if (str == null) str = name; return this.parse(str, args); - } + }*/ // Parse is used to handle non registered text public String parse(String str, Object... args) @@ -58,11 +52,6 @@ public class TextUtil { return tags; } - - public Map getLang() - { - return lang; - } public String tags(String str) {