Skip to content

Commit a7f56c6

Browse files
committed
Added worldborder support
1 parent 4990668 commit a7f56c6

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

ChunkBusterPlugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<artifactId>ChunkBusterPlugin</artifactId>
1010
<packaging>jar</packaging>
1111
<name>ChunkBusterPlugin</name>
12-
<version>1.2.6</version>
12+
<version>1.2.7</version>
1313

1414
<repositories>
1515
<repository>

ChunkBusterPlugin/src/main/java/codes/biscuit/chunkbuster/utils/ConfigValues.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ public boolean coreprotectHookEnabled() {
229229
return main.getConfig().getBoolean("hooks.coreprotect");
230230
}
231231

232+
boolean worldborderHookEnabled() {
233+
return main.getConfig().getBoolean("hooks.worldborder");
234+
}
235+
232236
public boolean worldguardHookEnabled() {
233237
return main.getConfig().getBoolean("hooks.worldguard");
234238
}

ChunkBusterPlugin/src/main/java/codes/biscuit/chunkbuster/utils/Utils.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import net.md_5.bungee.api.ChatColor;
66
import net.md_5.bungee.api.chat.ClickEvent;
77
import net.md_5.bungee.api.chat.TextComponent;
8-
import org.bukkit.Chunk;
9-
import org.bukkit.Location;
10-
import org.bukkit.Material;
8+
import org.bukkit.*;
119
import org.bukkit.block.Block;
1210
import org.bukkit.command.CommandSender;
1311
import org.bukkit.enchantments.Enchantment;
@@ -84,6 +82,7 @@ public void clearChunks(int chunkBusterArea, Location chunkBusterLocation, Playe
8482
Set<Material> ignoredBlocks = main.getConfigValues().getIgnoredBlocks();
8583
if (chunkBusterArea % 2 != 0) {
8684
RemovalQueue removalQueue = new RemovalQueue(main, p);
85+
WorldBorder border = chunkBusterLocation.getWorld().getWorldBorder();
8786
// Variables for the area to loop through
8887
int upperBound = ((chunkBusterArea-1)/2)+1;
8988
int lowerBound = (chunkBusterArea-1)/-2;
@@ -98,7 +97,9 @@ public void clearChunks(int chunkBusterArea, Location chunkBusterLocation, Playe
9897
for (int z = 0; z < 16; z++) {
9998
Block b = chunk.getBlock(x, y, z);
10099
if (!b.getType().equals(Material.AIR) && !ignoredBlocks.contains(b.getType())) {
101-
removalQueue.getBlocks().add(b);
100+
if (!main.getConfigValues().worldborderHookEnabled() || insideBorder(b, border)) {
101+
removalQueue.getBlocks().add(b);
102+
}
102103
}
103104
}
104105
}
@@ -113,8 +114,17 @@ public void clearChunks(int chunkBusterArea, Location chunkBusterLocation, Playe
113114
}
114115
}
115116

117+
private boolean insideBorder(Block block, WorldBorder border) {
118+
Location blockLocation = block.getLocation().add(0.5, 0, 0.5);
119+
double x = blockLocation.getX();
120+
double z = blockLocation.getZ();
121+
double size = border.getSize()/2;
122+
Location center = border.getCenter();
123+
return !((x >= center.clone().add(size, 0, 0).getX() || z >= center.clone().add(0, 0, size).getZ()) || (x <= center.clone().subtract(size,0,0).getX() || (z <= center.clone().subtract(0,0, size).getZ())));
124+
}
125+
116126
public void updateConfig(ChunkBuster main) { // Basic config updater that saves the old config, loads the new one, and inserts the old keys
117-
if (main.getConfigValues().getConfigVersion() < 2.1) {
127+
if (main.getConfigValues().getConfigVersion() < 2.2) {
118128
Map<String, Object> oldValues = new HashMap<>();
119129
for (String oldKey : main.getConfig().getKeys(true)) {
120130
oldValues.put(oldKey, main.getConfig().get(oldKey));
@@ -126,7 +136,7 @@ public void updateConfig(ChunkBuster main) { // Basic config updater that saves
126136
main.getConfig().set(newKey, oldValues.get(newKey));
127137
}
128138
}
129-
main.getConfig().set("config-version", 2.1);
139+
main.getConfig().set("config-version", 2.2);
130140
main.saveConfig();
131141
}
132142
}

ChunkBusterPlugin/src/main/resources/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ hooks:
120120
coreprotect: false # Whether CoreProtect should log all removed blocks or not. Will have no effect if coreprotect is not installed.
121121
worldguard: true # Check for block-break flag in regions
122122
towny: false # Check land build permissions
123+
worldborder: true # Check for the worldborder, may or may not be a tiny bit slower
123124

124125
# The minimum factions role for using chunkbusters
125126
# For FactionsUUID/SavageFactions, set this to either "leader"/"admin", "coleader", "moderator", "member"/"normal", "recruit"/"any"
@@ -131,4 +132,4 @@ minimum-factions-role: "any"
131132
show-update-messages: true
132133

133134
# Please do not edit :)
134-
config-version: 2.1
135+
config-version: 2.2

0 commit comments

Comments
 (0)