Skip to content

Commit

Permalink
Added IslandDeleteEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachesMLG committed Sep 23, 2023
1 parent 6bf07e5 commit 4436171
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4436171

Please sign in to comment.