Add hideEntity / showEntity API
This commit is contained in:
parent
7e2214dafd
commit
37fd1917e7
@ -133,7 +133,7 @@
|
|||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.range = i;
|
this.range = i;
|
||||||
this.lastSectionPos = SectionPosition.of(entity);
|
this.lastSectionPos = SectionPosition.of(entity);
|
||||||
@@ -1435,12 +1479,20 @@
|
@@ -1435,12 +1479,17 @@
|
||||||
|
|
||||||
public void updatePlayer(EntityPlayer entityplayer) {
|
public void updatePlayer(EntityPlayer entityplayer) {
|
||||||
if (entityplayer != this.entity) {
|
if (entityplayer != this.entity) {
|
||||||
@ -145,12 +145,9 @@
|
|||||||
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(entityplayer);
|
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(entityplayer);
|
||||||
|
|
||||||
+ // CraftBukkit start - respect vanish API
|
+ // CraftBukkit start - respect vanish API
|
||||||
+ if (this.entity instanceof EntityPlayer) {
|
+ if (!entityplayer.getBukkitEntity().canSee(this.entity.getBukkitEntity())) {
|
||||||
+ Player player = ((EntityPlayer) this.entity).getBukkitEntity();
|
|
||||||
+ if (!entityplayer.getBukkitEntity().canSee(player)) {
|
|
||||||
+ flag = false;
|
+ flag = false;
|
||||||
+ }
|
+ }
|
||||||
+ }
|
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
if (flag) {
|
if (flag) {
|
||||||
if (this.seenBy.add(entityplayer.connection)) {
|
if (this.seenBy.add(entityplayer.connection)) {
|
||||||
|
@ -399,7 +399,7 @@
|
|||||||
double d2 = (double) blockposition.getZ() - entityplayer.getZ();
|
double d2 = (double) blockposition.getZ() - entityplayer.getZ();
|
||||||
|
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) {
|
+ if (entityhuman != null && !entityplayer.getBukkitEntity().canSee(entityhuman.getBukkitEntity())) {
|
||||||
+ continue;
|
+ continue;
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
|
@ -598,7 +598,7 @@
|
|||||||
+ public void broadcastAll(Packet packet, EntityHuman entityhuman) {
|
+ public void broadcastAll(Packet packet, EntityHuman entityhuman) {
|
||||||
+ for (int i = 0; i < this.players.size(); ++i) {
|
+ for (int i = 0; i < this.players.size(); ++i) {
|
||||||
+ EntityPlayer entityplayer = this.players.get(i);
|
+ EntityPlayer entityplayer = this.players.get(i);
|
||||||
+ if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) {
|
+ if (entityhuman != null && !entityplayer.getBukkitEntity().canSee(entityhuman.getBukkitEntity())) {
|
||||||
+ continue;
|
+ continue;
|
||||||
+ }
|
+ }
|
||||||
+ ((EntityPlayer) this.players.get(i)).connection.send(packet);
|
+ ((EntityPlayer) this.players.get(i)).connection.send(packet);
|
||||||
@ -638,7 +638,7 @@
|
|||||||
EntityPlayer entityplayer = (EntityPlayer) this.players.get(i);
|
EntityPlayer entityplayer = (EntityPlayer) this.players.get(i);
|
||||||
|
|
||||||
+ // CraftBukkit start - Test if player receiving packet can see the source of the packet
|
+ // CraftBukkit start - Test if player receiving packet can see the source of the packet
|
||||||
+ if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) {
|
+ if (entityhuman != null && !entityplayer.getBukkitEntity().canSee(entityhuman.getBukkitEntity())) {
|
||||||
+ continue;
|
+ continue;
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
|
@ -144,7 +144,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||||||
private boolean hasPlayedBefore = false;
|
private boolean hasPlayedBefore = false;
|
||||||
private final ConversationTracker conversationTracker = new ConversationTracker();
|
private final ConversationTracker conversationTracker = new ConversationTracker();
|
||||||
private final Set<String> channels = new HashSet<String>();
|
private final Set<String> channels = new HashSet<String>();
|
||||||
private final Map<UUID, Set<WeakReference<Plugin>>> hiddenPlayers = new HashMap<>();
|
private final Map<UUID, Set<WeakReference<Plugin>>> hiddenEntities = new HashMap<>();
|
||||||
private static final WeakHashMap<Plugin, WeakReference<Plugin>> pluginWeakReferences = new WeakHashMap<>();
|
private static final WeakHashMap<Plugin, WeakReference<Plugin>> pluginWeakReferences = new WeakHashMap<>();
|
||||||
private int hash = 0;
|
private int hash = 0;
|
||||||
private double health = 20;
|
private double health = 20;
|
||||||
@ -1057,94 +1057,115 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void hidePlayer(Player player) {
|
public void hidePlayer(Player player) {
|
||||||
hidePlayer0(null, player);
|
hideEntity0(null, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void hidePlayer(Plugin plugin, Player player) {
|
public void hidePlayer(Plugin plugin, Player player) {
|
||||||
|
hideEntity(plugin, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hideEntity(Plugin plugin, org.bukkit.entity.Entity entity) {
|
||||||
Validate.notNull(plugin, "Plugin cannot be null");
|
Validate.notNull(plugin, "Plugin cannot be null");
|
||||||
Validate.isTrue(plugin.isEnabled(), "Plugin attempted to hide player while disabled");
|
Validate.isTrue(plugin.isEnabled(), "Plugin attempted to hide player while disabled");
|
||||||
|
|
||||||
hidePlayer0(plugin, player);
|
hideEntity0(plugin, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hidePlayer0(@Nullable Plugin plugin, Player player) {
|
private void hideEntity0(@Nullable Plugin plugin, org.bukkit.entity.Entity entity) {
|
||||||
Validate.notNull(player, "hidden player cannot be null");
|
Validate.notNull(entity, "hidden entity cannot be null");
|
||||||
if (getHandle().connection == null) return;
|
if (getHandle().connection == null) return;
|
||||||
if (equals(player)) return;
|
if (equals(entity)) return;
|
||||||
|
|
||||||
Set<WeakReference<Plugin>> hidingPlugins = hiddenPlayers.get(player.getUniqueId());
|
Set<WeakReference<Plugin>> hidingPlugins = hiddenEntities.get(entity.getUniqueId());
|
||||||
if (hidingPlugins != null) {
|
if (hidingPlugins != null) {
|
||||||
// Some plugins are already hiding the player. Just mark that this
|
// Some plugins are already hiding the entity. Just mark that this
|
||||||
// plugin wants the player hidden too and end.
|
// plugin wants the entity hidden too and end.
|
||||||
hidingPlugins.add(getPluginWeakReference(plugin));
|
hidingPlugins.add(getPluginWeakReference(plugin));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hidingPlugins = new HashSet<>();
|
hidingPlugins = new HashSet<>();
|
||||||
hidingPlugins.add(getPluginWeakReference(plugin));
|
hidingPlugins.add(getPluginWeakReference(plugin));
|
||||||
hiddenPlayers.put(player.getUniqueId(), hidingPlugins);
|
hiddenEntities.put(entity.getUniqueId(), hidingPlugins);
|
||||||
|
|
||||||
// Remove this player from the hidden player's EntityTrackerEntry
|
// Remove this entity from the hidden player's EntityTrackerEntry
|
||||||
PlayerChunkMap tracker = ((WorldServer) entity.level).getChunkSource().chunkMap;
|
PlayerChunkMap tracker = ((WorldServer) getHandle().level).getChunkSource().chunkMap;
|
||||||
EntityPlayer other = ((CraftPlayer) player).getHandle();
|
Entity other = ((CraftEntity) entity).getHandle();
|
||||||
PlayerChunkMap.EntityTracker entry = tracker.entityMap.get(other.getId());
|
PlayerChunkMap.EntityTracker entry = tracker.entityMap.get(other.getId());
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
entry.removePlayer(getHandle());
|
entry.removePlayer(getHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the hidden player from this player user list, if they're on it
|
// Remove the hidden entity from this player user list, if they're on it
|
||||||
if (other.sentListPacket) {
|
if (other instanceof EntityPlayer) {
|
||||||
getHandle().connection.send(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, other));
|
EntityPlayer otherPlayer = (EntityPlayer) other;
|
||||||
|
if (otherPlayer.sentListPacket) {
|
||||||
|
getHandle().connection.send(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, otherPlayer));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void showPlayer(Player player) {
|
public void showPlayer(Player player) {
|
||||||
showPlayer0(null, player);
|
showEntity0(null, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showPlayer(Plugin plugin, Player player) {
|
public void showPlayer(Plugin plugin, Player player) {
|
||||||
|
showEntity(plugin, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showEntity(Plugin plugin, org.bukkit.entity.Entity entity) {
|
||||||
Validate.notNull(plugin, "Plugin cannot be null");
|
Validate.notNull(plugin, "Plugin cannot be null");
|
||||||
// Don't require that plugin be enabled. A plugin must be allowed to call
|
// Don't require that plugin be enabled. A plugin must be allowed to call
|
||||||
// showPlayer during its onDisable() method.
|
// showPlayer during its onDisable() method.
|
||||||
showPlayer0(plugin, player);
|
showEntity0(plugin, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPlayer0(@Nullable Plugin plugin, Player player) {
|
private void showEntity0(@Nullable Plugin plugin, org.bukkit.entity.Entity entity) {
|
||||||
Validate.notNull(player, "shown player cannot be null");
|
Validate.notNull(entity, "shown entity cannot be null");
|
||||||
if (getHandle().connection == null) return;
|
if (getHandle().connection == null) return;
|
||||||
if (equals(player)) return;
|
if (equals(entity)) return;
|
||||||
|
|
||||||
Set<WeakReference<Plugin>> hidingPlugins = hiddenPlayers.get(player.getUniqueId());
|
Set<WeakReference<Plugin>> hidingPlugins = hiddenEntities.get(entity.getUniqueId());
|
||||||
if (hidingPlugins == null) {
|
if (hidingPlugins == null) {
|
||||||
return; // Player isn't hidden
|
return; // Entity isn't hidden
|
||||||
}
|
}
|
||||||
hidingPlugins.remove(getPluginWeakReference(plugin));
|
hidingPlugins.remove(getPluginWeakReference(plugin));
|
||||||
if (!hidingPlugins.isEmpty()) {
|
if (!hidingPlugins.isEmpty()) {
|
||||||
return; // Some other plugins still want the player hidden
|
return; // Some other plugins still want the entity hidden
|
||||||
}
|
}
|
||||||
hiddenPlayers.remove(player.getUniqueId());
|
hiddenEntities.remove(entity.getUniqueId());
|
||||||
|
|
||||||
PlayerChunkMap tracker = ((WorldServer) entity.level).getChunkSource().chunkMap;
|
PlayerChunkMap tracker = ((WorldServer) getHandle().level).getChunkSource().chunkMap;
|
||||||
EntityPlayer other = ((CraftPlayer) player).getHandle();
|
Entity other = ((CraftEntity) entity).getHandle();
|
||||||
|
|
||||||
getHandle().connection.send(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, other));
|
if (other instanceof EntityPlayer) {
|
||||||
|
EntityPlayer otherPlayer = (EntityPlayer) other;
|
||||||
|
getHandle().connection.send(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, otherPlayer));
|
||||||
|
}
|
||||||
|
|
||||||
PlayerChunkMap.EntityTracker entry = tracker.entityMap.get(other.getId());
|
PlayerChunkMap.EntityTracker entry = tracker.entityMap.get(other.getId());
|
||||||
if (entry != null && !entry.seenBy.contains(getHandle())) {
|
if (entry != null && !entry.seenBy.contains(getHandle().connection)) {
|
||||||
entry.updatePlayer(getHandle());
|
entry.updatePlayer(getHandle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDisconnectingPlayer(Player player) {
|
public void removeDisconnectingPlayer(Player player) {
|
||||||
hiddenPlayers.remove(player.getUniqueId());
|
hiddenEntities.remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canSee(Player player) {
|
public boolean canSee(Player player) {
|
||||||
return !hiddenPlayers.containsKey(player.getUniqueId());
|
return canSee((org.bukkit.entity.Entity) player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canSee(org.bukkit.entity.Entity entity) {
|
||||||
|
return !hiddenEntities.containsKey(entity.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user