diff --git a/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_Create.java b/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_Create.java index 858745302..c134d30ef 100644 --- a/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_Create.java +++ b/src/main/java/org/maxgamer/quickshop/Command/SubCommands/SubCommand_Create.java @@ -21,8 +21,6 @@ package org.maxgamer.quickshop.Command.SubCommands; import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang.BitField; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; diff --git a/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemSpawnEvent.java b/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemSpawnEvent.java index 93e9f2401..c5576bf79 100644 --- a/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemSpawnEvent.java +++ b/src/main/java/org/maxgamer/quickshop/Event/ShopDisplayItemSpawnEvent.java @@ -60,7 +60,7 @@ public class ShopDisplayItemSpawnEvent extends QSEvent implements Cancellable { */ @Deprecated public ShopDisplayItemSpawnEvent(@NotNull Shop shop, @NotNull ItemStack itemStack) { - this(shop, itemStack, DisplayItem.getNowUsing(itemStack)); + this(shop, itemStack, DisplayItem.getNowUsing()); } @Override diff --git a/src/main/java/org/maxgamer/quickshop/Listeners/DisplayBugFixListener.java b/src/main/java/org/maxgamer/quickshop/Listeners/DisplayBugFixListener.java index e305e4979..e93b63680 100644 --- a/src/main/java/org/maxgamer/quickshop/Listeners/DisplayBugFixListener.java +++ b/src/main/java/org/maxgamer/quickshop/Listeners/DisplayBugFixListener.java @@ -40,7 +40,7 @@ public class DisplayBugFixListener implements Listener { @EventHandler(ignoreCancelled = true) public void canBuild(BlockCanBuildEvent e) { if (!plugin.isDisplay() - || DisplayItem.getNowUsing(null) != DisplayType.ARMORSTAND + || DisplayItem.getNowUsing() != DisplayType.ARMORSTAND || e.isBuildable()) { return; } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index 4f2e599b9..74247649a 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -109,7 +109,7 @@ public class ContainerShop implements Shop { this.unlimited = unlimited; if (plugin.isDisplay()) { - switch (DisplayItem.getNowUsing(this.item)) { + switch (DisplayItem.getNowUsing()) { case UNKNOWN: Util.debugLog( "Failed to create a ContainerShop displayItem, the type is unknown, fallback to RealDisplayItem"); @@ -427,15 +427,6 @@ public class ContainerShop implements Shop { @Override public void checkDisplay() { - try { - // Workaround for error tracing when this is executed by tasks - checkDisplay0(); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - public void checkDisplay0() { if (!plugin.isDisplay() || !this.isLoaded) { // FIXME: Reinit scheduler on reloading config return; } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java index 2d8ca2faa..6473486b7 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java @@ -19,19 +19,10 @@ package org.maxgamer.quickshop.Shop; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -183,138 +174,7 @@ public interface DisplayItem { * * @return Using displayType. */ - static DisplayType getNowUsing(@Nullable ItemStack item) { - if (item != null) { - /* - * The below codes are massy like a shit (but not bad at function), need to cleanup - * - * Nest structure as: - * - 0: - * - small_: - * type: DEBUG_STICK - * lore: - * - mysterious item - * - gift - * strict: true - * - small2: - * type: - * - GLASS - * - GRASS - * - GRASS_BLOCK - * - 3: - * - small: - * type: BOW - * lore: common mark - */ - // type id such as 0, 1, 2, 3. - List typeSections = - QuickShop.instance.getConfig().getList("shop.display-type-specifics"); - for (Object typeSection : typeSections) { - // id as key - Util.debugLog(typeSection.toString() + " @ LEVEL 1, " + typeSection.getClass().getName()); - if (typeSection instanceof Map) { - Map itemSections = Map.class.cast(typeSection); - for (Entry itemSection : itemSections.entrySet()) { - // list - Util.debugLog(itemSection.toString() + " @ LEVEL 2, " + itemSection.getClass().getName()); - if (itemSection.getValue() instanceof List) { - List infoSections = List.class.cast(itemSection.getValue()); - for (Object $infoSection : infoSections) { - // custom name as key - Util.debugLog($infoSection.toString() + " @ LEVEL 3, " + $infoSection.getClass().getName()); - if ($infoSection instanceof Map) { - for (Object infoSectiont : Map.class.cast($infoSection).values()) { - Map infoSection = Map.class.cast(infoSectiont); - Util.debugLog(infoSection.toString() + " @ LEVEL 4, " + infoSection.getClass().getName()); - List type = Lists.newArrayList(); - boolean strictMeta = (boolean) infoSection.getOrDefault("strict-meta", false); - String name = ""; - List lore = Lists.newArrayList(); - int customModelData = -1; - - Object strOrListType = infoSection.getOrDefault("type", Lists.newArrayList()); - if (strOrListType instanceof List) { - for (Object s : (List) strOrListType) { - if (s instanceof String) { - type.add(Material.valueOf((String) s)); - } - } - } else { - type = Collections.singletonList(Material.valueOf((String) strOrListType)); - } - - name = (String) infoSection.getOrDefault("name", ""); - - Object strOrListLore = infoSection.getOrDefault("lore", Lists.newArrayList()); - if (strOrListLore instanceof List) { - for (Object s : (List) strOrListLore) { - if (s instanceof String) { - lore.add((String) s); - } - } - } else { - lore = Collections.singletonList((String) strOrListLore); - } - - customModelData = (int) infoSection.getOrDefault("custom-model-data", -1); - - boolean meta = !name.isEmpty() || !lore.isEmpty() || customModelData != -1; - if (type.isEmpty() || type.contains(item.getType())) { - if (meta) { - if (item.hasItemMeta()) { - ItemMeta itemMeta = item.getItemMeta(); - - if (!name.isEmpty()) { - if (!(itemMeta.hasDisplayName() && name.equals(itemMeta.getDisplayName()))) { - Util.debugLog("getNowUsing failed in name"); - return - DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")); - } - } - - if (!lore.isEmpty()) { - boolean loreCheck = strictMeta ? lore.equals(itemMeta.getLore()) : - lore.containsAll(itemMeta.getLore()); - if (!(itemMeta.hasLore() && loreCheck)) { - Util.debugLog("getNowUsing failed in lore"); - return - DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")); - } - } - - try { - if (customModelData != -1) { - if (!(itemMeta.hasCustomModelData() && - customModelData == itemMeta.getCustomModelData())) { - Util.debugLog("getNowUsing failed in CMD"); - return - DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")); - } - } - } catch (Exception e) { - ; - } - - Util.debugLog("getNowUsing passed thorough meta"); - return DisplayType.fromID((Integer) itemSection.getKey()); - } else { - ; - } - - } else { - Util.debugLog("getNowUsing passed without meta"); - return DisplayType.fromID((Integer) itemSection.getKey()); - } - } - } - } - } - } - } - } - } - } - + static DisplayType getNowUsing() { return DisplayType.fromID(QuickShop.instance.getConfig().getInt("shop.display-type")); } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayType.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayType.java index 5ae256b8a..b1fb5080a 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayType.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayType.java @@ -29,12 +29,10 @@ public enum DisplayType { * ARMORSTAND = USE ARMORSTAND DISPLAY * VIRTUALITEM = USE VIRTUAL DROPPED ITEM (CLIENT SIDE) * */ - UNKNOWN(-1), // same as 0 - + UNKNOWN(-1), REALITEM(0), ARMORSTAND(1), - - VIRTUALITEM(2); // not implement yet + VIRTUALITEM(2); private int id; diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index 9fb19af57..3372542bf 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -1111,7 +1111,7 @@ public class ShopManager { final String message = ChatColor.stripColor(msg); // Use from the main thread, because Bukkit hates life Bukkit.getScheduler() - .runTask( + .scheduleSyncDelayedTask( plugin, () -> { HashMap actions = getActions(); diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 517cfa472..b54f954a8 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -161,7 +161,7 @@ public class Util { return plugin.getOpenInvPlugin() != null; } - return bs instanceof InventoryHolder; + return bs instanceof BlockInventoryHolder; } /** @@ -243,19 +243,20 @@ public class Util { for (String log : logs) { String text = "[" - //+ ChatColor.DARK_GREEN - //+ ChatColor.BOLD - //+ "DEBUG" - //+ ChatColor.RESET - //+ "] [" + + ChatColor.DARK_GREEN + + ChatColor.BOLD + + "DEBUG" + + ChatColor.RESET + + "] [" + ChatColor.DARK_GREEN + className + ChatColor.RESET - + "] (" - /*+ " [" + + "]" + + " [" + ChatColor.DARK_GREEN + methodName - + ChatColor.RESET*/ + + ChatColor.RESET + + "] (" + ChatColor.DARK_GREEN + codeLine + ChatColor.RESET