use of com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent in project VotingPlugin by Ben12345rocks.
the class VoteShop method voteShop.
public void voteShop(Player player) {
BInventory inv = new BInventory(Config.getInstance().getVoteShopName());
for (String identifier : Config.getInstance().getIdentifiers()) {
ItemBuilder builder = new ItemBuilder(Config.getInstance().getIdentifierSection(identifier));
inv.addButton(Config.getInstance().getIdentifierSlot(identifier), new BInventoryButton(builder) {
@Override
public void onClick(ClickEvent event) {
Player player = event.getWhoClicked();
User user = UserManager.getInstance().getVotingPluginUser(player);
int points = Config.getInstance().getIdentifierCost(identifier);
String identifier = Config.getInstance().getIdentifierFromSlot(event.getSlot());
if (identifier != null) {
if (user.removePoints(points)) {
RewardHandler.getInstance().giveReward(user, Config.getInstance().getData(), Config.getInstance().getIdentifierRewardsPath(identifier));
user.sendMessage(Config.getInstance().getFormatShopPurchaseMsg().replace("%Identifier%", identifier).replace("%Points%", "" + points));
} else {
user.sendMessage(Config.getInstance().getFormatShopFailedMsg().replace("%Identifier%", identifier).replace("%Points%", "" + points));
}
}
}
});
}
if (Config.getInstance().getVoteShopBackButton()) {
inv.addButton(new BInventoryButton(PlayerGUIs.getInstance().getBackButton()) {
@Override
public void onClick(ClickEvent event) {
PlayerGUIs.getInstance().openVoteGUI(event.getPlayer(), UserManager.getInstance().getVotingPluginUser(player));
}
});
}
inv.openInventory(player);
}
Aggregations