From 792fd82d1ed774fa4563b8b02bd3bdd16fe0571a Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Mon, 19 Aug 2019 15:18:20 +0800 Subject: [PATCH] Use faster deepEquals method in java to replace lines check Former-commit-id: cec29e4517b627ca50c4e37bd06636acc34b4aaf [formerly 2261ef58b73b1bc28d8d2581869a81e728ee3699] Former-commit-id: 7241fc0086cb3804a684f401d01c2648f97bc358 --- .../maxgamer/quickshop/Util/ItemMatcher.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java b/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java index 08a3c58dc..78c375f86 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java +++ b/src/main/java/org/maxgamer/quickshop/Util/ItemMatcher.java @@ -1,6 +1,7 @@ package org.maxgamer.quickshop.Util; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -43,6 +44,11 @@ public class ItemMatcher { return false; // One of them is null (Can't be both, see above) } + requireStack = requireStack.clone(); + requireStack.setAmount(1); + givenStack = givenStack.clone(); + givenStack.setAmount(1); + if (plugin.getConfig().getBoolean("shop.strict-matches-check")) { Util.debugLog("Execute strict match check..."); return requireStack.equals(givenStack); @@ -218,15 +224,7 @@ public class ItemMatcher { } List lores1 = meta1.getLore(); List lores2 = meta2.getLore(); - if (lores1.size() != lores2.size()) { - return false; - } - for (int i = 0; i < lores1.size(); i++) { - if (!lores1.get(i).equals(lores2.get(i))) { - return false; - } - } - return true; + return !Arrays.deepEquals(lores1.toArray(), lores2.toArray()); } boolean matches(ItemStack requireStack, ItemStack givenStack) { @@ -330,9 +328,12 @@ public class ItemMatcher { if(!potion2.hasCustomEffects()){ return false; } - if (!Util.listMatches(potion1.getCustomEffects(),potion2.getCustomEffects())) { - return false; + if(!Arrays.deepEquals(potion1.getCustomEffects().toArray(),potion2.getCustomEffects().toArray())){ + return false; } +// if (!Util.listMatches(potion1.getCustomEffects(),potion2.getCustomEffects())) { +// return false; +// } } PotionData data1 = potion1.getBasePotionData(); PotionData data2 = potion2.getBasePotionData();