From b13afd53c19672bfb2d11c7baa669e8f263476f2 Mon Sep 17 00:00:00 2001 From: BenCodez Date: Sun, 30 Jun 2024 19:56:38 -0400 Subject: [PATCH] Added Shop.yml, with auto conversion from GUI.yml --- VotingPlugin/Resources/Shop.yml | 77 +++++++ .../votingplugin/VotingPluginMain.java | 19 +- .../votingplugin/commands/CommandLoader.java | 22 +- .../gui/admin/voteshop/AdminVoteVoteShop.java | 2 +- .../admin/voteshop/AdminVoteVoteShopItem.java | 14 +- .../voteshop/AdminVoteVoteShopItemRemove.java | 7 +- .../voteshop/AdminVoteVoteShopItems.java | 4 +- .../commands/gui/player/VoteShop.java | 46 ++-- .../commands/gui/player/VoteShopConfirm.java | 20 +- .../com/bencodez/votingplugin/config/GUI.java | 147 +------------ .../votingplugin/config/ShopFile.java | 208 ++++++++++++++++++ .../placeholders/PlaceHolders.java | 4 +- .../topvoter/TopVoterHandler.java | 12 +- 13 files changed, 367 insertions(+), 215 deletions(-) create mode 100644 VotingPlugin/Resources/Shop.yml create mode 100644 VotingPlugin/src/com/bencodez/votingplugin/config/ShopFile.java diff --git a/VotingPlugin/Resources/Shop.yml b/VotingPlugin/Resources/Shop.yml new file mode 100644 index 000000000..42fcb6dc2 --- /dev/null +++ b/VotingPlugin/Resources/Shop.yml @@ -0,0 +1,77 @@ +VoteShop: + Enabled: true + Name: 'VoteShop' + BackButton: true + # Hide items in vote shop which user can not buy + HideLimitedReached: true + # Requires above to be false + LimitReached: '&aYou reached your limit' + RequireConfirmation: false + Disabled: '&cVote shop disabled' + # If true, shop gui will reopen, updating all placeholders + ReopenGUIOnPurchase: false + +Shop: + # Identifier + # Used in placeholders for formats + # Do not have spaces in the identifier + # Change the identifier for each shop item + Diamond: + Identifier_Name: 'Diamond' + # Item + Material: 'DIAMOND' + Amount: 1 + Name: '&4Buy A Diamond' + # You can set skulls of the player using the following + # Remove the # to enable + #Skull: '%Player%' + Lore: + - '&c&lCost: &c3 Voting Points' + # Number of voting points this cost + Cost: 3 + # Permission required, leave blank for no permission + Permission: '' + # Hide if player doesn't have permission (only if permission is set) + HideOnNoPermission: true + # Whether or not to keep GUI open after purchase + CloseGUI: true + # Require confirmation on purchase, overrides global option above + RequireConfirmation: false + # Overrides other purchase message + #PurchaseMessage: 'Thanks for the purchase' + # Limit how many times you can buy this + #Limit: 3 + # Reset limit daily/weekly/monthly + #Reset: + #Daily: false + #Weekly: false + #Monthly: false + # If true, item is not buyable + #NotBuyable: false + # Rewards to run if player buys successfully + Rewards: + # Run command on purchase + #Commands: + #- 'command here' + Items: + Diamond: + Material: 'DIAMOND' + Amount: 1 + +# VoteShop extra items for display only +#ExtraItems: + #ItemIdentifier: + #... + +ShopConfirmPurchase: + Title: 'Confirm Purchase?' + YesItem: + Material: EMERALD_BLOCK + Amount: 1 + Name: '&aYes' + NoItem: + Material: BARRIER + Amount: 1 + Name: '&cNo' + + \ No newline at end of file diff --git a/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java b/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java index e953edb71..84a65a0cf 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java @@ -71,6 +71,7 @@ import com.bencodez.votingplugin.config.Config; import com.bencodez.votingplugin.config.ConfigVoteSites; import com.bencodez.votingplugin.config.GUI; +import com.bencodez.votingplugin.config.ShopFile; import com.bencodez.votingplugin.config.SpecialRewardsConfig; import com.bencodez.votingplugin.cooldown.CoolDownCheck; import com.bencodez.votingplugin.data.ServerData; @@ -144,6 +145,9 @@ public class VotingPluginMain extends AdvancedCorePlugin { @Getter private GUI gui; + @Getter + private ShopFile shopFile; + @Getter private LinkedHashMap lastMonthTopVoter; @@ -899,27 +903,27 @@ public void setData(String path, Object value) { }); } - for (String identifier : plugin.getGui().getChestShopIdentifiers()) { - addDirectlyDefinedRewards(new DirectlyDefinedReward("CHEST.Shop." + identifier + ".Rewards") { + for (String identifier : plugin.getShopFile().getShopIdentifiers()) { + addDirectlyDefinedRewards(new DirectlyDefinedReward("Shop." + identifier + ".Rewards") { @Override public void createSection(String key) { - getGui().createSection(key); + getShopFile().createSection(key); } @Override public ConfigurationSection getFileData() { - return getGui().getData(); + return getShopFile().getData(); } @Override public void save() { - getGui().saveData(); + getShopFile().saveData(); } @Override public void setData(String path, Object value) { - getGui().setValue(path, value); + getShopFile().setValue(path, value); } }); } @@ -1541,6 +1545,9 @@ private void setupFiles() { gui = new GUI(this); gui.setup(); + + shopFile = new ShopFile(this); + shopFile.setup(); serverData = new ServerData(this); diff --git a/VotingPlugin/src/com/bencodez/votingplugin/commands/CommandLoader.java b/VotingPlugin/src/com/bencodez/votingplugin/commands/CommandLoader.java index 73763ed7d..f0ccc8759 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/commands/CommandLoader.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/commands/CommandLoader.java @@ -1600,7 +1600,7 @@ public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) { VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(args[1]); plugin.getRewardHandler().giveReward(user, plugin.getConfigFile().getData(), - plugin.getGui().getChestShopIdentifierRewardsPath(args[3]), new RewardOptions()); + plugin.getShopFile().getShopIdentifierRewardsPath(args[3]), new RewardOptions()); sendMessage(sender, "&cVoteShop " + args[3] + " forced"); } }); @@ -2106,7 +2106,7 @@ public void updateReplacements() { @Override public void reload() { ArrayList sites = new ArrayList(); - for (String str : plugin.getGui().getChestShopIdentifiers()) { + for (String str : plugin.getShopFile().getShopIdentifiers()) { sites.add(str); } setReplace(sites); @@ -2187,7 +2187,7 @@ public void execute(CommandSender sender, String[] args) { } }); - if (plugin.getGui().isChestVoteShopEnabled()) { + if (plugin.getShopFile().isVoteShopEnabled()) { plugin.getVoteCommand().add(new CommandHandler(plugin, new String[] { "Shop" }, "VotingPlugin.Commands.Vote.Shop|" + playerPerm, "Open VoteShop GUI", false) { @@ -2202,13 +2202,13 @@ public void execute(CommandSender sender, String[] args) { @Override public void execute(CommandSender sender, String[] args) { - if (!plugin.getGui().isChestVoteShopEnabled()) { + if (!plugin.getShopFile().isVoteShopEnabled()) { sender.sendMessage(MessageAPI.colorize("&cVote shop disabled")); return; } String identifier = args[1]; - Set identifiers = plugin.getGui().getChestShopIdentifiers(); + Set identifiers = plugin.getShopFile().getShopIdentifiers(); if (ArrayUtils.containsIgnoreCase(identifiers, identifier)) { for (String ident : identifiers) { if (ident.equalsIgnoreCase(args[1])) { @@ -2216,7 +2216,7 @@ public void execute(CommandSender sender, String[] args) { } } - String perm = plugin.getGui().getChestVoteShopPermission(identifier); + String perm = plugin.getShopFile().getVoteShopPermission(identifier); boolean hasPerm = false; if (perm.isEmpty()) { hasPerm = true; @@ -2224,7 +2224,7 @@ public void execute(CommandSender sender, String[] args) { hasPerm = sender.hasPermission(perm); } - int limit = plugin.getGui().getChestShopIdentifierLimit(identifier); + int limit = plugin.getShopFile().getShopIdentifierLimit(identifier); VotingPluginUser user = plugin.getVotingPluginUserManager() .getVotingPluginUser(sender.getName()); @@ -2236,12 +2236,12 @@ public void execute(CommandSender sender, String[] args) { } } - if (!plugin.getGui().getChestVoteShopNotBuyable(identifier)) { + if (!plugin.getShopFile().getVoteShopNotBuyable(identifier)) { if (hasPerm) { if (plugin.getConfigFile().isExtraVoteShopCheck()) { user.cache(); } - int points = plugin.getGui().getChestShopIdentifierCost(identifier); + int points = plugin.getShopFile().getShopIdentifierCost(identifier); if (identifier != null) { if (limitPass) { @@ -2252,7 +2252,7 @@ public void execute(CommandSender sender, String[] args) { if (user.removePoints(points, true)) { plugin.getRewardHandler().giveReward(user, plugin.getGui().getData(), - plugin.getGui().getChestShopIdentifierRewardsPath(identifier), + plugin.getShopFile().getShopIdentifierRewardsPath(identifier), new RewardOptions().setPlaceholders(placeholders)); user.sendMessage(PlaceholderUtils.replacePlaceHolder( @@ -2266,7 +2266,7 @@ public void execute(CommandSender sender, String[] args) { plugin.getConfigFile().getFormatShopFailedMsg(), placeholders)); } } else { - user.sendMessage(plugin.getGui().getChestVoteShopLimitReached()); + user.sendMessage(plugin.getShopFile().getVoteShopLimitReached()); } } diff --git a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShop.java b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShop.java index b7d6154a3..34837affe 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShop.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShop.java @@ -59,7 +59,7 @@ public void onClick(ClickEvent clickEvent) { @Override public void onInput(Player player, String value) { - plugin.getGui().createShop(value); + plugin.getShopFile().createShop(value); plugin.reload(); } }); diff --git a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItem.java b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItem.java index 64754cc6b..ee0f1f033 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItem.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItem.java @@ -53,7 +53,7 @@ public void onChest(Player player) { inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.VoteShop"); // to add inv.addButton(new EditGUIButton(new ItemBuilder(Material.PAPER, 1), new EditGUIValueString("Identifier_Name", - plugin.getGui().getChestShopIdentifierIdentifierName(identifier)) { + plugin.getShopFile().getShopIdentifierIdentifierName(identifier)) { @Override public void setValue(Player player, String name) { @@ -61,7 +61,7 @@ public void setValue(Player player, String name) { } })); inv.addButton(new EditGUIButton(new ItemBuilder(Material.OAK_DOOR, 1), - new EditGUIValueString("Permission", plugin.getGui().getChestVoteShopPermission(identifier)) { + new EditGUIValueString("Permission", plugin.getShopFile().getVoteShopPermission(identifier)) { @Override public void setValue(Player player, String name) { @@ -69,7 +69,7 @@ public void setValue(Player player, String name) { } })); inv.addButton(new EditGUIButton(new ItemBuilder(Material.EMERALD, 1), - new EditGUIValueNumber("Cost", plugin.getGui().getChestShopIdentifierCost(identifier)) { + new EditGUIValueNumber("Cost", plugin.getShopFile().getShopIdentifierCost(identifier)) { @Override public void setValue(Player player, Number num) { @@ -77,7 +77,7 @@ public void setValue(Player player, Number num) { } })); inv.addButton(new EditGUIButton(new ItemBuilder(Material.BARRIER, 1), - new EditGUIValueNumber("Limit", plugin.getGui().getChestShopIdentifierLimit(identifier)) { + new EditGUIValueNumber("Limit", plugin.getShopFile().getShopIdentifierLimit(identifier)) { @Override public void setValue(Player player, Number num) { @@ -86,7 +86,7 @@ public void setValue(Player player, Number num) { })); // display item - ConfigurationSection displayItemData = plugin.getGui().getChestShopIdentifierSection(identifier); + ConfigurationSection displayItemData = plugin.getShopFile().getShopIdentifierSection(identifier); inv.addButton(new EditGUIButton(new ItemBuilder(displayItemData.getString("Material")).setAmount(1), new EditGUIValueString("Material", displayItemData.getString("Material")) { @@ -156,8 +156,8 @@ public void open() { } private void setPathData(String path, Object value) { - plugin.getGui().getData().set("CHEST.Shop." + identifier + "." + path, value); - plugin.getGui().saveData(); + plugin.getShopFile().getData().set("Shop." + identifier + "." + path, value); + plugin.getShopFile().saveData(); plugin.reload(); } diff --git a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItemRemove.java b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItemRemove.java index 01642acd8..a827b9534 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItemRemove.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItemRemove.java @@ -42,9 +42,9 @@ public void onChest(Player player) { BInventory inv = new BInventory("Edit VoteShop Remove Item"); inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.VoteShop"); - for (final String identifier : plugin.getGui().getChestShopIdentifiers()) { + for (final String identifier : plugin.getShopFile().getShopIdentifiers()) { inv.addButton( - new BInventoryButton(new ItemBuilder(plugin.getGui().getChestShopIdentifierSection(identifier)) + new BInventoryButton(new ItemBuilder(plugin.getShopFile().getShopIdentifierSection(identifier)) .addLoreLine("&c&lClick to remove")) { @Override @@ -54,7 +54,7 @@ public void onClick(ClickEvent clickEvent) { @Override public void onConfirm(Player p) { - plugin.getGui().removeShop(identifier); + plugin.getShopFile().removeShop(identifier); p.sendMessage("Removed " + identifier); plugin.reload(); } @@ -65,7 +65,6 @@ public void onDeny(Player p) { } }.open(); - } }.addData("ident", identifier)); } diff --git a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItems.java b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItems.java index c3c2f8972..60fb960ec 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItems.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/admin/voteshop/AdminVoteVoteShopItems.java @@ -41,9 +41,9 @@ public void onChest(Player player) { BInventory inv = new BInventory("Edit VoteShop Items"); inv.requirePermission("VotingPlugin.Commands.AdminVote.Edit.VoteShop"); - for (String identifier : plugin.getGui().getChestShopIdentifiers()) { + for (String identifier : plugin.getShopFile().getShopIdentifiers()) { inv.addButton( - new BInventoryButton(new ItemBuilder(plugin.getGui().getChestShopIdentifierSection(identifier))) { + new BInventoryButton(new ItemBuilder(plugin.getShopFile().getShopIdentifierSection(identifier))) { @Override public void onClick(ClickEvent clickEvent) { diff --git a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/player/VoteShop.java b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/player/VoteShop.java index c6bbfff46..819da6264 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/player/VoteShop.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/player/VoteShop.java @@ -46,8 +46,8 @@ public void onChat(CommandSender sender) { @Override public void onChest(Player player) { - if (!plugin.getGui().isChestVoteShopEnabled()) { - player.sendMessage(MessageAPI.colorize(plugin.getGui().getChestVoteShopDisabled())); + if (!plugin.getShopFile().isVoteShopEnabled()) { + player.sendMessage(MessageAPI.colorize(plugin.getShopFile().getVoteShopDisabled())); return; } @@ -58,14 +58,14 @@ public void onChest(Player player) { /* * if (!plugin.getConfigFile().isExtraVoteShopCheck()) { user.cacheAsync(); } */ - BInventory inv = new BInventory(plugin.getGui().getChestVoteShopName()); + BInventory inv = new BInventory(plugin.getShopFile().getVoteShopName()); inv.addPlaceholder("points", "" + user.getPoints()); inv.addPlaceholder("sitesavailable", "" + user.getSitesNotVotedOn()); inv.dontClose(); - for (final String identifier : plugin.getGui().getChestShopIdentifiers()) { + for (final String identifier : plugin.getShopFile().getShopIdentifiers()) { - String perm = plugin.getGui().getChestVoteShopPermission(identifier); + String perm = plugin.getShopFile().getVoteShopPermission(identifier); boolean hasPerm = false; if (perm.isEmpty()) { hasPerm = true; @@ -77,7 +77,7 @@ public void onChest(Player player) { } } - int limit = plugin.getGui().getChestShopIdentifierLimit(identifier); + int limit = plugin.getShopFile().getShopIdentifierLimit(identifier); boolean limitPass = true; if (limit > 0) { @@ -86,10 +86,10 @@ public void onChest(Player player) { } } - if (!plugin.getGui().getChestVoteShopNotBuyable(identifier)) { - if ((hasPerm || !plugin.getGui().getChestVoteShopHideOnNoPermission(identifier)) - && (limitPass || !plugin.getGui().isChestVoteShopHideLimitedReached())) { - ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestShopIdentifierSection(identifier)); + if (!plugin.getShopFile().getVoteShopNotBuyable(identifier)) { + if ((hasPerm || !plugin.getShopFile().getVoteShopHideOnNoPermission(identifier)) + && (limitPass || !plugin.getShopFile().isVoteShopHideLimitedReached())) { + ItemBuilder builder = new ItemBuilder(plugin.getShopFile().getShopIdentifierSection(identifier)); inv.addButton(new BInventoryButton(builder) { @@ -104,7 +104,7 @@ public void onClick(ClickEvent event) { String identifier = (String) getData("identifier"); int limit = (int) getData("Limit"); - int points = plugin.getGui().getChestShopIdentifierCost(identifier); + int points = plugin.getShopFile().getShopIdentifierCost(identifier); if (identifier != null) { // if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) { // event.closeInventory(); @@ -119,10 +119,10 @@ public void onClick(ClickEvent event) { } if (limitPass) { - if (!plugin.getGui().isChestVoteShopRequireConfirmation(identifier)) { + if (!plugin.getShopFile().isVoteShopRequireConfirmation(identifier)) { HashMap placeholders = new HashMap(); placeholders.put("identifier", - plugin.getGui().getChestShopIdentifierIdentifierName(identifier)); + plugin.getShopFile().getShopIdentifierIdentifierName(identifier)); placeholders.put("points", "" + points); placeholders.put("limit", "" + limit); if (user.removePoints(points, true)) { @@ -132,12 +132,12 @@ public void onClick(ClickEvent event) { plugin.getServerData().addVoteShopPurchase(identifier); } - plugin.getRewardHandler().giveReward(user, plugin.getGui().getData(), - plugin.getGui().getChestShopIdentifierRewardsPath(identifier), + plugin.getRewardHandler().giveReward(user, plugin.getShopFile().getData(), + plugin.getShopFile().getShopIdentifierRewardsPath(identifier), new RewardOptions().setPlaceholders(placeholders)); user.sendMessage(PlaceholderUtils.replacePlaceHolder( - plugin.getGui().getCHESTVoteShopPurchase(identifier), + plugin.getShopFile().getVoteShopPurchase(identifier), placeholders)); if (limit > 0) { user.setVoteShopIdentifierLimit(identifier, @@ -159,10 +159,10 @@ public void run() { } } else { - user.sendMessage(plugin.getGui().getChestVoteShopLimitReached()); + user.sendMessage(plugin.getShopFile().getVoteShopLimitReached()); } plugin.getCommandLoader().processSlotClick(player, user, identifier); - if (plugin.getGui().isChestVoteShopReopenGUIOnPurchase()) { + if (plugin.getShopFile().isVoteShopReopenGUIOnPurchase()) { plugin.getCommandLoader().processSlotClick(player, user, "shop"); } } @@ -172,7 +172,7 @@ public void run() { } } else { if (hasPerm) { - ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestShopIdentifierSection(identifier)); + ItemBuilder builder = new ItemBuilder(plugin.getShopFile().getShopIdentifierSection(identifier)); inv.addButton(new BInventoryButton(builder) { @Override @@ -185,20 +185,20 @@ public void onClick(ClickEvent event) { } } - for (final String str : plugin.getGui().getChestGUIVoteShopExtraItems()) { - inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestGUIVoteShopExtraItems(str))) { + for (final String str : plugin.getShopFile().getVoteShopExtraItems()) { + inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getShopFile().getGUIVoteShopExtraItems(str))) { @Override public void onClick(ClickEvent clickEvent) { plugin.getCommandLoader().processSlotClick(player, user, str); - new RewardBuilder(plugin.getGui().getData(), + new RewardBuilder(plugin.getShopFile().getData(), "CHEST.VoteShopExtraItems." + str + "." + clickEvent.getButton().getLastRewardsPath(player)) .setGiveOffline(false).send(clickEvent.getPlayer()); } }); } - if (plugin.getGui().isChestVoteShopBackButton()) { + if (plugin.getShopFile().isVoteShopBackButton()) { inv.addButton(plugin.getCommandLoader().getBackButton(user)); } diff --git a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/player/VoteShopConfirm.java b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/player/VoteShopConfirm.java index dd63c16d7..802507b56 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/player/VoteShopConfirm.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/commands/gui/player/VoteShopConfirm.java @@ -47,15 +47,15 @@ public void onChat(CommandSender sender) { @Override public void onChest(Player player) { PlayerUtils.setPlayerMeta(plugin, player, "ident", identifier); - BInventory inv = new BInventory(plugin.getGui().getChestShopConfirmPurchaseTitle()); + BInventory inv = new BInventory(plugin.getShopFile().getShopConfirmPurchaseTitle()); inv.dontClose(); - inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestShopConfirmPurchaseYesItem())) { + inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getShopFile().getShopConfirmPurchaseYesItem())) { @Override public void onClick(ClickEvent event) { user.cache(); - int points = plugin.getGui().getChestShopIdentifierCost(identifier); - int limit = plugin.getGui().getChestShopIdentifierLimit(identifier); + int points = plugin.getShopFile().getShopIdentifierCost(identifier); + int limit = plugin.getShopFile().getShopIdentifierLimit(identifier); HashMap placeholders = new HashMap(); placeholders.put("identifier", identifier); placeholders.put("points", "" + points); @@ -67,12 +67,12 @@ public void onClick(ClickEvent event) { plugin.getServerData().addVoteShopPurchase(identifier); } - plugin.getRewardHandler().giveReward(user, plugin.getGui().getData(), - plugin.getGui().getChestShopIdentifierRewardsPath(identifier), + plugin.getRewardHandler().giveReward(user, plugin.getShopFile().getData(), + plugin.getShopFile().getShopIdentifierRewardsPath(identifier), new RewardOptions().setPlaceholders(placeholders)); user.sendMessage(PlaceholderUtils - .replacePlaceHolder(plugin.getGui().getCHESTVoteShopPurchase(identifier), placeholders)); + .replacePlaceHolder(plugin.getShopFile().getVoteShopPurchase(identifier), placeholders)); if (limit > 0) { user.setVoteShopIdentifierLimit(identifier, user.getVoteShopIdentifierLimit(identifier) + 1); } @@ -80,7 +80,7 @@ public void onClick(ClickEvent event) { user.sendMessage(PlaceholderUtils .replacePlaceHolder(plugin.getConfigFile().getFormatShopFailedMsg(), placeholders)); } - if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) { + if (plugin.getShopFile().getVoteShopCloseGUI(identifier)) { event.getButton().getInv().closeInv(player, null); } else { new VoteShop(plugin, event.getPlayer(), user).open(); @@ -88,11 +88,11 @@ public void onClick(ClickEvent event) { } }); - inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getGui().getChestShopConfirmPurchaseNoItem())) { + inv.addButton(new BInventoryButton(new ItemBuilder(plugin.getShopFile().getShopConfirmPurchaseNoItem())) { @Override public void onClick(ClickEvent event) { - if (plugin.getGui().getChestVoteShopCloseGUI(identifier)) { + if (plugin.getShopFile().getVoteShopCloseGUI(identifier)) { event.getButton().getInv().closeInv(player, null); } else { new VoteShop(plugin, event.getPlayer(), user).open(); diff --git a/VotingPlugin/src/com/bencodez/votingplugin/config/GUI.java b/VotingPlugin/src/com/bencodez/votingplugin/config/GUI.java index bda5d4bea..f20611379 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/config/GUI.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/config/GUI.java @@ -56,34 +56,6 @@ public class GUI extends YMLFile { @Getter private String bookVoteURLBookGUITitle = "&cVoteURL"; - @Getter - @ConfigDataConfigurationSection(path = "CHEST.ShopConfirmPurchase.NoItem") - private ConfigurationSection chestShopConfirmPurchaseNoItem; - - @Getter - @ConfigDataString(path = "CHEST.ShopConfirmPurchase.Title") - private String chestShopConfirmPurchaseTitle = "Confirm Purchase?"; - - @Getter - @ConfigDataConfigurationSection(path = "CHEST.ShopConfirmPurchase.YesItem") - private ConfigurationSection chestShopConfirmPurchaseYesItem; - - @Getter - @ConfigDataString(path = "CHEST.VoteShopDisabled") - private String chestVoteShopDisabled = "&cVote shop disabled"; - - @ConfigDataBoolean(path = "CHEST.VoteShopHideLimitedReached") - @Getter - private boolean chestVoteShopHideLimitedReached = true; - - @ConfigDataString(path = "CHEST.VoteShopLimitReached") - @Getter - private String chestVoteShopLimitReached = "&aYou reached your limit"; - - @ConfigDataBoolean(path = "CHEST.VoteShopRequireConfirmation") - @Getter - private boolean chestVoteShopRequireConfirmation = false; - @ConfigDataBoolean(path = "CHEST.VoteBest.BackButton") @Getter private boolean chestVoteBestBackButton = true; @@ -167,54 +139,10 @@ public GUI(VotingPluginMain plugin) { this.plugin = plugin; } - public void createShop(String value) { - ConfigurationSection shopData = getData().createSection("CHEST.Shop." + value); - shopData.set("Identifier_Name", value); - shopData.set("Material", "STONE"); - shopData.set("Amount", 1); - shopData.set("Name", "&cPlaceholder item"); - shopData.set("Cost", 1); - shopData.set("Permission", ""); - shopData.set("CloseGUI", true); - shopData.set("RequireConfirmation", false); - - shopData.set("Rewards.Items.Item1.Material", "STONE"); - shopData.set("Rewards.Items.Item1.Amount", 1); - saveData(); - } - @ConfigDataConfigurationSection(path = "CHEST.BackButton") @Getter private ConfigurationSection CHESTBackButton; - public int getChestShopIdentifierCost(String identifier) { - return getData().getInt("CHEST.Shop." + identifier + ".Cost"); - } - - public String getChestShopIdentifierIdentifierName(String identifier) { - return getData().getString("CHEST.Shop." + identifier + ".Identifier_Name", identifier); - } - - public int getChestShopIdentifierLimit(String identifier) { - return getData().getInt("CHEST.Shop." + identifier + ".Limit", -1); - } - - public String getChestShopIdentifierRewardsPath(String identifier) { - return "CHEST.Shop." + identifier + ".Rewards"; - } - - public Set getChestShopIdentifiers() { - ConfigurationSection shop = getData().getConfigurationSection("CHEST.Shop"); - if (shop != null) { - return shop.getKeys(false); - } - return new HashSet(); - } - - public ConfigurationSection getChestShopIdentifierSection(String identifier) { - return getData().getConfigurationSection("CHEST.Shop." + identifier); - } - @ConfigDataConfigurationSection(path = "CHEST.VoteBest.DayBest.Item") @Getter private ConfigurationSection chestVoteBestDayBestItem; @@ -246,6 +174,10 @@ public String getChestVoteGUISlotCommand(String slot) { return getData().getString("CHEST.VoteGUI." + slot + ".Command", ""); } + public ConfigurationSection getChestGUIExtraItemsItem(String gui, String item) { + return getData().getConfigurationSection("CHEST." + gui + ".ExtraItems." + item); + } + /** * Gets the vote GUI slot lore. * @@ -315,55 +247,6 @@ public String getChestVoteNextCustomSiteNamesDisplays(String site) { @Getter private String chestVoteRewardName = "VoteReward"; - @ConfigDataBoolean(path = "CHEST.VoteShopBackButton") - @Getter - private boolean chestVoteShopBackButton = true; - - @ConfigDataBoolean(path = "CHEST.VoteShopReopenGUIOnPurchase") - @Getter - private boolean chestVoteShopReopenGUIOnPurchase = true; - - public boolean getChestVoteShopCloseGUI(String shop) { - return getData().getBoolean("CHEST.Shop." + shop + ".CloseGUI", true); - } - - public boolean getChestVoteShopHideOnNoPermission(String shop) { - return getData().getBoolean("CHEST.Shop." + shop + ".HideOnNoPermission", true); - } - - @ConfigDataBoolean(path = "CHEST.VoteShopEnabled") - @Getter - private boolean chestVoteShopEnabled = true; - - @ConfigDataString(path = "CHEST.VoteShopName") - @Getter - private String chestVoteShopName = "VoteShop"; - - public boolean getChestVoteShopNotBuyable(String shop) { - return getData().getBoolean("CHEST.Shop." + shop + ".NotBuyable", false); - } - - public String getChestVoteShopPermission(String ident) { - return getData().getString("CHEST.Shop." + ident + ".Permission", ""); - } - - public String getCHESTVoteShopPurchase(String identifier) { - return getData().getString("CHEST.Shop." + identifier + ".PurchaseMessage", - plugin.getConfigFile().getFormatShopPurchaseMsg()); - } - - public boolean getChestVoteShopResetDaily(String shop) { - return getData().getBoolean("CHEST.Shop." + shop + ".Reset.Daily", false); - } - - public boolean getChestVoteShopResetMonthly(String shop) { - return getData().getBoolean("CHEST.Shop." + shop + ".Reset.Monthly", false); - } - - public boolean getChestVoteShopResetWeekly(String shop) { - return getData().getBoolean("CHEST.Shop." + shop + ".Reset.Weekly", false); - } - @ConfigDataBoolean(path = "CHEST.VoteStreak.BackButton") @Getter private boolean chestVoteStreakBackButton = false; @@ -523,18 +406,6 @@ public Set getChestGUIExtraItems(String gui) { return new HashSet(); } - public ConfigurationSection getChestGUIVoteShopExtraItems(String item) { - return getData().getConfigurationSection("CHEST.VoteShopExtraItems." + item); - } - - @ConfigDataKeys(path = "CHEST.VoteShopExtraItems") - @Getter - private Set chestGUIVoteShopExtraItems = new HashSet(); - - public ConfigurationSection getChestGUIExtraItemsItem(String gui, String item) { - return getData().getConfigurationSection("CHEST." + gui + ".ExtraItems." + item); - } - @ConfigDataString(path = "CHEST.VoteURL.SiteName") @Getter private String chestVoteURLGUISiteName = "&c%Name%"; @@ -567,11 +438,6 @@ public ConfigurationSection getChestGUIExtraItemsItem(String gui, String item) { @Getter private boolean chestVoteURLViewAllUrlsButtonEnabled = false; - public boolean isChestVoteShopRequireConfirmation(String identifier) { - return getData().getBoolean("CHEST.Shop." + identifier + ".RequireConfirmation", - isChestVoteShopRequireConfirmation()); - } - @Override public void loadValues() { new AnnotationHandler().load(getData(), this); @@ -581,9 +447,4 @@ public void loadValues() { public void onFileCreation() { plugin.saveResource("GUI.yml", true); } - - public void removeShop(String value) { - getData().set("CHEST.Shop." + value, null); - saveData(); - } } diff --git a/VotingPlugin/src/com/bencodez/votingplugin/config/ShopFile.java b/VotingPlugin/src/com/bencodez/votingplugin/config/ShopFile.java new file mode 100644 index 000000000..8be0d76bf --- /dev/null +++ b/VotingPlugin/src/com/bencodez/votingplugin/config/ShopFile.java @@ -0,0 +1,208 @@ +package com.bencodez.votingplugin.config; + +import java.io.File; +import java.util.HashSet; +import java.util.Set; + +import org.bukkit.configuration.ConfigurationSection; + +import com.bencodez.advancedcore.api.yml.YMLFile; +import com.bencodez.simpleapi.file.annotation.AnnotationHandler; +import com.bencodez.simpleapi.file.annotation.ConfigDataBoolean; +import com.bencodez.simpleapi.file.annotation.ConfigDataConfigurationSection; +import com.bencodez.simpleapi.file.annotation.ConfigDataKeys; +import com.bencodez.simpleapi.file.annotation.ConfigDataString; +import com.bencodez.votingplugin.VotingPluginMain; + +import lombok.Getter; + +public class ShopFile extends YMLFile { + + @Getter + @ConfigDataConfigurationSection(path = "ShopConfirmPurchase.NoItem") + private ConfigurationSection shopConfirmPurchaseNoItem; + + @Getter + @ConfigDataString(path = "ShopConfirmPurchase.Title") + private String shopConfirmPurchaseTitle = "Confirm Purchase?"; + + @Getter + @ConfigDataConfigurationSection(path = "ShopConfirmPurchase.YesItem") + private ConfigurationSection shopConfirmPurchaseYesItem; + + @Getter + @ConfigDataString(path = "VoteShop.Disabled") + private String voteShopDisabled = "&cVote shop disabled"; + + @ConfigDataBoolean(path = "VoteShop.HideLimitedReached") + @Getter + private boolean voteShopHideLimitedReached = true; + + @ConfigDataString(path = "VoteShop.LimitReached") + @Getter + private String voteShopLimitReached = "&aYou reached your limit"; + + @ConfigDataBoolean(path = "VoteShop.RequireConfirmation") + @Getter + private boolean voteShopRequireConfirmation = false; + + private VotingPluginMain plugin; + + public ShopFile(VotingPluginMain plugin) { + super(plugin, new File(plugin.getDataFolder(), "Shop.yml")); + this.plugin = plugin; + } + + public void createShop(String value) { + ConfigurationSection shopData = getData().createSection("Shop." + value); + shopData.set("Identifier_Name", value); + shopData.set("Material", "STONE"); + shopData.set("Amount", 1); + shopData.set("Name", "&cPlaceholder item"); + shopData.set("Cost", 1); + shopData.set("Permission", ""); + shopData.set("CloseGUI", true); + shopData.set("RequireConfirmation", false); + + shopData.set("Rewards.Items.Item1.Material", "STONE"); + shopData.set("Rewards.Items.Item1.Amount", 1); + saveData(); + } + + @ConfigDataConfigurationSection(path = "CHEST.BackButton") + @Getter + private ConfigurationSection CHESTBackButton; + + public int getShopIdentifierCost(String identifier) { + return getData().getInt("Shop." + identifier + ".Cost"); + } + + public String getShopIdentifierIdentifierName(String identifier) { + return getData().getString("Shop." + identifier + ".Identifier_Name", identifier); + } + + public int getShopIdentifierLimit(String identifier) { + return getData().getInt("Shop." + identifier + ".Limit", -1); + } + + public String getShopIdentifierRewardsPath(String identifier) { + return "Shop." + identifier + ".Rewards"; + } + + public Set getShopIdentifiers() { + ConfigurationSection shop = getData().getConfigurationSection("Shop"); + if (shop != null) { + return shop.getKeys(false); + } + return new HashSet(); + } + + public ConfigurationSection getShopIdentifierSection(String identifier) { + return getData().getConfigurationSection("Shop." + identifier); + } + + @ConfigDataBoolean(path = "VoteShop.BackButton") + @Getter + private boolean voteShopBackButton = true; + + @ConfigDataBoolean(path = "VoteShop.ReopenGUIOnPurchase") + @Getter + private boolean voteShopReopenGUIOnPurchase = true; + + public boolean getVoteShopCloseGUI(String shop) { + return getData().getBoolean("Shop." + shop + ".CloseGUI", true); + } + + public boolean getVoteShopHideOnNoPermission(String shop) { + return getData().getBoolean("Shop." + shop + ".HideOnNoPermission", true); + } + + @ConfigDataBoolean(path = "VoteShop.Enabled") + @Getter + private boolean voteShopEnabled = true; + + @ConfigDataString(path = "VoteShop.Name") + @Getter + private String voteShopName = "VoteShop"; + + public boolean getVoteShopNotBuyable(String shop) { + return getData().getBoolean("Shop." + shop + ".NotBuyable", false); + } + + public String getVoteShopPermission(String ident) { + return getData().getString("Shop." + ident + ".Permission", ""); + } + + public String getVoteShopPurchase(String identifier) { + return getData().getString("Shop." + identifier + ".PurchaseMessage", + plugin.getConfigFile().getFormatShopPurchaseMsg()); + } + + public boolean getVoteShopResetDaily(String shop) { + return getData().getBoolean("Shop." + shop + ".Reset.Daily", false); + } + + public boolean getVoteShopResetMonthly(String shop) { + return getData().getBoolean("Shop." + shop + ".Reset.Monthly", false); + } + + public boolean getVoteShopResetWeekly(String shop) { + return getData().getBoolean("Shop." + shop + ".Reset.Weekly", false); + } + + public ConfigurationSection getGUIVoteShopExtraItems(String item) { + return getData().getConfigurationSection("VoteShopExtraItems." + item); + } + + @ConfigDataKeys(path = "VoteShopExtraItems") + @Getter + private Set voteShopExtraItems = new HashSet(); + + public boolean isVoteShopRequireConfirmation(String identifier) { + return getData().getBoolean("Shop." + identifier + ".RequireConfirmation", isVoteShopRequireConfirmation()); + } + + @Override + public void loadValues() { + new AnnotationHandler().load(getData(), this); + } + + @Override + public void onFileCreation() { + plugin.saveResource("Shop.yml", true); + reloadData(); + // auto conversion + if (!plugin.getGui().isJustCreated()) { + plugin.getLogger().warning("Converting VoteShop configuration to Shop.yml from GUI.yml"); + convertFromGUIFile(); + } + } + + public void convertFromGUIFile() { + // booleans + setValue("VoteShop.Enabled", plugin.getGui().getData().getBoolean("CHEST.VoteShopEnabled")); + setValue("VoteShop.BackButton", plugin.getGui().getData().getBoolean("CHEST.VoteShopBackButton")); + setValue("VoteShop.HideLimitReached", plugin.getGui().getData().getBoolean("CHEST.VoteShopHideLimitedReached")); + setValue("VoteShop.RequireConfirmation", + plugin.getGui().getData().getBoolean("CHEST.VoteShopRequireConfirmation")); + setValue("VoteShop.ReopenGUIOnPurchase", + plugin.getGui().getData().getBoolean("CHEST.VoteShopReopenGUIOnPurchase")); + + // strings + setValue("VoteShop.Name", plugin.getGui().getData().getString("CHEST.VoteShopName")); + setValue("VoteShop.LimitReached", plugin.getGui().getData().getString("CHEST.VoteShopLimitReached")); + setValue("VoteShop.Disabled", plugin.getGui().getData().getString("CHEST.VoteShopDisabled")); + + // sections + setValue("Shop", plugin.getGui().getData().getConfigurationSection("CHEST.Shop")); + setValue("ExtraItems", plugin.getGui().getData().getConfigurationSection("CHEST.VoteShopExtraItems")); + setValue("ShopConfirmPurchase", plugin.getGui().getData().getConfigurationSection("CHEST.ShopConfirmPurchase")); + saveData(); + + } + + public void removeShop(String value) { + getData().set("Shop." + value, null); + saveData(); + } +} diff --git a/VotingPlugin/src/com/bencodez/votingplugin/placeholders/PlaceHolders.java b/VotingPlugin/src/com/bencodez/votingplugin/placeholders/PlaceHolders.java index 3acb19ae7..d8fda3dc1 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/placeholders/PlaceHolders.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/placeholders/PlaceHolders.java @@ -352,8 +352,8 @@ public String placeholderRequest(VotingPluginUser user, String identifier) { } }.withDescription("Get number of votes until next available milestone").updateDataKey("MilestoneCount")); - for (final String identifier : plugin.getGui().getChestShopIdentifiers()) { - if (plugin.getGui().getChestShopIdentifierLimit(identifier) > 0) { + for (final String identifier : plugin.getShopFile().getShopIdentifiers()) { + if (plugin.getShopFile().getShopIdentifierLimit(identifier) > 0) { placeholders.add(new PlaceHolder("VoteShopLimit_" + identifier) { @Override diff --git a/VotingPlugin/src/com/bencodez/votingplugin/topvoter/TopVoterHandler.java b/VotingPlugin/src/com/bencodez/votingplugin/topvoter/TopVoterHandler.java index 9c60efdc8..65dcfdda8 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/topvoter/TopVoterHandler.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/topvoter/TopVoterHandler.java @@ -198,8 +198,8 @@ public void onDayChange(DayChangeEvent event) { e.printStackTrace(); } - for (String shopIdent : plugin.getGui().getChestShopIdentifiers()) { - if (plugin.getGui().getChestVoteShopResetDaily(shopIdent)) { + for (String shopIdent : plugin.getShopFile().getShopIdentifiers()) { + if (plugin.getShopFile().getVoteShopResetDaily(shopIdent)) { resetVoteShopLimit(shopIdent); } } @@ -315,8 +315,8 @@ public void onMonthChange(MonthChangeEvent event) { resetGottenMilestones(); } - for (String shopIdent : plugin.getGui().getChestShopIdentifiers()) { - if (plugin.getGui().getChestVoteShopResetMonthly(shopIdent)) { + for (String shopIdent : plugin.getShopFile().getShopIdentifiers()) { + if (plugin.getShopFile().getVoteShopResetMonthly(shopIdent)) { resetVoteShopLimit(shopIdent); } } @@ -425,8 +425,8 @@ public void onWeekChange(WeekChangeEvent event) { e.printStackTrace(); } - for (String shopIdent : plugin.getGui().getChestShopIdentifiers()) { - if (plugin.getGui().getChestVoteShopResetWeekly(shopIdent)) { + for (String shopIdent : plugin.getShopFile().getShopIdentifiers()) { + if (plugin.getShopFile().getVoteShopResetWeekly(shopIdent)) { resetVoteShopLimit(shopIdent); } }