Fix faulty WG logic

This commit is contained in:
nossr50 2020-01-27 20:38:52 -08:00
parent aaffafb88b
commit e3edc9a18f
3 changed files with 35 additions and 33 deletions

View File

@ -5,5 +5,4 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ConfigSerializable @ConfigSerializable
public class General { public class General {
} }

View File

@ -86,6 +86,7 @@ public class mcMMO extends JavaPlugin {
private ScoreboardManager scoreboardManager; private ScoreboardManager scoreboardManager;
private SoundManager soundManager; private SoundManager soundManager;
private HardcoreManager hardcoreManager; private HardcoreManager hardcoreManager;
private WorldGuardManager worldGuardManager;
/* Not-Managers but my naming scheme sucks */ /* Not-Managers but my naming scheme sucks */
private DatabaseManagerFactory databaseManagerFactory; private DatabaseManagerFactory databaseManagerFactory;
@ -307,13 +308,15 @@ public class mcMMO extends JavaPlugin {
@Override @Override
public void onLoad() public void onLoad()
{ {
worldGuardUtils = new WorldGuardUtils(this); //Init WGU
if(getServer().getPluginManager().getPlugin("WorldGuard") != null) { if(getServer().getPluginManager().getPlugin("WorldGuard") != null) {
worldGuardUtils = new WorldGuardUtils(); //Init WGU
if(worldGuardUtils.isWorldGuardLoaded()) { if(worldGuardUtils.isWorldGuardLoaded()) {
//Register flags //Register flags
System.out.println("[mcMMO - Registering World Guard Flags...]"); System.out.println("[mcMMO - Registering World Guard Flags...]");
worldGuardUtils.getWorldGuardManager().registerFlags(); worldGuardManager = new WorldGuardManager();
worldGuardManager.registerFlags();
} }
} }
} }
@ -749,7 +752,7 @@ public class mcMMO extends JavaPlugin {
} }
public WorldGuardManager getWorldGuardManager() { public WorldGuardManager getWorldGuardManager() {
return worldGuardUtils.getWorldGuardManager(); return worldGuardManager;
} }
public PartyManager getPartyManager() { public PartyManager getPartyManager() {

View File

@ -1,6 +1,9 @@
package com.gmail.nossr50.worldguard; package com.gmail.nossr50.worldguard;
import com.gmail.nossr50.mcMMO;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,10 +15,7 @@ public class WorldGuardUtils {
private boolean isLoaded = false; private boolean isLoaded = false;
private boolean detectedIncompatibleWG = false; private boolean detectedIncompatibleWG = false;
private static final ArrayList<String> WGClassList; private static final ArrayList<String> WGClassList;
private WorldGuardManager worldGuardManager; protected final mcMMO pluginRef;
public WorldGuardUtils() {
}
static { static {
/* /*
@ -41,6 +41,10 @@ public class WorldGuardUtils {
WGClassList.add("com.sk89q.worldguard.protection.regions.RegionQuery"); WGClassList.add("com.sk89q.worldguard.protection.regions.RegionQuery");
} }
public WorldGuardUtils(mcMMO pluginRef) {
this.pluginRef = pluginRef;
}
public boolean isWorldGuardLoaded() public boolean isWorldGuardLoaded()
{ {
if(detectedIncompatibleWG) if(detectedIncompatibleWG)
@ -68,7 +72,7 @@ public class WorldGuardUtils {
if(plugin == null) { if(plugin == null) {
//WG is not present //WG is not present
detectedIncompatibleWG = true; detectedIncompatibleWG = true;
System.out.println("[mcMMO WorldGuardUtils Debug] WorldGuard was not detected."); pluginRef.getLogger().info("WorldGuard was not detected.");
} else { } else {
//Check that its actually of class WorldGuardPlugin //Check that its actually of class WorldGuardPlugin
if(plugin instanceof WorldGuardPlugin) if(plugin instanceof WorldGuardPlugin)
@ -77,9 +81,6 @@ public class WorldGuardUtils {
{ {
worldGuardPluginRef = (WorldGuardPlugin) plugin; worldGuardPluginRef = (WorldGuardPlugin) plugin;
isLoaded = true; isLoaded = true;
//Init WG Manager
worldGuardManager = new WorldGuardManager();
} }
} else { } else {
//Plugin is not of the expected type //Plugin is not of the expected type
@ -87,6 +88,7 @@ public class WorldGuardUtils {
} }
} }
return worldGuardPluginRef; return worldGuardPluginRef;
} }
@ -98,7 +100,10 @@ public class WorldGuardUtils {
*/ */
private boolean isCompatibleVersion(Plugin plugin) { private boolean isCompatibleVersion(Plugin plugin) {
//Check that the version of WG is at least version 7.xx //Check that the version of WG is at least version 7.xx
// boolean allClassesFound = true; boolean allClassesFound = true;
if (detectedIncompatibleWG) {
return false;
}
if (!plugin.getDescription().getVersion().startsWith("7")) { if (!plugin.getDescription().getVersion().startsWith("7")) {
markWGIncompatible(); markWGIncompatible();
@ -107,10 +112,9 @@ public class WorldGuardUtils {
for(String classString : WGClassList) { for(String classString : WGClassList) {
try { try {
Class<?> checkForClass = Class.forName(classString); Class<?> checkForClass = Class.forName(classString);
detectedIncompatibleWG = false; //In case this was set to true previously
} catch (ClassNotFoundException | NoClassDefFoundError e) { } catch (ClassNotFoundException | NoClassDefFoundError e) {
// allClassesFound = false; allClassesFound = false;
System.out.println("[mcMMO WorldGuardUtils Debug] Missing WorldGuard class - "+classString); pluginRef.getLogger().severe("Missing WorldGuard class - "+classString);
markWGIncompatible(); markWGIncompatible();
} }
} }
@ -118,17 +122,17 @@ public class WorldGuardUtils {
/* /*
* If WG appears to have all of its classes we can then check to see if its been initialized properly * If WG appears to have all of its classes we can then check to see if its been initialized properly
*/ */
// try { try {
// if(allClassesFound) { if(allClassesFound) {
// if(!((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).isInitialized()) { if(!((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).isInitialized()) {
// markWGIncompatible(); markWGIncompatible();
// System.out.println("[mcMMO WorldGuardUtils Debug] WG did not initialize properly, this can cause errors with mcMMO so mcMMO is disabling certain features."); pluginRef.getLogger().severe("WG did not initialize properly, this can cause errors with mcMMO so mcMMO is disabling certain features.");
// } }
// } }
// } catch (Exception e) { } catch (Exception e) {
// markWGIncompatible(); markWGIncompatible();
// e.printStackTrace(); e.printStackTrace();
// } }
} }
return !detectedIncompatibleWG; return !detectedIncompatibleWG;
@ -138,14 +142,10 @@ public class WorldGuardUtils {
* Mark WG as being incompatible to avoid unnecessary operations * Mark WG as being incompatible to avoid unnecessary operations
*/ */
private void markWGIncompatible() { private void markWGIncompatible() {
System.out.println("[mcMMO WorldGuardUtils Debug] You are using a version of WG that is not compatible with mcMMO, " + pluginRef.getLogger().severe("You are using a version of WG that is not compatible with mcMMO, " +
"WG features for mcMMO will be disabled. mcMMO requires you to be using a new version of WG7 " + "WG features for mcMMO will be disabled. mcMMO requires you to be using a new version of WG7 " +
"in order for it to use WG features. Not all versions of WG7 are compatible."); "in order for it to use WG features. Not all versions of WG7 are compatible.");
System.out.println("[mcMMO WorldGuardUtils Debug] mcMMO will continue to function normally, but if you wish to use WG support you must use a compatible version."); pluginRef.getLogger().severe("mcMMO will continue to function normally, but if you wish to use WG support you must use a compatible version.");
detectedIncompatibleWG = true; detectedIncompatibleWG = true;
} }
public WorldGuardManager getWorldGuardManager() {
return worldGuardManager;
}
} }