From 123c05a98e57d176382d4f3f6798fcd6d4bd19a8 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sun, 6 Mar 2016 14:50:15 -0500 Subject: [PATCH 01/21] Update to 1.9 --- pom.xml | 8 +-- .../Breeze/Configuration/Configuration.java | 22 ++++---- .../com/Acrobot/Breeze/Database/Database.java | 5 +- .../Acrobot/Breeze/Utils/Encoding/Base64.java | 14 ++--- .../ChestShop/Containers/AdminInventory.java | 51 +++++++++++++++++-- .../Listeners/AuthMeChestShopListener.java | 12 +---- 6 files changed, 74 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index e7cf242..8b4875f 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ org.bukkit bukkit - 1.8.8-R0.1-SNAPSHOT + 1.9-R0.1-SNAPSHOT provided @@ -144,6 +144,7 @@ + com.griefcraft.lwc @@ -278,8 +280,8 @@ maven-compiler-plugin 2.3.2 - 1.6 - 1.6 + 1.7 + 1.7 diff --git a/src/main/java/com/Acrobot/Breeze/Configuration/Configuration.java b/src/main/java/com/Acrobot/Breeze/Configuration/Configuration.java index 249fc2c..da9c302 100644 --- a/src/main/java/com/Acrobot/Breeze/Configuration/Configuration.java +++ b/src/main/java/com/Acrobot/Breeze/Configuration/Configuration.java @@ -1,14 +1,19 @@ package com.Acrobot.Breeze.Configuration; -import com.Acrobot.Breeze.Configuration.Annotations.PrecededBySpace; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Scanner; + import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import java.io.*; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.Scanner; +import com.Acrobot.Breeze.Configuration.Annotations.PrecededBySpace; /** * A class which can be used to make configs easier to load @@ -71,18 +76,13 @@ public class Configuration { * @return If the file ends with space */ public static boolean endsWithSpace(File file) { - try { - Scanner scanner = new Scanner(file); + try (Scanner scanner = new Scanner(file)) { String lastLine = ""; while (scanner.hasNextLine()) { lastLine = scanner.nextLine(); } - if (scanner != null) { - scanner.close(); - } - return lastLine.isEmpty(); } catch (FileNotFoundException e) { e.printStackTrace(); diff --git a/src/main/java/com/Acrobot/Breeze/Database/Database.java b/src/main/java/com/Acrobot/Breeze/Database/Database.java index 6db6f78..026ea69 100644 --- a/src/main/java/com/Acrobot/Breeze/Database/Database.java +++ b/src/main/java/com/Acrobot/Breeze/Database/Database.java @@ -1,10 +1,11 @@ package com.Acrobot.Breeze.Database; -import javax.persistence.Entity; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import javax.persistence.Entity; + /** * Database class, which can be used to connect to JDBC * @@ -49,7 +50,7 @@ public class Database { return false; } - String tableName = ((javax.persistence.Table) clazz.getAnnotation(javax.persistence.Table.class)).name(); + String tableName = clazz.getAnnotation(javax.persistence.Table.class).name(); Table table = getTable(tableName); EntityParser parser = new EntityParser(clazz); diff --git a/src/main/java/com/Acrobot/Breeze/Utils/Encoding/Base64.java b/src/main/java/com/Acrobot/Breeze/Utils/Encoding/Base64.java index 5f7812e..1d82446 100644 --- a/src/main/java/com/Acrobot/Breeze/Utils/Encoding/Base64.java +++ b/src/main/java/com/Acrobot/Breeze/Utils/Encoding/Base64.java @@ -406,7 +406,7 @@ public class Base64 { byte[] ALPHABET = getAlphabet(options); - // 1 2 3 + // 1 2 3 // 01234567890123456789012345678901 Bit position // --------000000001111111122222222 Array position from threeBytes // --------| || || || | Six bit groups to index ALPHABET @@ -1106,8 +1106,8 @@ public class Base64 { else { // There's a bad input character in the Base64 stream. throw new java.io.IOException(String.format( - "Bad Base64 input character decimal %d in array position %d", ((int) source[i]) & 0xFF, i)); - } // end else: + "Bad Base64 input character decimal %d in array position %d", (source[i]) & 0xFF, i)); + } // end else: } // each input character byte[] out = new byte[outBuffPosn]; @@ -1164,7 +1164,7 @@ public class Base64 { boolean dontGunzip = (options & DONT_GUNZIP) != 0; if ((bytes != null) && (bytes.length >= 4) && (!dontGunzip)) { - int head = ((int) bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); + int head = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); if (java.util.zip.GZIPInputStream.GZIP_MAGIC == head) { java.io.ByteArrayInputStream bais = null; java.util.zip.GZIPInputStream gzis = null; @@ -1515,7 +1515,7 @@ public class Base64 { out.close(); } catch (Exception ex) { } - } // end finally + } // end finally } // end encodeFileToFile @@ -1545,7 +1545,7 @@ public class Base64 { out.close(); } catch (Exception ex) { } - } // end finally + } // end finally } // end decodeFileToFile @@ -1683,7 +1683,7 @@ public class Base64 { else { // Must have broken out from above. throw new java.io.IOException("Improperly padded Base64 input."); - } // end + } // end } // end else: decode } // end else: get data diff --git a/src/main/java/com/Acrobot/ChestShop/Containers/AdminInventory.java b/src/main/java/com/Acrobot/ChestShop/Containers/AdminInventory.java index d01bcfe..ff1ac40 100644 --- a/src/main/java/com/Acrobot/ChestShop/Containers/AdminInventory.java +++ b/src/main/java/com/Acrobot/ChestShop/Containers/AdminInventory.java @@ -1,5 +1,11 @@ package com.Acrobot.ChestShop.Containers; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; + +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryType; @@ -7,45 +13,49 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.ListIterator; - /** * @author Acrobot */ public class AdminInventory implements Inventory { + @Override public int getSize() { return Integer.MAX_VALUE; } + @Override public int getMaxStackSize() { return Integer.MAX_VALUE; } + @Override public void setMaxStackSize(int i) { } + @Override public String getName() { return "Admin inventory"; } + @Override public ItemStack getItem(int i) { return null; } + @Override public void setItem(int i, ItemStack itemStack) { } + @Override public HashMap addItem(ItemStack... itemStacks) { return new HashMap(); } + @Override public HashMap removeItem(ItemStack... itemStacks) { return new HashMap(); } + @Override public ItemStack[] getContents() { return new ItemStack[]{ new ItemStack(Material.CHEST, 1), @@ -53,37 +63,46 @@ public class AdminInventory implements Inventory { }; } + @Override public void setContents(ItemStack[] itemStacks) { } + @Override public boolean contains(int i) { return true; } + @Override public boolean contains(Material material) { return true; } + @Override public boolean contains(ItemStack itemStack) { return true; } + @Override public boolean contains(int i, int i1) { return true; } + @Override public boolean contains(Material material, int i) { return true; } + @Override public boolean contains(ItemStack itemStack, int i) { return true; } + @Override public boolean containsAtLeast(ItemStack itemStack, int i) { return true; } + @Override public HashMap all(int i) { HashMap items = new HashMap(); items.put(1, new ItemStack(i, Integer.MAX_VALUE)); @@ -91,6 +110,7 @@ public class AdminInventory implements Inventory { return items; } + @Override public HashMap all(Material material) { if (material.getMaxDurability() != 0) { HashMap items = new HashMap(); @@ -105,6 +125,7 @@ public class AdminInventory implements Inventory { return all(material.getId()); } + @Override public HashMap all(ItemStack itemStack) { HashMap items = new HashMap(); @@ -116,58 +137,78 @@ public class AdminInventory implements Inventory { return items; } + @Override public int first(int i) { return 0; } + @Override public int first(Material material) { return 0; } + @Override public int first(ItemStack itemStack) { return 0; } + @Override public int firstEmpty() { return 0; } + @Override public void remove(int i) { } + @Override public void remove(Material material) { } + @Override public void remove(ItemStack itemStack) { } + @Override public void clear(int i) { } + @Override public void clear() { } + @Override public List getViewers() { return new ArrayList(); } + @Override public String getTitle() { return "Admin inventory"; } + @Override public InventoryType getType() { return null; } + @Override public InventoryHolder getHolder() { return null; } + @Override public ListIterator iterator() { return null; } + @Override public ListIterator iterator(int i) { return null; } + + @Override + public Location getLocation() { + return null; + } } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java index 1e61fa9..371e7d4 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java @@ -1,18 +1,10 @@ package com.Acrobot.ChestShop.Listeners; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import com.Acrobot.ChestShop.Events.PreTransactionEvent; -import com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome; - -import fr.xephi.authme.api.NewAPI; - public class AuthMeChestShopListener implements Listener { - NewAPI AuthMeAPI = NewAPI.getInstance(); + /*NewAPI AuthMeAPI = NewAPI.getInstance(); @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPreTransaction(PreTransactionEvent event) { @@ -31,5 +23,5 @@ public class AuthMeChestShopListener implements Listener { } event.setCancelled(TransactionOutcome.CLIENT_DOES_NOT_HAVE_PERMISSION); - } + }*/ } From ef5ccbb77558859c87d70abc84178f838c79285f Mon Sep 17 00:00:00 2001 From: Brian Ronald Date: Sun, 8 May 2016 00:29:20 +0100 Subject: [PATCH 02/21] Implement missing methods so that this compiles without errors --- .../Acrobot/ChestShop/Containers/AdminInventory.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/Acrobot/ChestShop/Containers/AdminInventory.java b/src/main/java/com/Acrobot/ChestShop/Containers/AdminInventory.java index ff1ac40..124c34c 100644 --- a/src/main/java/com/Acrobot/ChestShop/Containers/AdminInventory.java +++ b/src/main/java/com/Acrobot/ChestShop/Containers/AdminInventory.java @@ -67,6 +67,16 @@ public class AdminInventory implements Inventory { public void setContents(ItemStack[] itemStacks) { } + @Override + public ItemStack[] getStorageContents() { + return new ItemStack[0]; + } + + @Override + public void setStorageContents(ItemStack[] itemStacks) throws IllegalArgumentException { + + } + @Override public boolean contains(int i) { return true; From a9f2f228d677960d6cffe90fe82cf9ee867cee9b Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Thu, 9 Jun 2016 22:38:15 -0400 Subject: [PATCH 03/21] Update to 1.10, attempt fix for item overflow --- pom.xml | 2 +- .../Acrobot/Breeze/Utils/InventoryUtil.java | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 8b4875f..e287f63 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ org.bukkit bukkit - 1.9-R0.1-SNAPSHOT + 1.10-R0.1-SNAPSHOT provided diff --git a/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java b/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java index 2987f59..4379a3f 100644 --- a/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java +++ b/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java @@ -1,13 +1,13 @@ package com.Acrobot.Breeze.Utils; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + /** * @author Acrobot */ @@ -49,7 +49,7 @@ public class InventoryUtil { * @return Is the inventory empty? */ public static boolean isEmpty(Inventory inventory) { - for (ItemStack stack : inventory.getContents()) { + for (ItemStack stack : inventory.getStorageContents()) { if (!MaterialUtil.isEmpty(stack)) { return false; } @@ -89,7 +89,7 @@ public class InventoryUtil { return true; } - for (ItemStack iStack : inventory.getContents()) { + for (ItemStack iStack : inventory.getStorageContents()) { if (left <= 0) { return true; } @@ -125,7 +125,7 @@ public class InventoryUtil { int amountLeft = item.getAmount(); - for (int currentSlot = 0; currentSlot < inventory.getSize() && amountLeft > 0; currentSlot++) { + for (int currentSlot = 0; currentSlot < effectiveSize(inventory) && amountLeft > 0; currentSlot++) { ItemStack currentItem = inventory.getItem(currentSlot); ItemStack duplicate = item.clone(); @@ -152,6 +152,12 @@ public class InventoryUtil { return amountLeft; } + // Don't use the armor slots or extra slots + private static int effectiveSize(Inventory inventory) + { + return inventory.getStorageContents().length; + } + /** * Adds an item to the inventor * From c4c879117aca2686556440ff696b52e15c897435 Mon Sep 17 00:00:00 2001 From: Stanislav Usenkov Date: Wed, 6 Jul 2016 18:55:40 +0600 Subject: [PATCH 04/21] We should update Metrics! --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e287f63..35861b2 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ org.mcstats.bukkit metrics - R7 + R8-SNAPSHOT compile From a13b2c9070d9496d24fcd074d4fe8c19f4a9d8c7 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Thu, 7 Jul 2016 12:15:43 -0400 Subject: [PATCH 05/21] Fix a few NPE's caused by null accounts Thanks @mibby --- .../Economy/Plugins/VaultListener.java | 51 +++++++++++++------ .../Acrobot/ChestShop/UUIDs/NameManager.java | 33 +++++++----- 2 files changed, 56 insertions(+), 28 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 e27a125..bd3d487 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 @@ -61,10 +61,15 @@ public class VaultListener implements Listener { return; } - double balance = provider.getBalance(NameManager.getLastSeenName(event.getAccount()), event.getWorld().getName()); + double balance = 0; + String lastSeen = NameManager.getLastSeenName(event.getAccount()); - if (balance > Double.MAX_VALUE) { - balance = Double.MAX_VALUE; + if (lastSeen != null) { + balance = provider.getBalance(lastSeen, event.getWorld().getName()); + + if (balance > Double.MAX_VALUE) { + balance = Double.MAX_VALUE; + } } event.setAmount(balance); @@ -77,9 +82,14 @@ public class VaultListener implements Listener { } World world = event.getWorld(); + String lastSeen = NameManager.getLastSeenName(event.getAccount()); - if (provider.has(NameManager.getLastSeenName(event.getAccount()), world.getName(), event.getDoubleAmount())) { - event.hasEnough(true); + if (lastSeen != null) { + if (provider.has(lastSeen, world.getName(), event.getDoubleAmount())) { + event.hasEnough(true); + } + } else { + event.hasEnough(false); } } @@ -90,10 +100,8 @@ public class VaultListener implements Listener { } World world = event.getWorld(); - - if (!provider.hasAccount(NameManager.getLastSeenName(event.getAccount()), world.getName())) { - event.hasAccount(false); - } + String lastSeen = NameManager.getLastSeenName(event.getAccount()); + event.hasAccount(lastSeen != null && provider.hasAccount(lastSeen, world.getName())); } @EventHandler @@ -103,7 +111,6 @@ public class VaultListener implements Listener { } String formatted = provider.format(event.getDoubleAmount()); - event.setFormattedAmount(formatted); } @@ -114,8 +121,11 @@ public class VaultListener implements Listener { } World world = event.getWorld(); + String lastSeen = NameManager.getLastSeenName(event.getTarget()); - provider.depositPlayer(NameManager.getLastSeenName(event.getTarget()), world.getName(), event.getDoubleAmount()); + if (lastSeen != null) { + provider.depositPlayer(lastSeen, world.getName(), event.getDoubleAmount()); + } } @EventHandler @@ -125,8 +135,11 @@ public class VaultListener implements Listener { } World world = event.getWorld(); + String lastSeen = NameManager.getLastSeenName(event.getTarget()); - provider.withdrawPlayer(NameManager.getLastSeenName(event.getTarget()), world.getName(), event.getDoubleAmount()); + if (lastSeen != null) { + provider.withdrawPlayer(NameManager.getLastSeenName(event.getTarget()), world.getName(), event.getDoubleAmount()); + } } @EventHandler @@ -152,18 +165,26 @@ public class VaultListener implements Listener { return; } - if (!provider.hasAccount(NameManager.getLastSeenName(event.getAccount()), event.getWorld().getName())) { + String lastSeen = NameManager.getLastSeenName(event.getAccount()); + String world = event.getWorld().getName(); + + if (lastSeen == null) { event.canHold(false); return; } - EconomyResponse response = provider.depositPlayer(NameManager.getLastSeenName(event.getAccount()), event.getWorld().getName(), event.getDoubleAmount()); + if (!provider.hasAccount(lastSeen, world)) { + event.canHold(false); + return; + } + + EconomyResponse response = provider.depositPlayer(lastSeen, world, event.getDoubleAmount()); if (!response.transactionSuccess()) { event.canHold(false); return; } - provider.withdrawPlayer(NameManager.getLastSeenName(event.getAccount()), event.getWorld().getName(), event.getDoubleAmount()); + provider.withdrawPlayer(lastSeen, world, event.getDoubleAmount()); } } diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index ce6eabd..f39eeb1 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -10,19 +10,21 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.j256.ormlite.dao.Dao; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.logging.Level; /** * Lets you save/cache username and UUID relations * * @author Andrzej Pomirski (Acrobot) */ -@SuppressWarnings("UnusedAssignment") //I deliberately set the variables to null while initializing +@SuppressWarnings("UnusedAssignment") // I deliberately set the variables to null while initializing public class NameManager { private static Dao accounts; @@ -35,9 +37,9 @@ public class NameManager { return lastSeenName.get(uuid); } - if (Bukkit.getOfflinePlayer(uuid).getName() != null) { - String lastSeen = Bukkit.getOfflinePlayer(uuid).getName(); - + OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); + String lastSeen = player.getName(); + if (lastSeen != null) { lastSeenName.put(uuid, lastSeen); return lastSeen; } @@ -46,22 +48,27 @@ public class NameManager { try { account = accounts.queryBuilder().selectColumns("lastSeenName", "name").where().eq("uuid", uuid).queryForFirst(); - } catch (SQLException e) { - e.printStackTrace(); - return null; + } catch (SQLException ex) { + Bukkit.getLogger().log(Level.WARNING, "[ChestShop] Failed to find last seen name for " + uuid + ":", ex); } if (account == null) { - return ""; + return null; } - if (account.getLastSeenName() != null) { - lastSeenName.put(uuid, account.getLastSeenName()); - } else if (account.getName() != null) { - lastSeenName.put(uuid, account.getName()); + lastSeen = account.getLastSeenName(); + if (lastSeen != null) { + lastSeenName.put(uuid, lastSeen); + return lastSeen; } - return account.getLastSeenName(); + lastSeen = account.getName(); + if (lastSeen != null) { + lastSeenName.put(uuid, lastSeen); + return lastSeen; + } + + return null; } public static UUID getUUID(String username) { From 02d18df559e00546b2fb6335e48856790ee7a3fd Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sat, 20 Aug 2016 16:08:46 -0400 Subject: [PATCH 06/21] Fix an error with empty signs Fixes #3 --- src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java index 9ea2488..91af31a 100644 --- a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java +++ b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java @@ -81,7 +81,10 @@ public class ChestShopSign { if (player == null) return false; if (sign == null) return true; - return NameManager.canUseName(player, sign.getLine(NAME_LINE)); + String name = sign.getLine(NAME_LINE); + if (name == null || name.isEmpty()) return true; + + return NameManager.canUseName(player, name); } public static boolean isValidPreparedSign(String[] lines) { From 5749c84c2895a926dcbcd89dd08ccedeb86e672e Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sat, 20 Aug 2016 16:17:10 -0400 Subject: [PATCH 07/21] Fix and re-enable AuthMe hook --- pom.xml | 10 ++++---- .../java/com/Acrobot/ChestShop/ChestShop.java | 4 +++- .../ChestShop/Configuration/Properties.java | 9 ++++++- .../Listeners/AuthMeChestShopListener.java | 24 +++++++++++++++---- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 35861b2..06de8fc 100644 --- a/pom.xml +++ b/pom.xml @@ -69,9 +69,9 @@ - org.bukkit - bukkit - 1.10-R0.1-SNAPSHOT + org.spigotmc + spigot-api + 1.10.2-R0.1-SNAPSHOT provided @@ -144,11 +144,10 @@ - com.griefcraft.lwc diff --git a/src/main/java/com/Acrobot/ChestShop/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/ChestShop.java index cc787b3..05147a7 100644 --- a/src/main/java/com/Acrobot/ChestShop/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/ChestShop.java @@ -43,6 +43,7 @@ import org.bukkit.Server; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.Event; import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import org.mcstats.Metrics; @@ -213,7 +214,8 @@ public class ChestShop extends JavaPlugin { registerEvent(new ItemInfoListener()); registerEvent(new GarbageTextListener()); - if (this.getServer().getPluginManager().getPlugin("AuthMe") != null && this.getServer().getPluginManager().getPlugin("ChestShop").isEnabled()){ + Plugin authMe = getServer().getPluginManager().getPlugin("AuthMe"); + if (authMe != null && authMe.isEnabled()){ registerEvent(new AuthMeChestShopListener()); } diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java index fd44ef3..0e71e55 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java @@ -127,7 +127,14 @@ public class Properties { @ConfigurationComment("Do you want ChestShop to respect WorldGuard's chest protection?") public static boolean WORLDGUARD_USE_PROTECTION = false; + @PrecededBySpace + @ConfigurationComment("Do you want to deny shop access to unlogged users?") + public static boolean AUTHME_HOOK = true; + + @ConfigurationComment("Do you want to allow shop access to unregistered users? (Example: registration is optional)") + public static boolean AUTHME_ALLOW_UNREGISTERED = false; + @PrecededBySpace @ConfigurationComment("How much Heroes exp should people get for creating a ChestShop?") public static double HEROES_EXP = 100; -} +} \ No newline at end of file diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java index 371e7d4..0bab71c 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java @@ -1,27 +1,43 @@ package com.Acrobot.ChestShop.Listeners; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import com.Acrobot.ChestShop.Configuration.Properties; +import com.Acrobot.ChestShop.Events.PreTransactionEvent; +import com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome; + +import fr.xephi.authme.api.NewAPI; + public class AuthMeChestShopListener implements Listener { - /*NewAPI AuthMeAPI = NewAPI.getInstance(); + NewAPI AuthMeAPI = NewAPI.getInstance(); @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPreTransaction(PreTransactionEvent event) { if (event.getClient() == null) { return; } - Player player = event.getClient(); + if (!Properties.AUTHME_HOOK) { + return; + } + if (AuthMeAPI.isUnrestricted(player)) { return; } + if (!AuthMeAPI.isRegistered(player.getName()) && Properties.AUTHME_ALLOW_UNREGISTERED) { + return; + } + if (AuthMeAPI.isAuthenticated(player)) { return; } event.setCancelled(TransactionOutcome.CLIENT_DOES_NOT_HAVE_PERMISSION); - }*/ -} + } +} \ No newline at end of file From f31e5b260231646bfdeb3ae8cc953e0a3416e078 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Fri, 26 Aug 2016 20:19:02 -0400 Subject: [PATCH 08/21] Try to get it to compile --- pom.xml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 06de8fc..d1af6b6 100644 --- a/pom.xml +++ b/pom.xml @@ -10,9 +10,9 @@ Chest-and-sign shop plugin for Bukkit - scm:git:git://github.com/Acrobot/ChestShop-3 - scm:git:ssh://git@github.com/Acrobot/ChestShop-3.git - https://github.com/Acrobot/ChestShop-3 + scm:git:git://github.com/dmulloy2/ChestShop-3 + scm:git:ssh://git@github.com/dmulloy2/ChestShop-3.git + https://github.com/dmulloy2/ChestShop-3 @@ -30,11 +30,7 @@ vault-repo - http://nexus.theyeticave.net/content/repositories/pub_releases - - - heroes-repo - http://nexus.theyeticave.net/content/repositories/pub_snapshots/ + http://nexus.hc.to/content/repositories/pub_releases/ authme-repo @@ -95,7 +91,7 @@ net.milkbowl.vault Vault - 1.5.2 + 1.6.6 provided From 8f962f9345f842d357667c0397e5076eabd5c5e9 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Fri, 26 Aug 2016 20:36:35 -0400 Subject: [PATCH 09/21] Fix heroes dependency --- pom.xml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index d1af6b6..05eec6b 100644 --- a/pom.xml +++ b/pom.xml @@ -126,16 +126,12 @@ com.herocraftonline.heroes Heroes - 1.5.5.6-SNAPSHOT + 1.5.5 provided - org.bukkit - bukkit - - - org.bukkit - craftbukkit + * + * From e11b1430b47e904b8447bdfe01a978a1bcfa5604 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sat, 27 Aug 2016 12:44:39 -0400 Subject: [PATCH 10/21] Add download link to the readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 809159f..3aa1877 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ ChestShop ================================ +My fork of ChestShop. Downloads can be found here: [http://ci.dmulloy2.net/job/ChestShop](http://ci.dmulloy2.net/job/ChestShop) + ChestShop is an awesome plugin for managing your server's economy. By using chests and signs, you can effectively create your own market! @@ -28,6 +30,4 @@ To install external dependencies, place your .jar into the main folder and launc Links -------------------------------- -* [Forum Thread](http://forums.bukkit.org/threads/4150/) -* [BukkitDev site](http://dev.bukkit.org/server-mods/chestshop/) -* [Bug Tracker](http://dev.bukkit.org/server-mods/chestshop/tickets/?status=+) +* [Downloads](http://ci.dmulloy2.net/job/ChestShop) From 17eb698e289f43e75919deca0c6d783c61d4c3e6 Mon Sep 17 00:00:00 2001 From: mibby Date: Sat, 27 Aug 2016 19:58:45 -0700 Subject: [PATCH 11/21] Move sign-update() to break listener This fixes an infinite loop crash where the sign update calls the piston event and the update again and again. Also signs can't even be pushed by pistons... --- .../Acrobot/ChestShop/Listeners/Block/Break/SignBreak.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 905bcda..70754f8 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 @@ -63,6 +63,9 @@ public class SignBreak implements Listener { public static void onSignBreak(BlockBreakEvent event) { if (!canBlockBeBroken(event.getBlock(), event.getPlayer())) { event.setCancelled(true); + if (isSign(event.getBlock())) { + event.getBlock().getState().update(); + } } } @@ -118,7 +121,6 @@ public class SignBreak implements Listener { boolean canBeBroken = true; for (Sign sign : attachedSigns) { - sign.update(); if (!canBeBroken || !ChestShopSign.isValid(sign)) { continue; From 8c7594be51bc6053a30a111e8ac3c15acd280bce Mon Sep 17 00:00:00 2001 From: mibby Date: Sat, 27 Aug 2016 20:09:09 -0700 Subject: [PATCH 12/21] Revert PlayerKick Behavior Partial revert of 'Do not let people with already used usernames connect to the server' commit. See comments here https://github.com/Acrobot/ChestShop-3/commit/b0369d8e69c9035c29756756a3794c5277001882#commitcomment-14185778 and here. https://github.com/Acrobot/ChestShop-3/commit/c169df2265ef5aa679e47bd4f1acbd64f40cb19e#commitcomment-12846919 I personally believe ChestShops should not dictate whether a player is allowed to connect to the server or not. I personally have had issues with ChestShops kicking legitimate players from the server in online mode. --- .../ChestShop/Listeners/Player/PlayerConnect.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java index 56233f1..ec18498 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java @@ -27,18 +27,6 @@ public class PlayerConnect implements Listener { String playerName = NameUtil.stripUsername(playerDTO.getName()); UUID uuid = NameManager.getUUID(playerName); - if (uuid != null && !playerDTO.getUniqueId().equals(uuid)) { - Bukkit.getScheduler().runTask(ChestShop.getPlugin(), new Runnable() { - @Override - public void run() { - Bukkit.getPlayer(playerDTO.getUniqueId()).kickPlayer("[ChestShop]" + - "Unfortunately, this username was already used by " + - "another player."); - - } - }); - } - NameManager.storeUsername(playerDTO); } }); From 58258c858fcba249fca6f52cea784f583e7c0de0 Mon Sep 17 00:00:00 2001 From: mibby Date: Sat, 27 Aug 2016 20:20:46 -0700 Subject: [PATCH 13/21] Re-add database suppression. Re-add database suppression for SQLite driver start-up log warnings. https://dev.bukkit.org/bukkit-plugins/chestshop/tickets/1059-warning-you-seem-to-not-be-using-the-xerial-sqlite/ https://dev.bukkit.org/bukkit-plugins/chestshop/tickets/1086-error-com-acrobot-chest-shop-ormlite-db-sqlite-database/ --- .../java/com/Acrobot/ChestShop/ChestShop.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/main/java/com/Acrobot/ChestShop/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/ChestShop.java index 05147a7..a2b1ce5 100644 --- a/src/main/java/com/Acrobot/ChestShop/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/ChestShop.java @@ -38,6 +38,15 @@ import com.Acrobot.ChestShop.Signs.RestrictedSign; import com.Acrobot.ChestShop.UUIDs.NameManager; import com.Acrobot.ChestShop.Updater.Updater; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.LoggerConfig; +import org.apache.logging.log4j.core.filter.AbstractFilter; +import org.apache.logging.log4j.message.Message; + import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.configuration.file.YamlConfiguration; @@ -82,6 +91,7 @@ public class ChestShop extends JavaPlugin { Configuration.pairFileAndClass(loadFile("config.yml"), Properties.class); Configuration.pairFileAndClass(loadFile("local.yml"), Messages.class); + turnOffDatabaseLogging(); handleMigrations(); itemDatabase = new ItemDatabase(); @@ -115,6 +125,46 @@ public class ChestShop extends JavaPlugin { startUpdater(); } + private void turnOffDatabaseLogging() { + LoggerContext ctx = (LoggerContext) LogManager.getContext(false); + org.apache.logging.log4j.core.config.Configuration config = ctx.getConfiguration(); + LoggerConfig loggerConfig = config.getLoggerConfig(""); + + loggerConfig.addFilter(new AbstractFilter() { + @Override + public Result filter(org.apache.logging.log4j.core.Logger logger, Level level, Marker marker, String msg, Object... params) { + return filter(logger.getName(), level); + } + + @Override + public Result filter(org.apache.logging.log4j.core.Logger logger, Level level, Marker marker, Object msg, Throwable t) { + return filter(logger.getName(), level); + } + + @Override + public Result filter(org.apache.logging.log4j.core.Logger logger, Level level, Marker marker, Message msg, Throwable t) { + return filter(logger.getName(), level); + } + + @Override + public Result filter(LogEvent event) { + return filter(event.getLoggerName(), event.getLevel()); + } + + private Result filter(String classname, Level level) { + if (level.isAtLeastAsSpecificAs(Level.ERROR) && !classname.contains("SqliteDatabaseType")) { + return Result.NEUTRAL; + } + + if (classname.contains("SqliteDatabaseType") || classname.contains("TableUtils")) { + return Result.DENY; + } else { + return Result.NEUTRAL; + } + } + }); + } + private void handleMigrations() { File versionFile = loadFile("version"); YamlConfiguration previousVersion = YamlConfiguration.loadConfiguration(versionFile); From 050ce613475d960272786eef61271c74cc41c2d9 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Tue, 20 Sep 2016 15:40:41 -0400 Subject: [PATCH 14/21] Try to fix (or just ignore) a weird null pointer Fixes #6 --- .../com/Acrobot/ChestShop/UUIDs/NameManager.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index f39eeb1..bd0dedd 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -214,10 +214,17 @@ public class NameManager { } public static void dropUsername(final Player player) { - final UUID uuid = player.getUniqueId(); + if (player == null) return; - if (usernameToUUID.containsValue(uuid)) { - usernameToUUID.inverse().remove(uuid); + final UUID uuid = player.getUniqueId(); + if (uuid == null) return; + + try { + if (usernameToUUID.containsValue(uuid)) { + usernameToUUID.inverse().remove(uuid); + } + } catch (NullPointerException e) { + // Sigh... } String shortName = NameUtil.stripUsername(player.getName()); From e186635484d214ee621bff0692d725777616c1a0 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Tue, 20 Sep 2016 15:45:18 -0400 Subject: [PATCH 15/21] Try to fix a few more errors Fixes #7 --- .../ChestShop/Listeners/Player/PlayerConnect.java | 12 +++++------- .../ChestShop/Listeners/Player/PlayerInteract.java | 5 ++++- .../Listeners/ShopRemoval/ShopRefundListener.java | 4 ++++ .../com/Acrobot/ChestShop/UUIDs/NameManager.java | 6 +++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java index ec18498..643be6c 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java @@ -1,16 +1,14 @@ package com.Acrobot.ChestShop.Listeners.Player; -import com.Acrobot.Breeze.Utils.NameUtil; -import com.Acrobot.ChestShop.ChestShop; -import com.Acrobot.ChestShop.UUIDs.NameManager; -import com.Acrobot.ChestShop.UUIDs.PlayerDTO; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import java.util.UUID; +import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.UUIDs.NameManager; +import com.Acrobot.ChestShop.UUIDs.PlayerDTO; /** * @author Acrobot @@ -24,8 +22,8 @@ public class PlayerConnect implements Listener { Bukkit.getScheduler().runTaskAsynchronously(ChestShop.getPlugin(), new Runnable() { @Override public void run() { - String playerName = NameUtil.stripUsername(playerDTO.getName()); - UUID uuid = NameManager.getUUID(playerName); + // String playerName = NameUtil.stripUsername(playerDTO.getName()); + // UUID uuid = NameManager.getUUID(playerName); NameManager.storeUsername(playerDTO); } 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 ce657c1..00c7c04 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java @@ -118,8 +118,11 @@ public class PlayerInteract implements Listener { String material = sign.getLine(ITEM_LINE); String ownerName = NameManager.getFullUsername(name); - UUID uuid = NameManager.getUUID(ownerName); + if (ownerName == null || ownerName.isEmpty()) { + return null; + } + UUID uuid = NameManager.getUUID(ownerName); if (uuid == null) { return null; } 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 cfd792d..f480fef 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java @@ -32,6 +32,10 @@ public class ShopRefundListener implements Listener { } String ownerName = NameManager.getFullUsername(event.getSign().getLine(NAME_LINE)); + if (ownerName.isEmpty()) { + return; + } + UUID owner = NameManager.getUUID(ownerName); CurrencyAddEvent currencyEvent = new CurrencyAddEvent(BigDecimal.valueOf(refundPrice), owner, event.getSign().getWorld()); diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index bd0dedd..a2bf230 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -9,6 +9,8 @@ import com.Acrobot.ChestShop.Signs.ChestShopSign; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.j256.ormlite.dao.Dao; + +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -72,6 +74,8 @@ public class NameManager { } public static UUID getUUID(String username) { + Validate.notEmpty(username, "user cannot be null or empty!"); + if (usernameToUUID.containsKey(username)) { return usernameToUUID.get(username); } @@ -241,7 +245,7 @@ public class NameManager { return false; } - return shortenedName.equals(name) || Permission.otherName(player, name) || player.getUniqueId().equals(getUUID(name)); + return shortenedName.equals(name) || Permission.otherName(player, name) || (!name.isEmpty() && player.getUniqueId().equals(getUUID(name))); } public static boolean isAdminShop(UUID uuid) { From 24df17fde2c1d82349fd53b5d2748a5ed43d1d19 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Thu, 22 Sep 2016 11:57:49 -0400 Subject: [PATCH 16/21] Restore compatibility with 1.8 Fixes #9 --- .../Acrobot/Breeze/Utils/InventoryUtil.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java b/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java index 4379a3f..7dd43ae 100644 --- a/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java +++ b/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java @@ -12,6 +12,21 @@ import org.bukkit.inventory.ItemStack; * @author Acrobot */ public class InventoryUtil { + private static Boolean legacyContents = null; + + private static ItemStack[] getStorageContents(Inventory inventory) { + if (legacyContents == null) { + try { + inventory.getStorageContents(); + legacyContents = false; + } catch (NoSuchMethodError e) { + legacyContents = true; + } + } + + return legacyContents ? inventory.getContents() : inventory.getStorageContents(); + } + /** * Returns the amount of the item inside the inventory * @@ -49,7 +64,7 @@ public class InventoryUtil { * @return Is the inventory empty? */ public static boolean isEmpty(Inventory inventory) { - for (ItemStack stack : inventory.getStorageContents()) { + for (ItemStack stack : getStorageContents(inventory)) { if (!MaterialUtil.isEmpty(stack)) { return false; } @@ -89,7 +104,7 @@ public class InventoryUtil { return true; } - for (ItemStack iStack : inventory.getStorageContents()) { + for (ItemStack iStack : getStorageContents(inventory)) { if (left <= 0) { return true; } @@ -155,7 +170,7 @@ public class InventoryUtil { // Don't use the armor slots or extra slots private static int effectiveSize(Inventory inventory) { - return inventory.getStorageContents().length; + return getStorageContents(inventory).length; } /** From 24eb1b1e1970e0222021cfd4a94c7865d5f53232 Mon Sep 17 00:00:00 2001 From: L4BORG Date: Thu, 13 Oct 2016 18:11:23 +0200 Subject: [PATCH 17/21] 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 18/21] 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; From 93c978ce027a7fb6e2790a74a38bd3cc199b4378 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Mon, 21 Nov 2016 11:42:17 -0500 Subject: [PATCH 19/21] Update to 1.11 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 05eec6b..c33e41c 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ org.spigotmc spigot-api - 1.10.2-R0.1-SNAPSHOT + 1.11-R0.1-SNAPSHOT provided From fa7a196babb5c44df3b0078abf98e49ced93ba31 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Mon, 21 Nov 2016 11:43:09 -0500 Subject: [PATCH 20/21] Fix static access --- .../Economy/Plugins/VaultListener.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 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 2a3832a..196ebad 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 @@ -1,10 +1,12 @@ package com.Acrobot.ChestShop.Listeners.Economy.Plugins; -import com.Acrobot.ChestShop.ChestShop; -import com.Acrobot.ChestShop.Events.Economy.*; -import com.Acrobot.ChestShop.UUIDs.NameManager; +import java.math.BigDecimal; + +import javax.annotation.Nullable; + import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.World; @@ -12,8 +14,15 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.plugin.RegisteredServiceProvider; -import javax.annotation.Nullable; -import java.math.BigDecimal; +import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Events.Economy.AccountCheckEvent; +import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent; +import com.Acrobot.ChestShop.Events.Economy.CurrencyAmountEvent; +import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent; +import com.Acrobot.ChestShop.Events.Economy.CurrencyFormatEvent; +import com.Acrobot.ChestShop.Events.Economy.CurrencyHoldEvent; +import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent; +import com.Acrobot.ChestShop.Events.Economy.CurrencyTransferEvent; /** * Represents a Vault connector @@ -23,7 +32,7 @@ import java.math.BigDecimal; public class VaultListener implements Listener { private static Economy provider; - private VaultListener(Economy provider) { this.provider = provider; } + private VaultListener(Economy provider) { VaultListener.provider = provider; } public static Economy getProvider() { return provider; } From fc3c134c2aa2762f1b3ede86cf7fa8ad7964abb4 Mon Sep 17 00:00:00 2001 From: Eredrim Date: Sat, 7 Jan 2017 23:14:27 +0100 Subject: [PATCH 21/21] Update residence comptibility --- pom.xml | 7 +++---- .../Plugins/ResidenceChestProtection.java | 14 +++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index c33e41c..64344ac 100644 --- a/pom.xml +++ b/pom.xml @@ -237,11 +237,10 @@ - - net.t00thpick1 - residence - 3.0.0q-SNAPSHOT + com.bekvon.bukkit.residence + Residence + 4.5.3.0 provided diff --git a/src/main/java/com/Acrobot/ChestShop/Plugins/ResidenceChestProtection.java b/src/main/java/com/Acrobot/ChestShop/Plugins/ResidenceChestProtection.java index 183ac15..5abcceb 100644 --- a/src/main/java/com/Acrobot/ChestShop/Plugins/ResidenceChestProtection.java +++ b/src/main/java/com/Acrobot/ChestShop/Plugins/ResidenceChestProtection.java @@ -1,10 +1,10 @@ package com.Acrobot.ChestShop.Plugins; import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent; -import net.t00thpick1.residence.Residence; -import net.t00thpick1.residence.api.ResidenceAPI; -import net.t00thpick1.residence.api.areas.ResidenceArea; -import net.t00thpick1.residence.api.flags.FlagManager; +import com.bekvon.bukkit.residence.Residence; +import com.bekvon.bukkit.residence.api.ResidenceApi; +import com.bekvon.bukkit.residence.containers.Flags; +import com.bekvon.bukkit.residence.protection.ClaimedResidence; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -25,10 +25,10 @@ public class ResidenceChestProtection implements Listener { Block block = event.getBlock(); Player player = event.getPlayer(); - ResidenceArea area = ResidenceAPI.getResidenceManager().getByLocation(block.getLocation()); + ClaimedResidence residence = ResidenceApi.getResidenceManager().getByLoc(block.getLocation()); - if (area != null) { - if (!area.allowAction(player.getName(), FlagManager.CONTAINER) && !Residence.getInstance().isAdminMode(player)) { + if (residence != null) { + if (!residence.getPermissions().playerHas(player, Flags.container, true) && !Residence.isResAdminOn(player)) { //Doesn't have permissions to that chest. event.setResult(Event.Result.DENY); }