From 1e85e427ca0e18fbd7b19914afca875d264633e1 Mon Sep 17 00:00:00 2001 From: Acrobot Date: Thu, 20 Sep 2012 22:38:11 +0200 Subject: [PATCH] REALLY fixed Admin Shops now Also, fixed out of stock message to include items. Oh, and Shift+clicking correctly gets the item amount. --- com/Acrobot/ChestShop/Economy/Economy.java | 2 +- .../Listeners/Player/PlayerInteract.java | 6 ++- .../PreTransaction/ErrorMessageSender.java | 41 +++++++++++++++++-- plugin.yml | 2 +- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/com/Acrobot/ChestShop/Economy/Economy.java b/com/Acrobot/ChestShop/Economy/Economy.java index 3f9450d..84c7c3d 100644 --- a/com/Acrobot/ChestShop/Economy/Economy.java +++ b/com/Acrobot/ChestShop/Economy/Economy.java @@ -17,7 +17,7 @@ public class Economy { private static EcoPlugin economy; public static boolean isOwnerEconomicallyActive(Inventory inventory) { - return !ChestShopSign.isAdminShop(inventory) || getServerAccountName().isEmpty(); + return !ChestShopSign.isAdminShop(inventory) || !getServerAccountName().isEmpty(); } public static boolean hasAccount(String p) { diff --git a/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java b/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java index 85462fb..94cda84 100644 --- a/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java @@ -136,7 +136,11 @@ public class PlayerInteract implements Listener { Action buy = Config.getBoolean(REVERSE_BUTTONS) ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK; if (action == buy) { - amount = InventoryUtil.getAmount(item, inventory); + if (inventory instanceof AdminInventory) { + amount = Integer.MAX_VALUE; + } else { + amount = InventoryUtil.getAmount(item, inventory); + } } else { amount = InventoryUtil.getAmount(item, player.getInventory()); } diff --git a/com/Acrobot/ChestShop/Listeners/PreTransaction/ErrorMessageSender.java b/com/Acrobot/ChestShop/Listeners/PreTransaction/ErrorMessageSender.java index a6a59ae..df6d50f 100644 --- a/com/Acrobot/ChestShop/Listeners/PreTransaction/ErrorMessageSender.java +++ b/com/Acrobot/ChestShop/Listeners/PreTransaction/ErrorMessageSender.java @@ -1,5 +1,6 @@ package com.Acrobot.ChestShop.Listeners.PreTransaction; +import com.Acrobot.Breeze.Utils.MaterialUtil; import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Language; import com.Acrobot.ChestShop.Config.Property; @@ -9,6 +10,10 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; + +import java.util.LinkedList; +import java.util.List; /** * @author Acrobot @@ -22,7 +27,7 @@ public class ErrorMessageSender implements Listener { Language message = null; - switch(event.getTransactionOutcome()) { + switch (event.getTransactionOutcome()) { case SHOP_DOES_NOT_BUY_THIS_ITEM: message = Language.NO_BUYING_HERE; break; @@ -48,7 +53,8 @@ public class ErrorMessageSender implements Listener { message = Language.NOT_ENOUGH_ITEMS_TO_SELL; break; case NOT_ENOUGH_STOCK_IN_CHEST: - sendMessageToOwner(event.getOwner(), Language.NOT_ENOUGH_STOCK_IN_YOUR_SHOP); + String messageOutOfStock = Config.getLocal(Language.NOT_ENOUGH_STOCK_IN_YOUR_SHOP).replace("%material", getItemNames(event.getStock())); + sendMessageToOwner(event.getOwner(), messageOutOfStock); message = Language.NOT_ENOUGH_STOCK; break; case SHOP_IS_RESTRICTED: @@ -64,10 +70,37 @@ public class ErrorMessageSender implements Listener { } } - private static void sendMessageToOwner(OfflinePlayer owner, Language message) { + private static String getItemNames(ItemStack[] stock) { + List items = new LinkedList(); + + for (ItemStack stack : stock) { + boolean hadItem = false; + + for (ItemStack item : items) { + if (MaterialUtil.equals(stack, item)) { + item.setAmount(item.getAmount() + stack.getAmount()); + hadItem = true; + } + } + + if (!hadItem) { + items.add(stack.clone()); + } + } + + StringBuilder names = new StringBuilder(50); + + for (ItemStack item : items) { + names.append(MaterialUtil.getName(item)).append(',').append(' '); + } + + return names.toString(); + } + + private static void sendMessageToOwner(OfflinePlayer owner, String message) { if (owner.isOnline() && Config.getBoolean(Property.SHOW_MESSAGE_OUT_OF_STOCK)) { Player player = (Player) owner; - player.sendMessage(Config.getLocal(message)); + player.sendMessage(message); } } } diff --git a/plugin.yml b/plugin.yml index 4e04bef..057d154 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop -version: 3.50t0012 +version: 3.50t0013 #for CButD dev-url: http://dev.bukkit.org/server-mods/chestshop/