diff --git a/build.gradle.kts b/build.gradle.kts index b8569d7c6..d119d156b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,7 +23,7 @@ dependencies { implementation("org.jetbrains:annotations:24.0.1") implementation("com.j256.ormlite:ormlite-core:6.1") implementation("com.j256.ormlite:ormlite-jdbc:6.1") - implementation("com.iridium:IridiumTeams:2.1.4") + implementation("com.iridium:IridiumTeams:2.1.5") // Other dependencies that are not required or already available at runtime compileOnly("org.projectlombok:lombok:1.18.26") diff --git a/src/main/java/com/iridium/iridiumskyblock/api/IslandDeleteEvent.java b/src/main/java/com/iridium/iridiumskyblock/api/IslandDeleteEvent.java new file mode 100644 index 000000000..ed3029e65 --- /dev/null +++ b/src/main/java/com/iridium/iridiumskyblock/api/IslandDeleteEvent.java @@ -0,0 +1,39 @@ +package com.iridium.iridiumskyblock.api; + +import com.iridium.iridiumskyblock.database.Island; +import com.iridium.iridiumskyblock.database.User; +import lombok.Getter; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +@Getter +public class IslandDeleteEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + @NotNull private final Island island; + @NotNull private final User user; + + public IslandDeleteEvent(@NotNull Island island, @NotNull User user) { + this.island = island; + this.user = user; + } + + @NotNull + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + +} \ No newline at end of file diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java index 7acaea250..cdb7182c2 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java @@ -9,6 +9,7 @@ import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.api.IslandCreateEvent; +import com.iridium.iridiumskyblock.api.IslandDeleteEvent; import com.iridium.iridiumskyblock.configs.Schematics; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; @@ -206,13 +207,19 @@ private void deleteIslandBlocks(Island island, World world, int y, CompletableFu } @Override - public void deleteTeam(Island island, User user) { + public boolean deleteTeam(Island island, User user) { + IslandDeleteEvent islandDeleteEvent = new IslandDeleteEvent(island, user); + Bukkit.getPluginManager().callEvent(islandDeleteEvent); + if (islandDeleteEvent.isCancelled()) return false; + if (IridiumSkyblock.getInstance().getConfiguration().removeIslandBlocksOnDelete) { deleteIslandBlocks(island); } IridiumSkyblock.getInstance().getDatabaseManager().getIslandTableManager().delete(island); getMembersOnIsland(island).forEach(member -> PlayerUtils.teleportSpawn(member.getPlayer())); + + return true; } @Override