From 399e928bda0eb2562ca03a4f16bfd74baa65c856 Mon Sep 17 00:00:00 2001 From: Sotr Date: Fri, 12 Apr 2019 12:44:36 +0800 Subject: [PATCH] Optimize location3DEqual Former-commit-id: 5a04fb06859af6def40a2e311a84250714b9e155 [formerly 2b6368fb0c28e57ed3b53a57eb06a5d44f79aee5] Former-commit-id: 54922e734d04b15d55439dba89dc242a031cb5b9 --- .../java/org/maxgamer/quickshop/Util/Util.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 786ef1191..97be49815 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -46,6 +46,7 @@ public class Util { private static QuickShop plugin; private static Method storageContents; static Map timerMap = new HashMap(); + protected static boolean devMode; public String boolean2String(boolean bool) { if (bool) { return "Enabled"; @@ -57,6 +58,8 @@ public class Util { blacklist.clear(); shoppables.clear(); restrictedPrices.clear(); + + devMode = plugin.getConfig().getBoolean("dev-mode"); plugin = QuickShop.instance; for (String s : plugin.getConfig().getStringList("shop-blocks")) { @@ -237,11 +240,11 @@ public class Util { Util.debugLog("Find args: "+b.getLocation().toString()); Util.debugLog("Left: "+leftC.getLocation().toString()); Util.debugLog("Right: "+rightC.getLocation().toString()); - if(location3DEqual(b.getLocation(),leftC.getLocation())) { + if(equalsBlockStateLocation(oneSideOfChest, leftC)) { Util.debugLog("Clicked left chest"); return rightC.getBlock(); } - if(location3DEqual(b.getLocation(),rightC.getLocation())) { + if(equalsBlockStateLocation(oneSideOfChest, leftC)) { Util.debugLog("Clicked right chest"); return leftC.getBlock(); } @@ -252,6 +255,11 @@ public class Util { return null; } } + + private static final boolean equalsBlockStateLocation(BlockState b1, BlockState b2) { + return b1.getX() == b2.getX() && b1.getY() == b2.getY() && b1.getZ() == b2.getZ(); + } + public static boolean location3DEqual(Location loc1, Location loc2){ if(loc1.getWorld().getName() != loc2.getWorld().getName()) return false; @@ -875,8 +883,8 @@ public class Util { * @param String logs */ public static void debugLog(String logs) { - if(plugin.getConfig().getBoolean("dev-mode")) { - plugin.getLogger().info("[DEBUG] "+logs); + if(devMode) { + plugin.getLogger().warning("[DEBUG] "+logs); } }