+ * If you need a custom message, use {@link #askConfirmation(User, String, Runnable)}
* @param user User to ask confirmation to.
* @param confirmed Runnable to be executed if successfully confirmed.
*/
diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommand.java
index 7e34456b6..b7e450a36 100644
--- a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommand.java
+++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommand.java
@@ -107,51 +107,66 @@ private boolean getIsland(User user, List
* This method stops position finding task and process teleporation.
*/
- private void finishTask()
+ void finishTask()
{
// Still Async!
// Nothing left to check and still not canceled
@@ -297,64 +293,40 @@ private void finishTask()
else if (this.entity instanceof Player player)
{
// Return to main thread and teleport the player
- Bukkit.getScheduler().runTask(this.plugin, () ->
- {
- // Failed, no safe spot
- if (!this.failureMessage.isEmpty())
- {
- User.getInstance(this.entity).notify(this.failureMessage);
- }
+ Bukkit.getScheduler().runTask(this.plugin, () -> returnAndTeleport(player));
+ }
+ // We do not teleport entities if position failed.
+ // Fail the completion
+ this.result.complete(false);
- // Check highest block
- Block highestBlock = this.world.getHighestBlockAt(this.location);
+ }
- if (highestBlock.getType().isSolid() &&
- this.plugin.getIslandsManager().isSafeLocation(highestBlock.getLocation()))
- {
- // Try to teleport player to the highest block.
- this.asyncTeleport(highestBlock.getLocation().add(new Vector(0.5D, 0D, 0.5D)));
- return;
- }
- else if (!this.plugin.getIWM().inWorld(this.entity.getLocation()))
- {
- // Last resort
- player.performCommand("spawn");
- }
- else if (!this.cancelIfFail)
- {
- // Create a spot for the player to be
- if (this.world.getEnvironment().equals(World.Environment.NETHER))
- {
- this.makeAndTeleport(Material.NETHERRACK);
- }
- else if (this.world.getEnvironment().equals(World.Environment.THE_END))
- {
- this.makeAndTeleport(Material.END_STONE);
- }
- else
- {
- this.makeAndTeleport(Material.COBBLESTONE);
- }
- }
+ void returnAndTeleport(Player player) {
+ // Notify player
+ User.getInstance(this.entity).notify("general.errors.no-safe-location-found");
- if (this.failRunnable != null)
- {
- Bukkit.getScheduler().runTask(this.plugin, this.failRunnable);
- }
+ // Check highest block
+ Block highestBlock = this.world.getHighestBlockAt(this.location);
- this.result.complete(false);
- });
+ if (highestBlock.getType().isSolid() &&
+ this.plugin.getIslandsManager().isSafeLocation(highestBlock.getLocation()))
+ {
+ // Try to teleport player to the highest block.
+ this.asyncTeleport(highestBlock.getLocation().add(new Vector(0.5D, 0D, 0.5D)));
}
- else
+ else if (!this.plugin.getIWM().inWorld(this.entity.getLocation()))
{
- // We do not teleport entities if position failed.
-
- if (this.failRunnable != null)
- {
- Bukkit.getScheduler().runTask(this.plugin, this.failRunnable);
+ // Last resort
+ player.performCommand("spawn");
+ }
+ else if (!this.cancelIfFail)
+ {
+ // Create a spot for the player to be
+ switch(world.getEnvironment()) {
+ case NETHER -> this.makeAndTeleport(Material.NETHERRACK);
+ case THE_END -> this.makeAndTeleport(Material.END_STONE);
+ default -> this.makeAndTeleport(Material.COBBLESTONE);
}
-
- this.result.complete(false);
}
}
@@ -364,7 +336,7 @@ else if (this.world.getEnvironment().equals(World.Environment.THE_END))
* above location and fills the space between them with air.
* @param baseMaterial Material that will be for top and bottom block.
*/
- private void makeAndTeleport(Material baseMaterial)
+ void makeAndTeleport(Material baseMaterial)
{
this.location.getBlock().getRelative(BlockFace.DOWN).setType(baseMaterial, false);
this.location.getBlock().setType(Material.AIR, false);
@@ -380,7 +352,7 @@ private void makeAndTeleport(Material baseMaterial)
* This method scans all populated positions and returns true if position is found, or false, if not.
* @return {@code true} if safe position is found, otherwise false.
*/
- private boolean scanBlockQueue()
+ boolean scanBlockQueue()
{
boolean blockFound = false;
@@ -396,7 +368,7 @@ private boolean scanBlockQueue()
/**
* This method triggers a task that will teleport entity in a main thread.
*/
- private void teleportEntity(final Location location)
+ void teleportEntity(final Location location)
{
// Return to main thread and teleport the player
Bukkit.getScheduler().runTask(this.plugin, () -> this.asyncTeleport(location));
@@ -407,7 +379,7 @@ private void teleportEntity(final Location location)
* This method performs async teleportation and runs end tasks for spot-finder.
* @param location Location where player should be teleported.
*/
- private void asyncTeleport(final Location location)
+ void asyncTeleport(final Location location)
{
Util.teleportAsync(this.entity, location).thenRun(() ->
{
@@ -429,7 +401,7 @@ private void asyncTeleport(final Location location)
* @param positionData Position data that must be checked.
* @return {@code true} if position is found and no extra processing required, {@code false} otherwise.
*/
- private boolean checkPosition(PositionData positionData)
+ boolean checkPosition(PositionData positionData)
{
if (this.portal)
{
@@ -477,12 +449,12 @@ else if (this.noPortalPosition == null)
/**
* PositionData record holds information about position where player will be teleported.
* @param vector Vector of the position.
+ * @param block Block material on which player will be placed.
+ * @param spaceOne Material one block above block.
+ * @param spaceTwo Material two blocks above block.
* @param distance Distance till the position.
- * @param block Block on which player will be placed.
- * @param spaceOne One block above block.
- * @param spaceTwo Two blocks above block.
*/
- private record PositionData(Vector vector, Material block, Material spaceOne, Material spaceTwo, double distance) {}
+ record PositionData(Vector vector, Material block, Material spaceOne, Material spaceTwo, double distance) {}
public static Builder builder(BentoBox plugin)
@@ -496,6 +468,10 @@ public static Builder builder(BentoBox plugin)
// ---------------------------------------------------------------------
+ /**
+ * Builder for ClosestSafeSpotTeleport
+ *
+ */
public static class Builder
{
private Builder(BentoBox plugin)
@@ -590,11 +566,6 @@ public ClosestSafeSpotTeleport build()
return null;
}
- if (this.failureMessage.isEmpty() && this.entity instanceof Player)
- {
- this.failureMessage = "general.errors.no-safe-location-found";
- }
-
return new ClosestSafeSpotTeleport(this);
}
@@ -669,29 +640,6 @@ public Runnable getSuccessRunnable()
return this.successRunnable;
}
-
- /**
- * Gets fail runnable.
- *
- * @return the fail runnable
- */
- public Runnable getFailRunnable()
- {
- return this.failRunnable;
- }
-
-
- /**
- * Gets failure message.
- *
- * @return the failure message
- */
- public String getFailureMessage()
- {
- return this.failureMessage;
- }
-
-
/**
* Is portal boolean.
*
@@ -749,16 +697,6 @@ public boolean isCancelIfFail()
*/
private Runnable successRunnable;
- /**
- * Runnable that will be triggered after failing teleportation.
- */
- private Runnable failRunnable;
-
- /**
- * Stores the failure message that is sent to a player.
- */
- private String failureMessage = "";
-
/**
* Boolean that indicates if teleportation should search for portal.
*/
@@ -827,16 +765,6 @@ public boolean isCancelIfFail()
*/
private final Runnable successRunnable;
- /**
- * Runnable that will be triggered after failing teleportation.
- */
- private final Runnable failRunnable;
-
- /**
- * Stores the failure message that is sent to a player.
- */
- private final String failureMessage;
-
/**
* CompletableFuture that is triggered upon finishing position searching.
*/
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 4dff30944..ac15aa754 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -62,4 +62,4 @@ permissions:
default: op
bentobox.perms:
description: Allow use of '/bentobox perms' command
- default: OP
+ default: op
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 3664f7e46..16eb982b1 100644
--- a/src/test/java/world/bentobox/bentobox/api/addons/AddonClassLoaderTest.java
+++ b/src/test/java/world/bentobox/bentobox/api/addons/AddonClassLoaderTest.java
@@ -53,7 +53,8 @@ private enum mandatoryTags {
MAIN,
NAME,
VERSION,
- AUTHORS
+ AUTHORS,
+ ICON
}
/**
* Used for file writing etc.
@@ -129,7 +130,11 @@ private YamlConfiguration getYaml(List{@code
+ *
{@code
* POTION:NAME:
* Example:
- * {@code
+ *
{@code
* POTION:STRENGTH:1:EXTENDED:SPLASH:1
* }
* @param part String array that contains 6 elements.
@@ -261,13 +261,13 @@ private static ItemStack parseBanner(String[] part) {
/**
* This method parses array of 2 to 3 elements that represents player head.
* Format:
- * {@code
+ *
{@code
* PLAYER_HEAD:
* Example:
- * {@code
+ *
{@code
* PLAYER_HEAD:1
* PLAYER_HEAD:BONNe1704
* PLAYER_HEAD:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYWY1ZjE1OTg4NmNjNTMxZmZlYTBkOGFhNWY5MmVkNGU1ZGE2NWY3MjRjMDU3MGFmODZhOTBiZjAwYzY3YzQyZSJ9fX0:1
diff --git a/src/main/java/world/bentobox/bentobox/util/Util.java b/src/main/java/world/bentobox/bentobox/util/Util.java
index b804d5d73..574fea82f 100644
--- a/src/main/java/world/bentobox/bentobox/util/Util.java
+++ b/src/main/java/world/bentobox/bentobox/util/Util.java
@@ -13,7 +13,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
@@ -578,7 +577,7 @@ public static String translateColorCodes(@NonNull String textToColor) {
*/
@NonNull
public static String stripSpaceAfterColorCodes(@NonNull String textToStrip) {
- Validate.notNull(textToStrip, "Cannot strip null text");
+ if (textToStrip == null) return "";
textToStrip = textToStrip.replaceAll("(" + ChatColor.COLOR_CHAR + ".)[\\s]", "$1");
return textToStrip;
}
@@ -738,7 +737,7 @@ public static WorldRegenerator getRegenerator() {
}
return regenerator;
}
-
+
/**
* Checks what version the server is running and picks the appropriate NMS handler, or fallback
* @return PasteHandler
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 d25bd0ac0..61ea184c8 100644
--- a/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java
+++ b/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java
@@ -54,9 +54,6 @@ public class ClosestSafeSpotTeleport
this.portal = builder.isPortal();
this.successRunnable = builder.getSuccessRunnable();
- this.failRunnable = builder.getFailRunnable();
-
- this.failureMessage = builder.getFailureMessage();
this.result = builder.getResult();
this.world = Objects.requireNonNull(this.location.getWorld());
@@ -72,7 +69,7 @@ public class ClosestSafeSpotTeleport
* This is main method that triggers safe spot search.
* It starts with the given location and afterwards checks all blocks in required area.
*/
- private void checkLocation()
+ void checkLocation()
{
if (!this.portal && this.plugin.getIslandsManager().isSafeLocation(this.location))
{
@@ -115,7 +112,7 @@ private void checkLocation()
/**
* This method loads all chunks in async and populates blockQueue with all blocks.
*/
- private void gatherChunks()
+ void gatherChunks()
{
// Set a flag so this is only run if it's not already in progress
if (this.checking.get())
@@ -165,7 +162,7 @@ private void gatherChunks()
*
* @return - list of chunk coordinates to be scanned
*/
- private List