Skip to content

Commit

Permalink
chore: i like this more
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreSchwang committed Jan 26, 2025
1 parent e086d7a commit 2d736d8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
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;
Expand All @@ -59,6 +58,7 @@
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;
Expand All @@ -85,8 +85,11 @@
@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;
Expand Down Expand Up @@ -320,7 +323,7 @@ public void onBigBoom(EntityExplodeEvent event) {
if (this.lastRadius != 0) {
List<Entity> 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));
}
Expand Down Expand Up @@ -371,8 +374,7 @@ public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event)
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
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;
Expand All @@ -55,9 +56,6 @@

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;
Expand Down Expand Up @@ -136,7 +134,7 @@ public void creatureSpawnEvent(EntitySpawnEvent event) {
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);
}
Expand All @@ -158,7 +156,7 @@ public void creatureSpawnEvent(EntitySpawnEvent event) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
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;
Expand Down Expand Up @@ -377,8 +376,7 @@ public void onEffect(@NonNull EntityPotionEffectEvent event) {

@EventHandler
public void onVehicleEntityCollision(VehicleEntityCollisionEvent e) {
final Class<? extends Entity> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
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;
Expand All @@ -54,8 +54,6 @@
@SuppressWarnings("unused")
public class ProjectileEventListener implements Listener {

private static final NamespacedKey FISHING_BOBBER = NamespacedKey.minecraft("fishing_bobber");

private final PlotAreaManager plotAreaManager;

@Inject
Expand Down Expand Up @@ -136,7 +134,7 @@ public void onProjectileLaunch(ProjectileLaunchEvent event) {
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;
}
Expand Down Expand Up @@ -196,7 +194,7 @@ public void onProjectileHit(ProjectileHitEvent event) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
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;
Expand All @@ -60,8 +60,6 @@

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");

Expand Down Expand Up @@ -344,8 +342,7 @@ public static boolean entityDamage(Entity damager, Entity victim, EntityDamageEv
}
//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;
}
}
Expand Down

0 comments on commit 2d736d8

Please sign in to comment.