diff --git a/src/main/java/com/gmail/nossr50/commands/spout/MchudCommand.java b/src/main/java/com/gmail/nossr50/commands/spout/MchudCommand.java index f52501576..772744aa4 100644 --- a/src/main/java/com/gmail/nossr50/commands/spout/MchudCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/spout/MchudCommand.java @@ -14,16 +14,15 @@ public class MchudCommand extends SpoutCommand { @Override protected boolean oneArgument(Command command, CommandSender sender, String[] args) { - for (HudType hudType : HudType.values()) { - if (hudType.toString().equalsIgnoreCase(args[0])) { - playerProfile.setHudType(hudType); - spoutHud.initializeXpBar(); - spoutHud.updateXpBar(); - return true; - } + try { + playerProfile.setHudType(HudType.valueOf(args[0].toUpperCase().trim())); + spoutHud.initializeXpBar(); + spoutHud.updateXpBar(); + return true; + } + catch (IllegalArgumentException ex) { + sender.sendMessage(LocaleLoader.getString("Commands.mchud.Invalid")); + return true; } - - sender.sendMessage(LocaleLoader.getString("Commands.mchud.Invalid")); - return true; } } diff --git a/src/main/java/com/gmail/nossr50/config/spout/SpoutConfig.java b/src/main/java/com/gmail/nossr50/config/spout/SpoutConfig.java index 4d3b66f46..5a61d93a6 100644 --- a/src/main/java/com/gmail/nossr50/config/spout/SpoutConfig.java +++ b/src/main/java/com/gmail/nossr50/config/spout/SpoutConfig.java @@ -6,11 +6,9 @@ import com.gmail.nossr50.datatypes.spout.huds.HudType; public class SpoutConfig extends ConfigLoader { private static SpoutConfig instance; - public HudType defaultHudType; private SpoutConfig() { super("spout.yml"); - loadKeys(); } public static SpoutConfig getInstance() { @@ -24,17 +22,14 @@ public class SpoutConfig extends ConfigLoader { @Override protected void loadKeys() { // Setup default HUD - String temp = config.getString("Spout.HUD.Default", "STANDARD"); + } - for (HudType hudType : HudType.values()) { - if (hudType.toString().equalsIgnoreCase(temp)) { - defaultHudType = hudType; - break; - } + public HudType getDefaultHudType() { + try { + return HudType.valueOf(config.getString("Spout.HUD.Default", "STANDARD").toUpperCase().trim()); } - - if (defaultHudType == null) { - defaultHudType = HudType.STANDARD; + catch (IllegalArgumentException ex) { + return HudType.STANDARD; } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java index 4c1395c99..79013b5d3 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java @@ -46,7 +46,7 @@ public class PlayerProfile { mobHealthbarType = Config.getInstance().getMobHealthbarDefault(); if (mcMMO.spoutEnabled) { - hudType = SpoutConfig.getInstance().defaultHudType; + hudType = SpoutConfig.getInstance().getDefaultHudType(); } else { hudType = HudType.DISABLED; @@ -94,11 +94,7 @@ public class PlayerProfile { DatabaseManager.write("INSERT INTO " + tablePrefix + "huds (user_id) VALUES (" + userId + ")"); } else { - for (HudType type : HudType.values()) { - if (type.toString().equalsIgnoreCase(huds.get(1).get(0))) { - hudType = type; - } - } + hudType = HudType.valueOf(huds.get(1).get(0)); } mobHealthbarType = MobHealthbarType.valueOf(DatabaseManager.read("SELECT mobhealthbar FROM " + tablePrefix + "huds WHERE user_id = " + userId).get(1).get(0)); @@ -312,11 +308,7 @@ public class PlayerProfile { } if (character.length > 33) { - for (HudType type : HudType.values()) { - if (type.toString().equalsIgnoreCase(character[33])) { - hudType = type; - } - } + hudType = HudType.valueOf(character[33]); } if (character.length > 34) {