From a0e721815d3183a97745ea03c1503fd8c495c733 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 7 Dec 2014 15:13:33 +0100 Subject: [PATCH] Add LEVELS cost to icons. --- ChestCommands/plugin.yml | 2 +- .../filoghost/chestcommands/config/Lang.java | 1 + .../internal/icon/ExtendedIcon.java | 20 +++++++++++++++++++ .../filoghost/chestcommands/nms/v1_8_R1.java | 2 +- .../serializer/IconSerializer.java | 8 ++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ChestCommands/plugin.yml b/ChestCommands/plugin.yml index f6d2919..c30a846 100644 --- a/ChestCommands/plugin.yml +++ b/ChestCommands/plugin.yml @@ -1,6 +1,6 @@ name: ChestCommands main: com.gmail.filoghost.chestcommands.ChestCommands -version: 3.0.6 +version: 3.0.7 softdepend: [Vault, BarAPI, PlayerPoints] commands: diff --git a/ChestCommands/src/com/gmail/filoghost/chestcommands/config/Lang.java b/ChestCommands/src/com/gmail/filoghost/chestcommands/config/Lang.java index 0799771..4eab251 100644 --- a/ChestCommands/src/com/gmail/filoghost/chestcommands/config/Lang.java +++ b/ChestCommands/src/com/gmail/filoghost/chestcommands/config/Lang.java @@ -10,6 +10,7 @@ public class Lang extends SpecialConfig { public String no_required_item = "&cYou must have &e{amount}x {material} &c(ID: {id}, data value: {datavalue}) for this."; public String no_money = "&cYou need {money}$ for this."; public String no_points = "&cYou need {points} player points for this."; + public String no_exp = "&cYou need {levels} XP levels for this."; public String menu_not_found = "&cMenu not found! Please inform the staff."; public String open_menu = "&aOpening the menu \"{menu}\"."; public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}."; diff --git a/ChestCommands/src/com/gmail/filoghost/chestcommands/internal/icon/ExtendedIcon.java b/ChestCommands/src/com/gmail/filoghost/chestcommands/internal/icon/ExtendedIcon.java index e55e95d..691ff65 100644 --- a/ChestCommands/src/com/gmail/filoghost/chestcommands/internal/icon/ExtendedIcon.java +++ b/ChestCommands/src/com/gmail/filoghost/chestcommands/internal/icon/ExtendedIcon.java @@ -23,6 +23,7 @@ public class ExtendedIcon extends Icon { private double moneyPrice; private int playerPointsPrice; + private int expLevelsPrice; private RequiredItem requiredItem; public ExtendedIcon() { @@ -105,6 +106,14 @@ public class ExtendedIcon extends Icon { this.playerPointsPrice = playerPointsPrice; } + public int getExpLevelsPrice() { + return expLevelsPrice; + } + + public void setExpLevelsPrice(int expLevelsPrice) { + this.expLevelsPrice = expLevelsPrice; + } + public RequiredItem getRequiredItem() { return requiredItem; } @@ -152,6 +161,13 @@ public class ExtendedIcon extends Icon { } } + if (expLevelsPrice > 0) { + if (player.getLevel() < expLevelsPrice) { + player.sendMessage(ChestCommands.getLang().no_exp.replace("{levels}", Integer.toString(expLevelsPrice))); + return closeOnClick; + } + } + if (requiredItem != null) { if (!requiredItem.hasItem(player)) { @@ -181,6 +197,10 @@ public class ExtendedIcon extends Icon { } } + if (expLevelsPrice > 0) { + player.setLevel(player.getLevel() - expLevelsPrice); + } + if (requiredItem != null) { requiredItem.takeItem(player); } diff --git a/ChestCommands/src/com/gmail/filoghost/chestcommands/nms/v1_8_R1.java b/ChestCommands/src/com/gmail/filoghost/chestcommands/nms/v1_8_R1.java index c051dc5..54137a7 100644 --- a/ChestCommands/src/com/gmail/filoghost/chestcommands/nms/v1_8_R1.java +++ b/ChestCommands/src/com/gmail/filoghost/chestcommands/nms/v1_8_R1.java @@ -31,4 +31,4 @@ public class v1_8_R1 implements AttributeRemover { return CraftItemStack.asCraftMirror(nmsStack); } -} +} \ No newline at end of file diff --git a/ChestCommands/src/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java b/ChestCommands/src/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java index 38b81a9..2a9bac8 100644 --- a/ChestCommands/src/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java +++ b/ChestCommands/src/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java @@ -32,6 +32,7 @@ public class IconSerializer { COMMAND = "COMMAND", PRICE = "PRICE", POINTS = "POINTS", + EXP_LEVELS = "LEVELS", REQUIRED_ITEM = "REQUIRED-ITEM", PERMISSION = "PERMISSION", PERMISSION_MESSAGE = "PERMISSION-MESSAGE", @@ -133,6 +134,13 @@ public class IconSerializer { errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative POINTS: " + price); } + int levels = section.getInt(Nodes.EXP_LEVELS); + if (levels > 0) { + icon.setExpLevelsPrice(points); + } else if (levels < 0) { + errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative LEVELS: " + price); + } + if (section.isSet(Nodes.REQUIRED_ITEM)) { try { ItemStackReader itemReader = new ItemStackReader(section.getString(Nodes.REQUIRED_ITEM), true);