Improved IslandInfoEvent to include the calling addon.

This makes it easier for listeners to determine if they should react or
not.
This commit is contained in:
tastybento 2023-06-19 09:38:49 -07:00
parent c0beba7467
commit 393a0131f9
4 changed files with 37 additions and 6 deletions

View File

@ -35,7 +35,7 @@ public class AdminInfoCommand extends CompositeCommand {
}
// If there are no args, then the player wants info on the island at this location
if (args.isEmpty()) {
getIslands().getIslandAt(user.getLocation()).ifPresentOrElse(i -> new IslandInfo(i).showAdminInfo(user), () ->
getIslands().getIslandAt(user.getLocation()).ifPresentOrElse(i -> new IslandInfo(i).showAdminInfo(user, getAddon()), () ->
user.sendMessage("commands.admin.info.no-island"));
return true;
}
@ -48,7 +48,7 @@ public class AdminInfoCommand extends CompositeCommand {
// Show info for this player
Island island = getIslands().getIsland(getWorld(), targetUUID);
if (island != null) {
new IslandInfo(island).showAdminInfo(user);
new IslandInfo(island).showAdminInfo(user, getAddon());
if (!getIslands().getQuarantinedIslandByUser(getWorld(), targetUUID).isEmpty()) {
user.sendMessage("commands.admin.info.islands-in-trash");
}

View File

@ -9,6 +9,7 @@ import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
import world.bentobox.bentobox.database.objects.Island;
@ -228,6 +229,10 @@ public class IslandEvent extends IslandBaseEvent {
* @since 1.24.0 Previous name of island
*/
private String previousName;
/**
* @since 1.24.0 GameMode addon causing this event
*/
private Addon addon;
public IslandEventBuilder island(Island island) {
this.island = island;
@ -329,6 +334,16 @@ public class IslandEvent extends IslandBaseEvent {
this.previousName = previousName;
return this;
}
/**
* Addon that triggered this event, e.g. BSkyBlock
* @param addon Addon.
* @since 1.24.0
*/
public IslandEventBuilder addon(Addon addon) {
this.addon = addon;
return this;
}
private IslandBaseEvent getEvent() {
return switch (reason) {
@ -355,7 +370,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);
case INFO -> new IslandInfoEvent(island, player, admin, location, addon);
default -> new IslandGeneralEvent(island, player, admin, location);
};
}

View File

@ -6,6 +6,7 @@ import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island;
@ -15,6 +16,7 @@ import world.bentobox.bentobox.database.objects.Island;
*/
public class IslandInfoEvent extends IslandBaseEvent {
private final Addon addon;
private static final HandlerList handlers = new HandlerList();
@Override
@ -31,10 +33,21 @@ public class IslandInfoEvent extends IslandBaseEvent {
* @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
* @param addon the addon parent that is calling this info command, e.g., BSkyBlock
*/
public IslandInfoEvent(Island island, UUID player, boolean admin, Location location) {
public IslandInfoEvent(Island island, UUID player, boolean admin, Location location, Addon addon) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
this.addon = addon;
}
/**
* @return the gameMode that is for this island
*/
public Addon getGameMode() {
return addon;
}
}

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.addons.Addon;
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
@ -44,8 +45,9 @@ public class IslandInfo {
/**
* Shows admin info of this island
* @param user user asking
* @param addon Addon executing this command
*/
public void showAdminInfo(User user) {
public void showAdminInfo(User user, Addon addon) {
user.sendMessage("commands.admin.info.title");
user.sendMessage("commands.admin.info.island-uuid", TextVariables.UUID, island.getUniqueId());
if (owner == null) {
@ -99,12 +101,13 @@ public class IslandInfo {
if (island.getPurgeProtected()) {
user.sendMessage("commands.admin.info.purge-protected");
}
// Fire info event
// Fire info event to allow other addons to add to info
IslandEvent.builder()
.island(island)
.location(island.getCenter())
.reason(IslandEvent.Reason.INFO)
.involvedPlayer(user.getUniqueId())
.addon(addon)
.admin(true)
.build();
}