diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 32bb3ff18..68e760b3e 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -199,6 +199,7 @@ public class QuickShop extends JavaPlugin { private ShopContainerWatcher shopContainerWatcher; private DisplayDupeRemoverWatcher displayDupeRemoverWatcher; private BukkitAPIWrapper bukkitAPIWrapper; + private boolean isUtilInited = false; /** * Get the Player's Shop limit. @@ -351,11 +352,14 @@ public class QuickShop extends JavaPlugin { replaceLogger(); this.bootError = null; + getLogger().info("Loading up integration modules."); this.integrationHelper = new IntegrationHelper(); this.integrationHelper.callIntegrationsLoad(IntegrateStage.onLoadBegin); if(getConfig().getBoolean("integration.worldguard.enable")){ Plugin wg = Bukkit.getPluginManager().getPlugin("WorldGuard"); - if(wg != null && wg.isEnabled()){ + Util.debugLogHeavy("Check WG plugin..."); + if(wg != null){ + Util.debugLogHeavy("Loading WG modules."); this.integrationHelper.register(new WorldGuardIntegration(this)); //WG require register flags when onLoad called. } } @@ -480,6 +484,7 @@ public class QuickShop extends JavaPlugin { /* Initalize the Utils */ itemMatcher = new ItemMatcher(this); Util.initialize(); + this.isUtilInited = true; try { MsgUtil.loadCfgMessages(); } catch (Exception e) { diff --git a/src/main/java/org/maxgamer/quickshop/Util/IntegrationHelper.java b/src/main/java/org/maxgamer/quickshop/Util/IntegrationHelper.java index c6a9d5aae..b1cc8d061 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/IntegrationHelper.java +++ b/src/main/java/org/maxgamer/quickshop/Util/IntegrationHelper.java @@ -19,6 +19,7 @@ package org.maxgamer.quickshop.Util; +import lombok.Getter; import org.bukkit.Location; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -28,15 +29,15 @@ import org.maxgamer.quickshop.PluginsIntegration.IntegrationStage; import java.util.HashSet; import java.util.Set; - +@Getter public class IntegrationHelper { - Set integrations = new HashSet<>(); + private Set integrations = new HashSet<>(); public void register(@NotNull IntegratedPlugin clazz) { if (!isIntegrationClass(clazz)) { throw new InvaildIntegratedPluginClass(); } - Util.debugLog("Registering "+clazz.getName()); + Util.debugLogHeavy("Registering "+clazz.getName()); integrations.add(clazz); } @@ -45,15 +46,17 @@ public class IntegrationHelper { if (!isIntegrationClass(clazz)) { throw new InvaildIntegratedPluginClass(); } - Util.debugLog("Unregistering "+clazz.getName()); + Util.debugLogHeavy("Unregistering "+clazz.getName()); integrations.remove(clazz); } public void callIntegrationsLoad(@NotNull IntegrateStage stage) { integrations.forEach(integratedPlugin -> { if (integratedPlugin.getClass().getDeclaredAnnotation(IntegrationStage.class).loadStage() == stage) { - Util.debugLog("Calling for load "+integratedPlugin.getName()); + Util.debugLogHeavy("Calling for load "+integratedPlugin.getName()); integratedPlugin.load(); + }else{ + Util.debugLogHeavy("Ignored calling because "+integratedPlugin.getName()+" stage is "+integratedPlugin.getClass().getDeclaredAnnotation(IntegrationStage.class).loadStage()); } }); } @@ -61,7 +64,7 @@ public class IntegrationHelper { public void callIntegrationsUnload(@NotNull IntegrateStage stage) { integrations.forEach(integratedPlugin -> { if (integratedPlugin.getClass().getDeclaredAnnotation(IntegrationStage.class).loadStage() == stage) { - Util.debugLog("Calling for unload "+integratedPlugin.getName()); + Util.debugLogHeavy("Calling for unload "+integratedPlugin.getName()); integratedPlugin.unload(); } }); @@ -70,7 +73,7 @@ public class IntegrationHelper { public boolean callIntegrationsCanCreate(@NotNull Player player, @NotNull Location location) { for (IntegratedPlugin integratedPlugin : integrations) { if (!integratedPlugin.canCreateShopHere(player, location)) { - Util.debugLog("Integration " + integratedPlugin.getName() + " denied the player " + player.getName() + " at " + location + " shop creation."); + Util.debugLogHeavy("Integration " + integratedPlugin.getName() + " denied the player " + player.getName() + " at " + location + " shop creation."); return false; } } @@ -80,7 +83,7 @@ public class IntegrationHelper { public boolean callIntegrationsCanTrade(@NotNull Player player, @NotNull Location location) { for (IntegratedPlugin integratedPlugin : integrations) { if (!integratedPlugin.canTradeShopHere(player, location)) { - Util.debugLog("Integration " + integratedPlugin.getName() + " denied the player " + player.getName() + " at " + location + " shop trading."); + Util.debugLogHeavy("Integration " + integratedPlugin.getName() + " denied the player " + player.getName() + " at " + location + " shop trading."); return false; } } @@ -88,7 +91,7 @@ public class IntegrationHelper { } private boolean isIntegrationClass(@NotNull IntegratedPlugin clazz) { - return clazz.getClass().getAnnotation(IntegrationStage.class) != null; + return clazz.getClass().getDeclaredAnnotation(IntegrationStage.class) != null; } } diff --git a/src/main/java/org/maxgamer/quickshop/Util/Paste/Paste.java b/src/main/java/org/maxgamer/quickshop/Util/Paste/Paste.java index 83ade7530..2e1348465 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Paste/Paste.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Paste/Paste.java @@ -115,6 +115,9 @@ public class Paste { finalReport.append("\tOnlineMode: ").append(Bukkit.getOnlineMode()).append("\n"); finalReport.append("\tBukkitVersion: ").append(Bukkit.getVersion()).append("\n"); finalReport.append("\tWorldContainer: ").append(Bukkit.getWorldContainer()).append("\n"); + List modules = new ArrayList<>();; + plugin.getIntegrationHelper().getIntegrations().forEach(m->modules.add(m.getName())); + finalReport.append("\tLoaded Integrations: ").append(Util.list2String(modules)).append("\n"); finalReport.append("================================================\n"); finalReport.append("Worlds:\n"); finalReport.append("\tTotal: ").append(Bukkit.getWorlds().size()).append("\n"); diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 878986c0b..8364415b6 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -41,6 +41,7 @@ import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.maxgamer.quickshop.Database.MySQLCore; +import org.maxgamer.quickshop.NonQuickShopStuffs.de.Keyle.MyPet.api.util.Colorizer; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Shop.DisplayItem; import org.maxgamer.quickshop.Shop.Shop; @@ -66,14 +67,14 @@ public class Util { private static EnumSet blacklist = EnumSet.noneOf(Material.class); @Getter private static List debugLogs = new LinkedList<>(); - private static boolean devMode; + private static boolean devMode = true; private static QuickShop plugin; private static EnumMap> restrictedPrices = new EnumMap<>(Material.class); private static Object serverInstance; private static EnumSet shoppables = EnumSet.noneOf(Material.class); private static Field tpsField; private static List worldBlacklist = new ArrayList<>(); - private static boolean disableDebugLogger; + private static boolean disableDebugLogger = false; /** * Convert strArray to String. @@ -198,6 +199,7 @@ public class Util { * * @param logs logs */ + public static void debugLog(@NotNull String... logs) { if (!devMode) { if (disableDebugLogger) { @@ -220,7 +222,7 @@ public class Util { for (String log : logs) { String text = "["+ChatColor.DARK_GREEN + ChatColor.BOLD + "DEBUG" + ChatColor.RESET + "] [" + ChatColor.DARK_GREEN + className + ChatColor.RESET + "]" + " [" + ChatColor.DARK_GREEN + methodName + ChatColor.RESET + "] (" + ChatColor.DARK_GREEN + codeLine + ChatColor.RESET + ") " + log; - debugLogs.add(text); + debugLogs.add(Colorizer.stripColors(text)); if (debugLogs.size() > 500000) /* Keep debugLogs max can have 500k lines. */ { debugLogs.remove(0); } @@ -241,6 +243,42 @@ public class Util { } } } + /** + * Print debug log when plugin running on dev mode. + * + * @param logs logs + */ + + public static void debugLogHeavy(@NotNull String... logs) { + if (!QuickShop.instance.getConfig().getBoolean("dev-mode")) { + return; + } + long startTime = System.currentTimeMillis(); + String className = Thread.currentThread().getStackTrace()[2].getClassName(); + try { + Class c = Class.forName(className); + className = c.getSimpleName(); + if (!c.getSimpleName().isEmpty()) { + className = c.getSimpleName(); + } + } catch (ClassNotFoundException e) { + //Ignore + } + String methodName = Thread.currentThread().getStackTrace()[2].getMethodName(); + int codeLine = Thread.currentThread().getStackTrace()[2].getLineNumber(); + + for (String log : logs) { + String text = "["+ChatColor.DARK_GREEN + ChatColor.BOLD + "DEBUG" + ChatColor.RESET + "] [" + ChatColor.DARK_GREEN + className + ChatColor.RESET + "]" + " [" + ChatColor.DARK_GREEN + methodName + ChatColor.RESET + "] (" + ChatColor.DARK_GREEN + codeLine + ChatColor.RESET + ") " + log; + debugLogs.add(Colorizer.stripColors(text)); + if (debugLogs.size() > 500000) /* Keep debugLogs max can have 500k lines. */ { + debugLogs.remove(0); + } + if (QuickShop.instance.getConfig().getBoolean("dev-mode")) { + QuickShop.instance.getLogger().info(text); + } + } + long debugLogCost = System.currentTimeMillis() - startTime; + } /** * Covert YAML string to ItemStack.