[Not Tested] Bug Fixes n Debug Improvements

- Fixed WorldGuard Flags
- Improved Debugging
This commit is contained in:
Aria Sangarin 2020-06-04 18:33:57 +02:00
parent 6670a3263f
commit b9b9a35471
4 changed files with 38 additions and 14 deletions

View File

@ -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();
}

View File

@ -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())

View File

@ -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);
}
}

View File

@ -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) {