Add LEVELS cost to icons.

This commit is contained in:
filoghost 2014-12-07 15:13:33 +01:00
parent 387baf5ab6
commit a0e721815d
5 changed files with 31 additions and 2 deletions

View File

@ -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:

View File

@ -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}.";

View File

@ -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);
}

View File

@ -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);