mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-28 12:55:34 +01:00
Minor readability improvements in EntityDamageByBlockListener
This commit is contained in:
parent
554e17df02
commit
3742e018c4
@ -23,37 +23,44 @@ public final class EntityDamageByBlockListener extends Queue implements Listener
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
protected void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
|
||||
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) {
|
||||
final Entity entity = event.getEntity();
|
||||
Block block = entity.getLocation().getBlock();
|
||||
String user = "#" + damager.getType().name().toLowerCase(Locale.ROOT);
|
||||
if (user.contains("tnt")) {
|
||||
user = "#tnt";
|
||||
}
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof ItemFrame) && !(entity instanceof ArmorStand) && !(entity instanceof EnderCrystal)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.isCancelled() && Config.getConfig(entity.getWorld()).BLOCK_BREAK) {
|
||||
if (entity instanceof ItemFrame) {
|
||||
Material frameType = BukkitAdapter.ADAPTER.getFrameType(entity);
|
||||
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);
|
||||
}
|
||||
}
|
||||
Block damager = event.getDamager();
|
||||
if (damager == null || damager.getType() == Material.MAGMA_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled() || !Config.getConfig(entity.getWorld()).BLOCK_BREAK) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = entity.getLocation().getBlock();
|
||||
String user = "#" + damager.getType().name().toLowerCase(Locale.ROOT);
|
||||
if (user.contains("tnt")) {
|
||||
user = "#tnt";
|
||||
}
|
||||
|
||||
if (entity instanceof ItemFrame) {
|
||||
Material frameType = BukkitAdapter.ADAPTER.getFrameType(entity);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user