diff --git a/src/main/java/com/Acrobot/ChestShop/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/ChestShop.java index d7e7cace4..0129ed05f 100644 --- a/src/main/java/com/Acrobot/ChestShop/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/ChestShop.java @@ -21,9 +21,6 @@ import com.Acrobot.ChestShop.Commands.Give; import com.Acrobot.ChestShop.Commands.ItemInfo; import com.Acrobot.ChestShop.Commands.RemoveAccessor; -import com.Acrobot.ChestShop.Commands.SetAmount; -import com.Acrobot.ChestShop.Commands.SetItem; -import com.Acrobot.ChestShop.Commands.SetPrice; import com.Acrobot.ChestShop.Commands.Toggle; import com.Acrobot.ChestShop.Commands.Version; import com.Acrobot.ChestShop.Configuration.Messages; @@ -56,7 +53,6 @@ import com.Acrobot.ChestShop.Listeners.PostTransaction.TransactionLogger; import com.Acrobot.ChestShop.Listeners.PostTransaction.TransactionMessageSender; import com.Acrobot.ChestShop.Listeners.PreShopCreation.ChestChecker; -import com.Acrobot.ChestShop.Listeners.PreShopCreation.ItemChecker; import com.Acrobot.ChestShop.Listeners.PreShopCreation.MoneyChecker; import com.Acrobot.ChestShop.Listeners.PreShopCreation.NameChecker; import com.Acrobot.ChestShop.Listeners.PreShopCreation.PriceChecker; @@ -143,9 +139,6 @@ public void onEnable() { getCommand("csVersion").setExecutor(new Version()); getCommand("csGive").setExecutor(new Give()); getCommand("cstoggle").setExecutor(new Toggle()); - getCommand("csSetItem").setExecutor(new SetItem()); - getCommand("csSetPrice").setExecutor(new SetPrice()); - getCommand("csSetAmount").setExecutor(new SetAmount()); getCommand("csAddAccessor").setExecutor(new AddAccessor()); getCommand("csRemoveAccessor").setExecutor(new RemoveAccessor()); } @@ -290,7 +283,6 @@ private void registerPreShopCreationEvents() { } registerEvent(new ChestChecker()); - registerEvent(new ItemChecker()); registerEvent(new MoneyChecker()); registerEvent(new NameChecker()); registerEvent(new com.Acrobot.ChestShop.Listeners.PreShopCreation.PermissionChecker()); diff --git a/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java b/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java index 7ebaecec8..fe514cec2 100644 --- a/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java +++ b/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java @@ -1,17 +1,18 @@ package com.Acrobot.ChestShop.Economy; +import java.math.BigDecimal; +import java.util.UUID; + +import org.bukkit.World; +import org.bukkit.inventory.Inventory; + import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Configuration.Properties; +import com.Acrobot.ChestShop.Containers.AdminInventory; import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent; import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent; import com.Acrobot.ChestShop.Events.Economy.CurrencyFormatEvent; import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent; -import com.Acrobot.ChestShop.Signs.ChestShopSign; -import org.bukkit.World; -import org.bukkit.inventory.Inventory; - -import java.math.BigDecimal; -import java.util.UUID; /** * @author Acrobot @@ -23,7 +24,7 @@ public static String getServerAccountName() { } public static boolean isOwnerEconomicallyActive(Inventory inventory) { - return !ChestShopSign.isAdminShop(inventory) || !getServerAccountName().isEmpty(); + return !(inventory instanceof AdminInventory) || !getServerAccountName().isEmpty(); } public static boolean add(UUID name, World world, double amount) { diff --git a/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java index 7de3d5aa3..5e74568b5 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java @@ -4,6 +4,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; /** * Represents a state before shop is created @@ -18,11 +19,23 @@ public class PreShopCreationEvent extends Event { private CreationOutcome outcome = CreationOutcome.SHOP_CREATED_SUCCESSFULLY; private Sign sign; private String[] signLines; + private ItemStack itemStack; - public PreShopCreationEvent(Player creator, Sign sign, String[] signLines) { + public PreShopCreationEvent(Player creator, Sign sign, String[] signLines, ItemStack itemStack) { this.creator = creator; this.sign = sign; this.signLines = signLines.clone(); + this.itemStack = itemStack; + if (itemStack == null) + outcome = CreationOutcome.INVALID_ITEM; + } + + public String getQuantityLine() { + return signLines[2]; + } + + public ItemStack getItemStack() { + return itemStack.clone(); } /** diff --git a/src/main/java/com/Acrobot/ChestShop/Events/ShopCreatedEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/ShopCreatedEvent.java index 8455d4369..66f8ca5ac 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/ShopCreatedEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/ShopCreatedEvent.java @@ -1,11 +1,15 @@ package com.Acrobot.ChestShop.Events; import javax.annotation.Nullable; + import org.bukkit.block.Container; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; + +import com.Acrobot.ChestShop.Signs.ChestShopMetaData; /** * Represents a state after shop creation @@ -19,14 +23,24 @@ public class ShopCreatedEvent extends Event { private final Sign sign; private final String[] signLines; + private final ChestShopMetaData chestShopMetaData; @Nullable private final Container chest; - public ShopCreatedEvent(Player creator, Sign sign, @Nullable Container chest, String[] signLines) { + public ShopCreatedEvent(Player creator, Sign sign, @Nullable Container chest, String[] signLines, ChestShopMetaData chestShopMetaData) { this.creator = creator; this.sign = sign; this.chest = chest; this.signLines = signLines.clone(); + this.chestShopMetaData = chestShopMetaData; + } + + public ItemStack getItemStack() { + return chestShopMetaData.getItemStack(); + } + + public int getQuantity() { + return chestShopMetaData.getQuantity(); } /** diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/Break/SignBreak.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/Break/SignBreak.java index 2f85334ea..cb7eefb96 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/Break/SignBreak.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/Break/SignBreak.java @@ -124,7 +124,7 @@ public static boolean canBlockBeBroken(Block block, Player breaker) { for (Sign sign : attachedSigns) { - if (!canBeBroken || !ChestShopSign.isLegacyValid(sign)) { + if (!canBeBroken || !ChestShopSign.isChestShop(sign)) { continue; } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java index fbec0b17a..1a8c8ae42 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java @@ -1,5 +1,7 @@ package com.Acrobot.ChestShop.Listeners.Block; +import java.util.UUID; + import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockState; @@ -8,6 +10,7 @@ import org.bukkit.block.Sign; import org.bukkit.block.sign.Side; import org.bukkit.block.sign.SignSide; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.SignChangeEvent; @@ -17,12 +20,15 @@ import com.Acrobot.Breeze.Utils.BlockUtil; import com.Acrobot.Breeze.Utils.MaterialUtil; +import com.Acrobot.Breeze.Utils.PriceUtil; import com.Acrobot.Breeze.Utils.StringUtil; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.Events.PreShopCreationEvent; import com.Acrobot.ChestShop.Events.ShopCreatedEvent; +import com.Acrobot.ChestShop.Signs.ChestShopMetaData; import com.Acrobot.ChestShop.Signs.ChestShopSign; +import com.Acrobot.ChestShop.UUIDs.NameManager; import com.Acrobot.ChestShop.Utils.uBlock; /** @@ -51,13 +57,8 @@ public static void onSignChange(SignChangeEvent event) { return; } - PreShopCreationEvent preEvent = new PreShopCreationEvent(event.getPlayer(), (Sign) signBlock.getState(), line); - ItemStack itemStack = getItemStack(event.getLine(4), (Sign) event.getBlock().getState()); - if (itemStack == null) { - preEvent.setOutcome(PreShopCreationEvent.CreationOutcome.INVALID_ITEM); - } - + PreShopCreationEvent preEvent = new PreShopCreationEvent(event.getPlayer(), (Sign) signBlock.getState(), line, itemStack); ChestShop.callEvent(preEvent); if (preEvent.isCancelled()) { @@ -68,7 +69,10 @@ public static void onSignChange(SignChangeEvent event) { event.setLine(i, preEvent.getSignLine(i)); } - ShopCreatedEvent postEvent = new ShopCreatedEvent(preEvent.getPlayer(), preEvent.getSign(), uBlock.findConnectedChest(preEvent.getSign()), preEvent.getSignLines()); + ChestShopMetaData chestShopMetaData = createShopMetaData(preEvent.getSign(), event.getPlayer(), event.getLines(), itemStack); + + ShopCreatedEvent postEvent = new ShopCreatedEvent(preEvent.getPlayer(), preEvent.getSign(), + uBlock.findConnectedChest(preEvent.getSign()), preEvent.getSignLines(), chestShopMetaData); ChestShop.callEvent(postEvent); // clear back side @@ -78,7 +82,37 @@ public static void onSignChange(SignChangeEvent event) { signSide.setLine(i, ""); } - ChestShopSign.createShop(sign, event.getPlayer(), event.getLines(), itemStack); + ChestShopSign.saveChestShopMetaData(sign, chestShopMetaData); + } + + public static ChestShopMetaData createShopMetaData(Sign sign, Player creator, String[] signLines, ItemStack itemStack) { + + int quantity = Integer.parseInt(signLines[1].replaceAll("[^0-9]", "")); + + String priceLine = signLines[3]; + double sellPrice = PriceUtil.getSellPrice(priceLine); + double buyPrice = PriceUtil.getBuyPrice(priceLine); + + String ownerLine = signLines[0]; + boolean isAdminShop = ChestShopSign.isAdminshopLine(ownerLine); + + if (isAdminShop) { + return createAdminChestShop(sign, quantity, sellPrice, buyPrice, itemStack); + } else { + return createChestShop(sign, creator.getUniqueId(), quantity, sellPrice, buyPrice, itemStack); + } + + } + + private static ChestShopMetaData createChestShop(Sign sign, UUID owner, int quantity, double sellPrice, double buyPrice, + ItemStack itemStack) { + + return new ChestShopMetaData(owner, quantity, sellPrice, buyPrice, itemStack); + } + + private static ChestShopMetaData createAdminChestShop(Sign sign, int quantity, double sellPrice, double buyPrice, ItemStack itemStack) { + + return new ChestShopMetaData(NameManager.getAdminShopUUID(), quantity, sellPrice, buyPrice, itemStack); } private static ItemStack getItemStack(String itemLine, Sign sign) { diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java index 0cc46a4cb..ed32acd9e 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java @@ -1,7 +1,6 @@ package com.Acrobot.ChestShop.Listeners.Modules; import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.INVALID_PRICE; -import static com.Acrobot.ChestShop.Signs.ChestShopSign.ITEM_LINE; import static com.Acrobot.ChestShop.Signs.ChestShopSign.PRICE_LINE; import java.io.File; @@ -12,7 +11,6 @@ import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; -import com.Acrobot.Breeze.Utils.MaterialUtil; import com.Acrobot.Breeze.Utils.PriceUtil; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Events.PreShopCreationEvent; @@ -50,7 +48,7 @@ public PriceRestrictionModule() { @EventHandler public void onPreShopCreation(PreShopCreationEvent event) { - ItemStack material = MaterialUtil.getItem(event.getSignLine(ITEM_LINE)); + ItemStack material = event.getItemStack(); if (material == null) { return; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostShopCreation/ShopCreationLogger.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostShopCreation/ShopCreationLogger.java index 15ef7db32..99474273d 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PostShopCreation/ShopCreationLogger.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostShopCreation/ShopCreationLogger.java @@ -1,8 +1,6 @@ package com.Acrobot.ChestShop.Listeners.PostShopCreation; -import static com.Acrobot.ChestShop.Signs.ChestShopSign.ITEM_LINE; import static com.Acrobot.ChestShop.Signs.ChestShopSign.PRICE_LINE; -import static com.Acrobot.ChestShop.Signs.ChestShopSign.QUANTITY_LINE; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -24,7 +22,7 @@ public static void onShopCreation(final ShopCreatedEvent event) { String creator = event.getPlayer().getName(); String typeOfShop = ChestShopSign.isAdminShop(event.getSign()) ? "an Admin Shop" : "a shop"; - String item = event.getSignLine(QUANTITY_LINE) + ' ' + event.getSignLine(ITEM_LINE); + String item = event.getQuantity() + ' ' + event.getItemStack().getType().toString(); String prices = event.getSignLine(PRICE_LINE); String location = LocationUtil.locationToString(event.getSign().getLocation()); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EmptyShopDeleter.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EmptyShopDeleter.java index 2d77605c2..aece720dd 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EmptyShopDeleter.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EmptyShopDeleter.java @@ -1,12 +1,5 @@ package com.Acrobot.ChestShop.Listeners.PostTransaction; -import com.Acrobot.Breeze.Utils.InventoryUtil; -import com.Acrobot.ChestShop.ChestShop; -import com.Acrobot.ChestShop.Configuration.Properties; -import com.Acrobot.ChestShop.Events.ShopDestroyedEvent; -import com.Acrobot.ChestShop.Events.TransactionEvent; -import com.Acrobot.ChestShop.Signs.ChestShopSign; -import com.Acrobot.ChestShop.Utils.uBlock; import org.bukkit.Material; import org.bukkit.block.Container; import org.bukkit.block.Sign; @@ -16,6 +9,14 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import com.Acrobot.Breeze.Utils.InventoryUtil; +import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Configuration.Properties; +import com.Acrobot.ChestShop.Events.ShopDestroyedEvent; +import com.Acrobot.ChestShop.Events.TransactionEvent; +import com.Acrobot.ChestShop.Signs.ChestShopSign; +import com.Acrobot.ChestShop.Utils.uBlock; + /** * @author Acrobot */ @@ -31,7 +32,7 @@ public static void onTransaction(TransactionEvent event) { Sign sign = event.getSign(); Container connectedChest = uBlock.findConnectedChest(sign); - if (!shopShouldBeRemoved(ownerInventory, event.getStock())) { + if (!shopShouldBeRemoved(sign, ownerInventory, event.getStock())) { return; } @@ -60,14 +61,14 @@ public static void onTransaction(TransactionEvent event) { } sign.getBlock().setType(Material.AIR); - if (Properties.REMOVE_EMPTY_CHESTS && !ChestShopSign.isAdminShop(ownerInventory) && InventoryUtil.isEmpty(ownerInventory)) { + if (Properties.REMOVE_EMPTY_CHESTS && !ChestShopSign.isAdminShop(sign) && InventoryUtil.isEmpty(ownerInventory)) { connectedChest.getBlock().setType(Material.AIR); } else { ownerInventory.addItem(new ItemStack(signMaterial, 1)); } } - private static boolean shopShouldBeRemoved(Inventory inventory, ItemStack stock) { - return Properties.REMOVE_EMPTY_SHOPS && !ChestShopSign.isAdminShop(inventory) && !InventoryUtil.hasItems(stock, inventory); + private static boolean shopShouldBeRemoved(Sign sign, Inventory inventory, ItemStack stock) { + return Properties.REMOVE_EMPTY_SHOPS && !ChestShopSign.isAdminShop(sign) && !InventoryUtil.hasItems(stock, inventory); } } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/PermissionChecker.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/PermissionChecker.java index 8f8e625ad..62c2adef4 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/PermissionChecker.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/PermissionChecker.java @@ -5,7 +5,6 @@ import static com.Acrobot.ChestShop.Permission.SHOP_CREATION_BUY; import static com.Acrobot.ChestShop.Permission.SHOP_CREATION_ID; import static com.Acrobot.ChestShop.Permission.SHOP_CREATION_SELL; -import static com.Acrobot.ChestShop.Signs.ChestShopSign.ITEM_LINE; import static com.Acrobot.ChestShop.Signs.ChestShopSign.PRICE_LINE; import static org.bukkit.event.EventPriority.HIGH; @@ -14,7 +13,6 @@ import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; -import com.Acrobot.Breeze.Utils.MaterialUtil; import com.Acrobot.Breeze.Utils.PriceUtil; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Events.PreShopCreationEvent; @@ -33,9 +31,8 @@ public static void onPreShopCreation(PreShopCreationEvent event) { } String priceLine = event.getSignLine(PRICE_LINE); - String itemLine = event.getSignLine(ITEM_LINE); - ItemStack item = MaterialUtil.getItem(itemLine); + ItemStack item = event.getItemStack(); if (item == null || Permission.has(player, SHOP_CREATION_ID + item.getType().name().toLowerCase())) { return; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/QuantityChecker.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/QuantityChecker.java index 50053b785..2444bf080 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/QuantityChecker.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/QuantityChecker.java @@ -1,13 +1,13 @@ package com.Acrobot.ChestShop.Listeners.PreShopCreation; -import com.Acrobot.Breeze.Utils.NumberUtil; -import com.Acrobot.ChestShop.Events.PreShopCreationEvent; +import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.INVALID_QUANTITY; + import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.INVALID_QUANTITY; -import static com.Acrobot.ChestShop.Signs.ChestShopSign.QUANTITY_LINE; +import com.Acrobot.Breeze.Utils.NumberUtil; +import com.Acrobot.ChestShop.Events.PreShopCreationEvent; /** * @author Acrobot @@ -16,7 +16,7 @@ public class QuantityChecker implements Listener { @EventHandler(priority = EventPriority.LOWEST) public static void onPreShopCreation(PreShopCreationEvent event) { - String quantity = event.getSignLine(QUANTITY_LINE); + String quantity = event.getQuantityLine(); if (!NumberUtil.isInteger(quantity)) { event.setOutcome(INVALID_QUANTITY); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java index a8be38dc8..f4ec6f08d 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java @@ -32,7 +32,7 @@ public static void onShopDestroy(ShopDestroyedEvent event) { return; } - UUID owner = ChestShopSign.getOwnerUUID(event.getSign()); + UUID owner = ChestShopSign.getOwner(event.getSign()); CurrencyAddEvent currencyEvent = new CurrencyAddEvent(BigDecimal.valueOf(refundPrice), owner, event.getSign().getWorld()); ChestShop.callEvent(currencyEvent); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRemovalLogger.java b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRemovalLogger.java index 079723be3..ed5cef12d 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRemovalLogger.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRemovalLogger.java @@ -1,9 +1,5 @@ package com.Acrobot.ChestShop.Listeners.ShopRemoval; -import static com.Acrobot.ChestShop.Signs.ChestShopSign.ITEM_LINE; -import static com.Acrobot.ChestShop.Signs.ChestShopSign.PRICE_LINE; -import static com.Acrobot.ChestShop.Signs.ChestShopSign.QUANTITY_LINE; - import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -11,6 +7,7 @@ import com.Acrobot.Breeze.Utils.LocationUtil; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Events.ShopDestroyedEvent; +import com.Acrobot.ChestShop.Signs.ChestShopMetaData; import com.Acrobot.ChestShop.Signs.ChestShopSign; import com.Acrobot.ChestShop.UUIDs.NameManager; @@ -26,11 +23,15 @@ public static void onShopRemoval(final ShopDestroyedEvent event) { return; } - String shopOwner = NameManager.getFullNameFor(ChestShopSign.getOwnerUUID(event.getSign())); + ChestShopMetaData chestShopMetaData = ChestShopSign.getChestShopMetaData(event.getSign()); + if (chestShopMetaData == null) + return; + + String shopOwner = NameManager.getFullNameFor(chestShopMetaData.getOwner()); String typeOfShop = ChestShopSign.isAdminShop(event.getSign()) ? "An Admin Shop" : "A shop belonging to " + shopOwner; - String item = event.getSign().getLine(QUANTITY_LINE) + ' ' + event.getSign().getLine(ITEM_LINE); - String prices = event.getSign().getLine(PRICE_LINE); + String item = chestShopMetaData.getQuantity() + ' ' + chestShopMetaData.getItemStack().getType().toString(); + String prices = "B " + chestShopMetaData.getBuyPrice() + " : " + chestShopMetaData.getSellPrice() + " S"; String location = LocationUtil.locationToString(event.getSign().getLocation()); String message = String.format(REMOVAL_MESSAGE, typeOfShop, item, prices, location); diff --git a/src/main/java/com/Acrobot/ChestShop/Security.java b/src/main/java/com/Acrobot/ChestShop/Security.java index 72a570b09..840e03ef5 100644 --- a/src/main/java/com/Acrobot/ChestShop/Security.java +++ b/src/main/java/com/Acrobot/ChestShop/Security.java @@ -46,7 +46,7 @@ public static boolean canPlaceSign(Player player, Sign sign) { if (chest != null) { Sign existingShopSign = uBlock.getConnectedSign(chest.getBlock(), sign.getBlock()); if (existingShopSign != null) { - UUID existingSignUUID = ChestShopSign.getOwnerUUID(sign); + UUID existingSignUUID = ChestShopSign.getOwner(sign); if (existingSignUUID == null || !existingSignUUID.equals(player.getUniqueId())) { return false; } diff --git a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java index 2c80ceccf..61702e2c6 100644 --- a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java +++ b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java @@ -11,12 +11,10 @@ import org.bukkit.block.BlockState; import org.bukkit.block.Sign; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import com.Acrobot.Breeze.Utils.PriceUtil; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.UUIDs.NameManager; @@ -36,38 +34,6 @@ public static void createNamespacedKeys(ChestShop chestShop) { METADATA_NAMESPACED_KEY = new NamespacedKey(chestShop, "metadata"); } - public static void createShop(Sign sign, Player creator, String[] signLines, ItemStack itemStack) { - - int quantity = Integer.parseInt(signLines[1].replaceAll("[^0-9]", "")); - - String priceLine = signLines[3]; - double sellPrice = PriceUtil.getSellPrice(priceLine); - double buyPrice = PriceUtil.getBuyPrice(priceLine); - - String ownerLine = signLines[0]; - boolean isAdminShop = ownerLine.replace(" ", "").equalsIgnoreCase(Properties.ADMIN_SHOP_NAME.replace(" ", "")); - - if (isAdminShop) { - createAdminChestShop(sign, quantity, sellPrice, buyPrice, itemStack); - } else { - createChestShop(sign, creator.getUniqueId(), quantity, sellPrice, buyPrice, itemStack); - } - - } - - private static void createChestShop(Sign sign, UUID owner, int quantity, double sellPrice, double buyPrice, ItemStack itemStack) { - - ChestShopMetaData chestShopMetaData = new ChestShopMetaData(owner, quantity, sellPrice, buyPrice, itemStack); - saveChestShopMetaData(sign, chestShopMetaData); - } - - private static void createAdminChestShop(Sign sign, int quantity, double sellPrice, double buyPrice, ItemStack itemStack) { - - ChestShopMetaData chestShopMetaData = new ChestShopMetaData(NameManager.getAdminShopUUID(), quantity, sellPrice, buyPrice, - itemStack); - saveChestShopMetaData(sign, chestShopMetaData); - } - public static boolean isAdminShop(Sign sign) { return getChestShopMetaData(sign).isOwner(NameManager.getAdminShopUUID()); } @@ -178,7 +144,7 @@ public static ChestShopMetaData getChestShopMetaData(Sign sign) { } } - private static void saveChestShopMetaData(Sign sign, ChestShopMetaData chestShopMetaData) { + public static void saveChestShopMetaData(Sign sign, ChestShopMetaData chestShopMetaData) { try { @@ -202,4 +168,8 @@ public static boolean isValidPreparedSign(String[] lines) { } return lines[PRICE_LINE].indexOf(':') == lines[PRICE_LINE].lastIndexOf(':'); } + + public static boolean isAdminshopLine(String ownerLine) { + return ownerLine.replace(" ", "").equalsIgnoreCase(Properties.ADMIN_SHOP_NAME.replace(" ", "")); + } } diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index 57aaf25a8..2f3b43030 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -140,7 +140,7 @@ private static String storeUsername(final UUID uuid, String name) { public static boolean canUseName(OfflinePlayer player, String name) { - if (ChestShopSign.isAdminShopNameString(name)) { + if (ChestShopSign.isAdminshopLine(name)) { return false; }