Skip to content

Commit

Permalink
Add config option to show the maximum protection range border.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Feb 18, 2021
1 parent 6101275 commit c6c81e6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 25 deletions.
21 changes: 20 additions & 1 deletion src/main/java/world/bentobox/border/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ public class Settings implements ConfigObject {
@ConfigComment("Use barrier blocks. If false, the border is indicated by particles only.")
@ConfigEntry(path = "use-barrier-blocks")
private boolean useBarrierBlocks = true;

@ConfigComment("")
@ConfigComment("Default border behavior")
@ConfigEntry(path = "show-by-default")
private boolean showByDefault= true;

@ConfigComment("")
@ConfigComment("Show max-protection range border. This is a visual border only and not a barrier.")
@ConfigEntry(path = "show-max-border")
private boolean showMaxBorder= true;

/**
* @param disabledGameModes new disabledGameModes value.
*/
Expand Down Expand Up @@ -72,4 +77,18 @@ public boolean isShowByDefault() {
public void setShowByDefault(boolean showByDefault) {
this.showByDefault = showByDefault;
}

/**
* @return the showMaxBorder
*/
public boolean isShowMaxBorder() {
return showMaxBorder;
}

/**
* @param showMaxBorder the showMaxBorder to set
*/
public void setShowMaxBorder(boolean showMaxBorder) {
this.showMaxBorder = showMaxBorder;
}
}
62 changes: 38 additions & 24 deletions src/main/java/world/bentobox/border/listeners/PlayerBorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class PlayerBorder implements Listener {
private static final BlockData BLOCK = Material.BARRIER.createBlockData();
private final Border addon;
private static final Particle PARTICLE = Particle.REDSTONE;
private static final Particle MAX_PARTICLE = Particle.BARRIER;
private static final Particle.DustOptions PARTICLE_DUST_RED = new Particle.DustOptions(Color.RED, 1.0F);
private static final Particle.DustOptions PARTICLE_DUST_BLUE = new Particle.DustOptions(Color.BLUE, 1.0F);
private static final int BARRIER_RADIUS = 5;
Expand Down Expand Up @@ -91,46 +92,59 @@ public void showBarrier(Player player, Island island) {

// Get the locations to show
Location loc = player.getLocation();
int xMin = island.getMinProtectedX();
int xMax = island.getMaxProtectedX();
int zMin = island.getMinProtectedZ();
int zMax = island.getMaxProtectedZ();
int radius = BARRIER_RADIUS;
if (loc.getBlockX() - xMin < radius) {
showWalls(player, loc,
island.getMinProtectedX(),
island.getMaxProtectedX(),
island.getMinProtectedZ(),
island.getMaxProtectedZ(), false);
// If the max border needs to be shown, show it as well
if (addon.getSettings().isShowMaxBorder()) {
showWalls(player, loc,
island.getMinX(),
island.getMaxX(),
island.getMinZ(),
island.getMaxZ(), true);
}

}

private void showWalls(Player player, Location loc, int xMin, int xMax, int zMin, int zMax, boolean max) {
if (loc.getBlockX() - xMin < BARRIER_RADIUS) {
// Close to min x
for (int z = Math.max(loc.getBlockZ() - radius, zMin); z < loc.getBlockZ() + radius && z < zMax; z++) {
for (int y = -radius; y < radius; y++) {
showPlayer(player, xMin-1, loc.getBlockY() + y, z);
for (int z = Math.max(loc.getBlockZ() - BARRIER_RADIUS, zMin); z < loc.getBlockZ() + BARRIER_RADIUS && z < zMax; z++) {
for (int y = -BARRIER_RADIUS; y < BARRIER_RADIUS; y++) {
showPlayer(player, xMin-1, loc.getBlockY() + y, z, max);
}
}
}
if (loc.getBlockZ() - zMin < radius) {
if (loc.getBlockZ() - zMin < BARRIER_RADIUS) {
// Close to min z
for (int x = Math.max(loc.getBlockX() - radius, xMin); x < loc.getBlockX() + radius && x < xMax; x++) {
for (int y = -radius; y < radius; y++) {
showPlayer(player, x, loc.getBlockY() + y, zMin-1);
for (int x = Math.max(loc.getBlockX() - BARRIER_RADIUS, xMin); x < loc.getBlockX() + BARRIER_RADIUS && x < xMax; x++) {
for (int y = -BARRIER_RADIUS; y < BARRIER_RADIUS; y++) {
showPlayer(player, x, loc.getBlockY() + y, zMin-1, max);
}
}
}
if (xMax - loc.getBlockX() < radius) {
if (xMax - loc.getBlockX() < BARRIER_RADIUS) {
// Close to max x
for (int z = Math.max(loc.getBlockZ() - radius, zMin); z < loc.getBlockZ() + radius && z < zMax; z++) {
for (int y = -radius; y < radius; y++) {
showPlayer(player, xMax, loc.getBlockY() + y, z); // not xMax+1, that's outside the region
for (int z = Math.max(loc.getBlockZ() - BARRIER_RADIUS, zMin); z < loc.getBlockZ() + BARRIER_RADIUS && z < zMax; z++) {
for (int y = -BARRIER_RADIUS; y < BARRIER_RADIUS; y++) {
showPlayer(player, xMax, loc.getBlockY() + y, z, max); // not xMax+1, that's outside the region
}
}
}
if (zMax - loc.getBlockZ() < radius) {
if (zMax - loc.getBlockZ() < BARRIER_RADIUS) {
// Close to max z
for (int x = Math.max(loc.getBlockX() - radius, xMin); x < loc.getBlockX() + radius && x < xMax; x++) {
for (int y = -radius; y < radius; y++) {
showPlayer(player, x, loc.getBlockY() + y, zMax); // not zMax+1, that's outside the region
for (int x = Math.max(loc.getBlockX() - BARRIER_RADIUS, xMin); x < loc.getBlockX() + BARRIER_RADIUS && x < xMax; x++) {
for (int y = -BARRIER_RADIUS; y < BARRIER_RADIUS; y++) {
showPlayer(player, x, loc.getBlockY() + y, zMax, max); // not zMax+1, that's outside the region
}
}
}

}

private void showPlayer(Player player, int i, int j, int k) {
private void showPlayer(Player player, int i, int j, int k, boolean max) {
// Get if on or in border
if (addon.getSettings().isUseBarrierBlocks()
&& player.getLocation().getBlockX() == i
Expand All @@ -141,9 +155,9 @@ private void showPlayer(Player player, int i, int j, int k) {
Location l = new Location(player.getWorld(), i, j, k);
Util.getChunkAtAsync(l).thenAccept(c -> {
if (j < 0 || j > player.getWorld().getMaxHeight()) {
User.getInstance(player).spawnParticle(PARTICLE, PARTICLE_DUST_RED, i + 0.5D, j + 0.0D, k + 0.5D);
User.getInstance(player).spawnParticle(max ? MAX_PARTICLE : PARTICLE, PARTICLE_DUST_RED, i + 0.5D, j + 0.0D, k + 0.5D);
} else {
User.getInstance(player).spawnParticle(PARTICLE, PARTICLE_DUST_BLUE, i + 0.5D, j + 0.0D, k + 0.5D);
User.getInstance(player).spawnParticle(max ? MAX_PARTICLE : PARTICLE, PARTICLE_DUST_BLUE, i + 0.5D, j + 0.0D, k + 0.5D);
}
if (addon.getSettings().isUseBarrierBlocks() && (l.getBlock().isEmpty() || l.getBlock().isLiquid())) {
player.sendBlockChange(l, BLOCK);
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ use-barrier-blocks: true

# Default border behavior
show-by-default: true

# Show max-protection range border. This is a visual border only and not a barrier
show-max-border: true

0 comments on commit c6c81e6

Please sign in to comment.