2023-03-14 20:37:05 +01:00
|
|
|
package net.citizensnpcs.nms.v1_19_R3.entity;
|
2022-06-08 05:58:22 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.lang.invoke.MethodHandle;
|
|
|
|
import java.util.List;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2022-06-08 05:58:22 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
2023-03-14 20:37:05 +01:00
|
|
|
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
|
2022-06-08 05:58:22 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.metadata.MetadataValue;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import org.bukkit.util.Vector;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2022-06-08 05:58:22 +02:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2022-06-08 05:58:22 +02:00
|
|
|
import net.citizensnpcs.Settings.Setting;
|
|
|
|
import net.citizensnpcs.api.CitizensAPI;
|
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
2023-01-01 08:26:35 +01:00
|
|
|
import net.citizensnpcs.api.npc.NPC.NPCUpdate;
|
2022-06-08 05:58:22 +02:00
|
|
|
import net.citizensnpcs.api.trait.trait.Inventory;
|
2022-07-07 17:34:15 +02:00
|
|
|
import net.citizensnpcs.api.util.SpigotUtil;
|
2023-03-14 20:37:05 +01:00
|
|
|
import net.citizensnpcs.nms.v1_19_R3.network.EmptyNetHandler;
|
|
|
|
import net.citizensnpcs.nms.v1_19_R3.network.EmptyNetworkManager;
|
|
|
|
import net.citizensnpcs.nms.v1_19_R3.util.EmptyAdvancementDataPlayer;
|
|
|
|
import net.citizensnpcs.nms.v1_19_R3.util.EmptyServerStatsCounter;
|
2023-03-19 14:48:40 +01:00
|
|
|
import net.citizensnpcs.nms.v1_19_R3.util.MobAI;
|
|
|
|
import net.citizensnpcs.nms.v1_19_R3.util.MobAI.ForwardingMobAI;
|
2023-03-14 20:37:05 +01:00
|
|
|
import net.citizensnpcs.nms.v1_19_R3.util.NMSImpl;
|
2022-06-08 05:58:22 +02:00
|
|
|
import net.citizensnpcs.npc.CitizensNPC;
|
|
|
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
|
|
|
import net.citizensnpcs.npc.skin.SkinPacketTracker;
|
|
|
|
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
|
|
|
import net.citizensnpcs.trait.Gravity;
|
|
|
|
import net.citizensnpcs.trait.SkinTrait;
|
|
|
|
import net.citizensnpcs.util.NMS;
|
|
|
|
import net.citizensnpcs.util.Util;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.network.chat.Component;
|
|
|
|
import net.minecraft.network.chat.MutableComponent;
|
|
|
|
import net.minecraft.network.chat.contents.LiteralContents;
|
|
|
|
import net.minecraft.network.protocol.PacketFlow;
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
import net.minecraft.server.level.ServerLevel;
|
|
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
|
|
import net.minecraft.server.level.ServerPlayerGameMode;
|
2022-06-24 06:43:23 +02:00
|
|
|
import net.minecraft.sounds.SoundEvent;
|
2022-06-08 05:58:22 +02:00
|
|
|
import net.minecraft.stats.ServerStatsCounter;
|
2022-11-13 13:54:06 +01:00
|
|
|
import net.minecraft.tags.TagKey;
|
2022-06-08 05:58:22 +02:00
|
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
import net.minecraft.world.level.GameType;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
2022-11-13 13:54:06 +01:00
|
|
|
import net.minecraft.world.level.material.Fluid;
|
2022-11-10 14:31:32 +01:00
|
|
|
import net.minecraft.world.phys.AABB;
|
2022-06-08 05:58:22 +02:00
|
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
|
2023-03-19 14:48:40 +01:00
|
|
|
public class EntityHumanNPC extends ServerPlayer implements NPCHolder, SkinnableEntity, ForwardingMobAI {
|
|
|
|
private MobAI ai;
|
2022-06-08 05:58:22 +02:00
|
|
|
private int jumpTicks = 0;
|
|
|
|
private final CitizensNPC npc;
|
2022-07-22 09:22:55 +02:00
|
|
|
private boolean setBukkitEntity;
|
2022-06-08 05:58:22 +02:00
|
|
|
private final SkinPacketTracker skinTracker;
|
|
|
|
private EmptyServerStatsCounter statsCache;
|
|
|
|
|
2022-12-08 16:21:09 +01:00
|
|
|
public EntityHumanNPC(MinecraftServer minecraftServer, ServerLevel world, GameProfile gameProfile, NPC npc) {
|
|
|
|
super(minecraftServer, world, gameProfile);
|
2022-06-08 05:58:22 +02:00
|
|
|
this.npc = (CitizensNPC) npc;
|
|
|
|
if (npc != null) {
|
2023-03-19 14:48:40 +01:00
|
|
|
ai = new BasicMobAI(this);
|
2022-06-08 05:58:22 +02:00
|
|
|
skinTracker = new SkinPacketTracker(this);
|
|
|
|
try {
|
|
|
|
GAMEMODE_SETTING.invoke(gameMode, GameType.SURVIVAL, null);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
initialise(minecraftServer);
|
|
|
|
} else {
|
|
|
|
skinTracker = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean causeFallDamage(float f, float f1, DamageSource damagesource) {
|
2023-11-05 09:35:22 +01:00
|
|
|
if (npc == null || !npc.isFlyable())
|
2022-06-08 05:58:22 +02:00
|
|
|
return super.causeFallDamage(f, f1, damagesource);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void checkFallDamage(double d0, boolean flag, BlockState iblockdata, BlockPos blockposition) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
super.checkFallDamage(d0, flag, iblockdata, blockposition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void die(DamageSource damagesource) {
|
|
|
|
// players that die are not normally removed from the world. when the
|
|
|
|
// NPC dies, we are done with the instance and it should be removed.
|
2023-11-05 09:35:22 +01:00
|
|
|
if (dead)
|
2022-06-08 05:58:22 +02:00
|
|
|
return;
|
|
|
|
super.die(damagesource);
|
2023-03-26 20:52:56 +02:00
|
|
|
Bukkit.getScheduler().runTaskLater(CitizensAPI.getPlugin(), () -> {
|
|
|
|
EntityHumanNPC.this.getLevel().removePlayerImmediately(EntityHumanNPC.this, RemovalReason.KILLED);
|
|
|
|
((ServerLevel) level).getChunkSource().removeEntity(EntityHumanNPC.this);
|
2022-06-08 05:58:22 +02:00
|
|
|
}, 15); // give enough time for death and smoke animation
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void doTick() {
|
|
|
|
if (npc == null) {
|
|
|
|
super.doTick();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.baseTick();
|
2023-03-19 14:48:40 +01:00
|
|
|
boolean navigating = npc.getNavigator().isNavigating() || ai.getMoveControl().hasWanted();
|
2022-06-08 05:58:22 +02:00
|
|
|
if (!navigating && getBukkitEntity() != null
|
|
|
|
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
|
2022-07-07 17:34:15 +02:00
|
|
|
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))
|
2023-10-01 11:27:38 +02:00
|
|
|
&& (!npc.isProtected() || SpigotUtil.checkYSafe(getY(), getBukkitEntity().getWorld()))) {
|
2022-06-08 05:58:22 +02:00
|
|
|
moveWithFallDamage(Vec3.ZERO);
|
|
|
|
}
|
|
|
|
Vec3 mot = getDeltaMovement();
|
|
|
|
if (Math.abs(mot.x) < EPSILON && Math.abs(mot.y) < EPSILON && Math.abs(mot.z) < EPSILON) {
|
|
|
|
setDeltaMovement(Vec3.ZERO);
|
|
|
|
}
|
|
|
|
if (navigating) {
|
2023-03-19 14:48:40 +01:00
|
|
|
if (!ai.getNavigation().isDone()) {
|
|
|
|
ai.getNavigation().tick();
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
moveOnCurrentHeading();
|
|
|
|
}
|
2023-03-19 14:48:40 +01:00
|
|
|
tickAI();
|
2023-04-10 18:10:45 +02:00
|
|
|
detectEquipmentUpdates();
|
|
|
|
noPhysics = isSpectator();
|
2022-06-08 05:58:22 +02:00
|
|
|
if (isSpectator()) {
|
|
|
|
this.onGround = false;
|
|
|
|
}
|
2023-05-03 19:20:57 +02:00
|
|
|
|
|
|
|
pushEntities();
|
|
|
|
|
2023-02-26 08:51:59 +01:00
|
|
|
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
|
2022-11-10 14:31:32 +01:00
|
|
|
AABB axisalignedbb;
|
|
|
|
if (this.isPassenger() && !this.getVehicle().isRemoved()) {
|
|
|
|
axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0);
|
|
|
|
} else {
|
|
|
|
axisalignedbb = this.getBoundingBox().inflate(1.0, 0.5, 1.0);
|
|
|
|
}
|
|
|
|
for (Entity entity : this.level.getEntities(this, axisalignedbb)) {
|
|
|
|
entity.playerTouch(this);
|
|
|
|
}
|
|
|
|
}
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
|
2023-03-19 14:48:40 +01:00
|
|
|
@Override
|
|
|
|
public MobAI getAI() {
|
|
|
|
return ai;
|
|
|
|
}
|
|
|
|
|
2022-06-08 05:58:22 +02:00
|
|
|
@Override
|
|
|
|
public CraftPlayer getBukkitEntity() {
|
2022-07-22 09:22:55 +02:00
|
|
|
if (npc != null && !setBukkitEntity) {
|
2022-06-08 05:58:22 +02:00
|
|
|
NMSImpl.setBukkitEntity(this, new PlayerNPC(this));
|
2022-07-22 09:22:55 +02:00
|
|
|
setBukkitEntity = true;
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
return super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
2022-06-24 06:43:23 +02:00
|
|
|
@Override
|
|
|
|
protected SoundEvent getDeathSound() {
|
2023-01-01 08:26:35 +01:00
|
|
|
return NMSImpl.getSoundEffect(npc, super.getDeathSound(), NPC.Metadata.DEATH_SOUND);
|
2022-06-24 06:43:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SoundEvent getHurtSound(DamageSource damagesource) {
|
2023-01-01 08:26:35 +01:00
|
|
|
return NMSImpl.getSoundEffect(npc, super.getHurtSound(damagesource), NPC.Metadata.HURT_SOUND);
|
2022-06-24 06:43:23 +02:00
|
|
|
}
|
|
|
|
|
2022-06-08 05:58:22 +02:00
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GameProfile getProfile() {
|
|
|
|
return super.getGameProfile();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getSkinName() {
|
|
|
|
String skinName = npc.getOrAddTrait(SkinTrait.class).getSkinName();
|
|
|
|
if (skinName == null) {
|
|
|
|
skinName = npc.getName();
|
|
|
|
}
|
|
|
|
return skinName.toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SkinPacketTracker getSkinTracker() {
|
|
|
|
return skinTracker;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ServerStatsCounter getStats() {
|
|
|
|
return this.statsCache == null ? statsCache = new EmptyServerStatsCounter() : statsCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Component getTabListDisplayName() {
|
2023-11-05 09:35:22 +01:00
|
|
|
if (Setting.DISABLE_TABLIST.asBoolean())
|
2022-06-08 05:58:22 +02:00
|
|
|
return MutableComponent.create(new LiteralContents(""));
|
|
|
|
return super.getTabListDisplayName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hurt(DamageSource damagesource, float f) {
|
|
|
|
// knock back velocity is cancelled and sent to client for handling when
|
|
|
|
// the entity is a player. there is no client so make this happen
|
|
|
|
// manually.
|
|
|
|
boolean damaged = super.hurt(damagesource, f);
|
|
|
|
if (damaged && hurtMarked) {
|
|
|
|
hurtMarked = false;
|
2023-11-05 09:35:22 +01:00
|
|
|
Bukkit.getScheduler().runTask(CitizensAPI.getPlugin(), (Runnable) () -> EntityHumanNPC.this.hurtMarked = true);
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
return damaged;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initialise(MinecraftServer minecraftServer) {
|
|
|
|
try {
|
2023-10-01 11:27:38 +02:00
|
|
|
EmptyNetworkManager conn = new EmptyNetworkManager(PacketFlow.CLIENTBOUND);
|
2022-06-08 05:58:22 +02:00
|
|
|
connection = new EmptyNetHandler(minecraftServer, conn, this);
|
|
|
|
conn.setListener(connection);
|
|
|
|
} catch (IOException e) {
|
|
|
|
}
|
|
|
|
this.invulnerableTime = 0;
|
|
|
|
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
|
|
|
|
setSkinFlags((byte) 0xFF);
|
|
|
|
EmptyAdvancementDataPlayer.clear(this.getAdvancements());
|
|
|
|
NMSImpl.setAdvancement(this.getBukkitEntity(),
|
|
|
|
new EmptyAdvancementDataPlayer(minecraftServer.getFixerUpper(), minecraftServer.getPlayerList(),
|
|
|
|
minecraftServer.getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isInWall() {
|
2023-11-05 09:35:22 +01:00
|
|
|
if (npc == null || noPhysics || isSleeping())
|
2022-06-08 05:58:22 +02:00
|
|
|
return super.isInWall();
|
|
|
|
return Util.inBlock(getBukkitEntity());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPushable() {
|
2023-01-01 08:26:35 +01:00
|
|
|
return npc == null ? super.isPushable() : npc.data().<Boolean> get(NPC.Metadata.COLLIDABLE, !npc.isProtected());
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
|
2022-11-13 16:33:18 +01:00
|
|
|
@Override
|
|
|
|
public void knockback(double strength, double dx, double dz) {
|
2023-11-05 09:35:22 +01:00
|
|
|
NMS.callKnockbackEvent(npc, (float) strength, dx, dz, evt -> super.knockback((float) evt.getStrength(),
|
2023-06-12 15:20:51 +02:00
|
|
|
evt.getKnockbackVector().getX(), evt.getKnockbackVector().getZ()));
|
2022-11-13 16:33:18 +01:00
|
|
|
}
|
|
|
|
|
2022-06-08 05:58:22 +02:00
|
|
|
private void moveOnCurrentHeading() {
|
|
|
|
if (jumping) {
|
|
|
|
if (onGround && jumpTicks == 0) {
|
|
|
|
jumpFromGround();
|
|
|
|
jumpTicks = 10;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
jumpTicks = 0;
|
|
|
|
}
|
|
|
|
xxa *= 0.98F;
|
|
|
|
zza *= 0.98F;
|
|
|
|
moveWithFallDamage(new Vec3(this.xxa, this.yya, this.zza));
|
|
|
|
NMS.setHeadYaw(getBukkitEntity(), getYRot());
|
|
|
|
if (jumpTicks > 0) {
|
|
|
|
jumpTicks--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void moveWithFallDamage(Vec3 vec) {
|
|
|
|
double y = getY();
|
|
|
|
travel(vec);
|
|
|
|
if (!npc.isProtected()) {
|
|
|
|
doCheckFallDamage(getY() - y, onGround);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onClimbable() {
|
2023-11-05 09:35:22 +01:00
|
|
|
if (npc == null || !npc.isFlyable())
|
2022-06-08 05:58:22 +02:00
|
|
|
return super.onClimbable();
|
2023-11-05 09:35:22 +01:00
|
|
|
else
|
2022-06-08 05:58:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void push(double x, double y, double z) {
|
|
|
|
Vector vector = Util.callPushEvent(npc, x, y, z);
|
|
|
|
if (vector != null) {
|
|
|
|
super.push(vector.getX(), vector.getY(), vector.getZ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void push(Entity entity) {
|
|
|
|
// this method is called by both the entities involved - cancelling
|
|
|
|
// it will not stop the NPC from moving.
|
|
|
|
super.push(entity);
|
|
|
|
if (npc != null) {
|
|
|
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove(RemovalReason reason) {
|
|
|
|
super.remove(reason);
|
|
|
|
getAdvancements().save();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSkinFlags(byte flags) {
|
2022-12-03 11:21:46 +01:00
|
|
|
getEntityData().set(net.minecraft.world.entity.player.Player.DATA_PLAYER_MODE_CUSTOMISATION, flags);
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSkinName(String name) {
|
|
|
|
npc.getOrAddTrait(SkinTrait.class).setSkinName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSkinName(String name, boolean forceUpdate) {
|
|
|
|
npc.getOrAddTrait(SkinTrait.class).setSkinName(name, forceUpdate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSkinPersistent(String skinName, String signature, String data) {
|
|
|
|
npc.getOrAddTrait(SkinTrait.class).setSkinPersistent(skinName, signature, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void tick() {
|
|
|
|
super.tick();
|
|
|
|
if (npc == null)
|
|
|
|
return;
|
|
|
|
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", getBukkitEntity());
|
|
|
|
updatePackets(npc.getNavigator().isNavigating());
|
|
|
|
npc.update();
|
|
|
|
}
|
|
|
|
|
2023-03-19 14:48:40 +01:00
|
|
|
@Override
|
|
|
|
public void tickAI() {
|
|
|
|
ai.getMoveControl().tick();
|
|
|
|
ai.getJumpControl().tick();
|
|
|
|
}
|
|
|
|
|
2022-06-08 05:58:22 +02:00
|
|
|
@Override
|
|
|
|
public void travel(Vec3 vec3d) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
super.travel(vec3d);
|
|
|
|
} else {
|
|
|
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-13 13:54:06 +01:00
|
|
|
@Override
|
|
|
|
public boolean updateFluidHeightAndDoFluidPushing(TagKey<Fluid> tagkey, double d0) {
|
|
|
|
Vec3 old = getDeltaMovement().add(0, 0, 0);
|
|
|
|
boolean res = super.updateFluidHeightAndDoFluidPushing(tagkey, d0);
|
|
|
|
if (!npc.isPushableByFluids()) {
|
|
|
|
setDeltaMovement(old);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-06-08 05:58:22 +02:00
|
|
|
private void updatePackets(boolean navigating) {
|
2023-01-01 08:26:35 +01:00
|
|
|
if (!npc.isUpdating(NPCUpdate.PACKET))
|
2022-06-08 05:58:22 +02:00
|
|
|
return;
|
2023-03-30 17:13:38 +02:00
|
|
|
|
2023-01-01 08:26:35 +01:00
|
|
|
effectsDirty = true;
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class PlayerNPC extends CraftPlayer implements NPCHolder, SkinnableEntity {
|
|
|
|
private final CitizensNPC npc;
|
|
|
|
|
|
|
|
private PlayerNPC(EntityHumanNPC entity) {
|
|
|
|
super((CraftServer) Bukkit.getServer(), entity);
|
|
|
|
this.npc = entity.npc;
|
|
|
|
npc.getOrAddTrait(Inventory.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canSee(org.bukkit.entity.Entity entity) {
|
2023-11-05 09:35:22 +01:00
|
|
|
if (entity != null && entity.getType().name().contains("ITEM_FRAME"))
|
2022-06-08 05:58:22 +02:00
|
|
|
return false; // optimise for large maps in item frames
|
|
|
|
return super.canSee(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Player getBukkitEntity() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EntityHumanNPC getHandle() {
|
|
|
|
return (EntityHumanNPC) this.entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<MetadataValue> getMetadata(String metadataKey) {
|
2022-07-22 09:22:55 +02:00
|
|
|
return ((CraftServer) Bukkit.getServer()).getEntityMetadata().getMetadata(this, metadataKey);
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getSkinName() {
|
|
|
|
return ((SkinnableEntity) this.entity).getSkinName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SkinPacketTracker getSkinTracker() {
|
|
|
|
return ((SkinnableEntity) this.entity).getSkinTracker();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasMetadata(String metadataKey) {
|
2022-07-22 09:22:55 +02:00
|
|
|
return ((CraftServer) Bukkit.getServer()).getEntityMetadata().hasMetadata(this, metadataKey);
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
|
2022-07-22 09:22:55 +02:00
|
|
|
((CraftServer) Bukkit.getServer()).getEntityMetadata().removeMetadata(this, metadataKey, owningPlugin);
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
|
2022-07-22 09:22:55 +02:00
|
|
|
((CraftServer) Bukkit.getServer()).getEntityMetadata().setMetadata(this, metadataKey, newMetadataValue);
|
2022-06-08 05:58:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSkinFlags(byte flags) {
|
|
|
|
((SkinnableEntity) this.entity).setSkinFlags(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSkinName(String name) {
|
|
|
|
((SkinnableEntity) this.entity).setSkinName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSkinName(String skinName, boolean forceUpdate) {
|
|
|
|
((SkinnableEntity) this.entity).setSkinName(skinName, forceUpdate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSkinPersistent(String skinName, String signature, String data) {
|
|
|
|
((SkinnableEntity) this.entity).setSkinPersistent(skinName, signature, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final float EPSILON = 0.003F;
|
|
|
|
private static final MethodHandle GAMEMODE_SETTING = NMS.getFirstMethodHandle(ServerPlayerGameMode.class, true,
|
|
|
|
GameType.class, GameType.class);
|
|
|
|
private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0);
|
|
|
|
}
|