chore: start work on flexible entity type wrapper

This commit is contained in:
Pierre Maurice Schwang
2025-10-27 22:09:55 +01:00
parent df15203f2b
commit 6c06d5f11d
9 changed files with 409 additions and 284 deletions

View File

@@ -24,6 +24,7 @@ import com.google.inject.Injector;
import com.google.inject.Key; import com.google.inject.Key;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.google.inject.Stage; import com.google.inject.Stage;
import com.plotsquared.bukkit.entity.EntityType;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import com.plotsquared.bukkit.inject.BackupModule; import com.plotsquared.bukkit.inject.BackupModule;
import com.plotsquared.bukkit.inject.BukkitModule; import com.plotsquared.bukkit.inject.BukkitModule;
@@ -794,60 +795,29 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
if (entity.getMetadata("ps_custom_spawned").stream().anyMatch(MetadataValue::asBoolean)) { if (entity.getMetadata("ps_custom_spawned").stream().anyMatch(MetadataValue::asBoolean)) {
continue; continue;
} }
// TODO: use (type) pattern matching when targeting java 21
switch (entity.getType().toString()) { switch (EntityType.of(entity.getType())) {
case "EGG": case EGG, FISHING_BOBBER, EYE_OF_ENDER, AREA_EFFECT_CLOUD, EXPERIENCE_ORB, LEASH_KNOT, FIREWORK_ROCKET,
case "FISHING_HOOK", "FISHING_BOBBER": LIGHTNING_BOLT, WITHER_SKULL, UNKNOWN, PLAYER, MANNEQUIN, BLOCK_DISPLAY, INTERACTION, ITEM_DISPLAY,
case "ENDER_SIGNAL", "EYE_OF_ENDER": GLOW_ITEM_FRAME, TEXT_DISPLAY, OMINOUS_ITEM_SPAWNER, MARKER -> {
case "AREA_EFFECT_CLOUD":
case "EXPERIENCE_ORB":
case "LEASH_HITCH", "LEASH_KNOT":
case "FIREWORK", "FIREWORK_ROCKET":
case "LIGHTNING", "LIGHTNING_BOLT":
case "WITHER_SKULL":
case "UNKNOWN":
case "PLAYER":
// non moving / unmovable // non moving / unmovable
continue; }
case "THROWN_EXP_BOTTLE", "EXPERIENCE_BOTTLE": case EXPERIENCE_BOTTLE, SPLASH_POTION, LINGERING_POTION, SNOWBALL, SHULKER_BULLET, SPECTRAL_ARROW,
case "SPLASH_POTION", "POTION": ENDER_PEARL, ARROW, LLAMA_SPIT, TRIDENT -> {
case "SNOWBALL":
case "SHULKER_BULLET":
case "SPECTRAL_ARROW":
case "ENDER_PEARL":
case "ARROW":
case "LLAMA_SPIT":
case "TRIDENT":
// managed elsewhere | projectile // managed elsewhere | projectile
continue; }
case "ITEM_FRAME": case TNT, FALLING_BLOCK -> {
case "PAINTING": // managed elsewhere
}
case ITEM_FRAME, PAINTING -> {
// Not vehicles // Not vehicles
continue; }
case "ARMOR_STAND": // ARMOR_STAND temporarily classified as vehicle
// Temporarily classify as vehicle case ARMOR_STAND, MINECART, CHEST_MINECART, COMMAND_BLOCK_MINECART, FURNACE_MINECART, HOPPER_MINECART,
case "MINECART": SPAWNER_MINECART, END_CRYSTAL, TNT_MINECART, ACACIA_BOAT, BIRCH_BOAT, CHERRY_BOAT, DARK_OAK_BOAT,
case "MINECART_CHEST": JUNGLE_BOAT, MANGROVE_BOAT, OAK_BOAT, PALE_OAK_BOAT, SPRUCE_BOAT, BAMBOO_RAFT, ACACIA_CHEST_BOAT,
case "CHEST_MINECART": BIRCH_CHEST_BOAT, CHERRY_CHEST_BOAT, DARK_OAK_CHEST_BOAT, JUNGLE_CHEST_BOAT, MANGROVE_CHEST_BOAT,
case "MINECART_COMMAND": OAK_CHEST_BOAT, PALE_OAK_CHEST_BOAT, SPRUCE_CHEST_BOAT, BAMBOO_CHEST_RAFT -> {
case "COMMAND_BLOCK_MINECART":
case "MINECART_FURNACE":
case "FURNACE_MINECART":
case "MINECART_HOPPER":
case "HOPPER_MINECART":
case "MINECART_MOB_SPAWNER":
case "SPAWNER_MINECART":
case "END_CRYSTAL":
case "ENDER_CRYSTAL": // Backwards compatibility for 1.20.4
case "MINECART_TNT":
case "TNT_MINECART":
case "CHEST_BOAT":
case "BOAT":
case "ACACIA_BOAT", "BIRCH_BOAT", "CHERRY_BOAT", "DARK_OAK_BOAT", "JUNGLE_BOAT", "MANGROVE_BOAT",
"OAK_BOAT", "PALE_OAK_BOAT", "SPRUCE_BOAT", "BAMBOO_RAFT":
case "ACACIA_CHEST_BOAT", "BIRCH_CHEST_BOAT", "CHERRY_CHEST_BOAT", "DARK_OAK_CHEST_BOAT",
"JUNGLE_CHEST_BOAT", "MANGROVE_CHEST_BOAT", "OAK_CHEST_BOAT", "PALE_OAK_CHEST_BOAT",
"SPRUCE_CHEST_BOAT", "BAMBOO_CHEST_RAFT":
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) { if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
com.plotsquared.core.location.Location location = BukkitUtil.adapt(entity.getLocation()); com.plotsquared.core.location.Location location = BukkitUtil.adapt(entity.getLocation());
Plot plot = location.getPlot(); Plot plot = location.getPlot();
@@ -872,22 +842,15 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
this.removeRoadEntity(entity, iterator); this.removeRoadEntity(entity, iterator);
} }
} }
continue; }
case "SMALL_FIREBALL": case SMALL_FIREBALL, FIREBALL, DRAGON_FIREBALL, ITEM, WIND_CHARGE, BREEZE_WIND_CHARGE -> {
case "FIREBALL":
case "DRAGON_FIREBALL":
case "DROPPED_ITEM", "ITEM":
if (Settings.Enabled_Components.KILL_ROAD_ITEMS if (Settings.Enabled_Components.KILL_ROAD_ITEMS
&& plotArea.getOwnedPlotAbs(BukkitUtil.adapt(entity.getLocation())) == null) { && plotArea.getOwnedPlotAbs(BukkitUtil.adapt(entity.getLocation())) == null) {
this.removeRoadEntity(entity, iterator); this.removeRoadEntity(entity, iterator);
} }
// dropped item // dropped item
continue; }
case "PRIMED_TNT", "TNT": case SHULKER -> {
case "FALLING_BLOCK":
// managed elsewhere
continue;
case "SHULKER":
if (Settings.Enabled_Components.KILL_ROAD_MOBS && (Settings.Enabled_Components.KILL_NAMED_ROAD_MOBS || entity.getCustomName() == null)) { if (Settings.Enabled_Components.KILL_ROAD_MOBS && (Settings.Enabled_Components.KILL_NAMED_ROAD_MOBS || entity.getCustomName() == null)) {
LivingEntity livingEntity = (LivingEntity) entity; LivingEntity livingEntity = (LivingEntity) entity;
List<MetadataValue> meta = entity.getMetadata("shulkerPlot"); List<MetadataValue> meta = entity.getMetadata("shulkerPlot");
@@ -928,80 +891,16 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
} }
} }
} }
continue; }
case "ZOMBIFIED_PIGLIN": case ZOMBIFIED_PIGLIN, PIGLIN_BRUTE, LLAMA, DONKEY, MULE, ZOMBIE_HORSE, SKELETON_HORSE, HUSK,
case "PIGLIN_BRUTE": ELDER_GUARDIAN, WITHER_SKELETON, STRAY, ZOMBIE_VILLAGER, EVOKER, EVOKER_FANGS, VEX, VINDICATOR,
case "LLAMA": POLAR_BEAR, BAT, BLAZE, CAVE_SPIDER, CHICKEN, COW, CREEPER, ENDERMAN, ENDERMITE, ENDER_DRAGON, GHAST,
case "DONKEY": HAPPY_GHAST, GIANT, GUARDIAN, HORSE, IRON_GOLEM, MAGMA_CUBE, MOOSHROOM, OCELOT, PIG, RABBIT, SHEEP,
case "MULE": SILVERFISH, SKELETON, SLIME, SNOW_GOLEM, SPIDER, SQUID, VILLAGER, WITCH, WITHER, WOLF, ZOMBIE,
case "ZOMBIE_HORSE": PARROT, SALMON, DOLPHIN, TROPICAL_FISH, DROWNED, COD, TURTLE, PUFFERFISH, PHANTOM, ILLUSIONER, CAT,
case "SKELETON_HORSE": PANDA, FOX, PILLAGER, TRADER_LLAMA, WANDERING_TRADER, RAVAGER, BEE, HOGLIN, PIGLIN, ZOGLIN, FROG,
case "HUSK": GOAT, WARDEN, TADPOLE, ALLAY, ARMADILLO, AXOLOTL, STRIDER, SNIFFER, CAMEL, BOGGED, COPPER_GOLEM,
case "ELDER_GUARDIAN": GLOW_SQUID, BREEZE, CREAKING -> {
case "WITHER_SKELETON":
case "STRAY":
case "ZOMBIE_VILLAGER":
case "EVOKER":
case "EVOKER_FANGS":
case "VEX":
case "VINDICATOR":
case "POLAR_BEAR":
case "BAT":
case "BLAZE":
case "CAVE_SPIDER":
case "CHICKEN":
case "COW":
case "CREEPER":
case "ENDERMAN":
case "ENDERMITE":
case "ENDER_DRAGON":
case "GHAST":
case "HAPPY_GHAST": // 1.21.6+
case "GHASTLING": // 1.21.6+
case "GIANT":
case "GUARDIAN":
case "HORSE":
case "IRON_GOLEM":
case "MAGMA_CUBE":
case "MUSHROOM_COW", "MOOSHROOM":
case "OCELOT":
case "PIG":
case "PIG_ZOMBIE":
case "RABBIT":
case "SHEEP":
case "SILVERFISH":
case "SKELETON":
case "SLIME":
case "SNOWMAN", "SNOW_GOLEM":
case "SPIDER":
case "SQUID":
case "VILLAGER":
case "WITCH":
case "WITHER":
case "WOLF":
case "ZOMBIE":
case "PARROT":
case "SALMON":
case "DOLPHIN":
case "TROPICAL_FISH":
case "DROWNED":
case "COD":
case "TURTLE":
case "PUFFERFISH":
case "PHANTOM":
case "ILLUSIONER":
case "CAT":
case "PANDA":
case "FOX":
case "PILLAGER":
case "TRADER_LLAMA":
case "WANDERING_TRADER":
case "RAVAGER":
case "BEE":
case "HOGLIN":
case "PIGLIN":
case "ZOGLIN":
default: {
if (Settings.Enabled_Components.KILL_ROAD_MOBS) { if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
Location location = entity.getLocation(); Location location = entity.getLocation();
if (BukkitUtil.adapt(location).isPlotRoad()) { if (BukkitUtil.adapt(location).isPlotRoad()) {

View File

@@ -0,0 +1,261 @@
package com.plotsquared.bukkit.entity;
import com.sk89q.worldedit.util.Enums;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.EnumMap;
/**
* Wrapper Class for Bukkit {@link org.bukkit.entity.EntityType EntityTypes}.
* <br>
* Intended for a backwards compatible way to interact with entity types. Enum Constants should always be named after the
* constants of bukkits EntityType enum in the latest supported versions. Backwards compatible enum constants identifiers
* should have a comment assigned to them, so they can be removed in future versions.
*/
@ApiStatus.Internal
public enum EntityType {
ACACIA_BOAT,
ACACIA_CHEST_BOAT,
ALLAY,
AREA_EFFECT_CLOUD,
ARMADILLO,
ARMOR_STAND,
ARROW,
AXOLOTL,
BAMBOO_CHEST_RAFT,
BAMBOO_RAFT,
BAT,
BEE,
BIRCH_BOAT,
BIRCH_CHEST_BOAT,
BLAZE,
BLOCK_DISPLAY,
BOGGED,
BREEZE,
BREEZE_WIND_CHARGE,
CAMEL,
CAT,
CAVE_SPIDER,
CHERRY_BOAT,
CHERRY_CHEST_BOAT,
// 1.20.5: MINECART_CHEST -> CHEST_MINECART
CHEST_MINECART("MINECART_CHEST"),
CHICKEN,
COD,
// 1.20.5: MINECART_COMMAND -> COMMAND_BLOCK_MINECART
COMMAND_BLOCK_MINECART("MINECART_COMMAND"),
COPPER_GOLEM,
COW,
CREAKING,
CREEPER,
DARK_OAK_BOAT,
DARK_OAK_CHEST_BOAT,
DOLPHIN,
DONKEY,
DRAGON_FIREBALL,
DROWNED,
EGG,
ELDER_GUARDIAN,
// 1.20.5: ENDER_CRYSTAL -> END_CRYSTAL
END_CRYSTAL("ENDER_CRYSTAL"),
ENDER_DRAGON,
ENDER_PEARL,
ENDERMAN,
ENDERMITE,
EVOKER,
EVOKER_FANGS,
// 1.20.5: THROWN_EXP_BOTTLE -> EXPERIENCE_BOTTLE
EXPERIENCE_BOTTLE("THROWN_EXP_BOTTLE"),
EXPERIENCE_ORB,
// 1.20.5: ENDER_SIGNAL -> EYE_OF_ENDER
EYE_OF_ENDER("ENDER_SIGNAL"),
FALLING_BLOCK,
FIREBALL,
// 1.20.5: FIREWORK -> FIREWORK_ROCKET
FIREWORK_ROCKET("FIREWORK"),
// 1.20.5: FISHING_HOOK -> FISHING_BOBBER
FISHING_BOBBER("FISHING_HOOK"),
FOX,
FROG,
// 1.20.5: MINECART_FURNACE -> FURNACE_MINECART
FURNACE_MINECART("MINECART_FURNACE"),
GHAST,
GIANT,
GLOW_ITEM_FRAME,
GLOW_SQUID,
GOAT,
GUARDIAN,
HAPPY_GHAST,
HOGLIN,
// 1.20.5: MINECART_HOPPER -> HOPPER_MINECART
HOPPER_MINECART("MINECART_HOPPER"),
HORSE,
HUSK,
ILLUSIONER,
INTERACTION,
IRON_GOLEM,
// 1.20.5: DROPPED_ITEM -> ITEM
ITEM("DROPPED_ITEM"),
ITEM_DISPLAY,
ITEM_FRAME,
JUNGLE_BOAT,
JUNGLE_CHEST_BOAT,
// 1.20.5: LEASH_HITCH -> LEASH_KNOT
LEASH_KNOT("LEASH_HITCH"),
// 1.20.5: LIGHTNING -> LIGHTNING_BOLT
LIGHTNING_BOLT("LIGHTNING"),
LINGERING_POTION,
LLAMA,
LLAMA_SPIT,
MAGMA_CUBE,
MANGROVE_BOAT,
MANGROVE_CHEST_BOAT,
MANNEQUIN,
MARKER,
MINECART,
// 1.20.5: MUSHROOM_COW -> MOOSHROOM
MOOSHROOM("MUSHROOM_COW"),
MULE,
// 1.21.3: BOAT -> boat subvariants (oak, dark_oak, ...)
OAK_BOAT("BOAT"),
// 1.21.3: CHEST_BOAT -> chest boat subvariants (oak, dark_oak, ...)
OAK_CHEST_BOAT("CHEST_BOAT"),
OCELOT,
OMINOUS_ITEM_SPAWNER,
PAINTING,
PALE_OAK_BOAT,
PALE_OAK_CHEST_BOAT,
PANDA,
PARROT,
PHANTOM,
PIG,
PIGLIN,
PIGLIN_BRUTE,
PILLAGER,
PLAYER,
POLAR_BEAR,
PUFFERFISH,
RABBIT,
RAVAGER,
SALMON,
SHEEP,
SHULKER,
SHULKER_BULLET,
SILVERFISH,
SKELETON,
SKELETON_HORSE,
SLIME,
SMALL_FIREBALL,
SNIFFER,
// 1.20.5: SNOWMAN -> SNOW_GOLEM
SNOW_GOLEM("SNOWMAN"),
SNOWBALL,
// 1.20.5: MINECART_MOB_SPAWNER -> SPAWNER_MINECART
SPAWNER_MINECART("MINECART_MOB_SPAWNER"),
SPECTRAL_ARROW,
SPIDER,
// 1.21.5: POTION -> SPLASH_POTION + LINGERING_POTION (use SPLASH_POTION FOR compatibility)
SPLASH_POTION("POTION"),
SPRUCE_BOAT,
SPRUCE_CHEST_BOAT,
SQUID,
STRAY,
STRIDER,
TADPOLE,
TEXT_DISPLAY,
// 1.20.5: PRIMED_TNT -> TNT
TNT("PRIMED_TNT"),
// 1.20.5: MINECART_TNT -> TNT_MINECART
TNT_MINECART("MINECART_TNT"),
TRADER_LLAMA,
TRIDENT,
TROPICAL_FISH,
TURTLE,
UNKNOWN,
VEX,
VILLAGER,
VINDICATOR,
WANDERING_TRADER,
WARDEN,
WIND_CHARGE,
WITCH,
WITHER,
WITHER_SKELETON,
WITHER_SKULL,
WOLF,
ZOGLIN,
ZOMBIE,
ZOMBIE_HORSE,
ZOMBIE_VILLAGER,
ZOMBIFIED_PIGLIN;
private static final Logger LOGGER = LoggerFactory.getLogger("PlotSquared/" + EntityType.class.getSimpleName());
private static final EnumMap<org.bukkit.entity.EntityType, EntityType> BUKKIT_TO_INTERNAL =
new EnumMap<>(org.bukkit.entity.EntityType.class);
private final org.bukkit.entity.EntityType bukkitType;
EntityType(final String... additionalBukkitEnumFields) {
org.bukkit.entity.EntityType temp = null;
try {
temp = org.bukkit.entity.EntityType.valueOf(name());
} catch (IllegalArgumentException ignored) {
if (additionalBukkitEnumFields.length > 0) {
temp = Enums.findByValue(org.bukkit.entity.EntityType.class, additionalBukkitEnumFields);
}
}
bukkitType = temp;
}
public @Nullable org.bukkit.entity.EntityType bukkitType() {
return bukkitType;
}
public boolean isAlive() {
return this.bukkitType != null && this.bukkitType.isAlive();
}
public boolean isSpawnable() {
return this.bukkitType != null && this.bukkitType.isSpawnable();
}
@Override
public String toString() {
return "EntityType{name=" + name() + "}";
}
public static EntityType of(org.bukkit.entity.EntityType bukkitType) {
return BUKKIT_TO_INTERNAL.get(bukkitType);
}
public static EntityType of(Entity entity) {
return of(entity.getType());
}
static {
// Register all entity types with their aliases
for (final EntityType value : values()) {
org.bukkit.entity.EntityType bukkitType = value.bukkitType();
if (bukkitType != null) {
BUKKIT_TO_INTERNAL.put(bukkitType, value);
}
}
// Make sure this wrapper contains EVERY possible entity type available by the server
for (final org.bukkit.entity.EntityType bukkitType : org.bukkit.entity.EntityType.values()) {
if (!BUKKIT_TO_INTERNAL.containsKey(bukkitType)) {
LOGGER.error(
"EntityType {} provided by server has no wrapper equivalent. Is this server version supported? " +
"Falling back to 'UNKNOWN' type.",
bukkitType
);
BUKKIT_TO_INTERNAL.put(bukkitType, EntityType.UNKNOWN);
}
}
}
}

View File

@@ -21,7 +21,6 @@ package com.plotsquared.bukkit.entity;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
public abstract class EntityWrapper { public abstract class EntityWrapper {
@@ -36,7 +35,7 @@ public abstract class EntityWrapper {
EntityWrapper(final @NonNull Entity entity) { EntityWrapper(final @NonNull Entity entity) {
this.entity = entity; this.entity = entity;
this.type = entity.getType(); this.type = EntityType.of(entity.getType());
final Location location = entity.getLocation(); final Location location = entity.getLocation();
this.x = location.getX(); this.x = location.getX();
@@ -49,7 +48,7 @@ public abstract class EntityWrapper {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public String toString() { public String toString() {
return String.format("[%s, x=%s, y=%s, z=%s]", type.getName(), x, y, z); return String.format("[%s, x=%s, y=%s, z=%s]", type, x, y, z);
} }
public abstract Entity spawn(World world, int xOffset, int zOffset); public abstract Entity spawn(World world, int xOffset, int zOffset);

View File

@@ -37,6 +37,7 @@ import org.bukkit.entity.ChestBoat;
import org.bukkit.entity.ChestedHorse; import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.EnderDragon; import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.GlowItemFrame;
import org.bukkit.entity.IronGolem; import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
@@ -52,6 +53,7 @@ import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.List; import java.util.List;
import java.util.Objects;
public final class ReplicatingEntityWrapper extends EntityWrapper { public final class ReplicatingEntityWrapper extends EntityWrapper {
@@ -85,7 +87,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
return; return;
} }
List<Entity> passengers = entity.getPassengers(); List<Entity> passengers = entity.getPassengers();
if (passengers.size() > 0) { if (!passengers.isEmpty()) {
this.base.passenger = new ReplicatingEntityWrapper(passengers.get(0), depth); this.base.passenger = new ReplicatingEntityWrapper(passengers.get(0), depth);
} }
this.base.fall = entity.getFallDistance(); this.base.fall = entity.getFallDistance();
@@ -101,44 +103,40 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (!entity.hasGravity()) { if (!entity.hasGravity()) {
this.noGravity = true; this.noGravity = true;
} }
switch (entity.getType().toString()) { switch (EntityType.of(entity.getType())) {
case "BOAT", "ACACIA_BOAT", "BIRCH_BOAT", "CHERRY_BOAT", "DARK_OAK_BOAT", "JUNGLE_BOAT", "MANGROVE_BOAT", case ACACIA_BOAT, BIRCH_BOAT, CHERRY_BOAT, DARK_OAK_BOAT, JUNGLE_BOAT, MANGROVE_BOAT,
"OAK_BOAT", "PALE_OAK_BOAT", "SPRUCE_BOAT", "BAMBOO_RAFT" -> { OAK_BOAT, PALE_OAK_BOAT, SPRUCE_BOAT, BAMBOO_RAFT -> {
Boat boat = (Boat) entity; Boat boat = (Boat) entity;
this.dataByte = getOrdinal(Boat.Type.values(), boat.getBoatType()); this.dataByte = getOrdinal(Boat.Type.values(), boat.getBoatType());
return;
} }
case "ACACIA_CHEST_BOAT", "BIRCH_CHEST_BOAT", "CHERRY_CHEST_BOAT", "DARK_OAK_CHEST_BOAT", case ACACIA_CHEST_BOAT, BIRCH_CHEST_BOAT, CHERRY_CHEST_BOAT, DARK_OAK_CHEST_BOAT,
"JUNGLE_CHEST_BOAT", "MANGROVE_CHEST_BOAT", "OAK_CHEST_BOAT", "PALE_OAK_CHEST_BOAT", JUNGLE_CHEST_BOAT, MANGROVE_CHEST_BOAT, OAK_CHEST_BOAT, PALE_OAK_CHEST_BOAT,
"SPRUCE_CHEST_BOAT", "BAMBOO_CHEST_RAFT" -> { SPRUCE_CHEST_BOAT, BAMBOO_CHEST_RAFT -> {
ChestBoat boat = (ChestBoat) entity; ChestBoat boat = (ChestBoat) entity;
this.dataByte = getOrdinal(Boat.Type.values(), boat.getBoatType()); this.dataByte = getOrdinal(Boat.Type.values(), boat.getBoatType());
storeInventory(boat); storeInventory(boat);
} }
case "ARROW", "EGG", "END_CRYSTAL", "ENDER_CRYSTAL", "ENDER_PEARL", "ENDER_SIGNAL", "EXPERIENCE_ORB", "FALLING_BLOCK", "FIREBALL", case ARROW, EGG, END_CRYSTAL, ENDER_PEARL, EYE_OF_ENDER, EXPERIENCE_ORB, FALLING_BLOCK, FIREBALL,
"FIREWORK", "FISHING_HOOK", "LEASH_HITCH", "LIGHTNING", "MINECART", "MINECART_COMMAND", "MINECART_MOB_SPAWNER", FIREWORK_ROCKET, FISHING_BOBBER, LEASH_KNOT, LIGHTNING_BOLT, MINECART, COMMAND_BLOCK_MINECART,
"MINECART_TNT", "PLAYER", "PRIMED_TNT", "SLIME", "SMALL_FIREBALL", "SNOWBALL", "MINECART_FURNACE", "SPLASH_POTION", SPAWNER_MINECART, TNT_MINECART, PLAYER, TNT, SLIME, SMALL_FIREBALL, SNOWBALL, FURNACE_MINECART, SPLASH_POTION,
"THROWN_EXP_BOTTLE", "WITHER_SKULL", "UNKNOWN", "SPECTRAL_ARROW", "SHULKER_BULLET", "DRAGON_FIREBALL", "AREA_EFFECT_CLOUD", EXPERIENCE_BOTTLE, WITHER_SKULL, UNKNOWN, SPECTRAL_ARROW, SHULKER_BULLET, DRAGON_FIREBALL, AREA_EFFECT_CLOUD,
"TRIDENT", "LLAMA_SPIT" -> { TRIDENT, LLAMA_SPIT -> {
// Do this stuff later // Do this stuff later
return;
} }
// MISC // // MISC //
case "DROPPED_ITEM", "ITEM" -> { case ITEM -> {
Item item = (Item) entity; Item item = (Item) entity;
this.stack = item.getItemStack(); this.stack = item.getItemStack();
return;
} }
case "ITEM_FRAME" -> { case ITEM_FRAME, GLOW_ITEM_FRAME -> {
this.x = Math.floor(this.getX()); this.x = Math.floor(this.getX());
this.y = Math.floor(this.getY()); this.y = Math.floor(this.getY());
this.z = Math.floor(this.getZ()); this.z = Math.floor(this.getZ());
ItemFrame itemFrame = (ItemFrame) entity; ItemFrame itemFrame = (ItemFrame) entity;
this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation()); this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation());
this.stack = itemFrame.getItem().clone(); this.stack = itemFrame.getItem().clone();
return;
} }
case "PAINTING" -> { case PAINTING -> {
this.x = Math.floor(this.getX()); this.x = Math.floor(this.getX());
this.y = Math.floor(this.getY()); this.y = Math.floor(this.getY());
this.z = Math.floor(this.getZ()); this.z = Math.floor(this.getZ());
@@ -150,18 +148,16 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.y -= 1; this.y -= 1;
} }
this.dataString = art.name(); this.dataString = art.name();
return;
} }
// END MISC // // END MISC //
// INVENTORY HOLDER // // INVENTORY HOLDER //
case "MINECART_CHEST", "CHEST_MINECART", "MINECART_HOPPER", "HOPPER_MINECART" -> { case CHEST_MINECART, HOPPER_MINECART -> {
storeInventory((InventoryHolder) entity); storeInventory((InventoryHolder) entity);
return;
} }
// START LIVING ENTITY // // START LIVING ENTITY //
// START AGEABLE // // START AGEABLE //
// START TAMEABLE // // START TAMEABLE //
case "CAMEL", "HORSE", "DONKEY", "LLAMA", "TRADER_LLAMA", "MULE", "SKELETON_HORSE", "ZOMBIE_HORSE" -> { case CAMEL, HORSE, DONKEY, LLAMA, TRADER_LLAMA, MULE, SKELETON_HORSE, ZOMBIE_HORSE -> {
AbstractHorse horse = (AbstractHorse) entity; AbstractHorse horse = (AbstractHorse) entity;
this.horse = new HorseStats(); this.horse = new HorseStats();
this.horse.jump = horse.getJumpStrength(); this.horse.jump = horse.getJumpStrength();
@@ -176,17 +172,15 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
storeBreedable(horse); storeBreedable(horse);
storeLiving(horse); storeLiving(horse);
storeInventory(horse); storeInventory(horse);
return;
} }
// END INVENTORY HOLDER // // END INVENTORY HOLDER //
case "WOLF", "OCELOT", "CAT", "PARROT" -> { case WOLF, OCELOT, CAT, PARROT -> {
storeTameable((Tameable) entity); storeTameable((Tameable) entity);
storeBreedable((Breedable) entity); storeBreedable((Breedable) entity);
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return;
} }
// END TAMEABLE // // END TAMEABLE //
case "SHEEP" -> { case SHEEP -> {
Sheep sheep = (Sheep) entity; Sheep sheep = (Sheep) entity;
if (sheep.isSheared()) { if (sheep.isSheared()) {
this.dataByte = (byte) 1; this.dataByte = (byte) 1;
@@ -196,21 +190,18 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.dataByte2 = getOrdinal(DyeColor.values(), sheep.getColor()); this.dataByte2 = getOrdinal(DyeColor.values(), sheep.getColor());
storeBreedable(sheep); storeBreedable(sheep);
storeLiving(sheep); storeLiving(sheep);
return;
} }
case "VILLAGER", "CHICKEN", "COW", "MUSHROOM_COW", "PIG", "TURTLE", "POLAR_BEAR" -> { case VILLAGER, CHICKEN, COW, MOOSHROOM, PIG, TURTLE, POLAR_BEAR -> {
storeBreedable((Breedable) entity); storeBreedable((Breedable) entity);
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return;
} }
case "RABBIT" -> { case RABBIT -> {
this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType()); this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType());
storeBreedable((Breedable) entity); storeBreedable((Breedable) entity);
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return;
} }
// END AGEABLE // // END AGEABLE //
case "ARMOR_STAND" -> { case ARMOR_STAND -> {
ArmorStand stand = (ArmorStand) entity; ArmorStand stand = (ArmorStand) entity;
this.inventory = this.inventory =
new ItemStack[]{stand.getItemInHand().clone(), stand.getHelmet().clone(), new ItemStack[]{stand.getItemInHand().clone(), stand.getHelmet().clone(),
@@ -254,31 +245,26 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (stand.isSmall()) { if (stand.isSmall()) {
this.stand.small = true; this.stand.small = true;
} }
return;
} }
case "ENDERMITE" -> { case ENDERMITE -> {
return;
} }
case "BAT" -> { case BAT -> {
if (((Bat) entity).isAwake()) { if (((Bat) entity).isAwake()) {
this.dataByte = (byte) 1; this.dataByte = (byte) 1;
} else { } else {
this.dataByte = (byte) 0; this.dataByte = (byte) 0;
} }
return;
} }
case "ENDER_DRAGON" -> { case ENDER_DRAGON -> {
EnderDragon entity1 = (EnderDragon) entity; EnderDragon entity1 = (EnderDragon) entity;
this.dataByte = (byte) entity1.getPhase().ordinal(); this.dataByte = (byte) entity1.getPhase().ordinal();
return;
} }
case "SKELETON", "WITHER_SKELETON", "GUARDIAN", "ELDER_GUARDIAN", "GHAST", "HAPPY_GHAST", "GHASTLING", "MAGMA_CUBE", "SQUID", "PIG_ZOMBIE", "HOGLIN", case SKELETON, WITHER_SKELETON, GUARDIAN, ELDER_GUARDIAN, GHAST, HAPPY_GHAST, MAGMA_CUBE,
"ZOMBIFIED_PIGLIN", "PIGLIN", "PIGLIN_BRUTE", "ZOMBIE", "WITHER", "WITCH", "SPIDER", "CAVE_SPIDER", "SILVERFISH", SQUID, HOGLIN, ZOMBIFIED_PIGLIN, PIGLIN, PIGLIN_BRUTE, ZOMBIE, WITHER, WITCH, SPIDER, CAVE_SPIDER, SILVERFISH,
"GIANT", "ENDERMAN", "CREEPER", "BLAZE", "SHULKER", "SNOWMAN", "SNOW_GOLEM" -> { GIANT, ENDERMAN, CREEPER, BLAZE, SHULKER, SNOW_GOLEM -> {
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return;
} }
case "IRON_GOLEM" -> { case IRON_GOLEM -> {
if (((IronGolem) entity).isPlayerCreated()) { if (((IronGolem) entity).isPlayerCreated()) {
this.dataByte = (byte) 1; this.dataByte = (byte) 1;
} else { } else {
@@ -390,8 +376,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
} }
/** /**
* @deprecated Use {@link #restoreBreedable(Breedable)} instead
* @since 7.1.0 * @since 7.1.0
* @deprecated Use {@link #restoreBreedable(Breedable)} instead
*/ */
@Deprecated(forRemoval = true, since = "7.1.0") @Deprecated(forRemoval = true, since = "7.1.0")
private void restoreAgeable(Ageable entity) { private void restoreAgeable(Ageable entity) {
@@ -405,8 +391,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
} }
/** /**
* @deprecated Use {@link #storeBreedable(Breedable)} instead
* @since 7.1.0 * @since 7.1.0
* @deprecated Use {@link #storeBreedable(Breedable)} instead
*/ */
@Deprecated(forRemoval = true, since = "7.1.0") @Deprecated(forRemoval = true, since = "7.1.0")
public void storeAgeable(Ageable aged) { public void storeAgeable(Ageable aged) {
@@ -455,16 +441,17 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
return null; return null;
} }
Entity entity; Entity entity;
switch (this.getType().toString()) { switch (this.getType()) {
case "DROPPED_ITEM", "ITEM" -> { case ITEM -> {
return world.dropItem(location, this.stack); return world.dropItem(location, this.stack);
} }
case "PLAYER", "LEASH_HITCH" -> { case PLAYER, LEASH_KNOT -> {
return null; return null;
} }
case "ITEM_FRAME" -> entity = world.spawn(location, ItemFrame.class); case ITEM_FRAME -> entity = world.spawn(location, ItemFrame.class);
case "PAINTING" -> entity = world.spawn(location, Painting.class); case GLOW_ITEM_FRAME -> entity = world.spawn(location, GlowItemFrame.class);
default -> entity = world.spawnEntity(location, this.getType()); case PAINTING -> entity = world.spawn(location, Painting.class);
default -> entity = world.spawnEntity(location, Objects.requireNonNull(this.getType().bukkitType()));
} }
if (this.depth == 0) { if (this.depth == 0) {
return entity; return entity;
@@ -491,16 +478,16 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (this.noGravity) { if (this.noGravity) {
entity.setGravity(false); entity.setGravity(false);
} }
switch (entity.getType().toString()) { switch (EntityType.of(entity.getType())) {
case "BOAT", "ACACIA_BOAT", "BIRCH_BOAT", "CHERRY_BOAT", "DARK_OAK_BOAT", "JUNGLE_BOAT", "MANGROVE_BOAT", case ACACIA_BOAT, BIRCH_BOAT, CHERRY_BOAT, DARK_OAK_BOAT, JUNGLE_BOAT, MANGROVE_BOAT,
"OAK_BOAT", "PALE_OAK_BOAT", "SPRUCE_BOAT", "BAMBOO_RAFT" -> { OAK_BOAT, PALE_OAK_BOAT, SPRUCE_BOAT, BAMBOO_RAFT -> {
Boat boat = (Boat) entity; Boat boat = (Boat) entity;
boat.setBoatType(Boat.Type.values()[dataByte]); boat.setBoatType(Boat.Type.values()[dataByte]);
return entity; return entity;
} }
case "ACACIA_CHEST_BOAT", "BIRCH_CHEST_BOAT", "CHERRY_CHEST_BOAT", "DARK_OAK_CHEST_BOAT", case ACACIA_CHEST_BOAT, BIRCH_CHEST_BOAT, CHERRY_CHEST_BOAT, DARK_OAK_CHEST_BOAT,
"JUNGLE_CHEST_BOAT", "MANGROVE_CHEST_BOAT", "OAK_CHEST_BOAT", "PALE_OAK_CHEST_BOAT", JUNGLE_CHEST_BOAT, MANGROVE_CHEST_BOAT, OAK_CHEST_BOAT, PALE_OAK_CHEST_BOAT,
"SPRUCE_CHEST_BOAT", "BAMBOO_CHEST_RAFT" -> { SPRUCE_CHEST_BOAT, BAMBOO_CHEST_RAFT -> {
ChestBoat boat = (ChestBoat) entity; ChestBoat boat = (ChestBoat) entity;
boat.setBoatType(Boat.Type.values()[dataByte]); boat.setBoatType(Boat.Type.values()[dataByte]);
restoreInventory(boat); restoreInventory(boat);
@@ -511,22 +498,22 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
((Slime) entity).setSize(this.dataByte); ((Slime) entity).setSize(this.dataByte);
return entity; return entity;
} */ } */
case "ARROW", "EGG", "END_CRYSTAL", "ENDER_CRYSTAL", "ENDER_PEARL", "ENDER_SIGNAL", "DROPPED_ITEM", "EXPERIENCE_ORB", "FALLING_BLOCK", case ARROW, EGG, END_CRYSTAL, ENDER_PEARL, EYE_OF_ENDER, ITEM, EXPERIENCE_ORB, FALLING_BLOCK, FIREBALL,
"FIREBALL", "FIREWORK", "FISHING_HOOK", "LEASH_HITCH", "LIGHTNING", "MINECART", "MINECART_COMMAND", FIREWORK_ROCKET, FISHING_BOBBER, LEASH_KNOT, LIGHTNING_BOLT, MINECART, COMMAND_BLOCK_MINECART, SPAWNER_MINECART,
"MINECART_MOB_SPAWNER", "MINECART_TNT", "PLAYER", "PRIMED_TNT", "SMALL_FIREBALL", "SNOWBALL", TNT_MINECART, PLAYER, TNT, SMALL_FIREBALL, SNOWBALL, SPLASH_POTION, EXPERIENCE_BOTTLE, SPECTRAL_ARROW,
"SPLASH_POTION", "THROWN_EXP_BOTTLE", "SPECTRAL_ARROW", "SHULKER_BULLET", "AREA_EFFECT_CLOUD", SHULKER_BULLET, AREA_EFFECT_CLOUD, DRAGON_FIREBALL, WITHER_SKULL, FURNACE_MINECART, LLAMA_SPIT, TRIDENT,
"DRAGON_FIREBALL", "WITHER_SKULL", "MINECART_FURNACE", "LLAMA_SPIT", "TRIDENT", "UNKNOWN" -> { UNKNOWN -> {
// Do this stuff later // Do this stuff later
return entity; return entity;
} }
// MISC // // MISC //
case "ITEM_FRAME" -> { case ITEM_FRAME, GLOW_ITEM_FRAME -> {
ItemFrame itemframe = (ItemFrame) entity; ItemFrame itemframe = (ItemFrame) entity;
itemframe.setRotation(Rotation.values()[this.dataByte]); itemframe.setRotation(Rotation.values()[this.dataByte]);
itemframe.setItem(this.stack); itemframe.setItem(this.stack);
return entity; return entity;
} }
case "PAINTING" -> { case PAINTING -> {
Painting painting = (Painting) entity; Painting painting = (Painting) entity;
painting.setFacingDirection(BlockFace.values()[this.dataByte], true); painting.setFacingDirection(BlockFace.values()[this.dataByte], true);
painting.setArt(Art.getByName(this.dataString), true); painting.setArt(Art.getByName(this.dataString), true);
@@ -534,14 +521,14 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
} }
// END MISC // // END MISC //
// INVENTORY HOLDER // // INVENTORY HOLDER //
case "MINECART_CHEST", "CHEST_MINECART", "MINECART_HOPPER", "HOPPER_MINECART" -> { case CHEST_MINECART, HOPPER_MINECART -> {
restoreInventory((InventoryHolder) entity); restoreInventory((InventoryHolder) entity);
return entity; return entity;
} }
// START LIVING ENTITY // // START LIVING ENTITY //
// START AGEABLE // // START AGEABLE //
// START TAMEABLE // // START TAMEABLE //
case "CAMEL", "HORSE", "DONKEY", "LLAMA", "TRADER_LLAMA", "MULE", "SKELETON_HORSE", "ZOMBIE_HORSE" -> { case CAMEL, HORSE, DONKEY, LLAMA, TRADER_LLAMA, MULE, SKELETON_HORSE, ZOMBIE_HORSE -> {
AbstractHorse horse = (AbstractHorse) entity; AbstractHorse horse = (AbstractHorse) entity;
horse.setJumpStrength(this.horse.jump); horse.setJumpStrength(this.horse.jump);
if (horse instanceof ChestedHorse) { if (horse instanceof ChestedHorse) {
@@ -558,14 +545,14 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
return entity; return entity;
} }
// END INVENTORY HOLDER // // END INVENTORY HOLDER //
case "WOLF", "OCELOT", "CAT", "PARROT" -> { case WOLF, OCELOT, CAT, PARROT -> {
restoreTameable((Tameable) entity); restoreTameable((Tameable) entity);
restoreBreedable((Breedable) entity); restoreBreedable((Breedable) entity);
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
} }
// END AGEABLE // // END AGEABLE //
case "SHEEP" -> { case SHEEP -> {
Sheep sheep = (Sheep) entity; Sheep sheep = (Sheep) entity;
if (this.dataByte == 1) { if (this.dataByte == 1) {
sheep.setSheared(true); sheep.setSheared(true);
@@ -577,13 +564,13 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
restoreLiving(sheep); restoreLiving(sheep);
return sheep; return sheep;
} }
case "VILLAGER", "CHICKEN", "COW", "TURTLE", "POLAR_BEAR", "MUSHROOM_COW", "PIG" -> { case VILLAGER, CHICKEN, COW, TURTLE, POLAR_BEAR, MOOSHROOM, PIG -> {
restoreBreedable((Breedable) entity); restoreBreedable((Breedable) entity);
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
} }
// END AGEABLE // // END AGEABLE //
case "RABBIT" -> { case RABBIT -> {
if (this.dataByte != 0) { if (this.dataByte != 0) {
((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]); ((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]);
} }
@@ -591,7 +578,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
} }
case "ARMOR_STAND" -> { case ARMOR_STAND -> {
// CHECK positions // CHECK positions
ArmorStand stand = (ArmorStand) entity; ArmorStand stand = (ArmorStand) entity;
if (this.inventory[0] != null) { if (this.inventory[0] != null) {
@@ -610,41 +597,27 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
stand.setBoots(this.inventory[4]); stand.setBoots(this.inventory[4]);
} }
if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) { if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) {
EulerAngle pose = EulerAngle pose = new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
stand.setHeadPose(pose); stand.setHeadPose(pose);
} }
if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) { if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) {
EulerAngle pose = EulerAngle pose = new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
stand.setBodyPose(pose); stand.setBodyPose(pose);
} }
if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0 if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0 || this.stand.leftLeg[2] != 0) {
|| this.stand.leftLeg[2] != 0) { EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1], this.stand.leftLeg[2]);
EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1],
this.stand.leftLeg[2]
);
stand.setLeftLegPose(pose); stand.setLeftLegPose(pose);
} }
if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0 if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0 || this.stand.rightLeg[2] != 0) {
|| this.stand.rightLeg[2] != 0) { EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1], this.stand.rightLeg[2]);
EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1],
this.stand.rightLeg[2]
);
stand.setRightLegPose(pose); stand.setRightLegPose(pose);
} }
if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0 if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0 || this.stand.leftArm[2] != 0) {
|| this.stand.leftArm[2] != 0) { EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1], this.stand.leftArm[2]);
EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1],
this.stand.leftArm[2]
);
stand.setLeftArmPose(pose); stand.setLeftArmPose(pose);
} }
if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0 if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0 || this.stand.rightArm[2] != 0) {
|| this.stand.rightArm[2] != 0) { EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1], this.stand.rightArm[2]);
EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1],
this.stand.rightArm[2]
);
stand.setRightArmPose(pose); stand.setRightArmPose(pose);
} }
if (this.stand.invisible) { if (this.stand.invisible) {
@@ -662,25 +635,28 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
restoreLiving(stand); restoreLiving(stand);
return stand; return stand;
} }
case "BAT" -> { case BAT -> {
if (this.dataByte != 0) { if (this.dataByte != 0) {
((Bat) entity).setAwake(true); ((Bat) entity).setAwake(true);
} }
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
} }
case "ENDER_DRAGON" -> { case ENDER_DRAGON -> {
if (this.dataByte != 0) { if (this.dataByte != 0) {
((EnderDragon) entity).setPhase(EnderDragon.Phase.values()[this.dataByte]); ((EnderDragon) entity).setPhase(EnderDragon.Phase.values()[this.dataByte]);
} }
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
} }
case "ENDERMITE", "GHAST", "HAPPY_GHAST", "GHASTLING", "MAGMA_CUBE", "SQUID", "PIG_ZOMBIE", "HOGLIN", "PIGLIN", "ZOMBIFIED_PIGLIN", "PIGLIN_BRUTE", "ZOMBIE", "WITHER", "WITCH", "SPIDER", "CAVE_SPIDER", "SILVERFISH", "GIANT", "ENDERMAN", "CREEPER", "BLAZE", "SNOWMAN", "SHULKER", "GUARDIAN", "ELDER_GUARDIAN", "SKELETON", "WITHER_SKELETON" -> { case ENDERMITE, GHAST, HAPPY_GHAST, MAGMA_CUBE, SQUID, HOGLIN, PIGLIN,
ZOMBIFIED_PIGLIN, PIGLIN_BRUTE, ZOMBIE, WITHER, WITCH, SPIDER, CAVE_SPIDER, SILVERFISH, GIANT,
ENDERMAN, CREEPER, BLAZE, SNOW_GOLEM, SHULKER, GUARDIAN, ELDER_GUARDIAN, SKELETON,
WITHER_SKELETON -> {
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
} }
case "IRON_GOLEM" -> { case IRON_GOLEM -> {
if (this.dataByte != 0) { if (this.dataByte != 0) {
((IronGolem) entity).setPlayerCreated(true); ((IronGolem) entity).setPlayerCreated(true);
} }

View File

@@ -20,6 +20,7 @@ package com.plotsquared.bukkit.listener;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.bukkit.entity.EntityType;
import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitEntityUtil; import com.plotsquared.bukkit.util.BukkitEntityUtil;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
@@ -52,7 +53,6 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Ageable; import org.bukkit.entity.Ageable;
import org.bukkit.entity.Boat; import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock; import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
@@ -148,8 +148,8 @@ public class EntityEventListener implements Listener {
if (area == null) { if (area == null) {
return; return;
} }
// Armour-stands are handled elsewhere and should not be handled by area-wide entity-spawn options // Armor-stands are handled elsewhere and should not be handled by area-wide entity-spawn options
if (entity.getType() == EntityType.ARMOR_STAND) { if (EntityType.of(event.getEntityType()) == EntityType.ARMOR_STAND) {
return; return;
} }
CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason(); CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
@@ -212,7 +212,7 @@ public class EntityEventListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityFall(EntityChangeBlockEvent event) { public void onEntityFall(EntityChangeBlockEvent event) {
if (event.getEntityType() != EntityType.FALLING_BLOCK) { if (EntityType.of(event.getEntityType()) != EntityType.FALLING_BLOCK) {
return; return;
} }
Block block = event.getBlock(); Block block = event.getBlock();
@@ -278,7 +278,7 @@ public class EntityEventListener implements Listener {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onDamage(EntityDamageEvent event) { public void onDamage(EntityDamageEvent event) {
if (event.getEntityType() != EntityType.PLAYER) { if (EntityType.of(event.getEntityType()) != EntityType.PLAYER) {
return; return;
} }
Location location = BukkitUtil.adapt(event.getEntity().getLocation()); Location location = BukkitUtil.adapt(event.getEntity().getLocation());

View File

@@ -18,6 +18,7 @@
*/ */
package com.plotsquared.bukkit.listener; package com.plotsquared.bukkit.listener;
import com.plotsquared.bukkit.entity.EntityType;
import com.plotsquared.bukkit.util.BukkitEntityUtil; import com.plotsquared.bukkit.util.BukkitEntityUtil;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
@@ -33,7 +34,6 @@ import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EnderCrystal; import org.bukkit.entity.EnderCrystal;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Vehicle; import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -84,6 +84,7 @@ public class EntitySpawnListener implements Listener {
public static void test(Entity entity) { public static void test(Entity entity) {
@NonNull World world = entity.getWorld(); @NonNull World world = entity.getWorld();
List<MetadataValue> meta = entity.getMetadata(KEY); List<MetadataValue> meta = entity.getMetadata(KEY);
final EntityType entityType = EntityType.of(entity);
if (meta.isEmpty()) { if (meta.isEmpty()) {
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) { if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) {
entity.setMetadata(KEY, new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation())); entity.setMetadata(KEY, new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation()));
@@ -94,7 +95,7 @@ public class EntitySpawnListener implements Listener {
if (!originWorld.equals(world)) { if (!originWorld.equals(world)) {
if (!ignoreTP) { if (!ignoreTP) {
if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) { if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) {
if (entity.getType() == EntityType.PLAYER) { if (entityType == EntityType.PLAYER) {
return; return;
} }
try { try {
@@ -108,7 +109,7 @@ public class EntitySpawnListener implements Listener {
} }
} }
} else { } else {
if (entity.getType() == EntityType.PLAYER) { if (entityType == EntityType.PLAYER) {
return; return;
} }
entity.remove(); entity.remove();
@@ -132,7 +133,7 @@ public class EntitySpawnListener implements Listener {
} }
} }
Plot plot = location.getOwnedPlotAbs(); Plot plot = location.getOwnedPlotAbs();
EntityType type = entity.getType(); EntityType type = EntityType.of(entity);
if (plot == null) { if (plot == null) {
if (entity instanceof Item) { if (entity instanceof Item) {
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) { if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
@@ -201,15 +202,16 @@ public class EntitySpawnListener implements Listener {
final PlotArea fromArea = fromLocLocation.getPlotArea(); final PlotArea fromArea = fromLocLocation.getPlotArea();
Location toLocLocation = BukkitUtil.adapt(toLocation.getLocation()); Location toLocLocation = BukkitUtil.adapt(toLocation.getLocation());
PlotArea toArea = toLocLocation.getPlotArea(); PlotArea toArea = toLocLocation.getPlotArea();
final EntityType entityType = EntityType.of(entity);
if (toArea == null) { if (toArea == null) {
if (fromLocation.getType() == EntityType.SHULKER && fromArea != null) { if (entityType == EntityType.SHULKER && fromArea != null) {
event.setCancelled(true); event.setCancelled(true);
} }
return; return;
} }
Plot toPlot = toArea.getOwnedPlot(toLocLocation); Plot toPlot = toArea.getOwnedPlot(toLocLocation);
if (fromLocation.getType() == EntityType.SHULKER && fromArea != null) { if (entityType == EntityType.SHULKER && fromArea != null) {
final Plot fromPlot = fromArea.getOwnedPlot(fromLocLocation); final Plot fromPlot = fromArea.getOwnedPlot(fromLocLocation);
if (fromPlot != null || toPlot != null) { if (fromPlot != null || toPlot != null) {
@@ -231,7 +233,7 @@ public class EntitySpawnListener implements Listener {
@EventHandler @EventHandler
public void spawn(CreatureSpawnEvent event) { public void spawn(CreatureSpawnEvent event) {
if (event.getEntityType() == EntityType.ARMOR_STAND) { if (EntityType.of(event.getEntityType()) == EntityType.ARMOR_STAND) {
testCreate(event.getEntity()); testCreate(event.getEntity());
} }
} }

View File

@@ -28,6 +28,7 @@ import com.destroystokyo.paper.event.entity.SlimePathfindEvent;
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent; import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent; import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.plotsquared.bukkit.entity.EntityType;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.command.Command; import com.plotsquared.core.command.Command;
@@ -55,11 +56,9 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.TileState; import org.bukkit.block.TileState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
@@ -84,9 +83,6 @@ import java.util.regex.Pattern;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class PaperListener implements Listener { 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 final PlotAreaManager plotAreaManager;
private Chunk lastChunk; private Chunk lastChunk;
@@ -182,8 +178,9 @@ public class PaperListener implements Listener {
if (area == null) { if (area == null) {
return; return;
} }
// Armour-stands are handled elsewhere and should not be handled by area-wide entity-spawn options final EntityType entityType = EntityType.of(event.getType());
if (event.getType() == EntityType.ARMOR_STAND) { // Armor-stands are handled elsewhere and should not be handled by area-wide entity-spawn options
if (entityType == EntityType.ARMOR_STAND) {
return; return;
} }
// If entities are spawning... the chunk should be loaded? // If entities are spawning... the chunk should be loaded?
@@ -202,7 +199,8 @@ public class PaperListener implements Listener {
return; return;
} }
} }
case "REINFORCEMENTS", "NATURAL", "MOUNT", "PATROL", "RAID", "SILVERFISH_BLOCK", "ENDER_PEARL", "TRAP", "VILLAGE_DEFENSE", "VILLAGE_INVASION", "BEEHIVE", "CHUNK_GEN" -> { case "REINFORCEMENTS", "NATURAL", "MOUNT", "PATROL", "RAID", "SILVERFISH_BLOCK", "ENDER_PEARL", "TRAP",
"VILLAGE_DEFENSE", "VILLAGE_INVASION", "BEEHIVE", "CHUNK_GEN" -> {
if (!area.isMobSpawning()) { if (!area.isMobSpawning()) {
event.setShouldAbortSpawn(true); event.setShouldAbortSpawn(true);
event.setCancelled(true); event.setCancelled(true);
@@ -233,24 +231,23 @@ public class PaperListener implements Listener {
} }
Plot plot = location.getOwnedPlotAbs(); Plot plot = location.getOwnedPlotAbs();
if (plot == null) { if (plot == null) {
EntityType type = event.getType();
// PreCreatureSpawnEvent **should** not be called for DROPPED_ITEM, just for the sake of consistency // PreCreatureSpawnEvent **should** not be called for DROPPED_ITEM, just for the sake of consistency
if (type.getKey().equals(ITEM)) { if (entityType == EntityType.ITEM) {
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) { if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
event.setCancelled(true); event.setCancelled(true);
} }
return; return;
} }
if (!area.isMobSpawning()) { if (!area.isMobSpawning()) {
if (type == EntityType.PLAYER) { if (entityType == EntityType.PLAYER) {
return; return;
} }
if (type.isAlive()) { if (entityType.isAlive()) {
event.setShouldAbortSpawn(true); event.setShouldAbortSpawn(true);
event.setCancelled(true); event.setCancelled(true);
} }
} }
if (!area.isMiscSpawnUnowned() && !type.isAlive()) { if (!area.isMiscSpawnUnowned() && !entityType.isAlive()) {
event.setShouldAbortSpawn(true); event.setShouldAbortSpawn(true);
event.setCancelled(true); event.setCancelled(true);
} }
@@ -322,6 +319,7 @@ public class PaperListener implements Listener {
return; return;
} }
Projectile entity = event.getProjectile(); Projectile entity = event.getProjectile();
EntityType entityType = EntityType.of(entity);
ProjectileSource shooter = entity.getShooter(); ProjectileSource shooter = entity.getShooter();
if (!(shooter instanceof Player)) { if (!(shooter instanceof Player)) {
return; return;
@@ -361,7 +359,7 @@ public class PaperListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (!plot.isAdded(pp.getUUID())) { } else if (!plot.isAdded(pp.getUUID())) {
if (entity.getType().getKey().equals(FISHING_BOBBER)) { if (entityType == EntityType.FISHING_BOBBER) {
if (plot.getFlag(FishingFlag.class)) { if (plot.getFlag(FishingFlag.class)) {
return; return;
} }

View File

@@ -21,6 +21,7 @@ package com.plotsquared.bukkit.listener;
import com.destroystokyo.paper.MaterialTags; import com.destroystokyo.paper.MaterialTags;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.plotsquared.bukkit.entity.EntityType;
import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitEntityUtil; import com.plotsquared.bukkit.util.BukkitEntityUtil;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
@@ -79,7 +80,6 @@ import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.task.TaskTime; import com.plotsquared.core.util.task.TaskTime;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.Enums;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
@@ -98,7 +98,6 @@ import org.bukkit.command.PluginCommand;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Boat; import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@@ -160,7 +159,6 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@@ -186,14 +184,6 @@ public class PlayerEventListener implements Listener {
Material.WRITTEN_BOOK Material.WRITTEN_BOOK
); );
/**
* The correct EntityType for End Crystal, determined once at class loading time.
* Tries END_CRYSTAL first (1.21+), falls back to ENDER_CRYSTAL (1.20.4 and older).
*/
private static final EntityType END_CRYSTAL_ENTITY_TYPE = Objects.requireNonNull(
Enums.findByValue(EntityType.class, "END_CRYSTAL", "ENDER_CRYSTAL")
);
private static final Set<String> DYES; private static final Set<String> DYES;
static { static {
@@ -1328,7 +1318,7 @@ public class PlayerEventListener implements Listener {
// reset the player's hand item if spawning needs to be cancelled. // reset the player's hand item if spawning needs to be cancelled.
if (type == Material.ARMOR_STAND || type == Material.END_CRYSTAL) { if (type == Material.ARMOR_STAND || type == Material.END_CRYSTAL) {
Plot plot = location.getOwnedPlotAbs(); Plot plot = location.getOwnedPlotAbs();
EntityType entityType = type == Material.ARMOR_STAND ? EntityType.ARMOR_STAND : END_CRYSTAL_ENTITY_TYPE; EntityType entityType = type == Material.ARMOR_STAND ? EntityType.ARMOR_STAND : EntityType.END_CRYSTAL;
if (BukkitEntityUtil.checkEntity(entityType, plot)) { if (BukkitEntityUtil.checkEntity(entityType, plot)) {
event.setCancelled(true); event.setCancelled(true);
break; break;
@@ -1709,7 +1699,7 @@ public class PlayerEventListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (event.getRightClicked().getType() == EntityType.UNKNOWN) { if (EntityType.of(event.getRightClicked().getType()) == EntityType.UNKNOWN) {
return; return;
} }
Location location = BukkitUtil.adapt(event.getRightClicked().getLocation()); Location location = BukkitUtil.adapt(event.getRightClicked().getLocation());

View File

@@ -18,6 +18,7 @@
*/ */
package com.plotsquared.bukkit.util; package com.plotsquared.bukkit.util;
import com.plotsquared.bukkit.entity.EntityType;
import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
@@ -48,7 +49,6 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import org.bukkit.entity.Creature; import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework; import org.bukkit.entity.Firework;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
@@ -189,7 +189,7 @@ public class BukkitEntityUtil {
); );
return false; return false;
} }
} else if (victim.getType() == EntityType.ARMOR_STAND) { } else if (EntityType.of(victim.getType()) == EntityType.ARMOR_STAND) {
if (plot != null && (plot.getFlag(MiscBreakFlag.class) || plot if (plot != null && (plot.getFlag(MiscBreakFlag.class) || plot
.isAdded(plotPlayer.getUUID()))) { .isAdded(plotPlayer.getUUID()))) {
return true; return true;
@@ -354,7 +354,7 @@ public class BukkitEntityUtil {
} }
public static boolean checkEntity(Entity entity, Plot plot) { public static boolean checkEntity(Entity entity, Plot plot) {
return checkEntity(entity.getType(), plot); return checkEntity(EntityType.of(entity.getType()), plot);
} }
public static boolean checkEntity(EntityType type, Plot plot) { public static boolean checkEntity(EntityType type, Plot plot) {
@@ -364,7 +364,7 @@ public class BukkitEntityUtil {
} }
final com.sk89q.worldedit.world.entity.EntityType entityType = final com.sk89q.worldedit.world.entity.EntityType entityType =
BukkitAdapter.adapt(type); BukkitAdapter.adapt(type.bukkitType());
if (EntityCategories.PLAYER.contains(entityType)) { if (EntityCategories.PLAYER.contains(entityType)) {
return false; return false;