bbs = plugin.getBlueprintsManager().getBlueprintBundles(command.getAddon()).values()
- .stream().sorted(sortByDisplayName).collect(Collectors.toList());
+ .stream().sorted(sortByDisplayName).toList();
// Loop through them and create items in the panel
for (BlueprintBundle bb : bbs) {
String perm = command.getPermissionPrefix() + "island.create." + bb.getUniqueId();
@@ -50,7 +49,7 @@ public class IslandCreationPanel {
// Add an item
PanelItem item = new PanelItemBuilder()
.name(bb.getDisplayName())
- .description(bb.getDescription().stream().map(Util::translateColorCodes).collect(Collectors.toList()))
+ .description(bb.getDescription().stream().map(Util::translateColorCodes).toList())
.icon(bb.getIcon()).clickHandler((panel, user1, clickType, slot1) -> {
user1.closeInventory();
command.execute(user1, label, Collections.singletonList(bb.getUniqueId()));
diff --git a/src/main/java/world/bentobox/bentobox/panels/ManagementPanel.java b/src/main/java/world/bentobox/bentobox/panels/ManagementPanel.java
index 3c6293c6a..197c80ba7 100644
--- a/src/main/java/world/bentobox/bentobox/panels/ManagementPanel.java
+++ b/src/main/java/world/bentobox/bentobox/panels/ManagementPanel.java
@@ -1,7 +1,6 @@
package world.bentobox.bentobox.panels;
import java.util.List;
-import java.util.stream.Collectors;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@@ -91,7 +90,7 @@ public class ManagementPanel {
}
}
case ADDONS -> {
- addons = plugin.getAddonsManager().getEnabledAddons().stream().filter(addon -> !(addon instanceof GameModeAddon)).collect(Collectors.toList());
+ addons = plugin.getAddonsManager().getEnabledAddons().stream().filter(addon -> !(addon instanceof GameModeAddon)).toList();
if (addons.isEmpty()) {
looksEmpty(builder, user);
break;
diff --git a/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java b/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java
index 4f8f907e1..9657aba49 100644
--- a/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java
+++ b/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java
@@ -124,7 +124,7 @@ public class SettingsTab implements Tab, ClickHandler {
plugin.getPlayers().setFlagsDisplayMode(user.getUniqueId(), plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId()).getNext());
flags = getFlags();
}
- return flags.stream().map((f -> f.toPanelItem(plugin, user, island, plugin.getIWM().getHiddenFlags(world).contains(f.getID())))).collect(Collectors.toList());
+ return flags.stream().map((f -> f.toPanelItem(plugin, user, island, plugin.getIWM().getHiddenFlags(world).contains(f.getID())))).toList();
}
@Override
diff --git a/src/main/java/world/bentobox/bentobox/panels/settings/WorldDefaultSettingsTab.java b/src/main/java/world/bentobox/bentobox/panels/settings/WorldDefaultSettingsTab.java
index 5917a93f6..dd680cbfd 100644
--- a/src/main/java/world/bentobox/bentobox/panels/settings/WorldDefaultSettingsTab.java
+++ b/src/main/java/world/bentobox/bentobox/panels/settings/WorldDefaultSettingsTab.java
@@ -2,7 +2,6 @@ package world.bentobox.bentobox.panels.settings;
import java.util.Arrays;
import java.util.List;
-import java.util.stream.Collectors;
import org.bukkit.Material;
import org.bukkit.World;
@@ -82,7 +81,7 @@ public class WorldDefaultSettingsTab extends SettingsTab implements Tab {
TextVariables.DESCRIPTION, user.getTranslation(f.getDescriptionReference()),
"[setting]", worldSetting).split("\n")));
return i;
- }).collect(Collectors.toList());
+ }).toList();
}
}
diff --git a/src/main/java/world/bentobox/bentobox/util/DefaultPasteUtil.java b/src/main/java/world/bentobox/bentobox/util/DefaultPasteUtil.java
index f6e1ce18d..7cd43cef5 100644
--- a/src/main/java/world/bentobox/bentobox/util/DefaultPasteUtil.java
+++ b/src/main/java/world/bentobox/bentobox/util/DefaultPasteUtil.java
@@ -1,16 +1,29 @@
package world.bentobox.bentobox.util;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
-import org.bukkit.block.*;
+import org.bukkit.block.Banner;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
+import org.bukkit.block.CreatureSpawner;
+import org.bukkit.block.Sign;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.WallSign;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
+
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
@@ -20,9 +33,6 @@ import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.nms.PasteHandler;
-import java.util.*;
-import java.util.concurrent.CompletableFuture;
-
/**
* A utility class for {@link PasteHandler}
*
@@ -37,6 +47,8 @@ public class DefaultPasteUtil {
plugin = BentoBox.getInstance();
}
+ private DefaultPasteUtil() {} // private constructor to hide the implicit public one.
+
/**
* Set the block to the location
*
diff --git a/src/main/java/world/bentobox/bentobox/util/DeleteIslandChunks.java b/src/main/java/world/bentobox/bentobox/util/DeleteIslandChunks.java
index a9be0f62b..178052bbf 100644
--- a/src/main/java/world/bentobox/bentobox/util/DeleteIslandChunks.java
+++ b/src/main/java/world/bentobox/bentobox/util/DeleteIslandChunks.java
@@ -1,7 +1,11 @@
package world.bentobox.bentobox.util;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import org.bukkit.World;
import org.bukkit.scheduler.BukkitRunnable;
+
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.events.island.IslandEvent;
@@ -9,9 +13,6 @@ import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
import world.bentobox.bentobox.database.objects.IslandDeletion;
import world.bentobox.bentobox.nms.WorldRegenerator;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.atomic.AtomicBoolean;
-
/**
* Deletes islands chunk by chunk
*
diff --git a/src/main/java/world/bentobox/bentobox/util/ItemParser.java b/src/main/java/world/bentobox/bentobox/util/ItemParser.java
index aaf583e9f..49335b69e 100644
--- a/src/main/java/world/bentobox/bentobox/util/ItemParser.java
+++ b/src/main/java/world/bentobox/bentobox/util/ItemParser.java
@@ -35,6 +35,7 @@ import world.bentobox.bentobox.BentoBox;
*/
public class ItemParser {
+ private ItemParser() {} // private constructor to hide the implicit public one.
/**
* Parse given string to ItemStack.
* @param text String value of item stack.
@@ -110,20 +111,20 @@ public class ItemParser {
returnValue = parseItemDurabilityAndQuantity(part);
}
- if (returnValue != null) {
- // If wrapper is just for code-style null-pointer checks.
- if (customModelData != null) {
- // We have custom data model. Now assign it to the item-stack.
- ItemMeta itemMeta = returnValue.getItemMeta();
+ if (returnValue != null
+ // If wrapper is just for code-style null-pointer checks.
+ && customModelData != null) {
+ // We have custom data model. Now assign it to the item-stack.
+ ItemMeta itemMeta = returnValue.getItemMeta();
- // Another null-pointer check for materials that does not have item meta.
- if (itemMeta != null) {
- itemMeta.setCustomModelData(customModelData);
- // Update meta to the return item.
- returnValue.setItemMeta(itemMeta);
- }
+ // Another null-pointer check for materials that does not have item meta.
+ if (itemMeta != null) {
+ itemMeta.setCustomModelData(customModelData);
+ // Update meta to the return item.
+ returnValue.setItemMeta(itemMeta);
}
}
+
} catch (Exception exception) {
BentoBox.getInstance().logError("Could not parse item " + text + " " + exception.getLocalizedMessage());
returnValue = defaultItemStack;
@@ -169,8 +170,8 @@ public class ItemParser {
ItemMeta meta = durability.getItemMeta();
- if (meta instanceof Damageable) {
- ((Damageable) meta).setDamage(Integer.parseInt(part[1]));
+ if (meta instanceof Damageable damageable) {
+ damageable.setDamage(Integer.parseInt(part[1]));
durability.setItemMeta(meta);
}
@@ -181,9 +182,13 @@ public class ItemParser {
/**
* This method parses array of 6 items into an item stack.
* Format:
+ * {@code
* POTION:NAME::::QTY
+ * }
* Example:
+ * {@code
* POTION:STRENGTH:1:EXTENDED:SPLASH:1
+ * }
* @param part String array that contains 6 elements.
* @return Potion with given properties.
*/
@@ -256,13 +261,17 @@ public class ItemParser {
/**
* This method parses array of 2 to 3 elements that represents player head.
* Format:
+ * {@code
* PLAYER_HEAD::QTY
* PLAYER_HEAD:
* PLAYER_HEAD:QTY
+ * }
* Example:
+ * {@code
* PLAYER_HEAD:1
* PLAYER_HEAD:BONNe1704
* PLAYER_HEAD:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYWY1ZjE1OTg4NmNjNTMxZmZlYTBkOGFhNWY5MmVkNGU1ZGE2NWY3MjRjMDU3MGFmODZhOTBiZjAwYzY3YzQyZSJ9fX0:1
+ * }
* @param part String array that contains at least 2 elements.
* @return Player head with given properties.
*/
@@ -309,7 +318,9 @@ public class ItemParser {
// Apply new meta to the item.
playerHead.setItemMeta(meta);
- } catch (Exception ignored) {}
+ } catch (Exception ignored) {
+ // Ignored
+ }
return playerHead;
}
diff --git a/src/main/java/world/bentobox/bentobox/util/Util.java b/src/main/java/world/bentobox/bentobox/util/Util.java
index ad56f9384..7a633bd31 100644
--- a/src/main/java/world/bentobox/bentobox/util/Util.java
+++ b/src/main/java/world/bentobox/bentobox/util/Util.java
@@ -2,13 +2,16 @@ package world.bentobox.bentobox.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
@@ -21,7 +24,20 @@ import org.bukkit.World.Environment;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
-import org.bukkit.entity.*;
+import org.bukkit.entity.Allay;
+import org.bukkit.entity.Animals;
+import org.bukkit.entity.Bat;
+import org.bukkit.entity.EnderDragon;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Flying;
+import org.bukkit.entity.IronGolem;
+import org.bukkit.entity.Monster;
+import org.bukkit.entity.Player;
+import org.bukkit.entity.PufferFish;
+import org.bukkit.entity.Shulker;
+import org.bukkit.entity.Slime;
+import org.bukkit.entity.Snowman;
+import org.bukkit.entity.WaterMob;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
@@ -33,7 +49,6 @@ import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.nms.PasteHandler;
import world.bentobox.bentobox.nms.WorldRegenerator;
-import world.bentobox.bentobox.versions.ServerCompatibility;
/**
@@ -44,7 +59,7 @@ import world.bentobox.bentobox.versions.ServerCompatibility;
*/
public class Util {
/**
- * Use standard color code definition: &.
+ * Use standard color code definition: {@code &}.
*/
private static final Pattern HEX_PATTERN = Pattern.compile("([a-fA-F0-9]{6}|[a-fA-F0-9]{3})");
private static final String NETHER = "_nether";
@@ -164,17 +179,17 @@ public class Util {
}
/**
- * Return a list of online players this player can see, i.e. are not invisible
+ * Return an immutable list of online players this player can see, i.e. are not invisible
* @param user - the User - if null, all player names on the server are shown
* @return a list of online players this player can see
*/
public static List getOnlinePlayerList(User user) {
if (user == null || !user.isPlayer()) {
// Console and null get to see every player
- return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
+ return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
}
// Otherwise prevent invisible players from seeing
- return Bukkit.getOnlinePlayers().stream().filter(p -> user.getPlayer().canSee(p)).map(Player::getName).collect(Collectors.toList());
+ return Bukkit.getOnlinePlayers().stream().filter(p -> user.getPlayer().canSee(p)).map(Player::getName).toList();
}
/**
@@ -341,19 +356,9 @@ public class Util {
// Bat extends Mob
// Most of passive mobs extends Animals
- if (ServerCompatibility.getInstance().isVersion(ServerCompatibility.ServerVersion.V1_18,
- ServerCompatibility.ServerVersion.V1_18_1,
- ServerCompatibility.ServerVersion.V1_18_2))
- {
- return entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman ||
- entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat;
- }
- else
- {
- return entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman ||
+ return entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman ||
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat ||
entity instanceof Allay;
- }
}
/*
@@ -661,8 +666,21 @@ public class Util {
* @param commandType - the type of command being run - used in the console error message
*/
public static void runCommands(User user, @NonNull List commands, String commandType) {
+ runCommands(user, user.getName(), commands, commandType);
+ }
+
+ /**
+ * Run a list of commands for a user
+ * @param user - user affected by the commands
+ * @param ownerName - name of the island owner, or the user's name if it is the user's island
+ * @param commands - a list of commands
+ * @param commandType - the type of command being run - used in the console error message
+ * @since 1.22.0
+ */
+ public static void runCommands(User user, String ownerName, @NonNull List commands, String commandType) {
commands.forEach(command -> {
command = command.replace("[player]", user.getName());
+ command = command.replace("[owner]", ownerName);
if (command.startsWith("[SUDO]")) {
// Execute the command by the player
if (!user.isOnline() || !user.performCommand(command.substring(6))) {
@@ -769,7 +787,7 @@ public class Util {
public static String sanitizeInput(String input)
{
return ChatColor.stripColor(
- Util.translateColorCodes(input.replaceAll("[\\\\/:*?\"<>|\s]", "_"))).
- toLowerCase();
+ Util.translateColorCodes(input.replaceAll("[\\\\/:*?\"<>|\s]", "_"))).
+ toLowerCase();
}
}
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 c24ff8c89..8a2965b3b 100644
--- a/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java
+++ b/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java
@@ -7,6 +7,16 @@
package world.bentobox.bentobox.util.teleport;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot;
@@ -21,15 +31,6 @@ import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Objects;
-import java.util.PriorityQueue;
-import java.util.Queue;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.atomic.AtomicBoolean;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
@@ -73,30 +74,28 @@ public class ClosestSafeSpotTeleport
*/
private void checkLocation()
{
- if (this.plugin.getIslandsManager().isSafeLocation(this.location))
+ if (!this.portal && this.plugin.getIslandsManager().isSafeLocation(this.location))
{
- if (!this.portal)
- {
- // If this is not a portal teleport, then go to the safe location immediately
- this.teleportEntity(this.location);
- // Position search is completed. Quit faster.
- return;
- }
+ // If this is not a portal teleport, then go to the safe location immediately
+ this.teleportEntity(this.location);
+ // Position search is completed. Quit faster.
+ return;
}
+
// Players should not be teleported outside protection range if they already are in it.
this.boundingBox = this.plugin.getIslandsManager().getIslandAt(this.location).
- map(Island::getProtectionBoundingBox).
- orElseGet(() -> {
- int protectionRange = this.plugin.getIWM().getIslandProtectionRange(this.world);
+ map(Island::getProtectionBoundingBox).
+ orElseGet(() -> {
+ double protectionRange = this.plugin.getIWM().getIslandProtectionRange(this.world);
- return new BoundingBox(this.location.getBlockX() - protectionRange,
- Math.max(this.world.getMinHeight(), this.location.getBlockY() - protectionRange),
- this.location.getBlockZ() - protectionRange,
- this.location.getBlockX() + protectionRange,
- Math.min(this.world.getMaxHeight(), this.location.getBlockY() + protectionRange),
- this.location.getBlockZ() + protectionRange);
- });
+ return new BoundingBox(this.location.getBlockX() - protectionRange,
+ Math.max(this.world.getMinHeight(), this.location.getBlockY() - protectionRange),
+ this.location.getBlockZ() - protectionRange,
+ this.location.getBlockX() + protectionRange,
+ Math.min(this.world.getMaxHeight(), this.location.getBlockY() + protectionRange),
+ this.location.getBlockZ() + protectionRange);
+ });
// The maximal range of search.
this.range = Math.min(this.plugin.getSettings().getSafeSpotSearchRange(), (int) this.boundingBox.getWidthX() / 2);
@@ -147,17 +146,17 @@ public class ClosestSafeSpotTeleport
// Get the chunk snapshot and scan it
Util.getChunkAtAsync(this.world, chunkPair.x, chunkPair.z).
- thenApply(Chunk::getChunkSnapshot).
- whenCompleteAsync((snapshot, e) ->
+ thenApply(Chunk::getChunkSnapshot).
+ whenCompleteAsync((snapshot, e) ->
+ {
+ if (snapshot != null)
{
- if (snapshot != null)
- {
- // Find best spot based on collected information chunks.
- this.scanAndPopulateBlockQueue(snapshot);
- }
+ // Find best spot based on collected information chunks.
+ this.scanAndPopulateBlockQueue(snapshot);
+ }
- this.checking.set(false);
- });
+ this.checking.set(false);
+ });
}
@@ -173,11 +172,9 @@ public class ClosestSafeSpotTeleport
int x = this.location.getBlockX();
int z = this.location.getBlockZ();
- int range = 20;
-
// Normalize block coordinates to chunk coordinates and add extra 1 for visiting.
- int numberOfChunks = (((x + range) >> 4) - ((x - range) >> 4) + 1) *
- (((z + range) >> 4) - ((z - range) >> 4) + 1);
+ int numberOfChunks = (((x + SCAN_RANGE) >> 4) - ((x - SCAN_RANGE) >> 4) + 1) *
+ (((z + SCAN_RANGE) >> 4) - ((z - SCAN_RANGE) >> 4) + 1);
// Ideally it would be if visitor switch from clockwise to counter-clockwise if X % 16 < 8 and
// up to down if Z % 16 < 8.
@@ -214,11 +211,11 @@ public class ClosestSafeSpotTeleport
* @param chunkCoord Chunk coordinate.
*/
private void addChunk(List> chunksToScan,
- Pair blockCoord,
- Pair