diff --git a/src/main/java/org/maxgamer/quickshop/Command/QS.java b/src/main/java/org/maxgamer/quickshop/Command/QS.java index fd47cd2d7..e48b53081 100644 --- a/src/main/java/org/maxgamer/quickshop/Command/QS.java +++ b/src/main/java/org/maxgamer/quickshop/Command/QS.java @@ -254,8 +254,7 @@ public class QS implements CommandExecutor { for (int i = 2; i < args.length; i++) { sb.append(" " + args[i]); } - String lookFor = sb.toString(); - lookFor = lookFor.toLowerCase(); + String lookFor = sb.toString().toLowerCase(); Player p = (Player) sender; Location loc = p.getEyeLocation().clone(); double minDistance = plugin.getConfig().getInt("shop.find-distance"); @@ -270,11 +269,13 @@ public class QS implements CommandExecutor { if (inChunk == null) continue; for (Shop shop : inChunk.values()) { - if (MsgUtil.getItemi18n(shop.getDataName()).toLowerCase().contains(lookFor) - && shop.getLocation().distanceSquared(loc) < minDistanceSquared) { - closest = shop; - minDistanceSquared = shop.getLocation().distanceSquared(loc); - } + if (!Util.getItemStackName(shop.getItem()).toLowerCase().contains(lookFor)) + continue; + + if (!(shop.getLocation().distanceSquared(loc) < minDistanceSquared)) + continue; + closest = shop; + minDistanceSquared = shop.getLocation().distanceSquared(loc); } } } @@ -343,8 +344,7 @@ public class QS implements CommandExecutor { b.getRelative(p.getFacing().getOppositeFace())); plugin.getShopManager().getActions().put(p.getUniqueId(), info); p.sendMessage( - MsgUtil.getMessage("how-much-to-trade-for", MsgUtil - .getItemi18n(info.getItem().getType().name()))); + MsgUtil.getMessage("how-much-to-trade-for", Util.getItemStackName(item))); } else { plugin.getShopManager().handleChat(p, args[1]); } @@ -392,7 +392,7 @@ public class QS implements CommandExecutor { shop.update(); MsgUtil.sendControlPanelInfo(sender, shop); sender.sendMessage(MsgUtil - .getMessage("command.now-buying", MsgUtil.getItemi18n(shop.getItem().getType().name()))); + .getMessage("command.now-buying", Util.getItemStackName(shop.getItem()))); return; } } @@ -411,7 +411,7 @@ public class QS implements CommandExecutor { //shop.setSignText(); shop.update(); sender.sendMessage(MsgUtil - .getMessage("command.now-buying", MsgUtil.getItemi18n(shop.getItem().getType().name()))); + .getMessage("command.now-buying", Util.getItemStackName(shop.getItem()))); return; } } @@ -432,7 +432,7 @@ public class QS implements CommandExecutor { shop.update(); MsgUtil.sendControlPanelInfo(sender, shop); sender.sendMessage(MsgUtil - .getMessage("command.now-selling", MsgUtil.getItemi18n(shop.getItem().getType().name()))); + .getMessage("command.now-selling", Util.getItemStackName(shop.getItem()))); return; } @@ -452,7 +452,7 @@ public class QS implements CommandExecutor { //shop.setSignText(); shop.update(); sender.sendMessage(MsgUtil - .getMessage("command.now-selling", MsgUtil.getItemi18n(shop.getItem().getType().name()))); + .getMessage("command.now-selling", Util.getItemStackName(shop.getItem()))); return; } } diff --git a/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java index c83ed1490..7067b5954 100644 --- a/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java +++ b/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java @@ -156,7 +156,7 @@ public class PlayerListener implements Listener { Info info = new Info(b.getLocation(), ShopAction.CREATE, e.getItem(), last); plugin.getShopManager().getActions().put(p.getUniqueId(), info); p.sendMessage( - MsgUtil.getMessage("how-much-to-trade-for", MsgUtil.getItemi18n(info.getItem().getType().name()))); + MsgUtil.getMessage("how-much-to-trade-for", Util.getItemStackName(shop.getItem()))); } } else if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && Util.isWallSign(e.getClickedBlock().getType())) { diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index cba41685e..3639e1583 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -58,6 +58,7 @@ public class QuickShop extends JavaPlugin { private LogWatcher logWatcher; private ItemMatcher itemMatcher; private DisplayBugFixListener displayBugFixListener; + private LockListener lockListener; // /** Whether players are required to sneak to create/buy from a shop */ // public boolean sneak; // /** Whether players are required to sneak to create a shop */ @@ -190,8 +191,10 @@ public class QuickShop extends JavaPlugin { Timer enableTimer = new Timer(true); /* PreInit for BootError feature */ commandExecutor = new QS(this); + //noinspection ConstantConditions getCommand("qs").setExecutor(commandExecutor); commandTabCompleter = new Tab(this); + //noinspection ConstantConditions getCommand("qs").setTabCompleter(commandTabCompleter); getLogger().info("Quickshop Reremake"); @@ -220,6 +223,9 @@ public class QuickShop extends JavaPlugin { /* Process Metrics and Sentry error reporter. */ metrics = new Metrics(this); + + /* It will generate a new UUID above updateConfig */ + //noinspection ConstantConditions serverUniqueID = UUID.fromString(getConfig().getString("server-uuid")); sentryErrorReporter = new SentryErrorReporter(this); @@ -236,36 +242,21 @@ public class QuickShop extends JavaPlugin { itemMatcher = new ItemMatcher(this); Util.initialize(); - setupDBonEnableding = true; - setupDatabase(); //Load the database - setupDBonEnableding = false; - MsgUtil.loadItemi18n(); MsgUtil.loadEnchi18n(); MsgUtil.loadPotioni18n(); + setupDBonEnableding = true; + setupDatabase(); //Load the database + setupDBonEnableding = false; + /* Initalize the tools */ // Create the shop manager. this.shopManager = new ShopManager(this); this.databaseManager = new DatabaseManager(this, database); this.permissionChecker = new PermissionChecker(this); - //if (this.display) { - // Display item handler thread - // getLogger().info("Starting item scheduler"); - // ShopVaildWatcher itemWatcher = new ShopVaildWatcher(this); - // shopVaildWatchTask = Bukkit.getScheduler().runTaskTimer(this, itemWatcher, 600, 600); - //} - if (this.getConfig().getBoolean("log-actions")) { - // Logger Handler - this.logWatcher = new LogWatcher(this, new File(this.getDataFolder(), "qs.log")); - logWatcher.task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, this.logWatcher, 150, 150); - } - if (getConfig().getBoolean("shop.lock")) { - LockListener ll = new LockListener(this); - getServer().getPluginManager().registerEvents(ll, this); - } - getServer().getPluginManager().registerEvents(new UpdateWatcher(), this); + ConfigurationSection limitCfg = this.getConfig().getConfigurationSection("limits"); if (limitCfg != null) { getLogger().info("Limit cfg found..."); @@ -280,17 +271,16 @@ public class QuickShop extends JavaPlugin { if (getConfig().getInt("shop.find-distance") > 100) { getLogger().severe("Shop.find-distance is too high! It may cause lag! Pick a number under 100!"); } - + /* Load all shops. */ shopLoader = new ShopLoader(this); shopLoader.loadShops(); + getLogger().info("Registering Listeners..."); + // Register events if (getConfig().getBoolean("shop.lock")) { LockListener lockListener = new LockListener(this); Bukkit.getServer().getPluginManager().registerEvents(lockListener, this); } - - getLogger().info("Registering Listeners"); - // Register events blockListener = new BlockListener(this); playerListener = new PlayerListener(this); worldListener = new WorldListener(this); diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index 9eab88f52..3b60be760 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -445,7 +445,7 @@ public class ContainerShop implements Shop { // This should not happen. if (amount > 0) { plugin.getLogger().log(Level.WARNING, "Could not take all items from a players inventory on purchase! " + p - .getName() + ", missing: " + amount + ", item: " + this.getDataName() + "!"); + .getName() + ", missing: " + amount + ", item: " + Util.getItemStackName(this.getItem()) + "!"); } } else { ItemStack[] playerContents = p.getInventory().getContents(); @@ -628,16 +628,6 @@ public class ContainerShop implements Shop { return this.getLocation().getBlock().equals(Util.getAttached(b)); } - /** - * Convenience method. Equivilant to - * org.maxgamer.quickshop.Util.getName(shop.getItem()). - * - * @return The name of this shops item - */ - public String getDataName() { - return Util.getName(this.getItem()); - } - /** * Deletes the shop from the list of shops and queues it for database */ diff --git a/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java index dfd88de5a..0c303a561 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java @@ -107,7 +107,8 @@ public class RealDisplayItem implements DisplayItem { continue; Item eItem = (Item) entity; if (!DisplayItem.checkIsGuardItemStack(eItem.getItemStack())) { - Util.debugLog(Util.getName(eItem.getItemStack()) + " not a shop displayItem: Failed check guardedItemStack"); + Util.debugLog(Util + .getItemStackName(eItem.getItemStack()) + " not a shop displayItem: Failed check guardedItemStack"); continue; } if (!eItem.getUniqueId().equals(this.item.getUniqueId())) { @@ -117,7 +118,8 @@ public class RealDisplayItem implements DisplayItem { entity.remove(); removed = true; } else { - Util.debugLog(Util.getName(eItem.getItemStack()) + " not a shop displayItem: Failed check shop display."); + Util.debugLog(Util + .getItemStackName(eItem.getItemStack()) + " not a shop displayItem: Failed check shop display."); } } } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/Shop.java b/src/main/java/org/maxgamer/quickshop/Shop/Shop.java index c2aa94009..1cc395e70 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/Shop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/Shop.java @@ -178,13 +178,6 @@ public abstract interface Shop { */ public abstract boolean isAttached(Block paramBlock); - /** - * Get item will show on the sign - * - * @return The text will show on the sign - */ - public abstract String getDataName(); - /** * Delete shop from ram, and database. */ diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index b80018591..be0e35cd9 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -404,14 +404,13 @@ public class ShopManager { space = 10000; if (space < amount) { p.sendMessage(MsgUtil - .getMessage("shop-has-no-space", "" + space, MsgUtil.getItemi18n(shop.getItem().getType().name()))); + .getMessage("shop-has-no-space", "" + space, Util.getItemStackName(shop.getItem()))); return; } int count = Util.countItems(p.getInventory(), shop.getItem()); // Not enough items if (amount > count) { - p.sendMessage(MsgUtil.getMessage("you-dont-have-that-many-items", "" + count, MsgUtil - .getItemi18n(shop.getItem().getType().name()))); + p.sendMessage(MsgUtil.getMessage("you-dont-have-that-many-items", "" + count, Util.getItemStackName(shop.getItem()))); return; } if (amount == 0) { @@ -462,8 +461,8 @@ public class ShopManager { // Give them the money after we know we succeeded plugin.getEcon().deposit(p.getUniqueId(), total * (1 - tax)); // Notify the owner of the purchase. - String msg = MsgUtil.getMessage("player-sold-to-your-store", p.getName(), "" + amount, MsgUtil - .getItemi18n(shop.getItem().getType().name())); + String msg = MsgUtil.getMessage("player-sold-to-your-store", p.getName(), "" + amount, Util + .getItemStackName(shop.getItem())); if (space == amount) msg += "\n" + MsgUtil.getMessage("shop-out-of-space", "" + shop.getLocation().getBlockX(), "" + shop.getLocation() .getBlockY(), "" + shop.getLocation().getBlockZ()); @@ -493,8 +492,8 @@ public class ShopManager { if (stock == -1) stock = 10000; if (stock < amount) { - p.sendMessage(MsgUtil.getMessage("shop-stock-too-low", "" + shop.getRemainingStock(), MsgUtil - .getItemi18n(shop.getItem().getType().name()))); + p.sendMessage(MsgUtil + .getMessage("shop-stock-too-low", "" + shop.getRemainingStock(), Util.getItemStackName(shop.getItem()))); return; } if (amount == 0) { @@ -548,20 +547,20 @@ public class ShopManager { } // Notify the shop owner if (plugin.getConfig().getBoolean("show-tax")) { - String msg = MsgUtil.getMessage("player-bought-from-your-store-tax", p.getName(), "" + amount, MsgUtil - .getItemi18n(shop.getItem().getType().name()), Util.format((tax * total))); + String msg = MsgUtil.getMessage("player-bought-from-your-store-tax", p.getName(), "" + amount, Util + .getItemStackName(shop.getItem()), Util.format((tax * total))); if (stock == amount) msg += "\n" + MsgUtil.getMessage("shop-out-of-stock", "" + shop.getLocation().getBlockX(), "" + shop - .getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), MsgUtil - .getItemi18n(shop.getItem().getType().name())); + .getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), Util + .getItemStackName(shop.getItem())); MsgUtil.send(shop.getOwner(), msg, shop.isUnlimited()); } else { - String msg = MsgUtil.getMessage("player-bought-from-your-store", p.getName(), "" + amount, MsgUtil - .getItemi18n(shop.getItem().getType().name())); + String msg = MsgUtil.getMessage("player-bought-from-your-store", p.getName(), "" + amount, Util + .getItemStackName(shop.getItem())); if (stock == amount) msg += "\n" + MsgUtil.getMessage("shop-out-of-stock", "" + shop.getLocation().getBlockX(), "" + shop - .getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), MsgUtil - .getItemi18n(shop.getItem().getType().name())); + .getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), Util + .getItemStackName(shop.getItem())); MsgUtil.send(shop.getOwner(), msg, shop.isUnlimited()); } // Transfers the item from A to B diff --git a/src/main/java/org/maxgamer/quickshop/Util/IncompatibleChecker.java b/src/main/java/org/maxgamer/quickshop/Util/IncompatibleChecker.java index aba65ff4e..b3ad7d05c 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/IncompatibleChecker.java +++ b/src/main/java/org/maxgamer/quickshop/Util/IncompatibleChecker.java @@ -6,6 +6,7 @@ public class IncompatibleChecker { private final ArrayList incompatibleVersionList = new ArrayList<>(); public IncompatibleChecker() { + incompatibleVersionList.clear(); mc1_5(); mc1_6(); mc1_7(); diff --git a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java index eab3fafc5..223e1df91 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java @@ -26,7 +26,6 @@ import org.bukkit.entity.Tameable; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.*; import org.maxgamer.quickshop.QuickShop; @@ -653,7 +652,7 @@ public class MsgUtil { //Enabled sendItemholochat(shop, shop.getItem(), p, ChatColor.DARK_PURPLE + MsgUtil .getMessage("tableformat.left_begin") + " " + MsgUtil - .getMessage("menu.item", MsgUtil.getDisplayName(shop.getItem()))); + .getMessage("menu.item", Util.getItemStackName(shop.getItem()))); if (Util.isTool(items.getType())) { chatSheetPrinter.printLine(MsgUtil.getMessage("menu.damage-percent-remaining", Util.getToolPercentage(items))); } @@ -671,7 +670,7 @@ public class MsgUtil { } } chatSheetPrinter.printLine(MsgUtil - .getMessage("menu.price-per", MsgUtil.getDisplayName(shop.getItem()), Util.format(shop.getPrice()))); + .getMessage("menu.price-per", Util.getItemStackName(shop.getItem()), Util.format(shop.getPrice()))); if (shop.isBuying()) { chatSheetPrinter.printLine(MsgUtil.getMessage("menu.this-shop-is-buying")); } else { @@ -714,7 +713,7 @@ public class MsgUtil { chatSheetPrinter.printHeader(); chatSheetPrinter.printLine(MsgUtil.getMessage("menu.successful-purchase")); chatSheetPrinter.printLine(MsgUtil - .getMessage("menu.item-name-and-price", "" + amount, MsgUtil.getDisplayName(shop.getItem()), Util + .getMessage("menu.item-name-and-price", "" + amount, Util.getItemStackName(shop.getItem()), Util .format((amount * shop.getPrice())))); Map enchs = new HashMap<>(); if (shop.getItem().hasItemMeta() && shop.getItem().getItemMeta().hasEnchants()) @@ -751,7 +750,7 @@ public class MsgUtil { chatSheetPrinter.printHeader(); chatSheetPrinter.printLine(MsgUtil.getMessage("menu.successfully-sold")); chatSheetPrinter.printLine(MsgUtil - .getMessage("menu.item-name-and-price", "" + amount, MsgUtil.getDisplayName(shop.getItem()), Util + .getMessage("menu.item-name-and-price", "" + amount, Util.getItemStackName(shop.getItem()), Util .format((amount * shop.getPrice())))); if (plugin.getConfig().getBoolean("show-tax")) { double tax = plugin.getConfig().getDouble("tax"); @@ -787,21 +786,6 @@ public class MsgUtil { chatSheetPrinter.printFooter(); } - /** - * Get item's displayname. - * @param iStack stack - * @return itemDisplayName - */ - public static String getDisplayName(@NotNull ItemStack iStack) { - ItemStack is = iStack.clone(); - if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) { - return is.getItemMeta().getDisplayName(); - } else { - return MsgUtil.getItemi18n(is.getType().name()); - } - - } - /** * getMessage in messages.yml * @@ -904,91 +888,91 @@ public class MsgUtil { normalmessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, cBuilder.create())); player.spigot().sendMessage(normalmessage); } catch (Throwable t) { - sendItemholochatAsNormaly(itemStack, player, normalText); + t.printStackTrace(); } } - /** - * Send the ItemPreview chat msg by Bukkit API. - * More worst than NMS mode. - * *STILL WIP* - * - * @param itemStack Target ItemStack - * @param player Target player - * @param normalText The text you will see - */ - // Without NMS - private static void sendItemholochatAsNormaly(@NotNull ItemStack itemStack, @NotNull Player player, @NotNull String normalText) { - try { - String Itemname = null; - List Itemlore = new ArrayList<>(); - String finalItemdata = null; - Map enchs = new HashMap(); - Map Itemenchs = new HashMap(); - if (itemStack.hasItemMeta()) { - ItemMeta iMeta = itemStack.getItemMeta(); - if (iMeta.hasDisplayName()) { - Itemname = iMeta.getDisplayName(); - } else { - Itemname = MsgUtil.getItemi18n(itemStack.getType().name()); - } - if (iMeta.hasLore()) { - Itemlore = iMeta.getLore(); - } else { - Itemlore = new ArrayList(); - } - if (iMeta.hasEnchants()) { - enchs = iMeta.getEnchants(); - for (Entry entries : enchs.entrySet()) { - String i18n = MsgUtil.getEnchi18n(entries.getKey()); - if (i18n != null) { - Itemenchs.put(i18n, entries.getValue()); - } else { - Itemenchs = null; - } - } - } - } else { - Itemname = MsgUtil.getDisplayName(itemStack); - Itemlore = null; - Itemenchs = null; - } - if (Itemname != MsgUtil.getItemi18n(itemStack.getType().name())) { - finalItemdata = Itemname + " " + ChatColor.GRAY + "(" + MsgUtil.getItemi18n(itemStack.getType() - .name()) + ChatColor.GRAY + ")"; - } else { - finalItemdata = Itemname; - } - - finalItemdata += "\n"; - List a = new ArrayList<>(); - List b = new ArrayList<>(); - a.addAll(Itemenchs.keySet()); - b.addAll(Itemenchs.values()); - for (int i = 0; i < a.size(); i++) { - finalItemdata += ChatColor.GRAY + a.get(i) + " " + RomanNumber.toRoman(b.get(i)) + "\n"; - } - - String potionResult = Util.getPotiondata(itemStack); - if (potionResult != null) { - finalItemdata += potionResult; - } - - if (Itemlore != null) { - for (String string : Itemlore) { - finalItemdata += ChatColor.DARK_PURPLE + "" + ChatColor.ITALIC + string + "\n"; - } - } - TextComponent normalmessage = new TextComponent(normalText + " " + MsgUtil.getMessage("menu.preview")); - ComponentBuilder cBuilder = new ComponentBuilder(finalItemdata); - HoverEvent he = new HoverEvent(HoverEvent.Action.SHOW_TEXT, cBuilder.create()); - normalmessage.setHoverEvent(he); - player.spigot().sendMessage(normalmessage); - } catch (Exception e) { - player.sendMessage(normalText); - QuickShop.instance.getLogger() - .severe("QuickShop cannot send Advanced chat message, Are you using CraftBukkit? Please use Spigot or a Spigot fork."); - } - } + // /** + // * Send the ItemPreview chat msg by Bukkit API. + // * More worst than NMS mode. + // * *STILL WIP* + // * + // * @param itemStack Target ItemStack + // * @param player Target player + // * @param normalText The text you will see + // */ + // // Without NMS + // private static void sendItemholochatAsNormaly(@NotNull ItemStack itemStack, @NotNull Player player, @NotNull String normalText) { + // try { + // String Itemname = null; + // List Itemlore = new ArrayList<>(); + // String finalItemdata = null; + // Map enchs = new HashMap(); + // Map Itemenchs = new HashMap(); + // if (itemStack.hasItemMeta()) { + // ItemMeta iMeta = itemStack.getItemMeta(); + // if (iMeta.hasDisplayName()) { + // Itemname = iMeta.getDisplayName(); + // } else { + // Itemname = Util.getItemStackName(itemStack); + // } + // if (iMeta.hasLore()) { + // Itemlore = iMeta.getLore(); + // } else { + // Itemlore = new ArrayList(); + // } + // if (iMeta.hasEnchants()) { + // enchs = iMeta.getEnchants(); + // for (Entry entries : enchs.entrySet()) { + // String i18n = MsgUtil.getEnchi18n(entries.getKey()); + // if (i18n != null) { + // Itemenchs.put(i18n, entries.getValue()); + // } else { + // Itemenchs = null; + // } + // } + // } + // } else { + // Itemname =Util.getItemStackName(itemStack); + // Itemlore = null; + // Itemenchs = null; + // } + // if (Itemname != MsgUtil.getItemi18n(itemStack.getType().name())) { + // finalItemdata = Itemname + " " + ChatColor.GRAY + "(" + MsgUtil.getItemi18n(itemStack.getType() + // .name()) + ChatColor.GRAY + ")"; + // } else { + // finalItemdata = Itemname; + // } + // + // finalItemdata += "\n"; + // List a = new ArrayList<>(); + // List b = new ArrayList<>(); + // a.addAll(Itemenchs.keySet()); + // b.addAll(Itemenchs.values()); + // for (int i = 0; i < a.size(); i++) { + // finalItemdata += ChatColor.GRAY + a.get(i) + " " + RomanNumber.toRoman(b.get(i)) + "\n"; + // } + // + // String potionResult = Util.getPotiondata(itemStack); + // if (potionResult != null) { + // finalItemdata += potionResult; + // } + // + // if (Itemlore != null) { + // for (String string : Itemlore) { + // finalItemdata += ChatColor.DARK_PURPLE + "" + ChatColor.ITALIC + string + "\n"; + // } + // } + // TextComponent normalmessage = new TextComponent(normalText + " " + MsgUtil.getMessage("menu.preview")); + // ComponentBuilder cBuilder = new ComponentBuilder(finalItemdata); + // HoverEvent he = new HoverEvent(HoverEvent.Action.SHOW_TEXT, cBuilder.create()); + // normalmessage.setHoverEvent(he); + // player.spigot().sendMessage(normalmessage); + // } catch (Exception e) { + // player.sendMessage(normalText); + // QuickShop.instance.getLogger() + // .severe("QuickShop cannot send Advanced chat message, Are you using CraftBukkit? Please use Spigot or a Spigot fork."); + // } + // } } diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 49d54abd5..c15a37996 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -10,7 +10,6 @@ import java.util.Map.Entry; import com.google.common.io.Files; import lombok.*; -import org.apache.commons.lang.StringUtils; import org.bukkit.*; import org.bukkit.block.*; import org.bukkit.block.data.Directional; @@ -37,7 +36,7 @@ import org.maxgamer.quickshop.Shop.Shop; public class Util { private static EnumSet blacklist = EnumSet.noneOf(Material.class); private static EnumSet shoppables = EnumSet.noneOf(Material.class); - private static EnumMap> restrictedPrices = new EnumMap>(Material.class); + private static EnumMap> restrictedPrices = new EnumMap<>(Material.class); private static List worldBlacklist = new ArrayList<>(); @Getter private static List debugLogs = new ArrayList<>(); private static QuickShop plugin; @@ -88,7 +87,7 @@ public class Util { .warning("Material " + sp[0] + " in config.yml can't match with a valid Materials, check your config.yml!"); continue; } - restrictedPrices.put(mat, new SimpleEntry(Double.valueOf(sp[1]), Double.valueOf(sp[2]))); + restrictedPrices.put(mat, new SimpleEntry<>(Double.valueOf(sp[1]), Double.valueOf(sp[2]))); } catch (Exception e) { plugin.getLogger().warning("Invalid price restricted material: " + s); } @@ -157,6 +156,8 @@ public class Util { Set keys = config.getKeys(true); for (String key : keys) { String filtered = config.getString(key); + if (filtered == null) + continue; if (filtered.startsWith("MemorySection")) { continue; } @@ -194,6 +195,7 @@ public class Util { } if (!isShoppables(b.getType())) return false; + //noinspection RedundantIfStatement if (isBlacklistWorld(b.getWorld())) return false; return true; @@ -291,27 +293,6 @@ public class Util { .getBlockZ()) && (b1.getWorld().getName().equals(b2.getWorld().getName())); } - /** - * Check two location is or not equals for the BlockPosition on 2D - * - * @param loc1 location 1 - * @param loc2 location 2 - * @return Equals or not. - */ - public static boolean location3DEqual(@NotNull Location loc1, @NotNull Location loc2) { - if (loc1.equals(loc2)) - return true; - if (!loc1.getWorld().getName().equals(loc2.getWorld().getName())) - return false; - if (loc1.getBlockX() != loc2.getBlockX()) - return false; - if (loc1.getBlockY() != loc2.getBlockY()) - return false; - if (loc1.getBlockZ() != loc2.getBlockZ()) - return false; - return true; - } - /** * Checks whether someone else's shop is within reach of a hopper being placed by a player. * @@ -368,21 +349,6 @@ public class Util { return cfg.getItemStack("item"); } - /** - * Fetches an ItemStack's name - For example, converting INK_SAC:11 to - * Dandellion Yellow, or WOOL:14 to Red Wool - * - * @param itemStack The itemstack to fetch the name of - * @return The human readable item name. - */ - public static String getName(@NotNull ItemStack itemStack) { -// if (NMS.isPotion(itemStack.getType())) { -// return CustomPotionsName.getFullName(itemStack); -// } - String vanillaName = itemStack.getType().name(); - return prettifyText(vanillaName); - } - /** * Converts a name like IRON_INGOT into Iron Ingot to improve readability * @@ -394,20 +360,13 @@ public class Util { if (nameParts.length == 1) { return firstUppercase(ugly); } - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < nameParts.length; i++) { sb.append(firstUppercase(nameParts[i])); if (i + 1 != nameParts.length) sb.append(" "); } - - // for (String part : nameParts) { - // sb.append(firstUppercase(part) + " "); - // } - return sb.toString(); } @@ -426,47 +385,6 @@ public class Util { return itemMeta.getLocalizedName(); } - /** - * Get item's sign name for display on the sign. - * - * @param itemStack target itemStack - * @return String ItemOnSignName - */ - // Let's make very long names shorter for our sign - public static String getNameForSign(@NotNull ItemStack itemStack) { -// if (NMS.isPotion(itemStack.getType())) { -// return CustomPotionsName.getSignName(itemStack); -// } - ItemStack is = itemStack.clone(); - is.setAmount(1); - - if (is.hasItemMeta()) { - if (is.getItemMeta().hasDisplayName()) { - return is.getItemMeta().getDisplayName(); - } - } - - String name = MsgUtil.getItemi18n(itemStack.getType().name()).trim(); - - String[] nameParts = name.split("_"); - if (nameParts.length == 1) { - return firstUppercase(nameParts[0]); - } - - for (int i = 0; i < nameParts.length - 1; i++) { - int length = StringUtils.join(nameParts).length(); - if (length > 16) { - nameParts[i] = nameParts[i].substring(0, 1) + "."; - } else { - nameParts[i] = firstUppercase(nameParts[i]); - } - } - - nameParts[nameParts.length - 1] = firstUppercase(nameParts[nameParts.length - 1]); - - return StringUtils.join(nameParts); - } - /** * First uppercase for every words the first char for a text. * @@ -490,24 +408,6 @@ public class Util { return !(mat.getMaxDurability() == 0); } - // /** - // * Sort the HashMap - // * @param map map - // * @return Sorted HashMap - // */ - // public static Map sortHashMap(Map map) { - // List> list = new ArrayList>(map.entrySet()); - // Collections.sort(list, new Comparator>() { - // - // public int compare(Entry o1, - // Entry o2) { - // return o1.getValue().compareTo(o2.getValue()); - // } - // - // }); - // return map; - // } - /** * Formats the given number according to how vault would like it. E.g. $50 or 5 * dollars. @@ -530,7 +430,6 @@ public class Util { Util.debugLog("format", e.getMessage()); Util.debugLog("format", "Use alternate-currency-symbol to formatting, Cause NumberFormatException"); return plugin.getConfig().getString("shop.alternate-currency-symbol") + n; - // return "$" + n; } } @@ -618,16 +517,6 @@ public class Util { * @return is or not a wall_sign */ public static boolean isWallSign(@NotNull Material material) { - - // try { - // if (Tag.WALL_SIGNS.isTagged(material)) - // return true; - // } catch (Throwable e) { - // if (material.name().endsWith("WALL_SIGN") || material.name().equals("WALL_SIGN")) - // return true; - // } - //if (material.name().endsWith("WALL_SIGN") || material.name().equals("WALL_SIGN")) - // return true; return Tag.WALL_SIGNS.isTagged(material); } @@ -696,33 +585,6 @@ public class Util { } } - //Use NMS - - - // /** - // * Format ench level. - // * - // * @param level level - // * @return formated level - // */ - // private static String formatEnchLevel(@NotNull Integer level) { - // switch (level) { - // case 1: - // return "I"; - // case 2: - // return "II"; - // case 3: - // return "III"; - // case 4: - // return "IV"; - // case 5: - // return "V"; - // default: - // return String.valueOf(level); - // - // } - // } - /** * @param iStack itemstack * @return potion data, readable @@ -781,13 +643,13 @@ public class Util { */ public static boolean isDevEdition() { String version = QuickShop.instance.getDescription().getVersion().toLowerCase(); - if (version.contains("dev") || version.contains("develop") || version.contains("alpha") || version - .contains("beta") || version - .contains("test") || version.contains("snapshot") || version.contains("preview")) { - return true; - } else { - return false; - } + return (version.contains("dev") || + version.contains("develop") || + version.contains("alpha") || + version.contains("beta") || + version.contains("test") || + version.contains("snapshot") || + version.contains("preview")); } /** @@ -798,17 +660,28 @@ public class Util { if (inv == null) return; try { - for (int i = 0; i < inv.getSize(); i++) - if (DisplayItem.checkIsGuardItemStack(inv.getItem(i))) { + for (int i = 0; i < inv.getSize(); i++) { + ItemStack itemStack = inv.getItem(i); + if (itemStack == null) + continue; + if (DisplayItem.checkIsGuardItemStack(itemStack)) { // Found Item and remove it. inv.setItem(i, new ItemStack(Material.AIR, 0)); Util.debugLog("Found a displayitem in an inventory, it has been removed."); } + } } catch (Throwable t) { + //Ignore } } + public static String getItemStackName(@NotNull ItemStack itemStack) { + if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName()) + return itemStack.getItemMeta().getDisplayName(); + return MsgUtil.getItemi18n(itemStack.getType().name()); + } + private static Object serverInstance; private static Field tpsField;