From b9b9a35471c6a9b1eaba977c0a2e4167854640f5 Mon Sep 17 00:00:00 2001 From: Aria Sangarin Date: Thu, 4 Jun 2020 18:33:57 +0200 Subject: [PATCH] [Not Tested] Bug Fixes n Debug Improvements - Fixed WorldGuard Flags - Improved Debugging --- .../java/net/Indyuce/mmocore/MMOCore.java | 21 ++++++++++++++++--- .../event/trigger/LevelUpEventTrigger.java | 3 +++ .../mmocore/api/util/debug/DebugMode.java | 16 ++++++++++++-- .../mmocore/comp/flags/WorldGuardFlags.java | 12 +++-------- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 1e273cde..eebc9807 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -151,6 +151,13 @@ public class MMOCore extends JavaPlugin { if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) loadManager.registerLoader(new MythicMobsMMOLoader()); + + /* + * WorldGuard closes the flag registry after 'onLoad()', + * so it must be registered here or it will throw an IllegalStateException + */ + if(Bukkit.getPluginManager().getPlugin("WorldGuard") != null) + flagPlugin = new WorldGuardFlags(); } public void onEnable() { @@ -176,7 +183,6 @@ public class MMOCore extends JavaPlugin { if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) { regionHandler = new WorldGuardRegionHandler(); - flagPlugin = new WorldGuardFlags(); getLogger().log(Level.INFO, "Hooked onto WorldGuard"); } else if (Bukkit.getPluginManager().getPlugin("Residence") != null) { flagPlugin = new ResidenceFlags(); @@ -256,8 +262,8 @@ public class MMOCore extends JavaPlugin { /* * enable debug mode for extra debug tools. */ - if (getConfig().getBoolean("debug")) - new DebugMode(); + if (getConfig().contains("debug")) + new DebugMode(getConfig().getInt("debug", 0)); if (configManager.overrideVanillaExp = getConfig().getBoolean("override-vanilla-exp")) Bukkit.getPluginManager().registerEvents(new VanillaExperienceOverride(), this); @@ -414,10 +420,19 @@ public class MMOCore extends JavaPlugin { log(Level.INFO, message); } + public static void debug(int value, String message) { + debug(value, Level.INFO, message); + } + public static void log(Level level, String message) { plugin.getLogger().log(level, message); } + public static void debug(int value, Level level, String message) { + if(DebugMode.level > (value - 1)) + plugin.getLogger().log(level, message); + } + public File getJarFile() { return getFile(); } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/LevelUpEventTrigger.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/LevelUpEventTrigger.java index 17bc5438..9ef60028 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/LevelUpEventTrigger.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/LevelUpEventTrigger.java @@ -3,6 +3,7 @@ package net.Indyuce.mmocore.api.player.profess.event.trigger; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.profess.PlayerClass; @@ -22,9 +23,11 @@ public class LevelUpEventTrigger implements EventTriggerHandler { if(event.hasProfession()) { String prof = event.getProfession().getId().toLowerCase(); + MMOCore.debug(2, "[DEBUG] Looking for triggers: level-up-" + prof); processTrigger(player, profess, "level-up-" + prof); processTrigger(player, profess, "level-up-" + prof + "-" + event.getNewLevel()); } else { + MMOCore.debug(2, "[DEBUG] Normal level up trigger."); processTrigger(player, profess, "level-up"); processTrigger(player, profess, "level-up-" + event.getNewLevel()); if(profess.getMaxLevel() == event.getNewLevel()) diff --git a/src/main/java/net/Indyuce/mmocore/api/util/debug/DebugMode.java b/src/main/java/net/Indyuce/mmocore/api/util/debug/DebugMode.java index 6497f94c..6e441059 100644 --- a/src/main/java/net/Indyuce/mmocore/api/util/debug/DebugMode.java +++ b/src/main/java/net/Indyuce/mmocore/api/util/debug/DebugMode.java @@ -3,8 +3,20 @@ package net.Indyuce.mmocore.api.util.debug; import net.Indyuce.mmocore.MMOCore; public class DebugMode { - public DebugMode() { - if (MMOCore.plugin.getConfig().getBoolean("debug-action-bar.enabled")) + /* + * Debug Levels: + * 1: + * - Print WorldGuard Flag Registry + * 2: + * - Print Profession Trigger Things + * 3: + * - Debug Action Bar + */ + public static int level = 0; + + public DebugMode(int i) { + level = i; + if (level > 2 && MMOCore.plugin.getConfig().getBoolean("debug-action-bar.enabled")) new ActionBarRunnable().runTaskTimer(MMOCore.plugin, 0, 10); } } diff --git a/src/main/java/net/Indyuce/mmocore/comp/flags/WorldGuardFlags.java b/src/main/java/net/Indyuce/mmocore/comp/flags/WorldGuardFlags.java index 0d11f334..982416f3 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/flags/WorldGuardFlags.java +++ b/src/main/java/net/Indyuce/mmocore/comp/flags/WorldGuardFlags.java @@ -33,10 +33,10 @@ public class WorldGuardFlags implements FlagPlugin { try { registry.register(flag); flags.put(customFlag.getPath(), flag); - MMOCore.log(Level.INFO, "[FLAGDEBUG] Registered WG Flag\n" + MMOCore.debug(1, "[FLAGDEBUG] Registered WG Flag\n" + " - Info{name=" + flag.getName() + ",path=" + customFlag.getPath() + "}"); } catch (Exception exception) { - MMOCore.log(Level.SEVERE, "[FLAGDEBUG] FAILED to register WG Flag\n" + MMOCore.debug(1, Level.SEVERE, "[FLAGDEBUG] FAILED to register WG Flag\n" + " - Info{name=" + flag.getName() + ",path=" + customFlag.getPath() + "}"); exception.printStackTrace(); } @@ -55,14 +55,8 @@ public class WorldGuardFlags implements FlagPlugin { @Override public boolean isFlagAllowed(Player player, CustomFlag customFlag) { - StateFlag flag = flags.get(customFlag.getPath()); - if(flag == null) MMOCore.log(Level.SEVERE, "[FLAGDEBUG] Found Null value WG Flag\n" - + " - Info{path=" + customFlag.getPath() + "}"); - else MMOCore.log(Level.INFO, "[FLAGDEBUG] Checking WG Flag\n" - + " - Info{name=" + flag.getName() + ",path=" + customFlag.getPath() + "}"); - return getApplicableRegion(player.getLocation()).queryValue(worldguardPlugin.wrapPlayer(player), - flag) != StateFlag.State.DENY; + flags.get(customFlag.getPath())) != StateFlag.State.DENY; } private ApplicableRegionSet getApplicableRegion(Location loc) {