1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Added ItemsAdder support (fixes #2575)

This commit is contained in:
TheBusyBiscuit 2020-12-09 11:41:59 +01:00
parent 2e13cd2e88
commit 88c81a9cc2
3 changed files with 46 additions and 9 deletions

24
pom.xml
View File

@ -49,11 +49,11 @@
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
</repository>
<repository>
<id>paper-repo</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://papermc.io/repo/repository/maven-public</url>
</repository>
<repository>
<id>jitpack.io</id>
@ -61,7 +61,7 @@
</repository>
<repository>
<id>worldedit-repo</id>
<url>https://maven.sk89q.com/repo/</url>
<url>https://maven.sk89q.com/repo</url>
</repository>
<repository>
<id>codemc-repo</id>
@ -69,11 +69,11 @@
</repository>
<repository>
<id>placeholderapi-repo</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi</url>
</repository>
<repository>
<id>walshy-public</id>
<url>https://repo.walshy.dev/public/</url>
<url>https://repo.walshy.dev/public</url>
</repository>
</repositories>
@ -419,5 +419,19 @@
<version>3.1.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.LoneDev6</groupId>
<artifactId>itemsadder-api</artifactId>
<version>0.1.2</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<!-- We use javax.annotation instead. Excluding this -->
<!-- prevents us from using inconsistent annotations -->
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@ -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;
}

View File

@ -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;
}