(index));
+ Bukkit.getPluginManager().callEvent(changeEvent);
+ if (changeEvent.isCancelled()) return;
+
+ if (shop.removeSideIndex(side, index))
+ Message.ITEM_REMOVED.sendMessage(pSender);
+ else
+ Message.ITEM_NOT_REMOVED.sendMessage(pSender);
+ }
+
+ /**
+ * Sets the item for the specified side to a Shop
+ *
+ * With no variables sent, this will use the amount and data of the held item
+ *
+ *
+ * If the player uses a int in the first variable they can change the amount for the item they are holding
+ *
+ *
+ * With 2 variables used the player can use an amount and material to set the sign instead of a held item
+ *
+ */
+ public void setSide() {
+ Shop shop = findShop();
+
+ if (shop == null)
+ return;
+
+ int amount = 0;
+ Material mat = null;
+
+ if (command.hasArgAt(1) && isInt(command.getArgAt(1))) {
+ amount = Integer.parseInt(command.getArgAt(1));
+ }
+
+ if (command.hasArgAt(2) && Material.getMaterial(command.getArgAt(2).toUpperCase()) != null) {
+ mat = Material.getMaterial(command.getArgAt(2).toUpperCase());
+ }
+
+ if (!(shop.getUsersUUID(ShopRole.MANAGER, ShopRole.OWNER).contains(pSender.getUniqueId())
+ || (Setting.UNLIMITED_ADMIN.getBoolean() && Permissions.isAdminEnabled(pSender)))) {
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
+ return;
+ }
+
+ ItemStack itemInHand;
+
+ if (mat == null) {
+ itemInHand = pSender.getInventory().getItemInMainHand().clone();
+ } else {
+ itemInHand = new ItemStack(mat, 1);
+ }
+
+ if (itemInHand.getType() == Material.AIR) {
+ Message.HELD_EMPTY.sendMessage(pSender);
+ return;
+ }
+
+ if (isIllegal(side, itemInHand.getType())) {
+ Message.ILLEGAL_ITEM.sendMessage(pSender);
+ return;
+ }
+
+ if (!(shop.getShopType().isITrade() && shop.getInventoryLocation() == null) && itemInHand.getType().toString().endsWith("SHULKER_BOX") && shop.getInventoryLocation().getBlock().getType().toString().endsWith("SHULKER_BOX")) {
+ Message.NO_SHULKER_ITEM.sendMessage(pSender);
+ return;
+ }
+
+ if (amount > 0) {
+ itemInHand.setAmount(amount);
+ }
+
+ if (Math.ceil((double) itemInHand.getAmount() / (double) itemInHand.getMaxStackSize()) > Setting.MAX_ITEMS_PER_TRADE_SIDE.getInt()) {
+ Message.TOO_MANY_ITEMS.sendMessage(pSender, new Tuple<>(Variable.SIDE.toString(), side.toString().toLowerCase()));
+ return;
+ }
+
+ PlayerShopChangeEvent changeEvent = new PlayerShopChangeEvent(pSender, shop, ShopChange.valueOf("SET_" + side.toString()), new ObjectHolder(itemInHand));
+ Bukkit.getPluginManager().callEvent(changeEvent);
+ if (changeEvent.isCancelled()) return;
+
+ shop.setSideItems(side, itemInHand);
+
+ Message.ITEM_ADDED.sendMessage(pSender);
+ }
+
+ /**
+ * Adds a item to the specified side of a Shop
+ *
+ * With no variables sent will use the amount and data of the held item
+ *
+ *
+ * If the player uses a int in the first variable they can change the amount for the item they are holding
+ *
+ *
+ * With 2 variables used the player can use an amount and material to set the sign instead of a held item
+ *
+ */
+ public void addSide() {
+ Shop shop = findShop();
+
+ if (shop == null)
+ return;
+
+ int amount = 0;
+ Material mat = null;
+
+ if (command.hasArgAt(1) && isInt(command.getArgAt(1))) {
+ amount = Integer.parseInt(command.getArgAt(1));
+ }
+
+ if (command.hasArgAt(2) && Material.getMaterial(command.getArgAt(2).toUpperCase()) != null) {
+ mat = Material.getMaterial(command.getArgAt(2).toUpperCase());
+ }
+
+ if (!(shop.getUsersUUID(ShopRole.MANAGER, ShopRole.OWNER).contains(pSender.getUniqueId())
+ || (Setting.UNLIMITED_ADMIN.getBoolean() && Permissions.isAdminEnabled(pSender)))) {
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
+ return;
+ }
+
+ ItemStack itemInHand;
+
+ if (mat == null) {
+ itemInHand = pSender.getInventory().getItemInMainHand().clone();
+ } else {
+ itemInHand = new ItemStack(mat, 1);
+ }
+
+ if (itemInHand.getType() == Material.AIR) {
+ Message.HELD_EMPTY.sendMessage(pSender);
+ return;
+ }
+
+ if (isIllegal(side, itemInHand.getType())) {
+ Message.ILLEGAL_ITEM.sendMessage(pSender);
+ return;
+ }
+
+ if (!(shop.getShopType().isITrade() && shop.getInventoryLocation() == null) && itemInHand.getType().toString().endsWith("SHULKER_BOX") && shop.getInventoryLocation().getBlock().getType().toString().endsWith("SHULKER_BOX")) {
+ Message.NO_SHULKER_ITEM.sendMessage(pSender);
+ return;
+ }
+
+ if (amount > 0) {
+ itemInHand.setAmount(amount);
+ }
+
+ if (shop.getSideList(side).size() + Math.ceil((double) itemInHand.getAmount() / (double) itemInHand.getMaxStackSize()) > Setting.MAX_ITEMS_PER_TRADE_SIDE.getInt()) {
+ Message.TOO_MANY_ITEMS.sendMessage(pSender, new Tuple<>(Variable.SIDE.toString(), side.toString().toLowerCase()));
+ return;
+ }
+
+ PlayerShopChangeEvent changeEvent = new PlayerShopChangeEvent(pSender, shop, ShopChange.valueOf("ADD_" + side.toString()), new ObjectHolder(itemInHand));
+ Bukkit.getPluginManager().callEvent(changeEvent);
+ if (changeEvent.isCancelled()) return;
+
+ shop.addSideItem(side, itemInHand);
+
+ Message.ITEM_ADDED.sendMessage(pSender);
+ }
+}
diff --git a/src/main/java/org/shanerx/tradeshop/commands/commandrunners/ShopUserCommand.java b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/ShopUserCommand.java
new file mode 100644
index 00000000..86cb6e2f
--- /dev/null
+++ b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/ShopUserCommand.java
@@ -0,0 +1,260 @@
+/*
+ *
+ * Copyright (c) 2016-2019
+ * SparklingComet @ http://shanerx.org
+ * KillerOfPie @ http://killerofpie.github.io
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * NOTICE: All modifications made by others to the source code belong
+ * to the respective contributor. No contributor should be held liable for
+ * any damages of any kind, whether be material or moral, which were
+ * caused by their contribution(s) to the project. See the full License for more information.
+ *
+ */
+
+package org.shanerx.tradeshop.commands.commandrunners;
+
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.shanerx.tradeshop.TradeShop;
+import org.shanerx.tradeshop.commands.CommandPass;
+import org.shanerx.tradeshop.data.config.Message;
+import org.shanerx.tradeshop.data.config.Setting;
+import org.shanerx.tradeshop.data.config.Variable;
+import org.shanerx.tradeshop.framework.ShopChange;
+import org.shanerx.tradeshop.framework.events.PlayerShopChangeEvent;
+import org.shanerx.tradeshop.player.Permissions;
+import org.shanerx.tradeshop.player.ShopRole;
+import org.shanerx.tradeshop.player.ShopUser;
+import org.shanerx.tradeshop.shop.Shop;
+import org.shanerx.tradeshop.shoplocation.ShopLocation;
+import org.shanerx.tradeshop.utils.objects.ObjectHolder;
+import org.shanerx.tradeshop.utils.objects.Tuple;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+enum UserOperationStatus {
+ SUCCESSFUL(Message.UPDATED_SHOP_USERS_SUCCESSFUL),
+ FAILED(Message.UPDATED_SHOP_USERS_FAILED),
+ FAILED_CAPACITY(Message.UPDATED_SHOP_USERS_FAILED_CAPACITY),
+ FAILED_EXISTING(Message.UPDATED_SHOP_USERS_FAILED_EXISTING),
+ FAILED_MISSING(Message.UPDATED_SHOP_USERS_FAILED_MISSING);
+
+ private final Message text;
+
+ UserOperationStatus(Message text) {
+ this.text = text;
+ }
+
+ @Override
+ public String toString() {
+ return text.toString();
+ }
+}
+
+/**
+ * Implementation of CommandRunner for commands that view/change shop users
+ *
+ * @since 2.6.0
+ */
+public class ShopUserCommand extends CommandRunner {
+
+ private OfflinePlayer target;
+
+ public ShopUserCommand(TradeShop instance, CommandPass command) {
+ super(instance, command);
+ }
+
+ /**
+ * Tells the player who the Owner/Managers/Members that are on the shop are
+ */
+ public void who() {
+ String owner = "";
+ StringBuilder managers = new StringBuilder();
+ StringBuilder members = new StringBuilder();
+ Shop shop = findShop();
+
+ if (shop == null)
+ return;
+
+ if (shop.getShopType().isITrade()) {
+ Message.WHO_MESSAGE.sendMessage(pSender,
+ new Tuple<>(Variable.OWNER.toString(), Setting.ITRADESHOP_OWNER.getString()),
+ new Tuple<>(Variable.MANAGERS.toString(), "None"),
+ new Tuple<>(Variable.MEMBERS.toString(), "None"));
+ return;
+ }
+
+ if (shop.getOwner() != null)
+ owner = shop.getOwner().getName();
+
+ if (shop.hasUsers(ShopRole.MANAGER)) {
+ for (ShopUser usr : shop.getUsers(ShopRole.MANAGER)) {
+ if (managers.toString().equals(""))
+ managers = new StringBuilder(usr.getName());
+ else
+ managers.append(", ").append(usr.getName());
+ }
+ }
+
+ if (shop.hasUsers(ShopRole.MEMBER)) {
+ for (ShopUser usr : shop.getUsers(ShopRole.MEMBER)) {
+ if (members.toString().equals(""))
+ members = new StringBuilder(usr.getName());
+ else
+ members.append(", ").append(usr.getName());
+ }
+ }
+
+ if (managers.toString().equals("")) {
+ managers = new StringBuilder("None");
+ }
+ if (members.toString().equals("")) {
+ members = new StringBuilder("None");
+ }
+ Message.WHO_MESSAGE.sendMessage(pSender,
+ new Tuple<>(Variable.OWNER.toString(), owner),
+ new Tuple<>(Variable.MANAGERS.toString(), managers.toString()),
+ new Tuple<>(Variable.MEMBERS.toString(), members.toString()));
+ }
+
+ /**
+ * Adds or Removes the specified player to/from the shop as the specified role
+ */
+ public void editUser(ShopRole role, ShopChange change) {
+ boolean applyAllOwned = command.hasArgAt(2) && command.getArgAt(2).length() > 0 && toBool(command.getArgAt(2));
+ Set ownedShops = new HashSet<>();
+ Map updateStatuses = new HashMap<>();
+
+ Shop tempShop = shopUserCommandStart(applyAllOwned);
+
+ if (tempShop == null && target == null) {
+ return;
+ }
+
+ if (applyAllOwned) {
+ for (String location : plugin.getDataStorage().loadPlayer(pSender.getUniqueId()).getOwnedShops()) {
+ ownedShops.add(plugin.getDataStorage().loadShopFromSign(ShopLocation.fromString(location)));
+ }
+ } else {
+ ownedShops.add(tempShop);
+ }
+
+ for (Shop shop : ownedShops) {
+ eachOwnedShop:
+ {
+ switch (change) {
+ case REMOVE_USER:
+ if (!shop.getUsersUUID(ShopRole.MANAGER, ShopRole.MEMBER).contains(target.getUniqueId())) {
+ updateStatuses.put(shop.getShopLocationAsSL().toString(), UserOperationStatus.FAILED_MISSING.toString());
+ break eachOwnedShop;
+ }
+ break;
+ case ADD_MANAGER:
+ case ADD_MEMBER:
+ if (shop.getUsersUUID(ShopRole.MANAGER, ShopRole.MEMBER).contains(target.getUniqueId())) {
+ updateStatuses.put(shop.getShopLocationAsSL().toString(), UserOperationStatus.FAILED_EXISTING.toString());
+ break eachOwnedShop;
+ } else if (shop.getUsers(ShopRole.MANAGER, ShopRole.MEMBER).size() >= Setting.MAX_SHOP_USERS.getInt()) {
+ updateStatuses.put(shop.getShopLocationAsSL().toString(), UserOperationStatus.FAILED_CAPACITY.toString());
+ break eachOwnedShop;
+ }
+ break;
+ case SET_MANAGER:
+ case SET_MEMBER:
+ if (shop.getUsersExcluding(Collections.singletonList(target.getUniqueId()), ShopRole.MANAGER, ShopRole.MEMBER).size() >= Setting.MAX_SHOP_USERS.getInt()) {
+ updateStatuses.put(shop.getShopLocationAsSL().toString(), UserOperationStatus.FAILED_CAPACITY.toString());
+ break eachOwnedShop;
+ }
+ break;
+ }
+
+ PlayerShopChangeEvent changeEvent = new PlayerShopChangeEvent(pSender, shop, change, new ObjectHolder(target));
+ Bukkit.getPluginManager().callEvent(changeEvent);
+ if (changeEvent.isCancelled()) return;
+
+ boolean success = false;
+
+ switch (change) {
+ case SET_MANAGER:
+ case SET_MEMBER:
+ success = shop.setUser(target.getUniqueId(), role);
+ break;
+ case ADD_MEMBER:
+ case ADD_MANAGER:
+ success = shop.addUser(target.getUniqueId(), role);
+ break;
+ case REMOVE_USER:
+ success = shop.removeUser(target.getUniqueId());
+ break;
+ }
+
+ if (success)
+ updateStatuses.put(shop.getShopLocationAsSL().toString(), UserOperationStatus.SUCCESSFUL.toString());
+ else
+ updateStatuses.put(shop.getShopLocationAsSL().toString(), UserOperationStatus.FAILED.toString());
+ }
+ }
+
+ Message.UPDATED_SHOP_USERS.sendUserEditMultiLineMessage(pSender, Collections.singletonMap(Variable.UPDATED_SHOPS, updateStatuses));
+ }
+
+
+ //region Util Methods
+ //------------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Checks if targeted player exists and if player is looking at a shop while not targetting all owned shops
+ *
+ * @param applyAllOwned Is Player targetting all owned shops
+ * @return shop if found or null if not needed; returning null while setting target to null indicates failure, command should respond with an immediate blank return.
+ */
+ private Shop shopUserCommandStart(boolean applyAllOwned) {
+ target = Bukkit.getOfflinePlayer(command.getArgAt(1));
+ if (!target.hasPlayedBefore()) {
+ Message.PLAYER_NOT_FOUND.sendMessage(pSender);
+ target = null;
+ return null;
+ }
+
+ if (!applyAllOwned) {
+ Shop shop = findShop();
+
+ if (shop == null) {
+ // Message.NO_SIGHTED_SHOP.sendMessage(pSender); // Message is sent by findShop()
+ target = null;
+ return null;
+ }
+
+ if (!shop.getOwner().getUUID().equals(pSender.getUniqueId())
+ || (Setting.UNLIMITED_ADMIN.getBoolean() && Permissions.isAdminEnabled(pSender))) {
+ Message.NO_SHOP_PERMISSION.sendMessage(pSender);
+ target = null;
+ return null;
+ }
+
+ return shop;
+ }
+
+ return null;
+ }
+
+
+ //------------------------------------------------------------------------------------------------------------------
+ //endregion
+}
\ No newline at end of file
diff --git a/src/main/java/org/shanerx/tradeshop/commands/commandrunners/WhatCommand.java b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/WhatCommand.java
new file mode 100644
index 00000000..a1699523
--- /dev/null
+++ b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/WhatCommand.java
@@ -0,0 +1,119 @@
+/*
+ *
+ * Copyright (c) 2016-2019
+ * SparklingComet @ http://shanerx.org
+ * KillerOfPie @ http://killerofpie.github.io
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * NOTICE: All modifications made by others to the source code belong
+ * to the respective contributor. No contributor should be held liable for
+ * any damages of any kind, whether be material or moral, which were
+ * caused by their contribution(s) to the project. See the full License for more information.
+ *
+ */
+
+package org.shanerx.tradeshop.commands.commandrunners;
+
+import de.themoep.inventorygui.GuiElementGroup;
+import de.themoep.inventorygui.InventoryGui;
+import de.themoep.inventorygui.StaticGuiElement;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemStack;
+import org.shanerx.tradeshop.TradeShop;
+import org.shanerx.tradeshop.commands.CommandPass;
+import org.shanerx.tradeshop.data.config.Message;
+import org.shanerx.tradeshop.data.config.Setting;
+import org.shanerx.tradeshop.item.ShopItemSide;
+import org.shanerx.tradeshop.item.ShopItemStack;
+import org.shanerx.tradeshop.player.Permissions;
+import org.shanerx.tradeshop.shop.Shop;
+import org.shanerx.tradeshop.shop.ShopType;
+
+/**
+ * Implementation of GUICommand for the `what` command
+ *
+ * @since 2.3.0
+ */
+public class WhatCommand extends GUICommand {
+
+ public WhatCommand(TradeShop instance, CommandPass command) {
+ super(instance, command);
+ }
+
+ /**
+ * Opens a GUI containing the items to be traded at the shop the player is looking at
+ */
+ public void what() {
+ Shop shop = findShop();
+
+ if (shop == null)
+ return;
+
+ shop.updateFullTradeCount();
+ shop.updateSign();
+
+ if (!Permissions.hasPermission(pSender, Permissions.INFO)) {
+ command.sendMessage(Message.NO_COMMAND_PERMISSION.getPrefixed());
+ return;
+ }
+
+ InventoryGui gui = new InventoryGui(plugin, colorize(shop.getShopType() == ShopType.ITRADE ?
+ Setting.ITRADESHOP_OWNER.getString() :
+ Bukkit.getOfflinePlayer(shop.getOwner().getUUID()).getName() + "'s Shop"),
+ WHAT_MENU);
+
+ GuiElementGroup costGroup = new GuiElementGroup('q'), productGroup = new GuiElementGroup('e');
+
+ gui.setFiller(new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE, 1));
+
+ if (costItems.isEmpty()) {
+ for (ShopItemStack item : shop.getSideList(ShopItemSide.COST)) {
+ costItems.add(item.clone());
+ }
+ }
+
+ if (productItems.isEmpty()) {
+ for (ShopItemStack item : shop.getSideList(ShopItemSide.PRODUCT)) {
+ productItems.add(item.clone());
+ }
+ }
+
+
+ for (int i = 0; i < costItems.size(); i++) {
+ costGroup.addElement(itemSettingMenu(i, ShopItemSide.COST, false));
+ }
+
+ for (int i = 0; i < productItems.size(); i++) {
+ productGroup.addElement(itemSettingMenu(i, ShopItemSide.PRODUCT, false));
+ }
+
+ gui.addElement(new StaticGuiElement('1', new ItemStack(Material.LIME_STAINED_GLASS_PANE),
+ " "));
+ gui.addElement(new StaticGuiElement('2', new ItemStack(Material.BLACK_STAINED_GLASS_PANE),
+ " "));
+ gui.addElement(new StaticGuiElement('3', new ItemStack(Material.LIGHT_BLUE_STAINED_GLASS_PANE),
+ " "));
+ gui.addElement(new StaticGuiElement('4', new ItemStack(Material.GOLD_NUGGET),
+ "Cost", "This is the item", "that you give to", "make the trade."));
+ gui.addElement(new StaticGuiElement('5', new ItemStack(Material.GRASS_BLOCK),
+ "Product", "This is the item", "that you receive", "from the trade."));
+ gui.addElement(getPrevButton());
+ gui.addElement(getNextButton());
+ gui.addElement(costGroup);
+ gui.addElement(productGroup);
+
+ gui.show(pSender);
+ }
+}
diff --git a/src/main/java/org/shanerx/tradeshop/utils/config/ConfigManager.java b/src/main/java/org/shanerx/tradeshop/data/config/ConfigManager.java
similarity index 60%
rename from src/main/java/org/shanerx/tradeshop/utils/config/ConfigManager.java
rename to src/main/java/org/shanerx/tradeshop/data/config/ConfigManager.java
index fa086e71..8eab75e8 100644
--- a/src/main/java/org/shanerx/tradeshop/utils/config/ConfigManager.java
+++ b/src/main/java/org/shanerx/tradeshop/data/config/ConfigManager.java
@@ -23,7 +23,7 @@
*
*/
-package org.shanerx.tradeshop.utils.config;
+package org.shanerx.tradeshop.data.config;
import com.google.common.base.CaseFormat;
import com.google.common.base.Charsets;
@@ -33,6 +33,8 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.shanerx.tradeshop.TradeShop;
+import org.shanerx.tradeshop.shop.ShopSettingKeys;
+import org.shanerx.tradeshop.shop.ShopType;
import java.io.File;
import java.io.FileOutputStream;
@@ -41,7 +43,10 @@
import java.io.Writer;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
import java.util.logging.Level;
public class ConfigManager {
@@ -77,7 +82,7 @@ public String colour(String toColour) {
return ChatColor.translateAlternateColorCodes('&', toColour);
}
- public void load() {
+ public boolean load() {
try {
if (!PLUGIN.getDataFolder().isDirectory()) {
PLUGIN.getDataFolder().mkdirs();
@@ -92,40 +97,67 @@ public void load() {
config = YamlConfiguration.loadConfiguration(file);
- setDefaults();
+ return setDefaults();
}
public void reload() {
- load();
+ Set hasUpgraded = new HashSet<>();
+ hasUpgraded.add(load());
switch (configType) {
case CONFIG:
- Setting.upgrade();
- PLUGIN.setUseInternalPerms(Setting.USE_INTERNAL_PERMISSIONS.getBoolean());
+ hasUpgraded.add(Setting.upgrade());
break;
case MESSAGES:
- Message.upgrade();
+ hasUpgraded.add(Message.upgrade());
break;
}
- save();
+ save(hasUpgraded.contains(true));
- PLUGIN.setSkipHopperProtection(
- Setting.BITRADESHOP_HOPPER_EXPORT.getBoolean() &&
- Setting.BITRADESHOP_HOPPER_IMPORT.getBoolean() &&
- Setting.TRADESHOP_HOPPER_IMPORT.getBoolean() &&
- Setting.TRADESHOP_HOPPER_EXPORT.getBoolean());
+ updateSkipHoppers();
}
- public void setDefaults() {
+ public void updateSkipHoppers() {
+ try {
+ Set skipCheck = new HashSet<>();
+ skipCheck.add(ShopSettingKeys.HOPPER_EXPORT.getDefaultValue(ShopType.TRADE).asBoolean());
+ skipCheck.add(ShopSettingKeys.HOPPER_IMPORT.getDefaultValue(ShopType.TRADE).asBoolean());
+ skipCheck.add(ShopSettingKeys.HOPPER_EXPORT.getDefaultValue(ShopType.BITRADE).asBoolean());
+ skipCheck.add(ShopSettingKeys.HOPPER_IMPORT.getDefaultValue(ShopType.BITRADE).asBoolean());
+ skipCheck.add(!ShopSettingKeys.HOPPER_EXPORT.isUserEditable(ShopType.TRADE));
+ skipCheck.add(!ShopSettingKeys.HOPPER_IMPORT.isUserEditable(ShopType.TRADE));
+ skipCheck.add(!ShopSettingKeys.HOPPER_EXPORT.isUserEditable(ShopType.BITRADE));
+ skipCheck.add(!ShopSettingKeys.HOPPER_IMPORT.isUserEditable(ShopType.BITRADE));
+ skipCheck.remove(true);
+
+ PLUGIN.setSkipHopperProtection(!skipCheck.contains(false));
+ } catch (NullPointerException ignored) {
+ }
+ }
+
+ public boolean setDefaults() {
+ Set hasUpgraded = new HashSet<>();
+
switch (configType) {
case CONFIG:
- Arrays.stream(Setting.values()).forEach((setting) -> addKeyValue(setting.getPath(), setting.getDefaultValue()));
+ Arrays.stream(Setting.values()).forEach((setting) -> hasUpgraded.add(addKeyValue(setting.getPath(), setting.getDefaultValue())));
break;
case MESSAGES:
- Arrays.stream(Message.values()).forEach((message) -> addKeyValue(message.getPath(), message.getDefaultValue()));
+ Arrays.stream(Message.values()).forEach((message) -> hasUpgraded.add(addKeyValue(message.getPath(), message.getDefaultValue())));
break;
}
+
+ return hasUpgraded.contains(true);
+ }
+
+ /**
+ * Saves the file if passed boolean is true
+ *
+ * @param shouldSave true if save should proceed
+ */
+ public void save(boolean shouldSave) {
+ if (shouldSave) save();
}
public void save() {
@@ -153,14 +185,14 @@ public void save() {
switch (configType) {
case CONFIG:
- Arrays.stream(SettingSection.values()).sorted(new CompareSettingSections()).forEach((section) -> outputMap.put(section.getPath(), section.getFileString()));
- Arrays.stream(Setting.values()).forEach((section) -> outputMap.put(section.getSection().getPath(),
- outputMap.getOrDefault(section.getSection().getPath(), "") + section.getFileString()));
+ Arrays.stream(SettingSection.values()).sorted(new CompareSettingSections()).forEach((section) -> outputMap.put(section.getPath().toLowerCase().replace("_", "-"), section.getFileString()));
+ Arrays.stream(Setting.values()).forEach((setting) -> outputMap.put(setting.getSection().getPath().toLowerCase().replace("_", "-"),
+ outputMap.getOrDefault(setting.getSection().getPath().toLowerCase().replace("_", "-"), "") + setting.getFileString()));
break;
case MESSAGES:
- Arrays.stream(MessageSection.values()).sorted(new CompareMessageSections()).forEach((section) -> outputMap.put(section.getPath(), section.getFileString()));
- Arrays.stream(Message.values()).forEach((section) -> outputMap.put(section.getSection().getPath(),
- outputMap.getOrDefault(section.getSection().getPath(), "") + section.getFileString()));
+ Arrays.stream(MessageSection.values()).sorted(new CompareMessageSections()).forEach((section) -> outputMap.put(section.getPath().toLowerCase().replace("_", "-"), section.getFileString()));
+ Arrays.stream(Message.values()).forEach((message) -> outputMap.put(message.getSection().getPath().toLowerCase().replace("_", "-"),
+ outputMap.getOrDefault(message.getSection().getPath().toLowerCase().replace("_", "-"), "") + message.getFileString()));
break;
}
@@ -180,10 +212,22 @@ public void save() {
config = YamlConfiguration.loadConfiguration(file);
}
- private void addKeyValue(String node, Object value) {
- if (config.get(node) == null || (config.get(node) != null && config.get(node).toString().isEmpty())) {
+ private boolean addKeyValue(String node, Object value) {
+ node = node.toLowerCase().replace("_", "-");
+ if (value instanceof Map) {
+ for (Map.Entry entry : ((Map, ?>) value).entrySet()) {
+ String newNode = node + "." + entry.getKey().toString().toLowerCase().replace("_", "-");
+ if (config.get(newNode) == null || (config.get(newNode) != null && config.get(newNode).toString().isEmpty())) {
+ config.set(newNode, entry.getValue().toString());
+ return true;
+ }
+ }
+ } else if (config.get(node) == null || (config.get(node) != null && config.get(node).toString().isEmpty())) {
config.set(node, value);
+ return true;
}
+
+ return false;
}
public enum ConfigType {
@@ -212,7 +256,12 @@ public int compare(SettingSection o1, SettingSection o2) {
// if o1's parent is o2 then o2 goes first
} else if (o1.getParent() == o2) {
return 1;
- // if neither of the above are true and one Section has a parent and the other doesn't, then the one without the parent goes first
+ // if neither is the parent of the other but one Section has a parent and the other doesn't
+ } else if (o1.hasParent() != o2.hasParent()) {
+ return o1.hasParent() ? compare(o1.getParent(), o2) : compare(o1, o2.getParent()); // compare existing parent to other section
+ // if both have parents but they aren't the same parent
+ } else if (o1.getParent() != null && !o1.getParent().equals(o2.getParent())) {
+ return compare(o1.getParent(), o2.getParent()); // compare the parents of both
}
// Otherwise, compare weight
@@ -229,9 +278,12 @@ public int compare(MessageSection o1, MessageSection o2) {
// if o1's parent is o2 then o2 goes first
} else if (o1.getParent() == o2) {
return 1;
- // if neither of the above are true and one Section has a parent and the other doesn't, then the one without the parent goes first
+ // if neither is the parent of the other but one Section has a parent and the other doesn't
} else if (o1.hasParent() != o2.hasParent()) {
- return o1.hasParent() ? 1 : -1;
+ return o1.hasParent() ? compare(o1.getParent(), o2) : compare(o1, o2.getParent()); // compare existing parent to other section
+ // if both have parents but they aren't the same parent
+ } else if (o1.getParent() != null && !o1.getParent().equals(o2.getParent())) {
+ return compare(o1.getParent(), o2.getParent()); // compare the parents of both
}
// Otherwise, compare weight
diff --git a/src/main/java/org/shanerx/tradeshop/utils/config/Language.java b/src/main/java/org/shanerx/tradeshop/data/config/Language.java
similarity index 73%
rename from src/main/java/org/shanerx/tradeshop/utils/config/Language.java
rename to src/main/java/org/shanerx/tradeshop/data/config/Language.java
index aeb0d9d3..c92ad819 100644
--- a/src/main/java/org/shanerx/tradeshop/utils/config/Language.java
+++ b/src/main/java/org/shanerx/tradeshop/data/config/Language.java
@@ -23,11 +23,11 @@
*
*/
-package org.shanerx.tradeshop.utils.config;
+package org.shanerx.tradeshop.data.config;
import org.bukkit.configuration.file.YamlConfiguration;
import org.shanerx.tradeshop.TradeShop;
-import org.shanerx.tradeshop.enumys.DebugLevels;
+import org.shanerx.tradeshop.utils.debug.DebugLevels;
import java.io.File;
import java.io.InputStream;
@@ -105,36 +105,41 @@ public String getLang() {
return lang;
}
- public String getHeader(LangSection section, String path) {
- String fullPath = section + "." + path + ".header";
- return langYAML.getString(fullPath, "");
+ public String getHeader(LangSection section, LangSubSection subSection, String path) {
+ return getString(section, subSection, path, "header");
}
- public Object getDefault(LangSection section, String path) {
- String fullPath = section + "." + path + ".default", defaultValue = langYAML.getString(fullPath);
- return defaultValue != null ? defaultValue : getDefaultLangValue(fullPath).toString();
+ public String getDefault(LangSection section, LangSubSection subSection, String path) {
+ return getStringOrDefault(section, subSection, path, "default");
}
- public String getPreComment(LangSection section, String path) {
- String fullPath = section + "." + path + ".pre-comment";
- return langYAML.getString(fullPath, "");
+ public String getPreComment(LangSection section, LangSubSection subSection, String path) {
+ return getString(section, subSection, path, "pre-comment");
+ }
+
+ public String getPostComment(LangSection section, LangSubSection subSection, String path) {
+ return getString(section, subSection, path, "post-comment");
}
- public String getPostComment(LangSection section, String path) {
- String fullPath = section + "." + path + ".post-comment";
+ public String getString(LangSection section, LangSubSection subSection, String key, String field) {
+ String fullPath = section + "." + subSection + "." + key + "." + field;
return langYAML.getString(fullPath, "");
}
+ public String getStringOrDefault(LangSection section, LangSubSection subSection, String key, String field) {
+ String fullPath = section + "." + subSection + "." + key + "." + field, value = getString(section, subSection, key, field);
+ return value != null ? value : getDefaultLangValue(fullPath).toString();
+ }
+
public boolean isLoaded() {
return loaded;
}
public enum LangSection {
- MESSAGE_SECTION,
MESSAGE,
- SETTING_SECTION,
- SETTING;
+ SETTING,
+ PERMISSION;
LangSection() {
}
@@ -145,4 +150,18 @@ public String toString() {
}
}
+
+ public enum LangSubSection {
+ VALUES,
+ SECTIONS;
+
+ LangSubSection() {
+ }
+
+ @Override
+ public String toString() {
+ return name().toLowerCase().replace("_", "-");
+ }
+ }
+
}
diff --git a/src/main/java/org/shanerx/tradeshop/utils/config/Message.java b/src/main/java/org/shanerx/tradeshop/data/config/Message.java
similarity index 77%
rename from src/main/java/org/shanerx/tradeshop/utils/config/Message.java
rename to src/main/java/org/shanerx/tradeshop/data/config/Message.java
index aaba7126..82f46992 100644
--- a/src/main/java/org/shanerx/tradeshop/utils/config/Message.java
+++ b/src/main/java/org/shanerx/tradeshop/data/config/Message.java
@@ -23,23 +23,25 @@
*
*/
-package org.shanerx.tradeshop.utils.config;
+package org.shanerx.tradeshop.data.config;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.shanerx.tradeshop.TradeShop;
-import org.shanerx.tradeshop.objects.Debug;
-import org.shanerx.tradeshop.objects.ShopItemStack;
-import org.shanerx.tradeshop.utils.Tuple;
+import org.shanerx.tradeshop.item.ShopItemStack;
import org.shanerx.tradeshop.utils.Utils;
+import org.shanerx.tradeshop.utils.debug.Debug;
+import org.shanerx.tradeshop.utils.objects.Tuple;
import org.yaml.snakeyaml.Yaml;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -55,7 +57,7 @@ public enum Message {
FEATURE_DISABLED(MessageSection.NONE, "feature-disabled"),
HELD_EMPTY(MessageSection.NONE, "held-empty"),
ILLEGAL_ITEM(MessageSection.NONE, "illegal-item"),
- NO_SHULKER_COST(MessageSection.NONE, "no-shulker-cost"),
+ NO_SHULKER_ITEM(MessageSection.NONE, "no-shulker-item"),
INSUFFICIENT_ITEMS(MessageSection.NONE, "insufficient-items"),
SHOP_INSUFFICIENT_ITEMS(MessageSection.NONE, "shop-insufficient-items"),
INVALID_ARGUMENTS(MessageSection.NONE, "invalid-arguments"),
@@ -90,8 +92,12 @@ public enum Message {
SUCCESSFUL_SETUP(MessageSection.NONE, "successful-setup"),
TOO_MANY_CHESTS(MessageSection.NONE, "too-many-chests"),
TOO_MANY_ITEMS(MessageSection.NONE, "too-many-items"),
- UNSUCCESSFUL_SHOP_MEMBERS(MessageSection.NONE, "unsuccessful-shop-members"),
- UPDATED_SHOP_MEMBERS(MessageSection.NONE, "updated-shop-members"),
+ UPDATED_SHOP_USERS(MessageSection.NONE, "updated-shop-users"),
+ UPDATED_SHOP_USERS_SUCCESSFUL(MessageSection.NONE, "pdated-shop-users-successful"),
+ UPDATED_SHOP_USERS_FAILED(MessageSection.NONE, "updated-shop-users-failed"),
+ UPDATED_SHOP_USERS_FAILED_CAPACITY(MessageSection.NONE, "updated-shop-users-failed-capacity"),
+ UPDATED_SHOP_USERS_FAILED_EXISTING(MessageSection.NONE, "updated-shop-users-failed-existing"),
+ UPDATED_SHOP_USERS_FAILED_MISSING(MessageSection.NONE, "updated-shop-users-failed-missing"),
WHO_MESSAGE(MessageSection.NONE, "who-message"),
VIEW_PLAYER_LEVEL(MessageSection.NONE, "view-player-level"),
SET_PLAYER_LEVEL(MessageSection.NONE, "set-player-level"),
@@ -113,13 +119,15 @@ public enum Message {
}
// Method to fix any values that have changed with updates
- static void upgrade() {
+ static boolean upgrade() {
double version = MESSAGE_VERSION.getDouble();
+ Set hasUpgraded = new HashSet<>(); // Uses this instead of a boolean to later replace below ifs with boolean return methods...
//Changes if CONFIG_VERSION is below 1.1, then update to 1.1
if (checkVersion(version, 1.1)) {
if (TOO_MANY_ITEMS.getString().equals("&cThis trade can not take any more %side%!")) {
- TOO_MANY_ITEMS.setValue(PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, TOO_MANY_ITEMS.getPath()));
+ TOO_MANY_ITEMS.setValue(PLUGIN.getLanguage().getDefault(Language.LangSection.SETTING, Language.LangSubSection.VALUES, TOO_MANY_ITEMS.getPath()));
+ hasUpgraded.add(true);
}
version = 1.1;
}
@@ -129,8 +137,10 @@ static void upgrade() {
Arrays.stream(values()).forEach((message) -> {
String str = message.getString().replace("{", "%").replace("}", "%");
- if (!str.equals(message.getString()))
+ if (!str.equals(message.getString())) {
message.setValue(str);
+ hasUpgraded.add(true);
+ }
});
version = 1.2;
@@ -139,13 +149,16 @@ static void upgrade() {
//Changes if CONFIG_VERSION is below 1.3, then update to 1.3
if (checkVersion(version, 1.3)) {
if (INSUFFICIENT_ITEMS.getString().equals("&cYou do not have &e%AMOUNT% %ITEM%&c!")) {
- INSUFFICIENT_ITEMS.setValue(PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, INSUFFICIENT_ITEMS.getPath()));
+ INSUFFICIENT_ITEMS.setValue(PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, Language.LangSubSection.VALUES, INSUFFICIENT_ITEMS.getPath()));
+ hasUpgraded.add(true);
}
if (SHOP_INSUFFICIENT_ITEMS.getString().equals("&cThis shop does not have enough &e%AMOUNT% %ITEM%&c to trade!")) {
- SHOP_INSUFFICIENT_ITEMS.setValue(PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, SHOP_INSUFFICIENT_ITEMS.getPath()));
+ SHOP_INSUFFICIENT_ITEMS.setValue(PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, Language.LangSubSection.VALUES, SHOP_INSUFFICIENT_ITEMS.getPath()));
+ hasUpgraded.add(true);
}
if (ON_TRADE.getString().equals("&aYou have traded your &e%AMOUNT2% %ITEM2% &afor &e%AMOUNT1% %ITEM1% &awith %SELLER%")) {
- ON_TRADE.setValue(PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, ON_TRADE.getPath()));
+ ON_TRADE.setValue(PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, Language.LangSubSection.VALUES, ON_TRADE.getPath()));
+ hasUpgraded.add(true);
}
@@ -153,6 +166,8 @@ static void upgrade() {
}
MESSAGE_VERSION.setValue(version != 0.0 ? version : 1.3);
+
+ return hasUpgraded.contains(true);
}
private static boolean checkVersion(double version, double maxVersion) {
@@ -168,15 +183,15 @@ public String getKey() {
}
public Object getDefaultValue() {
- return PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, path);
+ return PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, Language.LangSubSection.VALUES, path);
}
public String getPostComment() {
- return PLUGIN.getLanguage().getPostComment(Language.LangSection.MESSAGE, path);
+ return PLUGIN.getLanguage().getPostComment(Language.LangSection.MESSAGE, Language.LangSubSection.VALUES, path);
}
public String getPreComment() {
- return PLUGIN.getLanguage().getPreComment(Language.LangSection.MESSAGE, path);
+ return PLUGIN.getLanguage().getPreComment(Language.LangSection.MESSAGE, Language.LangSubSection.VALUES, path);
}
public MessageSection getSection() {
@@ -224,7 +239,7 @@ public String toString() {
}
public String getPrefixed() {
- return PLUGIN.getMessageManager().colour(Setting.MESSAGE_PREFIX.getString() + " " + this);
+ return PLUGIN.getMessageManager().colour(Setting.MESSAGE_PREFIX.getString().trim() + " " + this);
}
@@ -278,7 +293,7 @@ public final void sendItemMultiLineMessage(Player player, Map> entry : itemsToFill.entrySet()) {
Pattern pattern = Pattern.compile(MULTILINEREGEX.replace("&V&", entry.getKey().toString()));
@@ -315,6 +330,52 @@ public final void sendItemMultiLineMessage(Player player, Map> valuesToFill, Tuple... replacements) {
+ if (valuesToFill.isEmpty()) {
+ sendMessage(player, replacements);
+ return;
+ }
+
+ boolean isJson = getString().startsWith("#json ");
+ String message = getPrefixed().replaceFirst("#json ", "");
+
+ Debug debug = new Utils().PLUGIN.getDebugger();
+
+ for (Map.Entry> entry : valuesToFill.entrySet()) {
+ Pattern pattern = Pattern.compile(MULTILINEREGEX.replace("&V&", entry.getKey().toString()));
+ Matcher matcher = pattern.matcher(message);
+
+ if (entry.getValue().get(0) == null) {
+ entry.getValue().remove(0);
+ }
+
+ while (matcher.find()) {
+ StringBuilder itemList = new StringBuilder();
+ String found = matcher.group(), format = found.replaceAll("[{}]", "").split("=")[1];
+
+ entry.getValue().forEach((k, v) -> {
+ itemList.append("\n")
+ .append(format.replace(Variable.SHOP.toString(), k).replace(Variable.STATUS.toString(), v));
+ });
+
+ message = message.replace(found, itemList.toString());
+ }
+ }
+
+ for (Tuple replace : replacements) {
+ message = message.replace(replace.getLeft().toUpperCase(), replace.getRight())
+ .replace(replace.getLeft().toLowerCase(), replace.getRight())
+ .replace(replace.getLeft(), replace.getRight());
+ }
+
+ if (isJson) {
+ sendMessageDirectJson(player, message);
+ } else {
+ sendMessageDirect(player, message);
+ }
+ }
+
@SafeVarargs
public final void sendMessage(CommandSender sender, Tuple... replacements) {
if (sender instanceof Player) {
diff --git a/src/main/java/org/shanerx/tradeshop/utils/config/MessageSection.java b/src/main/java/org/shanerx/tradeshop/data/config/MessageSection.java
similarity index 93%
rename from src/main/java/org/shanerx/tradeshop/utils/config/MessageSection.java
rename to src/main/java/org/shanerx/tradeshop/data/config/MessageSection.java
index 501f128b..e4b36fd1 100644
--- a/src/main/java/org/shanerx/tradeshop/utils/config/MessageSection.java
+++ b/src/main/java/org/shanerx/tradeshop/data/config/MessageSection.java
@@ -23,7 +23,7 @@
*
*/
-package org.shanerx.tradeshop.utils.config;
+package org.shanerx.tradeshop.data.config;
import org.bukkit.Bukkit;
import org.shanerx.tradeshop.TradeShop;
@@ -77,15 +77,15 @@ public boolean hasParent() {
}
public String getPostComment() {
- return PLUGIN.getLanguage().getPostComment(Language.LangSection.MESSAGE_SECTION, name().toLowerCase().replace("_", "-"));
+ return PLUGIN.getLanguage().getPostComment(Language.LangSection.MESSAGE, Language.LangSubSection.SECTIONS, name().toLowerCase().replace("_", "-"));
}
public String getPreComment() {
- return PLUGIN.getLanguage().getPreComment(Language.LangSection.MESSAGE_SECTION, name().toLowerCase().replace("_", "-"));
+ return PLUGIN.getLanguage().getPreComment(Language.LangSection.MESSAGE, Language.LangSubSection.SECTIONS, name().toLowerCase().replace("_", "-"));
}
public String getSectionHeader() {
- return PLUGIN.getLanguage().getHeader(Language.LangSection.MESSAGE_SECTION, name().toLowerCase().replace("_", "-"));
+ return PLUGIN.getLanguage().getHeader(Language.LangSection.MESSAGE, Language.LangSubSection.SECTIONS, name().toLowerCase().replace("_", "-"));
}
public String getFileString() {
diff --git a/src/main/java/org/shanerx/tradeshop/utils/config/Setting.java b/src/main/java/org/shanerx/tradeshop/data/config/Setting.java
similarity index 61%
rename from src/main/java/org/shanerx/tradeshop/utils/config/Setting.java
rename to src/main/java/org/shanerx/tradeshop/data/config/Setting.java
index fb9613f7..7178328d 100644
--- a/src/main/java/org/shanerx/tradeshop/utils/config/Setting.java
+++ b/src/main/java/org/shanerx/tradeshop/data/config/Setting.java
@@ -23,23 +23,31 @@
*
*/
-package org.shanerx.tradeshop.utils.config;
+package org.shanerx.tradeshop.data.config;
import org.bukkit.Bukkit;
import org.shanerx.tradeshop.TradeShop;
-import org.shanerx.tradeshop.objects.IllegalItemList;
+import org.shanerx.tradeshop.item.IllegalItemList;
+import org.shanerx.tradeshop.item.ShopItemStackSettingKeys;
+import org.shanerx.tradeshop.shop.ShopSettingKeys;
+import org.shanerx.tradeshop.shop.ShopSign;
+import org.shanerx.tradeshop.shop.ShopType;
import org.yaml.snakeyaml.Yaml;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
-import java.util.Objects;
+import java.util.Map;
+import java.util.Set;
public enum Setting {
// PostComment " " adds single newline below setting and "\n" adds 2 newlines below
// PreComment `/n ` will have a new comment marker added after a sufficient space for proper formatting
- CONFIG_VERSION(SettingSection.NONE, "config-version", 0.0),
+ CONFIG_VERSION(SettingSection.NONE, "config-version", 1.3),
// System Options
DATA_STORAGE_TYPE(SettingSection.SYSTEM_OPTIONS, "data-storage-type", "FLATFILE"),
@@ -47,10 +55,9 @@ public enum Setting {
CHECK_UPDATES(SettingSection.SYSTEM_OPTIONS, "check-updates", true),
ALLOW_METRICS(SettingSection.SYSTEM_OPTIONS, "allow-metrics", true),
UNLIMITED_ADMIN(SettingSection.SYSTEM_OPTIONS, "unlimited-admin", false),
- USE_INTERNAL_PERMISSIONS(SettingSection.SYSTEM_OPTIONS, "use-internal-permissions", false),
// Language Options
- MESSAGE_PREFIX(SettingSection.LANGUAGE_OPTIONS, "message-prefix", "&a[&eTradeShop&a] "),
+ MESSAGE_PREFIX(SettingSection.LANGUAGE_OPTIONS, "message-prefix", "&a[&eTradeShop&a]"),
SHOP_GOOD_COLOUR(SettingSection.LANGUAGE_OPTIONS, "shop-good-colour", "&2"),
SHOP_INCOMPLETE_COLOUR(SettingSection.LANGUAGE_OPTIONS, "shop-incomplete-colour", "&7"),
@@ -62,7 +69,7 @@ public enum Setting {
SHOP_OUTOFSTOCK_STATUS(SettingSection.LANGUAGE_OPTIONS, "shop-outofstock-status", "&c"),
// Global Options
- ALLOWED_DIRECTIONS(SettingSection.GLOBAL_OPTIONS, "allowed-directions", new String[]{"DOWN", "WEST", "SOUTH", "EAST", "NORTH", "UP"}),
+ CHEST_DIRECTIONS(SettingSection.GLOBAL_OPTIONS, "chest-directions", new String[]{"BACK", "DOWN", "LEFT", "RIGHT", "UP", "FRONT"}),
ALLOWED_SHOPS(SettingSection.GLOBAL_OPTIONS, "allowed-shops", new String[]{"CHEST", "TRAPPED_CHEST", "SHULKER"}),
MAX_EDIT_DISTANCE(SettingSection.GLOBAL_OPTIONS, "max-edit-distance", 4),
ALLOW_TOGGLE_STATUS(SettingSection.GLOBAL_OPTIONS, "allow-toggle-status", true),
@@ -74,46 +81,51 @@ public enum Setting {
MULTI_TRADE_DEFAULT(SettingSection.GLOBAL_MULTI_TRADE, "default-multi", 2),
MULTI_TRADE_MAX(SettingSection.GLOBAL_MULTI_TRADE, "max-multi", 6),
- // Illegal Item Options
- GLOBAL_ILLEGAL_ITEMS_TYPE(SettingSection.GLOBAL_ILLEGAL_ITEMS, "type", IllegalItemList.ListType.BLACKLIST.toString()),
- GLOBAL_ILLEGAL_ITEMS_LIST(SettingSection.GLOBAL_ILLEGAL_ITEMS, "list", new String[]{"Bedrock", "Command_Block", "Barrier"}),
- COST_ILLEGAL_ITEMS_TYPE(SettingSection.COST_ILLEGAL_ITEMS, "type", IllegalItemList.ListType.DISABLED.toString()),
- COST_ILLEGAL_ITEMS_LIST(SettingSection.COST_ILLEGAL_ITEMS, "list", new String[]{}),
- PRODUCT_ILLEGAL_ITEMS_TYPE(SettingSection.PRODUCT_ILLEGAL_ITEMS, "type", IllegalItemList.ListType.DISABLED.toString()),
- PRODUCT_ILLEGAL_ITEMS_LIST(SettingSection.PRODUCT_ILLEGAL_ITEMS, "list", new String[]{}),
-
// Shop Options
MAX_SHOP_USERS(SettingSection.SHOP_OPTIONS, "max-shop-users", 5),
MAX_SHOPS_PER_CHUNK(SettingSection.SHOP_OPTIONS, "max-shops-per-chunk", 128),
MAX_ITEMS_PER_TRADE_SIDE(SettingSection.SHOP_OPTIONS, "max-items-per-trade-side", 6),
ALLOW_USER_PURCHASING(SettingSection.SHOP_OPTIONS, "allow-user-purchasing", false),
MULTIPLE_ITEMS_ON_SIGN(SettingSection.SHOP_OPTIONS, "multiple-items-on-sign", "Use '/ts what'"),
+ NO_COST_TEXT(SettingSection.SHOP_OPTIONS, "no-cost-text", "nothing"),
+ NO_COST_AMOUNT(SettingSection.SHOP_OPTIONS, "no-cost-amount", "1"),
+
+ SHOP_PER_ITEM_SETTINGS(SettingSection.SHOP_ITEM_OPTIONS, "shop-per-item-settings", ShopItemStackSettingKeys.getDefaultConfigMap()),
+
+ SHOP_SIGN_DEFAULT_COLOURS(SettingSection.SHOP_SIGN_OPTIONS, "sign-default-colours", ShopSign.getDefaultColourMap()),
// Trade Shop Options
TRADESHOP_HEADER(SettingSection.TRADE_SHOP_OPTIONS, "header", "Trade"),
TRADESHOP_EXPLODE(SettingSection.TRADE_SHOP_OPTIONS, "allow-explode", false),
- TRADESHOP_HOPPER_EXPORT(SettingSection.TRADE_SHOP_OPTIONS, "allow-hopper-export", false),
- TRADESHOP_HOPPER_IMPORT(SettingSection.TRADE_SHOP_OPTIONS, "allow-hopper-import", false),
+ TRADE_PER_SHOP_SETTINGS(SettingSection.TRADE_SHOP_OPTIONS, "trade-per-shop-settings", ShopSettingKeys.getSettingConfigMap(ShopType.TRADE)),
// ITrade Shop Options
ITRADESHOP_OWNER(SettingSection.ITRADE_SHOP_OPTIONS, "owner", "Server Shop"),
ITRADESHOP_HEADER(SettingSection.ITRADE_SHOP_OPTIONS, "header", "iTrade"),
ITRADESHOP_EXPLODE(SettingSection.ITRADE_SHOP_OPTIONS, "allow-explode", false),
- ITRADESHOP_NO_COST_TEXT(SettingSection.ITRADE_SHOP_OPTIONS, "no-cost-text", "nothing"),
- ITRADESHOP_NO_COST_AMOUNT(SettingSection.ITRADE_SHOP_OPTIONS, "no-cost-amount", "1"),
+ ITRADE_PER_SHOP_SETTINGS(SettingSection.ITRADE_SHOP_OPTIONS, "itrade-per-shop-settings", ShopSettingKeys.getSettingConfigMap(ShopType.ITRADE)),
// BiTrade Shop Options
BITRADESHOP_HEADER(SettingSection.BITRADE_SHOP_OPTIONS, "header", "BiTrade"),
BITRADESHOP_EXPLODE(SettingSection.BITRADE_SHOP_OPTIONS, "allow-explode", false),
- BITRADESHOP_HOPPER_EXPORT(SettingSection.BITRADE_SHOP_OPTIONS, "allow-hopper-export", false),
- BITRADESHOP_HOPPER_IMPORT(SettingSection.BITRADE_SHOP_OPTIONS, "allow-hopper-import", false);
+ BITRADE_PER_SHOP_SETTINGS(SettingSection.BITRADE_SHOP_OPTIONS, "bitrade-per-shop-settings", ShopSettingKeys.getSettingConfigMap(ShopType.BITRADE)),
- public static final TradeShop PLUGIN = Objects.requireNonNull((TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop"));
+ // Illegal Item Options
+ GLOBAL_ILLEGAL_ITEMS_TYPE(SettingSection.GLOBAL_ILLEGAL_ITEMS, "type", IllegalItemList.ListType.BLACKLIST.toString()),
+ GLOBAL_ILLEGAL_ITEMS_LIST(SettingSection.GLOBAL_ILLEGAL_ITEMS, "list", new String[]{"Bedrock", "Command_Block", "Barrier"}),
+ COST_ILLEGAL_ITEMS_TYPE(SettingSection.COST_ILLEGAL_ITEMS, "type", IllegalItemList.ListType.DISABLED.toString()),
+ COST_ILLEGAL_ITEMS_LIST(SettingSection.COST_ILLEGAL_ITEMS, "list", new String[]{}),
+ PRODUCT_ILLEGAL_ITEMS_TYPE(SettingSection.PRODUCT_ILLEGAL_ITEMS, "type", IllegalItemList.ListType.DISABLED.toString()),
+ PRODUCT_ILLEGAL_ITEMS_LIST(SettingSection.PRODUCT_ILLEGAL_ITEMS, "list", new String[]{});
+
+ public static final TradeShop PLUGIN = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop");
private final String key, path;
private final Object defaultValue;
private final SettingSection section;
+ private final String leadIncrease = " ";
+
Setting(SettingSection section, String key, Object defaultValue) {
this.section = section;
this.key = key;
@@ -126,8 +138,9 @@ public static Setting findSetting(String search) {
}
// Method to fix any values that have changed with updates
- static void upgrade() {
+ static boolean upgrade() {
double version = CONFIG_VERSION.getDouble();
+ Set hasUpgraded = new HashSet<>(); // Uses this instead of a boolean to later replace below ifs with boolean return methods...
ConfigManager configManager = PLUGIN.getSettingManager();
// 2.2.2 Changed enable debug from true/false to integer
@@ -140,46 +153,55 @@ static void upgrade() {
if (configManager.getConfig().contains("itradeshop.owner")) {
configManager.getConfig().set(ITRADESHOP_OWNER.path, configManager.getConfig().get("itradeshop.owner"));
configManager.getConfig().set("itradeshop.owner", null);
+ hasUpgraded.add(true);
}
if (configManager.getConfig().contains("itradeshop.header")) {
configManager.getConfig().set(ITRADESHOP_HEADER.path, configManager.getConfig().get("itradeshop.header"));
configManager.getConfig().set("itradeshop.header", null);
+ hasUpgraded.add(true);
}
if (configManager.getConfig().contains("itradeshop.allow-explode")) {
configManager.getConfig().set(ITRADESHOP_EXPLODE.path, configManager.getConfig().get("itradeshop.allow-explode"));
configManager.getConfig().set("itradeshop.allow-explode", null);
+ hasUpgraded.add(true);
}
if (configManager.getConfig().contains("tradeshop.header")) {
configManager.getConfig().set(TRADESHOP_HEADER.path, configManager.getConfig().get("tradeshop.header"));
configManager.getConfig().set("tradeshop.header", null);
+ hasUpgraded.add(true);
}
if (configManager.getConfig().contains("tradeshop.allow-explode")) {
configManager.getConfig().set(TRADESHOP_EXPLODE.path, configManager.getConfig().get("tradeshop.allow-explode"));
configManager.getConfig().set("tradeshop.allow-explode", null);
+ hasUpgraded.add(true);
}
if (configManager.getConfig().contains("tradeshop.allow-hopper-export")) {
- configManager.getConfig().set(TRADESHOP_HOPPER_EXPORT.path, configManager.getConfig().get("tradeshop.allow-hopper-export"));
+ configManager.getConfig().set("trade-shop-options.allow-hopper-export", configManager.getConfig().get("tradeshop.allow-hopper-export"));
configManager.getConfig().set("tradeshop.allow-hopper-export", null);
+ hasUpgraded.add(true);
}
if (configManager.getConfig().contains("bitradeshop.header")) {
configManager.getConfig().set(BITRADESHOP_HEADER.path, configManager.getConfig().get("bitradeshop.header"));
configManager.getConfig().set("bitradeshop.header", null);
+ hasUpgraded.add(true);
}
if (configManager.getConfig().contains("bitradeshop.allow-explode")) {
configManager.getConfig().set(BITRADESHOP_EXPLODE.path, configManager.getConfig().get("bitradeshop.allow-explode"));
configManager.getConfig().set("bitradeshop.allow-explode", null);
+ hasUpgraded.add(true);
}
if (configManager.getConfig().contains("bitradeshop.allow-hopper-export")) {
- configManager.getConfig().set(BITRADESHOP_HOPPER_EXPORT.path, configManager.getConfig().get("bitradeshop.allow-hopper-export"));
+ configManager.getConfig().set("bitrade-shop-options.allow-hopper-export", configManager.getConfig().get("bitradeshop.allow-hopper-export"));
configManager.getConfig().set("bitradeshop.allow-hopper-export", null);
+ hasUpgraded.add(true);
}
@@ -191,12 +213,61 @@ static void upgrade() {
configManager.getConfig().set(GLOBAL_ILLEGAL_ITEMS_LIST.path, configManager.getConfig().get("global-options.illegal-items"));
GLOBAL_ILLEGAL_ITEMS_LIST.setValue(configManager.getConfig().getStringList("global-options.illegal-items").removeAll(Arrays.asList("Air", "Void_Air", "Cave_Air")));
configManager.getConfig().set("global-options.illegal-items", null);
+ hasUpgraded.add(true);
}
version = 1.2;
}
+ if (version < 1.3) {
+ String oldKey = "itrade-shop-options.no-cost-text";
+ if (configManager.getConfig().contains(oldKey)) {
+ configManager.getConfig().set(NO_COST_TEXT.path, configManager.getConfig().get(oldKey));
+ configManager.getConfig().set(oldKey, null);
+ hasUpgraded.add(true);
+ }
+
+ oldKey = "itrade-shop-options.no-cost-amount";
+ if (configManager.getConfig().contains(oldKey)) {
+ configManager.getConfig().set(NO_COST_AMOUNT.path, configManager.getConfig().get(oldKey));
+ configManager.getConfig().set(oldKey, null);
+ hasUpgraded.add(true);
+ }
+
+ oldKey = "bitrade-shop-options.allow-hopper-export";
+ if (configManager.getConfig().contains(oldKey)) {
+ configManager.getConfig().set(BITRADE_PER_SHOP_SETTINGS.getPath() + ".allow-hopper-export", configManager.getConfig().get(oldKey));
+ configManager.getConfig().set(oldKey, null);
+ hasUpgraded.add(true);
+ }
+
+ oldKey = "bitrade-shop-options.allow-hopper-import";//
+ if (configManager.getConfig().contains(oldKey)) {
+ configManager.getConfig().set(BITRADE_PER_SHOP_SETTINGS.getPath() + ".allow-hopper-import", configManager.getConfig().get(oldKey));
+ configManager.getConfig().set(oldKey, null);
+ hasUpgraded.add(true);
+ }
+
+ oldKey = "trade-shop-options.allow-hopper-export";//
+ if (configManager.getConfig().contains(oldKey)) {
+ configManager.getConfig().set(TRADE_PER_SHOP_SETTINGS.getPath() + ".allow-hopper-export", configManager.getConfig().get(oldKey));
+ configManager.getConfig().set(oldKey, null);
+ hasUpgraded.add(true);
+ }
+
+ oldKey = "trade-shop-options.allow-hopper-import";//
+ if (configManager.getConfig().contains(oldKey)) {
+ configManager.getConfig().set(TRADE_PER_SHOP_SETTINGS.getPath() + ".allow-hopper-import", configManager.getConfig().get(oldKey));
+ configManager.getConfig().set(oldKey, null);
+ hasUpgraded.add(true);
+ }
+
+ version = 1.3;
+ }
+
CONFIG_VERSION.setValue(version);
+
+ return hasUpgraded.contains(true);
}
public String getKey() {
@@ -207,12 +278,24 @@ public Object getDefaultValue() {
return defaultValue;
}
+ public String getMappedString(String subKey) {
+ return PLUGIN.getSettingManager().getConfig().getConfigurationSection(getPath()).getString(subKey.toLowerCase().replace("_", "-"));
+ }
+
+ public boolean getMappedBoolean(String subKey) {
+ return PLUGIN.getSettingManager().getConfig().getConfigurationSection(getPath()).getBoolean(subKey.toLowerCase().replace("_", "-"));
+ }
+
+ public Object getMappedObject(String subKey) {
+ return PLUGIN.getSettingManager().getConfig().getConfigurationSection(getPath()).get(subKey.toLowerCase().replace("_", "-"));
+ }
+
public String getPostComment() {
- return PLUGIN.getLanguage().getPostComment(Language.LangSection.SETTING, path);
+ return PLUGIN.getLanguage().getPostComment(Language.LangSection.SETTING, Language.LangSubSection.VALUES, path);
}
public String getPreComment() {
- return PLUGIN.getLanguage().getPreComment(Language.LangSection.SETTING, path);
+ return PLUGIN.getLanguage().getPreComment(Language.LangSection.SETTING, Language.LangSubSection.VALUES, path);
}
public SettingSection getSection() {
@@ -223,6 +306,27 @@ public String getPath() {
return path;
}
+ private String processMapValue(Map, ?> valueMap, String localLead) {
+ StringBuilder processed = new StringBuilder();
+
+ List