Skip to content

Commit

Permalink
Added Shop.yml, with auto conversion from GUI.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCodez committed Jun 30, 2024
1 parent c1f9ba2 commit b13afd5
Show file tree
Hide file tree
Showing 13 changed files with 367 additions and 215 deletions.
77 changes: 77 additions & 0 deletions VotingPlugin/Resources/Shop.yml
Original file line number Diff line number Diff line change
@@ -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'


19 changes: 13 additions & 6 deletions VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,6 +145,9 @@ public class VotingPluginMain extends AdvancedCorePlugin {
@Getter
private GUI gui;

@Getter
private ShopFile shopFile;

@Getter
private LinkedHashMap<TopVoterPlayer, Integer> lastMonthTopVoter;

Expand Down Expand Up @@ -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);
}
});
}
Expand Down Expand Up @@ -1541,6 +1545,9 @@ private void setupFiles() {

gui = new GUI(this);
gui.setup();

shopFile = new ShopFile(this);
shopFile.setup();

serverData = new ServerData(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
});
Expand Down Expand Up @@ -2106,7 +2106,7 @@ public void updateReplacements() {
@Override
public void reload() {
ArrayList<String> sites = new ArrayList<String>();
for (String str : plugin.getGui().getChestShopIdentifiers()) {
for (String str : plugin.getShopFile().getShopIdentifiers()) {
sites.add(str);
}
setReplace(sites);
Expand Down Expand Up @@ -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) {

Expand All @@ -2202,29 +2202,29 @@ 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<String> identifiers = plugin.getGui().getChestShopIdentifiers();
Set<String> identifiers = plugin.getShopFile().getShopIdentifiers();
if (ArrayUtils.containsIgnoreCase(identifiers, identifier)) {
for (String ident : identifiers) {
if (ident.equalsIgnoreCase(args[1])) {
identifier = ident;
}
}

String perm = plugin.getGui().getChestVoteShopPermission(identifier);
String perm = plugin.getShopFile().getVoteShopPermission(identifier);
boolean hasPerm = false;
if (perm.isEmpty()) {
hasPerm = true;
} else {
hasPerm = sender.hasPermission(perm);
}

int limit = plugin.getGui().getChestShopIdentifierLimit(identifier);
int limit = plugin.getShopFile().getShopIdentifierLimit(identifier);

VotingPluginUser user = plugin.getVotingPluginUserManager()
.getVotingPluginUser(sender.getName());
Expand All @@ -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) {
Expand All @@ -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(
Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,31 @@ 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) {
setPathData(getKey(), 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) {
setPathData(getKey(), 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) {
setPathData(getKey(), num.intValue());
}
}));
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) {
Expand All @@ -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")) {

Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand All @@ -65,7 +65,6 @@ public void onDeny(Player p) {
}
}.open();


}
}.addData("ident", identifier));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit b13afd5

Please sign in to comment.