From e18c7cb245f38fcab5ef07e43cd351c8fa10301d Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 15 Oct 2020 13:50:12 +0200 Subject: [PATCH] Fixed a dupe bug with mcMMO --- CHANGELOG.md | 1 + .../services/plugins/ClearLagIntegration.java | 8 ++++ .../plugins/EmeraldEnchantsCategory.java | 1 + .../services/plugins/McMMOIntegration.java | 16 +++++++ .../plugins/PlaceholderAPIIntegration.java | 7 ++++ .../plugins/ThirdPartyPluginService.java | 42 ++++++++++++++++++- .../plugins/WorldEditIntegration.java | 7 ++++ .../implementation/SlimefunPlugin.java | 8 ++++ .../listeners/BlockListener.java | 5 +++ 9 files changed, 93 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e5ca0d4c..7c3ecac3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,6 +92,7 @@ * Fixed #2411 * Fixed #2423 * Fixed #2452 +* Fixed a dupe bug with mcMMO ## Release Candidate 16 (07 Sep 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#16 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ClearLagIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ClearLagIntegration.java index e1e12038d..212bb1f3f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ClearLagIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ClearLagIntegration.java @@ -11,8 +11,16 @@ import org.bukkit.event.Listener; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import me.minebuilders.clearlag.Clearlag; import me.minebuilders.clearlag.events.EntityRemoveEvent; +/** + * This handles all integrations with {@link Clearlag}. + * We don't want it to clear our altar items. + * + * @author TheBusyBiscuit + * + */ class ClearLagIntegration implements Listener { ClearLagIntegration(@Nonnull SlimefunPlugin plugin) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/EmeraldEnchantsCategory.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/EmeraldEnchantsCategory.java index ecd2fd7b0..486c59af8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/EmeraldEnchantsCategory.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/EmeraldEnchantsCategory.java @@ -12,6 +12,7 @@ import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; import me.mrCookieSlime.EmeraldEnchants.EnchantmentGuide; +@Deprecated class EmeraldEnchantsCategory extends FlexCategory { public EmeraldEnchantsCategory(@Nonnull NamespacedKey key) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/McMMOIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/McMMOIntegration.java index dd6507501..553627469 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/McMMOIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/McMMOIntegration.java @@ -15,6 +15,12 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +/** + * This handles all integrations with {@link mcMMO}. + * + * @author TheBusyBiscuit + * + */ class McMMOIntegration implements Listener { McMMOIntegration(@Nonnull SlimefunPlugin plugin) { @@ -36,6 +42,16 @@ class McMMOIntegration implements Listener { } } + /** + * This method checks if an {@link ItemStack} can be salvaged or not. + * We basically don't want players to salvage any {@link SlimefunItem} unless + * it is a {@link VanillaItem}. + * + * @param item + * The {@link ItemStack} to check + * + * @return Whether this item can be safely salvaged + */ private boolean isSalvageable(@Nonnull ItemStack item) { SlimefunItem sfItem = SlimefunItem.getByItem(item); return sfItem == null || sfItem instanceof VanillaItem; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIIntegration.java index 344fd5ef0..d49426458 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIIntegration.java @@ -13,8 +13,15 @@ import org.bukkit.entity.Player; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.expansion.PlaceholderExpansion; +/** + * This is our integration for {@link PlaceholderAPI}. + * + * @author TheBusyBiscuit + * + */ class PlaceholderAPIIntegration extends PlaceholderExpansion { private final String version; 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 d516567ca..4bf85071f 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 @@ -9,9 +9,12 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.NamespacedKey; 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.core.categories.FlexCategory; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; @@ -32,9 +35,11 @@ public class ThirdPartyPluginService { private final SlimefunPlugin plugin; + private boolean initialized = false; private boolean isExoticGardenInstalled = false; private boolean isChestTerminalInstalled = false; private boolean isEmeraldEnchantsInstalled = false; + private boolean isMcMMOInstalled = false; /** * This gets overridden if ExoticGarden is loaded @@ -51,7 +56,16 @@ public class ThirdPartyPluginService { this.plugin = plugin; } + /** + * This method initializes all third party integrations. + */ public void start() { + if (initialized) { + throw new UnsupportedOperationException("Third Party Integrations have already been initialized!"); + } + + initialized = true; + if (isPluginInstalled("PlaceholderAPI")) { try { PlaceholderAPIIntegration hook = new PlaceholderAPIIntegration(plugin); @@ -84,9 +98,19 @@ public class ThirdPartyPluginService { } } - // mcMMO Block Placer Integration + // mcMMO Integration if (isPluginInstalled("mcMMO")) { - new McMMOIntegration(plugin); + try { + // This makes sure that the FakeEvent interface is present. + // Class.forName("com.gmail.nossr50.events.fake.FakeEvent"); + + 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); + } } /* @@ -136,4 +160,18 @@ 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) { + // TODO: Change this to FakeEvent once the new mcMMO build was released + return isMcMMOInstalled && event instanceof FakeBlockBreakEvent; + } + } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/WorldEditIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/WorldEditIntegration.java index 104e1bb27..38af34726 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/WorldEditIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/WorldEditIntegration.java @@ -14,6 +14,13 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import me.mrCookieSlime.Slimefun.api.BlockStorage; +/** + * This handles all integrations with {@link WorldEdit}. + * If an are is cleared, we also wanna clear all Slimefun-related block data. + * + * @author TheBusyBiscuit + * + */ class WorldEditIntegration { WorldEditIntegration() { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java index d95c1272f..781d46bb0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java @@ -181,9 +181,14 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { command.register(); registry.load(config); } else if (getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) { + getLogger().log(Level.INFO, "CS-CoreLib was detected!"); long timestamp = System.nanoTime(); PaperLib.suggestPaper(this); + if (PaperLib.isPaper()) { + getLogger().log(Level.INFO, "Paper was detected! Performance optimizations have been applied."); + } + // We wanna ensure that the Server uses a compatible version of Minecraft if (isVersionUnsupported()) { getServer().getPluginManager().disablePlugin(this); @@ -275,7 +280,10 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { autoSavingService.start(this, config.getInt("options.auto-save-delay-in-minutes")); ticker.start(this); + + getLogger().log(Level.INFO, "Loading Third-Party plugin integrations..."); thirdPartySupportService.start(); + gitHubService.start(this); // Hooray! diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index 00fc2b18f..815cb6c6e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -83,6 +83,11 @@ public class BlockListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent e) { + if (SlimefunPlugin.getThirdPartySupportService().isEventFaked(e)) { + // This is a "fake" event, we can ignore it. + return; + } + checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock()); ItemStack item = e.getPlayer().getInventory().getItemInMainHand();