Просмотр исходного кода

compatibility with FAWE ( :| )

nossr50 5 лет назад
Родитель
Сommit
101b0671fe

+ 1 - 0
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:

+ 19 - 14
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;
@@ -85,21 +86,25 @@ public class WorldGuardManager {
 
     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
         }
     }
 

+ 22 - 4
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;
@@ -93,23 +95,39 @@ public class WorldGuardUtils {
      */
     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;
     }
 
     /**