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,37 +23,44 @@ 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) {
Block damager = event.getDamager(); Entity entity = event.getEntity();
if (event.getEntity() instanceof ItemFrame || event.getEntity() instanceof ArmorStand || event.getEntity() instanceof EnderCrystal) { if (!(entity instanceof ItemFrame) && !(entity instanceof ArmorStand) && !(entity instanceof EnderCrystal)) {
if (damager != null && damager.getType() != Material.MAGMA_BLOCK) { return;
final Entity entity = event.getEntity(); }
Block block = entity.getLocation().getBlock();
String user = "#" + damager.getType().name().toLowerCase(Locale.ROOT);
if (user.contains("tnt")) {
user = "#tnt";
}
if (!event.isCancelled() && Config.getConfig(entity.getWorld()).BLOCK_BREAK) { Block damager = event.getDamager();
if (entity instanceof ItemFrame) { if (damager == null || damager.getType() == Material.MAGMA_BLOCK) {
Material frameType = BukkitAdapter.ADAPTER.getFrameType(entity); return;
ItemFrame frame = (ItemFrame) event.getEntity(); }
int data = 0;
if (frame.getItem() != null) { if (event.isCancelled() || !Config.getConfig(entity.getWorld()).BLOCK_BREAK) {
data = Util.getBlockId(frame.getItem().getType()); return;
} }
Queue.queueBlockBreak(user, block.getState(), frameType, null, data);
Queue.queueBlockPlace(user, block.getState(), frameType, null, frameType, -1, 0, null); Block block = entity.getLocation().getBlock();
} String user = "#" + damager.getType().name().toLowerCase(Locale.ROOT);
else if (entity instanceof ArmorStand) { if (user.contains("tnt")) {
Database.containerBreakCheck(user, Material.ARMOR_STAND, entity, null, block.getLocation()); user = "#tnt";
Queue.queueBlockBreak(user, block.getState(), Material.ARMOR_STAND, null, (int) entity.getLocation().getYaw()); }
}
else if (entity instanceof EnderCrystal) { if (entity instanceof ItemFrame) {
EnderCrystal crystal = (EnderCrystal) event.getEntity(); Material frameType = BukkitAdapter.ADAPTER.getFrameType(entity);
Queue.queueBlockBreak(user, block.getState(), Material.END_CRYSTAL, null, crystal.isShowingBottom() ? 1 : 0); ItemFrame frame = (ItemFrame) event.getEntity();
} int data = 0;
} if (frame.getItem() != null) {
data = Util.getBlockId(frame.getItem().getType());
} }
Queue.queueBlockBreak(user, block.getState(), frameType, null, data);
Queue.queueBlockPlace(user, block.getState(), frameType, null, frameType, -1, 0, null);
}
else if (entity instanceof ArmorStand) {
Database.containerBreakCheck(user, Material.ARMOR_STAND, entity, null, block.getLocation());
Queue.queueBlockBreak(user, block.getState(), Material.ARMOR_STAND, null, (int) entity.getLocation().getYaw());
}
else if (entity instanceof EnderCrystal) {
EnderCrystal crystal = (EnderCrystal) event.getEntity();
Queue.queueBlockBreak(user, block.getState(), Material.END_CRYSTAL, null, crystal.isShowingBottom() ? 1 : 0);
} }
} }