Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/main/java/dev/espi/protectionstones/ListenerClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.entity.WindCharge;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -50,7 +51,6 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.List;
Expand Down Expand Up @@ -372,7 +372,7 @@ public void onSpongeAbsorb(SpongeAbsorbEvent event) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockFade(BlockFadeEvent e) {
if (ProtectionStones.isProtectBlock(e.getBlock())) {
Expand Down Expand Up @@ -437,26 +437,27 @@ private void pistonUtil(List<Block> pushedBlocks, BlockPistonEvent e) {

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockExplode(BlockExplodeEvent e) {
explodeUtil(e.blockList(), e.getBlock().getLocation().getWorld());
explodeUtil(e.blockList(), e.getBlock().getLocation().getWorld(), false);
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent e) {
explodeUtil(e.blockList(), e.getLocation().getWorld());
boolean isWindCharge = e.getEntity() instanceof WindCharge;
explodeUtil(e.blockList(), e.getLocation().getWorld(), isWindCharge);
}

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

// events like ender dragon block break, wither running into block break, etc.
if (!blockExplodeUtil(e.getBlock().getWorld(), e.getBlock())) {
if (!blockExplodeUtil(e.getBlock().getWorld(), e.getBlock(), false)) {
// if block shouldn't be exploded, cancel the event
e.setCancelled(true);
}
}

private void explodeUtil(List<Block> blockList, World w) {
private void explodeUtil(List<Block> blockList, World w, boolean isWindCharge) {
// loop through exploded blocks
for (int i = 0; i < blockList.size(); i++) {
Block b = blockList.get(i);
Expand All @@ -467,12 +468,12 @@ private void explodeUtil(List<Block> blockList, World w) {
i--;
}

blockExplodeUtil(w, b);
blockExplodeUtil(w, b, isWindCharge);
}
}

// returns whether the block is exploded
private boolean blockExplodeUtil(World w, Block b) {
private boolean blockExplodeUtil(World w, Block b, boolean isWindCharge) {
if (ProtectionStones.isProtectBlock(b)) {
String id = WGUtils.createPSID(b.getLocation());
PSProtectBlock blockOptions = ProtectionStones.getBlockOptions(b);
Expand All @@ -482,6 +483,10 @@ private boolean blockExplodeUtil(World w, Block b) {
return false;
}

if (isWindCharge && blockOptions.preventWindChargeExplode) {
return false;
}

// manually set to air if exploded so there is no natural item drop
b.setType(Material.AIR);

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/espi/protectionstones/PSProtectBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public class PSProtectBlock {
public boolean preventPistonPush;
@Path("behaviour.prevent_explode")
public boolean preventExplode;
@Path("behaviour.prevent_wind_charge_explode")
public boolean preventWindChargeExplode;
@Path("behaviour.destroy_region_when_explode")
public boolean destroyRegionWhenExplode;
@Path("behaviour.prevent_silk_touch")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ static String resolveBlockConfig(PSProtectBlock b, String identifier) {
return b.preventPistonPush + "";
case "behaviour_prevent_explode":
return b.preventExplode + "";
case "behaviour_prevent_wind_charge_explode":
return b.preventWindChargeExplode + "";
case "behaviour_destroy_region_when_explode":
return b.destroyRegionWhenExplode + "";
case "behaviour_prevent_silk_touch":
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/block1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ placing_bypasses_wg_passthrough = true
# Recommended to keep true to prevent players from exploiting more protection stones with /ps unhide (when the block is destroyed)
prevent_explode = true

# Prevents the block from being destroyed when exploded wind charge.
# Recommended to keep true if you don't want to ban all explosions, but don't want the region to explode using this method
prevent_wind_charge_explode = true

# Destroys the protection stone region when block is exploded. Can be useful for PVP/Factions servers.
# prevent_explode must be false for this to work.
destroy_region_when_explode = false
Expand Down