From a713b7be075c0ce2efaf6b52602f7e192bda7c83 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 12 Feb 2023 15:21:32 -0800 Subject: [PATCH 01/26] Version 1.21.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ec646dbe7..b05d88628 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ -LOCAL - 1.22.0 + 1.22.1 bentobox-world https://sonarcloud.io From 7d0eb3586d1be8db4c3d3102d0f3a37bca5bf828 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 15 Feb 2023 16:01:52 -0800 Subject: [PATCH 02/26] Make events public so they can be instantiated in 3rd party JUnit tests I need to create "fake" events to test addons but unless they are public I cannot. All Bukkit events are public, so this should be fine. --- .../world/bentobox/bentobox/api/events/IslandBaseEvent.java | 6 +++--- .../bentobox/bentobox/api/events/island/IslandBanEvent.java | 2 +- .../bentobox/api/events/island/IslandCreateEvent.java | 2 +- .../bentobox/api/events/island/IslandCreatedEvent.java | 2 +- .../bentobox/api/events/island/IslandDeleteChunksEvent.java | 2 +- .../bentobox/api/events/island/IslandDeleteEvent.java | 2 +- .../bentobox/api/events/island/IslandDeletedEvent.java | 2 +- .../bentobox/api/events/island/IslandEnterEvent.java | 2 +- .../bentobox/api/events/island/IslandExitEvent.java | 2 +- .../bentobox/api/events/island/IslandExpelEvent.java | 2 +- .../bentobox/api/events/island/IslandGeneralEvent.java | 2 +- .../bentobox/api/events/island/IslandLockEvent.java | 2 +- .../bentobox/api/events/island/IslandNewIslandEvent.java | 2 +- .../bentobox/api/events/island/IslandPreCreateEvent.java | 2 +- .../bentobox/api/events/island/IslandPreclearEvent.java | 2 +- .../api/events/island/IslandProtectionRangeChangeEvent.java | 2 +- .../bentobox/api/events/island/IslandRegisteredEvent.java | 2 +- .../bentobox/api/events/island/IslandReservedEvent.java | 2 +- .../bentobox/api/events/island/IslandResetEvent.java | 2 +- .../bentobox/api/events/island/IslandResettedEvent.java | 2 +- .../bentobox/api/events/island/IslandUnlockEvent.java | 2 +- .../bentobox/api/events/island/IslandUnregisteredEvent.java | 2 +- .../bentobox/bentobox/api/events/team/TeamDeleteEvent.java | 2 +- .../bentobox/bentobox/api/events/team/TeamGeneralEvent.java | 2 +- .../bentobox/bentobox/api/events/team/TeamInfoEvent.java | 2 +- .../bentobox/bentobox/api/events/team/TeamInviteEvent.java | 2 +- .../bentobox/bentobox/api/events/team/TeamJoinEvent.java | 2 +- .../bentobox/bentobox/api/events/team/TeamJoinedEvent.java | 2 +- .../bentobox/bentobox/api/events/team/TeamKickEvent.java | 2 +- .../bentobox/bentobox/api/events/team/TeamLeaveEvent.java | 2 +- .../bentobox/bentobox/api/events/team/TeamRejectEvent.java | 2 +- .../bentobox/api/events/team/TeamSetownerEvent.java | 2 +- .../bentobox/api/events/team/TeamUninviteEvent.java | 2 +- 33 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/events/IslandBaseEvent.java b/src/main/java/world/bentobox/bentobox/api/events/IslandBaseEvent.java index d09a7c12b..1c31b3346 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/IslandBaseEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/IslandBaseEvent.java @@ -23,7 +23,7 @@ public abstract class IslandBaseEvent extends BentoBoxEvent implements Cancellab protected final Event rawEvent; protected IslandBaseEvent newEvent; - protected IslandBaseEvent(Island island) { + public IslandBaseEvent(Island island) { super(); this.island = island; playerUUID = island == null ? null : island.getOwner(); @@ -38,7 +38,7 @@ protected IslandBaseEvent(Island island) { * @param admin - true if ths is due to an admin event * @param location - the location */ - protected IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Location location) { + public IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Location location) { super(); this.island = island; this.playerUUID = playerUUID; @@ -54,7 +54,7 @@ protected IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Locatio * @param location - the location * @param rawEvent - the raw event */ - protected IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Location location, Event rawEvent) { + public IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Location location, Event rawEvent) { super(); this.island = island; this.playerUUID = playerUUID; diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandBanEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandBanEvent.java index c1e5b3a4f..4d4bc14f8 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandBanEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandBanEvent.java @@ -28,7 +28,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandBanEvent(Island island, UUID player, boolean admin, Location location) { + public IslandBanEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandCreateEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandCreateEvent.java index 75d56792f..099551095 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandCreateEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandCreateEvent.java @@ -28,7 +28,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandCreateEvent(Island island, UUID player, boolean admin, Location location, @NonNull BlueprintBundle blueprintBundle) { + public IslandCreateEvent(Island island, UUID player, boolean admin, Location location, @NonNull BlueprintBundle blueprintBundle) { // Final variables have to be declared in the constructor super(island, player, admin, location); this.blueprintBundle = blueprintBundle; diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandCreatedEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandCreatedEvent.java index 303a7ab03..d9c43b94d 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandCreatedEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandCreatedEvent.java @@ -25,7 +25,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandCreatedEvent(Island island, UUID player, boolean admin, Location location) { + public IslandCreatedEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeleteChunksEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeleteChunksEvent.java index f05ebabdf..ac3c4334b 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeleteChunksEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeleteChunksEvent.java @@ -28,7 +28,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandDeleteChunksEvent(Island island, UUID player, boolean admin, Location location, IslandDeletion deletedIsland) { + public IslandDeleteChunksEvent(Island island, UUID player, boolean admin, Location location, IslandDeletion deletedIsland) { // Final variables have to be declared in the constructor super(island, player, admin, location); this.deletedIslandInfo = deletedIsland; diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeleteEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeleteEvent.java index dec404e22..5a36fbf3d 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeleteEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeleteEvent.java @@ -26,7 +26,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandDeleteEvent(Island island, UUID player, boolean admin, Location location) { + public IslandDeleteEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeletedEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeletedEvent.java index f3d31de98..3d9f62aa1 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeletedEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandDeletedEvent.java @@ -30,7 +30,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandDeletedEvent(Island island, UUID player, boolean admin, Location location, IslandDeletion deletedIsland) { + public IslandDeletedEvent(Island island, UUID player, boolean admin, Location location, IslandDeletion deletedIsland) { // Final variables have to be declared in the constructor super(island, player, admin, location); this.deletedIslandInfo = deletedIsland; diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandEnterEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandEnterEvent.java index eaf732e4b..98bc01a3a 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandEnterEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandEnterEvent.java @@ -29,7 +29,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandEnterEvent(Island island, UUID player, boolean admin, Location location, @Nullable Island fromIsland, Event rawEvent) { + public IslandEnterEvent(Island island, UUID player, boolean admin, Location location, @Nullable Island fromIsland, Event rawEvent) { // Final variables have to be declared in the constructor super(island, player, admin, location, rawEvent); this.fromIsland = fromIsland; diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandExitEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandExitEvent.java index c378a473f..667f7c3d2 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandExitEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandExitEvent.java @@ -29,7 +29,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandExitEvent(Island island, UUID player, boolean admin, Location location, @Nullable Island toIsland, Event rawEvent) { + public IslandExitEvent(Island island, UUID player, boolean admin, Location location, @Nullable Island toIsland, Event rawEvent) { // Final variables have to be declared in the constructor super(island, player, admin, location, rawEvent); this.toIsland = toIsland; diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandExpelEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandExpelEvent.java index f412810fd..8a8892065 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandExpelEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandExpelEvent.java @@ -29,7 +29,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandExpelEvent(Island island, UUID player, boolean admin, Location location) { + public IslandExpelEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandGeneralEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandGeneralEvent.java index 597f9caf8..2c102315c 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandGeneralEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandGeneralEvent.java @@ -26,7 +26,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandGeneralEvent(Island island, UUID player, boolean admin, Location location) { + public IslandGeneralEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandLockEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandLockEvent.java index 39322bd13..6d2bd4115 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandLockEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandLockEvent.java @@ -26,7 +26,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandLockEvent(Island island, UUID player, boolean admin, Location location) { + public IslandLockEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandNewIslandEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandNewIslandEvent.java index babdb66be..5810f6146 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandNewIslandEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandNewIslandEvent.java @@ -26,7 +26,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandNewIslandEvent(Island island, UUID player, boolean admin, Location location) { + public IslandNewIslandEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandPreCreateEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandPreCreateEvent.java index 698ab59c1..fd7166caa 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandPreCreateEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandPreCreateEvent.java @@ -25,7 +25,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandPreCreateEvent(UUID player) { + public IslandPreCreateEvent(UUID player) { // Final variables have to be declared in the constructor super(null, player, false, null); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandPreclearEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandPreclearEvent.java index 5b9d54381..78d650ee1 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandPreclearEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandPreclearEvent.java @@ -27,7 +27,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandPreclearEvent(Island island, UUID player, boolean admin, Location location, @NonNull Island oldIsland) { + public IslandPreclearEvent(Island island, UUID player, boolean admin, Location location, @NonNull Island oldIsland) { // Final variables have to be declared in the constructor super(island, player, admin, location); // Create a copy of the old island diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandProtectionRangeChangeEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandProtectionRangeChangeEvent.java index d38d21a3b..7cfc4aaea 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandProtectionRangeChangeEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandProtectionRangeChangeEvent.java @@ -46,7 +46,7 @@ public static HandlerList getHandlerList() { * @param newRange of type int * @param oldRange of type int */ - IslandProtectionRangeChangeEvent(Island island, UUID player, boolean admin, Location location, int newRange, int oldRange) { + public IslandProtectionRangeChangeEvent(Island island, UUID player, boolean admin, Location location, int newRange, int oldRange) { super(island, player, admin, location); this.newRange = newRange; this.oldRange = oldRange; diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandRegisteredEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandRegisteredEvent.java index c3189fed2..1ab0a1539 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandRegisteredEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandRegisteredEvent.java @@ -26,7 +26,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandRegisteredEvent(Island island, UUID player, boolean admin, Location location) { + public IslandRegisteredEvent(Island island, UUID player, boolean admin, Location location) { super(island, player, admin, location); } } \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandReservedEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandReservedEvent.java index 3a8fb474c..b6db1092b 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandReservedEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandReservedEvent.java @@ -26,7 +26,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandReservedEvent(Island island, UUID player, boolean admin, Location location) { + public IslandReservedEvent(Island island, UUID player, boolean admin, Location location) { super(island, player, admin, location); } } \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandResetEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandResetEvent.java index 1b7a4043c..f1eb3456c 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandResetEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandResetEvent.java @@ -29,7 +29,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandResetEvent(Island island, UUID player, boolean admin, Location location, @NonNull BlueprintBundle blueprintBundle, @NonNull Island oldIsland) { + public IslandResetEvent(Island island, UUID player, boolean admin, Location location, @NonNull BlueprintBundle blueprintBundle, @NonNull Island oldIsland) { // Final variables have to be declared in the constructor super(island, player, admin, location); this.blueprintBundle = blueprintBundle; diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandResettedEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandResettedEvent.java index 5b8200a7c..c326c3acf 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandResettedEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandResettedEvent.java @@ -27,7 +27,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandResettedEvent(Island island, UUID player, boolean admin, Location location, Island oldIsland) { + public IslandResettedEvent(Island island, UUID player, boolean admin, Location location, Island oldIsland) { // Final variables have to be declared in the constructor super(island, player, admin, location); // Create a copy of the old island diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandUnlockEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandUnlockEvent.java index 95726975e..868d62407 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandUnlockEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandUnlockEvent.java @@ -26,7 +26,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandUnlockEvent(Island island, UUID player, boolean admin, Location location) { + public IslandUnlockEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandUnregisteredEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandUnregisteredEvent.java index d11d9c1fc..b76204b11 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandUnregisteredEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandUnregisteredEvent.java @@ -26,7 +26,7 @@ public static HandlerList getHandlerList() { return handlers; } - IslandUnregisteredEvent(Island island, UUID player, boolean admin, Location location) { + public IslandUnregisteredEvent(Island island, UUID player, boolean admin, Location location) { super(island, player, admin, location); } } \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamDeleteEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamDeleteEvent.java index 0317b7c7a..1f7f1a37a 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamDeleteEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamDeleteEvent.java @@ -22,7 +22,7 @@ public static HandlerList getHandlerList() { return handlers; } - TeamDeleteEvent(Island island, UUID player, boolean admin, Location location) { + public TeamDeleteEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamGeneralEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamGeneralEvent.java index 1a3a862bf..d18e0f37c 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamGeneralEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamGeneralEvent.java @@ -22,7 +22,7 @@ public static HandlerList getHandlerList() { return handlers; } - TeamGeneralEvent(Island island, UUID player, boolean admin, Location location) { + public TeamGeneralEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamInfoEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamInfoEvent.java index 0cf632e8b..2fa9747ff 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamInfoEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamInfoEvent.java @@ -22,7 +22,7 @@ public static HandlerList getHandlerList() { return handlers; } - TeamInfoEvent(Island island, UUID player, boolean admin, Location location) { + public TeamInfoEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamInviteEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamInviteEvent.java index 6bd40dcbe..b0b1da4dc 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamInviteEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamInviteEvent.java @@ -22,7 +22,7 @@ public static HandlerList getHandlerList() { return handlers; } - TeamInviteEvent(Island island, UUID player, boolean admin, Location location) { + public TeamInviteEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamJoinEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamJoinEvent.java index 6523a113e..8590b85f7 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamJoinEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamJoinEvent.java @@ -22,7 +22,7 @@ public static HandlerList getHandlerList() { return handlers; } - TeamJoinEvent(Island island, UUID player, boolean admin, Location location) { + public TeamJoinEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamJoinedEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamJoinedEvent.java index 7164d3c59..74222257b 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamJoinedEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamJoinedEvent.java @@ -34,7 +34,7 @@ public static HandlerList getHandlerList() { * @param location - location * @since 1.3.0 */ - TeamJoinedEvent(Island island, UUID player, boolean admin, Location location) { + public TeamJoinedEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamKickEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamKickEvent.java index f3bd18b14..61f846491 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamKickEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamKickEvent.java @@ -22,7 +22,7 @@ public static HandlerList getHandlerList() { return handlers; } - TeamKickEvent(Island island, UUID player, boolean admin, Location location) { + public TeamKickEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamLeaveEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamLeaveEvent.java index d4c16a7af..345b5a12e 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamLeaveEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamLeaveEvent.java @@ -27,7 +27,7 @@ public static HandlerList getHandlerList() { return handlers; } - TeamLeaveEvent(Island island, UUID player, boolean admin, Location location) { + public TeamLeaveEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamRejectEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamRejectEvent.java index 218b88746..be3afa475 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamRejectEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamRejectEvent.java @@ -22,7 +22,7 @@ public static HandlerList getHandlerList() { return handlers; } - TeamRejectEvent(Island island, UUID player, boolean admin, Location location) { + public TeamRejectEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamSetownerEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamSetownerEvent.java index e907cf91a..40e07bb95 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamSetownerEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamSetownerEvent.java @@ -28,7 +28,7 @@ public static HandlerList getHandlerList() { return handlers; } - TeamSetownerEvent(Island island, UUID player, boolean admin, Location location) { + public TeamSetownerEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamUninviteEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamUninviteEvent.java index 2a07712bb..9ae934526 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamUninviteEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamUninviteEvent.java @@ -22,7 +22,7 @@ public static HandlerList getHandlerList() { return handlers; } - TeamUninviteEvent(Island island, UUID player, boolean admin, Location location) { + public TeamUninviteEvent(Island island, UUID player, boolean admin, Location location) { // Final variables have to be declared in the constructor super(island, player, admin, location); } From 999ca242d7a7a0a87bea3ff52447d1581190834d Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 19 Feb 2023 08:41:21 -0800 Subject: [PATCH 03/26] Use Eclipse NonNull annotation instead of JetBrains NotNull --- .../world/bentobox/bentobox/database/objects/Island.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/database/objects/Island.java b/src/main/java/world/bentobox/bentobox/database/objects/Island.java index f5120c44a..58b7c493b 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/Island.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/Island.java @@ -24,7 +24,6 @@ import org.bukkit.util.BoundingBox; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; -import org.jetbrains.annotations.NotNull; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; @@ -749,7 +748,7 @@ public boolean inIslandSpace(Pair blockCoordinates) { * @since 1.5.2 */ @SuppressWarnings("ConstantConditions") - @NotNull + @NonNull public BoundingBox getBoundingBox() { return this.getBoundingBox(Environment.NORMAL); } @@ -928,7 +927,7 @@ public boolean onIsland(@NonNull Location target) { * @since 1.5.2 */ @SuppressWarnings("ConstantConditions") - @NotNull + @NonNull public BoundingBox getProtectionBoundingBox() { return this.getProtectionBoundingBox(Environment.NORMAL); } @@ -1645,7 +1644,7 @@ public void setProtectionCenter(Location location) throws IOException { * @return the homes * @since 1.16.0 */ - @NotNull + @NonNull public Map getHomes() { if (homes == null) { homes = new HashMap<>(); From 1b81e74f4c6a43fe6ab69f5ee30bb48ee3f8faaa Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 20 Feb 2023 09:59:26 -0800 Subject: [PATCH 04/26] Evaluates banned commands with spaces Addresses #2092 --- .../bentobox/listeners/BannedCommands.java | 33 ++++++++++++++++--- .../listeners/BannedCommandsTest.java | 29 ++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/listeners/BannedCommands.java b/src/main/java/world/bentobox/bentobox/listeners/BannedCommands.java index c9dc27be1..dcbf77f76 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/BannedCommands.java +++ b/src/main/java/world/bentobox/bentobox/listeners/BannedCommands.java @@ -36,19 +36,42 @@ public BannedCommands(@NonNull BentoBox plugin) { public void onVisitorCommand(PlayerCommandPreprocessEvent e) { if (!plugin.getIWM().inWorld(e.getPlayer().getLocation()) || e.getPlayer().isOp() || e.getPlayer().hasPermission(plugin.getIWM().getPermissionPrefix(e.getPlayer().getWorld()) + "mod.bypassprotect") - || plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getPlayer().getLocation())) { + || plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getPlayer().getLocation()) + || e.getMessage().isEmpty() + ) { return; } World w = e.getPlayer().getWorld(); // Check banned commands + // Split up the entry String[] args = e.getMessage().substring(1).toLowerCase(java.util.Locale.ENGLISH).split(" "); - if (plugin.getIWM().getVisitorBannedCommands(w).contains(args[0])) { - User user = User.getInstance(e.getPlayer()); - user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation("protection.command-is-banned")); - e.setCancelled(true); + // Loop through each of the banned commands + for (String cmd : plugin.getIWM().getVisitorBannedCommands(w)) { + if (checkCmd(cmd, args)) { + User user = User.getInstance(e.getPlayer()); + user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation("protection.command-is-banned")); + e.setCancelled(true); + return; + } } } + private boolean checkCmd(String cmd, String[] args) { + // Commands are guilty until proven innocent :-) + boolean banned = true; + // Get the elements of the banned command by splitting it + String[] bannedSplit = cmd.toLowerCase(java.util.Locale.ENGLISH).split(" "); + // If the banned command has the same number of elements or less than the entered command then it may be banned + if (bannedSplit.length <= args.length) { + for (int i = 0; i < bannedSplit.length; i++) { + if (!bannedSplit[i].equals(args[i])) { + banned = false; + } + } + } + return banned; + } + /** * Prevents falling players from using commands, like /warp * @param e - event diff --git a/src/test/java/world/bentobox/bentobox/listeners/BannedCommandsTest.java b/src/test/java/world/bentobox/bentobox/listeners/BannedCommandsTest.java index 2779bbbeb..0061942f3 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/BannedCommandsTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/BannedCommandsTest.java @@ -244,6 +244,35 @@ public void testBannedCommandsWithBannedCommandWithExtra() { assertTrue(e.isCancelled()); } + + /** + * Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)} + */ + @Test + public void testBannedCommandsWithBannedCommandWithExtraBannedStuff() { + PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "/banned_command with extra stuff"); + BannedCommands bvc = new BannedCommands(plugin); + List banned = new ArrayList<>(); + banned.add("banned_command with extra stuff"); + banned.add("another_banned_command"); + when(iwm.getVisitorBannedCommands(any())).thenReturn(banned); + bvc.onVisitorCommand(e); + verify(iwm).getVisitorBannedCommands(any()); + assertTrue(e.isCancelled()); + + } + + /** + * Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)} + */ + @Test + public void testBannedCommandsWithNothing() { + PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, ""); + BannedCommands bvc = new BannedCommands(plugin); + bvc.onVisitorCommand(e); + assertFalse(e.isCancelled()); + + } /** * Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)} From 6925a788f393835dc8eb9321e6e1d6c713729d2c Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 24 Feb 2023 17:33:53 -0800 Subject: [PATCH 05/26] Put back the deprecated way to delete and adds a GameModeAddon API to declare which type to use. AcidIsland will need updating to use this API. --- .../bentobox/api/addons/GameModeAddon.java | 9 ++ .../bentobox/managers/AddonsManager.java | 6 +- .../bentobox/nms/CopyWorldRegenerator.java | 101 ++++++++++++++++++ 3 files changed, 114 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java b/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java index 54cd8f6a1..66b58a940 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java @@ -130,5 +130,14 @@ public Optional getAdminCommand() { * @since 1.4.0 */ public abstract void saveWorldSettings(); + + /** + * Defines if the game mode uses the latest {@link ChunkGenerator} API or + * deprecated {@link ChunkGenerator#generateChunkData(World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)} approach. + * @return true if this game mode is a void world and should just be deleted as such + */ + public boolean isUsesNewChunkGeneration() { + return false; + } } diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index ed1be9554..4fd612efe 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -314,8 +314,10 @@ private void enableAddon(Addon addon) { if (addon instanceof GameModeAddon gameMode) { // Create the gameWorlds gameMode.createWorlds(); - // Create the seed worlds - createSeedWorlds(gameMode); + if (gameMode.isUsesNewChunkGeneration()) { + // Create the seed worlds + createSeedWorlds(gameMode); + } plugin.getIWM().addGameMode(gameMode); // Save and load blueprints plugin.getBlueprintsManager().extractDefaultBlueprints(gameMode); diff --git a/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java index c6a3f67b1..141aa0852 100644 --- a/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/CopyWorldRegenerator.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Random; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -24,6 +25,7 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; import org.bukkit.entity.Villager; +import org.bukkit.generator.ChunkGenerator; import org.bukkit.inventory.InventoryHolder; import org.bukkit.material.Colorable; import org.bukkit.scheduler.BukkitRunnable; @@ -34,6 +36,7 @@ import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.database.objects.IslandDeletion; +import world.bentobox.bentobox.util.MyBiomeGrid; /** * Regenerates by using a seed world. The seed world is created using the same generator as the game @@ -63,6 +66,10 @@ protected CopyWorldRegenerator() { @Override public CompletableFuture regenerate(GameModeAddon gm, IslandDeletion di, World world) { + return gm.isUsesNewChunkGeneration() ? regenerateCopy(gm, di, world) : regenerateSimple(gm, di, world); + } + + public CompletableFuture regenerateCopy(GameModeAddon gm, IslandDeletion di, World world) { CompletableFuture bigFuture = new CompletableFuture<>(); new BukkitRunnable() { private int chunkX = di.getMinXChunk(); @@ -263,4 +270,98 @@ else if (blockState instanceof Banner banner && b instanceof Banner toBanner) { toBanner.setPatterns(banner.getPatterns()); } } + + + public CompletableFuture regenerateSimple(GameModeAddon gm, IslandDeletion di, World world) { + CompletableFuture bigFuture = new CompletableFuture<>(); + new BukkitRunnable() { + private int chunkX = di.getMinXChunk(); + private int chunkZ = di.getMinZChunk(); + CompletableFuture currentTask = CompletableFuture.completedFuture(null); + + @Override + public void run() { + if (!currentTask.isDone()) return; + if (isEnded(chunkX)) { + cancel(); + bigFuture.complete(null); + return; + } + List> newTasks = new ArrayList<>(); + for (int i = 0; i < plugin.getSettings().getDeleteSpeed(); i++) { + if (isEnded(chunkX)) { + break; + } + final int x = chunkX; + final int z = chunkZ; + newTasks.add(regenerateChunk(gm, di, world, x, z)); + chunkZ++; + if (chunkZ > di.getMaxZChunk()) { + chunkZ = di.getMinZChunk(); + chunkX++; + } + } + currentTask = CompletableFuture.allOf(newTasks.toArray(new CompletableFuture[0])); + } + + private boolean isEnded(int chunkX) { + return chunkX > di.getMaxXChunk(); + } + }.runTaskTimer(plugin, 0L, 20L); + return bigFuture; + } + + @SuppressWarnings("deprecation") + private CompletableFuture regenerateChunk(GameModeAddon gm, IslandDeletion di, World world, int chunkX, int chunkZ) { + CompletableFuture chunkFuture = PaperLib.getChunkAtAsync(world, chunkX, chunkZ); + CompletableFuture invFuture = chunkFuture.thenAccept(chunk -> + Arrays.stream(chunk.getTileEntities()).filter(InventoryHolder.class::isInstance) + .filter(te -> di.inBounds(te.getLocation().getBlockX(), te.getLocation().getBlockZ())) + .forEach(te -> ((InventoryHolder) te).getInventory().clear()) + ); + CompletableFuture entitiesFuture = chunkFuture.thenAccept(chunk -> { + for (Entity e : chunk.getEntities()) { + if (!(e instanceof Player)) { + e.remove(); + } + } + }); + CompletableFuture copyFuture = chunkFuture.thenApply(chunk -> { + // Reset blocks + MyBiomeGrid grid = new MyBiomeGrid(chunk.getWorld().getEnvironment()); + ChunkGenerator cg = gm.getDefaultWorldGenerator(chunk.getWorld().getName(), "delete"); + // Will be null if use-own-generator is set to true + if (cg != null) { + ChunkGenerator.ChunkData cd = cg.generateChunkData(chunk.getWorld(), new Random(), chunk.getX(), chunk.getZ(), grid); + copyChunkDataToChunk(chunk, cd, grid, di.getBox()); + } + return chunk; + }); + CompletableFuture postCopyFuture = copyFuture.thenAccept(chunk -> + // Remove all entities in chunk, including any dropped items as a result of clearing the blocks above + Arrays.stream(chunk.getEntities()).filter(e -> !(e instanceof Player) && di.inBounds(e.getLocation().getBlockX(), e.getLocation().getBlockZ())).forEach(Entity::remove)); + return CompletableFuture.allOf(invFuture, entitiesFuture, postCopyFuture); + } + + @SuppressWarnings("deprecation") + private void copyChunkDataToChunk(Chunk chunk, ChunkGenerator.ChunkData chunkData, ChunkGenerator.BiomeGrid biomeGrid, BoundingBox limitBox) { + double baseX = chunk.getX() << 4; + double baseZ = chunk.getZ() << 4; + int minHeight = chunk.getWorld().getMinHeight(); + int maxHeight = chunk.getWorld().getMaxHeight(); + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + if (!limitBox.contains(baseX + x, 0, baseZ + z)) { + continue; + } + for (int y = minHeight; y < maxHeight; y++) { + setBlockInNativeChunk(chunk, x, y, z, chunkData.getBlockData(x, y, z), false); + // 3D biomes, 4 blocks separated + if (x % 4 == 0 && y % 4 == 0 && z % 4 == 0) { + chunk.getBlock(x, y, z).setBiome(biomeGrid.getBiome(x, y, z)); + } + } + } + } + } } From 2c283ae3a9a5cd0f08392d5b748949961687bb7a Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 26 Feb 2023 17:48:37 -0800 Subject: [PATCH 06/26] Javadoc and other cleanup from code analysis (#2099) --- .../api/addons/request/package-info.java | 2 +- .../api/localization/BentoBoxLocale.java | 2 +- .../bentobox/bentobox/api/user/User.java | 4 - .../bentobox/blueprints/package-info.java | 2 +- .../bentobox/bentobox/database/Database.java | 2 +- .../bentobox/database/objects/Island.java | 8 -- .../bentobox/database/objects/Players.java | 2 +- .../database/sql/SQLDatabaseHandler.java | 2 +- .../bentobox/hooks/LangUtilsHook.java | 93 +++++++++++----- .../bentobox/listeners/BannedCommands.java | 3 +- .../flags/clicklisteners/GeoMobLimitTab.java | 4 +- .../flags/protection/BreedingListener.java | 2 +- .../flags/protection/LockAndBanListener.java | 2 +- .../teleports/EntityTeleportListener.java | 4 +- .../teleports/PlayerTeleportListener.java | 4 +- .../bentobox/managers/AddonsManager.java | 1 - .../bentobox/managers/LocalesManager.java | 2 +- .../bentobox/managers/PlayersManager.java | 2 +- .../DefaultNewIslandLocationStrategy.java | 2 +- .../bentobox/bentobox/util/MyBiomeGrid.java | 26 ++--- .../world/bentobox/bentobox/util/Util.java | 2 +- .../teleport/ClosestSafeSpotTeleport.java | 2 +- .../world/bentobox/bentobox/SettingsTest.java | 1 - .../api/addons/AddonClassLoaderTest.java | 34 ++---- .../api/addons/AddonDescriptionTest.java | 1 - .../api/commands/DefaultHelpCommandTest.java | 1 - .../commands/DelayedTeleportCommandTest.java | 1 - .../api/commands/HiddenCommandTest.java | 1 - .../admin/AdminDeleteCommandTest.java | 1 - .../admin/AdminGetrankCommandTest.java | 16 +-- .../commands/admin/AdminInfoCommandTest.java | 2 - .../admin/AdminRegisterCommandTest.java | 1 - .../admin/AdminResetFlagsCommandTest.java | 2 - .../admin/AdminSetrankCommandTest.java | 2 - .../admin/AdminSetspawnCommandTest.java | 1 - .../admin/AdminSettingsCommandTest.java | 2 - .../admin/AdminSwitchCommandTest.java | 2 - .../admin/AdminTeleportCommandTest.java | 8 +- .../admin/AdminUnregisterCommandTest.java | 1 - .../AdminBlueprintCopyCommandTest.java | 2 - .../AdminBlueprintDeleteCommandTest.java | 2 - .../AdminBlueprintLoadCommandTest.java | 3 - .../AdminBlueprintSaveCommandTest.java | 2 - .../AdminBlueprintsListCommandTest.java | 4 - .../admin/purge/AdminPurgeCommandTest.java | 1 - .../purge/AdminPurgeUnownedCommandTest.java | 1 - .../admin/range/AdminRangeCommandTest.java | 1 - .../range/AdminRangeDisplayCommandTest.java | 1 - .../range/AdminRangeResetCommandTest.java | 1 - .../admin/range/AdminRangeSetCommandTest.java | 1 - .../admin/team/AdminTeamAddCommandTest.java | 1 - .../team/AdminTeamDisbandCommandTest.java | 1 - .../admin/team/AdminTeamKickCommandTest.java | 1 - .../team/AdminTeamSetownerCommandTest.java | 1 - .../island/IslandBanlistCommandTest.java | 1 - .../island/IslandCreateCommandTest.java | 5 - .../island/IslandExpelCommandTest.java | 1 - .../commands/island/IslandGoCommandTest.java | 1 - .../island/IslandHomesCommandTest.java | 1 - .../island/IslandInfoCommandTest.java | 2 - .../island/IslandNearCommandTest.java | 2 - .../island/IslandResetCommandTest.java | 1 - .../island/IslandSethomeCommandTest.java | 1 - .../island/IslandSpawnCommandTest.java | 2 - .../island/IslandUnbanCommandTest.java | 1 - .../island/team/IslandTeamCommandTest.java | 2 - .../team/IslandTeamCoopCommandTest.java | 1 - .../IslandTeamInviteAcceptCommandTest.java | 2 - .../team/IslandTeamInviteCommandTest.java | 1 - .../team/IslandTeamKickCommandTest.java | 1 - .../team/IslandTeamLeaveCommandTest.java | 1 - .../team/IslandTeamSetownerCommandTest.java | 2 - .../team/IslandTeamTrustCommandTest.java | 1 - .../team/IslandTeamUncoopCommandTest.java | 1 - .../team/IslandTeamUntrustCommandTest.java | 1 - .../events/addon/AddonEnableEventTest.java | 1 - .../api/events/island/IslandEventTest.java | 87 ++++----------- .../bentobox/bentobox/api/flags/FlagTest.java | 2 - .../clicklisteners/IslandToggleClickTest.java | 1 - .../clicklisteners/WorldToggleClickTest.java | 1 - .../api/localization/BentoBoxLocaleTest.java | 1 - .../bentobox/api/panels/PanelTest.java | 2 - .../api/panels/builders/PanelBuilderTest.java | 1 - .../bentobox/api/user/NotifierTest.java | 3 - .../blueprints/BlueprintPasterTest.java | 1 - .../commands/BentoBoxReloadCommandTest.java | 2 - .../bentobox/database/DatabaseTest.java | 57 +++------- .../adapters/ItemStackTypeAdapterTest.java | 6 -- .../database/objects/IslandDeletionTest.java | 1 - .../bentobox/database/objects/IslandTest.java | 8 +- .../database/objects/PlayersTest.java | 1 - .../adapters/LogEntryListAdapterTest.java | 3 +- .../sql/mysql/MySQLDatabaseConnectorTest.java | 3 - .../sql/mysql/MySQLDatabaseHandlerTest.java | 26 +---- .../yaml/YamlDatabaseHandlerTest.java | 32 +----- .../placeholders/PlaceholderAPIHookTest.java | 1 - .../listeners/BlockEndDragonTest.java | 2 - .../listeners/JoinLeaveListenerTest.java | 8 +- .../listeners/PanelListenerManagerTest.java | 3 - .../PortalTeleportationListenerTest.java | 1 - .../StandardSpawnProtectionListenerTest.java | 2 - .../listeners/flags/AbstractCommonSetup.java | 3 +- .../clicklisteners/GeoMobLimitTabTest.java | 1 - .../BlockInteractionListenerTest.java | 1 - .../protection/BreakBlocksListenerTest.java | 1 - .../flags/protection/BucketListenerTest.java | 1 - .../flags/protection/EggListenerTest.java | 1 - .../flags/protection/ElytraListenerTest.java | 1 - .../EntityInteractListenerTest.java | 1 - .../ExperiencePickupListenerTest.java | 1 - .../flags/protection/HurtingListenerTest.java | 1 - .../protection/InventoryListenerTest.java | 1 - .../protection/LockAndBanListenerTest.java | 1 - .../protection/PlaceBlocksListenerTest.java | 1 - .../protection/ThrowingListenerTest.java | 1 - .../flags/settings/MobSpawnListenerTest.java | 61 +++-------- .../flags/settings/PVPListenerTest.java | 1 - .../CleanSuperFlatListenerTest.java | 1 - .../CoarseDirtTillingListenerTest.java | 2 - .../worldsettings/EnterExitListenerTest.java | 1 - .../InvincibleVisitorsListenerTest.java | 1 - .../IslandRespawnListenerTest.java | 1 - .../OfflineGrowthListenerTest.java | 12 +-- .../OfflineRedstoneListenerTest.java | 4 +- .../PetTeleportListenerTest.java | 1 - .../worldsettings/RemoveMobsListenerTest.java | 1 - .../VisitorKeepInventoryListenerTest.java | 2 - .../worldsettings/WitherListenerTest.java | 2 - .../teleports/EntityTeleportListenerTest.java | 11 -- .../lists/GameModePlaceholderTest.java | 1 - .../bentobox/managers/AddonsManagerTest.java | 16 +-- .../BlueprintClipboardManagerTest.java | 38 ++----- .../managers/BlueprintsManagerTest.java | 102 +++++++----------- .../IslandChunkDeletionManagerTest.java | 1 - .../managers/IslandDeletionManagerTest.java | 2 - .../managers/IslandWorldManagerTest.java | 1 - .../bentobox/managers/IslandsManagerTest.java | 3 - .../bentobox/managers/LocalesManagerTest.java | 17 --- .../bentobox/managers/PlayersManagerTest.java | 2 - .../bentobox/managers/RanksManagerTest.java | 1 - .../DefaultNewIslandLocationStrategyTest.java | 2 - .../managers/island/NewIslandTest.java | 10 -- .../panels/BlueprintManagementPanelTest.java | 2 - .../panels/IslandCreationPanelTest.java | 1 - .../bentobox/panels/LanguagePanelTest.java | 2 - .../bentobox/util/ItemParserTest.java | 27 ++--- .../bentobox/bentobox/util/UtilTest.java | 60 +++-------- .../util/teleport/SafeSpotTeleportTest.java | 2 - 148 files changed, 264 insertions(+), 703 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/addons/request/package-info.java b/src/main/java/world/bentobox/bentobox/api/addons/request/package-info.java index f643446bd..e19d9946a 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/request/package-info.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/request/package-info.java @@ -3,7 +3,7 @@ *

* Addons can expose data that they want to expose. To access it, call this class with the appropriate addon name, * the label for the data that is requested and if required, a map of key-value pairs that will be given to the addon. - * + *

* Note Since BentoBox 1.17.0, Addons can be declared as Pladdons and be loaded by the Bukkit classloader. This * enables Plugins to access Addon methods directly so this API is not required. *

diff --git a/src/main/java/world/bentobox/bentobox/api/localization/BentoBoxLocale.java b/src/main/java/world/bentobox/bentobox/api/localization/BentoBoxLocale.java index 4d9a0674a..e13c58545 100644 --- a/src/main/java/world/bentobox/bentobox/api/localization/BentoBoxLocale.java +++ b/src/main/java/world/bentobox/bentobox/api/localization/BentoBoxLocale.java @@ -163,7 +163,7 @@ public YamlConfiguration getConfig() { /** * Returns the list of prefixes available in this locale. - * @return list of prefixes available in this locale. + * @return Set of prefixes available in this locale. * @since 1.13.0 */ @NonNull diff --git a/src/main/java/world/bentobox/bentobox/api/user/User.java b/src/main/java/world/bentobox/bentobox/api/user/User.java index 68dd641e3..2bcba88ca 100644 --- a/src/main/java/world/bentobox/bentobox/api/user/User.java +++ b/src/main/java/world/bentobox/bentobox/api/user/User.java @@ -206,7 +206,6 @@ public Set getEffectivePermissions() { /** * Get the user's inventory * @return player's inventory - * @throws {@link NullPointerException} - if user is not a player */ @NonNull public PlayerInventory getInventory() { @@ -216,7 +215,6 @@ public PlayerInventory getInventory() { /** * Get the user's location * @return location - * @throws {@link NullPointerException} - if user is not a player */ @NonNull public Location getLocation() { @@ -252,7 +250,6 @@ public boolean isPlayer() { * Use {@link #isOfflinePlayer()} before calling this method * @return the offline player * @since 1.3.0 - * @throws {@link NullPointerException} - if user is not an offline player */ @NonNull public OfflinePlayer getOfflinePlayer() { @@ -580,7 +577,6 @@ public void teleport(Location location) { /** * Gets the current world this entity resides in * @return World - world - * @throws {@link NullPointerException} - if user is not a player */ @NonNull public World getWorld() { diff --git a/src/main/java/world/bentobox/bentobox/blueprints/package-info.java b/src/main/java/world/bentobox/bentobox/blueprints/package-info.java index 36d90d13a..65375e721 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/package-info.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/package-info.java @@ -1,6 +1,6 @@ /** * This package contains non-API classes that handle Blueprints. - * + *

* Blueprints are BentoBox's version of schematics, but contain * additional useful info. * diff --git a/src/main/java/world/bentobox/bentobox/database/Database.java b/src/main/java/world/bentobox/bentobox/database/Database.java index 0eae05e35..0f5679c63 100644 --- a/src/main/java/world/bentobox/bentobox/database/Database.java +++ b/src/main/java/world/bentobox/bentobox/database/Database.java @@ -85,7 +85,7 @@ public T loadObject(String uniqueId) { /** * Save object async. Saving may be done sync, depending on the underlying database. * @param instance to save - * @return true if no immediate errors. If async, errors may occur later. + * @return Completable future that results in true if successful. * @since 1.13.0 */ public CompletableFuture saveObjectAsync(T instance) { diff --git a/src/main/java/world/bentobox/bentobox/database/objects/Island.java b/src/main/java/world/bentobox/bentobox/database/objects/Island.java index 58b7c493b..1c2fa534d 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/Island.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/Island.java @@ -724,7 +724,6 @@ public boolean inIslandSpace(int x, int z) { * @param location - location * @return true if in island space */ - @SuppressWarnings("ConstantConditions") public boolean inIslandSpace(Location location) { return Util.sameWorld(this.world, location.getWorld()) && (location.getWorld().getEnvironment().equals(Environment.NORMAL) || @@ -747,7 +746,6 @@ public boolean inIslandSpace(Pair blockCoordinates) { * @return a {@link BoundingBox} of the full island space. * @since 1.5.2 */ - @SuppressWarnings("ConstantConditions") @NonNull public BoundingBox getBoundingBox() { return this.getBoundingBox(Environment.NORMAL); @@ -778,7 +776,6 @@ public BoundingBox getBoundingBox(Environment environment) else if (Environment.THE_END.equals(environment) && this.isEndIslandEnabled()) { // If end world is generated, return end island bounding box. - //noinspection ConstantConditions boundingBox = new BoundingBox(this.getMinX(), this.getEndWorld().getMinHeight(), this.getMinZ(), @@ -789,7 +786,6 @@ else if (Environment.THE_END.equals(environment) && this.isEndIslandEnabled()) else if (Environment.NETHER.equals(environment) && this.isNetherIslandEnabled()) { // If nether world is generated, return nether island bounding box. - //noinspection ConstantConditions boundingBox = new BoundingBox(this.getMinX(), this.getNetherWorld().getMinHeight(), this.getMinZ(), @@ -909,7 +905,6 @@ public boolean isSpawn() { * @param target location to check, not null * @return {@code true} if this location is within this island's protected area, {@code false} otherwise. */ - @SuppressWarnings("ConstantConditions") public boolean onIsland(@NonNull Location target) { return Util.sameWorld(this.world, target.getWorld()) && (target.getWorld().getEnvironment().equals(Environment.NORMAL) || @@ -926,7 +921,6 @@ public boolean onIsland(@NonNull Location target) { * @return a {@link BoundingBox} of this island's protected area. * @since 1.5.2 */ - @SuppressWarnings("ConstantConditions") @NonNull public BoundingBox getProtectionBoundingBox() { return this.getProtectionBoundingBox(Environment.NORMAL); @@ -958,7 +952,6 @@ public BoundingBox getProtectionBoundingBox(Environment environment) else if (Environment.THE_END.equals(environment) && this.isEndIslandEnabled()) { // If end world is generated, return end island bounding box. - //noinspection ConstantConditions boundingBox = new BoundingBox(this.getMinProtectedX(), this.getEndWorld().getMinHeight(), this.getMinProtectedZ(), @@ -969,7 +962,6 @@ else if (Environment.THE_END.equals(environment) && this.isEndIslandEnabled()) else if (Environment.NETHER.equals(environment) && this.isNetherIslandEnabled()) { // If nether world is generated, return nether island bounding box. - //noinspection ConstantConditions boundingBox = new BoundingBox(this.getMinProtectedX(), this.getNetherWorld().getMinHeight(), this.getMinProtectedZ(), diff --git a/src/main/java/world/bentobox/bentobox/database/objects/Players.java b/src/main/java/world/bentobox/bentobox/database/objects/Players.java index 7590147cb..5e64c9f5d 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/Players.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/Players.java @@ -119,7 +119,7 @@ public Location getHomeLocation(World world, int number) { /** * @param world - world - * @return List of home locations + * @return Map of home locations * @deprecated Homes are stored in the island object now */ @Deprecated(since="1.18.0", forRemoval=true) diff --git a/src/main/java/world/bentobox/bentobox/database/sql/SQLDatabaseHandler.java b/src/main/java/world/bentobox/bentobox/database/sql/SQLDatabaseHandler.java index 961606b1e..dfbe923c6 100644 --- a/src/main/java/world/bentobox/bentobox/database/sql/SQLDatabaseHandler.java +++ b/src/main/java/world/bentobox/bentobox/database/sql/SQLDatabaseHandler.java @@ -225,7 +225,7 @@ public T loadObject(@NonNull String uniqueId) * Return the object decoded from JSON or null if there is an error * @param uniqueId - unique Id of object used in error reporting * @param preparedStatement - database statement to execute - * @return + * @return T */ private T getObject(@NonNull String uniqueId, PreparedStatement preparedStatement) { try (ResultSet resultSet = preparedStatement.executeQuery()) diff --git a/src/main/java/world/bentobox/bentobox/hooks/LangUtilsHook.java b/src/main/java/world/bentobox/bentobox/hooks/LangUtilsHook.java index 45629ffe8..4fabee528 100644 --- a/src/main/java/world/bentobox/bentobox/hooks/LangUtilsHook.java +++ b/src/main/java/world/bentobox/bentobox/hooks/LangUtilsHook.java @@ -91,7 +91,7 @@ private static String getUserLocale(User user) { /** * Get the item display name. - * + *

* If the item contains a custom name, return its custom name. * If the item itself does not have a custom name, the material * name will be translated and returned. @@ -515,29 +515,74 @@ public static String getPredefinedTropicalFishName(TropicalFishBucketMeta meta, int variant = (pcol & 255) << 24 | (bcol & 255) << 16 | (patt & 255) << 8 | type; switch (variant) { - case 117506305: return "Anemone"; - case 117899265: return "Black Tang"; - case 185008129: return "Blue Tang"; - case 117441793: return "Butterflyfish"; - case 118161664: return "Cichlid"; - case 65536 : return "Clownfish"; - case 50726144 : return "Cotton Candy Betta"; - case 67764993 : return "Dottyback"; - case 234882305: return "Emperor Red Snapper"; - case 67110144 : return "Goatfish"; - case 117441025: return "Moorish Idol"; - case 16778497 : return "Ornate Butterflyfish"; - case 101253888: return "Parrotfish"; - case 50660352 : return "Queen Angelfish"; - case 918529 : return "Red Cichlid"; - case 235340288: return "Red Lipped Blenny"; - case 918273 : return "Red Snapper"; - case 67108865 : return "Threadfin"; - case 917504 : return "Tomato Clownfish"; - case 459008 : return "Triggerfish"; - case 67699456 : return "Yellowtail Parrotfish"; - case 67371009 : return "Yellow Tang"; - default : break; + case 117506305 -> { + return "Anemone"; + } + case 117899265 -> { + return "Black Tang"; + } + case 185008129 -> { + return "Blue Tang"; + } + case 117441793 -> { + return "Butterflyfish"; + } + case 118161664 -> { + return "Cichlid"; + } + case 65536 -> { + return "Clownfish"; + } + case 50726144 -> { + return "Cotton Candy Betta"; + } + case 67764993 -> { + return "Dottyback"; + } + case 234882305 -> { + return "Emperor Red Snapper"; + } + case 67110144 -> { + return "Goatfish"; + } + case 117441025 -> { + return "Moorish Idol"; + } + case 16778497 -> { + return "Ornate Butterflyfish"; + } + case 101253888 -> { + return "Parrotfish"; + } + case 50660352 -> { + return "Queen Angelfish"; + } + case 918529 -> { + return "Red Cichlid"; + } + case 235340288 -> { + return "Red Lipped Blenny"; + } + case 918273 -> { + return "Red Snapper"; + } + case 67108865 -> { + return "Threadfin"; + } + case 917504 -> { + return "Tomato Clownfish"; + } + case 459008 -> { + return "Triggerfish"; + } + case 67699456 -> { + return "Yellowtail Parrotfish"; + } + case 67371009 -> { + return "Yellow Tang"; + } + default -> { + } } } return null; diff --git a/src/main/java/world/bentobox/bentobox/listeners/BannedCommands.java b/src/main/java/world/bentobox/bentobox/listeners/BannedCommands.java index dcbf77f76..c644eb1a5 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/BannedCommands.java +++ b/src/main/java/world/bentobox/bentobox/listeners/BannedCommands.java @@ -65,7 +65,8 @@ private boolean checkCmd(String cmd, String[] args) { if (bannedSplit.length <= args.length) { for (int i = 0; i < bannedSplit.length; i++) { if (!bannedSplit[i].equals(args[i])) { - banned = false; + banned = false; + break; } } } diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTab.java b/src/main/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTab.java index 84b2d759c..ce37e7635 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTab.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTab.java @@ -34,11 +34,11 @@ public class GeoMobLimitTab implements Tab, ClickHandler { /** * A list of all living entity types, minus some */ - private static final List LIVING_ENTITY_TYPES = Collections.unmodifiableList(Arrays.stream(EntityType.values()) + private static final List LIVING_ENTITY_TYPES = Arrays.stream(EntityType.values()) .filter(EntityType::isAlive) .filter(t -> !(t.equals(EntityType.PLAYER) || t.equals(EntityType.GIANT) || t.equals(EntityType.ARMOR_STAND))) .sorted(Comparator.comparing(EntityType::name)) - .toList()); + .toList(); public enum EntityLimitTabType { GEO_LIMIT, diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListener.java index 78526ec6a..6d61d761a 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListener.java @@ -32,7 +32,7 @@ public class BreedingListener extends FlagListener { /** * A list of items that cause breeding if a player has them in their hand and they click an animal * This list may need to be extended with future versions of Minecraft. - * See this Minecraft Wiki page for reference: https://minecraft.gamepedia.com/Breeding#Breeding_foods. + * See this Minecraft Wiki page for reference: .... */ private static final Map> BREEDING_ITEMS; static { diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListener.java index 9cca062cd..ad20ba54b 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListener.java @@ -135,7 +135,7 @@ private CheckResult check(@NonNull Player player, Location loc) * Checks if a player is banned from this location and notifies them if so * @param player - player * @param loc - location to check - * @return true if banned + * @return CheckResult */ private CheckResult checkAndNotify(@NonNull Player player, Location loc) { diff --git a/src/main/java/world/bentobox/bentobox/listeners/teleports/EntityTeleportListener.java b/src/main/java/world/bentobox/bentobox/listeners/teleports/EntityTeleportListener.java index 5e188f2b7..490694fa1 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/teleports/EntityTeleportListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/teleports/EntityTeleportListener.java @@ -51,10 +51,10 @@ public EntityTeleportListener(@NonNull BentoBox bentoBox) /** * This listener checks entity portal events and triggers appropriate methods to transfer * entities to the correct location in other dimension. - * + *

* This event is triggered when entity is about to being teleported because of contact with the * nether portal or end gateway portal (exit portal triggers respawn). - * + *

* This event is not called if nether/end is disabled in server settings. * * @param event the entity portal event. diff --git a/src/main/java/world/bentobox/bentobox/listeners/teleports/PlayerTeleportListener.java b/src/main/java/world/bentobox/bentobox/listeners/teleports/PlayerTeleportListener.java index fa0ebfc80..1f4b2cbfc 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/teleports/PlayerTeleportListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/teleports/PlayerTeleportListener.java @@ -63,10 +63,10 @@ public PlayerTeleportListener(@NonNull BentoBox plugin) /** * This listener checks player portal events and triggers appropriate methods to transfer * players to the correct location in other dimension. - * + *

* This event is triggered when player is about to being teleported because of contact with the * nether portal or end gateway portal (exit portal triggers respawn). - * + *

* This event is not called if nether/end is disabled in server settings. * * @param event the player portal event. diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index 4fd612efe..a9511de82 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -346,7 +346,6 @@ private void enableAddon(Addon addon) { /** * Create seed worlds, which are used for deletion - * @param gameMode */ private void createSeedWorlds(GameModeAddon gameMode) { if (gameMode.getOverWorld() != null) { diff --git a/src/main/java/world/bentobox/bentobox/managers/LocalesManager.java b/src/main/java/world/bentobox/bentobox/managers/LocalesManager.java index d2ee1dc54..cb54aa29d 100644 --- a/src/main/java/world/bentobox/bentobox/managers/LocalesManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/LocalesManager.java @@ -120,7 +120,7 @@ public String getOrDefault(String reference, String defaultText) { /** * Gets the list of prefixes from the user's locale, the server's locale and the en-US locale file. * @param user the user to get the locale, not null. - * @return the list of prefixes from the user's locale, the server's locale and the en-US locale file. + * @return the set of prefixes from the user's locale, the server's locale and the en-US locale file. * @since 1.13.0 */ public Set getAvailablePrefixes(@NonNull User user) { diff --git a/src/main/java/world/bentobox/bentobox/managers/PlayersManager.java b/src/main/java/world/bentobox/bentobox/managers/PlayersManager.java index 1cf40a945..cad7a15de 100644 --- a/src/main/java/world/bentobox/bentobox/managers/PlayersManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/PlayersManager.java @@ -284,7 +284,7 @@ public Location getHomeLocation(World world, UUID playerUUID) { /** * Provides all home locations for player * @param playerUUID - the player's UUID - * @return List of home locations + * @return Map of home locations * @deprecated Use {@link IslandsManager#getHomeLocations(world.bentobox.bentobox.database.objects.Island)} */ @Deprecated(since="1.18.0", forRemoval=true) diff --git a/src/main/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategy.java b/src/main/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategy.java index 26593d042..46994fac7 100644 --- a/src/main/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategy.java +++ b/src/main/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategy.java @@ -70,7 +70,7 @@ public Location getNextLocation(World world) { * Checks if there is an island or blocks at this location * * @param location - the location - * @return Result enum if island found, null if blocks found, false if nothing found + * @return Result enum indicated what was found or not found */ protected Result isIsland(Location location) { // Quick check diff --git a/src/main/java/world/bentobox/bentobox/util/MyBiomeGrid.java b/src/main/java/world/bentobox/bentobox/util/MyBiomeGrid.java index 56d17a8ce..c776b715b 100644 --- a/src/main/java/world/bentobox/bentobox/util/MyBiomeGrid.java +++ b/src/main/java/world/bentobox/bentobox/util/MyBiomeGrid.java @@ -18,22 +18,18 @@ public class MyBiomeGrid implements BiomeGrid { Map map = new HashMap<>(); private Biome defaultBiome; public MyBiomeGrid(Environment environment) { - switch(environment) { - case NETHER: - try { - // 1.16 onwards - defaultBiome = Biome.valueOf("NETHER_WASTES"); - } catch (Exception e) { - // Before 1.16 - defaultBiome = Biome.valueOf("NETHER"); + switch (environment) { + case NETHER -> { + try { + // 1.16 onwards + defaultBiome = Biome.valueOf("NETHER_WASTES"); + } catch (Exception e) { + // Before 1.16 + defaultBiome = Biome.valueOf("NETHER"); + } } - break; - case THE_END: - defaultBiome = Biome.THE_END; - break; - default: - defaultBiome = Biome.PLAINS; - break; + case THE_END -> defaultBiome = Biome.THE_END; + default -> defaultBiome = Biome.PLAINS; } } diff --git a/src/main/java/world/bentobox/bentobox/util/Util.java b/src/main/java/world/bentobox/bentobox/util/Util.java index 7a633bd31..822bf7ef7 100644 --- a/src/main/java/world/bentobox/bentobox/util/Util.java +++ b/src/main/java/world/bentobox/bentobox/util/Util.java @@ -467,7 +467,7 @@ public static BlockStateSnapshotResult getBlockState(@NonNull Block block, boole /** * Detects if the current MC version is at least the following version. - * + *

* Assumes 0 patch version. * * @param minor Min Minor Version diff --git a/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java b/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java index 8a2965b3b..d25bd0ac0 100644 --- a/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java +++ b/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java @@ -276,7 +276,7 @@ private void scanAndPopulateBlockQueue(ChunkSnapshot chunkSnapshot) /** * This method finishes the chunk loading task and checks from all remaining positions in block queue * to find the best location for teleportation. - * + *

* This method stops position finding task and process teleporation. */ private void finishTask() diff --git a/src/test/java/world/bentobox/bentobox/SettingsTest.java b/src/test/java/world/bentobox/bentobox/SettingsTest.java index b8e464c63..b482dc96c 100644 --- a/src/test/java/world/bentobox/bentobox/SettingsTest.java +++ b/src/test/java/world/bentobox/bentobox/SettingsTest.java @@ -28,7 +28,6 @@ public class SettingsTest { private Settings s; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/addons/AddonClassLoaderTest.java b/src/test/java/world/bentobox/bentobox/api/addons/AddonClassLoaderTest.java index 8a501b652..3664f7e46 100644 --- a/src/test/java/world/bentobox/bentobox/api/addons/AddonClassLoaderTest.java +++ b/src/test/java/world/bentobox/bentobox/api/addons/AddonClassLoaderTest.java @@ -49,7 +49,7 @@ @PrepareForTest( { BentoBox.class, Bukkit.class }) public class AddonClassLoaderTest { - private enum MandatoryTags { + private enum mandatoryTags { MAIN, NAME, VERSION, @@ -76,7 +76,6 @@ private enum MandatoryTags { private BentoBox plugin; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -91,7 +90,7 @@ public void setUp() throws Exception { } - public void makeAddon(List missingTags) throws IOException { + public void makeAddon(List missingTags) throws IOException { // Make the addon dataFolder = new File("dataFolder"); jarFile = new File("addon.jar"); @@ -112,18 +111,18 @@ public void makeAddon(List missingTags) throws IOException { Files.deleteIfExists(ymlFile.toPath()); } - private YamlConfiguration getYaml(List missingTags) { + private YamlConfiguration getYaml(List missingTags) { YamlConfiguration r = new YamlConfiguration(); - if (!missingTags.contains(MandatoryTags.NAME)) { + if (!missingTags.contains(mandatoryTags.NAME)) { r.set("name", "TestAddon"); } - if (!missingTags.contains(MandatoryTags.MAIN)) { + if (!missingTags.contains(mandatoryTags.MAIN)) { r.set("main", "world.bentobox.test.Test"); } - if (!missingTags.contains(MandatoryTags.VERSION)) { + if (!missingTags.contains(mandatoryTags.VERSION)) { r.set("version", "1.0.0"); } - if (!missingTags.contains(MandatoryTags.AUTHORS)) { + if (!missingTags.contains(mandatoryTags.AUTHORS)) { r.set("authors", "tastybento"); } r.set("metrics", false); @@ -174,7 +173,6 @@ private void addFile(byte[] buffer, FileOutputStream stream, JarOutputStream out } /** - * @throws java.lang.Exception */ @After public void TearDown() throws IOException { @@ -199,7 +197,6 @@ public void onDisable() { } /** * Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#AddonClassLoader(world.bentobox.bentobox.managers.AddonsManager, org.bukkit.configuration.file.YamlConfiguration, java.io.File, java.lang.ClassLoader)}. - * @throws MalformedURLException */ @Test public void testAddonClassLoader() throws MalformedURLException { @@ -208,7 +205,6 @@ public void testAddonClassLoader() throws MalformedURLException { /** * Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#asDescription(org.bukkit.configuration.file.YamlConfiguration)}. - * @throws InvalidAddonDescriptionException */ @Test public void testAsDescription() throws InvalidAddonDescriptionException { @@ -232,11 +228,10 @@ public void testAsDescription() throws InvalidAddonDescriptionException { /** * Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#asDescription(org.bukkit.configuration.file.YamlConfiguration)}. - * @throws InvalidAddonDescriptionException */ @Test public void testAsDescriptionNoName() { - YamlConfiguration yml = this.getYaml(List.of(MandatoryTags.NAME)); + YamlConfiguration yml = this.getYaml(List.of(mandatoryTags.NAME)); try { AddonClassLoader.asDescription(yml); } catch (InvalidAddonDescriptionException e) { @@ -246,11 +241,10 @@ public void testAsDescriptionNoName() { /** * Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#asDescription(org.bukkit.configuration.file.YamlConfiguration)}. - * @throws InvalidAddonDescriptionException */ @Test public void testAsDescriptionNoAuthors() { - YamlConfiguration yml = this.getYaml(List.of(MandatoryTags.AUTHORS)); + YamlConfiguration yml = this.getYaml(List.of(mandatoryTags.AUTHORS)); try { AddonClassLoader.asDescription(yml); } catch (InvalidAddonDescriptionException e) { @@ -260,11 +254,10 @@ public void testAsDescriptionNoAuthors() { /** * Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#asDescription(org.bukkit.configuration.file.YamlConfiguration)}. - * @throws InvalidAddonDescriptionException */ @Test public void testAsDescriptionNoVersion() { - YamlConfiguration yml = this.getYaml(List.of(MandatoryTags.VERSION)); + YamlConfiguration yml = this.getYaml(List.of(mandatoryTags.VERSION)); try { AddonClassLoader.asDescription(yml); } catch (InvalidAddonDescriptionException e) { @@ -274,11 +267,10 @@ public void testAsDescriptionNoVersion() { /** * Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#asDescription(org.bukkit.configuration.file.YamlConfiguration)}. - * @throws InvalidAddonDescriptionException */ @Test public void testAsDescriptionNoMain() { - YamlConfiguration yml = this.getYaml(List.of(MandatoryTags.MAIN)); + YamlConfiguration yml = this.getYaml(List.of(mandatoryTags.MAIN)); try { AddonClassLoader.asDescription(yml); } catch (InvalidAddonDescriptionException e) { @@ -288,7 +280,6 @@ public void testAsDescriptionNoMain() { /** * Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#findClass(java.lang.String)}. - * @throws MalformedURLException */ @Test public void testFindClassString() throws MalformedURLException { @@ -299,7 +290,6 @@ public void testFindClassString() throws MalformedURLException { /** * Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#findClass(java.lang.String, boolean)}. - * @throws MalformedURLException */ @Test public void testFindClassStringBoolean() throws MalformedURLException { @@ -310,7 +300,6 @@ public void testFindClassStringBoolean() throws MalformedURLException { /** * Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#getAddon()}. - * @throws MalformedURLException */ @Test public void testGetAddon() throws MalformedURLException { @@ -321,7 +310,6 @@ public void testGetAddon() throws MalformedURLException { /** * Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#getClasses()}. - * @throws MalformedURLException */ @Test public void testGetClasses() throws MalformedURLException { diff --git a/src/test/java/world/bentobox/bentobox/api/addons/AddonDescriptionTest.java b/src/test/java/world/bentobox/bentobox/api/addons/AddonDescriptionTest.java index f19ca1550..b7f9f4398 100644 --- a/src/test/java/world/bentobox/bentobox/api/addons/AddonDescriptionTest.java +++ b/src/test/java/world/bentobox/bentobox/api/addons/AddonDescriptionTest.java @@ -24,7 +24,6 @@ public class AddonDescriptionTest { private ConfigurationSection configSec; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/DefaultHelpCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/DefaultHelpCommandTest.java index 3c4a43f39..21c2c328a 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/DefaultHelpCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/DefaultHelpCommandTest.java @@ -39,7 +39,6 @@ public class DefaultHelpCommandTest { private User user; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/DelayedTeleportCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/DelayedTeleportCommandTest.java index c7000bd52..4b947d2f7 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/DelayedTeleportCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/DelayedTeleportCommandTest.java @@ -80,7 +80,6 @@ public class DelayedTeleportCommandTest { private Notifier notifier; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/HiddenCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/HiddenCommandTest.java index f8c36e630..d00950143 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/HiddenCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/HiddenCommandTest.java @@ -45,7 +45,6 @@ public class HiddenCommandTest { private User user; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminDeleteCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminDeleteCommandTest.java index eafab8ab5..1649e3599 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminDeleteCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminDeleteCommandTest.java @@ -57,7 +57,6 @@ public class AdminDeleteCommandTest { private UUID uuid; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminGetrankCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminGetrankCommandTest.java index cd9ca2506..85402082b 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminGetrankCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminGetrankCommandTest.java @@ -71,7 +71,6 @@ public class AdminGetrankCommandTest { private Island island; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -99,12 +98,12 @@ public void setUp() throws Exception { Map online = new HashMap<>(); Set onlinePlayers = new HashSet<>(); - for (int j = 0; j < NAMES.length; j++) { + for (String name : NAMES) { Player p1 = mock(Player.class); UUID uuid = UUID.randomUUID(); when(p1.getUniqueId()).thenReturn(uuid); - when(p1.getName()).thenReturn(NAMES[j]); - online.put(uuid, NAMES[j]); + when(p1.getName()).thenReturn(name); + online.put(uuid, name); onlinePlayers.add(p1); } PowerMockito.mockStatic(Bukkit.class); @@ -115,7 +114,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { @@ -221,15 +219,11 @@ public void testTabCompleteUserStringListOfStringNoChars() { public void testTabCompleteUserStringListOfStringWithChars() { Optional> result = c.tabComplete(user, "", Collections.singletonList("g")); assertTrue(result.isPresent()); - result.ifPresent(list -> { - assertEquals(1, list.size()); - }); + result.ifPresent(list -> assertEquals(1, list.size())); // Two names result = c.tabComplete(user, "", Collections.singletonList("f")); assertTrue(result.isPresent()); - result.ifPresent(list -> { - assertEquals(2, list.size()); - }); + result.ifPresent(list -> assertEquals(2, list.size())); } } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommandTest.java index 2ea39b024..c9abe12c9 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommandTest.java @@ -81,7 +81,6 @@ public class AdminInfoCommandTest { private IslandWorldManager iwm; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -141,7 +140,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminRegisterCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminRegisterCommandTest.java index bc25f8ebf..e1ac03ac6 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminRegisterCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminRegisterCommandTest.java @@ -68,7 +68,6 @@ public class AdminRegisterCommandTest { private IslandDeletionManager idm; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminResetFlagsCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminResetFlagsCommandTest.java index 4f5e64f4f..7e1260d6a 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminResetFlagsCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminResetFlagsCommandTest.java @@ -78,7 +78,6 @@ public class AdminResetFlagsCommandTest { private @Nullable User user; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -140,7 +139,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSetrankCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSetrankCommandTest.java index 60f4d44ab..10a72c98b 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSetrankCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSetrankCommandTest.java @@ -63,7 +63,6 @@ public class AdminSetrankCommandTest { private UUID targetUUID; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -106,7 +105,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSetspawnCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSetspawnCommandTest.java index 4e2aabed7..6829efb2e 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSetspawnCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSetspawnCommandTest.java @@ -52,7 +52,6 @@ public class AdminSetspawnCommandTest { private IslandsManager im; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommandTest.java index 14f844015..91a48aa26 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommandTest.java @@ -93,7 +93,6 @@ public class AdminSettingsCommandTest { private PluginManager pluginManager; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -187,7 +186,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSwitchCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSwitchCommandTest.java index 9aa60dcfe..86ea63f79 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSwitchCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminSwitchCommandTest.java @@ -50,7 +50,6 @@ public class AdminSwitchCommandTest { private UUID notUUID; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -85,7 +84,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommandTest.java index 9d692be09..2e19b2970 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommandTest.java @@ -78,7 +78,6 @@ public class AdminTeleportCommandTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -142,12 +141,7 @@ public void setUp() throws Exception { when(lm.get(any(), any())).thenReturn("mock translation"); when(plugin.getLocalesManager()).thenReturn(lm); - when(user.getTranslation(Mockito.anyString(),Mockito.anyString(), Mockito.anyString())).thenAnswer(new Answer() { - - @Override - public String answer(InvocationOnMock invocation) throws Throwable { - return invocation.getArgument(0, String.class); - }}); + when(user.getTranslation(Mockito.anyString(),Mockito.anyString(), Mockito.anyString())).thenAnswer((Answer) invocation -> invocation.getArgument(0, String.class)); // Island location Location location = mock(Location.class); diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminUnregisterCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminUnregisterCommandTest.java index 66fe237f3..ea9762317 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminUnregisterCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminUnregisterCommandTest.java @@ -65,7 +65,6 @@ public class AdminUnregisterCommandTest { private UUID notUUID; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCopyCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCopyCommandTest.java index c822128fa..cdcbe9bea 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCopyCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCopyCommandTest.java @@ -61,7 +61,6 @@ public class AdminBlueprintCopyCommandTest { private AdminBlueprintCopyCommand abcc; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -111,7 +110,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintDeleteCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintDeleteCommandTest.java index 6601545f3..f338e454e 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintDeleteCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintDeleteCommandTest.java @@ -60,7 +60,6 @@ public class AdminBlueprintDeleteCommandTest { private Map map; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -107,7 +106,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintLoadCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintLoadCommandTest.java index 65c34f4ef..f3c911d45 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintLoadCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintLoadCommandTest.java @@ -33,7 +33,6 @@ import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.addons.GameModeAddon; -import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.blueprints.Blueprint; import world.bentobox.bentobox.managers.BlueprintsManager; @@ -65,7 +64,6 @@ public class AdminBlueprintLoadCommandTest { private File blueprintsFolder; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -118,7 +116,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintSaveCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintSaveCommandTest.java index 3d88a1a51..af71e869f 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintSaveCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintSaveCommandTest.java @@ -66,7 +66,6 @@ public class AdminBlueprintSaveCommandTest { private Blueprint bp = new Blueprint(); /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -115,7 +114,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintsListCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintsListCommandTest.java index ccc75c968..fa964e0ed 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintsListCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintsListCommandTest.java @@ -54,7 +54,6 @@ public class AdminBlueprintsListCommandTest { private File dataFolder; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -97,7 +96,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { @@ -157,7 +155,6 @@ public void testExecuteUserStringListOfStringNoBlueprintsFilesEmptyFolder() { /** * Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintListCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - * @throws IOException */ @Test public void testExecuteUserStringListOfStringNoBlueprintsFiles() throws IOException { @@ -170,7 +167,6 @@ public void testExecuteUserStringListOfStringNoBlueprintsFiles() throws IOExcept /** * Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintListCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - * @throws IOException */ @Test public void testExecuteUserStringListOfStringWithBlueprintsFiles() throws IOException { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommandTest.java index efb8e8fbb..f06e3c69d 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommandTest.java @@ -71,7 +71,6 @@ public class AdminPurgeCommandTest { private PlayersManager pm; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeUnownedCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeUnownedCommandTest.java index 191d15b43..81f242546 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeUnownedCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeUnownedCommandTest.java @@ -58,7 +58,6 @@ public class AdminPurgeUnownedCommandTest { private World world; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeCommandTest.java index 1a2b9806a..1d80a2b54 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeCommandTest.java @@ -43,7 +43,6 @@ public class AdminRangeCommandTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeDisplayCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeDisplayCommandTest.java index bfc1a4920..acef385f4 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeDisplayCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeDisplayCommandTest.java @@ -44,7 +44,6 @@ public class AdminRangeDisplayCommandTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeResetCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeResetCommandTest.java index e849c0903..c2d972593 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeResetCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeResetCommandTest.java @@ -59,7 +59,6 @@ public class AdminRangeResetCommandTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeSetCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeSetCommandTest.java index 4a3e8ad1e..03adffd1e 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeSetCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeSetCommandTest.java @@ -59,7 +59,6 @@ public class AdminRangeSetCommandTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamAddCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamAddCommandTest.java index c44e696ab..c7ea44c8a 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamAddCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamAddCommandTest.java @@ -58,7 +58,6 @@ public class AdminTeamAddCommandTest { private UUID notUUID; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamDisbandCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamDisbandCommandTest.java index d0da960d7..52db08e11 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamDisbandCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamDisbandCommandTest.java @@ -74,7 +74,6 @@ public class AdminTeamDisbandCommandTest { private UUID notUUID; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java index b49839e55..add9884e3 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java @@ -71,7 +71,6 @@ public class AdminTeamKickCommandTest { private PluginManager pim; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamSetownerCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamSetownerCommandTest.java index 9386190a9..2f8a4ce54 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamSetownerCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamSetownerCommandTest.java @@ -63,7 +63,6 @@ public class AdminTeamSetownerCommandTest { private UUID notUUID; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanlistCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanlistCommandTest.java index a0f6ca6d1..b30833585 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanlistCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanlistCommandTest.java @@ -66,7 +66,6 @@ public class IslandBanlistCommandTest { private Island island; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandCreateCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandCreateCommandTest.java index a80e43490..066b7c774 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandCreateCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandCreateCommandTest.java @@ -77,7 +77,6 @@ public class IslandCreateCommandTest { private BlueprintsManager bpm; /** - * @throws java.lang.Exception */ @SuppressWarnings("deprecation") @Before @@ -160,7 +159,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { @@ -230,7 +228,6 @@ public void testCanExecuteUserStringListOfStringTooManyIslands() { /** * Test method for {@link world.bentobox.bentobox.api.commands.island.IslandCreateCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - * @throws IOException */ @Test public void testExecuteUserStringListOfStringSuccess() throws Exception { @@ -250,7 +247,6 @@ public void testExecuteUserStringListOfStringSuccess() throws Exception { /** * Test method for {@link world.bentobox.bentobox.api.commands.island.IslandCreateCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - * @throws IOException */ @Test public void testExecuteUserStringListOfStringThrowException() throws Exception { @@ -302,7 +298,6 @@ public void testExecuteUserStringListOfStringNoBundleNoPanel() { /** * Test method for {@link world.bentobox.bentobox.api.commands.island.IslandCreateCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - * @throws IOException */ @Test public void testExecuteUserStringListOfStringKnownBundle() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java index 4de0543fb..2d02f7862 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java @@ -166,7 +166,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandGoCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandGoCommandTest.java index a9a2c752f..12c9c41aa 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandGoCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandGoCommandTest.java @@ -92,7 +92,6 @@ public class IslandGoCommandTest { private @Nullable WorldSettings ws; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandHomesCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandHomesCommandTest.java index 036f5fd69..50c2869cb 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandHomesCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandHomesCommandTest.java @@ -67,7 +67,6 @@ public class IslandHomesCommandTest { private IslandWorldManager iwm; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandInfoCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandInfoCommandTest.java index 2b1a8dfb6..e07422f17 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandInfoCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandInfoCommandTest.java @@ -81,7 +81,6 @@ public class IslandInfoCommandTest { private IslandWorldManager iwm; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -141,7 +140,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandNearCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandNearCommandTest.java index f9e316a5a..8c32a2ac3 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandNearCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandNearCommandTest.java @@ -85,7 +85,6 @@ public class IslandNearCommandTest { private Block block; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -160,7 +159,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandResetCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandResetCommandTest.java index 29dd09124..88e91c127 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandResetCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandResetCommandTest.java @@ -94,7 +94,6 @@ public class IslandResetCommandTest { private UUID uuid; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommandTest.java index 41cdc0e3b..cba130889 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSethomeCommandTest.java @@ -66,7 +66,6 @@ public class IslandSethomeCommandTest { private WorldSettings ws; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSpawnCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSpawnCommandTest.java index 6833eed29..ec60c548c 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSpawnCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandSpawnCommandTest.java @@ -81,7 +81,6 @@ public class IslandSpawnCommandTest { private Settings s; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -149,7 +148,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java index bc439fe80..c618582eb 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java @@ -68,7 +68,6 @@ public class IslandUnbanCommandTest { private Island island; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCommandTest.java index 31383471a..f2cb157d3 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCommandTest.java @@ -78,7 +78,6 @@ public class IslandTeamCommandTest { private @Nullable Island island; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -132,7 +131,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommandTest.java index 7f9e2541f..ef4bcbd1f 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommandTest.java @@ -68,7 +68,6 @@ public class IslandTeamCoopCommandTest { private Island island; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommandTest.java index acd8c421c..368d63e5a 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommandTest.java @@ -74,7 +74,6 @@ public class IslandTeamInviteAcceptCommandTest { private Invite invite; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -153,7 +152,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java index e935341a7..27410725b 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java @@ -78,7 +78,6 @@ public class IslandTeamInviteCommandTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java index 9468f93ef..c4c8710d5 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java @@ -88,7 +88,6 @@ public class IslandTeamKickCommandTest { private Addon addon; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamLeaveCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamLeaveCommandTest.java index 2be11e289..d61dbe29a 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamLeaveCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamLeaveCommandTest.java @@ -68,7 +68,6 @@ public class IslandTeamLeaveCommandTest { private World world; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamSetownerCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamSetownerCommandTest.java index c15064a1b..58d0ab29f 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamSetownerCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamSetownerCommandTest.java @@ -73,7 +73,6 @@ public class IslandTeamSetownerCommandTest { private IslandTeamSetownerCommand its; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -135,7 +134,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommandTest.java index bce4f2577..2a6808a82 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommandTest.java @@ -71,7 +71,6 @@ public class IslandTeamTrustCommandTest { private Player targetPlayer; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUncoopCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUncoopCommandTest.java index 0c61e74c3..804ca1da7 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUncoopCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUncoopCommandTest.java @@ -64,7 +64,6 @@ public class IslandTeamUncoopCommandTest { private Island island; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommandTest.java index 1754e91a0..76ffeef36 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommandTest.java @@ -63,7 +63,6 @@ public class IslandTeamUntrustCommandTest { private Island island; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/events/addon/AddonEnableEventTest.java b/src/test/java/world/bentobox/bentobox/api/events/addon/AddonEnableEventTest.java index 2d27787bc..71a89ad06 100644 --- a/src/test/java/world/bentobox/bentobox/api/events/addon/AddonEnableEventTest.java +++ b/src/test/java/world/bentobox/bentobox/api/events/addon/AddonEnableEventTest.java @@ -28,7 +28,6 @@ public class AddonEnableEventTest { private Addon addon; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/events/island/IslandEventTest.java b/src/test/java/world/bentobox/bentobox/api/events/island/IslandEventTest.java index d5add7b9e..0677e8281 100644 --- a/src/test/java/world/bentobox/bentobox/api/events/island/IslandEventTest.java +++ b/src/test/java/world/bentobox/bentobox/api/events/island/IslandEventTest.java @@ -49,7 +49,6 @@ public class IslandEventTest { private PluginManager pim; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -64,7 +63,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { @@ -103,69 +101,28 @@ public void testBuilder() { .build(); e = e.getNewEvent().orElse(e); switch (reason) { - case BAN: - assertTrue(e instanceof IslandBanEvent); - break; - case CREATE: - assertTrue(e instanceof IslandCreateEvent); - break; - case CREATED: - assertTrue(e instanceof IslandCreatedEvent); - break; - case DELETE: - assertTrue(e instanceof IslandDeleteEvent); - break; - case DELETED: - assertTrue(e instanceof IslandDeletedEvent); - break; - case DELETE_CHUNKS: - assertTrue(e instanceof IslandDeleteChunksEvent); - break; - case ENTER: - assertTrue(e instanceof IslandEnterEvent); - break; - case EXIT: - assertTrue(e instanceof IslandExitEvent); - break; - case EXPEL: - assertTrue(e instanceof IslandExpelEvent); - break; - case LOCK: - assertTrue(e instanceof IslandLockEvent); - break; - case PRECLEAR: - assertTrue(e instanceof IslandPreclearEvent); - break; - case RANGE_CHANGE: - assertTrue(e instanceof IslandProtectionRangeChangeEvent); - break; - case REGISTERED: - assertTrue(e instanceof IslandRegisteredEvent); - break; - case RESERVED: - assertTrue(e instanceof IslandReservedEvent); - break; - case RESET: - assertTrue(e instanceof IslandResetEvent); - break; - case RESETTED: - assertTrue(e instanceof IslandResettedEvent); - break; - case UNBAN: - assertTrue(e instanceof IslandUnbanEvent); - break; - case UNKNOWN: - assertTrue(e instanceof IslandGeneralEvent); - break; - case UNLOCK: - assertTrue(e instanceof IslandUnlockEvent); - break; - case UNREGISTERED: - assertTrue(e instanceof IslandUnregisteredEvent); - break; - default: - break; - + case BAN -> assertTrue(e instanceof IslandBanEvent); + case CREATE -> assertTrue(e instanceof IslandCreateEvent); + case CREATED -> assertTrue(e instanceof IslandCreatedEvent); + case DELETE -> assertTrue(e instanceof IslandDeleteEvent); + case DELETED -> assertTrue(e instanceof IslandDeletedEvent); + case DELETE_CHUNKS -> assertTrue(e instanceof IslandDeleteChunksEvent); + case ENTER -> assertTrue(e instanceof IslandEnterEvent); + case EXIT -> assertTrue(e instanceof IslandExitEvent); + case EXPEL -> assertTrue(e instanceof IslandExpelEvent); + case LOCK -> assertTrue(e instanceof IslandLockEvent); + case PRECLEAR -> assertTrue(e instanceof IslandPreclearEvent); + case RANGE_CHANGE -> assertTrue(e instanceof IslandProtectionRangeChangeEvent); + case REGISTERED -> assertTrue(e instanceof IslandRegisteredEvent); + case RESERVED -> assertTrue(e instanceof IslandReservedEvent); + case RESET -> assertTrue(e instanceof IslandResetEvent); + case RESETTED -> assertTrue(e instanceof IslandResettedEvent); + case UNBAN -> assertTrue(e instanceof IslandUnbanEvent); + case UNKNOWN -> assertTrue(e instanceof IslandGeneralEvent); + case UNLOCK -> assertTrue(e instanceof IslandUnlockEvent); + case UNREGISTERED -> assertTrue(e instanceof IslandUnregisteredEvent); + default -> { + } } } verify(pim, Mockito.times(Reason.values().length * 2)).callEvent(any()); diff --git a/src/test/java/world/bentobox/bentobox/api/flags/FlagTest.java b/src/test/java/world/bentobox/bentobox/api/flags/FlagTest.java index a25c7d88c..eb6545dca 100644 --- a/src/test/java/world/bentobox/bentobox/api/flags/FlagTest.java +++ b/src/test/java/world/bentobox/bentobox/api/flags/FlagTest.java @@ -68,7 +68,6 @@ public class FlagTest { private BentoBox plugin; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -102,7 +101,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClickTest.java b/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClickTest.java index 587f2a6f1..9a840f7bd 100644 --- a/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClickTest.java +++ b/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClickTest.java @@ -64,7 +64,6 @@ public class IslandToggleClickTest { private SettingsTab settingsTab; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClickTest.java b/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClickTest.java index e1247fc9c..1ae8337ab 100644 --- a/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClickTest.java +++ b/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClickTest.java @@ -53,7 +53,6 @@ public class WorldToggleClickTest { private PluginManager pim; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/localization/BentoBoxLocaleTest.java b/src/test/java/world/bentobox/bentobox/api/localization/BentoBoxLocaleTest.java index e3ac92f54..1beefa775 100644 --- a/src/test/java/world/bentobox/bentobox/api/localization/BentoBoxLocaleTest.java +++ b/src/test/java/world/bentobox/bentobox/api/localization/BentoBoxLocaleTest.java @@ -42,7 +42,6 @@ public class BentoBoxLocaleTest { private BannerMeta bannerMeta; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/panels/PanelTest.java b/src/test/java/world/bentobox/bentobox/api/panels/PanelTest.java index 67ecb9dae..823176692 100644 --- a/src/test/java/world/bentobox/bentobox/api/panels/PanelTest.java +++ b/src/test/java/world/bentobox/bentobox/api/panels/PanelTest.java @@ -57,7 +57,6 @@ public class PanelTest { private Inventory inv; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -78,7 +77,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/api/panels/builders/PanelBuilderTest.java b/src/test/java/world/bentobox/bentobox/api/panels/builders/PanelBuilderTest.java index d1bed0081..aab11b812 100644 --- a/src/test/java/world/bentobox/bentobox/api/panels/builders/PanelBuilderTest.java +++ b/src/test/java/world/bentobox/bentobox/api/panels/builders/PanelBuilderTest.java @@ -34,7 +34,6 @@ public class PanelBuilderTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/api/user/NotifierTest.java b/src/test/java/world/bentobox/bentobox/api/user/NotifierTest.java index 3d8bcd10c..d16eca1e0 100644 --- a/src/test/java/world/bentobox/bentobox/api/user/NotifierTest.java +++ b/src/test/java/world/bentobox/bentobox/api/user/NotifierTest.java @@ -18,7 +18,6 @@ public class NotifierTest { private Notifier n; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -26,7 +25,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { @@ -61,7 +59,6 @@ public void testNotifyUserStringMultisend() { /** * Test method for {@link world.bentobox.bentobox.api.user.Notifier#notify(world.bentobox.bentobox.api.user.User, java.lang.String)}. - * @throws InterruptedException */ @Test public void testNotifyUserStringMultisendWaitSend() throws InterruptedException { diff --git a/src/test/java/world/bentobox/bentobox/blueprints/BlueprintPasterTest.java b/src/test/java/world/bentobox/bentobox/blueprints/BlueprintPasterTest.java index f589723f0..d869cfdc2 100644 --- a/src/test/java/world/bentobox/bentobox/blueprints/BlueprintPasterTest.java +++ b/src/test/java/world/bentobox/bentobox/blueprints/BlueprintPasterTest.java @@ -56,7 +56,6 @@ public class BlueprintPasterTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/commands/BentoBoxReloadCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/BentoBoxReloadCommandTest.java index f5bb5256c..800ce3c35 100644 --- a/src/test/java/world/bentobox/bentobox/commands/BentoBoxReloadCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/commands/BentoBoxReloadCommandTest.java @@ -56,7 +56,6 @@ public class BentoBoxReloadCommandTest { private BentoBoxReloadCommand reload; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -106,7 +105,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/database/DatabaseTest.java b/src/test/java/world/bentobox/bentobox/database/DatabaseTest.java index 49780c7df..a6ab69d2b 100644 --- a/src/test/java/world/bentobox/bentobox/database/DatabaseTest.java +++ b/src/test/java/world/bentobox/bentobox/database/DatabaseTest.java @@ -60,7 +60,6 @@ public class DatabaseTest { private Island island; /** - * @throws java.lang.Exception */ @SuppressWarnings("unchecked") @Before @@ -91,7 +90,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { @@ -101,7 +99,6 @@ public void tearDown() throws Exception { /** * Check if logger logged a severe string - * @param stringToCheck */ private void checkSevereLog(String stringToCheck) { // This magic obtains the lambda from an argument @@ -114,7 +111,7 @@ private void checkSevereLog(String stringToCheck) { */ @Test public void testDatabaseBentoBoxClassOfT() { - new Database(plugin, Island.class); + new Database<>(plugin, Island.class); verify(plugin).getLogger(); verify(dbSetup).getHandler(any()); } @@ -124,40 +121,28 @@ public void testDatabaseBentoBoxClassOfT() { */ @Test public void testDatabaseAddonClassOfT() { - new Database(addon, Island.class); + new Database<>(addon, Island.class); verify(addon).getLogger(); verify(dbSetup).getHandler(any()); } /** * Test method for {@link world.bentobox.bentobox.database.Database#loadObjects()}. - * @throws IntrospectionException - * @throws NoSuchMethodException - * @throws ClassNotFoundException - * @throws InvocationTargetException - * @throws IllegalAccessException - * @throws InstantiationException */ @Test public void testLoadObjects() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, IntrospectionException { - Database db = new Database(plugin, Island.class); + Database db = new Database<>(plugin, Island.class); assertEquals(objectList, db.loadObjects()); verify(handler).loadObjects(); } /** * Test method for {@link world.bentobox.bentobox.database.Database#loadObjects()}. - * @throws IntrospectionException - * @throws NoSuchMethodException - * @throws ClassNotFoundException - * @throws InvocationTargetException - * @throws IllegalAccessException - * @throws InstantiationException */ @Test public void testLoadObjectsThrowException() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, IntrospectionException { when(handler.loadObjects()).thenThrow(new IllegalAccessException("No bad dog! No biscuit!")); - Database db = new Database(plugin, Island.class); + Database db = new Database<>(plugin, Island.class); db.loadObjects(); verify(handler).loadObjects(); checkSevereLog("Could not load objects from database! Error: No bad dog! No biscuit!"); @@ -166,16 +151,10 @@ public void testLoadObjectsThrowException() throws InstantiationException, Illeg /** * Test method for {@link world.bentobox.bentobox.database.Database#loadObject(java.lang.String)}. - * @throws IntrospectionException - * @throws NoSuchMethodException - * @throws ClassNotFoundException - * @throws InvocationTargetException - * @throws IllegalAccessException - * @throws InstantiationException */ @Test public void testLoadObject() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, IntrospectionException { - Database db = new Database(plugin, Island.class); + Database db = new Database<>(plugin, Island.class); String uniqueId = UUID.randomUUID().toString(); assertEquals(island, db.loadObject(uniqueId)); verify(handler).loadObject(eq(uniqueId)); @@ -183,13 +162,10 @@ public void testLoadObject() throws InstantiationException, IllegalAccessExcepti /** * Test method for {@link world.bentobox.bentobox.database.Database#saveObject(java.lang.Object)}. - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalAccessException */ @Test public void testSaveObject() throws IllegalAccessException, InvocationTargetException, IntrospectionException { - Database db = new Database(plugin, Island.class); + Database db = new Database<>(plugin, Island.class); db.saveObjectAsync(island); verify(handler).saveObject(eq(island)); @@ -197,14 +173,11 @@ public void testSaveObject() throws IllegalAccessException, InvocationTargetExce /** * Test method for {@link world.bentobox.bentobox.database.Database#saveObject(java.lang.Object)}. - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalAccessException */ @Test public void testSaveObjectException() throws IllegalAccessException, InvocationTargetException, IntrospectionException { doThrow(new IntrospectionException("No means no!")).when(handler).saveObject(any(Island.class)); - Database db = new Database(plugin, Island.class); + Database db = new Database<>(plugin, Island.class); db.saveObjectAsync(island); checkSevereLog("Could not save object to database! Error: No means no!"); } @@ -216,7 +189,7 @@ public void testSaveObjectException() throws IllegalAccessException, InvocationT public void testObjectExists() { when(handler.objectExists(eq("test"))).thenReturn(false); when(handler.objectExists(eq("exists"))).thenReturn(true); - Database db = new Database(plugin, Island.class); + Database db = new Database<>(plugin, Island.class); assertFalse(db.objectExists("test")); assertTrue(db.objectExists("exists")); } @@ -226,34 +199,28 @@ public void testObjectExists() { */ @Test public void testDeleteID() { - Database db = new Database(plugin, Island.class); + Database db = new Database<>(plugin, Island.class); db.deleteID("test"); verify(handler).deleteID(eq("test")); } /** * Test method for {@link world.bentobox.bentobox.database.Database#deleteObject(java.lang.Object)}. - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalAccessException */ @Test public void testDeleteObject() throws IllegalAccessException, InvocationTargetException, IntrospectionException { - Database db = new Database(plugin, Island.class); + Database db = new Database<>(plugin, Island.class); db.deleteObject(island); verify(handler).deleteObject(eq(island)); } /** * Test method for {@link world.bentobox.bentobox.database.Database#deleteObject(java.lang.Object)}. - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalAccessException */ @Test public void testDeleteObjectFail() throws IllegalAccessException, InvocationTargetException, IntrospectionException { doThrow(new IllegalArgumentException("Wot?!")).when(handler).deleteObject(any()); - Database db = new Database(plugin, Island.class); + Database db = new Database<>(plugin, Island.class); db.deleteObject(island); checkSevereLog("Could not delete object! Error: Wot?!"); } @@ -264,7 +231,7 @@ public void testDeleteObjectFail() throws IllegalAccessException, InvocationTarg */ @Test public void testClose() { - Database db = new Database(plugin, Island.class); + Database db = new Database<>(plugin, Island.class); db.close(); verify(handler).close(); } diff --git a/src/test/java/world/bentobox/bentobox/database/json/adapters/ItemStackTypeAdapterTest.java b/src/test/java/world/bentobox/bentobox/database/json/adapters/ItemStackTypeAdapterTest.java index 91b2abf19..abe0e4c78 100644 --- a/src/test/java/world/bentobox/bentobox/database/json/adapters/ItemStackTypeAdapterTest.java +++ b/src/test/java/world/bentobox/bentobox/database/json/adapters/ItemStackTypeAdapterTest.java @@ -64,7 +64,6 @@ public class ItemStackTypeAdapterTest { private ItemFactory itemFactory; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -105,7 +104,6 @@ public void tearDown() { /** * Test method for {@link world.bentobox.bentobox.database.json.adapters.ItemStackTypeAdapter#write(com.google.gson.stream.JsonWriter, org.bukkit.inventory.ItemStack)}. - * @throws IOException */ @Test public void testWriteJsonWriterItemStack() throws IOException { @@ -118,7 +116,6 @@ public void testWriteJsonWriterItemStack() throws IOException { /** * Test method for {@link world.bentobox.bentobox.database.json.adapters.ItemStackTypeAdapter#write(com.google.gson.stream.JsonWriter, org.bukkit.inventory.ItemStack)}. - * @throws IOException */ @Test public void testWriteJsonWriterItemStackNull() throws IOException { @@ -128,7 +125,6 @@ public void testWriteJsonWriterItemStackNull() throws IOException { /** * Test method for {@link world.bentobox.bentobox.database.json.adapters.ItemStackTypeAdapter#read(com.google.gson.stream.JsonReader)}. - * @throws IOException */ @Test public void testReadJsonReaderNull() throws IOException { @@ -138,7 +134,6 @@ public void testReadJsonReaderNull() throws IOException { /** * Test method for {@link world.bentobox.bentobox.database.json.adapters.ItemStackTypeAdapter#read(com.google.gson.stream.JsonReader)}. - * @throws IOException */ @Test public void testReadJsonReader() throws IOException { @@ -164,7 +159,6 @@ public void testReadJsonReader() throws IOException { /** * Test method for {@link world.bentobox.bentobox.database.json.adapters.ItemStackTypeAdapter#read(com.google.gson.stream.JsonReader)}. - * @throws IOException */ @Test public void testReadJsonReaderUnknownMaterial() throws IOException { diff --git a/src/test/java/world/bentobox/bentobox/database/objects/IslandDeletionTest.java b/src/test/java/world/bentobox/bentobox/database/objects/IslandDeletionTest.java index 503f96be5..8bbf3c805 100644 --- a/src/test/java/world/bentobox/bentobox/database/objects/IslandDeletionTest.java +++ b/src/test/java/world/bentobox/bentobox/database/objects/IslandDeletionTest.java @@ -54,7 +54,6 @@ public class IslandDeletionTest { private UUID uuid; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/database/objects/IslandTest.java b/src/test/java/world/bentobox/bentobox/database/objects/IslandTest.java index 35abf1726..0e5aad290 100644 --- a/src/test/java/world/bentobox/bentobox/database/objects/IslandTest.java +++ b/src/test/java/world/bentobox/bentobox/database/objects/IslandTest.java @@ -76,7 +76,6 @@ public class IslandTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -112,7 +111,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { @@ -471,7 +469,7 @@ public void testInIslandSpaceLocation() { */ @Test public void testInIslandSpacePairOfIntegerInteger() { - assertTrue(i.inIslandSpace(new Pair(0,0))); + assertTrue(i.inIslandSpace(new Pair<>(0, 0))); } /** @@ -611,7 +609,7 @@ public void testSetFlagFlagInt() { */ @Test public void testSetFlagFlagIntBoolean() { - Flag f = Flags.values().stream().filter(fl -> fl.hasSubflags()).findFirst().orElse(null); + Flag f = Flags.values().stream().filter(Flag::hasSubflags).findFirst().orElse(null); if (f != null) { i.setFlag(f, 100, true); assertTrue(i.isChanged()); @@ -813,7 +811,7 @@ public void testToggleFlagFlag() { */ @Test public void testToggleFlagFlagBoolean() { - Flag f = Flags.values().stream().filter(fl -> fl.hasSubflags()) + Flag f = Flags.values().stream().filter(Flag::hasSubflags) .filter(fl -> fl.getType().equals(Type.SETTING)) .findFirst().orElse(null); if (f != null) { diff --git a/src/test/java/world/bentobox/bentobox/database/objects/PlayersTest.java b/src/test/java/world/bentobox/bentobox/database/objects/PlayersTest.java index cfd02c6ae..3c0c23269 100644 --- a/src/test/java/world/bentobox/bentobox/database/objects/PlayersTest.java +++ b/src/test/java/world/bentobox/bentobox/database/objects/PlayersTest.java @@ -45,7 +45,6 @@ public class PlayersTest { private Players p; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapterTest.java b/src/test/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapterTest.java index 97240fff6..ce91f6469 100644 --- a/src/test/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapterTest.java +++ b/src/test/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapterTest.java @@ -29,7 +29,6 @@ public class LogEntryListAdapterTest { private List toLog; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -42,7 +41,7 @@ public void setUp() throws Exception { toLog.add(new LogEntry.Builder("BAN").data("player", target.toString()).data("issuer", issuer.toString()).build()); toLog.add(new LogEntry.Builder("UNBAN").data("player", target.toString()).data("issuer", issuer.toString()).build()); toLog.add(new LogEntry.Builder("UNOWNED").build()); - toLog.forEach(history::add); + history.addAll(toLog); } @After diff --git a/src/test/java/world/bentobox/bentobox/database/sql/mysql/MySQLDatabaseConnectorTest.java b/src/test/java/world/bentobox/bentobox/database/sql/mysql/MySQLDatabaseConnectorTest.java index b7dfdc367..01372e5fc 100644 --- a/src/test/java/world/bentobox/bentobox/database/sql/mysql/MySQLDatabaseConnectorTest.java +++ b/src/test/java/world/bentobox/bentobox/database/sql/mysql/MySQLDatabaseConnectorTest.java @@ -42,7 +42,6 @@ public class MySQLDatabaseConnectorTest { private Logger logger; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -57,7 +56,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { @@ -87,7 +85,6 @@ public void testCreateConnection() { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseConnector#createConnection()}. - * @throws SQLException */ @Ignore("Does not work in Java 11") @Test diff --git a/src/test/java/world/bentobox/bentobox/database/sql/mysql/MySQLDatabaseHandlerTest.java b/src/test/java/world/bentobox/bentobox/database/sql/mysql/MySQLDatabaseHandlerTest.java index 79e95a1d1..39a0acb78 100644 --- a/src/test/java/world/bentobox/bentobox/database/sql/mysql/MySQLDatabaseHandlerTest.java +++ b/src/test/java/world/bentobox/bentobox/database/sql/mysql/MySQLDatabaseHandlerTest.java @@ -82,7 +82,6 @@ public class MySQLDatabaseHandlerTest { @Mock private Settings settings; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -126,7 +125,6 @@ public void tearDown() { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#loadObjects()}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -138,7 +136,6 @@ public void testLoadObjectsNoConnection() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#loadObjects()}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -156,7 +153,6 @@ public void testLoadObjects() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#loadObjects()}. - * @throws SQLException */ @Test @Ignore @@ -175,7 +171,6 @@ public void testLoadObjectsPrefix() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#loadObjects()}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -193,7 +188,6 @@ public void testLoadObjectsBadJSON() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#loadObjects()}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -223,7 +217,6 @@ public void testLoadObjectNoConnection() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#loadObject(java.lang.String)}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -242,7 +235,6 @@ public void testLoadObject() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#loadObject(java.lang.String)}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -258,7 +250,6 @@ public void testLoadObjectBadJSON() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#loadObject(java.lang.String)}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -289,14 +280,13 @@ public void testSaveObjectNull() { @Ignore("After reworking to HikariCP, this does not work.") public void testSaveObjectNotDataObject() { @SuppressWarnings("rawtypes") - MySQLDatabaseHandler h = new MySQLDatabaseHandler(plugin, List.class, dbConn); + MySQLDatabaseHandler h = new MySQLDatabaseHandler<>(plugin, List.class, dbConn); h.saveObject(Collections.singletonList("test")); verify(plugin).logError(eq("This class is not a DataObject: java.util.Collections$SingletonList")); } /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#saveObject(java.lang.Object)}. - * @throws SQLException */ @Test @Ignore("Async cannot be tested") @@ -328,7 +318,6 @@ public void testSaveObject() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#saveObject(java.lang.Object)}. - * @throws SQLException */ @Test @Ignore("Async cannot be tested") @@ -358,14 +347,13 @@ public void testDeleteObjectNull() { @Ignore("After reworking to HikariCP, this does not work.") public void testDeleteObjectIncorrectType() { @SuppressWarnings("rawtypes") - MySQLDatabaseHandler h = new MySQLDatabaseHandler(plugin, List.class, dbConn); + MySQLDatabaseHandler h = new MySQLDatabaseHandler<>(plugin, List.class, dbConn); h.deleteObject(Collections.singletonList("test")); verify(plugin).logError(eq("This class is not a DataObject: java.util.Collections$SingletonList")); } /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#deleteObject(java.lang.Object)}. - * @throws SQLException */ @Test @Ignore("Async cannot be tested") @@ -379,7 +367,6 @@ public void testDeleteObject() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#objectExists(java.lang.String)}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -395,7 +382,6 @@ public void testObjectExistsNot() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#objectExists(java.lang.String)}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -412,7 +398,6 @@ public void testObjectExistsFalse() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#objectExists(java.lang.String)}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -429,7 +414,6 @@ public void testObjectExists() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#objectExists(java.lang.String)}. - * @throws SQLException */ @Test @Ignore @@ -447,7 +431,6 @@ public void testObjectExistsPrefix() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#objectExists(java.lang.String)}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -461,7 +444,6 @@ public void testObjectExistsError() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#deleteID(java.lang.String)}. - * @throws SQLException */ @Test @Ignore("Cannot test async") @@ -475,7 +457,6 @@ public void testDeleteID() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#deleteID(java.lang.String)}. - * @throws SQLException */ @Test @Ignore("Cannot test async") @@ -501,7 +482,6 @@ public void testMySQLDatabaseHandlerBadPassword() { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#MySQLDatabaseHandler(world.bentobox.bentobox.BentoBox, java.lang.Class, world.bentobox.bentobox.database.DatabaseConnector)}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") @@ -512,7 +492,6 @@ public void testMySQLDatabaseHandlerCreateSchema() throws SQLException { /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#MySQLDatabaseHandler(world.bentobox.bentobox.BentoBox, java.lang.Class, world.bentobox.bentobox.database.DatabaseConnector)}. - * @throws SQLException */ @Test @Ignore @@ -523,7 +502,6 @@ public void testMySQLDatabaseHandlerCreateSchemaPrefix() throws SQLException { } /** * Test method for {@link world.bentobox.bentobox.database.sql.mysql.MySQLDatabaseHandler#MySQLDatabaseHandler(world.bentobox.bentobox.BentoBox, java.lang.Class, world.bentobox.bentobox.database.DatabaseConnector)}. - * @throws SQLException */ @Test @Ignore("After reworking to HikariCP, this does not work.") diff --git a/src/test/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandlerTest.java b/src/test/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandlerTest.java index 6ed819ede..d86a05a90 100644 --- a/src/test/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandlerTest.java +++ b/src/test/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandlerTest.java @@ -81,7 +81,6 @@ public class YamlDatabaseHandlerTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -122,11 +121,10 @@ record = new File(islandTable, uuid.toString() + ".yml"); config2.save(record2); // Handler - handler = new YamlDatabaseHandler(plugin, Island.class, dbConnector); + handler = new YamlDatabaseHandler<>(plugin, Island.class, dbConnector); } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { @@ -161,12 +159,6 @@ public void testLoadObjects() throws InstantiationException, IllegalAccessExcept /** * Test method for {@link world.bentobox.bentobox.database.yaml.YamlDatabaseHandler#loadObject(java.lang.String)}. - * @throws IntrospectionException - * @throws NoSuchMethodException - * @throws ClassNotFoundException - * @throws InvocationTargetException - * @throws IllegalAccessException - * @throws InstantiationException */ @Ignore("YAML database is no longer supported") @Test @@ -181,9 +173,6 @@ public void testLoadObject() throws InstantiationException, IllegalAccessExcepti /** * Test method for {@link world.bentobox.bentobox.database.yaml.YamlDatabaseHandler#saveObject(java.lang.Object)}. - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalAccessException */ @Ignore("YAML database is no longer supported") @SuppressWarnings("unchecked") @@ -200,9 +189,6 @@ public void testSaveObject() throws IllegalAccessException, InvocationTargetExce /** * Test method for {@link world.bentobox.bentobox.database.yaml.YamlDatabaseHandler#saveObject(java.lang.Object)}. - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalAccessException */ @Test public void testSaveObjectNull() throws IllegalAccessException, InvocationTargetException, IntrospectionException { @@ -212,13 +198,10 @@ public void testSaveObjectNull() throws IllegalAccessException, InvocationTarget /** * Test method for {@link world.bentobox.bentobox.database.yaml.YamlDatabaseHandler#saveObject(java.lang.Object)}. - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalAccessException */ @Test public void testSaveObjectNotDO() throws IllegalAccessException, InvocationTargetException, IntrospectionException{ - YamlDatabaseHandler h = new YamlDatabaseHandler(plugin, String.class, dbConnector); + YamlDatabaseHandler h = new YamlDatabaseHandler<>(plugin, String.class, dbConnector); String test = ""; h.saveObject(test); verify(plugin).logError("This class is not a DataObject: java.lang.String"); @@ -226,9 +209,6 @@ public void testSaveObjectNotDO() throws IllegalAccessException, InvocationTarge /** * Test method for {@link world.bentobox.bentobox.database.yaml.YamlDatabaseHandler#deleteObject(java.lang.Object)}. - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalAccessException */ @Test public void testDeleteObject() throws IllegalAccessException, InvocationTargetException, IntrospectionException { @@ -237,9 +217,6 @@ public void testDeleteObject() throws IllegalAccessException, InvocationTargetEx /** * Test method for {@link world.bentobox.bentobox.database.yaml.YamlDatabaseHandler#deleteObject(java.lang.Object)}. - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalAccessException */ @Test public void testDeleteObjectNull() throws IllegalAccessException, InvocationTargetException, IntrospectionException { @@ -249,13 +226,10 @@ public void testDeleteObjectNull() throws IllegalAccessException, InvocationTarg /** * Test method for {@link world.bentobox.bentobox.database.yaml.YamlDatabaseHandler#deleteObject(java.lang.Object)}. - * @throws IntrospectionException - * @throws InvocationTargetException - * @throws IllegalAccessException */ @Test public void testDeleteObjectNotDO() throws IllegalAccessException, InvocationTargetException, IntrospectionException { - YamlDatabaseHandler h = new YamlDatabaseHandler(plugin, String.class, dbConnector); + YamlDatabaseHandler h = new YamlDatabaseHandler<>(plugin, String.class, dbConnector); String test = ""; h.deleteObject(test); verify(plugin).logError("This class is not a DataObject: java.lang.String"); diff --git a/src/test/java/world/bentobox/bentobox/hooks/placeholders/PlaceholderAPIHookTest.java b/src/test/java/world/bentobox/bentobox/hooks/placeholders/PlaceholderAPIHookTest.java index cc0c7b2d6..a69643076 100644 --- a/src/test/java/world/bentobox/bentobox/hooks/placeholders/PlaceholderAPIHookTest.java +++ b/src/test/java/world/bentobox/bentobox/hooks/placeholders/PlaceholderAPIHookTest.java @@ -64,7 +64,6 @@ public class PlaceholderAPIHookTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/BlockEndDragonTest.java b/src/test/java/world/bentobox/bentobox/listeners/BlockEndDragonTest.java index 3d41bcd81..97b289488 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/BlockEndDragonTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/BlockEndDragonTest.java @@ -71,7 +71,6 @@ public class BlockEndDragonTest { private Block block; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -113,7 +112,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/listeners/JoinLeaveListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/JoinLeaveListenerTest.java index aec0869b9..9e767a9b7 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/JoinLeaveListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/JoinLeaveListenerTest.java @@ -107,7 +107,6 @@ public class JoinLeaveListenerTest { private @NonNull Location location; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -183,12 +182,12 @@ public void setUp() throws Exception { Map online = new HashMap<>(); Set onlinePlayers = new HashSet<>(); - for (int j = 0; j < NAMES.length; j++) { + for (String name : NAMES) { Player p1 = mock(Player.class); UUID u = UUID.randomUUID(); when(p1.getUniqueId()).thenReturn(u); - when(p1.getName()).thenReturn(NAMES[j]); - online.put(u, NAMES[j]); + when(p1.getName()).thenReturn(name); + online.put(u, name); onlinePlayers.add(p1); } onlinePlayers.add(player); @@ -215,7 +214,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/listeners/PanelListenerManagerTest.java b/src/test/java/world/bentobox/bentobox/listeners/PanelListenerManagerTest.java index eedbac464..b5448eca5 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/PanelListenerManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/PanelListenerManagerTest.java @@ -77,7 +77,6 @@ public class PanelListenerManagerTest { private InventoryAction inv; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -132,7 +131,6 @@ class MyView extends InventoryView { private final String name; /** - * @param name */ public MyView(String name) { top = mock(Inventory.class); @@ -142,7 +140,6 @@ public MyView(String name) { } /** - * @param name */ public MyView(String name, Inventory inventory) { top = inventory; diff --git a/src/test/java/world/bentobox/bentobox/listeners/PortalTeleportationListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/PortalTeleportationListenerTest.java index bba5123b4..3bf11f288 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/PortalTeleportationListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/PortalTeleportationListenerTest.java @@ -497,7 +497,6 @@ public void testonIslandPortalFromWorldToNetherStandardMakePortals() { /** * Test method for {@link PortalTeleportationListener#onIslandPortal(org.bukkit.event.player.PlayerPortalEvent)}. - * @throws Exception */ @Test public void testonIslandPortalFromNetherStandard() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/StandardSpawnProtectionListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/StandardSpawnProtectionListenerTest.java index a1313c89a..b41fc2f1e 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/StandardSpawnProtectionListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/StandardSpawnProtectionListenerTest.java @@ -87,7 +87,6 @@ public class StandardSpawnProtectionListenerTest { private WorldSettings ws; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -141,7 +140,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/AbstractCommonSetup.java b/src/test/java/world/bentobox/bentobox/listeners/flags/AbstractCommonSetup.java index cd57498d1..6d5406a37 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/AbstractCommonSetup.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/AbstractCommonSetup.java @@ -50,7 +50,7 @@ /** * Common items for testing. Don't forget to use super.setUp()! - * + *

* Sets up BentoBox plugin, pluginManager and ItemFactory. * Location, world, playersManager and player. * IWM, Addon and WorldSettings. IslandManager with one @@ -172,7 +172,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTabTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTabTest.java index 8724383ee..4ecccedc1 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTabTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTabTest.java @@ -66,7 +66,6 @@ public class GeoMobLimitTabTest { private GameModeAddon gma; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BlockInteractionListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BlockInteractionListenerTest.java index bdb0c5f56..51e3fe309 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BlockInteractionListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BlockInteractionListenerTest.java @@ -121,7 +121,6 @@ private void setFlags() { /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java index 67166b2a3..ec0e59eea 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java @@ -59,7 +59,6 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup { private BreakBlocksListener bbl; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java index 34435a79e..dd99b6b87 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java @@ -42,7 +42,6 @@ public class BucketListenerTest extends AbstractCommonSetup { private BucketListener l; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EggListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EggListenerTest.java index bc0a4db49..b4103ff38 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EggListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EggListenerTest.java @@ -35,7 +35,6 @@ public class EggListenerTest extends AbstractCommonSetup { private EggListener el; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ElytraListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ElytraListenerTest.java index a1f0fdceb..7ede01502 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ElytraListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ElytraListenerTest.java @@ -33,7 +33,6 @@ public class ElytraListenerTest extends AbstractCommonSetup { private ElytraListener el; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EntityInteractListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EntityInteractListenerTest.java index 0f258b06e..8b8e5014a 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EntityInteractListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/EntityInteractListenerTest.java @@ -54,7 +54,6 @@ public class EntityInteractListenerTest extends AbstractCommonSetup { private EquipmentSlot hand; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ExperiencePickupListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ExperiencePickupListenerTest.java index 651419943..77a274bab 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ExperiencePickupListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ExperiencePickupListenerTest.java @@ -43,7 +43,6 @@ public class ExperiencePickupListenerTest extends AbstractCommonSetup { private Entity entity; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListenerTest.java index 9e9f777ad..596fba8ca 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListenerTest.java @@ -52,7 +52,6 @@ public class HurtingListenerTest extends AbstractCommonSetup { private User user; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListenerTest.java index d8046658f..391805324 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListenerTest.java @@ -64,7 +64,6 @@ public class InventoryListenerTest extends AbstractCommonSetup { private Material type; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListenerTest.java index 6eb7629fd..08e698197 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/LockAndBanListenerTest.java @@ -82,7 +82,6 @@ public class LockAndBanListenerTest { private BukkitScheduler sch; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java index c00ee2d57..3be61170c 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java @@ -51,7 +51,6 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup { private PlaceBlocksListener pbl; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ThrowingListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ThrowingListenerTest.java index c31cf7529..362e2c444 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ThrowingListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/ThrowingListenerTest.java @@ -34,7 +34,6 @@ public class ThrowingListenerTest extends AbstractCommonSetup { private ThrowingListener tl; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobSpawnListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobSpawnListenerTest.java index 9a943f4a1..cba3a2ada 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobSpawnListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobSpawnListenerTest.java @@ -206,53 +206,24 @@ private void checkBlocked(LivingEntity le, MobSpawnListener l) { for (SpawnReason reason: SpawnReason.values()) { CreatureSpawnEvent e = new CreatureSpawnEvent(le, reason); switch (reason) { - // Natural - case DEFAULT: - case DROWNED: - case JOCKEY: - case LIGHTNING: - case MOUNT: - case NATURAL: - case NETHER_PORTAL: - case OCELOT_BABY: - case PATROL: - case RAID: - case REINFORCEMENTS: - case SILVERFISH_BLOCK: - case TRAP: - case VILLAGE_DEFENSE: - case VILLAGE_INVASION: - // These should be blocked - l.onMobSpawn(e); - assertTrue("Natural spawn should be blocked: " + reason.toString(), e.isCancelled()); - break; + // Natural + case DEFAULT, DROWNED, JOCKEY, LIGHTNING, MOUNT, NATURAL, NETHER_PORTAL, OCELOT_BABY, PATROL, RAID, REINFORCEMENTS, SILVERFISH_BLOCK, TRAP, VILLAGE_DEFENSE, VILLAGE_INVASION -> { + // These should be blocked + l.onMobSpawn(e); + assertTrue("Natural spawn should be blocked: " + reason.toString(), e.isCancelled()); + } // Spawners - case SPAWNER: - l.onMobSpawn(e); - assertTrue("Spawners spawn should be blocked: " + reason.toString(), e.isCancelled()); - break; + case SPAWNER -> { + l.onMobSpawn(e); + assertTrue("Spawners spawn should be blocked: " + reason.toString(), e.isCancelled()); + } // Unnatural - player involved or allowed - case BREEDING: - case BUILD_IRONGOLEM: - case BUILD_SNOWMAN: - case BUILD_WITHER: - case CURED: - case CUSTOM: - case DISPENSE_EGG: - case EGG: - case ENDER_PEARL: - case EXPLOSION: - case INFECTION: - case SHEARED: - case SHOULDER_ENTITY: - case SPAWNER_EGG: - case SLIME_SPLIT: - l.onMobSpawn(e); - assertFalse("Should be not blocked: " + reason.toString(), e.isCancelled()); - break; - default: - break; - + case BREEDING, BUILD_IRONGOLEM, BUILD_SNOWMAN, BUILD_WITHER, CURED, CUSTOM, DISPENSE_EGG, EGG, ENDER_PEARL, EXPLOSION, INFECTION, SHEARED, SHOULDER_ENTITY, SPAWNER_EGG, SLIME_SPLIT -> { + l.onMobSpawn(e); + assertFalse("Should be not blocked: " + reason.toString(), e.isCancelled()); + } + default -> { + } } } diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java index 94e1f266e..c58075a64 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java @@ -119,7 +119,6 @@ public class PVPListenerTest { private Notifier notifier; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListenerTest.java index ca8e0b12c..603b0a503 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListenerTest.java @@ -66,7 +66,6 @@ public class CleanSuperFlatListenerTest { private WorldRegenerator regenerator; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CoarseDirtTillingListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CoarseDirtTillingListenerTest.java index dc5e480e8..aa1a13f9e 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CoarseDirtTillingListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CoarseDirtTillingListenerTest.java @@ -77,7 +77,6 @@ public class CoarseDirtTillingListenerTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -123,7 +122,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java index be3620e11..09b45ac2b 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java @@ -87,7 +87,6 @@ public class EnterExitListenerTest { private EnterExitListener listener; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java index bf729df5b..3dff93414 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListenerTest.java @@ -86,7 +86,6 @@ public class InvincibleVisitorsListenerTest { private World world; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/IslandRespawnListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/IslandRespawnListenerTest.java index 4af405df3..54c805df4 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/IslandRespawnListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/IslandRespawnListenerTest.java @@ -67,7 +67,6 @@ public class IslandRespawnListenerTest { private Server server; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/OfflineGrowthListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/OfflineGrowthListenerTest.java index b4833d384..17e6f7a2b 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/OfflineGrowthListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/OfflineGrowthListenerTest.java @@ -195,7 +195,7 @@ public void testOnCropGrowNonBentoBoxWorldIsland() { } /** - * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent}. + * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent)}. */ @Test public void testOnSpreadDoNothing() { @@ -209,7 +209,7 @@ public void testOnSpreadDoNothing() { } /** - * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent}. + * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent)}. */ @Test public void testOnSpreadMembersOnline() { @@ -227,7 +227,7 @@ public void testOnSpreadMembersOnline() { } /** - * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent}. + * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent)}. */ @Test public void testOnSpreadMembersOffline() { @@ -255,7 +255,7 @@ public void testOnSpreadMembersOffline() { } /** - * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent}. + * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent)}. */ @Test public void testOnSpreadMembersOfflineTree() { @@ -274,7 +274,7 @@ public void testOnSpreadMembersOfflineTree() { } /** - * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent}. + * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent)}. */ @Test public void testOnSpreadNonIsland() { @@ -289,7 +289,7 @@ public void testOnSpreadNonIsland() { } /** - * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent}. + * Test method for {@link OfflineGrowthListener#onSpread(BlockSpreadEvent)}. */ @Test public void testOnSpreadNonBentoBoxWorldIsland() { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/OfflineRedstoneListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/OfflineRedstoneListenerTest.java index 52b9ef8f6..1624808de 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/OfflineRedstoneListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/OfflineRedstoneListenerTest.java @@ -107,11 +107,11 @@ public void setUp() throws Exception { PowerMockito.mockStatic(Bukkit.class); // Online players Set onlinePlayers = new HashSet<>(); - for (int j = 0; j < NAMES.length; j++) { + for (String name : NAMES) { Player p1 = mock(Player.class); UUID u = UUID.randomUUID(); when(p1.getUniqueId()).thenReturn(u); - when(p1.getName()).thenReturn(NAMES[j]); + when(p1.getName()).thenReturn(name); // All ops when(p1.isOp()).thenReturn(true); onlinePlayers.add(p1); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/PetTeleportListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/PetTeleportListenerTest.java index c2e1a3a4e..55ed897a4 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/PetTeleportListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/PetTeleportListenerTest.java @@ -42,7 +42,6 @@ public class PetTeleportListenerTest extends AbstractCommonSetup { private AnimalTamer tamer; /** - * @throws java.lang.Exception */ @Override @Before diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/RemoveMobsListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/RemoveMobsListenerTest.java index 1a7866011..8cfb2cf8c 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/RemoveMobsListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/RemoveMobsListenerTest.java @@ -63,7 +63,6 @@ public class RemoveMobsListenerTest { private Settings settings; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/VisitorKeepInventoryListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/VisitorKeepInventoryListenerTest.java index c87ce4501..d6763cc71 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/VisitorKeepInventoryListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/VisitorKeepInventoryListenerTest.java @@ -80,7 +80,6 @@ public class VisitorKeepInventoryListenerTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -140,7 +139,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/WitherListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/WitherListenerTest.java index a81ee2da6..078042882 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/WitherListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/WitherListenerTest.java @@ -64,7 +64,6 @@ public class WitherListenerTest { private Map map; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -104,7 +103,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/listeners/teleports/EntityTeleportListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/teleports/EntityTeleportListenerTest.java index fac45889f..3192c0d34 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/teleports/EntityTeleportListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/teleports/EntityTeleportListenerTest.java @@ -43,7 +43,6 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup { /** - * @throws java.lang.Exception */ @Override @Before @@ -192,19 +191,12 @@ public void testOnEntityPortalTeleportEnabledIsAllowedInConfig() { assertTrue(event.isCancelled()); } - - /** - * TODO: Lots more tests can be written here. - */ /** * Test method for {@link world.bentobox.bentobox.listeners.teleports.EntityTeleportListener#onEntityEnterPortal(org.bukkit.event.entity.EntityPortalEnterEvent)}. */ @Test public void testOnEntityEnterPortal() { - /** - * TODO: Lots more tests can be written here. - */ } /** @@ -212,9 +204,6 @@ public void testOnEntityEnterPortal() { */ @Test public void testOnEntityExitPortal() { - /** - * TODO: Lots more tests can be written here. - */ } } diff --git a/src/test/java/world/bentobox/bentobox/lists/GameModePlaceholderTest.java b/src/test/java/world/bentobox/bentobox/lists/GameModePlaceholderTest.java index 7de4357d5..f1d13e4da 100644 --- a/src/test/java/world/bentobox/bentobox/lists/GameModePlaceholderTest.java +++ b/src/test/java/world/bentobox/bentobox/lists/GameModePlaceholderTest.java @@ -64,7 +64,6 @@ public class GameModePlaceholderTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/managers/AddonsManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/AddonsManagerTest.java index 3474e0fd2..afb1a3bcc 100644 --- a/src/test/java/world/bentobox/bentobox/managers/AddonsManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/AddonsManagerTest.java @@ -60,7 +60,6 @@ public class AddonsManagerTest { private CommandsManager cm; /** - * @throws Exception */ @Before public void setup() throws Exception { @@ -85,7 +84,6 @@ public void setup() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { @@ -351,8 +349,8 @@ public void testIsAddonCompatibleWithBentoBoxOldReleaseLongAPI() { } /** - * Test method for {@link world.bentobox.bentobox.managers.AddonsManager#isAddonCompatibleWithBentoBox(Addon, String)}. - * Prevents regression on https://github.com/BentoBoxWorld/BentoBox/issues/1346. + * Test method for {@link AddonsManager#isAddonCompatibleWithBentoBox(Addon, String)}. + * Prevents regression on issue 1346. */ @Test public void testIsAddonCompatibleWithBentoBoxNewRelease() { @@ -364,8 +362,6 @@ public void testIsAddonCompatibleWithBentoBoxNewRelease() { /** * Test method for {@link world.bentobox.bentobox.managers.AddonsManager#setPerms(Addon)} - * @throws InvalidAddonDescriptionException - * @throws InvalidConfigurationException */ @Test public void testSetPermsNoPerms() { @@ -377,8 +373,6 @@ public void testSetPermsNoPerms() { /** * Test method for {@link world.bentobox.bentobox.managers.AddonsManager#setPerms(Addon)} - * @throws InvalidAddonDescriptionException - * @throws InvalidConfigurationException */ @Test public void testSetPermsHasPerms() throws InvalidConfigurationException { @@ -401,8 +395,6 @@ public void testSetPermsHasPerms() throws InvalidConfigurationException { /** * Test method for {@link world.bentobox.bentobox.managers.AddonsManager#setPerms(Addon)} - * @throws InvalidAddonDescriptionException - * @throws InvalidConfigurationException */ @Test public void testSetPermsHasPermsError() throws InvalidConfigurationException { @@ -428,8 +420,6 @@ public void testSetPermsHasPermsError() throws InvalidConfigurationException { /** * Test method for {@link world.bentobox.bentobox.managers.AddonsManager#registerPermission(org.bukkit.configuration.ConfigurationSection, String)} - * @throws InvalidAddonDescriptionException - * @throws InvalidConfigurationException */ @Test public void testRegisterPermissionStandardPerm() throws InvalidAddonDescriptionException, InvalidConfigurationException { @@ -446,8 +436,6 @@ public void testRegisterPermissionStandardPerm() throws InvalidAddonDescriptionE /** * Test method for {@link world.bentobox.bentobox.managers.AddonsManager#registerPermission(org.bukkit.configuration.ConfigurationSection, String)} - * @throws InvalidAddonDescriptionException - * @throws InvalidConfigurationException */ @Test public void testRegisterPermissionGameModePerm() throws InvalidAddonDescriptionException, InvalidConfigurationException { diff --git a/src/test/java/world/bentobox/bentobox/managers/BlueprintClipboardManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/BlueprintClipboardManagerTest.java index 4e0919ff8..66f90c51a 100644 --- a/src/test/java/world/bentobox/bentobox/managers/BlueprintClipboardManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/BlueprintClipboardManagerTest.java @@ -123,7 +123,6 @@ private void zip(File targetFile) throws IOException { } /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -140,7 +139,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { @@ -184,7 +182,6 @@ public void testGetClipboard() { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}. - * @throws IOException */ @Test public void testLoadBlueprintNoSuchFile() { @@ -200,7 +197,6 @@ public void testLoadBlueprintNoSuchFile() { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}. - * @throws IOException */ @Test public void testLoadBlueprintNoFileInZip() throws IOException { @@ -223,7 +219,6 @@ public void testLoadBlueprintNoFileInZip() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}. - * @throws IOException */ @Test public void testLoadBlueprintFileInZipJSONError() throws IOException { @@ -247,15 +242,13 @@ public void testLoadBlueprintFileInZipJSONError() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}. - * @throws IOException */ @Test public void testLoadBlueprintFileInZipNoBedrock() throws IOException { blueprintFolder.mkdirs(); // Make a blueprint file File configFile = new File(blueprintFolder, BLUEPRINT); - byte[] bytes = jsonNoBedrock.getBytes(StandardCharsets.UTF_8); - Files.write(configFile.toPath(), bytes, StandardOpenOption.CREATE); + Files.writeString(configFile.toPath(), jsonNoBedrock, StandardOpenOption.CREATE); // Zip it zip(configFile); BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder); @@ -269,15 +262,13 @@ public void testLoadBlueprintFileInZipNoBedrock() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}. - * @throws IOException */ @Test public void testLoadBlueprintFileInZip() throws IOException { blueprintFolder.mkdirs(); // Make a blueprint file File configFile = new File(blueprintFolder, BLUEPRINT); - byte[] bytes = json.getBytes(StandardCharsets.UTF_8); - Files.write(configFile.toPath(), bytes, StandardOpenOption.CREATE); + Files.writeString(configFile.toPath(), json, StandardOpenOption.CREATE); // Zip it zip(configFile); BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder); @@ -292,15 +283,13 @@ public void testLoadBlueprintFileInZip() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#load(java.lang.String)}. - * @throws IOException */ @Test public void testLoadString() throws IOException { blueprintFolder.mkdirs(); // Make a blueprint file File configFile = new File(blueprintFolder, BLUEPRINT); - byte[] bytes = json.getBytes(StandardCharsets.UTF_8); - Files.write(configFile.toPath(), bytes, StandardOpenOption.CREATE); + Files.writeString(configFile.toPath(), json, StandardOpenOption.CREATE); // Zip it zip(configFile); BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder); @@ -316,15 +305,13 @@ public void testLoadString() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#load(world.bentobox.bentobox.api.user.User, java.lang.String)}. - * @throws IOException */ @Test public void testLoadUserString() throws IOException { blueprintFolder.mkdirs(); // Make a blueprint file File configFile = new File(blueprintFolder, BLUEPRINT); - byte[] bytes = json.getBytes(StandardCharsets.UTF_8); - Files.write(configFile.toPath(), bytes, StandardOpenOption.CREATE); + Files.writeString(configFile.toPath(), json, StandardOpenOption.CREATE); // Zip it zip(configFile); BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder); @@ -335,7 +322,6 @@ public void testLoadUserString() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#load(world.bentobox.bentobox.api.user.User, java.lang.String)}. - * @throws IOException */ @Test public void testLoadUserStringFail() throws IOException { @@ -348,7 +334,6 @@ public void testLoadUserStringFail() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}. - * @throws IOException */ @Test public void testSave() throws IOException { @@ -356,8 +341,7 @@ public void testSave() throws IOException { blueprintFolder.mkdirs(); // Make a blueprint file File configFile = new File(blueprintFolder, BLUEPRINT); - byte[] bytes = json.getBytes(StandardCharsets.UTF_8); - Files.write(configFile.toPath(), bytes, StandardOpenOption.CREATE); + Files.writeString(configFile.toPath(), json, StandardOpenOption.CREATE); // Zip it zip(configFile); BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder); @@ -371,7 +355,6 @@ public void testSave() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}. - * @throws IOException */ @Test public void testSaveBadChars() throws IOException { @@ -379,8 +362,7 @@ public void testSaveBadChars() throws IOException { blueprintFolder.mkdirs(); // Make a blueprint file File configFile = new File(blueprintFolder, BLUEPRINT); - byte[] bytes = json.getBytes(StandardCharsets.UTF_8); - Files.write(configFile.toPath(), bytes, StandardOpenOption.CREATE); + Files.writeString(configFile.toPath(), json, StandardOpenOption.CREATE); // Zip it zip(configFile); BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder); @@ -394,7 +376,6 @@ public void testSaveBadChars() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}. - * @throws IOException */ @Test public void testSaveForeignChars() throws IOException { @@ -402,8 +383,7 @@ public void testSaveForeignChars() throws IOException { blueprintFolder.mkdirs(); // Make a blueprint file File configFile = new File(blueprintFolder, BLUEPRINT); - byte[] bytes = json.getBytes(StandardCharsets.UTF_8); - Files.write(configFile.toPath(), bytes, StandardOpenOption.CREATE); + Files.writeString(configFile.toPath(), json, StandardOpenOption.CREATE); // Zip it zip(configFile); BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder); @@ -417,7 +397,6 @@ public void testSaveForeignChars() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}. - * @throws IOException */ @Test public void testSaveForeignBadChars() throws IOException { @@ -425,8 +404,7 @@ public void testSaveForeignBadChars() throws IOException { blueprintFolder.mkdirs(); // Make a blueprint file File configFile = new File(blueprintFolder, BLUEPRINT); - byte[] bytes = json.getBytes(StandardCharsets.UTF_8); - Files.write(configFile.toPath(), bytes, StandardOpenOption.CREATE); + Files.writeString(configFile.toPath(), json, StandardOpenOption.CREATE); // Zip it zip(configFile); BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder); diff --git a/src/test/java/world/bentobox/bentobox/managers/BlueprintsManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/BlueprintsManagerTest.java index 63bb1ba26..055efe1b3 100644 --- a/src/test/java/world/bentobox/bentobox/managers/BlueprintsManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/BlueprintsManagerTest.java @@ -97,7 +97,6 @@ public class BlueprintsManagerTest { @Mock private Server server; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -170,7 +169,6 @@ public void makeAddon() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { @@ -195,7 +193,6 @@ private void deleteDir(Path path) throws Exception { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintsManager#extractDefaultBlueprints(world.bentobox.bentobox.api.addons.GameModeAddon)}. - * @throws IOException */ @Test public void testExtractDefaultBlueprintsFolderExists() throws IOException { @@ -248,18 +245,15 @@ public void testGetBlueprintBundles() { @Test public void testLoadBlueprintBundlesNoBlueprintFolder() { // Set up running and verification - when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer(new Answer() { - - @Override - public BukkitTask answer(InvocationOnMock invocation) throws Throwable { - invocation.getArgument(1,Runnable.class).run(); - verify(plugin).logError(eq("There is no blueprint folder for addon name")); - verify(plugin).logError(eq("No blueprint bundles found! Creating a default one.")); - File blueprints = new File(dataFolder, BlueprintsManager.FOLDER_NAME); - File d = new File(blueprints, "default.json"); - assertTrue(d.exists()); - return task; - }}); + when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer) invocation -> { + invocation.getArgument(1,Runnable.class).run(); + verify(plugin).logError(eq("There is no blueprint folder for addon name")); + verify(plugin).logError(eq("No blueprint bundles found! Creating a default one.")); + File blueprints = new File(dataFolder, BlueprintsManager.FOLDER_NAME); + File d = new File(blueprints, "default.json"); + assertTrue(d.exists()); + return task; + }); BlueprintsManager bpm = new BlueprintsManager(plugin); bpm.loadBlueprintBundles(addon); @@ -271,14 +265,11 @@ public BukkitTask answer(InvocationOnMock invocation) throws Throwable { @Test public void testLoadBlueprintBundles() { // Set up running and verification - when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer(new Answer() { - - @Override - public BukkitTask answer(InvocationOnMock invocation) throws Throwable { - invocation.getArgument(1,Runnable.class).run(); - verify(plugin).logError(eq("No blueprint bundles found! Creating a default one.")); - return task; - }}); + when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer) invocation -> { + invocation.getArgument(1,Runnable.class).run(); + verify(plugin).logError(eq("No blueprint bundles found! Creating a default one.")); + return task; + }); BlueprintsManager bpm = new BlueprintsManager(plugin); bpm.extractDefaultBlueprints(addon); bpm.loadBlueprintBundles(addon); @@ -312,13 +303,10 @@ public void testLoadBlueprintsFailZero() { @Test public void testLoadBlueprints() { // Set up running and verification - when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer(new Answer() { - - @Override - public BukkitTask answer(InvocationOnMock invocation) throws Throwable { - invocation.getArgument(1,Runnable.class).run(); - return task; - }}); + when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer) invocation -> { + invocation.getArgument(1,Runnable.class).run(); + return task; + }); BlueprintsManager bpm = new BlueprintsManager(plugin); // Load once (makes default files too) bpm.loadBlueprintBundles(addon); @@ -369,15 +357,12 @@ public void testSaveBlueprintBundle() { File blueprints = new File(dataFolder, BlueprintsManager.FOLDER_NAME); // Set up running and verification - when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer(new Answer() { - - @Override - public BukkitTask answer(InvocationOnMock invocation) throws Throwable { - invocation.getArgument(1,Runnable.class).run(); - File d = new File(blueprints, "bundle.json"); - assertTrue(d.exists()); - return task; - }}); + when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer) invocation -> { + invocation.getArgument(1,Runnable.class).run(); + File d = new File(blueprints, "bundle.json"); + assertTrue(d.exists()); + return task; + }); BlueprintsManager bpm = new BlueprintsManager(plugin); bpm.saveBlueprintBundle(addon, bb); @@ -412,19 +397,16 @@ public void testSaveBlueprintBundles() { File d2 = new File(blueprints, "bundle2.json"); times = 0; // Set up running and verification - when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer(new Answer() { - - @Override - public BukkitTask answer(InvocationOnMock invocation) throws Throwable { - invocation.getArgument(1,Runnable.class).run(); - // Verify - times++; - if (times > 2) { - assertTrue(d.exists()); - assertTrue(d2.exists()); - } - return task; - }}); + when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer) invocation -> { + invocation.getArgument(1,Runnable.class).run(); + // Verify + times++; + if (times > 2) { + assertTrue(d.exists()); + assertTrue(d2.exists()); + } + return task; + }); // Save bpm.saveBlueprintBundles(); } @@ -614,7 +596,6 @@ public void testCheckPermBundlesDefault() { /** * Test method for {@link world.bentobox.bentobox.managers.BlueprintsManager#deleteBlueprintBundle(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle)}. - * @throws IOException */ @Test public void testDeleteBlueprintBundle() throws IOException { @@ -632,16 +613,13 @@ public void testDeleteBlueprintBundle() throws IOException { BlueprintsManager bpm = new BlueprintsManager(plugin); // Set up running and verification - when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer(new Answer() { - - @Override - public BukkitTask answer(InvocationOnMock invocation) throws Throwable { - invocation.getArgument(1,Runnable.class).run(); + when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer) invocation -> { + invocation.getArgument(1,Runnable.class).run(); - // Verify - assertFalse(d.exists()); - return task; - }}); + // Verify + assertFalse(d.exists()); + return task; + }); // Delete it bpm.deleteBlueprintBundle(addon, bb); diff --git a/src/test/java/world/bentobox/bentobox/managers/IslandChunkDeletionManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/IslandChunkDeletionManagerTest.java index 341a2966d..252857ea1 100644 --- a/src/test/java/world/bentobox/bentobox/managers/IslandChunkDeletionManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/IslandChunkDeletionManagerTest.java @@ -41,7 +41,6 @@ public class IslandChunkDeletionManagerTest { private Settings settings; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/managers/IslandDeletionManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/IslandDeletionManagerTest.java index c2b44a324..62f0a3879 100644 --- a/src/test/java/world/bentobox/bentobox/managers/IslandDeletionManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/IslandDeletionManagerTest.java @@ -72,7 +72,6 @@ public class IslandDeletionManagerTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -111,7 +110,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/managers/IslandWorldManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/IslandWorldManagerTest.java index 8613406ed..8b4af6d1e 100644 --- a/src/test/java/world/bentobox/bentobox/managers/IslandWorldManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/IslandWorldManagerTest.java @@ -73,7 +73,6 @@ public class IslandWorldManagerTest { private GameModeAddon gm; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java index 8482d55d2..169551906 100644 --- a/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java @@ -142,7 +142,6 @@ public class IslandsManagerTest { IslandsManager im; /** - * @throws java.lang.Exception */ @SuppressWarnings("unchecked") @Before @@ -339,7 +338,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { @@ -625,7 +623,6 @@ public void testGetIsland() { /** * Test method for {@link world.bentobox.bentobox.managers.IslandsManager#getIslandAt(org.bukkit.Location)}. - * @throws Exception */ @Test public void testGetIslandAtLocation() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/managers/LocalesManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/LocalesManagerTest.java index e5ca878ac..51e9da70e 100644 --- a/src/test/java/world/bentobox/bentobox/managers/LocalesManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/LocalesManagerTest.java @@ -52,7 +52,6 @@ public class LocalesManagerTest { private static final String BENTOBOX = "BentoBox"; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -79,7 +78,6 @@ private void makeFakeLocaleFile() throws IOException { /** * Deletes the fake locales folder - * @throws Exception */ @After public void cleanUp() throws Exception { @@ -121,7 +119,6 @@ public void testConstructor() { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#get(java.lang.String)}. - * @throws IOException */ @Test public void testGetString() throws IOException { @@ -132,7 +129,6 @@ public void testGetString() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#get(java.lang.String)}. - * @throws IOException */ @Test public void testGetStringFail() throws IOException { @@ -143,7 +139,6 @@ public void testGetStringFail() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#getOrDefault(java.lang.String, java.lang.String)}. - * @throws IOException */ @Test public void testGetOrDefaultStringString() throws IOException { @@ -154,7 +149,6 @@ public void testGetOrDefaultStringString() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#getOrDefault(java.lang.String, java.lang.String)}. - * @throws IOException */ @Test public void testGetOrDefaultStringStringFail() throws IOException { @@ -165,7 +159,6 @@ public void testGetOrDefaultStringStringFail() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#get(world.bentobox.bentobox.api.user.User, java.lang.String)}. - * @throws IOException */ @Test public void testGetNullUserString() throws IOException { @@ -177,7 +170,6 @@ public void testGetNullUserString() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#get(world.bentobox.bentobox.api.user.User, java.lang.String)}. - * @throws IOException */ @Test public void testGetUserString() throws IOException { @@ -190,7 +182,6 @@ public void testGetUserString() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#getOrDefault(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}. - * @throws IOException */ @Test public void testGetOrDefaultUserStringString() throws IOException { @@ -203,7 +194,6 @@ public void testGetOrDefaultUserStringString() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#get(world.bentobox.bentobox.api.user.User, java.lang.String)}. - * @throws IOException */ @Test public void testGetCanadianUserString() throws IOException { @@ -216,7 +206,6 @@ public void testGetCanadianUserString() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#get(world.bentobox.bentobox.api.user.User, java.lang.String)}. - * @throws IOException */ @Test public void testGetUserStringFail() throws IOException { @@ -229,7 +218,6 @@ public void testGetUserStringFail() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#getOrDefault(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}. - * @throws IOException */ @Test public void testGetOrDefaultUserStringStringFail() throws IOException { @@ -243,7 +231,6 @@ public void testGetOrDefaultUserStringStringFail() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#getAvailableLocales(boolean)}. - * @throws IOException */ @Test public void testGetAvailableLocales() throws IOException { @@ -263,7 +250,6 @@ public void testGetAvailableLocales() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#getLanguages()}. - * @throws IOException */ @Test public void testGetLanguages() throws IOException { @@ -274,7 +260,6 @@ public void testGetLanguages() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#reloadLanguages()}. - * @throws IOException */ @Test public void testReloadLanguagesNoAddons() throws IOException { @@ -292,7 +277,6 @@ public void testReloadLanguagesNoAddons() throws IOException { /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#reloadLanguages()}. - * @throws IOException */ @Test public void testReloadLanguages() throws IOException { @@ -395,7 +379,6 @@ private void add(File source, JarOutputStream target) throws IOException /** * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#reloadLanguages()}. - * @throws IOException */ @Test public void testReloadLanguagesNoLocaleFolder() throws IOException { diff --git a/src/test/java/world/bentobox/bentobox/managers/PlayersManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/PlayersManagerTest.java index cb0691ecd..9943e3a62 100644 --- a/src/test/java/world/bentobox/bentobox/managers/PlayersManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/PlayersManagerTest.java @@ -115,7 +115,6 @@ public static void beforeClass() throws IllegalAccessException, InvocationTarget } /** - * @throws java.lang.Exception */ @SuppressWarnings("unchecked") @Before @@ -236,7 +235,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/managers/RanksManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/RanksManagerTest.java index e292b55f2..fe925cc14 100644 --- a/src/test/java/world/bentobox/bentobox/managers/RanksManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/RanksManagerTest.java @@ -20,7 +20,6 @@ public class RanksManagerTest { public static RanksManager ranksManager; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategyTest.java b/src/test/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategyTest.java index 91c013287..8b0a8021f 100644 --- a/src/test/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategyTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategyTest.java @@ -64,7 +64,6 @@ public class DefaultNewIslandLocationStrategyTest { private int count; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -108,7 +107,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/managers/island/NewIslandTest.java b/src/test/java/world/bentobox/bentobox/managers/island/NewIslandTest.java index 74b36a812..e0e7c8958 100644 --- a/src/test/java/world/bentobox/bentobox/managers/island/NewIslandTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/island/NewIslandTest.java @@ -98,7 +98,6 @@ public class NewIslandTest { private BlueprintsManager bpm; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -167,7 +166,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { @@ -176,7 +174,6 @@ public void tearDown() { /** * Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}. - * @throws Exception */ @Test public void testBuilderNoUser(){ @@ -189,7 +186,6 @@ public void testBuilderNoUser(){ /** * Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}. - * @throws Exception */ @Test public void testBuilder() throws Exception { @@ -208,7 +204,6 @@ public void testBuilder() throws Exception { /** * Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}. - * @throws Exception */ @Test public void testBuilderReset() throws Exception { @@ -228,7 +223,6 @@ public void testBuilderReset() throws Exception { /** * Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}. - * @throws Exception */ @Test public void testBuilderNoOldIsland() throws Exception { @@ -246,7 +240,6 @@ public void testBuilderNoOldIsland() throws Exception { /** * Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}. - * @throws Exception */ @Test public void testBuilderNoOldIslandPaste() throws Exception { @@ -264,7 +257,6 @@ public void testBuilderNoOldIslandPaste() throws Exception { /** * Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}. - * @throws Exception */ @Test public void testBuilderHasIsland() throws Exception { @@ -285,7 +277,6 @@ public void testBuilderHasIsland() throws Exception { /** * Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}. - * @throws Exception */ @Test public void testBuilderHasIslandFail() throws Exception { @@ -307,7 +298,6 @@ public void testBuilderHasIslandFail() throws Exception { /** * Test method for {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}. - * @throws Exception */ @Test public void testBuilderHasIslandFailnoReserve() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/panels/BlueprintManagementPanelTest.java b/src/test/java/world/bentobox/bentobox/panels/BlueprintManagementPanelTest.java index b3729797b..4ff22b87e 100644 --- a/src/test/java/world/bentobox/bentobox/panels/BlueprintManagementPanelTest.java +++ b/src/test/java/world/bentobox/bentobox/panels/BlueprintManagementPanelTest.java @@ -69,7 +69,6 @@ public class BlueprintManagementPanelTest { private Blueprint blueprint; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -131,7 +130,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/panels/IslandCreationPanelTest.java b/src/test/java/world/bentobox/bentobox/panels/IslandCreationPanelTest.java index e88ee5aaf..935423414 100644 --- a/src/test/java/world/bentobox/bentobox/panels/IslandCreationPanelTest.java +++ b/src/test/java/world/bentobox/bentobox/panels/IslandCreationPanelTest.java @@ -80,7 +80,6 @@ public class IslandCreationPanelTest { /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { diff --git a/src/test/java/world/bentobox/bentobox/panels/LanguagePanelTest.java b/src/test/java/world/bentobox/bentobox/panels/LanguagePanelTest.java index b8962a044..cce75f540 100644 --- a/src/test/java/world/bentobox/bentobox/panels/LanguagePanelTest.java +++ b/src/test/java/world/bentobox/bentobox/panels/LanguagePanelTest.java @@ -76,7 +76,6 @@ public class LanguagePanelTest { private Map map; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -116,7 +115,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() { diff --git a/src/test/java/world/bentobox/bentobox/util/ItemParserTest.java b/src/test/java/world/bentobox/bentobox/util/ItemParserTest.java index d6524d592..e9cbfe29f 100644 --- a/src/test/java/world/bentobox/bentobox/util/ItemParserTest.java +++ b/src/test/java/world/bentobox/bentobox/util/ItemParserTest.java @@ -54,18 +54,11 @@ public void setUp() throws Exception { */ bannerMeta = mock(BannerMeta.class); when(itemFactory.getItemMeta(Mockito.any())).thenAnswer((Answer) invocation -> { - switch (invocation.getArgument(0, Material.class)) { - case RED_BANNER: - case WHITE_BANNER: - return bannerMeta; - case POTION: - case SPLASH_POTION: - case LINGERING_POTION: - case TIPPED_ARROW: - return potionMeta; - default: - return mock(ItemMeta.class); - } + return switch (invocation.getArgument(0, Material.class)) { + case RED_BANNER, WHITE_BANNER -> bannerMeta; + case POTION, SPLASH_POTION, LINGERING_POTION, TIPPED_ARROW -> potionMeta; + default -> mock(ItemMeta.class); + }; }); defaultItem = new ItemStack(Material.STONE); @@ -154,12 +147,12 @@ public void testParsePotionStrengthNotExtendedUpgradedSplash() { assertEquals(3, result.getAmount()); } - enum ex { + enum extend { NOT_EXTENDED, EXTENDED } - enum ty { + enum type { NO_SPLASH, SPLASH, LINGER @@ -179,10 +172,10 @@ enum ty { @Test public void testParsePotion() { for (PotionType type : PotionType.values()) { - for (ex e : ex.values()) { - for (ty t: ty.values()) { + for (extend e : extend.values()) { + for (ItemParserTest.type t: ItemParserTest.type.values()) { for (int up = 1; up < 2; up++) { - boolean isExtended = e.equals(ex.EXTENDED); + boolean isExtended = e.equals(extend.EXTENDED); boolean isUpgraded = up > 1; if (isExtended && notExtendable.contains(type)) { continue; diff --git a/src/test/java/world/bentobox/bentobox/util/UtilTest.java b/src/test/java/world/bentobox/bentobox/util/UtilTest.java index 6b6519388..fe94c8194 100644 --- a/src/test/java/world/bentobox/bentobox/util/UtilTest.java +++ b/src/test/java/world/bentobox/bentobox/util/UtilTest.java @@ -73,7 +73,6 @@ public class UtilTest { private ConsoleCommandSender sender; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -310,50 +309,21 @@ public void testBlockFaceToFloat() { for (BlockFace bf : BlockFace.values()) { float r = Util.blockFaceToFloat(bf); switch (bf) { - case EAST: - assertEquals(90F, r, 0); - break; - case EAST_NORTH_EAST: - assertEquals(67.5F, r, 0); - break; - case NORTH_EAST: - assertEquals(45F, r, 0); - break; - case NORTH_NORTH_EAST: - assertEquals(22.5F, r, 0); - break; - case NORTH_NORTH_WEST: - assertEquals(337.5F, r, 0); - break; - case NORTH_WEST: - assertEquals(315F, r, 0); - break; - case SOUTH: - assertEquals(180F, r, 0); - break; - case SOUTH_EAST: - assertEquals(135F, r, 0); - break; - case SOUTH_SOUTH_EAST: - assertEquals(157.5F, r, 0); - break; - case SOUTH_SOUTH_WEST: - assertEquals(202.5F, r, 0); - break; - case SOUTH_WEST: - assertEquals(225F, r, 0); - break; - case WEST: - assertEquals(270F, r, 0); - break; - case WEST_NORTH_WEST: - assertEquals(292.5F, r, 0); - break; - case WEST_SOUTH_WEST: - assertEquals(247.5F, r, 0); - break; - default: - assertEquals(0F, r, 0); + case EAST -> assertEquals(90F, r, 0); + case EAST_NORTH_EAST -> assertEquals(67.5F, r, 0); + case NORTH_EAST -> assertEquals(45F, r, 0); + case NORTH_NORTH_EAST -> assertEquals(22.5F, r, 0); + case NORTH_NORTH_WEST -> assertEquals(337.5F, r, 0); + case NORTH_WEST -> assertEquals(315F, r, 0); + case SOUTH -> assertEquals(180F, r, 0); + case SOUTH_EAST -> assertEquals(135F, r, 0); + case SOUTH_SOUTH_EAST -> assertEquals(157.5F, r, 0); + case SOUTH_SOUTH_WEST -> assertEquals(202.5F, r, 0); + case SOUTH_WEST -> assertEquals(225F, r, 0); + case WEST -> assertEquals(270F, r, 0); + case WEST_NORTH_WEST -> assertEquals(292.5F, r, 0); + case WEST_SOUTH_WEST -> assertEquals(247.5F, r, 0); + default -> assertEquals(0F, r, 0); } } } diff --git a/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportTest.java b/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportTest.java index a367578d3..c20357d38 100644 --- a/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportTest.java +++ b/src/test/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleportTest.java @@ -89,7 +89,6 @@ public class SafeSpotTeleportTest { @Mock private BukkitTask task; /** - * @throws java.lang.Exception */ @Before public void setUp() throws Exception { @@ -137,7 +136,6 @@ public void setUp() throws Exception { } /** - * @throws java.lang.Exception */ @After public void tearDown() throws Exception { From 2b40ae47d720bb55c3d74acd7ac45269744de1d2 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 4 Mar 2023 23:35:39 -0800 Subject: [PATCH 07/26] Update Spigot version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b05d88628..c780ea0d8 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,7 @@ 1.19.3-R0.1-SNAPSHOT - 1.19-R0.1-SNAPSHOT + 1.19.3-R0.1-SNAPSHOT 3.0.0 1.7.1 2.10.9 From c31458f8e606ac7aa42bd543427251447ecedf17 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 4 Mar 2023 23:36:32 -0800 Subject: [PATCH 08/26] Remove offending blueprint original particle shower which doesn't work Never did anything useful anyway. Fixes #2100 --- .../api/commands/admin/blueprints/AdminBlueprintCommand.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCommand.java index ca8a6eaf0..8246d157d 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCommand.java @@ -121,11 +121,6 @@ private void paintAxis(User user, BlueprintClipboard clipboard) { user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, maxY + 0.5, z + 0.5); } - // Drawing origin - if (clipboard.getOrigin() != null) { - user.spawnParticle(Particle.VILLAGER_HAPPY, null, clipboard.getOrigin().getBlockX() + 0.5, clipboard.getOrigin().getBlockY() + 0.5, clipboard.getOrigin().getBlockZ() + 0.5); - } - } protected void hideClipboard(User user) { From 2940d2e4927c1e8813c0399123fa4ecabf14c6f4 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 13 Mar 2023 20:17:03 -0700 Subject: [PATCH 09/26] Add cheat flag to prevent Endermen from teleporting Fixes #2105 --- .../flags/settings/MobTeleportListener.java | 39 +++++ .../world/bentobox/bentobox/lists/Flags.java | 8 + src/main/resources/locales/en-US.yml | 5 + .../settings/MobTeleportListenerTest.java | 148 ++++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 src/main/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListener.java create mode 100644 src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListenerTest.java diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListener.java new file mode 100644 index 000000000..db79e252d --- /dev/null +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListener.java @@ -0,0 +1,39 @@ +package world.bentobox.bentobox.listeners.flags.settings; + +import java.util.Optional; + +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityTeleportEvent; + +import world.bentobox.bentobox.api.flags.FlagListener; +import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.bentobox.lists.Flags; + +/** + * Handles natural mob teleporting. + * @author tastybento + */ +public class MobTeleportListener extends FlagListener { + + /** + * Check teleport of Endermen + * @param event EntityTeleportEvent + */ + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityTeleportEvent(EntityTeleportEvent event) { + World w = event.getFrom().getWorld(); + // If not in the right world exit immediately. + if (!this.getIWM().inWorld(w)) { + return; + } + Optional island = getIslands().getIslandAt(event.getEntity().getLocation()); + + if (Boolean.TRUE.equals(island.map(i -> !i.isAllowed(Flags.ENDERMAN_TELEPORT)).orElseGet( + () -> !Flags.ENDERMAN_TELEPORT.isSetForWorld(w)))) { + // Enderman teleport is disabled on island or world. Cancel it. + event.setCancelled(true); + } + } +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/lists/Flags.java b/src/main/java/world/bentobox/bentobox/lists/Flags.java index 10ad9570e..073fb83e5 100644 --- a/src/main/java/world/bentobox/bentobox/lists/Flags.java +++ b/src/main/java/world/bentobox/bentobox/lists/Flags.java @@ -42,6 +42,7 @@ import world.bentobox.bentobox.listeners.flags.protection.ThrowingListener; import world.bentobox.bentobox.listeners.flags.settings.DecayListener; import world.bentobox.bentobox.listeners.flags.settings.MobSpawnListener; +import world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener; import world.bentobox.bentobox.listeners.flags.settings.PVPListener; import world.bentobox.bentobox.listeners.flags.worldsettings.ChestDamageListener; import world.bentobox.bentobox.listeners.flags.worldsettings.CleanSuperFlatListener; @@ -488,6 +489,13 @@ private Flags() {} .listener(new EndermanListener()) .build(); + /** + * If {@code false}, prevents Endermans from teleporting + * @since 1.22.1 + */ + public static final Flag ENDERMAN_TELEPORT = new Flag.Builder("ENDERMAN_TELEPORT", Material.ENDER_PEARL).type(Type.SETTING) + .defaultSetting(true).listener(new MobTeleportListener()).mode(Flag.Mode.ADVANCED).build(); + public static final Flag ENTER_EXIT_MESSAGES = new Flag.Builder("ENTER_EXIT_MESSAGES", Material.DIRT).defaultSetting(true).type(Type.WORLD_SETTING) .listener(new EnterExitListener()) .build(); diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index ecf47e868..afdeb2cd4 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -971,6 +971,11 @@ protection: &a Endermen can remove &a blocks from islands name: "Enderman griefing" + ENDERMAN_TELEPORT: + description: |- + &a Endermen can teleport + &a if active. + name: "Enderman teleport" ENDER_PEARL: description: "Toggle use" name: "EnderPearls" diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListenerTest.java new file mode 100644 index 000000000..aa6523a08 --- /dev/null +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListenerTest.java @@ -0,0 +1,148 @@ +package world.bentobox.bentobox.listeners.flags.settings; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Optional; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.event.entity.EntityTeleportEvent; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.bentobox.lists.Flags; +import world.bentobox.bentobox.managers.IslandWorldManager; +import world.bentobox.bentobox.managers.IslandsManager; + +/** + * @author tastybento + * + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({BentoBox.class }) +public class MobTeleportListenerTest { + + @Mock + private IslandWorldManager iwm; + @Mock + private IslandsManager im; + @Mock + private Island island; + private MobTeleportListener mtl; + + @Mock + private Entity enderman; + @Mock + private Entity other; + @Mock + private Location from; + @Mock + private Location to; + @Mock + private World world; + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + // Set up plugin + BentoBox plugin = mock(BentoBox.class); + PowerMockito.mockStatic(BentoBox.class, Mockito.RETURNS_MOCKS); + when(BentoBox.getInstance()).thenReturn(plugin); + // Island World Manager + when(plugin.getIWM()).thenReturn(iwm); + when(iwm.inWorld(any(World.class))).thenReturn(true); + // Island Manager + when(plugin.getIslands()).thenReturn(im); + when(im.getIslandAt(any())).thenReturn(Optional.of(island)); + when(island.isAllowed(Flags.ENDERMAN_TELEPORT)).thenReturn(true); + + when(to.getWorld()).thenReturn(world); + when(from.getWorld()).thenReturn(world); + when(enderman.getType()).thenReturn(EntityType.ENDERMAN); + when(other.getType()).thenReturn(EntityType.AXOLOTL); + mtl = new MobTeleportListener(); + + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + Mockito.framework().clearInlineMocks(); + } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener#onEntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)}. + */ + @Test + public void testOnEntityTeleportEventEndermanNotAllowed() { + Flags.ENDERMAN_TELEPORT.setSetting(world, false); + when(island.isAllowed(Flags.ENDERMAN_TELEPORT)).thenReturn(false); + EntityTeleportEvent e = new EntityTeleportEvent(enderman, from, to); + mtl.onEntityTeleportEvent(e); + assertTrue(e.isCancelled()); + } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener#onEntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)}. + */ + @Test + public void testOnEntityTeleportEventEndermanNotAllowedWrongWorld() { + when(iwm.inWorld(any(World.class))).thenReturn(false); + Flags.ENDERMAN_TELEPORT.setSetting(world, false); + when(island.isAllowed(Flags.ENDERMAN_TELEPORT)).thenReturn(false); + EntityTeleportEvent e = new EntityTeleportEvent(enderman, from, to); + mtl.onEntityTeleportEvent(e); + assertFalse(e.isCancelled()); + } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener#onEntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)}. + */ + @Test + public void testOnEntityTeleportEventEndermanNotAllowedNotOnIsland() { + when(im.getIslandAt(any())).thenReturn(Optional.empty()); + Flags.ENDERMAN_TELEPORT.setSetting(world, false); + EntityTeleportEvent e = new EntityTeleportEvent(enderman, from, to); + mtl.onEntityTeleportEvent(e); + assertFalse(e.isCancelled()); + } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener#onEntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)}. + */ + @Test + public void testOnEntityTeleportEventEndermanAllowedDefault() { + EntityTeleportEvent e = new EntityTeleportEvent(enderman, from, to); + mtl.onEntityTeleportEvent(e); + assertFalse(e.isCancelled()); + } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener#onEntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)}. + */ + @Test + public void testOnEntityTeleportEventOther() { + EntityTeleportEvent e = new EntityTeleportEvent(other, from, to); + mtl.onEntityTeleportEvent(e); + assertFalse(e.isCancelled()); + } + +} From 70f044265ab5f06e99d7bc425644fa3885cc9237 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 13 Mar 2023 20:42:26 -0700 Subject: [PATCH 10/26] Fix test - 54 flags --- .../java/world/bentobox/bentobox/managers/FlagsManagerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/world/bentobox/bentobox/managers/FlagsManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/FlagsManagerTest.java index 761dc6330..5b92a5a7d 100644 --- a/src/test/java/world/bentobox/bentobox/managers/FlagsManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/FlagsManagerTest.java @@ -46,7 +46,7 @@ public class FlagsManagerTest { /** * Update this value if the number of registered listeners changes */ - private static final int NUMBER_OF_LISTENERS = 53; + private static final int NUMBER_OF_LISTENERS = 54; @Mock private BentoBox plugin; @Mock From 3285ef1ad2749d9182c24ac5d69bbe5beefd4a86 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 17 Mar 2023 20:45:15 -0700 Subject: [PATCH 11/26] Fix and enhancement for #2105 --- .../flags/settings/MobTeleportListener.java | 21 ++++-- .../world/bentobox/bentobox/lists/Flags.java | 8 +++ .../settings/MobTeleportListenerTest.java | 65 +++++++++++++++++++ 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListener.java index db79e252d..293aca179 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListener.java @@ -3,6 +3,7 @@ import java.util.Optional; import org.bukkit.World; +import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityTeleportEvent; @@ -12,28 +13,38 @@ import world.bentobox.bentobox.lists.Flags; /** - * Handles natural mob teleporting. + * Handles shulker or enderman teleporting * @author tastybento */ public class MobTeleportListener extends FlagListener { /** - * Check teleport of Endermen + * Check teleport of Endermen or Shulker * @param event EntityTeleportEvent */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onEntityTeleportEvent(EntityTeleportEvent event) { + // Only cover shulkers and enderman + if (!event.getEntityType().equals(EntityType.ENDERMAN) && !event.getEntityType().equals(EntityType.SHULKER)) { + return; + } World w = event.getFrom().getWorld(); - // If not in the right world exit immediately. - if (!this.getIWM().inWorld(w)) { + // If not in the right world exit immediately and check teleportation is within the same world + if (!this.getIWM().inWorld(w) || event.getTo() == null || !event.getFrom().getWorld().equals(event.getTo().getWorld())) { return; } Optional island = getIslands().getIslandAt(event.getEntity().getLocation()); - if (Boolean.TRUE.equals(island.map(i -> !i.isAllowed(Flags.ENDERMAN_TELEPORT)).orElseGet( + if (event.getEntityType().equals(EntityType.ENDERMAN) && Boolean.TRUE.equals(island.map(i -> !i.isAllowed(Flags.ENDERMAN_TELEPORT)).orElseGet( () -> !Flags.ENDERMAN_TELEPORT.isSetForWorld(w)))) { // Enderman teleport is disabled on island or world. Cancel it. event.setCancelled(true); } + + if (event.getEntityType().equals(EntityType.SHULKER) && Boolean.TRUE.equals(island.map(i -> !i.isAllowed(Flags.SHULKER_TELEPORT)).orElseGet( + () -> !Flags.SHULKER_TELEPORT.isSetForWorld(w)))) { + // Shulker teleport is disabled on island or world. Cancel it. + event.setCancelled(true); + } } } \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/lists/Flags.java b/src/main/java/world/bentobox/bentobox/lists/Flags.java index 073fb83e5..69133742c 100644 --- a/src/main/java/world/bentobox/bentobox/lists/Flags.java +++ b/src/main/java/world/bentobox/bentobox/lists/Flags.java @@ -495,6 +495,14 @@ private Flags() {} */ public static final Flag ENDERMAN_TELEPORT = new Flag.Builder("ENDERMAN_TELEPORT", Material.ENDER_PEARL).type(Type.SETTING) .defaultSetting(true).listener(new MobTeleportListener()).mode(Flag.Mode.ADVANCED).build(); + /** + * If {@code false}, prevents Shulkers from teleporting + * Uses same listener as ENDERMAN_TELEPORT + * @since 1.22.1 + */ + public static final Flag SHULKER_TELEPORT = new Flag.Builder("SHULKER_TELEPORT", Material.SHULKER_SHELL).type(Type.SETTING) + .defaultSetting(true).mode(Flag.Mode.ADVANCED).build(); + public static final Flag ENTER_EXIT_MESSAGES = new Flag.Builder("ENTER_EXIT_MESSAGES", Material.DIRT).defaultSetting(true).type(Type.WORLD_SETTING) .listener(new EnterExitListener()) diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListenerTest.java index aa6523a08..d570f162d 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/MobTeleportListenerTest.java @@ -48,6 +48,8 @@ public class MobTeleportListenerTest { @Mock private Entity enderman; @Mock + private Entity shulker; + @Mock private Entity other; @Mock private Location from; @@ -71,10 +73,12 @@ public void setUp() throws Exception { when(plugin.getIslands()).thenReturn(im); when(im.getIslandAt(any())).thenReturn(Optional.of(island)); when(island.isAllowed(Flags.ENDERMAN_TELEPORT)).thenReturn(true); + when(island.isAllowed(Flags.SHULKER_TELEPORT)).thenReturn(true); when(to.getWorld()).thenReturn(world); when(from.getWorld()).thenReturn(world); when(enderman.getType()).thenReturn(EntityType.ENDERMAN); + when(shulker.getType()).thenReturn(EntityType.SHULKER); when(other.getType()).thenReturn(EntityType.AXOLOTL); mtl = new MobTeleportListener(); @@ -145,4 +149,65 @@ public void testOnEntityTeleportEventOther() { assertFalse(e.isCancelled()); } + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener#onEntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)}. + */ + @Test + public void testOnEntityTeleportEventEndermanNotAllowedButOther() { + Flags.ENDERMAN_TELEPORT.setSetting(world, false); + Flags.SHULKER_TELEPORT.setSetting(world, false); + when(island.isAllowed(Flags.ENDERMAN_TELEPORT)).thenReturn(false); + when(island.isAllowed(Flags.SHULKER_TELEPORT)).thenReturn(false); + EntityTeleportEvent e = new EntityTeleportEvent(other, from, to); + mtl.onEntityTeleportEvent(e); + assertFalse(e.isCancelled()); + } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener#onEntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)}. + */ + @Test + public void testOnEntityTeleportEventShulkerNotAllowed() { + Flags.SHULKER_TELEPORT.setSetting(world, false); + when(island.isAllowed(Flags.SHULKER_TELEPORT)).thenReturn(false); + EntityTeleportEvent e = new EntityTeleportEvent(shulker, from, to); + mtl.onEntityTeleportEvent(e); + assertTrue(e.isCancelled()); + } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener#onEntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)}. + */ + @Test + public void testOnEntityTeleportEventShulkerNotAllowedWrongWorld() { + when(iwm.inWorld(any(World.class))).thenReturn(false); + Flags.SHULKER_TELEPORT.setSetting(world, false); + when(island.isAllowed(Flags.SHULKER_TELEPORT)).thenReturn(false); + EntityTeleportEvent e = new EntityTeleportEvent(shulker, from, to); + mtl.onEntityTeleportEvent(e); + assertFalse(e.isCancelled()); + } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener#onEntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)}. + */ + @Test + public void testOnEntityTeleportEventShulkerNotAllowedNotOnIsland() { + when(im.getIslandAt(any())).thenReturn(Optional.empty()); + Flags.SHULKER_TELEPORT.setSetting(world, false); + EntityTeleportEvent e = new EntityTeleportEvent(shulker, from, to); + mtl.onEntityTeleportEvent(e); + assertFalse(e.isCancelled()); + } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.settings.MobTeleportListener#onEntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)}. + */ + @Test + public void testOnEntityTeleportEventShulkerAllowedDefault() { + EntityTeleportEvent e = new EntityTeleportEvent(shulker, from, to); + mtl.onEntityTeleportEvent(e); + assertFalse(e.isCancelled()); + } + } From ca604f893cc52a2e9c8389f87bf73dbd3641a7a7 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 18 Mar 2023 10:27:50 -0700 Subject: [PATCH 12/26] Relates to #2104. Adds user.displayName() as a placeholder option (#2108) * Relates to #2104. Adds user.displayName() as a placeholder option * Fix test --- .../api/commands/island/IslandBanCommand.java | 4 +-- .../commands/island/IslandExpelCommand.java | 8 ++--- .../commands/island/IslandUnbanCommand.java | 4 +-- .../island/team/IslandTeamCoopCommand.java | 4 +-- .../team/IslandTeamInviteAcceptCommand.java | 10 +++--- .../island/team/IslandTeamInviteCommand.java | 4 +-- .../team/IslandTeamInviteRejectCommand.java | 6 ++-- .../island/team/IslandTeamKickCommand.java | 14 ++++---- .../island/team/IslandTeamLeaveCommand.java | 2 +- .../island/team/IslandTeamPromoteCommand.java | 4 +-- .../island/team/IslandTeamTrustCommand.java | 8 ++--- .../island/team/IslandTeamUncoopCommand.java | 4 +-- .../island/team/IslandTeamUntrustCommand.java | 4 +-- .../api/localization/TextVariables.java | 1 + .../bentobox/bentobox/api/user/User.java | 16 ++++++++-- .../commands/island/IslandBanCommandTest.java | 8 +++-- .../island/IslandExpelCommandTest.java | 8 +++-- .../island/IslandUnbanCommandTest.java | 7 ++-- .../team/IslandTeamCoopCommandTest.java | 5 ++- .../team/IslandTeamInviteCommandTest.java | 32 ++++++++++--------- .../team/IslandTeamKickCommandTest.java | 10 +++--- .../team/IslandTeamTrustCommandTest.java | 6 ++-- .../team/IslandTeamUntrustCommandTest.java | 1 + 23 files changed, 99 insertions(+), 71 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java index 388e4b1ce..bcf001ec3 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandBanCommand.java @@ -112,8 +112,8 @@ private boolean ban(@NonNull User issuer, User target) { } // Event is not cancelled if (island.ban(issuer.getUniqueId(), target.getUniqueId())) { - issuer.sendMessage("commands.island.ban.player-banned", TextVariables.NAME, target.getName()); - target.sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, issuer.getName()); + issuer.sendMessage("commands.island.ban.player-banned", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); + target.sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, issuer.getName(), TextVariables.DISPLAY_NAME, issuer.getDisplayName()); // If the player is online, has an island and on the banned island, move them home immediately if (target.isOnline() && getIslands().hasIsland(getWorld(), target.getUniqueId()) && island.onIsland(target.getLocation())) { getIslands().homeTeleportAsync(getWorld(), target.getPlayer()); diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommand.java index a13ad2587..be7fbc0c6 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommand.java @@ -116,17 +116,17 @@ public boolean execute(User user, String label, List args) { return false; } - target.sendMessage("commands.island.expel.player-expelled-you", TextVariables.NAME, user.getName()); + target.sendMessage("commands.island.expel.player-expelled-you", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); island.getWorld().playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F); if (getIslands().hasIsland(getWorld(), target) || getIslands().inTeam(getWorld(), target.getUniqueId())) { // Success - user.sendMessage(SUCCESS, TextVariables.NAME, target.getName()); + user.sendMessage(SUCCESS, TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); // Teleport home getIslands().homeTeleportAsync(getWorld(), target.getPlayer()); return true; } else if (getIslands().getSpawn(getWorld()).isPresent()){ // Success - user.sendMessage(SUCCESS, TextVariables.NAME, target.getName()); + user.sendMessage(SUCCESS, TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); getIslands().spawnTeleport(getWorld(), target.getPlayer()); return true; } else if (getIWM().getAddon(getWorld()) @@ -136,7 +136,7 @@ public boolean execute(User user, String label, List args) { .orElse(false) && target.performCommand(this.getTopLabel() + " create")) { getAddon().logWarning("Expel: " + target.getName() + " had no island, so one was created"); - user.sendMessage(SUCCESS, TextVariables.NAME, target.getName()); + user.sendMessage(SUCCESS, TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); return true; } diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java index 9f4f25a93..041636e0f 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommand.java @@ -94,8 +94,8 @@ public boolean execute(User user, String label, List args) { } // Event is not cancelled if (island.unban(user.getUniqueId(), target.getUniqueId())) { - user.sendMessage("commands.island.unban.player-unbanned", TextVariables.NAME, target.getName()); - target.sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, user.getName()); + user.sendMessage("commands.island.unban.player-unbanned", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); + target.sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); // Set cooldown if (getSettings().getBanCooldown() > 0 && getParent() != null) { getParent().getSubCommand("ban").ifPresent(subCommand -> diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommand.java index 50c1d12de..5da40ae6d 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommand.java @@ -105,8 +105,8 @@ public boolean execute(User user, String label, List args) { } island.setRank(target, RanksManager.COOP_RANK); - user.sendMessage("commands.island.team.coop.success", TextVariables.NAME, target.getName()); - target.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, user.getName()); + user.sendMessage("commands.island.team.coop.success", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); + target.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); } return true; } else { diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java index 5f17a3ab2..89bd8ab64 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java @@ -111,10 +111,10 @@ private void acceptTrustInvite(User user, Invite invite) { .rankChange(island.getRank(user), RanksManager.TRUSTED_RANK) .build(); if (inviter.isOnline()) { - inviter.sendMessage("commands.island.team.trust.success", TextVariables.NAME, user.getName()); + inviter.sendMessage("commands.island.team.trust.success", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); } if (inviter.isPlayer()) { - user.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, inviter.getName()); + user.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, inviter.getName(), TextVariables.DISPLAY_NAME, inviter.getDisplayName()); } } } @@ -138,10 +138,10 @@ private void acceptCoopInvite(User user, Invite invite) { .rankChange(island.getRank(user), RanksManager.COOP_RANK) .build(); if (inviter.isOnline()) { - inviter.sendMessage("commands.island.team.coop.success", TextVariables.NAME, user.getName()); + inviter.sendMessage("commands.island.team.coop.success", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); } if (inviter.isPlayer()) { - user.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, inviter.getName()); + user.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, inviter.getName(), TextVariables.DISPLAY_NAME, inviter.getDisplayName()); } } } @@ -188,7 +188,7 @@ private void acceptTeamInvite(User user, Invite invite) { user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel()); User inviter = User.getInstance(invite.getInviter()); if (inviter.isOnline()) { - inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName()); + inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); } getIslands().save(teamIsland); // Fire event diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java index a36584f14..5eb674a4c 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java @@ -129,9 +129,9 @@ public boolean execute(User user, String label, List args) { // Put the invited player (key) onto the list with inviter (value) // If someone else has invited a player, then this invite will overwrite the previous invite! itc.addInvite(Invite.Type.TEAM, user.getUniqueId(), invitedPlayer.getUniqueId()); - user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, invitedPlayer.getName()); + user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, invitedPlayer.getName(), TextVariables.DISPLAY_NAME, invitedPlayer.getDisplayName()); // Send message to online player - invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName()); + invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); invitedPlayer.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel()); if (getIslands().hasIsland(getWorld(), invitedPlayer.getUniqueId())) { invitedPlayer.sendMessage("commands.island.team.invite.you-will-lose-your-island"); diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteRejectCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteRejectCommand.java index b09644b77..12dff7c0e 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteRejectCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteRejectCommand.java @@ -42,9 +42,9 @@ public boolean execute(User user, String label, List args) { } Optional.ofNullable(itc.getInviter(playerUUID)) - .map(User::getInstance) - .ifPresent(inviter -> - inviter.sendMessage("commands.island.team.invite.reject.name-rejected-your-invite", TextVariables.NAME, user.getName()) + .map(User::getInstance) + .ifPresent(inviter -> + inviter.sendMessage("commands.island.team.invite.reject.name-rejected-your-invite", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()) ); // Remove this player from the global invite list diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommand.java index 8722dfa1f..061e82259 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommand.java @@ -70,11 +70,11 @@ public boolean execute(User user, String label, List args) { int targetRank = Objects.requireNonNull(island).getRank(targetUUID); if (rank <= targetRank) { - user.sendMessage("commands.island.team.kick.cannot-kick-rank", - TextVariables.NAME, getPlayers().getName(targetUUID)); + user.sendMessage("commands.island.team.kick.cannot-kick-rank", + TextVariables.NAME, getPlayers().getName(targetUUID)); return false; } - + if (!getSettings().isKickConfirmation()) { kick(user, targetUUID); return true; @@ -96,15 +96,15 @@ private void kick(User user, UUID targetUUID) { if (event.isCancelled()) { return; } - target.sendMessage("commands.island.team.kick.player-kicked", - TextVariables.GAMEMODE, getAddon().getDescription().getName(), - TextVariables.NAME, user.getName()); + target.sendMessage("commands.island.team.kick.player-kicked", + TextVariables.GAMEMODE, getAddon().getDescription().getName(), + TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); getIslands().removePlayer(getWorld(), targetUUID); // Clean the target player getPlayers().cleanLeavingPlayer(getWorld(), target, true, oldIsland); - user.sendMessage("commands.island.team.kick.success", TextVariables.NAME, target.getName()); + user.sendMessage("commands.island.team.kick.success", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); IslandEvent.builder() .island(oldIsland) .involvedPlayer(user.getUniqueId()) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamLeaveCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamLeaveCommand.java index db1a37379..01d455fa8 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamLeaveCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamLeaveCommand.java @@ -78,7 +78,7 @@ private void leave(User user) { } UUID ownerUUID = getIslands().getOwner(getWorld(), user.getUniqueId()); if (ownerUUID != null) { - User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName()); + User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); } getIslands().setLeaveTeam(getWorld(), user.getUniqueId()); // Clean the player diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamPromoteCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamPromoteCommand.java index 7c8722a79..d4a32daeb 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamPromoteCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamPromoteCommand.java @@ -82,7 +82,7 @@ private boolean change(User user, User target) { if (nextRank != RanksManager.OWNER_RANK && nextRank > currentRank) { getIslands().getIsland(getWorld(), user.getUniqueId()).setRank(target, nextRank); String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(nextRank)); - user.sendMessage("commands.island.team.promote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName); + user.sendMessage("commands.island.team.promote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName, TextVariables.DISPLAY_NAME, target.getDisplayName()); IslandEvent.builder() .island(island) .involvedPlayer(user.getUniqueId()) @@ -102,7 +102,7 @@ private boolean change(User user, User target) { if (prevRank >= RanksManager.MEMBER_RANK && prevRank < currentRank) { getIslands().getIsland(getWorld(), user.getUniqueId()).setRank(target, prevRank); String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(prevRank)); - user.sendMessage("commands.island.team.demote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName); + user.sendMessage("commands.island.team.demote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName, TextVariables.DISPLAY_NAME, target.getDisplayName()); IslandEvent.builder() .island(island) .involvedPlayer(user.getUniqueId()) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommand.java index a8db0863d..22ea20482 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommand.java @@ -96,9 +96,9 @@ public boolean execute(User user, String label, List args) { // Put the invited player (key) onto the list with inviter (value) // If someone else has invited a player, then this invite will overwrite the previous invite! itc.addInvite(Type.TRUST, user.getUniqueId(), target.getUniqueId()); - user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName()); + user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); // Send message to online player - target.sendMessage("commands.island.team.trust.name-has-invited-you", TextVariables.NAME, user.getName()); + target.sendMessage("commands.island.team.trust.name-has-invited-you", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel()); } else { if (island.getMemberSet(RanksManager.TRUSTED_RANK, false).size() >= getIslands().getMaxMembers(island, RanksManager.TRUSTED_RANK)) { @@ -107,8 +107,8 @@ public boolean execute(User user, String label, List args) { } island.setRank(target, RanksManager.TRUSTED_RANK); - user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName()); - target.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, user.getName()); + user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); + target.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); } return true; } else { diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUncoopCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUncoopCommand.java index e219d3043..5df6a1133 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUncoopCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUncoopCommand.java @@ -84,8 +84,8 @@ private boolean unCoopCmd(User user, UUID targetUUID) { Island island = getIslands().getIsland(getWorld(), user.getUniqueId()); if (island != null) { island.removeMember(targetUUID); - user.sendMessage("commands.island.team.uncoop.success", TextVariables.NAME, target.getName()); - target.sendMessage("commands.island.team.uncoop.you-are-no-longer-a-coop-member", TextVariables.NAME, user.getName()); + user.sendMessage("commands.island.team.uncoop.success", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); + target.sendMessage("commands.island.team.uncoop.you-are-no-longer-a-coop-member", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); // Set cooldown if (getSettings().getCoopCooldown() > 0 && getParent() != null) { getParent().getSubCommand("coop").ifPresent(subCommand -> diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommand.java index 74b3de095..57034bf66 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommand.java @@ -84,8 +84,8 @@ private boolean unTrustCmd(User user, UUID targetUUID) { Island island = getIslands().getIsland(getWorld(), user.getUniqueId()); if (island != null) { island.removeMember(targetUUID); - user.sendMessage("commands.island.team.untrust.success", TextVariables.NAME, target.getName()); - target.sendMessage("commands.island.team.untrust.you-are-no-longer-trusted", TextVariables.NAME, user.getName()); + user.sendMessage("commands.island.team.untrust.success", TextVariables.NAME, target.getName(), TextVariables.DISPLAY_NAME, target.getDisplayName()); + target.sendMessage("commands.island.team.untrust.you-are-no-longer-trusted", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); // Set cooldown if (getSettings().getTrustCooldown() > 0 && getParent() != null) { getParent().getSubCommand("trust").ifPresent(subCommand -> diff --git a/src/main/java/world/bentobox/bentobox/api/localization/TextVariables.java b/src/main/java/world/bentobox/bentobox/api/localization/TextVariables.java index 61bce6fb5..d6de42f82 100644 --- a/src/main/java/world/bentobox/bentobox/api/localization/TextVariables.java +++ b/src/main/java/world/bentobox/bentobox/api/localization/TextVariables.java @@ -9,6 +9,7 @@ public class TextVariables { private TextVariables() {} public static final String NAME = "[name]"; + public static final String DISPLAY_NAME = "[display_name]"; public static final String DESCRIPTION = "[description]"; public static final String NUMBER = "[number]"; public static final String RANK = "[rank]"; diff --git a/src/main/java/world/bentobox/bentobox/api/user/User.java b/src/main/java/world/bentobox/bentobox/api/user/User.java index 2bcba88ca..7af3d6b8a 100644 --- a/src/main/java/world/bentobox/bentobox/api/user/User.java +++ b/src/main/java/world/bentobox/bentobox/api/user/User.java @@ -230,6 +230,16 @@ public String getName() { return player != null ? player.getName() : plugin.getPlayers().getName(playerUUID); } + /** + * Get the user's display name + * @return player's display name if the player is online otherwise just their name + * @since 1.22.1 + */ + @NonNull + public String getDisplayName() { + return player != null ? player.getDisplayName() : plugin.getPlayers().getName(playerUUID); + } + /** * Check if the User is a player before calling this method. {@link #isPlayer()} * @return the player @@ -353,7 +363,7 @@ public int getPermissionValue(String permissionPrefix, int defaultValue) { if (permissions.isEmpty()) return defaultValue; return iteratePerms(permissions, permPrefix, defaultValue); - + } private int iteratePerms(List permissions, String permPrefix, int defaultValue) { @@ -474,7 +484,7 @@ private String replacePrefixes(String translation, String[] variables) { } private String replaceVars(String reference, String[] variables) { - + // Then replace variables if (variables.length > 1) { for (int i = 0; i < variables.length; i += 2) { @@ -486,7 +496,7 @@ private String replaceVars(String reference, String[] variables) { if (player != null) { reference = plugin.getPlaceholdersManager().replacePlaceholders(player, reference); } - + // If no translation has been found, return the reference for debug purposes. return reference; } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanCommandTest.java index d3fa9fb22..00635da93 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandBanCommandTest.java @@ -104,6 +104,7 @@ public void setUp() throws Exception { when(user.getUniqueId()).thenReturn(uuid); when(user.getPlayer()).thenReturn(p); when(user.getName()).thenReturn("tastybento"); + when(user.getDisplayName()).thenReturn("&Ctastybento"); when(user.getPermissionValue(anyString(), anyInt())).thenReturn(-1); when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class)); @@ -157,6 +158,7 @@ public void setUp() throws Exception { UUID uuid = UUID.randomUUID(); when(pm.getUUID(anyString())).thenReturn(uuid); when(targetPlayer.getName()).thenReturn("bill"); + when(targetPlayer.getDisplayName()).thenReturn("&Cbill"); when(targetPlayer.getUniqueId()).thenReturn(uuid); when(targetPlayer.isOp()).thenReturn(false); when(targetPlayer.isOnline()).thenReturn(true); @@ -278,7 +280,7 @@ public void testBanOfflineUserSuccess() { when(island.ban(any(), any())).thenReturn(true); // Run execute assertTrue(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill"))); - verify(user).sendMessage("commands.island.ban.player-banned", "[name]", "bill"); + verify(user).sendMessage("commands.island.ban.player-banned", TextVariables.NAME, "bill", TextVariables.DISPLAY_NAME, "&Cbill"); verify(targetPlayer).sendMessage("commands.island.ban.owner-banned-you"); } @@ -290,7 +292,7 @@ public void testBanOnlineUserSuccess() { when(island.ban(any(), any())).thenReturn(true); assertTrue(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill"))); - verify(user).sendMessage("commands.island.ban.player-banned", "[name]", "bill"); + verify(user).sendMessage("commands.island.ban.player-banned", TextVariables.NAME, "bill", TextVariables.DISPLAY_NAME, "&Cbill"); verify(targetPlayer).sendMessage("commands.island.ban.owner-banned-you"); } @@ -302,7 +304,7 @@ public void testCancelledBan() { when(island.ban(any(), any())).thenReturn(false); assertFalse(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill"))); - verify(user, never()).sendMessage("commands.island.ban.player-banned", TextVariables.NAME, targetPlayer.getName()); + verify(user, never()).sendMessage("commands.island.ban.player-banned", TextVariables.NAME, targetPlayer.getName(), TextVariables.DISPLAY_NAME, targetPlayer.getDisplayName()); verify(targetPlayer, never()).sendMessage("commands.island.ban.owner-banned-you"); } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java index 2d02f7862..d1de24250 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandExpelCommandTest.java @@ -111,6 +111,7 @@ public void setUp() throws Exception { when(p.getServer()).thenReturn(server); when(user.getPlayer()).thenReturn(p); when(user.getName()).thenReturn("tastybento"); + when(user.getDisplayName()).thenReturn("&Ctastybento"); when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class)); // Parent command has no aliases @@ -365,6 +366,7 @@ private Player setUpTarget() { when(t.getLocation()).thenReturn(mock(Location.class)); when(t.performCommand(anyString())).thenReturn(true); when(t.getName()).thenReturn("target"); + when(t.getDisplayName()).thenReturn("&Ctarget"); when(t.getServer()).thenReturn(server); when(server.getOnlinePlayers()).thenReturn(Collections.emptySet()); User.getInstance(t); @@ -381,7 +383,7 @@ private Player setUpTarget() { public void testExecuteUserStringListOfStringHasIsland() { testCanExecute(); assertTrue(iec.execute(user, "", Collections.singletonList("tasty"))); - verify(user).sendMessage("commands.island.expel.success", TextVariables.NAME, "target"); + verify(user).sendMessage("commands.island.expel.success", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Ctarget"); verify(im).homeTeleportAsync(any(), any()); } @@ -395,7 +397,7 @@ public void testExecuteUserStringListOfStringNoIslandSendToSpawn() { testCanExecute(); when(im.hasIsland(any(), any(User.class))).thenReturn(false); assertTrue(iec.execute(user, "", Collections.singletonList("tasty"))); - verify(user).sendMessage("commands.island.expel.success", TextVariables.NAME, "target"); + verify(user).sendMessage("commands.island.expel.success", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Ctarget"); verify(im).spawnTeleport(any(), any()); } @@ -415,7 +417,7 @@ public void testExecuteUserStringListOfStringCreateIsland() { testCanExecute(); when(im.hasIsland(any(), any(User.class))).thenReturn(false); assertTrue(iec.execute(user, "", Collections.singletonList("tasty"))); - verify(user).sendMessage("commands.island.expel.success", TextVariables.NAME, "target"); + verify(user).sendMessage("commands.island.expel.success", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Ctarget"); verify(addon).logWarning(eq("Expel: target had no island, so one was created")); } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java index c618582eb..195992862 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/IslandUnbanCommandTest.java @@ -92,6 +92,7 @@ public void setUp() throws Exception { when(user.getUniqueId()).thenReturn(uuid); when(user.getPlayer()).thenReturn(p); when(user.getName()).thenReturn("tastybento"); + when(user.getDisplayName()).thenReturn("&Ctastybento"); when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class)); // Parent command has no aliases @@ -240,6 +241,8 @@ public void testUnbanUser() { when(targetUser.isOp()).thenReturn(false); when(targetUser.isPlayer()).thenReturn(true); when(targetUser.isOnline()).thenReturn(false); + when(targetUser.getName()).thenReturn("target"); + when(targetUser.getDisplayName()).thenReturn("&Ctarget"); when(User.getInstance(any(UUID.class))).thenReturn(targetUser); // Mark as banned when(island.isBanned(eq(targetUUID))).thenReturn(true); @@ -248,8 +251,8 @@ public void testUnbanUser() { when(island.unban(any(), any())).thenReturn(true); assertTrue(iubc.canExecute(user, iubc.getLabel(), Collections.singletonList("bill"))); assertTrue(iubc.execute(user, iubc.getLabel(), Collections.singletonList("bill"))); - verify(user).sendMessage("commands.island.unban.player-unbanned", TextVariables.NAME, targetUser.getName()); - verify(targetUser).sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, user.getName()); + verify(user).sendMessage("commands.island.unban.player-unbanned", TextVariables.NAME, targetUser.getName(), TextVariables.DISPLAY_NAME, targetUser.getDisplayName()); + verify(targetUser).sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); } /** diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommandTest.java index ef4bcbd1f..38aae1ad6 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCoopCommandTest.java @@ -95,6 +95,7 @@ public void setUp() throws Exception { when(user.getUniqueId()).thenReturn(uuid); when(user.getPlayer()).thenReturn(p); when(user.getName()).thenReturn("tastybento"); + when(user.getDisplayName()).thenReturn("&Ctastybento"); when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class)); User.setPlugin(plugin); @@ -304,6 +305,8 @@ public void testExecuteTooManyCoops() { public void testExecuteSuccess() { Player p = mock(Player.class); when(p.getUniqueId()).thenReturn(notUUID); + when(p.getName()).thenReturn("target"); + when(p.getDisplayName()).thenReturn("&Ctarget"); User target = User.getInstance(p); // Can execute when(pm.getUUID(any())).thenReturn(notUUID); @@ -315,7 +318,7 @@ public void testExecuteSuccess() { // Execute when(im.getIsland(any(), any(UUID.class))).thenReturn(island); assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento"))); - verify(user).sendMessage("commands.island.team.coop.success", TextVariables.NAME, null); + verify(user).sendMessage("commands.island.team.coop.success", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Ctarget"); verify(island).setRank(target, RanksManager.COOP_RANK); } } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java index 27410725b..de0b1da13 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java @@ -101,6 +101,7 @@ public void setUp() throws Exception { when(user.getUniqueId()).thenReturn(uuid); when(user.getPlayer()).thenReturn(p); when(user.getName()).thenReturn("tastybento"); + when(user.getDisplayName()).thenReturn("&Ctastbento"); when(user.isOnline()).thenReturn(true); // Permission to invite 3 more players when(user.getPermissionValue(anyString(), anyInt())).thenReturn(3); @@ -116,6 +117,7 @@ public void setUp() throws Exception { when(target.getPlayer()).thenReturn(p); when(target.isOnline()).thenReturn(true); when(target.getName()).thenReturn("target"); + when(target.getDisplayName()).thenReturn("&Ctarget"); when(User.getInstance(eq(notUUID))).thenReturn(target); @@ -297,10 +299,10 @@ public void testExecuteSuccessTargetHasIsland() { verify(pim).callEvent(any(IslandBaseEvent.class)); verify(user, never()).sendMessage(eq("commands.island.team.invite.removing-invite")); verify(ic).addInvite(eq(Invite.Type.TEAM), eq(uuid), eq(notUUID)); - verify(user).sendMessage(eq("commands.island.team.invite.invitation-sent"), eq(TextVariables.NAME), eq("target")); - verify(target).sendMessage(eq("commands.island.team.invite.name-has-invited-you"), eq(TextVariables.NAME), eq("tastybento")); - verify(target).sendMessage(eq("commands.island.team.invite.to-accept-or-reject"), eq(TextVariables.LABEL), eq("island")); - verify(target).sendMessage(eq("commands.island.team.invite.you-will-lose-your-island")); + verify(user).sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Ctarget"); + verify(target).sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, "tastybento", TextVariables.DISPLAY_NAME, "&Ctastbento"); + verify(target).sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, "island"); + verify(target).sendMessage("commands.island.team.invite.you-will-lose-your-island"); } @@ -312,12 +314,12 @@ public void testExecuteSuccessTargetHasNoIsland() { testCanExecuteSuccess(); assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("target"))); verify(pim).callEvent(any(IslandBaseEvent.class)); - verify(user, never()).sendMessage(eq("commands.island.team.invite.removing-invite")); - verify(ic).addInvite(eq(Invite.Type.TEAM), eq(uuid), eq(notUUID)); - verify(user).sendMessage(eq("commands.island.team.invite.invitation-sent"), eq(TextVariables.NAME), eq("target")); - verify(target).sendMessage(eq("commands.island.team.invite.name-has-invited-you"), eq(TextVariables.NAME), eq("tastybento")); - verify(target).sendMessage(eq("commands.island.team.invite.to-accept-or-reject"), eq(TextVariables.LABEL), eq("island")); - verify(target, never()).sendMessage(eq("commands.island.team.invite.you-will-lose-your-island")); + verify(user, never()).sendMessage("commands.island.team.invite.removing-invite"); + verify(ic).addInvite(Invite.Type.TEAM, uuid, notUUID); + verify(user).sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Ctarget"); + verify(target).sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, "tastybento", TextVariables.DISPLAY_NAME, "&Ctastbento"); + verify(target).sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, "island"); + verify(target, never()).sendMessage("commands.island.team.invite.you-will-lose-your-island"); } @@ -328,16 +330,16 @@ public void testExecuteSuccessTargetHasNoIsland() { public void testExecuteTargetAlreadyInvited() { testCanExecuteSuccess(); - when(ic.isInvited(eq(notUUID))).thenReturn(true); + when(ic.isInvited(notUUID)).thenReturn(true); // Set up invite - when(ic.getInviter(eq(notUUID))).thenReturn(uuid); + when(ic.getInviter(notUUID)).thenReturn(uuid); Invite invite = mock(Invite.class); when(invite.getType()).thenReturn(Type.TEAM); - when(ic.getInvite(eq(notUUID))).thenReturn(invite); + when(ic.getInvite(notUUID)).thenReturn(invite); assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("target"))); verify(pim).callEvent(any(IslandBaseEvent.class)); - verify(ic).removeInvite(eq(notUUID)); - verify(user).sendMessage(eq("commands.island.team.invite.removing-invite")); + verify(ic).removeInvite(notUUID); + verify(user).sendMessage("commands.island.team.invite.removing-invite"); } } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java index c4c8710d5..29c98a69e 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java @@ -113,11 +113,13 @@ public void setUp() throws Exception { when(target.getUniqueId()).thenReturn(notUUID); when(target.isOnline()).thenReturn(true); when(target.getName()).thenReturn("poslovitch"); + when(target.getDisplayName()).thenReturn("&Cposlovich"); // Set the target user User.getInstance(target); when(user.getUniqueId()).thenReturn(uuid); when(user.getPlayer()).thenReturn(player); when(user.getName()).thenReturn("tastybento"); + when(user.getDisplayName()).thenReturn("&Ctastybento"); when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class)); User.setPlugin(plugin); @@ -263,7 +265,7 @@ public void testExecuteLargerTeamRank() { IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); verify(im).removePlayer(any(), eq(notUUID)); - verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch"); + verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich"); } /** @@ -353,7 +355,7 @@ public void testExecuteNoConfirmation() { IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); verify(im).removePlayer(any(), eq(notUUID)); - verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch"); + verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich"); } /** @@ -375,7 +377,7 @@ public void testExecuteNoConfirmationKeepInventory() { IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); verify(im).removePlayer(any(), eq(notUUID)); - verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch"); + verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich"); verify(target, Mockito.never()).getInventory(); } @@ -403,7 +405,7 @@ public void testExecuteNoConfirmationLoseInventoryOffline() { IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); verify(im).removePlayer(any(), eq(notUUID)); - verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch"); + verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich"); verify(target, Mockito.never()).getInventory(); verify(pm).cleanLeavingPlayer(any(), any(User.class), eq(true), eq(island)); } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommandTest.java index 2a6808a82..afb0507a4 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamTrustCommandTest.java @@ -100,11 +100,13 @@ public void setUp() throws Exception { when(user.getUniqueId()).thenReturn(uuid); when(user.getPlayer()).thenReturn(p); when(user.getName()).thenReturn("tastybento"); + when(user.getDisplayName()).thenReturn("&Ctastybento"); when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class)); User.setPlugin(plugin); // Target player when(targetPlayer.getUniqueId()).thenReturn(notUUID); when(targetPlayer.getName()).thenReturn("target"); + when(targetPlayer.getDisplayName()).thenReturn("&Cposlovich"); User.getInstance(targetPlayer); // Parent command has no aliases @@ -311,7 +313,7 @@ public void testExecuteSuccessNoConfirmation() { // Execute when(im.getIsland(any(), Mockito.any(UUID.class))).thenReturn(island); assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("target"))); - verify(user).sendMessage(eq("commands.island.team.trust.success"), eq(TextVariables.NAME), eq("target")); + verify(user).sendMessage("commands.island.team.trust.success", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Cposlovich"); verify(island).setRank(target, RanksManager.TRUSTED_RANK); verify(targetPlayer).sendMessage("commands.island.team.trust.you-are-trusted"); } @@ -333,7 +335,7 @@ public void testExecuteSuccessConfirmation() { // Execute when(im.getIsland(any(), Mockito.any(UUID.class))).thenReturn(island); assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("target"))); - verify(user).sendMessage(eq("commands.island.team.invite.invitation-sent"), eq(TextVariables.NAME), eq("target")); + verify(user).sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Cposlovich"); // Send message to online player verify(targetPlayer).sendMessage(eq("commands.island.team.trust.name-has-invited-you")); verify(targetPlayer).sendMessage(eq("commands.island.team.invite.to-accept-or-reject")); diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommandTest.java index 76ffeef36..948fc82ae 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamUntrustCommandTest.java @@ -90,6 +90,7 @@ public void setUp() throws Exception { when(user.getUniqueId()).thenReturn(uuid); when(user.getPlayer()).thenReturn(p); when(user.getName()).thenReturn("tastybento"); + when(user.getDisplayName()).thenReturn("&Ctastybento"); when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class)); User.setPlugin(plugin); From 2cb561b943653c1a6f457df4fb486ba1c941e7aa Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 18 Mar 2023 10:28:19 -0700 Subject: [PATCH 13/26] Update to 1.19.3 for NMS (#2107) * Update to 1.19.3 for NMS Clean up some imports and deprecation notifications. * Added 1.19.4 to compatible servers --- pom.xml | 4 ++-- .../api/panels/reader/ItemTemplateRecord.java | 2 -- .../panels/reader/PanelTemplateRecord.java | 1 - .../flags/clicklisteners/GeoMobLimitTab.java | 1 - .../flags/protection/BreakBlocksListener.java | 3 +++ .../WorldRegeneratorImpl.java | 6 +++--- .../bentobox/bentobox/util/MyBiomeGrid.java | 21 ++++++++++--------- .../versions/ServerCompatibility.java | 4 ++++ 8 files changed, 23 insertions(+), 19 deletions(-) rename src/main/java/world/bentobox/bentobox/nms/{v1_19_R2 => v1_19_R3}/WorldRegeneratorImpl.java (87%) diff --git a/pom.xml b/pom.xml index c780ea0d8..98b734cd0 100644 --- a/pom.xml +++ b/pom.xml @@ -73,10 +73,10 @@ 42.2.18 5.0.1 - 1.19.3-R0.1-SNAPSHOT + 1.19.4-R0.1-SNAPSHOT - 1.19.3-R0.1-SNAPSHOT + 1.19.4-R0.1-SNAPSHOT 3.0.0 1.7.1 2.10.9 diff --git a/src/main/java/world/bentobox/bentobox/api/panels/reader/ItemTemplateRecord.java b/src/main/java/world/bentobox/bentobox/api/panels/reader/ItemTemplateRecord.java index c1c157124..e5911c802 100644 --- a/src/main/java/world/bentobox/bentobox/api/panels/reader/ItemTemplateRecord.java +++ b/src/main/java/world/bentobox/bentobox/api/panels/reader/ItemTemplateRecord.java @@ -17,8 +17,6 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; -import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord.ActionRecords; - /** * This Record contains all necessary information about Item Template that can be used to craft panel item. * diff --git a/src/main/java/world/bentobox/bentobox/api/panels/reader/PanelTemplateRecord.java b/src/main/java/world/bentobox/bentobox/api/panels/reader/PanelTemplateRecord.java index 18d5506f1..f260fb564 100644 --- a/src/main/java/world/bentobox/bentobox/api/panels/reader/PanelTemplateRecord.java +++ b/src/main/java/world/bentobox/bentobox/api/panels/reader/PanelTemplateRecord.java @@ -15,7 +15,6 @@ import org.eclipse.jdt.annotation.Nullable; import world.bentobox.bentobox.api.panels.Panel; -import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem; /** * This is template object for the panel reader. It contains data that can exist in the panel. diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTab.java b/src/main/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTab.java index ce37e7635..b721dee20 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTab.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/clicklisteners/GeoMobLimitTab.java @@ -1,7 +1,6 @@ package world.bentobox.bentobox.listeners.flags.clicklisteners; import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; import java.util.List; diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java index 80deb6ffe..7d18a1378 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java @@ -74,6 +74,9 @@ public void onPlayerInteract(final PlayerInteractEvent e) case SPAWNER -> this.checkIsland(e, p, l, Flags.BREAK_SPAWNERS); case DRAGON_EGG -> this.checkIsland(e, p, l, Flags.DRAGON_EGG); case HOPPER -> this.checkIsland(e, p, l, Flags.BREAK_HOPPERS); + default -> { + // Do nothing + } } } diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_19_R2/WorldRegeneratorImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_19_R3/WorldRegeneratorImpl.java similarity index 87% rename from src/main/java/world/bentobox/bentobox/nms/v1_19_R2/WorldRegeneratorImpl.java rename to src/main/java/world/bentobox/bentobox/nms/v1_19_R3/WorldRegeneratorImpl.java index d74925517..2d1aecc76 100644 --- a/src/main/java/world/bentobox/bentobox/nms/v1_19_R2/WorldRegeneratorImpl.java +++ b/src/main/java/world/bentobox/bentobox/nms/v1_19_R3/WorldRegeneratorImpl.java @@ -1,10 +1,10 @@ -package world.bentobox.bentobox.nms.v1_19_R2; +package world.bentobox.bentobox.nms.v1_19_R3; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R2.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData; import net.minecraft.core.BlockPosition; import net.minecraft.world.level.World; diff --git a/src/main/java/world/bentobox/bentobox/util/MyBiomeGrid.java b/src/main/java/world/bentobox/bentobox/util/MyBiomeGrid.java index c776b715b..bd5499e34 100644 --- a/src/main/java/world/bentobox/bentobox/util/MyBiomeGrid.java +++ b/src/main/java/world/bentobox/bentobox/util/MyBiomeGrid.java @@ -14,22 +14,23 @@ * @author tastybento * */ +@SuppressWarnings("deprecation") public class MyBiomeGrid implements BiomeGrid { Map map = new HashMap<>(); private Biome defaultBiome; public MyBiomeGrid(Environment environment) { switch (environment) { - case NETHER -> { - try { - // 1.16 onwards - defaultBiome = Biome.valueOf("NETHER_WASTES"); - } catch (Exception e) { - // Before 1.16 - defaultBiome = Biome.valueOf("NETHER"); - } + case NETHER -> { + try { + // 1.16 onwards + defaultBiome = Biome.valueOf("NETHER_WASTES"); + } catch (Exception e) { + // Before 1.16 + defaultBiome = Biome.valueOf("NETHER"); } - case THE_END -> defaultBiome = Biome.THE_END; - default -> defaultBiome = Biome.PLAINS; + } + case THE_END -> defaultBiome = Biome.THE_END; + default -> defaultBiome = Biome.PLAINS; } } diff --git a/src/main/java/world/bentobox/bentobox/versions/ServerCompatibility.java b/src/main/java/world/bentobox/bentobox/versions/ServerCompatibility.java index dfef37415..50c58f533 100644 --- a/src/main/java/world/bentobox/bentobox/versions/ServerCompatibility.java +++ b/src/main/java/world/bentobox/bentobox/versions/ServerCompatibility.java @@ -214,6 +214,10 @@ public enum ServerVersion { * @since 1.22.0 */ V1_19_3(Compatibility.COMPATIBLE), + /** + * @since 1.22.1 + */ + V1_19_4(Compatibility.COMPATIBLE), ; private final Compatibility compatibility; From 5d67dbe5e38b4b9390ab0673502e1af58505d4be Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 18 Mar 2023 17:46:56 -0400 Subject: [PATCH 14/26] Javadoc clarification --- .../world/bentobox/bentobox/api/addons/GameModeAddon.java | 2 +- .../world/bentobox/bentobox/nms/SimpleWorldRegenerator.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java b/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java index 66b58a940..a45b12d68 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java @@ -117,7 +117,7 @@ public Optional getAdminCommand() { /** * Defines the world generator for this game mode * @param worldName - name of world that this applies to - * @param id - id if any + * @param id - id if any. "delete" is used when this request is for island deletion purposes * @return Chunk generator or null if one does not exist, e.g. the use own generator setting is true * @since 1.2.0 */ diff --git a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java index 7fcd72ea7..d46ef8415 100644 --- a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java @@ -11,7 +11,9 @@ import org.bukkit.block.data.BlockData; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; +import org.bukkit.generator.LimitedRegion; import org.bukkit.inventory.InventoryHolder; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.BoundingBox; @@ -105,6 +107,9 @@ private CompletableFuture regenerateChunk(GameModeAddon gm, IslandDeletion if (cg != null) { ChunkGenerator.ChunkData cd = cg.generateChunkData(chunk.getWorld(), new Random(), chunk.getX(), chunk.getZ(), grid); copyChunkDataToChunk(chunk, cd, grid, di.getBox()); + for (BlockPopulator pop : cg.getDefaultPopulators(world)) { + pop.populate(world, new Random(), chunkX, chunkZ, null); + } } return chunk; }); From 233e5ceb65498ef80e0f03084c08dcb93f96e3f7 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 19 Mar 2023 18:49:16 -0400 Subject: [PATCH 15/26] Add SHULKER_TELEPORT flag English text. --- src/main/resources/locales/en-US.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index afdeb2cd4..6c95e78b9 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -851,6 +851,11 @@ protection: name: "Shulker boxes" description: "Toggle shulker box interaction" hint: "Shulker box access disabled" + SHULKER_TELEPORT: + description: |- + &a Shulker can teleport + &a if active. + name: "Shulker teleport" TRAPPED_CHEST: name: "Trapped chests" description: "Toggle trapped chest interaction" From 6894695024f444275b6ace617df7ffbefcc4518b Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 23 Mar 2023 11:02:08 -0700 Subject: [PATCH 16/26] Clean up test classes; use latest API --- pom.xml | 2 +- .../admin/AdminTeleportCommandTest.java | 1 - .../StandardSpawnProtectionListenerTest.java | 6 ++-- .../flags/protection/BucketListenerTest.java | 29 ++++++++++--------- .../protection/PlaceBlocksListenerTest.java | 4 +-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 98b734cd0..a7659b985 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,7 @@ 1.19.4-R0.1-SNAPSHOT - 1.19.4-R0.1-SNAPSHOT + 1.19.3-R0.1-SNAPSHOT 3.0.0 1.7.1 2.10.9 diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommandTest.java index 2e19b2970..5d0bb3a76 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/AdminTeleportCommandTest.java @@ -29,7 +29,6 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; diff --git a/src/test/java/world/bentobox/bentobox/listeners/StandardSpawnProtectionListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/StandardSpawnProtectionListenerTest.java index b41fc2f1e..8beb740c2 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/StandardSpawnProtectionListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/StandardSpawnProtectionListenerTest.java @@ -324,7 +324,7 @@ public void testOnExplosionNoProtection() { */ @Test public void testOnBucketEmptyDisallowed() { - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.DOWN, null, null); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.DOWN, null, null, null); ssp.onBucketEmpty(e); assertTrue(e.isCancelled()); verify(player).sendMessage("protection.spawn-protected"); @@ -336,7 +336,7 @@ public void testOnBucketEmptyDisallowed() { @Test public void testOnBucketEmptyDisallowedNoProtection() { when(ws.isMakeNetherPortals()).thenReturn(true); - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.DOWN, null, null); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.DOWN, null, null, null); ssp.onBucketEmpty(e); assertFalse(e.isCancelled()); verify(player, never()).sendMessage("protection.spawn-protected"); @@ -348,7 +348,7 @@ public void testOnBucketEmptyDisallowedNoProtection() { @Test public void testOnBucketEmptyAllowed() { when(player.isOp()).thenReturn(true); - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.DOWN, null, null); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.DOWN, null, null, null); ssp.onBucketEmpty(e); assertFalse(e.isCancelled()); verify(player, never()).sendMessage("protection.spawn-protected"); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java index dd99b6b87..45ea1d3eb 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BucketListenerTest.java @@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.junit.Before; @@ -65,7 +66,7 @@ public void testOnBucketEmptyAllowed() { when(block.getLocation()).thenReturn(location); when(block.getRelative(any())).thenReturn(block); ItemStack item = mock(ItemStack.class); - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketEmpty(e); assertFalse(e.isCancelled()); } @@ -80,7 +81,7 @@ public void testOnBucketEmptyNotAllowed() { when(block.getLocation()).thenReturn(location); when(block.getRelative(any())).thenReturn(block); ItemStack item = mock(ItemStack.class); - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketEmpty(e); assertTrue(e.isCancelled()); verify(notifier).notify(any(), eq("protection.protected")); @@ -96,22 +97,22 @@ public void testOnBucketFillAllowed() { when(block.getRelative(any())).thenReturn(block); ItemStack item = mock(ItemStack.class); when(item.getType()).thenReturn(Material.WATER_BUCKET); - PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertFalse(e.isCancelled()); when(item.getType()).thenReturn(Material.BUCKET); - e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertFalse(e.isCancelled()); when(item.getType()).thenReturn(Material.LAVA_BUCKET); - e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertFalse(e.isCancelled()); when(item.getType()).thenReturn(Material.MILK_BUCKET); - e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertFalse(e.isCancelled()); } @@ -127,22 +128,22 @@ public void testOnBucketFillNotAllowed() { when(block.getRelative(any())).thenReturn(block); ItemStack item = mock(ItemStack.class); when(item.getType()).thenReturn(Material.WATER_BUCKET); - PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertTrue(e.isCancelled()); when(item.getType()).thenReturn(Material.BUCKET); - e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertTrue(e.isCancelled()); when(item.getType()).thenReturn(Material.LAVA_BUCKET); - e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertTrue(e.isCancelled()); when(item.getType()).thenReturn(Material.MILK_BUCKET); - e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertTrue(e.isCancelled()); @@ -163,22 +164,22 @@ public void testOnBucketFillMixedAllowed() { when(block.getRelative(any())).thenReturn(block); ItemStack item = mock(ItemStack.class); when(item.getType()).thenReturn(Material.WATER_BUCKET); - PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertFalse(e.isCancelled()); when(item.getType()).thenReturn(Material.BUCKET); - e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertTrue(e.isCancelled()); when(item.getType()).thenReturn(Material.LAVA_BUCKET); - e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertFalse(e.isCancelled()); when(item.getType()).thenReturn(Material.MILK_BUCKET); - e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item); + e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); l.onBucketFill(e); assertFalse(e.isCancelled()); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java index 3be61170c..bee267cf7 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java @@ -105,7 +105,7 @@ public void testOnHangingPlaceAllowed() { Hanging hanging = mock(Hanging.class); Block block = mock(Block.class); when(block.getLocation()).thenReturn(location); - HangingPlaceEvent e = new HangingPlaceEvent(hanging, player, block, BlockFace.EAST, null); + HangingPlaceEvent e = new HangingPlaceEvent(hanging, player, block, BlockFace.EAST, null, null); pbl.onHangingPlace(e); assertFalse(e.isCancelled()); verify(notifier, never()).notify(any(), eq("protection.protected")); @@ -120,7 +120,7 @@ public void testOnHangingPlaceNotAllowed() { Hanging hanging = mock(Hanging.class); Block block = mock(Block.class); when(block.getLocation()).thenReturn(location); - HangingPlaceEvent e = new HangingPlaceEvent(hanging, player, block, BlockFace.EAST, null); + HangingPlaceEvent e = new HangingPlaceEvent(hanging, player, block, BlockFace.EAST, null, null); pbl.onHangingPlace(e); assertTrue(e.isCancelled()); verify(notifier).notify(any(), eq("protection.protected")); From 907268c2f493da9927f04b737a9d82eb73ca6460 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 25 Mar 2023 09:08:18 -0700 Subject: [PATCH 17/26] Use Bukkit loadPlugin for loading Pladdons Provides compatibility with Paper. Ensured bytecode rewriting is done when code is loaded. --- .../java/world/bentobox/bentobox/managers/AddonsManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index a9511de82..e12865366 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -190,7 +190,7 @@ private void loadAddon(@NonNull File f) { private PladdonData loadPladdon(YamlConfiguration data, @NonNull File f) throws InvalidAddonInheritException, MalformedURLException, InvalidAddonDescriptionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InvalidDescriptionException { Addon addon = null; try { - Plugin pladdon = pluginLoader.loadPlugin(f); + Plugin pladdon = Bukkit.getPluginManager().loadPlugin(f); if (pladdon instanceof Pladdon pl) { addon = pl.getAddon(); addon.setDescription(AddonClassLoader.asDescription(data)); @@ -202,6 +202,8 @@ private PladdonData loadPladdon(YamlConfiguration data, @NonNull File f) throws return new PladdonData(null, false); } } catch (Exception ex) { + + ex.printStackTrace(); // Addon not pladdon AddonClassLoader addonClassLoader = new AddonClassLoader(this, data, f, this.getClass().getClassLoader()); // Get the addon itself From 25e601b26c6cb7d494219d6a781014f27dd1869f Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 25 Mar 2023 09:08:34 -0700 Subject: [PATCH 18/26] Now with proper commit... --- .../java/world/bentobox/bentobox/managers/AddonsManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index e12865366..856b0a9b7 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -202,8 +202,8 @@ private PladdonData loadPladdon(YamlConfiguration data, @NonNull File f) throws return new PladdonData(null, false); } } catch (Exception ex) { - - ex.printStackTrace(); + plugin.logError("Could not load pladdon " + f.getName() + ". Loading as addon."); + plugin.logStacktrace(ex); // Addon not pladdon AddonClassLoader addonClassLoader = new AddonClassLoader(this, data, f, this.getClass().getClassLoader()); // Get the addon itself From 85a7375004fc778143905293d97114886dbdda91 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 25 Mar 2023 15:50:39 -0700 Subject: [PATCH 19/26] Remove warnings on loading addons (not Pladdons) --- .../java/world/bentobox/bentobox/managers/AddonsManager.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index 856b0a9b7..0b78c10fb 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -202,8 +202,6 @@ private PladdonData loadPladdon(YamlConfiguration data, @NonNull File f) throws return new PladdonData(null, false); } } catch (Exception ex) { - plugin.logError("Could not load pladdon " + f.getName() + ". Loading as addon."); - plugin.logStacktrace(ex); // Addon not pladdon AddonClassLoader addonClassLoader = new AddonClassLoader(this, data, f, this.getClass().getClassLoader()); // Get the addon itself From 1a293a69363b367353cf0257ab7dddb8420ebf9c Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 26 Mar 2023 10:05:54 -0700 Subject: [PATCH 20/26] Implements NMS for pasting and supports older versions of server (#2110) * Implements NMS for pasting and supports older versions of server * Remove trial code that shouldn't have been committed. * Remove trial code that shouldn't have been committed. * Remove 1.19.3 support. * Use 1.19.4 in POM --- pom.xml | 3 +- .../bentobox/nms/SimpleWorldRegenerator.java | 1 - .../nms/v1_19_R3/PasteHandlerImpl.java | 82 +++++++++++++++++++ .../world/bentobox/bentobox/util/Util.java | 37 ++++++--- src/main/resources/plugin.yml | 1 + 5 files changed, 111 insertions(+), 13 deletions(-) create mode 100644 src/main/java/world/bentobox/bentobox/nms/v1_19_R3/PasteHandlerImpl.java diff --git a/pom.xml b/pom.xml index a7659b985..38d2f4ed6 100644 --- a/pom.xml +++ b/pom.xml @@ -91,6 +91,7 @@ 1.22.1 bentobox-world https://sonarcloud.io + ${project.basedir}/lib @@ -312,7 +313,7 @@ 3.2.2 provided - + org.spigotmc spigot diff --git a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java index d46ef8415..e7142284b 100644 --- a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java @@ -13,7 +13,6 @@ import org.bukkit.entity.Player; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; -import org.bukkit.generator.LimitedRegion; import org.bukkit.inventory.InventoryHolder; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.BoundingBox; diff --git a/src/main/java/world/bentobox/bentobox/nms/v1_19_R3/PasteHandlerImpl.java b/src/main/java/world/bentobox/bentobox/nms/v1_19_R3/PasteHandlerImpl.java new file mode 100644 index 000000000..14af30231 --- /dev/null +++ b/src/main/java/world/bentobox/bentobox/nms/v1_19_R3/PasteHandlerImpl.java @@ -0,0 +1,82 @@ +package world.bentobox.bentobox.nms.v1_19_R3; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData; + +import net.minecraft.core.BlockPosition; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.chunk.Chunk; +import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock; +import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity; +import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.bentobox.nms.PasteHandler; +import world.bentobox.bentobox.util.DefaultPasteUtil; +import world.bentobox.bentobox.util.Util; + +public class PasteHandlerImpl implements PasteHandler { + + protected static final IBlockData AIR = ((CraftBlockData) Bukkit.createBlockData(Material.AIR)).getState(); + + @Override + public CompletableFuture pasteBlocks(Island island, World world, Map blockMap) { + return blockMap.entrySet().stream() + .map(entry -> setBlock(island, entry.getKey(), entry.getValue())) + .collect( + Collectors.collectingAndThen( + Collectors.toList(), + list -> CompletableFuture.allOf(list.toArray(new CompletableFuture[0])) + ) + ); + } + + @Override + public CompletableFuture pasteEntities(Island island, World world, Map> entityMap) { + return entityMap.entrySet().stream() + .map(entry -> DefaultPasteUtil.setEntity(island, entry.getKey(), entry.getValue())) + .collect( + Collectors.collectingAndThen( + Collectors.toList(), + list -> CompletableFuture.allOf(list.toArray(new CompletableFuture[0])) + ) + ); + } + + /** + * Set the block to the location + * + * @param island - island + * @param location - location + * @param bpBlock - blueprint block + */ + public static CompletableFuture setBlock(Island island, Location location, BlueprintBlock bpBlock) { + return Util.getChunkAtAsync(location).thenRun(() -> { + Block block = location.getBlock(); + // Set the block data - default is AIR + BlockData bd = DefaultPasteUtil.createBlockData(bpBlock); + CraftBlockData craft = (CraftBlockData) bd; + net.minecraft.world.level.World nmsWorld = ((CraftWorld) location.getWorld()).getHandle(); + Chunk nmsChunk = nmsWorld.d(location.getBlockX() >> 4, location.getBlockZ() >> 4); + BlockPosition bp = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + // Setting the block to air before setting to another state prevents some console errors + nmsChunk.a(bp, AIR, false); + nmsChunk.a(bp, craft.getState(), false); + block.setBlockData(bd, false); + DefaultPasteUtil.setBlockState(island, block, bpBlock); + // Set biome + if (bpBlock.getBiome() != null) { + block.setBiome(bpBlock.getBiome()); + } + }); + } +} diff --git a/src/main/java/world/bentobox/bentobox/util/Util.java b/src/main/java/world/bentobox/bentobox/util/Util.java index 822bf7ef7..b804d5d73 100644 --- a/src/main/java/world/bentobox/bentobox/util/Util.java +++ b/src/main/java/world/bentobox/bentobox/util/Util.java @@ -738,6 +738,32 @@ public static WorldRegenerator getRegenerator() { } return regenerator; } + + /** + * Checks what version the server is running and picks the appropriate NMS handler, or fallback + * @return PasteHandler + */ + public static PasteHandler getPasteHandler() { + if (pasteHandler == null) { + String serverPackageName = Bukkit.getServer().getClass().getPackage().getName(); + String pluginPackageName = plugin.getClass().getPackage().getName(); + String version = serverPackageName.substring(serverPackageName.lastIndexOf('.') + 1); + PasteHandler handler; + try { + Class clazz = Class.forName(pluginPackageName + ".nms." + version + ".PasteHandlerImpl"); + if (PasteHandler.class.isAssignableFrom(clazz)) { + handler = (PasteHandler) clazz.getConstructor().newInstance(); + } else { + throw new IllegalStateException("Class " + clazz.getName() + " does not implement PasteHandler"); + } + } catch (Exception e) { + plugin.logWarning("No PasteHandler found for " + version + ", falling back to Bukkit API."); + handler = new world.bentobox.bentobox.nms.fallback.PasteHandlerImpl(); + } + setPasteHandler(handler); + } + return pasteHandler; + } /** * Set the paste handler the plugin will use @@ -747,17 +773,6 @@ public static void setPasteHandler(PasteHandler pasteHandler) { Util.pasteHandler = pasteHandler; } - /** - * Get the paste handler the plugin will use - * @return an NMS accelerated class for this server - */ - public static PasteHandler getPasteHandler() { - if (pasteHandler == null) { - setPasteHandler(new world.bentobox.bentobox.nms.fallback.PasteHandlerImpl()); - } - return pasteHandler; - } - /** * Broadcast a localized message to all players with the permission {@link Server#BROADCAST_CHANNEL_USERS} * diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index bc5ef1ccb..1d84e6f85 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -60,3 +60,4 @@ permissions: bentobox.version: description: Allows to use /bentobox version default: op + From 073f3a49d5dbb8673679827f2c6c0cec1bd98eb5 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 26 Mar 2023 10:06:38 -0700 Subject: [PATCH 21/26] Adds API to enable translations to be set and specific API for flags (#2109) This was a request on Discord so that plugins can set flags and set the name and lore for them too. --- .../bentobox/bentobox/api/flags/Flag.java | 28 ++++++++++ .../bentobox/managers/LocalesManager.java | 19 +++++++ .../bentobox/bentobox/api/flags/FlagTest.java | 51 +++++++++++++++---- .../bentobox/managers/LocalesManagerTest.java | 37 ++++++++++++-- 4 files changed, 121 insertions(+), 14 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/flags/Flag.java b/src/main/java/world/bentobox/bentobox/api/flags/Flag.java index e860b44e1..409296228 100644 --- a/src/main/java/world/bentobox/bentobox/api/flags/Flag.java +++ b/src/main/java/world/bentobox/bentobox/api/flags/Flag.java @@ -2,6 +2,7 @@ import java.util.Arrays; import java.util.HashSet; +import java.util.Locale; import java.util.Optional; import java.util.Set; @@ -466,6 +467,33 @@ public boolean hasSubflags() { public Set getSubflags() { return subflags; } + + /** + * Set the name of this flag for a specified locale. This enables the flag's name to be assigned via API. It will not be stored anywhere + * and must be rewritten using this call every time the flag is built. + * @param locale locale (language) to which this name should be assigned. Assigning to {@code Locale.US} will make this the default + * @param name the translated name for this flag + * @return true if successful, false if the locale is unknown to this server. + * See {@link world.bentobox.bentobox.managers.LocalesManager#getAvailableLocales(boolean sort)} + * @since 1.22.1 + */ + public boolean setTranslatedName(Locale locale, String name) { + return BentoBox.getInstance().getLocalesManager().setTranslation(locale, getNameReference(), name); + } + + /** + * Set the name of this flag for a specified locale. This enables the flag's name to be assigned via API. It will not be stored anywhere + * and must be rewritten using this call every time the flag is built. + * @param locale locale (language) to which this name should be assigned. Assigning to {@code Locale.US} will make this the default + * @param description the translated description for this flag + * @return true if successful, false if the locale is unknown to this server. + * See {@link world.bentobox.bentobox.managers.LocalesManager#getAvailableLocales(boolean sort)} + * @since 1.22.1 + */ + + public boolean setTranslatedDescription(Locale locale, String description) { + return BentoBox.getInstance().getLocalesManager().setTranslation(locale, getDescriptionReference(), description); + } @Override public String toString() { diff --git a/src/main/java/world/bentobox/bentobox/managers/LocalesManager.java b/src/main/java/world/bentobox/bentobox/managers/LocalesManager.java index cb54aa29d..ce5fbeb87 100644 --- a/src/main/java/world/bentobox/bentobox/managers/LocalesManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/LocalesManager.java @@ -104,6 +104,25 @@ public String get(String reference) { } return null; } + + /** + * Set the translation for a reference for a specific locale. The locale must be a known locale on this server. + * User {@link #getAvailableLocales(boolean)} to find out what locales are available. + * Note, the usual default locale is {@code Locale.US} + * @param locale locale + * @param reference reference + * @param translation translation + * @return true if successful, false if the locale is not a known locale on this server + * @since 1.22.1 + */ + public boolean setTranslation(Locale locale, String reference, String translation) { + // Set a translation + if (!languages.containsKey(locale)) { + return false; + } + languages.get(locale).set(reference, translation); + return true; + } /** * Gets the translated String corresponding to the reference from the server's or the en-US locale file. diff --git a/src/test/java/world/bentobox/bentobox/api/flags/FlagTest.java b/src/test/java/world/bentobox/bentobox/api/flags/FlagTest.java index eb6545dca..a1d44d8b0 100644 --- a/src/test/java/world/bentobox/bentobox/api/flags/FlagTest.java +++ b/src/test/java/world/bentobox/bentobox/api/flags/FlagTest.java @@ -6,6 +6,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -13,6 +15,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -45,6 +48,7 @@ import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; +import world.bentobox.bentobox.managers.LocalesManager; import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.util.Util; @@ -66,6 +70,8 @@ public class FlagTest { private IslandWorldManager iwm; @Mock private BentoBox plugin; + @Mock + private LocalesManager lm; /** */ @@ -76,7 +82,7 @@ public void setUp() throws Exception { PowerMockito.mockStatic(Util.class); // Return world - when(Util.getWorld(Mockito.any())).thenAnswer((Answer) invocation -> invocation.getArgument(0, World.class)); + when(Util.getWorld(any())).thenAnswer((Answer) invocation -> invocation.getArgument(0, World.class)); // World Settings when(plugin.getIWM()).thenReturn(iwm); @@ -92,8 +98,13 @@ public void setUp() throws Exception { PowerMockito.mockStatic(Bukkit.class); ItemFactory itemF = mock(ItemFactory.class); ItemMeta im = mock(ItemMeta.class); - when(itemF.getItemMeta(Mockito.any())).thenReturn(im); + when(itemF.getItemMeta(any())).thenReturn(im); when(Bukkit.getItemFactory()).thenReturn(itemF); + + // Locales manager + when(plugin.getLocalesManager()).thenReturn(lm); + // Setting US text is successful + when(lm.setTranslation(eq(Locale.US), anyString(), anyString())).thenReturn(true); // Flag f = new Flag.Builder("flagID", Material.ACACIA_PLANKS).type(Flag.Type.PROTECTION).listener(listener).build(); @@ -346,7 +357,7 @@ public void testToPanelItem() { IslandsManager im = mock(IslandsManager.class); Island island = mock(Island.class); - when(island.getFlag(Mockito.any())).thenReturn(RanksManager.VISITOR_RANK); + when(island.getFlag(any())).thenReturn(RanksManager.VISITOR_RANK); User user = mock(User.class); when(user.getUniqueId()).thenReturn(UUID.randomUUID()); @@ -357,27 +368,45 @@ public void testToPanelItem() { return sb.toString(); }; - when(user.getTranslation(Mockito.any(String.class),Mockito.any(),Mockito.any())).thenAnswer(answer); + when(user.getTranslation(any(String.class),any(),any())).thenAnswer(answer); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island); + when(im.getIsland(any(), any(UUID.class))).thenReturn(island); + when(im.getIsland(any(), any(User.class))).thenReturn(island); Optional oL = Optional.of(island); - when(im.getIslandAt(Mockito.any(Location.class))).thenReturn(oL); + when(im.getIslandAt(any(Location.class))).thenReturn(oL); when(plugin.getIslands()).thenReturn(im); RanksManager rm = mock(RanksManager.class); when(plugin.getRanksManager()).thenReturn(rm); - when(rm.getRank(Mockito.eq(RanksManager.VISITOR_RANK))).thenReturn("Visitor"); - when(rm.getRank(Mockito.eq(RanksManager.OWNER_RANK))).thenReturn("Owner"); + when(rm.getRank(RanksManager.VISITOR_RANK)).thenReturn("Visitor"); + when(rm.getRank(RanksManager.OWNER_RANK)).thenReturn("Owner"); PanelItem pi = f.toPanelItem(plugin, user, island, false); - verify(user).getTranslation(Mockito.eq("protection.flags.flagID.name")); - verify(user).getTranslation(Mockito.eq("protection.panel.flag-item.name-layout"), any()); + verify(user).getTranslation("protection.flags.flagID.name"); + verify(user).getTranslation(eq("protection.panel.flag-item.name-layout"), any()); assertEquals(Material.ACACIA_PLANKS, pi.getItem().getType()); } + + /** + * Test method for {@link world.bentobox.bentobox.api.flags.Flag#setTranslatedName(java.util.Locale, String)}. + */ + @Test + public void testSetTranslatedName() { + assertFalse(f.setTranslatedName(Locale.CANADA, "Good eh?")); + assertTrue(f.setTranslatedName(Locale.US, "Yihaa")); + } + + /** + * Test method for {@link world.bentobox.bentobox.api.flags.Flag#setTranslatedDescription(java.util.Locale, String)}. + */ + @Test + public void testSetTranslatedDescription() { + assertFalse(f.setTranslatedDescription(Locale.CANADA, "Good eh?")); + assertTrue(f.setTranslatedDescription(Locale.US, "Yihaa")); + } /** * Test method for {@link world.bentobox.bentobox.api.flags.Flag#toString()}. diff --git a/src/test/java/world/bentobox/bentobox/managers/LocalesManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/LocalesManagerTest.java index 51e9da70e..005e72494 100644 --- a/src/test/java/world/bentobox/bentobox/managers/LocalesManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/LocalesManagerTest.java @@ -1,9 +1,11 @@ package world.bentobox.bentobox.managers; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.BufferedInputStream; @@ -64,6 +66,10 @@ public void setUp() throws Exception { when(plugin.getSettings()).thenReturn(settings); } + /** + * Makes fake English and French local files + * @throws IOException if the file saving fails + */ private void makeFakeLocaleFile() throws IOException { File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + BENTOBOX); File english = new File(localeDir, Locale.US.toLanguageTag() + ".yml"); @@ -270,7 +276,7 @@ public void testReloadLanguagesNoAddons() throws IOException { makeFakeLocaleFile(); LocalesManager lm = new LocalesManager(plugin); lm.reloadLanguages(); - Mockito.verify(am).getAddons(); + verify(am).getAddons(); File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + BENTOBOX); assertTrue(localeDir.exists()); } @@ -313,7 +319,7 @@ public void testReloadLanguages() throws IOException { lm.reloadLanguages(); // Verify that the resources have been saved (note that they are not actually saved because addon is a mock) - Mockito.verify(addon).saveResource( + verify(addon).saveResource( Mockito.eq("locales/en-US.yml"), Mockito.any(), Mockito.eq(false), @@ -332,6 +338,8 @@ public void testReloadLanguages() throws IOException { } } + + private void add(File source, JarOutputStream target) throws IOException { @@ -388,9 +396,32 @@ public void testReloadLanguagesNoLocaleFolder() throws IOException { when(plugin.getAddonsManager()).thenReturn(am); LocalesManager lm = new LocalesManager(plugin); lm.reloadLanguages(); - Mockito.verify(am).getAddons(); + verify(am).getAddons(); File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + BENTOBOX); assertTrue(localeDir.exists()); } + /** + * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#setTranslation(Locale, String, String)}. + */ + @Test + public void testSetTranslationUnknownLocale() throws IOException { + makeFakeLocaleFile(); + LocalesManager lm = new LocalesManager(plugin); + assertFalse(lm.setTranslation(Locale.GERMAN, "anything.ref", "a translation")); + + } + + /** + * Test method for {@link world.bentobox.bentobox.managers.LocalesManager#setTranslation(Locale, String, String)}. + */ + @Test + public void testSetTranslationKnownLocale() throws IOException { + makeFakeLocaleFile(); + LocalesManager lm = new LocalesManager(plugin); + assertEquals("test string", lm.get("test.test")); + assertTrue(lm.setTranslation(Locale.US, "test.test", "a translation")); + assertEquals("a translation", lm.get("test.test")); + + } } From ba19b08f4cdf470db4eda93ddae0b58fa7c28302 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 7 Apr 2023 17:28:02 +0100 Subject: [PATCH 22/26] Version 1.23.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 38d2f4ed6..b541aa8cd 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ -LOCAL - 1.22.1 + 1.23.0 bentobox-world https://sonarcloud.io ${project.basedir}/lib From b4737f104c388f48b98420b0c11a82c47f48359f Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 7 Apr 2023 20:51:59 +0100 Subject: [PATCH 23/26] Implements HARVEST and CROP_PLANTING protection flags Requested by #2113 --- .../flags/protection/BreakBlocksListener.java | 27 ++++++-- .../flags/protection/PlaceBlocksListener.java | 17 ++++- .../world/bentobox/bentobox/lists/Flags.java | 21 +++++- src/main/resources/locales/en-US.yml | 12 ++++ .../protection/BreakBlocksListenerTest.java | 32 +++++++++ .../protection/PlaceBlocksListenerTest.java | 67 +++++++++++++++++++ 6 files changed, 166 insertions(+), 10 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java index 7d18a1378..a720ed67c 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java @@ -2,6 +2,7 @@ import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.block.data.BlockData; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.ArmorStand; @@ -31,7 +32,26 @@ public class BreakBlocksListener extends FlagListener { */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onBlockBreak(final BlockBreakEvent e) { - checkIsland(e, e.getPlayer(), e.getBlock().getLocation(), Flags.BREAK_BLOCKS); + Player p = e.getPlayer(); + Location l = e.getBlock().getLocation(); + Material m = e.getBlock().getType(); + switch (m) + { + case MELON -> this.checkIsland(e, p, l, Flags.HARVEST); + case PUMPKIN -> this.checkIsland(e, p, l, Flags.HARVEST); + default -> { + // Crops + if (Tag.CROPS.isTagged(m) + && !m.equals(Material.MELON_STEM) + && !m.equals(Material.PUMPKIN_STEM) + && !m.equals(Material.ATTACHED_MELON_STEM) + && !m.equals(Material.ATTACHED_PUMPKIN_STEM)) { + this.checkIsland(e, p, l, Flags.HARVEST); + } else { + checkIsland(e, p, l, Flags.BREAK_BLOCKS); + } + } + } } /** @@ -64,11 +84,10 @@ public void onPlayerInteract(final PlayerInteractEvent e) { return; } - Player p = e.getPlayer(); Location l = e.getClickedBlock().getLocation(); - - switch (e.getClickedBlock().getType()) + Material m = e.getClickedBlock().getType(); + switch (m) { case CAKE -> this.checkIsland(e, p, l, Flags.BREAK_BLOCKS); case SPAWNER -> this.checkIsland(e, p, l, Flags.BREAK_SPAWNERS); diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListener.java index 7b4b7d7c0..a77d1b785 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListener.java @@ -1,5 +1,7 @@ package world.bentobox.bentobox.listeners.flags.protection; +import java.util.Set; + import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -12,6 +14,7 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.flags.FlagListener; import world.bentobox.bentobox.lists.Flags; @@ -20,6 +23,7 @@ */ public class PlaceBlocksListener extends FlagListener { + public static final Set SEEDS = Set.of(Material.BEETROOT_SEEDS, Material.MELON_SEEDS, Material.WHEAT_SEEDS); /** * Check blocks being placed in general * @@ -28,7 +32,9 @@ public class PlaceBlocksListener extends FlagListener @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onBlockPlace(final BlockPlaceEvent e) { - if (e.getBlock().getType().equals(Material.FIRE) || + Material m = e.getBlock().getType(); + Material against = e.getBlockAgainst().getType(); + if (m.equals(Material.FIRE) || e.getItemInHand() == null || // Note that this should never happen officially, but it's possible for other plugins to cause it to happen e.getItemInHand().getType().equals(Material.WRITABLE_BOOK) || e.getItemInHand().getType().equals(Material.WRITTEN_BOOK)) @@ -36,8 +42,12 @@ public void onBlockPlace(final BlockPlaceEvent e) // Books can only be placed on lecterns and as such are protected by the LECTERN flag. return; } - - this.checkIsland(e, e.getPlayer(), e.getBlock().getLocation(), Flags.PLACE_BLOCKS); + // Crops + if (against.equals(Material.FARMLAND) && SEEDS.contains(e.getItemInHand().getType())) { + this.checkIsland(e, e.getPlayer(), e.getBlock().getLocation(), Flags.CROP_PLANTING); + } else { + this.checkIsland(e, e.getPlayer(), e.getBlock().getLocation(), Flags.PLACE_BLOCKS); + } } @@ -61,6 +71,7 @@ public void onHangingPlace(final HangingPlaceEvent e) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerHitItemFrame(PlayerInteractEntityEvent e) { + BentoBox.getInstance().logDebug(e.getEventName()); if (e.getRightClicked().getType().equals(EntityType.ITEM_FRAME) || e.getRightClicked().getType().equals(EntityType.GLOW_ITEM_FRAME)) { diff --git a/src/main/java/world/bentobox/bentobox/lists/Flags.java b/src/main/java/world/bentobox/bentobox/lists/Flags.java index 69133742c..4f74ca46e 100644 --- a/src/main/java/world/bentobox/bentobox/lists/Flags.java +++ b/src/main/java/world/bentobox/bentobox/lists/Flags.java @@ -288,12 +288,12 @@ private Flags() {} public static final Flag SHEARING = new Flag.Builder("SHEARING", Material.SHEARS).listener(new ShearingListener()).mode(Flag.Mode.ADVANCED).build(); // Item pickup or drop - public static final Flag ITEM_DROP = new Flag.Builder("ITEM_DROP", Material.DIAMOND).defaultSetting(true).listener(new ItemDropPickUpListener()).mode(Flag.Mode.BASIC).build(); - public static final Flag ITEM_PICKUP = new Flag.Builder("ITEM_PICKUP", Material.SUGAR_CANE).mode(Flag.Mode.BASIC).build(); + public static final Flag ITEM_DROP = new Flag.Builder("ITEM_DROP", Material.DIAMOND).defaultRank(RanksManager.VISITOR_RANK).listener(new ItemDropPickUpListener()).mode(Flag.Mode.BASIC).build(); + public static final Flag ITEM_PICKUP = new Flag.Builder("ITEM_PICKUP", Material.SUGAR_CANE).mode(Flag.Mode.BASIC).defaultRank(RanksManager.VISITOR_RANK).build(); // Experience public static final Flag EXPERIENCE_PICKUP = new Flag.Builder("EXPERIENCE_PICKUP", Material.EXPERIENCE_BOTTLE) - .listener(Util.isPaper() ? new PaperExperiencePickupListener() : new ExperiencePickupListener()).mode(Flag.Mode.ADVANCED).build(); + .listener(Util.isPaper() ? new PaperExperiencePickupListener() : new ExperiencePickupListener()).mode(Flag.Mode.ADVANCED).defaultRank(RanksManager.VISITOR_RANK).build(); // Command ranks public static final Flag COMMAND_RANKS = new Flag.Builder("COMMAND_RANKS", Material.PLAYER_HEAD) @@ -648,6 +648,21 @@ private Flags() {} */ public static final Flag ENTITY_PORTAL_TELEPORT = new Flag.Builder("ENTITY_PORTAL_TELEPORT", Material.ENDER_EYE).type(Type.WORLD_SETTING).defaultSetting(false).build(); + /** + * Harvest Setting + * Controls who gets to harvest any crop related contents. e.g. Wheat, Sugar Cane, melon blocks, not stems, pumpkin blocks, etc. + * @since 1.23.0 + */ + public static final Flag HARVEST = new Flag.Builder("HARVEST", Material.PUMPKIN).type(Type.PROTECTION).build(); + + /** + * Crop Planting + * Controls who gets to plant crops on tilled soil. + * @since 1.23.0 + */ + public static final Flag CROP_PLANTING = new Flag.Builder("CROP_PLANTING", Material.PUMPKIN_SEEDS).type(Type.PROTECTION).build(); + + /** * Provides a list of all the Flag instances contained in this class using reflection. * Deprecated Flags are ignored. diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 6c95e78b9..d83706da1 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -933,6 +933,11 @@ protection: &a by island visitor. name: "Creeper griefing protection" hint: "Creeper griefing disabled" + CROP_PLANTING: + description: |- + &a Set who can plant seeds. + name: "Crop planting" + hint: "Crop planting disabled" CROP_TRAMPLE: description: "Toggle crop trampling" name: "Trample crops" @@ -1041,6 +1046,13 @@ protection: &a outside protected &a island space name: "&e Limit mobs to island" + HARVEST: + description: |- + &a Set who can harvest crops. + &a Don't forget to allow item + &a pickup too! + name: "Crop harvesting" + hint: "Crop harvesting disabled" HIVE: description: |- &a Toggle hive harvesting. diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java index ec0e59eea..687916edd 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListenerTest.java @@ -80,6 +80,7 @@ public void setUp() throws Exception { public void testOnBlockBreakAllowed() { Block block = mock(Block.class); when(block.getLocation()).thenReturn(location); + when(block.getType()).thenReturn(Material.DIRT); BlockBreakEvent e = new BlockBreakEvent(block, player); bbl.onBlockBreak(e); assertFalse(e.isCancelled()); @@ -92,12 +93,43 @@ public void testOnBlockBreakAllowed() { public void testOnBlockBreakNotAllowed() { when(island.isAllowed(any(), any())).thenReturn(false); Block block = mock(Block.class); + when(block.getType()).thenReturn(Material.DIRT); when(block.getLocation()).thenReturn(location); BlockBreakEvent e = new BlockBreakEvent(block, player); bbl.onBlockBreak(e); assertTrue(e.isCancelled()); verify(notifier).notify(any(), eq("protection.protected")); } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}. + */ + @Test + public void testOnBlockHarvestNotAllowed() { + when(island.isAllowed(any(), eq(Flags.HARVEST))).thenReturn(false); + Block block = mock(Block.class); + when(block.getType()).thenReturn(Material.PUMPKIN); + when(block.getLocation()).thenReturn(location); + BlockBreakEvent e = new BlockBreakEvent(block, player); + bbl.onBlockBreak(e); + assertTrue(e.isCancelled()); + verify(notifier).notify(any(), eq("protection.protected")); + } + + /** + * Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}. + */ + @Test + public void testOnBlockHarvestAllowed() { + when(island.isAllowed(any(), eq(Flags.BREAK_BLOCKS))).thenReturn(false); + when(island.isAllowed(any(), eq(Flags.HARVEST))).thenReturn(true); + Block block = mock(Block.class); + when(block.getType()).thenReturn(Material.PUMPKIN); + when(block.getLocation()).thenReturn(location); + BlockBreakEvent e = new BlockBreakEvent(block, player); + bbl.onBlockBreak(e); + assertFalse(e.isCancelled()); + } /** * Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onBreakHanging(org.bukkit.event.hanging.HangingBreakByEntityEvent)}. diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java index bee267cf7..e04f72b41 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/protection/PlaceBlocksListenerTest.java @@ -89,6 +89,7 @@ public void testOnBlockPlace() { when(placedBlock.getLocation()).thenReturn(location); BlockState replacedBlockState = mock(BlockState.class); Block placedAgainst = mock(Block.class); + when(placedAgainst.getType()).thenReturn(Material.STONE); ItemStack itemInHand = mock(ItemStack.class); when(itemInHand.getType()).thenReturn(Material.STONE); EquipmentSlot hand = EquipmentSlot.HAND; @@ -153,6 +154,7 @@ public void testOnBlockPlaceNotAllowed() { when(placedBlock.getLocation()).thenReturn(location); BlockState replacedBlockState = mock(BlockState.class); Block placedAgainst = mock(Block.class); + when(placedAgainst.getType()).thenReturn(Material.STONE); ItemStack itemInHand = mock(ItemStack.class); when(itemInHand.getType()).thenReturn(Material.STONE); EquipmentSlot hand = EquipmentSlot.HAND; @@ -161,6 +163,71 @@ public void testOnBlockPlaceNotAllowed() { assertTrue(e.isCancelled()); verify(notifier).notify(any(), eq("protection.protected")); } + + /** + * Test method for {@link PlaceBlocksListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}. + */ + @Test + public void testOnBlockCropsAllowed() { + when(island.isAllowed(any(), eq(Flags.PLACE_BLOCKS))).thenReturn(false); + when(island.isAllowed(any(), eq(Flags.CROP_PLANTING))).thenReturn(true); + Block placedBlock = mock(Block.class); + when(placedBlock.getType()).thenReturn(Material.WHEAT); + when(placedBlock.getLocation()).thenReturn(location); + BlockState replacedBlockState = mock(BlockState.class); + Block placedAgainst = mock(Block.class); + when(placedAgainst.getType()).thenReturn(Material.FARMLAND); + ItemStack itemInHand = mock(ItemStack.class); + when(itemInHand.getType()).thenReturn(Material.WHEAT_SEEDS); + EquipmentSlot hand = EquipmentSlot.HAND; + BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, player, true, hand); + pbl.onBlockPlace(e); + assertFalse(e.isCancelled()); + } + + /** + * Test method for {@link PlaceBlocksListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}. + */ + @Test + public void testOnBlockCropsAllowedNotCrop() { + when(island.isAllowed(any(), eq(Flags.PLACE_BLOCKS))).thenReturn(false); + when(island.isAllowed(any(), eq(Flags.CROP_PLANTING))).thenReturn(true); + Block placedBlock = mock(Block.class); + when(placedBlock.getType()).thenReturn(Material.DIRT); + when(placedBlock.getLocation()).thenReturn(location); + BlockState replacedBlockState = mock(BlockState.class); + Block placedAgainst = mock(Block.class); + when(placedAgainst.getType()).thenReturn(Material.FARMLAND); + ItemStack itemInHand = mock(ItemStack.class); + when(itemInHand.getType()).thenReturn(Material.DIRT); + EquipmentSlot hand = EquipmentSlot.HAND; + BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, player, true, hand); + pbl.onBlockPlace(e); + assertTrue(e.isCancelled()); + verify(notifier).notify(any(), eq("protection.protected")); + } + + /** + * Test method for {@link PlaceBlocksListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}. + */ + @Test + public void testOnBlockCropsNotAllowed() { + when(island.isAllowed(any(), eq(Flags.PLACE_BLOCKS))).thenReturn(false); + when(island.isAllowed(any(), eq(Flags.CROP_PLANTING))).thenReturn(false); + Block placedBlock = mock(Block.class); + when(placedBlock.getType()).thenReturn(Material.WHEAT); + when(placedBlock.getLocation()).thenReturn(location); + BlockState replacedBlockState = mock(BlockState.class); + Block placedAgainst = mock(Block.class); + when(placedAgainst.getType()).thenReturn(Material.FARMLAND); + ItemStack itemInHand = mock(ItemStack.class); + when(itemInHand.getType()).thenReturn(Material.WHEAT_SEEDS); + EquipmentSlot hand = EquipmentSlot.HAND; + BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, player, true, hand); + pbl.onBlockPlace(e); + assertTrue(e.isCancelled()); + verify(notifier).notify(any(), eq("protection.protected")); + } /** * Test method for {@link PlaceBlocksListener#onBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}. From c235abbfa613a17b2e7c3dbc673bf2675fcde122 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 8 Apr 2023 00:39:27 +0300 Subject: [PATCH 24/26] Disable chunk generation on rengeneration (#2114) The SimpleWorldRegenerator generated world new chunks that were not generated before. It is not necessary, as regeneration should happen only on used chunks. --- .../bentobox/bentobox/nms/SimpleWorldRegenerator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java index e7142284b..f37efc192 100644 --- a/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java +++ b/src/main/java/world/bentobox/bentobox/nms/SimpleWorldRegenerator.java @@ -66,7 +66,12 @@ public void run() { } final int x = chunkX; final int z = chunkZ; - newTasks.add(regenerateChunk(gm, di, world, x, z)); + + // Only process non-generated chunks + if (world.isChunkGenerated(x, z)) { + newTasks.add(regenerateChunk(gm, di, world, x, z)); + } + chunkZ++; if (chunkZ > di.getMaxZChunk()) { chunkZ = di.getMinZChunk(); From 9ee5bcbcf2fa98fe5f4c10001917f59f060dc059 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 8 Apr 2023 15:49:27 +0100 Subject: [PATCH 25/26] 2023 --- src/main/resources/locales/en-US.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index d83706da1..122dc307b 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -1656,7 +1656,7 @@ successfully-loaded: |2 &6 ____ _ ____ &6 | _ \ | | | _ \ &7 by &a tastybento &7 and &a Poslovitch - &6 | |_) | ___ _ __ | |_ ___ | |_) | _____ __ &7 2017 - 2022 + &6 | |_) | ___ _ __ | |_ ___ | |_) | _____ __ &7 2017 - 2023 &6 | _ < / _ \ '_ \| __/ _ \| _ < / _ \ \/ / &6 | |_) | __/ | | | || (_) | |_) | (_) > < &b v&e [version] &6 |____/ \___|_| |_|\__\___/|____/ \___/_/\_\ &8 Loaded in &e [time]&8 ms. From 84e6523b9dbc50fc1dcae13409ec749192a71f8e Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 8 Apr 2023 16:20:35 +0100 Subject: [PATCH 26/26] Only disable Addons, not Pladdons Plugin disabling is done by the server. Fixes #2117 --- .../java/world/bentobox/bentobox/managers/AddonsManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index 0b78c10fb..8ccc1bc88 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -450,8 +450,8 @@ public void reloadAddons() { public void disableAddons() { if (!getEnabledAddons().isEmpty()) { plugin.log("Disabling addons..."); - // Disable addons - getEnabledAddons().forEach(this::disable); + // Disable addons - pladdons are disabled by the server + getEnabledAddons().stream().filter(addon -> !pladdons.keySet().contains(addon)).forEach(this::disable); plugin.log("Addons successfully disabled."); } // Unregister all commands