Skip to content

Commit

Permalink
fix: replace (removed) constants with backwards compatible alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreSchwang committed Jan 25, 2025
1 parent 1192bf2 commit bdb3399
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.PlotFlagUtil;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
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;
Expand Down Expand Up @@ -78,10 +80,14 @@

import java.util.Iterator;
import java.util.List;
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 final BukkitPlatform platform;
private final PlotAreaManager plotAreaManager;
private final EventDispatcher eventDispatcher;
Expand Down Expand Up @@ -152,8 +158,8 @@ public void creatureSpawnEvent(CreatureSpawnEvent event) {
}
}
case "REINFORCEMENTS", "NATURAL", "MOUNT", "PATROL", "RAID", "SHEARED", "SILVERFISH_BLOCK", "ENDER_PEARL",
"TRAP", "VILLAGE_DEFENSE", "VILLAGE_INVASION", "BEEHIVE", "CHUNK_GEN", "NETHER_PORTAL",
"FROZEN", "SPELL", "DEFAULT" -> {
"TRAP", "VILLAGE_DEFENSE", "VILLAGE_INVASION", "BEEHIVE", "CHUNK_GEN", "NETHER_PORTAL",
"FROZEN", "SPELL", "DEFAULT" -> {
if (!area.isMobSpawning()) {
event.setCancelled(true);
return;
Expand Down Expand Up @@ -314,7 +320,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().equals(EntityType.MINECART_TNT)) {
if (near instanceof TNTPrimed || near.getType().getKey().equals(TNT_MINECART)) {
if (!near.hasMetadata("plot")) {
near.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
}
Expand All @@ -338,7 +344,7 @@ public void onBigBoom(EntityExplodeEvent event) {
event.setCancelled(true);
//Spawn Explosion Particles when enabled in settings
if (Settings.General.ALWAYS_SHOW_EXPLOSIONS) {
event.getLocation().getWorld().spawnParticle(Particle.EXPLOSION_HUGE, event.getLocation(), 0);
event.getLocation().getWorld().spawnParticle(EXPLOSION_HUGE, event.getLocation(), 0);
}
}

Expand All @@ -365,7 +371,8 @@ 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,6 +28,7 @@
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;
Expand All @@ -54,6 +55,9 @@

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 @@ -132,7 +136,7 @@ public void creatureSpawnEvent(EntitySpawnEvent event) {
Plot plot = location.getOwnedPlotAbs();
EntityType type = entity.getType();
if (plot == null) {
if (type == EntityType.DROPPED_ITEM) {
if (type.getKey().equals(ITEM)) {
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
event.setCancelled(true);
}
Expand All @@ -154,7 +158,7 @@ public void creatureSpawnEvent(EntitySpawnEvent event) {
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
event.setCancelled(true);
}
if (type == EntityType.ENDER_CRYSTAL || type == EntityType.ARMOR_STAND) {
if (type.getKey().equals(END_CRYSTAL) || 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 @@ -52,6 +52,7 @@
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Chunk;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.block.TileState;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -80,6 +81,9 @@
@SuppressWarnings("unused")
public class PaperListener implements Listener {

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

private final PlotAreaManager plotAreaManager;
private Chunk lastChunk;

Expand Down Expand Up @@ -228,7 +232,7 @@ public void onPreCreatureSpawnEvent(PreCreatureSpawnEvent event) {
if (plot == null) {
EntityType type = event.getType();
// PreCreatureSpawnEvent **should** not be called for DROPPED_ITEM, just for the sake of consistency
if (type == EntityType.DROPPED_ITEM) {
if (type.getKey().equals(ITEM)) {
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
event.setCancelled(true);
}
Expand Down Expand Up @@ -354,7 +358,7 @@ public void onProjectileLaunch(PlayerLaunchProjectileEvent event) {
event.setCancelled(true);
}
} else if (!plot.isAdded(pp.getUUID())) {
if (entity.getType().equals(EntityType.FISHING_HOOK)) {
if (entity.getType().getKey().equals(FISHING_BOBBER)) {
if (plot.getFlag(FishingFlag.class)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
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 @@ -376,7 +377,8 @@ public void onEffect(@NonNull EntityPotionEffectEvent event) {

@EventHandler
public void onVehicleEntityCollision(VehicleEntityCollisionEvent e) {
if (e.getVehicle().getType() == EntityType.BOAT) {
final Class<? extends Entity> clazz = e.getVehicle().getType().getEntityClass();
if (clazz != null && (Boat.class.isAssignableFrom(clazz) || ChestBoat.class.isAssignableFrom(clazz))) {
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,6 +34,7 @@
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.EntityType;
import org.bukkit.entity.LivingEntity;
Expand All @@ -54,6 +55,8 @@
@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 @@ -134,7 +137,7 @@ public void onProjectileLaunch(ProjectileLaunchEvent event) {
event.setCancelled(true);
}
} else if (!plot.isAdded(pp.getUUID())) {
if (entity.getType().equals(EntityType.FISHING_HOOK)) {
if (entity.getType().getKey().equals(FISHING_BOBBER)) {
if (plot.getFlag(FishingFlag.class)) {
return;
}
Expand Down Expand Up @@ -194,7 +197,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().equals(EntityType.FISHING_HOOK) && plot.getFlag(
ProjectilesFlag.class) || (entity.getType().getKey().equals(FISHING_BOBBER) && plot.getFlag(
FishingFlag.class))) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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;
Expand All @@ -59,6 +60,8 @@

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 @@ -342,7 +345,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() == EntityType.FIREWORK) {
&& damager.getType().getKey().equals(FIREWORK_ROCKET)) {
return false;
}
}
Expand Down

0 comments on commit bdb3399

Please sign in to comment.