From 7e721920859aea17e7691edbfc78d6b4ae7171c4 Mon Sep 17 00:00:00 2001 From: KillerOfPie Date: Sat, 28 May 2022 16:53:21 -0700 Subject: [PATCH] Bug Fix for #134 - Moved #createShop to Utils - Made #createShop more generic so sign creation and commands could both use it - Added SHOP_CREATION Debug Level at bit 11(1024) - Added toDebug method to Shop to allow a easily readable output of the shop - Re-wrote updateSign methods to make them simpler to understand and allow sign/event passing from #createShop - Removed event storing and related methods from Shop as it was unnecessary - Deprecated #b64OverstackFixer since it is only used in legacy code - Fixed some spelling in comments(the green underlines were bothering me) - Removed unused `failed` methods from Utils --- .../commandrunners/CreateCommand.java | 86 +---------- .../data/storage/Json/ShopConfiguration.java | 8 + .../java/org/shanerx/tradeshop/shop/Shop.java | 112 +++++++++----- .../shop/listeners/ShopCreateListener.java | 83 +--------- .../tradeshop/shoplocation/ShopLocation.java | 2 +- .../org/shanerx/tradeshop/utils/Utils.java | 146 +++++++++++++++--- .../tradeshop/utils/debug/DebugLevels.java | 3 +- 7 files changed, 213 insertions(+), 227 deletions(-) diff --git a/src/main/java/org/shanerx/tradeshop/commands/commandrunners/CreateCommand.java b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/CreateCommand.java index 3572750c..c0b0b793 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/commandrunners/CreateCommand.java +++ b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/CreateCommand.java @@ -25,21 +25,13 @@ package org.shanerx.tradeshop.commands.commandrunners; -import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.block.Sign; 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.framework.events.PlayerShopCreateEvent; -import org.shanerx.tradeshop.item.ShopItemSide; -import org.shanerx.tradeshop.player.ShopRole; -import org.shanerx.tradeshop.player.ShopUser; -import org.shanerx.tradeshop.shop.Shop; -import org.shanerx.tradeshop.shop.ShopChest; import org.shanerx.tradeshop.shop.ShopType; -import org.shanerx.tradeshop.utils.objects.Tuple; /** * Implementation of CommandRunner for plugin commands that create new shops @@ -61,7 +53,7 @@ public void createTrade() { if (sign == null) return; - createShop(sign, ShopType.TRADE); + createShop(sign, pSender, ShopType.TRADE); } /** @@ -73,7 +65,7 @@ public void createBiTrade() { if (sign == null) return; - createShop(sign, ShopType.BITRADE); + createShop(sign, pSender, ShopType.BITRADE); } /** @@ -85,81 +77,9 @@ public void createITrade() { if (sign == null) return; - createShop(sign, ShopType.ITRADE); + createShop(sign, pSender, ShopType.ITRADE); } - - /** - * Create a shop from a non-shop sign in front of the player - * - * @param shopSign sign to make into a shop - * @param shopType type of shop to make - */ - private void createShop(Sign shopSign, ShopType shopType) { - if (ShopType.isShop(shopSign)) { - Message.EXISTING_SHOP.sendMessage(pSender); - return; - } - - ShopUser owner = new ShopUser(pSender, ShopRole.OWNER); - - if (!checkShopChest(shopSign.getBlock()) && !shopType.isITrade()) { - Message.NO_CHEST.sendMessage(pSender); - return; - } - - if (Setting.MAX_SHOPS_PER_CHUNK.getInt() <= plugin.getDataStorage().getShopCountInChunk(shopSign.getChunk())) { - Message.TOO_MANY_CHESTS.sendMessage(pSender); - return; - } - - ShopChest shopChest; - Shop shop; - Block chest = findShopChest(shopSign.getBlock()); - - if (!shopType.isITrade()) { - if (ShopChest.isShopChest(chest)) { - shopChest = new ShopChest(chest.getLocation()); - } else { - shopChest = new ShopChest(chest, pSender.getUniqueId(), shopSign.getLocation()); - } - - if (shopChest.hasOwner() && !shopChest.getOwner().equals(owner.getUUID())) { - Message.NO_SHOP_PERMISSION.sendMessage(pSender); - return; - } - - if (shopChest.hasShopSign() && !shopChest.getShopSign().getLocation().equals(shopSign.getLocation())) { - Message.EXISTING_SHOP.sendMessage(pSender); - return; - } - - shop = new Shop(new Tuple<>(shopSign.getLocation(), shopChest.getChest().getLocation()), shopType, owner); - shopChest.setName(); - - - if (shopChest.isEmpty() && shop.hasSide(ShopItemSide.PRODUCT)) { - Message.EMPTY_TS_ON_SETUP.sendMessage(pSender); - } - } else { - shop = new Shop(shopSign.getLocation(), shopType, owner); - } - - PlayerShopCreateEvent shopCreateEvent = new PlayerShopCreateEvent(pSender, shop); - Bukkit.getPluginManager().callEvent(shopCreateEvent); - if (shopCreateEvent.isCancelled()) { - return; - } - - shopSign.setLine(0, shopType.toHeader()); - shopSign.update(); - - shop.saveShop(); - - Message.SUCCESSFUL_SETUP.sendMessage(pSender); - } - - //region Util Methods //------------------------------------------------------------------------------------------------------------------ diff --git a/src/main/java/org/shanerx/tradeshop/data/storage/Json/ShopConfiguration.java b/src/main/java/org/shanerx/tradeshop/data/storage/Json/ShopConfiguration.java index 57160746..26232c78 100644 --- a/src/main/java/org/shanerx/tradeshop/data/storage/Json/ShopConfiguration.java +++ b/src/main/java/org/shanerx/tradeshop/data/storage/Json/ShopConfiguration.java @@ -126,6 +126,14 @@ public int size() { return jsonObj.size(); } + + /** + * Turns old overstacked itemstacks into individual stacks in a list + * + * @param oldB64 old B64 string to check/fix + * @return new list of ItemStacks + * @deprecated + */ private List b64OverstackFixer(String oldB64) { ShopItemStack oldStack = new ShopItemStack(oldB64); diff --git a/src/main/java/org/shanerx/tradeshop/shop/Shop.java b/src/main/java/org/shanerx/tradeshop/shop/Shop.java index f637a0ff..1d21b25b 100644 --- a/src/main/java/org/shanerx/tradeshop/shop/Shop.java +++ b/src/main/java/org/shanerx/tradeshop/shop/Shop.java @@ -43,6 +43,7 @@ import org.shanerx.tradeshop.player.PlayerSetting; import org.shanerx.tradeshop.player.ShopRole; import org.shanerx.tradeshop.player.ShopUser; +import org.shanerx.tradeshop.shoplocation.ShopChunk; import org.shanerx.tradeshop.shoplocation.ShopLocation; import org.shanerx.tradeshop.utils.Utils; import org.shanerx.tradeshop.utils.objects.Tuple; @@ -63,7 +64,6 @@ public class Shop implements Serializable { private final ShopLocation shopLoc; private List product, cost; private ShopLocation chestLoc; - private transient SignChangeEvent signChangeEvent; private transient Inventory storageInv; private transient Utils utils = new Utils(); private ShopStatus status = ShopStatus.INCOMPLETE; @@ -168,22 +168,6 @@ public void setStorageInventory() { storageInv = null; } - /** - * Adds the sign change event to the shop to be used during sign update - * - * @param event The SignChangeEvent to hold - */ - public void setEvent(SignChangeEvent event) { - this.signChangeEvent = event; - } - - /** - * Removes the SignChangeEvent from the shop(Should be done before leaving the event) - */ - public void removeEvent() { - this.signChangeEvent = null; - } - /** * Returns the storage block as a ShopChest * @@ -296,6 +280,37 @@ public void fixAfterLoad() { updateSign(); } + /** + * Generates a semi readable output of the shop object for debug output + * + * @return Return String for debug output + */ + public String toDebug() { + StringBuilder sb = new StringBuilder(); + sb.append("Shop Debug: \n"); + sb.append("Shop Chunk: ").append(new ShopChunk(shopLoc.getChunk()).serialize()).append("\n"); + sb.append("Sign Location: ").append(shopLoc.serialize()).append("\n"); + sb.append("Shop Type: ").append((isMissingItems() ? Setting.SHOP_INCOMPLETE_COLOUR : Setting.SHOP_GOOD_COLOUR).getString() + shopType.toHeader()).append("\n"); + sb.append("Shop Status: ").append(status.getLine()).append("\n"); + sb.append("Storage Location: ").append(hasStorage() ? getInventoryLocationAsSL().serialize() : "N/A").append("\n"); + sb.append("Storage Type: ").append(hasStorage() ? getStorage().getType().toString() : "N/A").append("\n"); + sb.append("Owner: ").append(owner.getName()).append(" | ").append(owner.getUUID()).append("\n"); + sb.append("Managers: ").append(managers.isEmpty() ? "N/A" : managers.size()).append("\n"); + if (!managers.isEmpty()) + getUsers(ShopRole.MANAGER).forEach(manager -> sb.append(" ").append(manager.getName()).append(" | ").append(manager.getUUID()).append("\n")); + sb.append("Members: ").append(members.isEmpty() ? "N/A" : members.size()).append("\n"); + if (!members.isEmpty()) + getUsers(ShopRole.MEMBER).forEach(member -> sb.append(" ").append(member.getName()).append(" | ").append(member.getUUID()).append("\n")); + sb.append("Products: ").append(product.isEmpty() ? "N/A" : product.size()).append("\n"); + if (!product.isEmpty()) + product.forEach(productItem -> sb.append(" ").append(productItem.toConsoleText()).append("\n")); + sb.append("Costs: ").append(cost.isEmpty() ? "N/A" : cost.size()).append("\n"); + if (!cost.isEmpty()) + cost.forEach(costItem -> sb.append(" ").append(costItem.toConsoleText()).append("\n")); + + return utils.colorize(sb.toString()); + } + /** * Saves the shop to file */ @@ -324,38 +339,50 @@ public Sign getShopSign() { * Updates the text on the shops sign */ public void updateSign() { - if (signChangeEvent != null) { - updateSign(signChangeEvent); - removeEvent(); - } else { - Sign s = getShopSign(); + Sign s = getShopSign(); - if (s != null) { - String[] signLines = updateSignLines(); + if (s == null) + return; - for (int i = 0; i < 4; i++) { - if (signLines[i] != null) - s.setLine(i, signLines[i]); - } + String[] signLines = updateSignLines(); - s.update(); - } + for (int i = 0; i < 4; i++) { + s.setLine(i, signLines[i]); } + + s.update(); } /** - * Updates the text on the shops sign during SignChangeEvent - * - * @param signEvent SignEvent to update the sign for + * Updates the text on the shops sign using the events sign if it matches location */ - public void updateSign(SignChangeEvent signEvent) { - String[] signLines = updateSignLines(); + public void updateSign(SignChangeEvent event) { + if (event == null || !event.getBlock().getLocation().equals(getShopLocation())) + return; - for (int i = 0; i < 4; i++) { - signEvent.setLine(i, signLines[i]); + String[] signLines = updateSignLines(); + + for (int i = 0; i < 4; i++) { + event.setLine(i, signLines[i]); } } + /** + * Updates the text on the shops sign using the passed sign if it matches location + */ + public void updateSign(Sign sign) { + if (sign == null || !sign.getLocation().equals(getShopLocation())) + return; + + String[] signLines = updateSignLines(); + + for (int i = 0; i < 4; i++) { + sign.setLine(i, signLines[i]); + } + + sign.update(); + } + /** * Updates the text for the shop signs * @@ -364,11 +391,7 @@ public void updateSign(SignChangeEvent signEvent) { private String[] updateSignLines() { String[] signLines = new String[4]; - if (isMissingItems()) { - signLines[0] = utils.colorize(Setting.SHOP_INCOMPLETE_COLOUR.getString() + shopType.toHeader()); - } else { - signLines[0] = utils.colorize(Setting.SHOP_GOOD_COLOUR.getString() + shopType.toHeader()); - } + signLines[0] = utils.colorize((isMissingItems() ? Setting.SHOP_INCOMPLETE_COLOUR : Setting.SHOP_GOOD_COLOUR).getString() + shopType.toHeader()); if (product.isEmpty()) { signLines[1] = ""; @@ -412,6 +435,11 @@ private String[] updateSignLines() { signLines[3] = status.getLine(); + for (int i = 0; i < 4; i++) { + if (signLines[i] == null) + signLines[i] = " "; + } + return signLines; } diff --git a/src/main/java/org/shanerx/tradeshop/shop/listeners/ShopCreateListener.java b/src/main/java/org/shanerx/tradeshop/shop/listeners/ShopCreateListener.java index 63623367..1f7cb158 100644 --- a/src/main/java/org/shanerx/tradeshop/shop/listeners/ShopCreateListener.java +++ b/src/main/java/org/shanerx/tradeshop/shop/listeners/ShopCreateListener.java @@ -25,9 +25,7 @@ package org.shanerx.tradeshop.shop.listeners; -import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -35,17 +33,10 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.inventory.ItemStack; -import org.shanerx.tradeshop.data.config.Message; -import org.shanerx.tradeshop.data.config.Setting; -import org.shanerx.tradeshop.framework.events.PlayerShopCreateEvent; import org.shanerx.tradeshop.item.ShopItemSide; -import org.shanerx.tradeshop.player.ShopRole; -import org.shanerx.tradeshop.player.ShopUser; import org.shanerx.tradeshop.shop.Shop; -import org.shanerx.tradeshop.shop.ShopChest; import org.shanerx.tradeshop.shop.ShopType; import org.shanerx.tradeshop.utils.Utils; -import org.shanerx.tradeshop.utils.objects.Tuple; @SuppressWarnings("unused") public class ShopCreateListener extends Utils implements Listener { @@ -68,78 +59,16 @@ public void onSignChange(SignChangeEvent event) { ShopType shopType = ShopType.getType(shopSign); Player p = event.getPlayer(); - ShopUser owner = new ShopUser(p, ShopRole.OWNER); - if (!shopType.checkPerm(p)) { - failedSign(event, shopType, Message.NO_TS_CREATE_PERMISSION); - return; - } - - if (!checkShopChest(shopSign.getBlock()) && !shopType.isITrade()) { - failedSign(event, shopType, Message.NO_CHEST); - return; - } - - if (Setting.MAX_SHOPS_PER_CHUNK.getInt() <= PLUGIN.getDataStorage().getShopCountInChunk(shopSign.getChunk())) { - failedSign(event, shopType, Message.TOO_MANY_CHESTS); - return; - } - - ShopChest shopChest; - Shop shop; - Block chest = findShopChest(event.getBlock()); - - if (!shopType.isITrade()) { - if (ShopChest.isShopChest(chest)) { - shopChest = new ShopChest(chest.getLocation()); - } else { - shopChest = new ShopChest(chest, p.getUniqueId(), shopSign.getLocation()); - } - - if (shopChest.hasOwner() && !shopChest.getOwner().equals(owner.getUUID())) { - failedSign(event, shopType, Message.NO_SHOP_PERMISSION); - return; - } + // Clear the first line since we already know it is going to be a Shop, and we have the type to pass separately + // Required as the createShop method needs to make sure the first line is blank for commands to avoid overwriting existing shops + shopSign.setLine(0, ""); - if (shopChest.hasShopSign() && !shopChest.getShopSign().getLocation().equals(shopSign.getLocation())) { - failedSign(event, shopType, Message.EXISTING_SHOP); - return; - } + Shop shop = createShop(shopSign, p, shopType, lineCheck(ShopItemSide.COST, event.getLine(2)), lineCheck(ShopItemSide.PRODUCT, event.getLine(1)), event); - shop = new Shop(new Tuple<>(shopSign.getLocation(), shopChest.getChest().getLocation()), shopType, owner); - shopChest.setName(); - - - if (shopChest.isEmpty() && shop.hasSide(ShopItemSide.PRODUCT)) { - p.sendMessage(Message.EMPTY_TS_ON_SETUP.getPrefixed()); - } - } else { - shop = new Shop(shopSign.getLocation(), shopType, owner); + if (shop == null) { + failedSignReset(event, shopType); } - - shop.setEvent(event); - - ItemStack product = lineCheck(ShopItemSide.PRODUCT, event.getLine(1)), - cost = lineCheck(ShopItemSide.COST, event.getLine(2)); - - if (product != null && !shop.hasSide(ShopItemSide.PRODUCT)) - shop.setSideItems(ShopItemSide.PRODUCT, product); - - if (cost != null && !shop.hasSide(ShopItemSide.COST)) - shop.setSideItems(ShopItemSide.COST, cost); - - PlayerShopCreateEvent shopCreateEvent = new PlayerShopCreateEvent(p, shop); - Bukkit.getPluginManager().callEvent(shopCreateEvent); - if (shopCreateEvent.isCancelled()) { - event.setCancelled(true); - return; - } - - shop.updateSign(event); - shop.removeEvent(); - shop.saveShop(); - - p.sendMessage(Message.SUCCESSFUL_SETUP.getPrefixed()); } private ItemStack lineCheck(ShopItemSide side, String line) { diff --git a/src/main/java/org/shanerx/tradeshop/shoplocation/ShopLocation.java b/src/main/java/org/shanerx/tradeshop/shoplocation/ShopLocation.java index 654b8622..f7fe073e 100644 --- a/src/main/java/org/shanerx/tradeshop/shoplocation/ShopLocation.java +++ b/src/main/java/org/shanerx/tradeshop/shoplocation/ShopLocation.java @@ -67,7 +67,7 @@ public static ShopLocation deserialize(String loc) { world = Bukkit.getWorld(locA[1].replace("-", "_")); if (world == null) { throw new IllegalWorldException("Cannot find world " + locA[1], new WorldlessLocation(x, y, z)); - // Not to maintainer: do NOT remove this aritificial error, it is supposed to be catched elsewhere + // Not to maintainer: do NOT remove this artificial error, it is supposed to be caught elsewhere // (Temporary fix for metadata world renaming bug until metadata is removed entirely) } diff --git a/src/main/java/org/shanerx/tradeshop/utils/Utils.java b/src/main/java/org/shanerx/tradeshop/utils/Utils.java index 9031dd16..fedfb4d5 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/Utils.java +++ b/src/main/java/org/shanerx/tradeshop/utils/Utils.java @@ -31,9 +31,9 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; +import org.bukkit.entity.Player; import org.bukkit.event.block.Action; import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -42,8 +42,11 @@ import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.data.config.Message; import org.shanerx.tradeshop.data.config.Setting; +import org.shanerx.tradeshop.framework.events.PlayerShopCreateEvent; import org.shanerx.tradeshop.item.ShopItemSide; import org.shanerx.tradeshop.item.ShopItemStack; +import org.shanerx.tradeshop.player.ShopRole; +import org.shanerx.tradeshop.player.ShopUser; import org.shanerx.tradeshop.shop.ExchangeStatus; import org.shanerx.tradeshop.shop.Shop; import org.shanerx.tradeshop.shop.ShopChest; @@ -215,28 +218,6 @@ public void failedSignReset(SignChangeEvent e, ShopType shop) { e.setLine(3, ""); } - /** - * Sets the event sign to a failed creation sign - * - * @param e event where shop creation failed - * @param shop Shoptype enum to get header - * @param msg The enum constant representing the error message - */ - public void failedSign(SignChangeEvent e, ShopType shop, Message msg) { - failedSignReset(e, shop); - e.getPlayer().sendMessage(colorize(Setting.MESSAGE_PREFIX.getString() + msg)); - } - - /** - * Sets the event sign to a failed creation sign - * - * @param e Event to reset the sign for - * @param msg The enum constant representing the error message - */ - public void failedTrade(PlayerInteractEvent e, Message msg) { - e.getPlayer().sendMessage(colorize(Setting.MESSAGE_PREFIX.getString() + msg)); - } - /** * Checks whether or not it is an illegal material. * @@ -488,6 +469,125 @@ public Tuple> canExchangeAll(Shop shop, Inventor return new Tuple<>(ExchangeStatus.SUCCESS, createBadList()); //Successfully completed trade } + /** + * Create a shop from a non-shop sign in front of the player + * + * @param shopSign sign to make into a shop + * @param creator player that is creating the shop + * @param shopType type of shop to make + * @param cost initial cost item for shop + * @param product initial product item for shop + * @param event SignUpdateEvent if being called from sign creation + * @return returns the shop object that was created + */ + public Shop createShop(Sign shopSign, Player creator, ShopType shopType, ItemStack cost, ItemStack product, SignChangeEvent event) { + if (ShopType.isShop(shopSign)) { + Message.EXISTING_SHOP.sendMessage(creator); + return null; + } + + ShopUser owner = new ShopUser(creator, ShopRole.OWNER); + + if (!checkShopChest(shopSign.getBlock()) && !shopType.isITrade()) { + Message.NO_CHEST.sendMessage(creator); + return null; + } + + if (Setting.MAX_SHOPS_PER_CHUNK.getInt() <= PLUGIN.getDataStorage().getShopCountInChunk(shopSign.getChunk())) { + Message.TOO_MANY_CHESTS.sendMessage(creator); + return null; + } + + ShopChest shopChest; + Shop shop; + Block chest = findShopChest(shopSign.getBlock()); + + if (!shopType.isITrade()) { + if (ShopChest.isShopChest(chest)) { + shopChest = new ShopChest(chest.getLocation()); + } else { + shopChest = new ShopChest(chest, creator.getUniqueId(), shopSign.getLocation()); + } + + if (shopChest.hasOwner() && !shopChest.getOwner().equals(owner.getUUID())) { + Message.NO_SHOP_PERMISSION.sendMessage(creator); + return null; + } + + if (shopChest.hasShopSign() && !shopChest.getShopSign().getLocation().equals(shopSign.getLocation())) { + Message.EXISTING_SHOP.sendMessage(creator); + return null; + } + + shop = new Shop(new Tuple<>(shopSign.getLocation(), shopChest.getChest().getLocation()), shopType, owner); + shopChest.setName(); + + if (cost != null && !shop.hasSide(ShopItemSide.COST)) + shop.setSideItems(ShopItemSide.COST, cost); + + if (product != null && !shop.hasSide(ShopItemSide.PRODUCT)) + shop.setSideItems(ShopItemSide.PRODUCT, product); + + if (shopChest.isEmpty() && shop.hasSide(ShopItemSide.PRODUCT)) { + Message.EMPTY_TS_ON_SETUP.sendMessage(creator); + } + } else { + shop = new Shop(shopSign.getLocation(), shopType, owner); + } + + debugger.log("-----Pre-Event-----", DebugLevels.SHOP_CREATION); + debugger.log(shop.toDebug(), DebugLevels.SHOP_CREATION); + + + debugger.log("-----Post-Event-----", DebugLevels.SHOP_CREATION); + PlayerShopCreateEvent shopCreateEvent = new PlayerShopCreateEvent(creator, shop); + Bukkit.getPluginManager().callEvent(shopCreateEvent); + if (shopCreateEvent.isCancelled()) { + debugger.log("Creation Failed!", DebugLevels.SHOP_CREATION); + return null; + } + + shop.saveShop(); + + if (event != null) { + shop.updateSign(event); + debugger.log("Event Sign Lines: \n" + event.getLine(0) + "\n" + event.getLine(1) + "\n" + event.getLine(2) + "\n" + event.getLine(3), DebugLevels.SHOP_CREATION); + } else { + shop.updateSign(shopSign); + debugger.log("Sign Lines: \n" + shopSign.getLine(0) + "\n" + shopSign.getLine(1) + "\n" + shopSign.getLine(2) + "\n" + shopSign.getLine(3), DebugLevels.SHOP_CREATION); + } + + Message.SUCCESSFUL_SETUP.sendMessage(creator); + debugger.log("Creation Successful!", DebugLevels.SHOP_CREATION); + return shop; + } + + /** + * Create a shop from a non-shop sign in front of the player + * + * @param shopSign sign to make into a shop + * @param creator player that is creating the shop + * @param shopType type of shop to make + * @return returns the shop object that was created + */ + public Shop createShop(Sign shopSign, Player creator, ShopType shopType) { + return createShop(shopSign, creator, shopType, null, null, null); + } + + /** + * Create a shop from a non-shop sign in front of the player + * + * @param shopSign sign to make into a shop + * @param creator player that is creating the shop + * @param shopType type of shop to make + * @param cost initial cost item for shop + * @param product initial product item for shop + * @return returns the shop object that was created + */ + public Shop createShop(Sign shopSign, Player creator, ShopType shopType, ItemStack cost, ItemStack product) { + return createShop(shopSign, creator, shopType, cost, product, null); + } + /** * Returns an arraylist of the ItemStack Objects to be removed/added, if it could not get enough of any items, it will return index 0 as null, followed by ItemStack Objects that could not be retrieved * diff --git a/src/main/java/org/shanerx/tradeshop/utils/debug/DebugLevels.java b/src/main/java/org/shanerx/tradeshop/utils/debug/DebugLevels.java index d09bacbc..db44c016 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/debug/DebugLevels.java +++ b/src/main/java/org/shanerx/tradeshop/utils/debug/DebugLevels.java @@ -41,7 +41,8 @@ public enum DebugLevels { NAME_COMPARE(7, Level.WARNING), // 64 SHULKERS_SUCK(8, Level.WARNING), // 128 ENCHANT_CHECKS(9, Level.WARNING), // 256 - OUTPUT(10, Level.WARNING) //512 + OUTPUT(10, Level.WARNING), // 512 + SHOP_CREATION(11, Level.INFO) // 1024 ; //position is what value to check for this level in the binary string -1.