Skip to content

Commit

Permalink
compatibility with FAWE ( :| )
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed Sep 20, 2019
1 parent e14c53d commit 101b067
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
@@ -1,6 +1,7 @@
Version 2.1.108
Fixed an amusing exploit for easy leveling in Acrobatics
mcMMO should no longer break if FAWE is being used in conjunction with WG on the server
Improved WG compatibility, mcMMO will now check if WG has loaded properly before hooking into it, which will prevent mcMMO from breaking if WG could not load properly.
mcMMO now loads after worlds do during start up (which is what it should be doing)

NOTES:
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/com/gmail/nossr50/worldguard/WorldGuardManager.java
@@ -1,5 +1,6 @@
package com.gmail.nossr50.worldguard;

import com.gmail.nossr50.mcMMO;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldguard.WorldGuard;
Expand Down Expand Up @@ -85,21 +86,25 @@ private WorldGuardPlugin getWorldGuard() {

public void registerFlags()
{
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();

try {
// register our flag with the registry
registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);
registry.register(WorldGuardFlags.MCMMO_HARDCORE_WG_FLAG);
System.out.println("mcMMO has registered WG flags successfully!");
} catch (FlagConflictException e) {
e.printStackTrace();
System.out.println("mcMMO has failed to register WG flags!");
// some other plugin registered a flag by the same name already.
// you may want to re-register with a different name, but this
// could cause issues with saved flags in region files. it's better
// to print a message to let the server admin know of the conflict
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();

try {
// register our flag with the registry
registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);
registry.register(WorldGuardFlags.MCMMO_HARDCORE_WG_FLAG);
System.out.println("mcMMO has registered WG flags successfully!");
} catch (FlagConflictException e) {
e.printStackTrace();
System.out.println("mcMMO has failed to register WG flags!");
// some other plugin registered a flag by the same name already.
// you may want to re-register with a different name, but this
// could cause issues with saved flags in region files. it's better
// to print a message to let the server admin know of the conflict
}
} catch (NoClassDefFoundError e) {
System.out.println("[mcMMO] Could not register WG Flags!"); //Don't use the Logger here
}
}

Expand Down
26 changes: 22 additions & 4 deletions src/main/java/com/gmail/nossr50/worldguard/WorldGuardUtils.java
@@ -1,7 +1,9 @@
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.protection.flags.registry.SimpleFlagRegistry;
import org.bukkit.plugin.Plugin;

import java.util.ArrayList;
Expand Down Expand Up @@ -93,23 +95,39 @@ private static WorldGuardPlugin getWorldGuard()
*/
private static boolean isCompatibleVersion(Plugin plugin) {
//Check that the version of WG is at least version 7.xx
if(!plugin.getDescription().getVersion().startsWith("7")) {
boolean allClassesFound = true;

if (!plugin.getDescription().getVersion().startsWith("7")) {
markWGIncompatible();
} else {
//Use Reflection to check for a class not present in all versions of WG7
for(String classString : WGClassList) {
try {
Class<?> checkForClass = Class.forName(classString);
detectedIncompatibleWG = false; //In case this was set to true previously
} catch (ClassNotFoundException | NoClassDefFoundError e) {
allClassesFound = false;
mcMMO.p.getLogger().severe("Missing WorldGuard class - "+classString);
markWGIncompatible();
return false;
}
}

/*
* If WG appears to have all of its classes we can then check to see if its been initialized properly
*/
try {
if(allClassesFound) {
if(!((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).isInitialized()) {
markWGIncompatible();
mcMMO.p.getLogger().severe("WG did not initialize properly, this can cause errors with mcMMO so mcMMO is disabling certain features.");
}
}
} catch (Exception e) {
markWGIncompatible();
e.printStackTrace();
}
}

return true;
return !detectedIncompatibleWG;
}

/**
Expand Down

0 comments on commit 101b067

Please sign in to comment.