diff --git a/Changelog.txt b/Changelog.txt index 4d8d3b3f0..75a97c82d 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -12,6 +12,8 @@ Version 1.3.10-dev + Added ability for custom blocks to drop a range of items. + Added Ability API functions + Added 50% & 150% XP boost perks + = Fixed "GenericLabel belonging to mcMMO..." message + = Fixed menu exit button not working = Fixed Repair enchant downgrade not working = Fixed NPE caused by Spout players after a /reload = Fixed ConcurrentModificationException on world unload diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java index 66a3900ea..38e591f7a 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java @@ -16,6 +16,7 @@ import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.util.Users; public class McremoveCommand implements CommandExecutor { @@ -102,10 +103,12 @@ public class McremoveCommand implements CommandExecutor { PlayerProfile playerProfile = Users.getProfile(player); if (playerProfile != null) { + playerProfile.getSpoutHud().removeWidgets(); Users.remove(player.getName()); if (player.isOnline()) { Users.addUser((Player) player); + SpoutStuff.reloadSpoutPlayer((Player) player); } } 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 f897af818..1851b5aea 100644 --- a/src/main/java/com/gmail/nossr50/commands/spout/MchudCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/spout/MchudCommand.java @@ -9,20 +9,13 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.config.SpoutConfig; -import com.gmail.nossr50.datatypes.HUDType; -import com.gmail.nossr50.datatypes.HUDmmo; +import com.gmail.nossr50.datatypes.HudType; +import com.gmail.nossr50.datatypes.SpoutHud; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.util.Users; public class MchudCommand implements CommandExecutor { - private final mcMMO plugin; - - public MchudCommand (mcMMO plugin) { - this.plugin = plugin; - } - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { String usage = ChatColor.RED + "Proper usage is /mchud "; //TODO: Locale @@ -40,33 +33,24 @@ public class MchudCommand implements CommandExecutor { switch (args.length) { case 1: Player player = (Player) sender; - PlayerProfile PP = Users.getProfile(player); - HUDType hud; + PlayerProfile playerProfile = Users.getProfile(player); - if (args[0].equalsIgnoreCase("disabled")) { - hud = HUDType.DISABLED; - } - else if (args[0].equalsIgnoreCase("standard")) { - hud = HUDType.STANDARD; - } - else if (args[0].equalsIgnoreCase("small")) { - hud = HUDType.SMALL; - } - else if (args[0].equalsIgnoreCase("retro")) { - hud = HUDType.RETRO; - } - else { - player.sendMessage(invalid); - return true; - } - - if (SpoutStuff.playerHUDs.containsKey(player)) { - SpoutStuff.playerHUDs.get(player).resetHUD(); - SpoutStuff.playerHUDs.remove(player); - PP.setHUDType(hud); - SpoutStuff.playerHUDs.put(player, new HUDmmo(player, plugin)); + for (HudType hudType : HudType.values()) { + if (hudType.toString().equalsIgnoreCase(args[0])) { + playerProfile.setHudType(hudType); + + SpoutHud spoutHud = playerProfile.getSpoutHud(); + + if (spoutHud != null) { + spoutHud.initializeXpBar(); + spoutHud.updateXpBar(); + } + + return true; + } } + player.sendMessage(invalid); return true; default: diff --git a/src/main/java/com/gmail/nossr50/commands/spout/XplockCommand.java b/src/main/java/com/gmail/nossr50/commands/spout/XplockCommand.java index 57751c4ba..38c3325b6 100644 --- a/src/main/java/com/gmail/nossr50/commands/spout/XplockCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/spout/XplockCommand.java @@ -13,7 +13,6 @@ import com.gmail.nossr50.config.SpoutConfig; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Skills; @@ -34,49 +33,48 @@ public class XplockCommand implements CommandExecutor { } Player player = (Player) sender; - PlayerProfile PP = Users.getProfile(player); + PlayerProfile playerProfile = Users.getProfile(player); switch (args.length) { case 0: - if (PP.getXpBarLocked()) { - PP.toggleXpBarLocked(); + if (playerProfile.getXpBarLocked()) { + playerProfile.toggleXpBarLocked(); player.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked")); return true; } - SkillType lastGained = PP.getLastGained(); + SkillType lastGained = playerProfile.getLastGained(); if (lastGained != null) { - PP.toggleXpBarLocked(); - PP.setSkillLock(lastGained); + playerProfile.toggleXpBarLocked(); + playerProfile.setSkillLock(lastGained); player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(lastGained.toString()) })); - return true; } else { player.sendMessage(usage); - return true; } + return true; + case 1: if (Skills.isSkill(args[0])) { if (Permissions.getInstance().permission(player, "mcmmo.skills." + args[0].toLowerCase())) { - PP.setXpBarLocked(true); - PP.setSkillLock(Skills.getSkillType(args[0])); - SpoutStuff.updateXpBar(player); + playerProfile.setXpBarLocked(true); + playerProfile.setSkillLock(Skills.getSkillType(args[0])); + playerProfile.updateXpBar(); player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", new Object[] { Misc.getCapitalized(args[0]) })); - return true; } else { player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission")); - return true; } } else { player.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); - return true; } + return true; + default: player.sendMessage(usage); return true; diff --git a/src/main/java/com/gmail/nossr50/config/SpoutConfig.java b/src/main/java/com/gmail/nossr50/config/SpoutConfig.java index 25930c1cf..721a15c17 100644 --- a/src/main/java/com/gmail/nossr50/config/SpoutConfig.java +++ b/src/main/java/com/gmail/nossr50/config/SpoutConfig.java @@ -1,7 +1,7 @@ package com.gmail.nossr50.config; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.datatypes.HUDType; +import com.gmail.nossr50.datatypes.HudType; public class SpoutConfig extends ConfigLoader { private static SpoutConfig instance; @@ -15,7 +15,7 @@ public class SpoutConfig extends ConfigLoader { return instance; } - public HUDType defaulthud; + public HudType defaultHudType; private SpoutConfig(mcMMO plugin) { super(plugin, "spout.yml"); @@ -85,14 +85,15 @@ public class SpoutConfig extends ConfigLoader { // Setup default HUD String temp = config.getString("Spout.HUD.Default", "STANDARD"); - for (HUDType x : HUDType.values()) { - if (x.toString().equalsIgnoreCase(temp.toString())) { - defaulthud = x; + for (HudType hudType : HudType.values()) { + if (hudType.toString().equalsIgnoreCase(temp.toString())) { + defaultHudType = hudType; + break; } } - if (defaulthud == null) { - defaulthud = HUDType.STANDARD; + if (defaultHudType == null) { + defaultHudType = HudType.STANDARD; } } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/HUDType.java b/src/main/java/com/gmail/nossr50/datatypes/HUDType.java index 1fa151d8f..aca3a9bd3 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/HUDType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/HUDType.java @@ -1,8 +1,12 @@ package com.gmail.nossr50.datatypes; -public enum HUDType { +public enum HudType { DISABLED, STANDARD, SMALL, RETRO; + + public HudType getNext() { + return values()[(ordinal() + 1) % values().length]; + } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/HUDmmo.java b/src/main/java/com/gmail/nossr50/datatypes/HUDmmo.java deleted file mode 100644 index 2259e82c4..000000000 --- a/src/main/java/com/gmail/nossr50/datatypes/HUDmmo.java +++ /dev/null @@ -1,417 +0,0 @@ -package com.gmail.nossr50.datatypes; - -import org.bukkit.entity.Player; -import org.getspout.spoutapi.SpoutManager; -import org.getspout.spoutapi.gui.Color; -import org.getspout.spoutapi.gui.GenericGradient; -import org.getspout.spoutapi.gui.GenericTexture; -import org.getspout.spoutapi.gui.RenderPriority; -import org.getspout.spoutapi.gui.Widget; -import org.getspout.spoutapi.player.SpoutPlayer; - -import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.config.SpoutConfig; -import com.gmail.nossr50.spout.SpoutStuff; -import com.gmail.nossr50.util.Misc; -import com.gmail.nossr50.util.Users; - -public class HUDmmo { - private int center_x = 427 / 2; - - private String playerName; - private final mcMMO plugin; - - private Widget xpbar = null; - private GenericGradient xpfill = null; - private GenericGradient xpbg = null; - private GenericGradient xpicon_bg = null; - private GenericGradient xpicon_border = null; - private GenericTexture xpicon = null; - - public HUDmmo(Player player, mcMMO plugin) { - this.playerName = player.getName(); - this.plugin = plugin; - initializeHUD(player); - } - - /** - * Initialize the HUD. - * - * @param player Player whose HUD to initialize - */ - public void initializeHUD(Player player) { - HUDType type = Users.getProfile(player).getHUDType(); - SpoutPlayer sPlayer = SpoutManager.getPlayer(player); - - switch (type) { - case RETRO: - initializeXpBarDisplayRetro(sPlayer); - break; - - case STANDARD: - initializeXpBarDisplayStandard(sPlayer); - break; - - case SMALL: - initializeXpBarDisplaySmall(sPlayer); - break; - - case DISABLED: - break; - - default: - break; - } - } - - /** - * Update the XP bar. - * - * @param type Type of XP bar - * @param player Player whose XP bar to update - */ - public void updateXpBarDisplay(HUDType type, Player player) { - PlayerProfile PP = Users.getProfile(player); - - switch (type) { - case RETRO: - updateXpBarRetro(player, PP); - break; - - case STANDARD: - updateXpBarStandard(player, PP); - break; - - case SMALL: - updateXpBarStandard(player, PP); - break; - - case DISABLED: - break; - - default: - break; - } - } - - /** - * Reset a player's HUD. - */ - public void resetHUD() { - SpoutPlayer sPlayer = SpoutStuff.getSpoutPlayer(playerName); - - if (sPlayer != null) { - sPlayer.getMainScreen().removeWidgets(plugin); - - //Reset the objects - xpbar = null; - xpfill = null; - xpbg = null; - xpicon = null; - - sPlayer.getMainScreen().setDirty(true); - } - } - - /** - * Initialize Retro XP bar. - * - * @param sPlayer Player to initialize XP bar for - */ - private void initializeXpBarDisplayRetro(SpoutPlayer sPlayer) { - Color border = new Color((float) SpoutConfig.getInstance().getRetroHUDXPBorderRed(), (float) SpoutConfig.getInstance().getRetroHUDXPBorderGreen(), (float) SpoutConfig.getInstance().getRetroHUDXPBorderBlue(), 1f); - Color green = new Color(0f, 1f, 0f, 1f); - Color background = new Color((float) SpoutConfig.getInstance().getRetroHUDXPBackgroundRed(), (float) SpoutConfig.getInstance().getRetroHUDXPBackgroundGreen(), (float) SpoutConfig.getInstance().getRetroHUDXPBackgroundBlue(), 1f); - Color darkbg = new Color(0.2f, 0.2f, 0.2f, 1f); - - xpicon = new GenericTexture(); - xpbar = new GenericGradient(); - xpfill = new GenericGradient(); - xpbg = new GenericGradient(); - - xpicon_bg = new GenericGradient(); - xpicon_border = new GenericGradient(); - - xpicon_bg.setBottomColor(darkbg); - xpicon_bg.setTopColor(darkbg); - xpicon_bg.setWidth(4); - xpicon_bg.setHeight(4); - xpicon_bg.setPriority(RenderPriority.High); - xpicon_bg.setX(142); - xpicon_bg.setY(10); - xpicon_bg.setDirty(true); - - xpicon_border.setBottomColor(border); - xpicon_border.setTopColor(border); - xpicon_border.setWidth(6); - xpicon_border.setHeight(6); - xpicon_border.setPriority(RenderPriority.Highest); - xpicon_border.setX(141); - xpicon_border.setY(9); - xpicon_border.setDirty(true); - - xpicon.setWidth(6); - xpicon.setHeight(6); - xpicon.setX(141); - xpicon.setY(9); - xpicon.setPriority(RenderPriority.Normal); - xpicon.setDirty(true); - xpicon.setUrl("Icon_r.png"); - - xpbar.setWidth(128); - xpbar.setHeight(4); - xpbar.setX(149); - xpbar.setY(10); - ((GenericGradient) xpbar).setBottomColor(border); - ((GenericGradient) xpbar).setTopColor(border); - xpbar.setPriority(RenderPriority.Highest); - xpbar.setDirty(true); - - xpfill.setWidth(0); - xpfill.setHeight(2); - xpfill.setX(150); - xpfill.setY(11); - xpfill.setBottomColor(green); - xpfill.setTopColor(green); - xpfill.setPriority(RenderPriority.Lowest); - xpfill.setDirty(true); - - xpbg.setWidth(126); - xpbg.setHeight(2); - xpbg.setX(150); - xpbg.setY(11); - xpbg.setBottomColor(background); - xpbg.setTopColor(background); - xpbg.setPriority(RenderPriority.Low); - xpbg.setDirty(true); - - if (SpoutConfig.getInstance().getXPBarEnabled()) { - sPlayer.getMainScreen().attachWidget(plugin, xpbar); - sPlayer.getMainScreen().attachWidget(plugin, xpfill); - sPlayer.getMainScreen().attachWidget(plugin, xpbg); - - if (SpoutConfig.getInstance().getXPBarIconEnabled()) { - sPlayer.getMainScreen().attachWidget(plugin, xpicon); - sPlayer.getMainScreen().attachWidget(plugin, xpicon_bg); - sPlayer.getMainScreen().attachWidget(plugin, xpicon_border); - } - } - - sPlayer.getMainScreen().setDirty(true); - } - - /** - * Initialize Standard XP bar. - * - * @param sPlayer Player to initialize XP bar for - */ - public void initializeXpBarDisplayStandard(SpoutPlayer sPlayer) { - if (SpoutConfig.getInstance().getXPBarEnabled()) { - xpbar = new GenericTexture(); - - ((GenericTexture) xpbar).setUrl("xpbar_inc000.png"); - - xpbar.setX(SpoutConfig.getInstance().getXPBarXPosition()); - xpbar.setY(SpoutConfig.getInstance().getXPBarYPosition()); - xpbar.setHeight(8); - xpbar.setWidth(256); - xpbar.setPriority(RenderPriority.Lowest); - - sPlayer.getMainScreen().attachWidget(plugin, xpbar); - - if (SpoutConfig.getInstance().getXPBarIconEnabled()) { - xpicon = new GenericTexture(); - - xpicon.setUrl("Icon.png"); - xpicon.setHeight(16); - xpicon.setWidth(32); - xpicon.setX(SpoutConfig.getInstance().getXPIconXPosition()); - xpicon.setY(SpoutConfig.getInstance().getXPIconYPosition()); - xpicon.setPriority(RenderPriority.High); - xpicon.setDirty(true); - - sPlayer.getMainScreen().attachWidget(plugin, xpicon); - } - } - - sPlayer.getMainScreen().setDirty(true); - } - - /** - * Initialize Small XP bar. - * - * @param sPlayer Player to initialize XP bar for - */ - private void initializeXpBarDisplaySmall(SpoutPlayer sPlayer) { - if (SpoutConfig.getInstance().getXPBarEnabled()) { - xpbar = new GenericTexture(); - - ((GenericTexture)xpbar).setUrl("xpbar_inc000.png"); - xpbar.setX(center_x - 64); - xpbar.setY(SpoutConfig.getInstance().getXPBarYPosition()); - xpbar.setHeight(4); - xpbar.setWidth(128); - xpbar.setPriority(RenderPriority.Lowest); - - sPlayer.getMainScreen().attachWidget(plugin, xpbar); - - if (SpoutConfig.getInstance().getXPBarIconEnabled()) { - xpicon = new GenericTexture(); - - xpicon.setUrl("Icon.png"); - xpicon.setHeight(8); - xpicon.setWidth(16); - xpicon.setX(center_x - (8 + 64)); - xpicon.setY(SpoutConfig.getInstance().getXPIconYPosition() + 2); - xpicon.setPriority(RenderPriority.High); - xpicon.setDirty(true); - - sPlayer.getMainScreen().attachWidget(plugin, xpicon); - } - } - - sPlayer.getMainScreen().setDirty(true); - } - - /** - * Update XP bar for Standard & Small styles. - * - * @param player Player whose XP bar to update - * @param PP Profile of the given player - */ - private void updateXpBarStandard(Player player, PlayerProfile PP) { - if (!SpoutConfig.getInstance().getXPBarEnabled()) { - return; - } - - SkillType theType = getType(PP); - - if (theType == null) { //Can this ever actually BE null? (Yes, it's null when the player has just logged in. It's not null when they gain XP in anything) - return; - } - - xpicon.setUrl(Misc.getCapitalized(theType.toString()) + ".png"); - xpicon.setDirty(true); - - ((GenericTexture) xpbar).setUrl(getUrlBar(getXpInc(PP.getSkillXpLevel(theType), PP.getXpToLevel(theType), HUDType.STANDARD))); - xpbar.setDirty(true); - - SpoutManager.getPlayer(player).getMainScreen().setDirty(true); - } - - /** - * Update XP bar for Retro styles. - * - * @param player Player whose XP bar to update - * @param PP Profile of the given player - */ - private void updateXpBarRetro(Player player, PlayerProfile PP) { - if (!SpoutConfig.getInstance().getXPBarEnabled()) { - return; - } - - SkillType theType = getType(PP); - - if (theType == null) { //Can this ever actually BE null? (Yes, it's null when the player has just logged in. It's not null when they gain XP in anything) - return; - } - - Color color = getRetroColor(theType); - - xpicon.setUrl(Misc.getCapitalized(theType.toString()) + "_r.png"); - - xpfill.setBottomColor(color); - xpfill.setTopColor(color); - xpfill.setWidth(getXpInc(PP.getSkillXpLevel(theType), PP.getXpToLevel(theType), HUDType.RETRO)); - xpfill.setDirty(true); - - SpoutManager.getPlayer(player).getMainScreen().setDirty(true); - } - - private static Color getRetroColor(SkillType type) { - switch (type) { - case ACROBATICS: - return new Color((float) SpoutConfig.getInstance().getRetroHUDAcrobaticsRed(), (float) SpoutConfig.getInstance().getRetroHUDAcrobaticsGreen(), (float) SpoutConfig.getInstance().getRetroHUDAcrobaticsBlue(), 1f); - - case ARCHERY: - return new Color((float) SpoutConfig.getInstance().getRetroHUDArcheryRed(), (float) SpoutConfig.getInstance().getRetroHUDArcheryGreen(), (float) SpoutConfig.getInstance().getRetroHUDArcheryBlue(), 1f); - - case AXES: - return new Color((float) SpoutConfig.getInstance().getRetroHUDAxesRed(), (float) SpoutConfig.getInstance().getRetroHUDAxesGreen(), (float) SpoutConfig.getInstance().getRetroHUDAxesBlue(), 1f); - - case EXCAVATION: - return new Color((float) SpoutConfig.getInstance().getRetroHUDExcavationRed(), (float) SpoutConfig.getInstance().getRetroHUDExcavationGreen(), (float) SpoutConfig.getInstance().getRetroHUDExcavationBlue(), 1f); - - case HERBALISM: - return new Color((float) SpoutConfig.getInstance().getRetroHUDHerbalismRed(), (float) SpoutConfig.getInstance().getRetroHUDHerbalismGreen(), (float) SpoutConfig.getInstance().getRetroHUDHerbalismBlue(), 1f); - - case MINING: - return new Color((float) SpoutConfig.getInstance().getRetroHUDMiningRed(), (float) SpoutConfig.getInstance().getRetroHUDMiningGreen(), (float) SpoutConfig.getInstance().getRetroHUDMiningBlue(), 1f); - - case REPAIR: - return new Color((float) SpoutConfig.getInstance().getRetroHUDRepairRed(), (float) SpoutConfig.getInstance().getRetroHUDRepairGreen(), (float) SpoutConfig.getInstance().getRetroHUDRepairBlue(), 1f); - - case SWORDS: - return new Color((float) SpoutConfig.getInstance().getRetroHUDSwordsRed(), (float) SpoutConfig.getInstance().getRetroHUDSwordsGreen(), (float) SpoutConfig.getInstance().getRetroHUDSwordsBlue(), 1f); - - case TAMING: - return new Color((float) SpoutConfig.getInstance().getRetroHUDTamingRed(), (float) SpoutConfig.getInstance().getRetroHUDTamingGreen(), (float) SpoutConfig.getInstance().getRetroHUDTamingBlue(), 1f); - - case UNARMED: - return new Color((float) SpoutConfig.getInstance().getRetroHUDUnarmedRed(), (float) SpoutConfig.getInstance().getRetroHUDUnarmedGreen(), (float) SpoutConfig.getInstance().getRetroHUDUnarmedBlue(), 1f); - - case WOODCUTTING: - return new Color((float) SpoutConfig.getInstance().getRetroHUDWoodcuttingRed(), (float) SpoutConfig.getInstance().getRetroHUDWoodcuttingGreen(), (float) SpoutConfig.getInstance().getRetroHUDWoodcuttingBlue(), 1f); - - case FISHING: - return new Color((float) SpoutConfig.getInstance().getRetroHUDFishingRed(), (float) SpoutConfig.getInstance().getRetroHUDFishingGreen(), (float) SpoutConfig.getInstance().getRetroHUDFishingBlue(), 1f); - - default: - return new Color(0.3f, 0.3f, 0.75f, 1f); - } - } - - private static String getUrlBar(Integer number) { - char[] num = number.toString().toCharArray(); - - switch (num.length) { - case 1: - return "xpbar_inc00" + number + ".png"; - - case 2: - return "xpbar_inc0" + number + ".png"; - - default: - return "xpbar_inc" + number + ".png"; - } - } - - private static Integer getXpInc(int skillxp, int xptolevel, HUDType hud) { - double percentage = (double) skillxp / xptolevel; - double inc; - - switch (hud) { - case RETRO: - inc = 0.0079365079365079; - break; - - case STANDARD: - inc = 0.0039370078740157; - break; - - default: - return 1; - } - - return (int) (percentage / inc); - } - - private static SkillType getType(PlayerProfile PP) { - if (PP.getXpBarLocked()) { - return PP.getSkillLock(); - } - else { - return PP.getLastGained(); - } - } -} diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index cf4fbbcd2..7886e8007 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -25,9 +25,9 @@ import com.gmail.nossr50.util.Users; public class PlayerProfile { /* HUD */ - private HUDType hud; - private int xpbarinc; - private SkillType lastgained; + private SpoutHud spoutHud; + private HudType hudType = SpoutConfig.getInstance().defaultHudType; + private SkillType lastGained; private SkillType skillLock; /* Party Stuff */ @@ -36,7 +36,7 @@ public class PlayerProfile { /* Toggles */ private boolean loaded; - private boolean partyhud = true, spoutcraft, xpbarlocked; + private boolean xpBarLocked; private boolean placedAnvil; private boolean partyChatMode, adminChatMode; private boolean godMode; @@ -45,14 +45,14 @@ public class PlayerProfile { superBreakerInformed = true, blastMiningInformed = true, serratedStrikesInformed = true, treeFellerInformed = true; private boolean hoePreparationMode, shovelPreparationMode, swordsPreparationMode, fistsPreparationMode, pickaxePreparationMode, axePreparationMode; - private boolean abilityuse = true; + private boolean abilityUse = true; /* Timestamps */ private int recentlyHurt; private int respawnATS; /* mySQL STUFF */ - private int userid; + private int userId; HashMap skills = new HashMap(); //Skills and Levels HashMap skillsXp = new HashMap(); //Skills and XP @@ -64,7 +64,6 @@ public class PlayerProfile { private final static String location = mcMMO.usersFile; public PlayerProfile(Player player, String playerName, boolean addNew) { - hud = SpoutConfig.getInstance().defaulthud; this.player = player; this.playerName = playerName; @@ -107,38 +106,33 @@ public class PlayerProfile { } public boolean loadMySQL() { - userid = mcMMO.database.getInt("SELECT id FROM " + Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'"); + userId = mcMMO.database.getInt("SELECT id FROM " + Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'"); - if (userid == 0) { + if (userId == 0) { return false; } else { - HashMap> huds = mcMMO.database.read("SELECT hudtype FROM " + Config.getInstance().getMySQLTablePrefix() + "huds WHERE user_id = " + userid); + HashMap> huds = mcMMO.database.read("SELECT hudtype FROM " + Config.getInstance().getMySQLTablePrefix() + "huds WHERE user_id = " + userId); if (huds.get(1) == null) { - mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "huds (user_id) VALUES (" + userid + ")"); + mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "huds (user_id) VALUES (" + userId + ")"); } else { - if (huds.get(1).get(0) != null) { - for (HUDType x : HUDType.values()) { - if (x.toString().equals(huds.get(1).get(0))) { - hud = x; - } + for (HudType hudType : HudType.values()) { + if (hudType.toString().equals(huds.get(1).get(0))) { + this.hudType = hudType; } } - else { - hud = SpoutConfig.getInstance().defaulthud; - } } /* * I'm still learning MySQL, this is a fix for adding a new table * its not pretty but it works */ - HashMap> cooldowns = mcMMO.database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + Config.getInstance().getMySQLTablePrefix() + "cooldowns WHERE user_id = " + userid); + HashMap> cooldowns = mcMMO.database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + Config.getInstance().getMySQLTablePrefix() + "cooldowns WHERE user_id = " + userId); if(cooldowns.get(1) == null) { - mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "cooldowns (user_id) VALUES (" + userid + ")"); + mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "cooldowns (user_id) VALUES (" + userId + ")"); } else { skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(cooldowns.get(1).get(0))); @@ -151,7 +145,7 @@ public class PlayerProfile { skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldowns.get(1).get(7))); } - HashMap> stats = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+Config.getInstance().getMySQLTablePrefix()+"skills WHERE user_id = " + userid); + HashMap> stats = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+Config.getInstance().getMySQLTablePrefix()+"skills WHERE user_id = " + userId); skills.put(SkillType.TAMING, Integer.valueOf(stats.get(1).get(0))); skills.put(SkillType.MINING, Integer.valueOf(stats.get(1).get(1))); skills.put(SkillType.REPAIR, Integer.valueOf(stats.get(1).get(2))); @@ -164,7 +158,7 @@ public class PlayerProfile { skills.put(SkillType.AXES, Integer.valueOf(stats.get(1).get(9))); skills.put(SkillType.ACROBATICS, Integer.valueOf(stats.get(1).get(10))); skills.put(SkillType.FISHING, Integer.valueOf(stats.get(1).get(11))); - HashMap> experience = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+Config.getInstance().getMySQLTablePrefix()+"experience WHERE user_id = " + userid); + HashMap> experience = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+Config.getInstance().getMySQLTablePrefix()+"experience WHERE user_id = " + userId); skillsXp.put(SkillType.TAMING, Integer.valueOf(experience.get(1).get(0))); skillsXp.put(SkillType.MINING, Integer.valueOf(experience.get(1).get(1))); skillsXp.put(SkillType.REPAIR, Integer.valueOf(experience.get(1).get(2))); @@ -184,10 +178,10 @@ public class PlayerProfile { public void addMySQLPlayer() { mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / 1000 + ")"); - userid = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'"); - mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "cooldowns (user_id) VALUES (" + userid + ")"); - mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "skills (user_id) VALUES (" + userid + ")"); - mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "experience (user_id) VALUES (" + userid + ")"); + userId = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'"); + mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "cooldowns (user_id) VALUES (" + userId + ")"); + mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "skills (user_id) VALUES (" + userId + ")"); + mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "experience (user_id) VALUES (" + userId + ")"); } public boolean load() { @@ -264,9 +258,9 @@ public class PlayerProfile { if (character.length > 32) skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(character[32])); if (character.length > 33) { - for (HUDType x : HUDType.values()) { - if (x.toString().equalsIgnoreCase(character[33])) { - hud = x; + for (HudType hudType : HudType.values()) { + if (hudType.toString().equalsIgnoreCase(character[33])) { + this.hudType = hudType; } } } @@ -295,8 +289,8 @@ public class PlayerProfile { // if we are using mysql save to database if (Config.getInstance().getUseMySQL()) { - mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "huds SET hudtype = '" + hud.toString() + "' WHERE user_id = " + userid); - mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + userid); + mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "huds SET hudtype = '" + hudType.toString() + "' WHERE user_id = " + userId); + mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + userId); mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "cooldowns SET " + " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER) + ", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER) @@ -306,7 +300,7 @@ public class PlayerProfile { + ", swords = " + skillsDATS.get(AbilityType.SERRATED_STRIKES) + ", axes = " + skillsDATS.get(AbilityType.SKULL_SPLIITER) + ", blast_mining = " + skillsDATS.get(AbilityType.BLAST_MINING) - + " WHERE user_id = " + userid); + + " WHERE user_id = " + userId); mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "skills SET " + " taming = " + skills.get(SkillType.TAMING) + ", mining = " + skills.get(SkillType.MINING) @@ -320,7 +314,7 @@ public class PlayerProfile { + ", axes = " + skills.get(SkillType.AXES) + ", acrobatics = " + skills.get(SkillType.ACROBATICS) + ", fishing = " + skills.get(SkillType.FISHING) - + " WHERE user_id = " + userid); + + " WHERE user_id = " + userId); mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "experience SET " + " taming = " + skillsXp.get(SkillType.TAMING) + ", mining = " + skillsXp.get(SkillType.MINING) @@ -334,7 +328,7 @@ public class PlayerProfile { + ", axes = " + skillsXp.get(SkillType.AXES) + ", acrobatics = " + skillsXp.get(SkillType.ACROBATICS) + ", fishing = " + skillsXp.get(SkillType.FISHING) - + " WHERE user_id = " + userid); + + " WHERE user_id = " + userId); } else { // otherwise save to flatfile @@ -389,7 +383,7 @@ public class PlayerProfile { writer.append(String.valueOf(skillsDATS.get(AbilityType.SERRATED_STRIKES)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SUPER_BREAKER)) + ":"); - writer.append(hud.toString() + ":"); + writer.append(hudType.toString() + ":"); writer.append(skills.get(SkillType.FISHING) + ":"); writer.append(skillsXp.get(SkillType.FISHING) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":"); @@ -449,7 +443,7 @@ public class PlayerProfile { out.append(0 + ":"); //DATS out.append(0 + ":"); //DATS out.append(0 + ":"); //DATS - out.append(SpoutConfig.getInstance().defaulthud.toString() + ":");//HUD + out.append(SpoutConfig.getInstance().defaultHudType.toString() + ":");//HUD out.append(0 + ":"); //Fishing out.append(0 +":"); //FishingXP out.append(0 + ":"); //Blast Mining @@ -468,7 +462,7 @@ public class PlayerProfile { */ public int getMySQLuserId() { - return userid; + return userId; } public boolean isLoaded() { @@ -503,45 +497,32 @@ public class PlayerProfile { * HUD Stuff */ - public void togglePartyHUD() { - partyhud = !partyhud; + public HudType getHudType() { + return hudType; } - public boolean getPartyHUD() { - return partyhud; + public void setHudType(HudType hudType) { + this.hudType = hudType; } - public void toggleSpoutEnabled() { - spoutcraft = !spoutcraft; + public SpoutHud getSpoutHud() { + return spoutHud; } - public HUDType getHUDType() { - return hud; - } - - public void setHUDType(HUDType type) { - hud = type; - save(); + public void setSpoutHud(SpoutHud spoutHud) { + this.spoutHud = spoutHud; } public void setXpBarLocked(boolean locked) { - xpbarlocked = locked; + xpBarLocked = locked; } public boolean getXpBarLocked() { - return xpbarlocked; + return xpBarLocked; } public void toggleXpBarLocked() { - xpbarlocked = !xpbarlocked; - } - - public int getXpBarInc() { - return xpbarinc; - } - - public void setXpBarInc(int newvalue) { - xpbarinc = newvalue; + xpBarLocked = !xpBarLocked; } public void setSkillLock(SkillType newvalue) { @@ -553,11 +534,15 @@ public class PlayerProfile { } public void setLastGained(SkillType newvalue) { - lastgained = newvalue; + lastGained = newvalue; } public SkillType getLastGained() { - return lastgained; + return lastGained; + } + + public void updateXpBar() { + spoutHud.updateXpBar(); } /* @@ -853,11 +838,11 @@ public class PlayerProfile { } public boolean getAbilityUse() { - return abilityuse; + return abilityUse; } public void toggleAbilityUse() { - abilityuse = !abilityuse; + abilityUse = !abilityUse; } /* @@ -962,7 +947,7 @@ public class PlayerProfile { else { mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, newValue)); skillsXp.put(skillType, skillsXp.get(skillType) + newValue); - lastgained = skillType; + lastGained = skillType; } } @@ -1033,7 +1018,7 @@ public class PlayerProfile { mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp)); skillsXp.put(skillType, skillsXp.get(skillType) + xp); - lastgained = skillType; + lastGained = skillType; } /** @@ -1101,8 +1086,6 @@ public class PlayerProfile { skills.put(skillType, skills.get(skillType) + levels); skillsXp.put(skillType, 0); } - - save(); } /** diff --git a/src/main/java/com/gmail/nossr50/datatypes/SpoutHud.java b/src/main/java/com/gmail/nossr50/datatypes/SpoutHud.java new file mode 100644 index 000000000..3744910ff --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/SpoutHud.java @@ -0,0 +1,67 @@ +package com.gmail.nossr50.datatypes; + +import org.getspout.spoutapi.SpoutManager; + +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.config.SpoutConfig; +import com.gmail.nossr50.datatypes.popups.Menu; +import com.gmail.nossr50.datatypes.popups.XpBar; + +public class SpoutHud { + private PlayerProfile playerProfile; + + private Menu menu; + private XpBar xpBar; + + public SpoutHud(PlayerProfile playerProfile) { + this.playerProfile = playerProfile; + + initializeXpBar(); + } + + /** + * Initialize the HUD. + */ + public void initializeXpBar() { + if (SpoutConfig.getInstance().getXPBarEnabled()) { + if (xpBar != null) { + xpBar.removeWidgets(); + } + + xpBar = new XpBar(SpoutManager.getPlayer(playerProfile.getPlayer()), playerProfile.getHudType()); + } + } + + /** + * Update the XP bar. + */ + public void updateXpBar() { + SkillType skillType = playerProfile.getXpBarLocked() ? playerProfile.getSkillLock() : playerProfile.getLastGained(); + + if (skillType == null) { + return; + } + + xpBar.update(skillType, playerProfile); + } + + public boolean isMenuOpened() { + return (menu != null) ? true : false; + } + + public void openMenu() { + menu = new Menu(SpoutManager.getPlayer(playerProfile.getPlayer()), playerProfile); + } + + public void onMenuClose() { + menu = null; + } + + public void removeWidgets() { + if (menu != null) { + menu.close(); + } + + SpoutManager.getPlayer(playerProfile.getPlayer()).getMainScreen().removeWidgets(mcMMO.p); + } +} \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonEscape.java b/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonEscape.java deleted file mode 100644 index 642a13d32..000000000 --- a/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonEscape.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.gmail.nossr50.datatypes.buttons; - -import org.getspout.spoutapi.gui.GenericButton; - -public class ButtonEscape extends GenericButton { - - public ButtonEscape() { - this.setText("EXIT"); - this.setWidth(60); - this.setHeight(20); - this.setDirty(true); - } -} diff --git a/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonHUDStyle.java b/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonHUDStyle.java deleted file mode 100644 index 4ba1229b0..000000000 --- a/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonHUDStyle.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.gmail.nossr50.datatypes.buttons; - -import com.gmail.nossr50.datatypes.PlayerProfile; - -public class ButtonHUDStyle extends ButtonToggle { - - public ButtonHUDStyle(PlayerProfile PP) { - super("HUD Type: ", PP.getHUDType().toString(), "Change your HUD style!"); //TODO: Needs more locale - } - - public void updateText(PlayerProfile PP) { - super.updateText("HUD Type: ", PP.getHUDType().toString()); //TODO: Needs more locale - } -} diff --git a/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonPartyToggle.java b/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonPartyToggle.java deleted file mode 100644 index 0c496d305..000000000 --- a/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonPartyToggle.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.gmail.nossr50.datatypes.buttons; - -import com.gmail.nossr50.datatypes.PlayerProfile; - -public class ButtonPartyToggle extends ButtonToggle { - - public ButtonPartyToggle(PlayerProfile PP) { - super("Party HUD: ", ((Boolean) PP.getPartyHUD()).toString(), "Toggle the Party HUD!"); //TODO: Needs more locale - } - - public void updateText(PlayerProfile PP) { - super.updateText("Party HUD: ", ((Boolean) PP.getPartyHUD()).toString()); //TODO: Needs more locale - } -} diff --git a/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonToggle.java b/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonToggle.java deleted file mode 100644 index 75b46707c..000000000 --- a/src/main/java/com/gmail/nossr50/datatypes/buttons/ButtonToggle.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.gmail.nossr50.datatypes.buttons; - -import org.getspout.spoutapi.gui.GenericButton; - -public class ButtonToggle extends GenericButton{ - - public ButtonToggle(String text1, String text2, String tooltip) { - this.setText(text1 + text2); - this.setTooltip(tooltip); - this.setWidth(120); - this.setHeight(20); - this.setDirty(true); - } - - public void updateText(String text1, String text2) { - this.setText(text1 + text2); - this.setDirty(true); - } -} diff --git a/src/main/java/com/gmail/nossr50/datatypes/buttons/McmmoButton.java b/src/main/java/com/gmail/nossr50/datatypes/buttons/McmmoButton.java new file mode 100644 index 000000000..f7ddea34d --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/buttons/McmmoButton.java @@ -0,0 +1,24 @@ +package com.gmail.nossr50.datatypes.buttons; + +import org.getspout.spoutapi.gui.GenericButton; + +public class McmmoButton extends GenericButton { + private Slot slot; + + public McmmoButton(String text, String toolTip) { + this.setText(text); + this.setTooltip(toolTip); + } + + public void connect(Slot slot) { + this.slot = slot; + } + + public void activate() { + slot.activate(); + } + + public interface Slot { + public void activate(); + } +} diff --git a/src/main/java/com/gmail/nossr50/datatypes/popups/Menu.java b/src/main/java/com/gmail/nossr50/datatypes/popups/Menu.java new file mode 100644 index 000000000..21e8f17b7 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/popups/Menu.java @@ -0,0 +1,80 @@ +package com.gmail.nossr50.datatypes.popups; + +import org.bukkit.ChatColor; +import org.getspout.spoutapi.SpoutManager; +import org.getspout.spoutapi.gui.GenericLabel; +import org.getspout.spoutapi.gui.GenericPopup; +import org.getspout.spoutapi.gui.InGameHUD; +import org.getspout.spoutapi.player.SpoutPlayer; + +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.datatypes.HudType; +import com.gmail.nossr50.datatypes.PlayerProfile; +import com.gmail.nossr50.datatypes.SpoutHud; +import com.gmail.nossr50.datatypes.buttons.McmmoButton; +import com.gmail.nossr50.datatypes.buttons.McmmoButton.Slot; + +public class Menu extends GenericPopup { + private McmmoButton hudButton; + private McmmoButton escapeButton; + private GenericLabel titleLabel = new GenericLabel(); + private GenericLabel escapeLabel = new GenericLabel(); + private static int centerX = 427 / 2; + private static int centerY = 240 / 2; + + public Menu(SpoutPlayer spoutPlayer, final PlayerProfile playerProfile) { + //240, 427 are the bottom right + titleLabel.setText(ChatColor.GOLD + "~mcMMO Menu~"); //TODO: Needs more locale + titleLabel.setWidth(100); + titleLabel.setHeight(100); + titleLabel.setX(centerX - 35); + titleLabel.setY((centerY / 2) - 20); + + escapeLabel.setText(ChatColor.GRAY + "Press ESCAPE to exit!"); //TODO: Needs more locale + escapeLabel.setWidth(100); + escapeLabel.setHeight(100); + escapeLabel.setX(titleLabel.getX() - 15); + escapeLabel.setY(titleLabel.getY() + 10); + + hudButton = new McmmoButton("HUD Type: " + playerProfile.getHudType().toString(), "Change your HUD style!"); + hudButton.setWidth(120); + hudButton.setHeight(20); + hudButton.setX(centerX - (hudButton.getWidth() / 2)); + hudButton.setY(centerY / 2); + hudButton.connect(new Slot() { + @Override + public void activate() { + HudType nextHudType = playerProfile.getHudType().getNext(); + SpoutHud spoutHud = playerProfile.getSpoutHud(); + + playerProfile.setHudType(nextHudType); + spoutHud.initializeXpBar(); + spoutHud.updateXpBar(); + hudButton.setText("HUD Type: " + nextHudType.toString()); + hudButton.setDirty(true); + } + }); + + escapeButton = new McmmoButton("EXIT", null); + escapeButton.setWidth(60); + escapeButton.setHeight(20); + escapeButton.setX(centerX - (escapeButton.getWidth() / 2)); + escapeButton.setY((centerY / 2) + (escapeButton.getHeight() * 2) + 5); + escapeButton.connect(new Slot() { + @Override + public void activate() { + SpoutManager.getPlayer(playerProfile.getPlayer()).getMainScreen().closePopup(); + } + }); + + attachWidget(mcMMO.p, hudButton); + attachWidget(mcMMO.p, titleLabel); + attachWidget(mcMMO.p, escapeLabel); + attachWidget(mcMMO.p, escapeButton); + + InGameHUD inGameHud = spoutPlayer.getMainScreen(); + + inGameHud.attachPopupScreen(this); + inGameHud.setDirty(true); + } +} diff --git a/src/main/java/com/gmail/nossr50/datatypes/popups/PopupMMO.java b/src/main/java/com/gmail/nossr50/datatypes/popups/PopupMMO.java deleted file mode 100644 index e182b5925..000000000 --- a/src/main/java/com/gmail/nossr50/datatypes/popups/PopupMMO.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.gmail.nossr50.datatypes.popups; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.getspout.spoutapi.gui.GenericLabel; -import org.getspout.spoutapi.gui.GenericPopup; - -import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.datatypes.PlayerProfile; -import com.gmail.nossr50.datatypes.buttons.ButtonEscape; -import com.gmail.nossr50.datatypes.buttons.ButtonHUDStyle; - -public class PopupMMO extends GenericPopup { - - private ButtonHUDStyle HUDButton = null; - private ButtonEscape EscapeButton = null; - private GenericLabel mcMMO_label = new GenericLabel(); - private GenericLabel tip_escape = new GenericLabel(); - private int center_x = 427 / 2; - private int center_y = 240 / 2; - - public PopupMMO(Player player, PlayerProfile PP, mcMMO plugin) { - - //240, 427 are the bottom right - mcMMO_label.setText(ChatColor.GOLD + "~mcMMO Menu~"); //TODO: Needs more locale - mcMMO_label.setX(center_x - 35); - mcMMO_label.setY((center_y / 2) - 20); - mcMMO_label.setDirty(true); - - tip_escape.setText(ChatColor.GRAY + "Press ESCAPE to exit!"); //TODO: Needs more locale - tip_escape.setX(mcMMO_label.getX() - 15); - tip_escape.setY(mcMMO_label.getY() + 10); - tip_escape.setDirty(true); - - HUDButton = new ButtonHUDStyle(PP); - HUDButton.setX(center_x - (HUDButton.getWidth() / 2)); - HUDButton.setY(center_y / 2); - HUDButton.setDirty(true); - - EscapeButton = new ButtonEscape(); - EscapeButton.setX(center_x - (EscapeButton.getWidth() / 2)); - EscapeButton.setY((center_y / 2) + (HUDButton.getHeight() * 2) + 5); - EscapeButton.setDirty(true); - - this.attachWidget(plugin, HUDButton); - this.attachWidget(plugin, mcMMO_label); - this.attachWidget(plugin, tip_escape); - this.attachWidget(plugin, EscapeButton); - - this.setDirty(true); - } - - public void updateButtons(PlayerProfile PP) { - HUDButton.updateText(PP); - //PartyButton.updateText(PP); - this.setDirty(true); - } -} diff --git a/src/main/java/com/gmail/nossr50/datatypes/popups/XpBar.java b/src/main/java/com/gmail/nossr50/datatypes/popups/XpBar.java new file mode 100644 index 000000000..82d0e9dc2 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/popups/XpBar.java @@ -0,0 +1,320 @@ +package com.gmail.nossr50.datatypes.popups; + +import org.getspout.spoutapi.gui.Color; +import org.getspout.spoutapi.gui.GenericGradient; +import org.getspout.spoutapi.gui.GenericTexture; +import org.getspout.spoutapi.gui.InGameHUD; +import org.getspout.spoutapi.gui.RenderPriority; +import org.getspout.spoutapi.gui.Widget; +import org.getspout.spoutapi.player.SpoutPlayer; + +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.config.SpoutConfig; +import com.gmail.nossr50.datatypes.HudType; +import com.gmail.nossr50.datatypes.PlayerProfile; +import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.util.Misc; + +public class XpBar { + private SpoutPlayer spoutPlayer; + + private Widget xpBar; + private GenericGradient xpFill; + private GenericGradient xpBackground; + private GenericGradient xpIconBackground; + private GenericGradient xpIconBorder; + private GenericTexture xpIcon; + + public XpBar(SpoutPlayer spoutPlayer, HudType hudType) { + this.spoutPlayer = spoutPlayer; + + switch (hudType) { + case RETRO: + initializeXpBarRetro(); + break; + + case STANDARD: + initializeXpBarStandard(); + break; + + case SMALL: + initializeXpBarSmall(); + break; + + case DISABLED: + break; + } + + spoutPlayer.getMainScreen().setDirty(true); + } + + /** + * Initialize Retro XP bar. + */ + private void initializeXpBarRetro() { + Color border = new Color((float) SpoutConfig.getInstance().getRetroHUDXPBorderRed(), (float) SpoutConfig.getInstance().getRetroHUDXPBorderGreen(), (float) SpoutConfig.getInstance().getRetroHUDXPBorderBlue(), 1f); + Color green = new Color(0f, 1f, 0f, 1f); + Color background = new Color((float) SpoutConfig.getInstance().getRetroHUDXPBackgroundRed(), (float) SpoutConfig.getInstance().getRetroHUDXPBackgroundGreen(), (float) SpoutConfig.getInstance().getRetroHUDXPBackgroundBlue(), 1f); + + xpBar = new GenericGradient(); + xpFill = new GenericGradient(); + xpBackground = new GenericGradient(); + + xpBar.setWidth(128); + xpBar.setHeight(4); + xpBar.setX(149); + xpBar.setY(10); + ((GenericGradient) xpBar).setBottomColor(border); + ((GenericGradient) xpBar).setTopColor(border); + xpBar.setPriority(RenderPriority.Highest); + spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpBar); + + xpFill.setWidth(0); + xpFill.setHeight(2); + xpFill.setX(150); + xpFill.setY(11); + xpFill.setBottomColor(green); + xpFill.setTopColor(green); + xpFill.setPriority(RenderPriority.Lowest); + spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpFill); + + xpBackground.setWidth(126); + xpBackground.setHeight(2); + xpBackground.setX(150); + xpBackground.setY(11); + xpBackground.setBottomColor(background); + xpBackground.setTopColor(background); + xpBackground.setPriority(RenderPriority.Low); + spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpBackground); + + if (SpoutConfig.getInstance().getXPBarIconEnabled()) { + Color darkbg = new Color(0.2f, 0.2f, 0.2f, 1f); + + xpIconBackground = new GenericGradient(); + xpIconBorder = new GenericGradient(); + xpIcon = new GenericTexture(); + + xpIconBackground.setBottomColor(darkbg); + xpIconBackground.setTopColor(darkbg); + xpIconBackground.setWidth(4); + xpIconBackground.setHeight(4); + xpIconBackground.setPriority(RenderPriority.High); + xpIconBackground.setX(142); + xpIconBackground.setY(10); + spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpIconBackground); + + xpIconBorder.setBottomColor(border); + xpIconBorder.setTopColor(border); + xpIconBorder.setWidth(6); + xpIconBorder.setHeight(6); + xpIconBorder.setPriority(RenderPriority.Highest); + xpIconBorder.setX(141); + xpIconBorder.setY(9); + spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpIconBorder); + + xpIcon.setWidth(6); + xpIcon.setHeight(6); + xpIcon.setX(141); + xpIcon.setY(9); + xpIcon.setPriority(RenderPriority.Normal); + xpIcon.setUrl("Icon_r.png"); + spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpIcon); + } + } + + /** + * Initialize Standard XP bar. + */ + private void initializeXpBarStandard() { + xpBar = new GenericTexture(); + + ((GenericTexture) xpBar).setUrl("xpbar_inc000.png"); + xpBar.setX(SpoutConfig.getInstance().getXPBarXPosition()); + xpBar.setY(SpoutConfig.getInstance().getXPBarYPosition()); + xpBar.setHeight(8); + xpBar.setWidth(256); + xpBar.setPriority(RenderPriority.Lowest); + spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpBar); + + if (SpoutConfig.getInstance().getXPBarIconEnabled()) { + xpIcon = new GenericTexture(); + + xpIcon.setUrl("Icon.png"); + xpIcon.setHeight(16); + xpIcon.setWidth(32); + xpIcon.setX(SpoutConfig.getInstance().getXPIconXPosition()); + xpIcon.setY(SpoutConfig.getInstance().getXPIconYPosition()); + xpIcon.setPriority(RenderPriority.High); + spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpIcon); + } + } + + /** + * Initialize Small XP bar. + */ + private void initializeXpBarSmall() { + xpBar = new GenericTexture(); + + ((GenericTexture)xpBar).setUrl("xpbar_inc000.png"); + xpBar.setX(427 / 2 - 64); + xpBar.setY(SpoutConfig.getInstance().getXPBarYPosition()); + xpBar.setHeight(4); + xpBar.setWidth(128); + xpBar.setPriority(RenderPriority.Lowest); + spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpBar); + + if (SpoutConfig.getInstance().getXPBarIconEnabled()) { + xpIcon = new GenericTexture(); + + xpIcon.setUrl("Icon.png"); + xpIcon.setHeight(8); + xpIcon.setWidth(16); + xpIcon.setX(427 / 2 - (8 + 64)); + xpIcon.setY(SpoutConfig.getInstance().getXPIconYPosition() + 2); + xpIcon.setPriority(RenderPriority.High); + spoutPlayer.getMainScreen().attachWidget(mcMMO.p, xpIcon); + } + } + + /** + * Update the XP bar. + * + * @param skillType + * @param playerProfile + */ + public void update(SkillType skillType, PlayerProfile playerProfile) { + switch (playerProfile.getHudType()) { + case RETRO: + updateXpBarRetro(skillType, playerProfile); + break; + + case STANDARD: + case SMALL: + updateXpBarStandard(skillType, playerProfile); + break; + + case DISABLED: + break; + } + } + + /** + * Update XP bar for Standard & Small styles. + * + * @param skillType + * @param playerProfile + */ + private void updateXpBarStandard(SkillType skillType, PlayerProfile playerProfile) { + xpIcon.setUrl(Misc.getCapitalized(skillType.toString()) + ".png"); + + ((GenericTexture) xpBar).setUrl(getUrlBar(getXpInc(playerProfile.getSkillXpLevel(skillType), playerProfile.getXpToLevel(skillType), HudType.STANDARD))); + + spoutPlayer.getMainScreen().setDirty(true); + } + + /** + * Update XP bar for Retro styles. + * + * @param skillType + */ + private void updateXpBarRetro(SkillType skillType, PlayerProfile playerProfile) { + Color color = getRetroColor(skillType); + + xpIcon.setUrl(Misc.getCapitalized(skillType.toString()) + "_r.png"); + + xpFill.setBottomColor(color); + xpFill.setTopColor(color); + xpFill.setWidth(getXpInc(playerProfile.getSkillXpLevel(skillType), playerProfile.getXpToLevel(skillType), HudType.RETRO)); + + spoutPlayer.getMainScreen().setDirty(true); + } + + private static Color getRetroColor(SkillType type) { + switch (type) { + case ACROBATICS: + return new Color((float) SpoutConfig.getInstance().getRetroHUDAcrobaticsRed(), (float) SpoutConfig.getInstance().getRetroHUDAcrobaticsGreen(), (float) SpoutConfig.getInstance().getRetroHUDAcrobaticsBlue(), 1f); + + case ARCHERY: + return new Color((float) SpoutConfig.getInstance().getRetroHUDArcheryRed(), (float) SpoutConfig.getInstance().getRetroHUDArcheryGreen(), (float) SpoutConfig.getInstance().getRetroHUDArcheryBlue(), 1f); + + case AXES: + return new Color((float) SpoutConfig.getInstance().getRetroHUDAxesRed(), (float) SpoutConfig.getInstance().getRetroHUDAxesGreen(), (float) SpoutConfig.getInstance().getRetroHUDAxesBlue(), 1f); + + case EXCAVATION: + return new Color((float) SpoutConfig.getInstance().getRetroHUDExcavationRed(), (float) SpoutConfig.getInstance().getRetroHUDExcavationGreen(), (float) SpoutConfig.getInstance().getRetroHUDExcavationBlue(), 1f); + + case HERBALISM: + return new Color((float) SpoutConfig.getInstance().getRetroHUDHerbalismRed(), (float) SpoutConfig.getInstance().getRetroHUDHerbalismGreen(), (float) SpoutConfig.getInstance().getRetroHUDHerbalismBlue(), 1f); + + case MINING: + return new Color((float) SpoutConfig.getInstance().getRetroHUDMiningRed(), (float) SpoutConfig.getInstance().getRetroHUDMiningGreen(), (float) SpoutConfig.getInstance().getRetroHUDMiningBlue(), 1f); + + case REPAIR: + return new Color((float) SpoutConfig.getInstance().getRetroHUDRepairRed(), (float) SpoutConfig.getInstance().getRetroHUDRepairGreen(), (float) SpoutConfig.getInstance().getRetroHUDRepairBlue(), 1f); + + case SWORDS: + return new Color((float) SpoutConfig.getInstance().getRetroHUDSwordsRed(), (float) SpoutConfig.getInstance().getRetroHUDSwordsGreen(), (float) SpoutConfig.getInstance().getRetroHUDSwordsBlue(), 1f); + + case TAMING: + return new Color((float) SpoutConfig.getInstance().getRetroHUDTamingRed(), (float) SpoutConfig.getInstance().getRetroHUDTamingGreen(), (float) SpoutConfig.getInstance().getRetroHUDTamingBlue(), 1f); + + case UNARMED: + return new Color((float) SpoutConfig.getInstance().getRetroHUDUnarmedRed(), (float) SpoutConfig.getInstance().getRetroHUDUnarmedGreen(), (float) SpoutConfig.getInstance().getRetroHUDUnarmedBlue(), 1f); + + case WOODCUTTING: + return new Color((float) SpoutConfig.getInstance().getRetroHUDWoodcuttingRed(), (float) SpoutConfig.getInstance().getRetroHUDWoodcuttingGreen(), (float) SpoutConfig.getInstance().getRetroHUDWoodcuttingBlue(), 1f); + + case FISHING: + return new Color((float) SpoutConfig.getInstance().getRetroHUDFishingRed(), (float) SpoutConfig.getInstance().getRetroHUDFishingGreen(), (float) SpoutConfig.getInstance().getRetroHUDFishingBlue(), 1f); + + default: + return new Color(0.3f, 0.3f, 0.75f, 1f); + } + } + + private static String getUrlBar(Integer number) { + char[] num = number.toString().toCharArray(); + + switch (num.length) { + case 1: + return "xpbar_inc00" + number + ".png"; + + case 2: + return "xpbar_inc0" + number + ".png"; + + default: + return "xpbar_inc" + number + ".png"; + } + } + + private static Integer getXpInc(int skillXp, int xpToLevel, HudType hudType) { + double percentage = (double) skillXp / xpToLevel; + double inc; + + switch (hudType) { + case RETRO: + inc = 0.0079365079365079; + break; + + case STANDARD: + inc = 0.0039370078740157; + break; + + default: + return 1; + } + + return (int) (percentage / inc); + } + + public void removeWidgets() { + InGameHUD inGameHud = spoutPlayer.getMainScreen(); + + if (xpBar != null) inGameHud.removeWidget(xpBar); + if (xpFill != null) inGameHud.removeWidget(xpFill); + if (xpBackground != null) inGameHud.removeWidget(xpBackground); + if (xpIconBackground != null) inGameHud.removeWidget(xpIconBackground); + if (xpIconBorder != null) inGameHud.removeWidget(xpIconBorder); + if (xpIcon != null) inGameHud.removeWidget(xpIcon); + } +} diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 1bb5da2c7..a36121c57 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -36,7 +36,6 @@ import com.gmail.nossr50.skills.gathering.BlastMining; import com.gmail.nossr50.skills.gathering.Fishing; import com.gmail.nossr50.skills.gathering.Herbalism; import com.gmail.nossr50.skills.taming.TamingManager; -import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.util.BlockChecks; import com.gmail.nossr50.util.Item; import com.gmail.nossr50.util.Permissions; @@ -137,11 +136,6 @@ public class PlayerListener implements Listener { /* GARBAGE COLLECTION */ - //Remove Spout Stuff - if (mcMMO.spoutEnabled && SpoutStuff.playerHUDs.containsKey(player)) { - SpoutStuff.playerHUDs.remove(player); - } - //Bleed it out BleedTimer.bleedOut(player); } diff --git a/src/main/java/com/gmail/nossr50/listeners/SpoutListener.java b/src/main/java/com/gmail/nossr50/listeners/SpoutListener.java index 2add0fd8f..c3b7c59b1 100644 --- a/src/main/java/com/gmail/nossr50/listeners/SpoutListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/SpoutListener.java @@ -7,28 +7,19 @@ import org.getspout.spoutapi.event.input.KeyPressedEvent; import org.getspout.spoutapi.event.screen.ButtonClickEvent; import org.getspout.spoutapi.event.screen.ScreenCloseEvent; import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent; +import org.getspout.spoutapi.gui.Button; import org.getspout.spoutapi.gui.ScreenType; import org.getspout.spoutapi.player.SpoutPlayer; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.SpoutConfig; -import com.gmail.nossr50.datatypes.HUDType; -import com.gmail.nossr50.datatypes.HUDmmo; +import com.gmail.nossr50.datatypes.SpoutHud; import com.gmail.nossr50.datatypes.PlayerProfile; -import com.gmail.nossr50.datatypes.buttons.ButtonEscape; -import com.gmail.nossr50.datatypes.buttons.ButtonHUDStyle; -import com.gmail.nossr50.datatypes.buttons.ButtonPartyToggle; -import com.gmail.nossr50.datatypes.popups.PopupMMO; +import com.gmail.nossr50.datatypes.buttons.McmmoButton; +import com.gmail.nossr50.datatypes.popups.Menu; import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.util.Users; public class SpoutListener implements Listener { - private final mcMMO plugin; - - public SpoutListener(mcMMO plugin) { - this.plugin = plugin; - } - /** * Monitor SpoutCraftEnable events. * @@ -36,19 +27,15 @@ public class SpoutListener implements Listener { */ @EventHandler public void onSpoutCraftEnable(SpoutCraftEnableEvent event) { - SpoutPlayer sPlayer = event.getPlayer(); - PlayerProfile PPs = Users.getProfile(sPlayer); + SpoutPlayer spoutPlayer = event.getPlayer(); + PlayerProfile playerProfile = Users.getProfile(spoutPlayer); //TODO: Add custom titles based on skills if (SpoutConfig.getInstance().getShowPowerLevel()) { - sPlayer.setTitle(sPlayer.getName()+ "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE+"." + ChatColor.GREEN + String.valueOf(PPs.getPowerLevel())); + spoutPlayer.setTitle(spoutPlayer.getName() + "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE+"." + ChatColor.GREEN + String.valueOf(playerProfile.getPowerLevel())); } - if (sPlayer.isSpoutCraftEnabled()) { - SpoutStuff.playerHUDs.put(sPlayer, new HUDmmo(sPlayer, plugin)); //Setup Party HUD stuff - - PPs.toggleSpoutEnabled(); - } + playerProfile.setSpoutHud(new SpoutHud(playerProfile)); //Setup Party HUD stuff } /** @@ -58,48 +45,10 @@ public class SpoutListener implements Listener { */ @EventHandler public void onButtonClick(ButtonClickEvent event) { - SpoutPlayer sPlayer = event.getPlayer(); - PlayerProfile PP = Users.getProfile(sPlayer); + Button button = event.getButton(); - if (event.getButton() instanceof ButtonHUDStyle) { - if (SpoutStuff.playerHUDs.containsKey(sPlayer)) { - SpoutStuff.playerHUDs.get(sPlayer).resetHUD(); - SpoutStuff.playerHUDs.remove(sPlayer); - - switch (PP.getHUDType()) { - case RETRO: - PP.setHUDType(HUDType.STANDARD); - break; - - case STANDARD: - PP.setHUDType(HUDType.SMALL); - break; - - case SMALL: - PP.setHUDType(HUDType.DISABLED); - break; - - case DISABLED: - PP.setHUDType(HUDType.RETRO); - break; - - default: - break; - } - - SpoutStuff.playerHUDs.put(sPlayer, new HUDmmo(sPlayer, plugin)); - SpoutStuff.playerScreens.get(sPlayer).updateButtons(PP); - } - } - else if (event.getButton() instanceof ButtonEscape) { - sPlayer.getMainScreen().closePopup(); - } - else if (event.getButton() instanceof ButtonPartyToggle) { - PP.togglePartyHUD(); - ButtonPartyToggle bpt = (ButtonPartyToggle) event.getButton(); - bpt.updateText(PP); - SpoutStuff.playerHUDs.get(sPlayer).resetHUD(); - SpoutStuff.playerHUDs.get(sPlayer).initializeHUD(sPlayer); + if (button instanceof McmmoButton) { + ((McmmoButton) button).activate(); } } @@ -110,8 +59,11 @@ public class SpoutListener implements Listener { */ @EventHandler public void onScreenClose(ScreenCloseEvent event) { - if (event.getScreen() instanceof PopupMMO) { - SpoutStuff.playerScreens.remove(event.getPlayer()); + if (event.getScreen() instanceof Menu) { + SpoutPlayer spoutPlayer = event.getPlayer(); + + Users.getProfile(spoutPlayer).getSpoutHud().onMenuClose(); + spoutPlayer.getMainScreen().setDirty(true); } } @@ -122,23 +74,17 @@ public class SpoutListener implements Listener { */ @EventHandler public void onKeyPressedEvent(KeyPressedEvent event) { - SpoutPlayer sPlayer = event.getPlayer(); + SpoutPlayer spoutPlayer = event.getPlayer(); - if (!sPlayer.isSpoutCraftEnabled() || sPlayer.getMainScreen().getActivePopup() != null || event.getScreenType() != ScreenType.GAME_SCREEN) { + if (spoutPlayer.getMainScreen().getActivePopup() != null || event.getScreenType() != ScreenType.GAME_SCREEN) { return; } if (event.getKey() == SpoutStuff.keypress) { - if (!SpoutStuff.playerScreens.containsKey(sPlayer)) { - PopupMMO mmoPop = new PopupMMO(sPlayer, Users.getProfile(sPlayer), plugin); + SpoutHud spoutHud = Users.getProfile(spoutPlayer).getSpoutHud(); - SpoutStuff.playerScreens.put(sPlayer, mmoPop); - sPlayer.getMainScreen().attachPopupScreen(SpoutStuff.playerScreens.get(sPlayer)); - sPlayer.getMainScreen().setDirty(true); - } - else { - sPlayer.getMainScreen().attachPopupScreen(SpoutStuff.playerScreens.get(sPlayer)); - sPlayer.getMainScreen().setDirty(true); + if (!spoutHud.isMenuOpened()) { + spoutHud.openMenu(); } } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 38bc3bc6b..a8f32d212 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -421,7 +421,7 @@ public class mcMMO extends JavaPlugin { getCommand("xplock").setExecutor(new XplockCommand()); } - getCommand("mchud").setExecutor(new MchudCommand(this)); + getCommand("mchud").setExecutor(new MchudCommand()); } /** diff --git a/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java b/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java index dee3dcfac..df1a6d0a9 100644 --- a/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java +++ b/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; -import java.util.HashMap; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -22,10 +21,8 @@ import org.getspout.spoutapi.player.SpoutPlayer; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.SpoutConfig; -import com.gmail.nossr50.datatypes.HUDmmo; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; -import com.gmail.nossr50.datatypes.popups.PopupMMO; import com.gmail.nossr50.listeners.SpoutListener; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Users; @@ -39,11 +36,7 @@ public class SpoutStuff { public final static String hudRetroDirectory = hudDirectory + "Retro" + File.separator; public final static String soundDirectory = spoutDirectory + "Sound" + File.separator; - private final static SpoutListener spoutListener = new SpoutListener(plugin); - - public static HashMap playerHUDs = new HashMap(); - public static HashMap playerScreens = new HashMap(); - + private final static SpoutListener spoutListener = new SpoutListener(); public static Keyboard keypress; /** @@ -200,21 +193,6 @@ public class SpoutStuff { plugin.getServer().getPluginManager().registerEvents(spoutListener, plugin); } - /** - * Gets a Spout player from a player name. - * - * @param playerName The player name - * @return the SpoutPlayer related to this player name, null if there's no player online with that name. - */ - public static SpoutPlayer getSpoutPlayer(String playerName) { - for (Player x : plugin.getServer().getOnlinePlayers()) { - if (x.getName().equalsIgnoreCase(playerName)) { - return SpoutManager.getPlayer(x); - } - } - return null; - } - /** * Handle level-up notifications through Spout. * @@ -567,22 +545,22 @@ public class SpoutStuff { } } - /** - * Update a player's Spout XP bar. - * - * @param player The player whose bar to update - */ - public static void updateXpBar(Player player) { - playerHUDs.get(player).updateXpBarDisplay(Users.getProfile(player).getHUDType(), player); //Is there a reason we can't just do HUDmmo.updateXpBarDisplay? - } - /** * Re-enable SpoutCraft for players after a /reload */ public static void reloadSpoutPlayers() { for (SpoutPlayer spoutPlayer : SpoutManager.getPlayerManager().getOnlinePlayers()) { - SpoutCraftEnableEvent spoutCraftEnableEvent = new SpoutCraftEnableEvent(spoutPlayer); - mcMMO.p.getServer().getPluginManager().callEvent(spoutCraftEnableEvent); - } + SpoutCraftEnableEvent spoutCraftEnableEvent = new SpoutCraftEnableEvent(spoutPlayer); + mcMMO.p.getServer().getPluginManager().callEvent(spoutCraftEnableEvent); + } + } + + public static void reloadSpoutPlayer(Player player) { + SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player); + + if (spoutPlayer != null) { + SpoutCraftEnableEvent spoutCraftEnableEvent = new SpoutCraftEnableEvent(spoutPlayer); + mcMMO.p.getServer().getPluginManager().callEvent(spoutCraftEnableEvent); + } } } diff --git a/src/main/java/com/gmail/nossr50/util/Skills.java b/src/main/java/com/gmail/nossr50/util/Skills.java index 3bf5e78dd..70c79a6f5 100644 --- a/src/main/java/com/gmail/nossr50/util/Skills.java +++ b/src/main/java/com/gmail/nossr50/util/Skills.java @@ -230,7 +230,7 @@ public class Skills { if (sPlayer.isSpoutCraftEnabled()) { if (SpoutConfig.getInstance().getXPBarEnabled()) { - SpoutStuff.updateXpBar(player); + profile.updateXpBar(); } SpoutStuff.levelUpNotification(skillType, sPlayer); @@ -254,7 +254,7 @@ public class Skills { SpoutPlayer sPlayer = (SpoutPlayer) player; if (sPlayer.isSpoutCraftEnabled()) { if (SpoutConfig.getInstance().getXPBarEnabled()) { - SpoutStuff.updateXpBar(player); + profile.updateXpBar(); } } }