瀏覽代碼

2.1.45 - mcMMO will check for outdated software and provide tips

nossr50 6 年之前
父節點
當前提交
820c3260c8
共有 3 個文件被更改,包括 88 次插入20 次删除
  1. 3 0
      Changelog.txt
  2. 1 1
      pom.xml
  3. 84 19
      src/main/java/com/gmail/nossr50/mcMMO.java

+ 3 - 0
Changelog.txt

@@ -7,6 +7,9 @@ Key:
   ! Change
   ! Change
   - Removal
   - Removal
 
 
+Version 2.1.45
+    mcMMO will now check to see if the server version is incompatible and inform server admins on how to fix the problem.
+
 Version 2.1.44
 Version 2.1.44
     Fixed a NPE with Alchemy brewing
     Fixed a NPE with Alchemy brewing
 
 

+ 1 - 1
pom.xml

@@ -2,7 +2,7 @@
     <modelVersion>4.0.0</modelVersion>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.gmail.nossr50.mcMMO</groupId>
     <groupId>com.gmail.nossr50.mcMMO</groupId>
     <artifactId>mcMMO</artifactId>
     <artifactId>mcMMO</artifactId>
-    <version>2.1.44</version>
+    <version>2.1.45</version>
     <name>mcMMO</name>
     <name>mcMMO</name>
     <url>https://github.com/mcMMO-Dev/mcMMO</url>
     <url>https://github.com/mcMMO-Dev/mcMMO</url>
     <scm>
     <scm>

+ 84 - 19
src/main/java/com/gmail/nossr50/mcMMO.java

@@ -47,6 +47,7 @@ import com.gmail.nossr50.worldguard.WorldGuardManager;
 import com.google.common.base.Charsets;
 import com.google.common.base.Charsets;
 import net.shatteredlands.shatt.backup.ZipLibrary;
 import net.shatteredlands.shatt.backup.ZipLibrary;
 import org.bstats.bukkit.Metrics;
 import org.bstats.bukkit.Metrics;
+import org.bukkit.Bukkit;
 import org.bukkit.entity.Player;
 import org.bukkit.entity.Player;
 import org.bukkit.event.HandlerList;
 import org.bukkit.event.HandlerList;
 import org.bukkit.metadata.FixedMetadataValue;
 import org.bukkit.metadata.FixedMetadataValue;
@@ -57,6 +58,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.InputStreamReader;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
 
 
@@ -88,6 +90,9 @@ public class mcMMO extends JavaPlugin {
     /* Plugin Checks */
     /* Plugin Checks */
     private static boolean healthBarPluginEnabled;
     private static boolean healthBarPluginEnabled;
 
 
+    // API checks
+    private static boolean serverAPIOutdated = false;
+
     // Config Validation Check
     // Config Validation Check
     public boolean noErrorsInConfigFiles = true;
     public boolean noErrorsInConfigFiles = true;
 
 
@@ -165,35 +170,54 @@ public class mcMMO extends JavaPlugin {
 
 
             databaseManager = DatabaseManagerFactory.getDatabaseManager();
             databaseManager = DatabaseManagerFactory.getDatabaseManager();
 
 
-            registerEvents();
-            registerCoreSkills();
-            registerCustomRecipes();
+            //Check for the newer API and tell them what to do if its missing
+            checkForOutdatedAPI();
+
+            if(serverAPIOutdated)
+            {
+                Bukkit
+                        .getScheduler()
+                        .scheduleSyncRepeatingTask(this,
+                                () -> getLogger().severe("You are running an outdated version of "+getServerSoftware()+", mcMMO will not work unless you update to a newer version!"),
+                        20, 20*60*30);
+
+                if(getServerSoftware() == ServerSoftwareType.CRAFTBUKKIT)
+                {
+                    Bukkit.getScheduler()
+                            .scheduleSyncRepeatingTask(this,
+                                    () -> getLogger().severe("We have detected you are using incompatible server software, our best guess is that you are using CraftBukkit. mcMMO requires Spigot or Paper, if you are not using CraftBukkit, you will still need to update your custom server software before mcMMO will work."),
+                    20, 20*60*30);
+                }
+            } else {
+                registerEvents();
+                registerCoreSkills();
+                registerCustomRecipes();
 
 
-            PartyManager.loadParties();
+                PartyManager.loadParties();
 
 
-            formulaManager = new FormulaManager();
-            holidayManager = new HolidayManager();
+                formulaManager = new FormulaManager();
+                holidayManager = new HolidayManager();
 
 
-            for (Player player : getServer().getOnlinePlayers()) {
-                new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
-            }
+                for (Player player : getServer().getOnlinePlayers()) {
+                    new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
+                }
 
 
-            debug("Version " + getDescription().getVersion() + " is enabled!");
+                debug("Version " + getDescription().getVersion() + " is enabled!");
 
 
-            scheduleTasks();
-            CommandRegistrationManager.registerCommands();
+                scheduleTasks();
+                CommandRegistrationManager.registerCommands();
 
 
-            placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager
+                placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager
 
 
-            if (Config.getInstance().getPTPCommandWorldPermissions()) {
-                Permissions.generateWorldTeleportPermissions();
-            }
+                if (Config.getInstance().getPTPCommandWorldPermissions()) {
+                    Permissions.generateWorldTeleportPermissions();
+                }
 
 
-            //Populate Ranked Skill Maps (DO THIS LAST)
-            RankUtils.populateRanks();
+                //Populate Ranked Skill Maps (DO THIS LAST)
+                RankUtils.populateRanks();
+            }
 
 
             //If anonymous statistics are enabled then use them
             //If anonymous statistics are enabled then use them
-
             Metrics metrics;
             Metrics metrics;
 
 
             if(Config.getInstance().getIsMetricsEnabled()) {
             if(Config.getInstance().getIsMetricsEnabled()) {
@@ -223,6 +247,47 @@ public class mcMMO extends JavaPlugin {
         worldBlacklist = new WorldBlacklist(this);
         worldBlacklist = new WorldBlacklist(this);
     }
     }
 
 
+    private void checkForOutdatedAPI() {
+        try {
+            Class<?> checkForClass = Class.forName("org.bukkit.event.block.BlockDropItemEvent");
+            Method newerAPIMethod =  checkForClass.getMethod("getItems");
+            Class<?> checkForClassBaseComponent = Class.forName("net.md_5.bungee.api.chat.BaseComponent");
+        } catch (ClassNotFoundException | NoSuchMethodException e) {
+            serverAPIOutdated = true;
+            String software = getServerSoftwareStr();
+            getLogger().severe("You are running an older version of " + software + " that is not compatible with mcMMO, update your server software!");
+        }
+    }
+
+    private enum ServerSoftwareType {
+        PAPER,
+        SPIGOT,
+        CRAFTBUKKIT
+    }
+
+    private ServerSoftwareType getServerSoftware()
+    {
+        if(Bukkit.getVersion().toLowerCase().contains("paper"))
+            return ServerSoftwareType.PAPER;
+        else if(Bukkit.getVersion().toLowerCase().contains("spigot"))
+            return ServerSoftwareType.SPIGOT;
+        else
+            return ServerSoftwareType.CRAFTBUKKIT;
+    }
+
+    private String getServerSoftwareStr()
+    {
+        switch(getServerSoftware())
+        {
+            case PAPER:
+                return "Paper";
+            case SPIGOT:
+                return "Spigot";
+            default:
+                return "CraftBukkit";
+        }
+    }
+
     @Override
     @Override
     public void onLoad()
     public void onLoad()
     {
     {