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) diff --git a/pom.xml b/pom.xml index d1f0d63..675c3ab 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 @@ -69,9 +65,9 @@ - org.bukkit - bukkit - 1.8.8-R0.1-SNAPSHOT + org.spigotmc + spigot-api + 1.11-R0.1-SNAPSHOT provided @@ -95,7 +91,7 @@ net.milkbowl.vault Vault - 1.5.2 + 1.6.6 provided @@ -130,16 +126,12 @@ com.herocraftonline.heroes Heroes - 1.5.5.6-SNAPSHOT + 1.5.5 provided - org.bukkit - bukkit - - - org.bukkit - craftbukkit + * + * @@ -241,11 +233,10 @@ - - net.t00thpick1 - residence - 3.0.0q-SNAPSHOT + com.bekvon.bukkit.residence + Residence + 4.5.3.0 provided @@ -274,8 +265,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/Breeze/Utils/InventoryUtil.java b/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java index 2987f59..7dd43ae 100644 --- a/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java +++ b/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java @@ -1,17 +1,32 @@ 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 */ 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.getContents()) { + for (ItemStack stack : getStorageContents(inventory)) { if (!MaterialUtil.isEmpty(stack)) { return false; } @@ -89,7 +104,7 @@ public class InventoryUtil { return true; } - for (ItemStack iStack : inventory.getContents()) { + for (ItemStack iStack : getStorageContents(inventory)) { if (left <= 0) { return true; } @@ -125,7 +140,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 +167,12 @@ public class InventoryUtil { return amountLeft; } + // Don't use the armor slots or extra slots + private static int effectiveSize(Inventory inventory) + { + return getStorageContents(inventory).length; + } + /** * Adds an item to the inventor * diff --git a/src/main/java/com/Acrobot/ChestShop/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/ChestShop.java index 3c060c9..fc2b94b 100644 --- a/src/main/java/com/Acrobot/ChestShop/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/ChestShop.java @@ -38,11 +38,21 @@ 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; 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; @@ -81,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(); @@ -114,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); @@ -212,8 +263,9 @@ public class ChestShop extends JavaPlugin { registerEvent(new ItemInfoListener()); registerEvent(new GarbageTextListener()); - - if (this.getServer().getPluginManager().getPlugin("AuthMe") != null && this.getServer().getPluginManager().getPlugin("AuthMe").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 03cfc2a..0e71e55 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java @@ -137,4 +137,4 @@ public class Properties { @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/Containers/AdminInventory.java b/src/main/java/com/Acrobot/ChestShop/Containers/AdminInventory.java index d01bcfe..124c34c 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,56 @@ public class AdminInventory implements Inventory { }; } + @Override 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; } + @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 +120,7 @@ public class AdminInventory implements Inventory { return items; } + @Override public HashMap all(Material material) { if (material.getMaxDurability() != 0) { HashMap items = new HashMap(); @@ -105,6 +135,7 @@ public class AdminInventory implements Inventory { return all(material.getId()); } + @Override public HashMap all(ItemStack itemStack) { HashMap items = new HashMap(); @@ -116,58 +147,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 371840d..0bab71c 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java @@ -40,4 +40,4 @@ public class AuthMeChestShopListener implements Listener { event.setCancelled(TransactionOutcome.CLIENT_DOES_NOT_HAVE_PERMISSION); } -} +} \ No newline at end of file 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; 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..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,18 +1,28 @@ 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; 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 @@ -20,11 +30,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) { VaultListener.provider = provider; } + + public static Economy getProvider() { return provider; } public boolean transactionCanFail() { return provider.getName().equals("Gringotts") || provider.getName().equals("GoldIsMoney") || provider.getName().equals("MultiCurrency"); @@ -61,10 +71,16 @@ 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()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(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 +93,15 @@ public class VaultListener implements Listener { } World world = event.getWorld(); + //String lastSeen = NameManager.getLastSeenName(event.getAccount()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(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 +112,10 @@ public class VaultListener implements Listener { } World world = event.getWorld(); + //String lastSeen = NameManager.getLastSeenName(event.getAccount()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getAccount()); - if (!provider.hasAccount(NameManager.getLastSeenName(event.getAccount()), world.getName())) { - event.hasAccount(false); - } + event.hasAccount(lastSeen != null && provider.hasAccount(lastSeen, world.getName())); } @EventHandler @@ -103,7 +125,6 @@ public class VaultListener implements Listener { } String formatted = provider.format(event.getDoubleAmount()); - event.setFormattedAmount(formatted); } @@ -114,8 +135,12 @@ public class VaultListener implements Listener { } World world = event.getWorld(); + //String lastSeen = NameManager.getLastSeenName(event.getTarget()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(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 +150,12 @@ public class VaultListener implements Listener { } World world = event.getWorld(); + //String lastSeen = NameManager.getLastSeenName(event.getTarget()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(event.getTarget()); - provider.withdrawPlayer(NameManager.getLastSeenName(event.getTarget()), world.getName(), event.getDoubleAmount()); + if (lastSeen != null) { + provider.withdrawPlayer(lastSeen, world.getName(), event.getDoubleAmount()); + } } @EventHandler @@ -152,18 +181,27 @@ public class VaultListener implements Listener { return; } - if (!provider.hasAccount(NameManager.getLastSeenName(event.getAccount()), event.getWorld().getName())) { + //String lastSeen = NameManager.getLastSeenName(event.getAccount()); + OfflinePlayer lastSeen = Bukkit.getOfflinePlayer(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/Listeners/Player/PlayerConnect.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java index 56233f1..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,20 +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); - - 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."); - - } - }); - } + // 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..eb36854 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,14 +113,19 @@ public class PlayerInteract implements Listener { String material = sign.getLine(ITEM_LINE); String ownerName = NameManager.getFullUsername(name); - UUID uuid = NameManager.getUUID(ownerName); - - if (uuid == null) { + if (ownerName == null || ownerName.isEmpty()) + return null; + + UUID uuid = NameManager.getUUID(ownerName); + if (uuid == null) return null; - } OfflinePlayer owner = Bukkit.getOfflinePlayer(uuid); + // check if player exists in economy + 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; double price = (action == buy ? PriceUtil.getBuyPrice(prices) : PriceUtil.getSellPrice(prices)); @@ -133,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/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/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/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); } 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) { diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index ce6eabd..cb9663b 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -9,20 +9,24 @@ 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; 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 +39,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,25 +50,32 @@ 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) { + Validate.notEmpty(username, "user cannot be null or empty!"); + if (usernameToUUID.containsKey(username)) { return usernameToUUID.get(username); } @@ -194,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()); } @@ -207,10 +219,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()); @@ -227,7 +246,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) { 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]