From a590ecc3df30cf488fa131cb2e3adab3887bf145 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Mon, 17 Jun 2019 21:21:46 +0800 Subject: [PATCH] Fixed display many bugs Former-commit-id: 545ca9cae6131a76872ed6e6a1def932d460d95d [formerly d37aab54dec5b52a45819a24fe0632fbc84b9f7f] Former-commit-id: d083c6558cc2e133a134c301c4860603bd21ce72 --- .../quickshop/Database/DatabaseManager.java | 4 +-- .../quickshop/Shop/ContainerShop.java | 2 +- .../maxgamer/quickshop/Shop/DisplayItem.java | 30 ++++++++++++++----- .../quickshop/Shop/RealDisplayItem.java | 2 ++ .../quickshop/Shop/ShopProtectionFlag.java | 11 +++++++ 5 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 src/main/java/org/maxgamer/quickshop/Shop/ShopProtectionFlag.java diff --git a/src/main/java/org/maxgamer/quickshop/Database/DatabaseManager.java b/src/main/java/org/maxgamer/quickshop/Database/DatabaseManager.java index d97f20141..81cf52d08 100644 --- a/src/main/java/org/maxgamer/quickshop/Database/DatabaseManager.java +++ b/src/main/java/org/maxgamer/quickshop/Database/DatabaseManager.java @@ -80,9 +80,9 @@ public class DatabaseManager { sqle.printStackTrace(); } long tookTime = timer.endTimer(); - if (tookTime > 300) + if (tookTime > 1500) warningSender - .sendWarn("Database performance warning: It took to long time (" + tookTime + ") to execute the task, change to a better MySQL server or switch to a local SQLite database!"); + .sendWarn("Database performance warning: It took too long time (" + tookTime + "ms) to execute the task, change to a better MySQL server or switch to a local SQLite database!"); } } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index ae28fa114..ef974ed85 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -810,7 +810,7 @@ public class ContainerShop implements Shop { @Override public void checkDisplay() { Util.debugLog("Checking the display..."); - if (this.displayItem == null) + if (!plugin.isDisplay()) return; if (!this.displayItem.isSpawned()) { /* Not spawned yet. */ diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java index 95c70d667..67f2e7995 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java @@ -3,12 +3,16 @@ package org.maxgamer.quickshop.Shop; import java.util.ArrayList; import java.util.List; +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.*; import org.maxgamer.quickshop.QuickShop; +import org.maxgamer.quickshop.Util.Util; + /** * @author Netherfoam A display item, that spawns a block above the chest and * cannot be interacted with. @@ -105,9 +109,12 @@ public interface DisplayItem { iMeta.setDisplayName("QuickShop DisplayItem"); } java.util.List lore = new ArrayList(); + Gson gson = new Gson(); + ShopProtectionFlag shopProtectionFlag = new ShopProtectionFlag(shop.getLocation().toString(), Util + .serialize(shop.getItem())); + String protectFlag = gson.toJson(shopProtectionFlag); for (int i = 0; i < 21; i++) { - lore.add("QuickShop DisplayItem#" + shop.getLocation() - .toString()); //Create 20 lines lore to make sure no stupid plugin accident remove mark. + lore.add(protectFlag); //Create 20 lines lore to make sure no stupid plugin accident remove mark. } iMeta.setLore(lore); itemStack.setItemMeta(iMeta); @@ -128,13 +135,18 @@ public interface DisplayItem { if (iMeta.getDisplayName().toLowerCase().contains("quickshop displayitem")) return true; } - if (iMeta.hasLore()) { + if (!iMeta.hasLore()) + return false; List lores = iMeta.getLore(); + Gson gson = new Gson(); for (String lore : lores) { - if (lore.toLowerCase().contains("quickshop displayitem")) + try { + gson.fromJson(lore, ShopProtectionFlag.class); return true; + } catch (JsonSyntaxException e) { + //Ignore + } } - } return false; } @@ -153,10 +165,14 @@ public interface DisplayItem { if (!iMeta.hasLore()) return false; List lores = iMeta.getLore(); + Gson gson = new Gson(); for (String lore : lores) { - if (lore.toLowerCase().contains("quickshop displayitem")) { - if (lore.equals("quickshop displayitem#" + shop.getLocation().toString())) + try { + ShopProtectionFlag shopProtectionFlag = gson.fromJson(lore, ShopProtectionFlag.class); + if (shopProtectionFlag.getShopLocation().equals(shop.getLocation().toString())) return true; + } catch (JsonSyntaxException e) { + //Ignore } } return false; diff --git a/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java index 6a7716735..07b6be550 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java @@ -116,6 +116,8 @@ public class RealDisplayItem implements DisplayItem { .getLocation().toString()); entity.remove(); removed = true; + } else { + Util.debugLog(Util.getName(eItem.getItemStack()) + " not a shop displayItem: Failed check shop display."); } } } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopProtectionFlag.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopProtectionFlag.java new file mode 100644 index 000000000..5135eabfc --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopProtectionFlag.java @@ -0,0 +1,11 @@ +package org.maxgamer.quickshop.Shop; + +import lombok.*; + +@Getter +@Setter +@AllArgsConstructor +public class ShopProtectionFlag { + private String shopLocation; + private String itemStackString; +}