Add IslandInfoEvent to allow addons to add to the island info command

This commit is contained in:
tastybento 2023-06-18 20:58:52 -07:00
parent 5a52978803
commit 09c60f24cf
3 changed files with 63 additions and 1 deletions

View File

@ -175,7 +175,12 @@ public class IslandEvent extends IslandBaseEvent {
* Event that will fire when an island is named or renamed
* @since 1.24.0
*/
NAME
NAME,
/**
* Event that will fire when the info command is executed. Allows addons to add to it
* @since 1.24.0
*/
INFO
}
public static IslandEventBuilder builder() {
@ -350,6 +355,7 @@ public class IslandEvent extends IslandBaseEvent {
case RANK_CHANGE -> new IslandRankChangeEvent(island, player, admin, location, oldRank, newRank);
case NEW_ISLAND -> new IslandNewIslandEvent(island, player, admin, location);
case NAME -> new IslandNameEvent(island, player, admin, location, previousName);
case INFO -> new IslandInfoEvent(island, player, admin, location);
default -> new IslandGeneralEvent(island, player, admin, location);
};
}

View File

@ -0,0 +1,40 @@
package world.bentobox.bentobox.api.events.island;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
/**
* Fired when an a player reuqets info about an island
* Cancellation has no effect.
*/
public class IslandInfoEvent extends IslandBaseEvent {
private static final HandlerList handlers = new HandlerList();
@Override
public @NonNull HandlerList getHandlers() {
return getHandlerList();
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* @param island island
* @param player player asking for the info
* @param admin true if this is an admin request
* @param location location of the player asking for the info
*/
public IslandInfoEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}

View File

@ -10,6 +10,7 @@ import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
@ -98,6 +99,14 @@ public class IslandInfo {
if (island.getPurgeProtected()) {
user.sendMessage("commands.admin.info.purge-protected");
}
// Fire info event
IslandEvent.builder()
.island(island)
.location(island.getCenter())
.reason(IslandEvent.Reason.INFO)
.involvedPlayer(user.getUniqueId())
.admin(true)
.build();
}
@ -130,6 +139,13 @@ public class IslandInfo {
user.sendMessage("commands.admin.info.banned-players");
island.getBanned().forEach(u -> user.sendMessage("commands.admin.info.banned-format", TextVariables.NAME, plugin.getPlayers().getName(u)));
}
// Fire info event
IslandEvent.builder()
.island(island)
.location(island.getCenter())
.reason(IslandEvent.Reason.INFO)
.involvedPlayer(user.getUniqueId())
.build();
return true;
}