diff --git a/src/main/java/world/bentobox/border/Settings.java b/src/main/java/world/bentobox/border/Settings.java index b3b3345..af8fb04 100644 --- a/src/main/java/world/bentobox/border/Settings.java +++ b/src/main/java/world/bentobox/border/Settings.java @@ -11,6 +11,7 @@ @StoreAt(filename = "config.yml", path = "addons/Border") public class Settings implements ConfigObject { + @ConfigComment("Border Configuration file by tastybento") @ConfigComment("") @ConfigComment("This list stores GameModes in which Border addon should not work.") @ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:") @@ -25,6 +26,12 @@ public class Settings implements ConfigObject { @ConfigEntry(path = "use-wbapi") private boolean useWbapi = false; + @ConfigComment("") + @ConfigComment("Teleport players back inside the border if they somehow get outside.") + @ConfigComment("This will teleport players back inside if they toggle the border with a command.") + @ConfigEntry(path = "return-teleport") + private boolean returnTeleport = true; + @ConfigComment("") @ConfigComment("Use barrier blocks. If false, the border is indicated by particles only.") @ConfigComment("Only applicable if vanilla world border is not used") @@ -112,4 +119,18 @@ public boolean isUseWbapi() { public void setUseWbapi(boolean useWbapi) { this.useWbapi = useWbapi; } + + /** + * @return the returnTeleport + */ + public boolean isReturnTeleport() { + return returnTeleport; + } + + /** + * @param returnTeleport the returnTeleport to set + */ + public void setReturnTeleport(boolean returnTeleport) { + this.returnTeleport = returnTeleport; + } } diff --git a/src/main/java/world/bentobox/border/listeners/PlayerListener.java b/src/main/java/world/bentobox/border/listeners/PlayerListener.java index 97c7672..e82a85c 100644 --- a/src/main/java/world/bentobox/border/listeners/PlayerListener.java +++ b/src/main/java/world/bentobox/border/listeners/PlayerListener.java @@ -71,12 +71,9 @@ public void onPlayerTeleport(PlayerTeleportEvent e) { @EventHandler(priority = EventPriority.NORMAL) public void onPlayerLeaveIsland(PlayerMoveEvent e) { - if (addon.getSettings().isUseWbapi()) { - return; - } Player p = e.getPlayer(); Location from = e.getFrom(); - if (!outsideCheck(e.getPlayer(), from, e.getTo())) { + if (!addon.getSettings().isReturnTeleport() || !outsideCheck(e.getPlayer(), from, e.getTo())) { return; } // Move the player back inside the border @@ -101,9 +98,16 @@ public void onPlayerLeaveIsland(PlayerMoveEvent e) { } + /** + * Check if the player is outside the island protection zone that they are supposed to be in. + * @param player - player moving + * @param from - from location + * @param to - to location + * @return true if outside the island protection zone + */ private boolean outsideCheck(Player player, Location from, Location to) { User user = User.getInstance(player); - // Only process if there is a change in X or Z coords + if ((from.getWorld() != null && from.getWorld().equals(to.getWorld()) && from.toVector().multiply(XZ).equals(to.toVector().multiply(XZ))) || !addon.getSettings().isUseBarrierBlocks() diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6be3af8..8fb66e7 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -8,10 +8,14 @@ disabled-gamemodes: [] # Use vanilla world border. Requires WorldBorderAPI plugin. # Download from https://github.com/yannicklamprecht/WorldBorderAPI/releases use-wbapi: true +# +# Teleport players back inside the border if they somehow get outside. +# This will teleport players back inside if they toggle the border with a command. +return-teleport: true # # Use barrier blocks. If false, the border is indicated by particles only. # Only applicable if vanilla world border is not used -use-barrier-blocks: true +use-barrier-blocks: false # # Default border behavior show-by-default: true