From 88c81a9cc2986b2d052ad40027c793575a62d6cd Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Wed, 9 Dec 2020 11:41:59 +0100 Subject: [PATCH] Added ItemsAdder support (fixes #2575) --- pom.xml | 24 +++++++++++++++---- .../listeners/BlockListener.java | 15 ++++++++---- .../integrations/IntegrationsManager.java | 16 +++++++++++++ 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 8ad83997c..dcb7c65d9 100644 --- a/pom.xml +++ b/pom.xml @@ -49,11 +49,11 @@ spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + https://hub.spigotmc.org/nexus/content/repositories/snapshots paper-repo - https://papermc.io/repo/repository/maven-public/ + https://papermc.io/repo/repository/maven-public jitpack.io @@ -61,7 +61,7 @@ worldedit-repo - https://maven.sk89q.com/repo/ + https://maven.sk89q.com/repo codemc-repo @@ -69,11 +69,11 @@ placeholderapi-repo - https://repo.extendedclip.com/content/repositories/placeholderapi/ + https://repo.extendedclip.com/content/repositories/placeholderapi walshy-public - https://repo.walshy.dev/public/ + https://repo.walshy.dev/public @@ -419,5 +419,19 @@ 3.1.6 provided + + com.github.LoneDev6 + itemsadder-api + 0.1.2 + provided + + + + + org.jetbrains + annotations + + + 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 080372fc1..6cb8f87ee 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 @@ -55,9 +55,11 @@ public class BlockListener implements Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockPlaceExisting(BlockPlaceEvent e) { - // This prevents Players from placing a block where another block already exists - // While this can cause ghost blocks it also prevents them from replacing grass - // or saplings etc... + /* + * This prevents Players from placing a block where another block already exists. + * While this can cause ghost blocks it also prevents them from replacing grass + * or saplings etc... + */ if (BlockStorage.hasBlockInfo(e.getBlock())) { e.setCancelled(true); } @@ -84,8 +86,13 @@ public class BlockListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent e) { + // Simply ignore any events that were faked by other plugins if (SlimefunPlugin.getThirdPartySupportService().isEventFaked(e)) { - // This is a "fake" event, we can ignore it. + return; + } + + // Also ignore custom blocks which were placed by other plugins + if (SlimefunPlugin.getThirdPartySupportService().isCustomBlock(e.getBlock())) { return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java index a64d68c77..203ad44d8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java @@ -4,11 +4,14 @@ import java.util.logging.Level; import javax.annotation.Nonnull; +import org.bukkit.Location; +import org.bukkit.block.Block; import org.bukkit.event.Event; import org.bukkit.plugin.Plugin; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; +import dev.lone.itemsadder.api.ItemsAdder; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.api.Slimefun; @@ -135,6 +138,19 @@ public class IntegrationsManager { return isMcMMOInstalled && event instanceof FakeBlockBreakEvent; } + /** + * This checks if one of our third party integrations has placed a custom + * {@link Block} at this {@link Location}. + * + * @param block + * The {@link Block} to check + * + * @return Whether a different custom {@link Block} exists at that {@link Location} + */ + public boolean isCustomBlock(@Nonnull Block block) { + return isItemsAdderInstalled && ItemsAdder.isCustomBlock(block); + } + public boolean isPlaceholderAPIInstalled() { return isPlaceholderAPIInstalled; }