Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Apr 18, 2021
2 parents 1a2f2f4 + a342c61 commit 8ce7e1c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>3.0.1</build.version>
<build.version>3.1.0</build.version>
<build.number>-LOCAL</build.number>
<!-- Sonar Cloud -->
<sonar.projectKey>BentoBoxWorld_Border</sonar.projectKey>
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/world/bentobox/border/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand All @@ -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")
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ce7e1c

Please sign in to comment.