diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandEvent.java index 45d190c2d..6077e5da5 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandEvent.java @@ -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); }; } diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandInfoEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandInfoEvent.java new file mode 100644 index 000000000..d5078e4c1 --- /dev/null +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandInfoEvent.java @@ -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); + } + +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/util/IslandInfo.java b/src/main/java/world/bentobox/bentobox/util/IslandInfo.java index e772b6ba5..8f5933e6a 100644 --- a/src/main/java/world/bentobox/bentobox/util/IslandInfo.java +++ b/src/main/java/world/bentobox/bentobox/util/IslandInfo.java @@ -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; }