From 24eb1b1e1970e0222021cfd4a94c7865d5f53232 Mon Sep 17 00:00:00 2001 From: L4BORG Date: Thu, 13 Oct 2016 18:11:23 +0200 Subject: [PATCH 1/2] Economy fixes, fix for https://github.com/dmulloy2/ChestShop-3/issues/11 --- .../Economy/Plugins/VaultListener.java | 30 ++++++++++------- .../Listeners/Player/PlayerInteract.java | 32 ++++++++----------- .../PostTransaction/EconomicModule.java | 2 +- .../ChestShop/Metadata/ItemDatabase.java | 5 ++- .../Acrobot/ChestShop/UUIDs/NameManager.java | 1 + src/main/resources/plugin.yml | 13 ++------ 6 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java index bd3d487..2a3832a 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java @@ -6,6 +6,7 @@ import com.Acrobot.ChestShop.UUIDs.NameManager; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.World; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -20,11 +21,11 @@ import java.math.BigDecimal; * @author Acrobot */ public class VaultListener implements Listener { - private final Economy provider; + private static Economy provider; - private VaultListener(Economy provider) { - this.provider = provider; - } + private VaultListener(Economy provider) { this.provider = provider; } + + public static Economy getProvider() { return provider; } public boolean transactionCanFail() { return provider.getName().equals("Gringotts") || provider.getName().equals("GoldIsMoney") || provider.getName().equals("MultiCurrency"); @@ -62,7 +63,8 @@ public class VaultListener implements Listener { } double balance = 0; - String lastSeen = NameManager.getLastSeenName(event.getAccount()); + //String lastSeen = NameManager.getLastSeenName(event.getAccount()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount()); if (lastSeen != null) { balance = provider.getBalance(lastSeen, event.getWorld().getName()); @@ -82,7 +84,8 @@ public class VaultListener implements Listener { } World world = event.getWorld(); - String lastSeen = NameManager.getLastSeenName(event.getAccount()); + //String lastSeen = NameManager.getLastSeenName(event.getAccount()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount()); if (lastSeen != null) { if (provider.has(lastSeen, world.getName(), event.getDoubleAmount())) { @@ -100,7 +103,9 @@ public class VaultListener implements Listener { } World world = event.getWorld(); - String lastSeen = NameManager.getLastSeenName(event.getAccount()); + //String lastSeen = NameManager.getLastSeenName(event.getAccount()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount()); + event.hasAccount(lastSeen != null && provider.hasAccount(lastSeen, world.getName())); } @@ -121,7 +126,8 @@ public class VaultListener implements Listener { } World world = event.getWorld(); - String lastSeen = NameManager.getLastSeenName(event.getTarget()); + //String lastSeen = NameManager.getLastSeenName(event.getTarget()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getTarget()); if (lastSeen != null) { provider.depositPlayer(lastSeen, world.getName(), event.getDoubleAmount()); @@ -135,10 +141,11 @@ public class VaultListener implements Listener { } World world = event.getWorld(); - String lastSeen = NameManager.getLastSeenName(event.getTarget()); + //String lastSeen = NameManager.getLastSeenName(event.getTarget()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getTarget()); if (lastSeen != null) { - provider.withdrawPlayer(NameManager.getLastSeenName(event.getTarget()), world.getName(), event.getDoubleAmount()); + provider.withdrawPlayer(lastSeen, world.getName(), event.getDoubleAmount()); } } @@ -165,7 +172,8 @@ public class VaultListener implements Listener { return; } - String lastSeen = NameManager.getLastSeenName(event.getAccount()); + //String lastSeen = NameManager.getLastSeenName(event.getAccount()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount()); String world = event.getWorld().getName(); if (lastSeen == null) { diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java index 00c7c04..2643ae4 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java @@ -6,6 +6,7 @@ import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.Containers.AdminInventory; import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Events.TransactionEvent; +import com.Acrobot.ChestShop.Listeners.Economy.Plugins.VaultListener; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Plugins.ChestShop; import com.Acrobot.ChestShop.Security; @@ -45,12 +46,11 @@ import static org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK; public class PlayerInteract implements Listener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public static void onInteract(PlayerInteractEvent event) { + public static void onInteract(PlayerInteractEvent event) + { Block block = event.getClickedBlock(); - - if (block == null) { + if (block == null) return; - } Action action = event.getAction(); Player player = event.getPlayer(); @@ -68,12 +68,10 @@ public class PlayerInteract implements Listener { return; } - if (!isSign(block) || player.getItemInHand().getType() == Material.SIGN) { // Blocking accidental sign edition + if (!isSign(block) || player.getItemInHand().getType() == Material.SIGN) // Blocking accidental sign edition return; - } Sign sign = (Sign) block.getState(); - if (!ChestShopSign.isValid(sign)) { return; } @@ -95,17 +93,14 @@ public class PlayerInteract implements Listener { event.setCancelled(true); } + //Bukkit.getLogger().info("ChestShop - DEBUG - "+block.getWorld().getName()+": "+block.getLocation().getBlockX()+", "+block.getLocation().getBlockY()+", "+block.getLocation().getBlockZ()); PreTransactionEvent pEvent = preparePreTransactionEvent(sign, player, action); - - if (pEvent == null) { + if (pEvent == null) return; - } Bukkit.getPluginManager().callEvent(pEvent); - - if (pEvent.isCancelled()) { + if (pEvent.isCancelled()) return; - } TransactionEvent tEvent = new TransactionEvent(pEvent, sign); Bukkit.getPluginManager().callEvent(tEvent); @@ -118,17 +113,19 @@ public class PlayerInteract implements Listener { String material = sign.getLine(ITEM_LINE); String ownerName = NameManager.getFullUsername(name); - if (ownerName == null || ownerName.isEmpty()) { + if (ownerName == null || ownerName.isEmpty()) return null; - } UUID uuid = NameManager.getUUID(ownerName); - if (uuid == null) { + if (uuid == null) return null; - } OfflinePlayer owner = Bukkit.getOfflinePlayer(uuid); + // check if player exists in economy + if(owner == null || owner.getName() == null || !VaultListener.getProvider().hasAccount(owner)) + return null; + Action buy = Properties.REVERSE_BUTTONS ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK; double price = (action == buy ? PriceUtil.getBuyPrice(prices) : PriceUtil.getSellPrice(prices)); @@ -136,7 +133,6 @@ public class PlayerInteract implements Listener { Inventory ownerInventory = (ChestShopSign.isAdminShop(sign) ? new AdminInventory() : chest != null ? chest.getInventory() : null); ItemStack item = MaterialUtil.getItem(material); - if (item == null || !NumberUtil.isInteger(quantity)) { player.sendMessage(Messages.prefix(Messages.INVALID_SHOP_DETECTED)); return null; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java index 44beac1..943d2ea 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java @@ -25,7 +25,7 @@ public class EconomicModule implements Listener { CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(BigDecimal.valueOf(event.getPrice()), event.getOwner().getUniqueId(), event.getSign().getWorld()); - ChestShop.callEvent(currencyAddEvent); + ChestShop.callEvent(currencyAddEvent); // java.lang.StackOverflowError CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(BigDecimal.valueOf(event.getPrice()), event.getClient()); ChestShop.callEvent(currencySubtractEvent); diff --git a/src/main/java/com/Acrobot/ChestShop/Metadata/ItemDatabase.java b/src/main/java/com/Acrobot/ChestShop/Metadata/ItemDatabase.java index 95a2736..e226e3d 100644 --- a/src/main/java/com/Acrobot/ChestShop/Metadata/ItemDatabase.java +++ b/src/main/java/com/Acrobot/ChestShop/Metadata/ItemDatabase.java @@ -76,7 +76,10 @@ public class ItemDatabase { * @param code Item code * @return ItemStack represented by this code */ - public ItemStack getFromCode(String code) { + public ItemStack getFromCode(String code) + { + // TODO java.lang.StackOverflowError - http://pastebin.com/eRD8wUFM - Corrupt item DB? + try { int id = Base62.decode(code); Item item = itemDao.queryBuilder().where().eq("id", id).queryForFirst(); diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index a2bf230..cb9663b 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -205,6 +205,7 @@ public class NameManager { account = new Account(player.getName(), player.getUniqueId()); if (!usernameToUUID.inverse().containsKey(uuid)) { + usernameToUUID.remove(player.getName()); // https://github.com/dmulloy2/ChestShop-3/issues/11 usernameToUUID.inverse().put(uuid, player.getName()); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8b96924..a398013 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,17 +1,8 @@ name: ChestShop - main: com.Acrobot.ChestShop.ChestShop - version: ${project.version} - -#for CButD -dev-url: http://dev.bukkit.org/server-mods/chestshop/ - - -author: Acrobot -description: > - A chest shop for economy plugins. - +author: [Acrobot, dmulloy2, L4BORG] +description: A chest shop for economy plugins. depend: [Vault] softdepend: [LWC, Lockette, Deadbolt, OddItem, WorldGuard, Heroes, SimpleChestLock, Residence] From 2ff945bbe6a13b9fca4e1db41e788e7b59fee2e9 Mon Sep 17 00:00:00 2001 From: L4BORG Date: Thu, 10 Nov 2016 03:17:27 +0100 Subject: [PATCH 2/2] Fix Admin Shops --- .../com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java index 2643ae4..eb36854 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java @@ -123,7 +123,7 @@ public class PlayerInteract implements Listener { OfflinePlayer owner = Bukkit.getOfflinePlayer(uuid); // check if player exists in economy - if(owner == null || owner.getName() == null || !VaultListener.getProvider().hasAccount(owner)) + if(!ChestShopSign.isAdminShop(sign) && (owner == null || owner.getName() == null || !VaultListener.getProvider().hasAccount(owner))) return null; Action buy = Properties.REVERSE_BUTTONS ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK;