Skip to content

Commit 76adcb4

Browse files
committed
Added the ability to use the {player} placeholder for the minimum and maximum y values in the config, to allow breaking of all the blocks above or below the player's y-level for example.
1 parent 5ae94e2 commit 76adcb4

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/main/java/xyz/biscut/chunkbuster/utils/ConfigValues.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,30 @@ public boolean showUpdateMessage() {
367367
return main.getConfig().getBoolean("show-update-messages");
368368
}
369369

370-
public int getMinimumY() {
371-
return main.getConfig().getInt("minimum-y");
370+
public int getMinimumY(Player p) {
371+
if (main.getConfig().getString("minimum-y").toLowerCase().contains("{player}")) {
372+
return (int)p.getLocation().getY();
373+
} else {
374+
try {
375+
return Integer.valueOf(main.getConfig().getString("minimum-y"));
376+
} catch (NumberFormatException ex) {
377+
main.getLogger().warning("Your minimum-y value is invalid, please either change this to an integer or '{player}' in the config.");
378+
return 0;
379+
}
380+
}
372381
}
373382

374-
public int getMaximumY() {
375-
return main.getConfig().getInt("maximum-y");
383+
public int getMaximumY(Player p) {
384+
if (main.getConfig().getString("maximum-y").toLowerCase().contains("{player}")) {
385+
return (int)p.getLocation().getY();
386+
} else {
387+
try {
388+
return Integer.valueOf(main.getConfig().getString("maximum-y"));
389+
} catch (NumberFormatException ex) {
390+
main.getLogger().warning("Your maximum-y value is invalid, please either change this to an integer or '{player}' in the config.");
391+
return 255;
392+
}
393+
}
376394
}
377395

378396
public double getConfigVersion() {

src/main/java/xyz/biscut/chunkbuster/utils/Utils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void clearChunks(int chunkBusterArea, Location chunkBusterLocation, Playe
4444
if (chunkBusterArea == 1) {
4545
RemovalQueue removalQueue = new RemovalQueue(main);
4646
waterChunks.add(chunkBusterLocation.getChunk());
47-
for (int y = main.getConfigValues().getMaximumY(); y >= main.getConfigValues().getMinimumY(); y--) {
47+
for (int y = main.getConfigValues().getMaximumY(p); y >= main.getConfigValues().getMinimumY(p); y--) {
4848
for (int x = 0; x < 16; x++) {
4949
for (int z = 0; z < 16; z++) {
5050
Block b = chunkBusterLocation.getChunk().getBlock(x, y, z);
@@ -64,7 +64,7 @@ public void clearChunks(int chunkBusterArea, Location chunkBusterLocation, Playe
6464
int lowerSearchBound = (chunkBusterArea - 1) / -2;
6565
int startingX = chunkBusterLocation.getChunk().getX();
6666
int startingZ = chunkBusterLocation.getChunk().getZ();
67-
for (int y = main.getConfigValues().getMaximumY(); y >= main.getConfigValues().getMinimumY(); y--) {
67+
for (int y = main.getConfigValues().getMaximumY(p); y >= main.getConfigValues().getMinimumY(p); y--) {
6868
for (int chunkX = lowerSearchBound; chunkX < upperSearchBound; chunkX++) {
6969
for (int chunkZ = lowerSearchBound; chunkZ < upperSearchBound; chunkZ++) {
7070
Chunk chunk = chunkBusterLocation.getWorld().getChunkAt(startingX + chunkX, startingZ + chunkZ);

src/main/resources/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ can-place-in-wilderness: true
3333
cooldown: 0
3434

3535
# Chunkbusters clear between this minimum value and the maximum value (both inclusive). 0 and 255 means the whole chunk.
36+
# You can use '{player}' for the player's Y-coordinate.
3637
minimum-y: 0
3738
maximum-y: 255
3839

0 commit comments

Comments
 (0)