Implement playerfilter api

This commit is contained in:
fullwall 2023-04-17 01:47:32 +08:00
parent 5ef99250e4
commit 71ecc7086b
30 changed files with 431 additions and 42 deletions

View File

@ -236,11 +236,7 @@
<relocation>
<pattern>net.byteflux.libby</pattern>
<shadedPattern>clib.net.byteflux.libby</shadedPattern>
</relocation>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>net.citizensnpcs.util.metrics</shadedPattern>
</relocation>
</relocation>
</relocations>
</configuration>
</execution>

View File

@ -486,7 +486,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
Skin.clearCache();
getServer().getPluginManager().callEvent(new CitizensPreReloadEvent());
saves.reloadFromSource();
saves.loadInto(npcRegistry);

View File

@ -85,6 +85,7 @@ import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.event.NPCLeftClickEvent;
import net.citizensnpcs.api.event.NPCRemoveEvent;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.event.NPCSpawnEvent;
import net.citizensnpcs.api.event.NPCVehicleDamageEvent;
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
@ -92,6 +93,7 @@ import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.api.trait.trait.PlayerFilter;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.npc.skin.SkinUpdateTracker;
@ -382,6 +384,13 @@ public class EventListen implements Listener {
toRespawn.values().remove(event.getNPC());
}
@EventHandler(ignoreCancelled = true)
public void onNPCSeenByPlayer(NPCSeenByPlayerEvent event) {
if (event.getNPC().hasTrait(PlayerFilter.class)) {
event.setCancelled(event.getNPC().getOrAddTrait(PlayerFilter.class).onSeenByPlayer(event.getPlayer()));
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onNPCSpawn(NPCSpawnEvent event) {
skinUpdateTracker.onNPCSpawn(event.getNPC());

View File

@ -64,6 +64,8 @@ import net.citizensnpcs.trait.WolfModifiers;
import net.citizensnpcs.trait.WoolColor;
import net.citizensnpcs.trait.text.Text;
import net.citizensnpcs.trait.waypoint.Waypoints;
import net.citizensnpcs.util.EntityPacketTracker;
import net.citizensnpcs.util.NMS;
public class CitizensTraitFactory implements TraitFactory {
private final List<TraitInfo> defaultTraits = Lists.newArrayList();
@ -98,7 +100,17 @@ public class CitizensTraitFactory implements TraitFactory {
registerTrait(TraitInfo.create(Owner.class));
registerTrait(TraitInfo.create(PacketNPC.class));
registerTrait(TraitInfo.create(PausePathfindingTrait.class));
registerTrait(TraitInfo.create(PlayerFilter.class));
registerTrait(TraitInfo.create(PlayerFilter.class).withSupplier(() -> new PlayerFilter((p, e) -> {
EntityPacketTracker ept = NMS.getPacketTracker(e);
if (ept != null) {
ept.unlink(p);
}
}, (p, e) -> {
EntityPacketTracker ept = NMS.getPacketTracker(e);
if (ept != null) {
ept.link(p);
}
})));
registerTrait(TraitInfo.create(Poses.class));
registerTrait(TraitInfo.create(Powered.class));
registerTrait(TraitInfo.create(RabbitType.class));

View File

@ -335,7 +335,6 @@ public class HologramTrait extends Trait {
continue;
line.setText(text);
hologramNPC.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, npc.getRawName().length() > 0);
}
}
@ -438,12 +437,15 @@ public class HologramTrait extends Trait {
this.text = text;
if (hologram != null) {
hologram.setName(Placeholders.replace(text, null, npc));
String name = Placeholders.replace(text, null, npc);
hologram.setName(name);
hologram.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, ChatColor.stripColor(name).length() > 0);
}
}
public void spawnNPC(double height) {
this.hologram = createHologram(Placeholders.replace(text, null, npc), height);
String name = Placeholders.replace(text, null, npc);
this.hologram = createHologram(name, height);
}
}

View File

@ -26,6 +26,10 @@ public class PacketNPC extends Trait {
super("packet");
}
public EntityPacketTracker getPacketTracker() {
return packetTracker;
}
@Override
public void onRemove() {
npc.despawn(DespawnReason.PENDING_RESPAWN);

View File

@ -52,7 +52,9 @@ import net.citizensnpcs.api.util.EntityDim;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator;
import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.trait.PacketNPC;
import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose;
import net.citizensnpcs.trait.versioned.SnifferTrait.SnifferState;
import net.citizensnpcs.util.EntityPacketTracker.PacketAggregator;
@ -441,6 +443,19 @@ public class NMS {
return BRIDGE.getNPC(entity);
}
public static EntityPacketTracker getPacketTracker(Entity entity) {
if (entity == null)
return null;
if (entity instanceof NPCHolder) {
NPC npc = ((NPCHolder) entity).getNPC();
if (npc.hasTrait(PacketNPC.class))
return npc.getOrAddTrait(PacketNPC.class).getPacketTracker();
}
if (!entity.isValid())
return null;
return BRIDGE.getPacketTracker(entity);
}
public static List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
return BRIDGE.getPassengers(entity);
}

View File

@ -59,7 +59,7 @@ public interface NMSBridge {
return packets;
}
public EntityPacketTracker createPacketTracker(Entity entity, PacketAggregator agg);
public EntityPacketTracker createPacketTracker(Entity entity, PacketAggregator agg);;
public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Throwable;
@ -87,6 +87,8 @@ public interface NMSBridge {
public NPC getNPC(Entity entity);
public EntityPacketTracker getPacketTracker(Entity entity);
public List<Entity> getPassengers(Entity entity);
public GameProfile getProfile(Player player);
@ -146,9 +148,9 @@ public interface NMSBridge {
public void remove(Entity entity);
public void removeFromServerPlayerList(Player player);
public void removeFromServerPlayerList(Player player);;
public void removeFromWorld(org.bukkit.entity.Entity entity);;
public void removeFromWorld(org.bukkit.entity.Entity entity);
public void removeHookIfNecessary(NPCRegistry npcRegistry, FishHook entity);
@ -167,15 +169,15 @@ public interface NMSBridge {
public void sendTeamPacket(Player recipient, Team team, int mode);
default public void setAggressive(Entity entity, boolean aggro) {
}
};
public default void setAllayDancing(Entity entity, boolean dancing) {
throw new UnsupportedOperationException();
}
};
public void setBodyYaw(Entity entity, float yaw);;
public void setBoundingBox(Entity entity, BoundingBox box);;
public void setBoundingBox(Entity entity, BoundingBox box);
public default void setCamelPose(Entity entity, CamelPose pose) {
throw new UnsupportedOperationException();
@ -183,7 +185,7 @@ public interface NMSBridge {
public void setCustomName(Entity entity, Object component, String string);
public void setDestination(Entity entity, double x, double y, double z, float speed);;
public void setDestination(Entity entity, double x, double y, double z, float speed);
public void setDimensions(Entity entity, EntityDim desired);

View File

@ -506,6 +506,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((EntityPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.clear((EntityPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.a();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity);

View File

@ -2,9 +2,11 @@ package net.citizensnpcs.nms.v1_10_R1.util;
import java.lang.reflect.Field;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -29,9 +31,14 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
if (entityplayer instanceof EntityHumanNPC)
return;
Entity tracker = getTracker(this);
if ((tracker instanceof NPCHolder
&& ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity())) || tracker.dead
|| tracker.getBukkitEntity().getType() != EntityType.PLAYER)
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
}
if (tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
return;
if (entityplayer != tracker && c(entityplayer)) {
if (!this.trackedPlayers.contains(entityplayer)

View File

@ -527,6 +527,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((EntityPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.clear((EntityPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.a();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity);

View File

@ -2,9 +2,11 @@ package net.citizensnpcs.nms.v1_11_R1.util;
import java.lang.reflect.Field;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_11_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -29,9 +31,14 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
if (entityplayer instanceof EntityHumanNPC)
return;
Entity tracker = getTracker(this);
if ((tracker instanceof NPCHolder
&& ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity())) || tracker.dead
|| tracker.getBukkitEntity().getType() != EntityType.PLAYER)
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
}
if (tracker.dead || tracker.getBukkitEntity().getType() != EntityType.PLAYER)
return;
if (entityplayer != tracker && c(entityplayer)) {
if (!this.trackedPlayers.contains(entityplayer)

View File

@ -532,6 +532,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((EntityPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.clear((EntityPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.a();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity);

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -56,7 +57,9 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
public void updatePlayer(final EntityPlayer entityplayer) {
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
if (npc.isHiddenFrom(entityplayer.getBukkitEntity()))
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
Integer trackingRange = npc.data().<Integer> get(NPC.Metadata.TRACKING_RANGE);
if (TRACKING_RANGE_SETTER != null && trackingRange != null

View File

@ -556,6 +556,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((EntityPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.clear((EntityPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.a();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity);

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_13_R2.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -55,7 +56,9 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
public void updatePlayer(final EntityPlayer entityplayer) {
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
if (npc.isHiddenFrom(entityplayer.getBukkitEntity()))
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
Integer trackingRange = npc.data().<Integer> get(NPC.Metadata.TRACKING_RANGE);
if (TRACKING_RANGE_SETTER != null && trackingRange != null

View File

@ -592,6 +592,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
EntityTracker entry = server.getChunkProvider().playerChunkMap.trackedEntities.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((EntityPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.clear((EntityPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.a();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity);

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -50,7 +51,9 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
public void updatePlayer(final EntityPlayer entityplayer) {
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
if (npc.isHiddenFrom(entityplayer.getBukkitEntity()))
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
Integer trackingRange = npc.data().<Integer> get(NPC.Metadata.TRACKING_RANGE);
if (TRACKING_RANGE_SETTER != null && trackingRange != null

View File

@ -607,6 +607,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
EntityTracker entry = server.getChunkProvider().playerChunkMap.trackedEntities.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((EntityPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.clear((EntityPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.a();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity);

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -50,7 +51,9 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
public void updatePlayer(final EntityPlayer entityplayer) {
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
if (npc.isHiddenFrom(entityplayer.getBukkitEntity()))
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
Integer trackingRange = npc.data().<Integer> get(NPC.Metadata.TRACKING_RANGE);
if (TRACKING_RANGE_SETTER != null && trackingRange != null

View File

@ -623,6 +623,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
EntityTracker entry = server.getChunkProvider().playerChunkMap.trackedEntities.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((EntityPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.clear((EntityPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.a();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity);

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -52,7 +53,9 @@ public class PlayerlistTracker extends PlayerChunkMap.EntityTracker {
public void updatePlayer(final EntityPlayer entityplayer) {
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
if (npc.isHiddenFrom(entityplayer.getBukkitEntity()))
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
Integer trackingRange = npc.data().<Integer> get(NPC.Metadata.TRACKING_RANGE);
if (TRACKING_RANGE_SETTER != null && trackingRange != null

View File

@ -633,6 +633,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
ServerLevel server = (ServerLevel) getHandle(entity).level;
TrackedEntity entry = server.getChunkProvider().chunkMap.G.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((ServerPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.removePlayer((ServerPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.broadcastRemoved();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity);

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -53,7 +54,9 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
public void updatePlayer(final ServerPlayer entityplayer) {
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
if (npc.isHiddenFrom(entityplayer.getBukkitEntity()))
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
Integer trackingRange = npc.data().<Integer> get(NPC.Metadata.TRACKING_RANGE);
if (TRACKING_RANGE_SETTER != null && trackingRange != null

View File

@ -639,6 +639,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
ServerLevel server = (ServerLevel) getHandle(entity).level;
TrackedEntity entry = server.getChunkSource().chunkMap.entityMap.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((ServerPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.removePlayer((ServerPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.broadcastRemoved();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity);
@ -1241,11 +1269,9 @@ public class NMSImpl implements NMSBridge {
float oldPitch = handle.getXRot();
handle.setYBodyRot(bodyYaw);
handle.setXRot(pitch);
sendPacketsNearby(null, from.getLocation(), new ClientboundTeleportEntityPacket(handle), // new
// ClientboundMoveEntityPacket.Rot(handle.getId(),
// (byte) (bodyYaw *
// 256.0F / 360.0F),
// (byte) (pitch * 256.0F / 360.0F), handle.onGround),
sendPacketsNearby(null, from.getLocation(), new ClientboundTeleportEntityPacket(handle),
// newClientboundMoveEntityPacket.Rot(handle.getId(), (byte) (bodyYaw *256.0F / 360.0F), (byte) (pitch *
// 256.0F / 360.0F), handle.onGround),
new ClientboundRotateHeadPacket(handle, (byte) (headYaw * 256.0F / 360.0F)));
handle.setYBodyRot(oldBody);
handle.setXRot(oldPitch);

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -53,7 +54,9 @@ public class PlayerlistTracker extends ChunkMap.TrackedEntity {
public void updatePlayer(final ServerPlayer entityplayer) {
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
if (npc.isHiddenFrom(entityplayer.getBukkitEntity()))
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
Integer trackingRange = npc.data().<Integer> get(NPC.Metadata.TRACKING_RANGE);
if (TRACKING_RANGE_SETTER != null && trackingRange != null

View File

@ -11,6 +11,7 @@ import com.google.common.collect.ForwardingSet;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_19_R3.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -74,9 +75,14 @@ public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
@Override
public void updatePlayer(final ServerPlayer entityplayer) {
if (entityplayer instanceof EntityHumanNPC)
return;
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
if (npc.isHiddenFrom(entityplayer.getBukkitEntity()))
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
Integer trackingRange = npc.data().<Integer> get(NPC.Metadata.TRACKING_RANGE);
if (TRACKING_RANGE_SETTER != null && trackingRange != null
@ -90,9 +96,6 @@ public class CitizensEntityTracker extends ChunkMap.TrackedEntity {
}
}
if (entityplayer instanceof EntityHumanNPC)
return;
super.updatePlayer(entityplayer);
}

View File

@ -671,6 +671,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
ServerLevel server = (ServerLevel) getHandle(entity).level;
TrackedEntity entry = server.getChunkSource().chunkMap.entityMap.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((ServerPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.removePlayer((ServerPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.broadcastRemoved();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity);
@ -2476,7 +2504,6 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle ADVANCEMENTS_PLAYER_SETTER = NMS.getFirstFinalSetter(ServerPlayer.class,
PlayerAdvancements.class);
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class);
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFirstFinalSetter(AttributeSupplier.class,
Map.class);

View File

@ -460,6 +460,34 @@ public class NMSImpl implements NMSBridge {
return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null;
}
@Override
public EntityPacketTracker getPacketTracker(org.bukkit.entity.Entity entity) {
WorldServer server = (WorldServer) NMSImpl.getHandle(entity).getWorld();
EntityTrackerEntry entry = server.getTracker().trackedEntities.get(entity.getEntityId());
if (entry == null)
return null;
return new EntityPacketTracker() {
@Override
public void link(Player player) {
entry.updatePlayer((EntityPlayer) getHandle(player));
}
@Override
public void run() {
}
@Override
public void unlink(Player player) {
entry.clear((EntityPlayer) getHandle(player));
}
@Override
public void unlinkAll(Consumer<Player> callback) {
entry.a();
}
};
}
@Override
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity passenger = NMSImpl.getHandle(entity).passenger;

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCSeenByPlayerEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
@ -52,9 +53,15 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
@Override
public void updatePlayer(final EntityPlayer entityplayer) {
// prevent updates to NPC "viewers"
if ((entityplayer instanceof EntityHumanNPC) || (tracker instanceof NPCHolder
&& ((NPCHolder) tracker).getNPC().isHiddenFrom(entityplayer.getBukkitEntity())))
if (entityplayer instanceof EntityHumanNPC)
return;
if (tracker instanceof NPCHolder) {
NPC npc = ((NPCHolder) tracker).getNPC();
NPCSeenByPlayerEvent event = new NPCSeenByPlayerEvent(npc, entityplayer.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
}
lastUpdatedPlayer = entityplayer;
super.updatePlayer(entityplayer);
lastUpdatedPlayer = null;