diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java index 103b1cf75..db4c912b0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java @@ -2,21 +2,17 @@ package io.github.thebusybiscuit.slimefun4.core.services.plugins; import java.util.Optional; import java.util.function.Function; -import java.util.logging.Level; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.block.Block; -import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; -import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; - import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import me.mrCookieSlime.Slimefun.api.Slimefun; +import io.github.thebusybiscuit.slimefun4.integrations.IntegrationsManager; /** * This Service holds all interactions and hooks with third-party {@link Plugin Plugins} @@ -29,20 +25,16 @@ import me.mrCookieSlime.Slimefun.api.Slimefun; * @see SlimefunPlugin * */ -public class ThirdPartyPluginService { - - private final SlimefunPlugin plugin; - - private boolean initialized = false; - private boolean isExoticGardenInstalled = false; - private boolean isChestTerminalInstalled = false; - private boolean isMcMMOInstalled = false; +public class ThirdPartyPluginService extends IntegrationsManager { /** * This gets overridden if ExoticGarden is loaded */ private Function> exoticGardenIntegration = b -> Optional.empty(); + private boolean isChestTerminalInstalled = false; + private boolean isExoticGardenInstalled = false; + /** * This initializes the {@link ThirdPartyPluginService} * @@ -50,77 +42,14 @@ public class ThirdPartyPluginService { * Our instance of {@link SlimefunPlugin} */ public ThirdPartyPluginService(@Nonnull SlimefunPlugin plugin) { - this.plugin = plugin; + super(plugin); } - /** - * This method initializes all third party integrations. - */ + @Override public void start() { - if (initialized) { - throw new UnsupportedOperationException("Third Party Integrations have already been initialized!"); - } + super.start(); - initialized = true; - - if (isPluginInstalled("PlaceholderAPI")) { - try { - PlaceholderAPIIntegration hook = new PlaceholderAPIIntegration(plugin); - hook.register(); - } catch (Exception | LinkageError x) { - String version = plugin.getServer().getPluginManager().getPlugin("PlaceholderAPI").getDescription().getVersion(); - - Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating PlaceholderAPI or Slimefun?"); - Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to hook into PlaceholderAPI v" + version); - } - } - - // WorldEdit Hook to clear Slimefun Data upon //set 0 //cut or any other equivalent - if (isPluginInstalled("WorldEdit")) { - try { - Class.forName("com.sk89q.worldedit.extent.Extent"); - new WorldEditIntegration(); - } catch (Exception | LinkageError x) { - String version = plugin.getServer().getPluginManager().getPlugin("WorldEdit").getDescription().getVersion(); - - Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating WorldEdit or Slimefun?"); - Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to hook into WorldEdit v" + version); - } - } - - // mcMMO Integration - if (isPluginInstalled("mcMMO")) { - try { - new McMMOIntegration(plugin); - isMcMMOInstalled = true; - } catch (Exception | LinkageError x) { - String version = plugin.getServer().getPluginManager().getPlugin("mcMMO").getDescription().getVersion(); - Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating mcMMO or Slimefun?"); - Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to hook into mcMMO v" + version); - } - } - - /* - * These Items are not marked as soft-dependencies and - * therefore need to be loaded after the Server has finished - * loading all plugins - */ - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { - if (isPluginInstalled("ClearLag")) { - new ClearLagIntegration(plugin); - } - - isChestTerminalInstalled = isPluginInstalled("ChestTerminal"); - }); - } - - private boolean isPluginInstalled(@Nonnull String hook) { - if (plugin.getServer().getPluginManager().isPluginEnabled(hook)) { - Slimefun.getLogger().log(Level.INFO, "Hooked into Plugin: {0}", hook); - return true; - } else { - return false; - } + plugin.getServer().getScheduler().runTask(plugin, () -> isChestTerminalInstalled = isPluginInstalled("ChestTerminal")); } @ParametersAreNonnullByDefault @@ -143,18 +72,4 @@ public class ThirdPartyPluginService { return exoticGardenIntegration.apply(block); } - /** - * This checks if one of our third party integrations faked an {@link Event}. - * Faked {@link Event Events} should be ignored in our logic. - * - * @param event - * The {@link Event} to test - * - * @return Whether this is a fake event - */ - public boolean isEventFaked(@Nonnull Event event) { - // This can be changed to "FakeEvent" in a later version - return isMcMMOInstalled && event instanceof FakeBlockBreakEvent; - } - } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ClearLagIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/ClearLagIntegration.java similarity index 94% rename from src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ClearLagIntegration.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/integrations/ClearLagIntegration.java index 212bb1f3f..ce4082a8f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ClearLagIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/ClearLagIntegration.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.core.services.plugins; +package io.github.thebusybiscuit.slimefun4.integrations; import java.util.Iterator; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java new file mode 100644 index 000000000..a64d68c77 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java @@ -0,0 +1,158 @@ +package io.github.thebusybiscuit.slimefun4.integrations; + +import java.util.logging.Level; + +import javax.annotation.Nonnull; + +import org.bukkit.event.Event; +import org.bukkit.plugin.Plugin; + +import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; + +import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.api.Slimefun; + +/** + * This Service holds all interactions and hooks with third-party {@link Plugin Plugins} + * that are not necessarily a dependency or a {@link SlimefunAddon}. + * + * Integration with these plugins happens inside Slimefun itself. + * + * @author TheBusyBiscuit + * + * @see SlimefunPlugin + * + */ +public class IntegrationsManager { + + protected final SlimefunPlugin plugin; + + private boolean isPlaceholderAPIInstalled = false; + private boolean isWorldEditInstalled = false; + private boolean isMcMMOInstalled = false; + private boolean isClearLagInstalled = false; + private boolean isItemsAdderInstalled = false; + + /** + * This initializes the {@link IntegrationsManager} + * + * @param plugin + * Our instance of {@link SlimefunPlugin} + */ + public IntegrationsManager(@Nonnull SlimefunPlugin plugin) { + this.plugin = plugin; + } + + /** + * This method initializes all third party integrations. + */ + public void start() { + // PlaceholderAPI hook to provide playerholders from Slimefun. + if (isPluginInstalled("PlaceholderAPI")) { + try { + PlaceholderAPIIntegration hook = new PlaceholderAPIIntegration(plugin); + hook.register(); + isPlaceholderAPIInstalled = true; + } catch (Exception | LinkageError x) { + String version = plugin.getServer().getPluginManager().getPlugin("PlaceholderAPI").getDescription().getVersion(); + + Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating PlaceholderAPI or Slimefun?"); + Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to hook into PlaceholderAPI v" + version); + } + } + + // WorldEdit Hook to clear Slimefun Data upon //set 0 //cut or any other equivalent + if (isPluginInstalled("WorldEdit")) { + try { + Class.forName("com.sk89q.worldedit.extent.Extent"); + new WorldEditIntegration(); + isWorldEditInstalled = true; + } catch (Exception | LinkageError x) { + String version = plugin.getServer().getPluginManager().getPlugin("WorldEdit").getDescription().getVersion(); + + Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating WorldEdit or Slimefun?"); + Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to hook into WorldEdit v" + version); + } + } + + // mcMMO Integration + if (isPluginInstalled("mcMMO")) { + try { + new McMMOIntegration(plugin); + isMcMMOInstalled = true; + } catch (Exception | LinkageError x) { + String version = plugin.getServer().getPluginManager().getPlugin("mcMMO").getDescription().getVersion(); + Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating mcMMO or Slimefun?"); + Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to hook into mcMMO v" + version); + } + } + + // ItemsAdder Integration + if (isPluginInstalled("ItemsAdder")) { + try { + isItemsAdderInstalled = true; + } catch (Exception | LinkageError x) { + String version = plugin.getServer().getPluginManager().getPlugin("ItemsAdder").getDescription().getVersion(); + Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating ItemsAdder or Slimefun?"); + Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to hook into ItemsAdder v" + version); + } + } + + // ClearLag integration (to prevent display items from getting deleted) + if (isPluginInstalled("ClearLag")) { + try { + new ClearLagIntegration(plugin); + isClearLagInstalled = true; + } catch (Exception | LinkageError x) { + String version = plugin.getServer().getPluginManager().getPlugin("ClearLag").getDescription().getVersion(); + Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating ClearLag or Slimefun?"); + Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to hook into ClearLag v" + version); + } + } + } + + protected boolean isPluginInstalled(@Nonnull String hook) { + if (plugin.getServer().getPluginManager().isPluginEnabled(hook)) { + Slimefun.getLogger().log(Level.INFO, "Hooked into Plugin: {0}", hook); + return true; + } else { + return false; + } + } + + /** + * This checks if one of our third party integrations faked an {@link Event}. + * Faked {@link Event Events} should be ignored in our logic. + * + * @param event + * The {@link Event} to test + * + * @return Whether this is a fake event + */ + public boolean isEventFaked(@Nonnull Event event) { + // This can be changed to "FakeEvent" in a later version + return isMcMMOInstalled && event instanceof FakeBlockBreakEvent; + } + + public boolean isPlaceholderAPIInstalled() { + return isPlaceholderAPIInstalled; + } + + public boolean isWorldEditInstalled() { + return isWorldEditInstalled; + } + + public boolean isMcMMOInstalled() { + return isMcMMOInstalled; + } + + public boolean isClearLagInstalled() { + return isClearLagInstalled; + } + + public boolean isItemsAdderInstalled() { + return isItemsAdderInstalled; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/McMMOIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/McMMOIntegration.java similarity index 96% rename from src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/McMMOIntegration.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/integrations/McMMOIntegration.java index 553627469..631da36c2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/McMMOIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/McMMOIntegration.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.core.services.plugins; +package io.github.thebusybiscuit.slimefun4.integrations; import javax.annotation.Nonnull; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java similarity index 98% rename from src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIIntegration.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java index d49426458..b6fa8a0cf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.core.services.plugins; +package io.github.thebusybiscuit.slimefun4.integrations; import java.util.Optional; import java.util.Set; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/WorldEditIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/WorldEditIntegration.java similarity index 96% rename from src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/WorldEditIntegration.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/integrations/WorldEditIntegration.java index 38af34726..5230c91a5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/WorldEditIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/WorldEditIntegration.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.core.services.plugins; +package io.github.thebusybiscuit.slimefun4.integrations; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/package-info.java new file mode 100644 index 000000000..61c871610 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/package-info.java @@ -0,0 +1,4 @@ +/** + * This package holds classes which are related to integrations between Slimefun and Third-Party plugins. + */ +package io.github.thebusybiscuit.slimefun4.integrations; \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 04a127c8a..873411e97 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,14 @@ description: Slimefun basically turns your entire Server into a FTB modpack with website: https://github.com/Slimefun main: io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin -softdepend: [CS-CoreLib, PlaceholderAPI, WorldEdit, EmeraldEnchants, mcMMO] + +softdepend: +- CS-CoreLib +- PlaceholderAPI +- WorldEdit +- ClearLag +- mcMMO +- ItemsAdder api-version: '1.14'