mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-12-31 20:42:17 +00:00
Add settings to protect items from explosions (#2504)
Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> Co-authored-by: pop4959 <pop4959@gmail.com> Adds protection settings to Protect to block item damage when entities such as wither skulls, fireballs, TNT and creepers explode. Closes #2284.
This commit is contained in:
parent
ea57e4ae01
commit
846043e9a0
3 changed files with 47 additions and 0 deletions
|
@ -792,22 +792,28 @@ protect:
|
|||
water-bucket-flow: false
|
||||
fire-spread: true
|
||||
lava-fire-spread: true
|
||||
lava-itemdamage: false
|
||||
flint-fire: false
|
||||
lightning-fire-spread: true
|
||||
portal-creation: false
|
||||
tnt-explosion: false
|
||||
tnt-playerdamage: false
|
||||
tnt-itemdamage: false
|
||||
tnt-minecart-explosion: false
|
||||
tnt-minecart-playerdamage: false
|
||||
tnt-minecart-itemdamage: false
|
||||
fireball-explosion: false
|
||||
fireball-fire: false
|
||||
fireball-playerdamage: false
|
||||
fireball-itemdamage: false
|
||||
witherskull-explosion: false
|
||||
witherskull-playerdamage: false
|
||||
witherskull-itemdamage: false
|
||||
wither-spawnexplosion: false
|
||||
wither-blockreplace: false
|
||||
creeper-explosion: false
|
||||
creeper-playerdamage: false
|
||||
creeper-itemdamage: false
|
||||
creeper-blockdamage: false
|
||||
ender-crystal-explosion: false
|
||||
enderdragon-blockdamage: true
|
||||
|
|
|
@ -5,12 +5,16 @@ import com.earth2me.essentials.utils.EnumUtil;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.minecart.ExplosiveMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.world.PortalCreateEvent;
|
||||
|
||||
import java.util.Set;
|
||||
|
@ -58,6 +62,37 @@ public class EssentialsProtectBlockListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (event.getEntity() instanceof Item) {
|
||||
if (event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK || event.getCause() == EntityDamageEvent.DamageCause.LAVA) {
|
||||
event.setCancelled(prot.getSettingBool(ProtectConfig.disable_lava_item_dmg));
|
||||
}
|
||||
|
||||
if (event.getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) {
|
||||
if (event.getDamager() instanceof TNTPrimed) {
|
||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_tnt_itemdmg));
|
||||
}
|
||||
|
||||
if (event.getDamager() instanceof Creeper) {
|
||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_creeper_itemdmg));
|
||||
}
|
||||
|
||||
if (event.getDamager() instanceof ExplosiveMinecart) {
|
||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_tntminecart_itemdmg));
|
||||
}
|
||||
|
||||
if (event.getDamager() instanceof WitherSkull) {
|
||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_witherskull_itemdmg));
|
||||
}
|
||||
|
||||
if (event.getDamager() instanceof Fireball) {
|
||||
event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_fireball_itemdmg));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockFromTo(final BlockFromToEvent event) {
|
||||
final Block block = event.getBlock();
|
||||
|
|
|
@ -4,6 +4,7 @@ package com.earth2me.essentials.protect;
|
|||
public enum ProtectConfig {
|
||||
disable_contactdmg("protect.disable.contactdmg", false),
|
||||
disable_lavadmg("protect.disable.lavadmg", false),
|
||||
disable_lava_item_dmg("protect.prevent.lava-itemdamage", false),
|
||||
disable_pvp("protect.disable.pvp", false),
|
||||
disable_projectiles("protect.disable.projectiles", false),
|
||||
disable_fall("protect.disable.fall", false),
|
||||
|
@ -26,17 +27,22 @@ public enum ProtectConfig {
|
|||
prevent_block_on_rail("protect.protect.prevent-block-on-rails", false),
|
||||
prevent_tnt_explosion("protect.prevent.tnt-explosion", false),
|
||||
prevent_tnt_playerdmg("protect.prevent.tnt-playerdamage", false),
|
||||
prevent_tnt_itemdmg("protect.prevent.tnt-itemdamage", false),
|
||||
prevent_tntminecart_explosion("protect.prevent.tnt-minecart-explosion", false),
|
||||
prevent_tntminecart_playerdmg("protect.prevent.tnt-minecart-playerdamage", false),
|
||||
prevent_tntminecart_itemdmg("protect.prevent.tnt-minecart-itemdamage", false),
|
||||
prevent_fireball_explosion("protect.prevent.fireball-explosion", false),
|
||||
prevent_fireball_fire("protect.prevent.fireball-fire", false),
|
||||
prevent_fireball_playerdmg("protect.prevent.fireball-playerdamage", false),
|
||||
prevent_fireball_itemdmg("protect.prevent.fireball-itemdamage", false),
|
||||
prevent_witherskull_explosion("protect.prevent.witherskull-explosion", false),
|
||||
prevent_witherskull_playerdmg("protect.prevent.witherskull-playerdamage", false),
|
||||
prevent_witherskull_itemdmg("protect.prevent.witherskull-itemdamage", false),
|
||||
prevent_wither_spawnexplosion("protect.prevent.wither-spawnexplosion", false),
|
||||
prevent_wither_blockreplace("protect.prevent.wither-blockreplace", false),
|
||||
prevent_creeper_explosion("protect.prevent.creeper-explosion", true),
|
||||
prevent_creeper_playerdmg("protect.prevent.creeper-playerdamage", false),
|
||||
prevent_creeper_itemdmg("protect.prevent.creeper-itemdamage", false),
|
||||
prevent_creeper_blockdmg("protect.prevent.creeper-blockdamage", false),
|
||||
prevent_ender_crystal_explosion("protect.prevent.ender-crystal-explosion", false),
|
||||
prevent_enderman_pickup("protect.prevent.enderman-pickup", false),
|
||||
|
|
Loading…
Reference in a new issue