Caching options is bad, and so was that way of getting the menu key.

This commit is contained in:
GJ 2013-05-15 15:28:05 -04:00
parent 36bdb8a63e
commit 00dee500e0
4 changed files with 14 additions and 29 deletions

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.config.spout; package com.gmail.nossr50.config.spout;
import org.getspout.spoutapi.keyboard.Keyboard;
import com.gmail.nossr50.config.ConfigLoader; import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.spout.huds.HudType; import com.gmail.nossr50.datatypes.spout.huds.HudType;
@ -34,7 +36,14 @@ public class SpoutConfig extends ConfigLoader {
} }
public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); } public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); }
public String getMenuKey() { return config.getString("Menu.Key", "KEY_M"); } public Keyboard getMenuKey() {
try {
return Keyboard.valueOf(config.getString("Menu.Key", "KEY_M").toUpperCase().trim());
}
catch (IllegalArgumentException ex) {
return Keyboard.KEY_M;
}
}
/* XP Bar */ /* XP Bar */
public boolean getXPBarEnabled() { return config.getBoolean("XP.Bar.Enabled", true); } public boolean getXPBarEnabled() { return config.getBoolean("XP.Bar.Enabled", true); }

View File

@ -11,13 +11,13 @@ import org.getspout.spoutapi.gui.Button;
import org.getspout.spoutapi.gui.ScreenType; import org.getspout.spoutapi.gui.ScreenType;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.config.spout.SpoutConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.spout.buttons.McMMOButton; import com.gmail.nossr50.datatypes.spout.buttons.McMMOButton;
import com.gmail.nossr50.datatypes.spout.huds.McMMOHud; import com.gmail.nossr50.datatypes.spout.huds.McMMOHud;
import com.gmail.nossr50.datatypes.spout.popups.McMMOMenu; import com.gmail.nossr50.datatypes.spout.popups.McMMOMenu;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.spout.SpoutUtils;
public class SpoutListener implements Listener { public class SpoutListener implements Listener {
@ -32,7 +32,7 @@ public class SpoutListener implements Listener {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(spoutPlayer); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(spoutPlayer);
// TODO: Add custom titles based on skills // TODO: Add custom titles based on skills
if (SpoutUtils.showPowerLevel) { if (SpoutConfig.getInstance().getShowPowerLevel()) {
spoutPlayer.setTitle(LocaleLoader.getString("Spout.Title", spoutPlayer.getTitle(), mcMMOPlayer.getPowerLevel())); spoutPlayer.setTitle(LocaleLoader.getString("Spout.Title", spoutPlayer.getTitle(), mcMMOPlayer.getPowerLevel()));
} }
@ -81,7 +81,7 @@ public class SpoutListener implements Listener {
return; return;
} }
if (event.getKey() == SpoutUtils.menuKey) { if (event.getKey() == SpoutConfig.getInstance().getMenuKey()) {
McMMOHud spoutHud = UserManager.getPlayer(spoutPlayer).getProfile().getSpoutHud(); McMMOHud spoutHud = UserManager.getPlayer(spoutPlayer).getProfile().getSpoutHud();
if (!spoutHud.isMenuOpened()) { if (!spoutHud.isMenuOpened()) {

View File

@ -321,7 +321,6 @@ public class mcMMO extends JavaPlugin {
spoutEnabled = true; spoutEnabled = true;
SpoutConfig.getInstance(); SpoutConfig.getInstance();
SpoutUtils.setupSpoutConfigs();
SpoutUtils.registerCustomEvent(); SpoutUtils.registerCustomEvent();
SpoutUtils.preCacheFiles(); SpoutUtils.preCacheFiles();
SpoutUtils.reloadSpoutPlayers(); // Handle spout players after a /reload SpoutUtils.reloadSpoutPlayers(); // Handle spout players after a /reload

View File

@ -13,13 +13,11 @@ import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent; import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
import org.getspout.spoutapi.keyboard.Keyboard;
import org.getspout.spoutapi.player.FileManager; import org.getspout.spoutapi.player.FileManager;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.spout.SpoutConfig;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.listeners.SpoutListener; import com.gmail.nossr50.listeners.SpoutListener;
@ -37,10 +35,8 @@ public class SpoutUtils {
public final static String hudRetroDirectory = hudDirectory + "Retro" + File.separator; public final static String hudRetroDirectory = hudDirectory + "Retro" + File.separator;
public final static String soundDirectory = spoutDirectory + "Sound" + File.separator; public final static String soundDirectory = spoutDirectory + "Sound" + File.separator;
public static boolean showPowerLevel;
private final static SpoutListener spoutListener = new SpoutListener(); private final static SpoutListener spoutListener = new SpoutListener();
public static Keyboard menuKey; // public static Keyboard menuKey;
/** /**
* Write file to disk. * Write file to disk.
@ -148,25 +144,6 @@ public class SpoutUtils {
writeFile("level.wav", soundDirectory); writeFile("level.wav", soundDirectory);
} }
/**
* Setup Spout config options
*/
public static void setupSpoutConfigs() {
showPowerLevel = SpoutConfig.getInstance().getShowPowerLevel();
String temp = SpoutConfig.getInstance().getMenuKey();
for (Keyboard x : Keyboard.values()) {
if (x.toString().equalsIgnoreCase(temp)) {
menuKey = x;
}
}
if (menuKey == null) {
mcMMO.p.getLogger().warning("Invalid KEY for Menu.Key, using KEY_M");
menuKey = Keyboard.KEY_M;
}
}
/** /**
* Get all the Spout files in the Resources folder. * Get all the Spout files in the Resources folder.
* *