Skip to content

Commit 89be4ae

Browse files
Dozz3sespidev
authored andcommitted
Add prevent_wind_charge option (#443)
1 parent a20ed45 commit 89be4ae

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

src/main/java/dev/espi/protectionstones/ListenerClass.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.bukkit.command.CommandSender;
3838
import org.bukkit.enchantments.Enchantment;
3939
import org.bukkit.entity.Player;
40+
import org.bukkit.entity.WindCharge;
4041
import org.bukkit.event.Event;
4142
import org.bukkit.event.EventHandler;
4243
import org.bukkit.event.EventPriority;
@@ -50,7 +51,6 @@
5051
import org.bukkit.event.player.PlayerJoinEvent;
5152
import org.bukkit.event.player.PlayerTeleportEvent;
5253
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
53-
import org.bukkit.inventory.Inventory;
5454
import org.bukkit.inventory.ItemStack;
5555

5656
import java.util.List;
@@ -372,7 +372,7 @@ public void onSpongeAbsorb(SpongeAbsorbEvent event) {
372372
event.setCancelled(true);
373373
}
374374
}
375-
375+
376376
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
377377
public void onBlockFade(BlockFadeEvent e) {
378378
if (ProtectionStones.isProtectBlock(e.getBlock())) {
@@ -437,26 +437,27 @@ private void pistonUtil(List<Block> pushedBlocks, BlockPistonEvent e) {
437437

438438
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
439439
public void onBlockExplode(BlockExplodeEvent e) {
440-
explodeUtil(e.blockList(), e.getBlock().getLocation().getWorld());
440+
explodeUtil(e.blockList(), e.getBlock().getLocation().getWorld(), false);
441441
}
442442

443443
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
444444
public void onEntityExplode(EntityExplodeEvent e) {
445-
explodeUtil(e.blockList(), e.getLocation().getWorld());
445+
boolean isWindCharge = e.getEntity() instanceof WindCharge;
446+
explodeUtil(e.blockList(), e.getLocation().getWorld(), isWindCharge);
446447
}
447448

448449
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
449450
public void onEntityChangeBlock(EntityChangeBlockEvent e) {
450451
if (!ProtectionStones.isProtectBlock(e.getBlock())) return;
451452

452453
// events like ender dragon block break, wither running into block break, etc.
453-
if (!blockExplodeUtil(e.getBlock().getWorld(), e.getBlock())) {
454+
if (!blockExplodeUtil(e.getBlock().getWorld(), e.getBlock(), false)) {
454455
// if block shouldn't be exploded, cancel the event
455456
e.setCancelled(true);
456457
}
457458
}
458459

459-
private void explodeUtil(List<Block> blockList, World w) {
460+
private void explodeUtil(List<Block> blockList, World w, boolean isWindCharge) {
460461
// loop through exploded blocks
461462
for (int i = 0; i < blockList.size(); i++) {
462463
Block b = blockList.get(i);
@@ -467,12 +468,12 @@ private void explodeUtil(List<Block> blockList, World w) {
467468
i--;
468469
}
469470

470-
blockExplodeUtil(w, b);
471+
blockExplodeUtil(w, b, isWindCharge);
471472
}
472473
}
473474

474475
// returns whether the block is exploded
475-
private boolean blockExplodeUtil(World w, Block b) {
476+
private boolean blockExplodeUtil(World w, Block b, boolean isWindCharge) {
476477
if (ProtectionStones.isProtectBlock(b)) {
477478
String id = WGUtils.createPSID(b.getLocation());
478479
PSProtectBlock blockOptions = ProtectionStones.getBlockOptions(b);
@@ -482,6 +483,10 @@ private boolean blockExplodeUtil(World w, Block b) {
482483
return false;
483484
}
484485

486+
if (isWindCharge && blockOptions.preventWindChargeExplode) {
487+
return false;
488+
}
489+
485490
// manually set to air if exploded so there is no natural item drop
486491
b.setType(Material.AIR);
487492

src/main/java/dev/espi/protectionstones/PSProtectBlock.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public class PSProtectBlock {
137137
public boolean preventPistonPush;
138138
@Path("behaviour.prevent_explode")
139139
public boolean preventExplode;
140+
@Path("behaviour.prevent_wind_charge_explode")
141+
public boolean preventWindChargeExplode;
140142
@Path("behaviour.destroy_region_when_explode")
141143
public boolean destroyRegionWhenExplode;
142144
@Path("behaviour.prevent_silk_touch")

src/main/java/dev/espi/protectionstones/placeholders/ConfigPlaceholders.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ static String resolveBlockConfig(PSProtectBlock b, String identifier) {
218218
return b.preventPistonPush + "";
219219
case "behaviour_prevent_explode":
220220
return b.preventExplode + "";
221+
case "behaviour_prevent_wind_charge_explode":
222+
return b.preventWindChargeExplode + "";
221223
case "behaviour_destroy_region_when_explode":
222224
return b.destroyRegionWhenExplode + "";
223225
case "behaviour_prevent_silk_touch":

src/main/resources/block1.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ placing_bypasses_wg_passthrough = true
224224
# Recommended to keep true to prevent players from exploiting more protection stones with /ps unhide (when the block is destroyed)
225225
prevent_explode = true
226226

227+
# Prevents the block from being destroyed when exploded wind charge.
228+
# Recommended to keep true if you don't want to ban all explosions, but don't want the region to explode using this method
229+
prevent_wind_charge_explode = true
230+
227231
# Destroys the protection stone region when block is exploded. Can be useful for PVP/Factions servers.
228232
# prevent_explode must be false for this to work.
229233
destroy_region_when_explode = false

0 commit comments

Comments
 (0)