Minor readability improvements in EntityDamageByBlockListener

This commit is contained in:
Intelli 2021-10-04 16:09:08 -06:00
parent 554e17df02
commit 3742e018c4

View File

@ -23,17 +23,26 @@ public final class EntityDamageByBlockListener extends Queue implements Listener
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
protected void onEntityDamageByBlock(EntityDamageByBlockEvent event) { protected void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof ItemFrame) && !(entity instanceof ArmorStand) && !(entity instanceof EnderCrystal)) {
return;
}
Block damager = event.getDamager(); Block damager = event.getDamager();
if (event.getEntity() instanceof ItemFrame || event.getEntity() instanceof ArmorStand || event.getEntity() instanceof EnderCrystal) { if (damager == null || damager.getType() == Material.MAGMA_BLOCK) {
if (damager != null && damager.getType() != Material.MAGMA_BLOCK) { return;
final Entity entity = event.getEntity(); }
if (event.isCancelled() || !Config.getConfig(entity.getWorld()).BLOCK_BREAK) {
return;
}
Block block = entity.getLocation().getBlock(); Block block = entity.getLocation().getBlock();
String user = "#" + damager.getType().name().toLowerCase(Locale.ROOT); String user = "#" + damager.getType().name().toLowerCase(Locale.ROOT);
if (user.contains("tnt")) { if (user.contains("tnt")) {
user = "#tnt"; user = "#tnt";
} }
if (!event.isCancelled() && Config.getConfig(entity.getWorld()).BLOCK_BREAK) {
if (entity instanceof ItemFrame) { if (entity instanceof ItemFrame) {
Material frameType = BukkitAdapter.ADAPTER.getFrameType(entity); Material frameType = BukkitAdapter.ADAPTER.getFrameType(entity);
ItemFrame frame = (ItemFrame) event.getEntity(); ItemFrame frame = (ItemFrame) event.getEntity();
@ -41,6 +50,7 @@ public final class EntityDamageByBlockListener extends Queue implements Listener
if (frame.getItem() != null) { if (frame.getItem() != null) {
data = Util.getBlockId(frame.getItem().getType()); data = Util.getBlockId(frame.getItem().getType());
} }
Queue.queueBlockBreak(user, block.getState(), frameType, null, data); Queue.queueBlockBreak(user, block.getState(), frameType, null, data);
Queue.queueBlockPlace(user, block.getState(), frameType, null, frameType, -1, 0, null); Queue.queueBlockPlace(user, block.getState(), frameType, null, frameType, -1, 0, null);
} }
@ -53,8 +63,5 @@ public final class EntityDamageByBlockListener extends Queue implements Listener
Queue.queueBlockBreak(user, block.getState(), Material.END_CRYSTAL, null, crystal.isShowingBottom() ? 1 : 0); Queue.queueBlockBreak(user, block.getState(), Material.END_CRYSTAL, null, crystal.isShowingBottom() ? 1 : 0);
} }
} }
}
}
}
} }