Skip to content

Commit a88bd44

Browse files
committed
Make worldguard hook check all 4 corners of a chunk instead of just the middle block, fix a bug with the new inventory stuff.
1 parent 221f2a4 commit a88bd44

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>codes.biscuit</groupId>
88
<artifactId>ChunkBuster</artifactId>
9-
<version>1.2.1</version>
9+
<version>1.2.2</version>
1010
<name>ChunkBuster</name>
1111

1212
<build>

src/main/java/codes/biscuit/chunkbuster/events/PlayerEvents.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,13 @@ public void onConfirmClick(InventoryClickEvent e) {
136136
itemSlot = p.getInventory().getHeldItemSlot();
137137
} else {
138138
for (int i = 0; i <= 40; i++) { // 40 should fix the offhand issue.
139-
ItemStack currentItem = p.getInventory().getItem(i);
140-
if (currentItem.getType().equals(main.getConfigValues().getChunkBusterMaterial()) && currentItem.hasItemMeta() && currentItem.getItemMeta().getEnchantLevel(Enchantment.LURE) > 0) {
139+
ItemStack currentItem;
140+
try {
141+
currentItem = p.getInventory().getItem(i);
142+
} catch (IndexOutOfBoundsException ex) {
143+
continue;
144+
}
145+
if (currentItem != null && currentItem.getType().equals(main.getConfigValues().getChunkBusterMaterial()) && currentItem.hasItemMeta() && currentItem.getItemMeta().getEnchantLevel(Enchantment.LURE) > 0) {
141146
itemSlot = i;
142147
break;
143148
}

src/main/java/codes/biscuit/chunkbuster/hooks/HookUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public boolean compareLocToPlayer(Location loc, Player p) {
107107
}
108108
if (main.getConfigValues().worldguardHookEnabled() && enabledHooks.containsKey(HookType.WORLDGUARD)) {
109109
WorldGuardHook worldGuardHook = (WorldGuardHook)enabledHooks.get(HookType.WORLDGUARD);
110-
if (!worldGuardHook.checkLocationBreakFlag(loc, p)) canBuild = false;
110+
if (!worldGuardHook.checkLocationBreakFlag(loc.getChunk(), p)) canBuild = false;
111111
}
112112
if (main.getConfigValues().townyHookEnabled() && enabledHooks.containsKey(HookType.TOWNY)) {
113113
TownyHook townyHook = (TownyHook)enabledHooks.get(HookType.TOWNY);

src/main/java/codes/biscuit/chunkbuster/hooks/TownyHook.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ boolean canBuild(Chunk chunk, Player p) {
1616
} else {
1717
Block[] cornerBlocks = {chunk.getBlock(0,chunk.getWorld().getMaxHeight()/2, 0), chunk.getBlock(0,chunk.getWorld().getMaxHeight()/2, 15),
1818
chunk.getBlock(15,chunk.getWorld().getMaxHeight()/2, 0), chunk.getBlock(15,chunk.getWorld().getMaxHeight()/2, 15)};
19-
2019
for (Block currentBlock : cornerBlocks) {
2120
if (!PlayerCacheUtil.getCachePermission(p, currentBlock.getLocation(), currentBlock.getType(), TownyPermission.ActionType.DESTROY)) return false;
2221
}

src/main/java/codes/biscuit/chunkbuster/hooks/WorldGuardHook.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@
88
import com.sk89q.worldguard.protection.flags.DefaultFlag;
99
import com.sk89q.worldguard.protection.flags.StateFlag;
1010
import org.bukkit.Bukkit;
11-
import org.bukkit.Location;
11+
import org.bukkit.Chunk;
12+
import org.bukkit.block.Block;
1213
import org.bukkit.entity.Player;
1314

1415
class WorldGuardHook {
1516

16-
boolean checkLocationBreakFlag(Location loc, Player p) {
17+
boolean checkLocationBreakFlag(Chunk chunk, Player p) {
1718
WorldGuardPlugin worldGuardPlugin = (WorldGuardPlugin)Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
1819
RegionContainer container = worldGuardPlugin.getRegionContainer();
19-
RegionQuery query = container.createQuery();
20-
ApplicableRegionSet set = query.getApplicableRegions(loc);
21-
LocalPlayer localPlayer = worldGuardPlugin.wrapPlayer(p);
22-
return !(set.queryState(localPlayer, DefaultFlag.BLOCK_BREAK) == StateFlag.State.DENY); // Block break isn't set to deny
20+
Block[] cornerBlocks = {chunk.getBlock(0,chunk.getWorld().getMaxHeight()/2, 0), chunk.getBlock(0,chunk.getWorld().getMaxHeight()/2, 15),
21+
chunk.getBlock(15,chunk.getWorld().getMaxHeight()/2, 0), chunk.getBlock(15,chunk.getWorld().getMaxHeight()/2, 15)};
22+
for (Block currentBlock : cornerBlocks) {
23+
RegionQuery query = container.createQuery();
24+
ApplicableRegionSet set = query.getApplicableRegions(currentBlock.getLocation());
25+
LocalPlayer localPlayer = worldGuardPlugin.wrapPlayer(p);
26+
if (set.queryState(localPlayer, DefaultFlag.BLOCK_BREAK) == StateFlag.State.DENY) return false; // If block break is set to deny
27+
}
28+
return true;
2329
}
2430
}

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ messages:
105105
not-minimum-role: '&cYou must be a faction (insert role) to use chunkbusters.'
106106
gui-cancel: '&cThe chunkbuster has been cancelled.'
107107
cooldown: '&cYou must wait {minutes} minute(s) and {seconds} second(s) to use this again!'
108-
no-item: 'You must have a chunk buster in your inventory!'
108+
no-item: '&cYou must have a chunk buster in your inventory!'
109109

110110
# Blocks that will not get cleared by chunkbusters. Use material enum names.
111111
ignored-materials:

0 commit comments

Comments
 (0)