diff --git a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/PlatformProvider.java b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/PlatformProvider.java index 174b44058..8824c47f7 100644 --- a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/PlatformProvider.java +++ b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/PlatformProvider.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.mcmmo.api.platform; -import com.gmail.nossr50.mcmmo.api.data.MMOPlayer; +import com.gmail.nossr50.mcmmo.api.platform.schedular.PlatformScheduler; import com.gmail.nossr50.mcmmo.api.platform.util.MetadataStore; import java.io.File; @@ -16,5 +16,21 @@ public interface PlatformProvider { File getDataFolder(); - void getVersion(); + String getVersion(); + + void earlyInit(); + + boolean isSupported(boolean print); + + default boolean isSupported() { + return isSupported(false); + }; + + ServerSoftwareType getServerType(); + + void onLoad(); + + void printUnsupported(); + + PlatformScheduler getScheduler(); } diff --git a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/ServerSoftwareType.java b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/ServerSoftwareType.java new file mode 100644 index 000000000..941aa028a --- /dev/null +++ b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/ServerSoftwareType.java @@ -0,0 +1,18 @@ +package com.gmail.nossr50.mcmmo.api.platform; + +public enum ServerSoftwareType { + PAPER("Paper"), + SPIGOT("Spigot"), + CRAFTBUKKIT("CraftBukkit"); + + private final String friendlyName; + + ServerSoftwareType(String friendlyName) { + + this.friendlyName = friendlyName; + } + + public String getFriendlyName() { + return friendlyName; + } +} \ No newline at end of file diff --git a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/schedular/PlatformScheduler.java b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/schedular/PlatformScheduler.java new file mode 100644 index 000000000..fc1c154d7 --- /dev/null +++ b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/schedular/PlatformScheduler.java @@ -0,0 +1,6 @@ +package com.gmail.nossr50.mcmmo.api.platform.schedular; + +public interface PlatformScheduler { + + +} diff --git a/mcmmo-bukkit/src/main/java/com/gmail/nossr50/mcmmo/bukkit/BukkitBoostrap.java b/mcmmo-bukkit/src/main/java/com/gmail/nossr50/mcmmo/bukkit/BukkitBoostrap.java index 8834ae955..e4827b128 100644 --- a/mcmmo-bukkit/src/main/java/com/gmail/nossr50/mcmmo/bukkit/BukkitBoostrap.java +++ b/mcmmo-bukkit/src/main/java/com/gmail/nossr50/mcmmo/bukkit/BukkitBoostrap.java @@ -1,13 +1,23 @@ package com.gmail.nossr50.mcmmo.bukkit; +import com.gmail.nossr50.listeners.BlockListener; +import com.gmail.nossr50.listeners.EntityListener; +import com.gmail.nossr50.listeners.InventoryListener; +import com.gmail.nossr50.listeners.PlayerListener; +import com.gmail.nossr50.listeners.SelfListener; +import com.gmail.nossr50.listeners.WorldListener; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcmmo.api.platform.PlatformProvider; +import com.gmail.nossr50.mcmmo.api.platform.ServerSoftwareType; import com.gmail.nossr50.mcmmo.api.platform.util.MetadataStore; +import org.bukkit.Bukkit; import org.bukkit.event.HandlerList; +import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; +import java.util.Locale; import java.util.logging.Logger; public class BukkitBoostrap extends JavaPlugin implements PlatformProvider { @@ -31,4 +41,64 @@ public class BukkitBoostrap extends JavaPlugin implements PlatformProvider { public MetadataStore getMetadataStore() { return null; } + + @Override + public String getVersion() { + return this.getVersion(); + } + + @Override + public void earlyInit() { + registerEvents(); + + } + + @Override + public boolean isSupported(boolean print) { + boolean ret = getServerType() != ServerSoftwareType.CRAFTBUKKIT; + if (!ret) { + Bukkit + .getScheduler() + .scheduleSyncRepeatingTask(this, + () -> getLogger().severe("You are running an outdated version of " + getServerType() + ", mcMMO will not work unless you update to a newer version!"), + 20, 20 * 60 * 30); + + if (getServerType() == 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); + } + } + + return ret; + } + + @Override + public ServerSoftwareType getServerType() { + if (Bukkit.getVersion().toLowerCase(Locale.ENGLISH).contains("paper")) + return ServerSoftwareType.PAPER; + else if (Bukkit.getVersion().toLowerCase(Locale.ENGLISH).contains("spigot")) + return ServerSoftwareType.SPIGOT; + else + return ServerSoftwareType.CRAFTBUKKIT; + } + + @Override + public void printUnsupported() { + + } + + + private void registerEvents() { + PluginManager pluginManager = getServer().getPluginManager(); + + // Register events + pluginManager.registerEvents(new PlayerListener(core), this); + pluginManager.registerEvents(new BlockListener(core), this); + pluginManager.registerEvents(new EntityListener(core), this); + pluginManager.registerEvents(new InventoryListener(core), this); + pluginManager.registerEvents(new SelfListener(core), this); + pluginManager.registerEvents(new WorldListener(core), this); + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java b/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java index f6e97bb6c..76468beea 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java @@ -10,7 +10,6 @@ import com.gmail.nossr50.config.playerleveling.ConfigLeveling; import com.gmail.nossr50.config.scoreboard.ConfigScoreboard; import com.gmail.nossr50.core.DynamicSettingsManager; import com.gmail.nossr50.core.MaterialMapStore; -import com.gmail.nossr50.core.MetadataConstants; import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManagerFactory; import com.gmail.nossr50.datatypes.skills.subskills.acrobatics.Roll; @@ -49,26 +48,21 @@ import com.gmail.nossr50.worldguard.WorldGuardManager; import com.gmail.nossr50.worldguard.WorldGuardUtils; import net.shatteredlands.shatt.backup.ZipLibrary; import org.bstats.bukkit.Metrics; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; -import java.util.Locale; public class mcMMO implements McMMOApi { /* Managers */ @@ -186,23 +180,12 @@ public class mcMMO implements McMMOApi { databaseManager = getDatabaseManagerFactory().getDatabaseManager(); //Check for the newer API and tell them what to do if its missing - CompatibilityCheck.checkForOutdatedAPI(this, serverAPIOutdated, getServerSoftwareStr()); + CompatibilityCheck.checkForOutdatedAPI(this, serverAPIOutdated, platformProvider.getServerType().getFriendlyName()); - 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); - } + if (!platformProvider.isSupported(true)) { + return; } else { - registerEvents(); + platformProvider.earlyInit(); registerCoreSkills(); registerCustomRecipes(); initParties(); @@ -240,7 +223,7 @@ public class mcMMO implements McMMOApi { if (getConfigManager().getConfigMetrics().isAllowAnonymousUsageStatistics()) { Metrics metrics; metrics = new Metrics(this); - metrics.addCustomChart(new Metrics.SimplePie("version", () -> getDescription().getVersion())); + metrics.addCustomChart(new Metrics.SimplePie("version", this::getVersion)); int levelScaleModifier = configManager.getConfigLeveling().getConfigSectionLevelingGeneral().getConfigSectionLevelScaling().getCosmeticLevelScaleModifier(); @@ -311,11 +294,12 @@ public class mcMMO implements McMMOApi { } private String getVersion() { - platformProvider.getVersion(); + return platformProvider.getVersion(); } public void onLoad() { + platformProvider.onLoad(); worldGuardUtils = new WorldGuardUtils(this); //Init WGU if(getServer().getPluginManager().getPlugin("WorldGuard") != null) { @@ -383,36 +367,6 @@ public class mcMMO implements McMMOApi { return playerLevelTools; } - /** - * Returns a ServerSoftwareType based on version strings - * Custom software is returned as CRAFTBUKKIT - * - * @return the ServerSoftwareType which likely matches the server - */ - private ServerSoftwareType getServerSoftware() { - if (Bukkit.getVersion().toLowerCase(Locale.ENGLISH).contains("paper")) - return ServerSoftwareType.PAPER; - else if (Bukkit.getVersion().toLowerCase(Locale.ENGLISH).contains("spigot")) - return ServerSoftwareType.SPIGOT; - else - return ServerSoftwareType.CRAFTBUKKIT; - } - - /** - * Gets a string version of ServerSoftwareType - * - * @return Formatted String of ServerSoftwareType - */ - private String getServerSoftwareStr() { - switch (getServerSoftware()) { - case PAPER: - return "Paper"; - case SPIGOT: - return "Spigot"; - default: - return "CraftBukkit"; - } - } public MaterialMapStore getMaterialMapStore() { return materialMapStore; @@ -619,18 +573,6 @@ public class mcMMO implements McMMOApi { configManager.loadConfigs(); } - private void registerEvents() { - PluginManager pluginManager = getServer().getPluginManager(); - - // Register events - pluginManager.registerEvents(new PlayerListener(this), this); - pluginManager.registerEvents(new BlockListener(this), this); - pluginManager.registerEvents(new EntityListener(this), this); - pluginManager.registerEvents(new InventoryListener(this), this); - pluginManager.registerEvents(new SelfListener(this), this); - pluginManager.registerEvents(new WorldListener(this), this); - } - /** * Registers core skills * This enables the skills in the new skill system @@ -749,12 +691,6 @@ public class mcMMO implements McMMOApi { return dynamicSettingsManager; } - private enum ServerSoftwareType { - PAPER, - SPIGOT, - CRAFTBUKKIT - } - public NotificationManager getNotificationManager() { return notificationManager; }