diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java index 4e2d207b0..1edf9f189 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java @@ -46,7 +46,6 @@ import com.sk89q.worldedit.util.Enums; import com.sk89q.worldedit.world.block.BlockType; import io.papermc.lib.PaperLib; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.Particle; import org.bukkit.World; import org.bukkit.block.Block; @@ -59,6 +58,7 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Vehicle; +import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.event.Cancellable; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -85,8 +85,11 @@ import java.util.Objects; @SuppressWarnings("unused") public class EntityEventListener implements Listener { - private static final NamespacedKey TNT_MINECART = NamespacedKey.minecraft("tnt_minecart"); - private static final Particle EXPLOSION_HUGE = Objects.requireNonNull(Enums.findByValue(Particle.class, "EXPLOSION_EMITTER", "EXPLOSION_HUGE")); + private static final Particle EXPLOSION_HUGE = Objects.requireNonNull(Enums.findByValue( + Particle.class, + "EXPLOSION_EMITTER", + "EXPLOSION_HUGE" + )); private final BukkitPlatform platform; private final PlotAreaManager plotAreaManager; @@ -320,7 +323,7 @@ public class EntityEventListener implements Listener { if (this.lastRadius != 0) { List nearby = event.getEntity().getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius); for (Entity near : nearby) { - if (near instanceof TNTPrimed || near.getType().getKey().equals(TNT_MINECART)) { + if (near instanceof TNTPrimed || near instanceof ExplosiveMinecart) { if (!near.hasMetadata("plot")) { near.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot)); } @@ -371,8 +374,7 @@ public class EntityEventListener implements Listener { // Burning player evaporating powder snow. Use same checks as // trampling farmland BlockType blockType = BukkitAdapter.asBlockType(type); - if (!this.eventDispatcher.checkPlayerBlockEvent( - pp, + if (!this.eventDispatcher.checkPlayerBlockEvent(pp, PlayerBlockEventType.TRIGGER_PHYSICAL, location, blockType, true )) { event.setCancelled(true); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java index e4a1bc5fe..432b13b01 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java @@ -28,12 +28,13 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import io.papermc.lib.PaperLib; import org.bukkit.Chunk; -import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.EnderCrystal; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Item; import org.bukkit.entity.Vehicle; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -55,9 +56,6 @@ import java.util.List; public class EntitySpawnListener implements Listener { - private static final NamespacedKey ITEM = NamespacedKey.minecraft("item"); - private static final NamespacedKey END_CRYSTAL = NamespacedKey.minecraft("end_crystal"); - private static final String KEY = "P2"; private static boolean ignoreTP = false; private static boolean hasPlotArea = false; @@ -136,7 +134,7 @@ public class EntitySpawnListener implements Listener { Plot plot = location.getOwnedPlotAbs(); EntityType type = entity.getType(); if (plot == null) { - if (type.getKey().equals(ITEM)) { + if (entity instanceof Item) { if (Settings.Enabled_Components.KILL_ROAD_ITEMS) { event.setCancelled(true); } @@ -158,7 +156,7 @@ public class EntitySpawnListener implements Listener { if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { event.setCancelled(true); } - if (type.getKey().equals(END_CRYSTAL) || type == EntityType.ARMOR_STAND) { + if (entity instanceof EnderCrystal || type == EntityType.ARMOR_STAND) { if (BukkitEntityUtil.checkEntity(entity, plot)) { event.setCancelled(true); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index 955d6f4c3..a9f97013f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -95,7 +95,6 @@ import org.bukkit.block.data.Waterlogged; import org.bukkit.command.PluginCommand; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Boat; -import org.bukkit.entity.ChestBoat; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.HumanEntity; @@ -377,8 +376,7 @@ public class PlayerEventListener implements Listener { @EventHandler public void onVehicleEntityCollision(VehicleEntityCollisionEvent e) { - final Class clazz = e.getVehicle().getType().getEntityClass(); - if (clazz != null && (Boat.class.isAssignableFrom(clazz) || ChestBoat.class.isAssignableFrom(clazz))) { + if (e.getEntity() instanceof Boat) { Location location = BukkitUtil.adapt(e.getEntity().getLocation()); if (location.isPlotArea()) { if (e.getEntity() instanceof Player) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java index 9569a9347..47e3b76e7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java @@ -34,8 +34,8 @@ import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.PlotFlagUtil; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; -import org.bukkit.NamespacedKey; import org.bukkit.entity.Entity; +import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; @@ -54,8 +54,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; @SuppressWarnings("unused") public class ProjectileEventListener implements Listener { - private static final NamespacedKey FISHING_BOBBER = NamespacedKey.minecraft("fishing_bobber"); - private final PlotAreaManager plotAreaManager; @Inject @@ -136,7 +134,7 @@ public class ProjectileEventListener implements Listener { event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { - if (entity.getType().getKey().equals(FISHING_BOBBER)) { + if (entity instanceof FishHook) { if (plot.getFlag(FishingFlag.class)) { return; } @@ -196,7 +194,7 @@ public class ProjectileEventListener implements Listener { return; } if (plot.isAdded(pp.getUUID()) || pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER) || plot.getFlag( - ProjectilesFlag.class) || (entity.getType().getKey().equals(FISHING_BOBBER) && plot.getFlag( + ProjectilesFlag.class) || (entity instanceof FishHook && plot.getFlag( FishingFlag.class))) { return; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java index 857d2d180..cb0272f2d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java @@ -45,11 +45,11 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; -import org.bukkit.NamespacedKey; import org.bukkit.entity.Arrow; import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.entity.EntityDamageEvent; @@ -60,8 +60,6 @@ import java.util.Objects; public class BukkitEntityUtil { - private static final NamespacedKey FIREWORK_ROCKET = NamespacedKey.minecraft("firework_rocket"); - public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE = new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake"); @@ -344,8 +342,7 @@ public class BukkitEntityUtil { } //disable the firework damage. too much of a headache to support at the moment. if (vplot != null) { - if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause - && damager.getType().getKey().equals(FIREWORK_ROCKET)) { + if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause && damager instanceof Firework) { return false; } }