mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 13:15:33 +01:00
Hopefully fix NPC tablist issues
This commit is contained in:
parent
3f95c57ea4
commit
36b9a0c4c8
@ -56,7 +56,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
private PlayerNavigation navigation;
|
private PlayerNavigation navigation;
|
||||||
private final CitizensNPC npc;
|
private final CitizensNPC npc;
|
||||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||||
private int useListName = -1;
|
|
||||||
|
|
||||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||||
PlayerInteractManager playerInteractManager, NPC npc) {
|
PlayerInteractManager playerInteractManager, NPC npc) {
|
||||||
@ -135,17 +134,18 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
return controllerJump;
|
return controllerJump;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Packet getListPacket(boolean removeFromPlayerList) {
|
private Packet getListPacket(Player player, boolean removeFromPlayerList) {
|
||||||
if (PLAYER_INFO_CONSTRUCTOR != null) {
|
if (PLAYER_INFO_CONSTRUCTOR != null) {
|
||||||
try {
|
try {
|
||||||
return PLAYER_INFO_CONSTRUCTOR.newInstance(getBukkitEntity().getPlayerListName(),
|
return PLAYER_INFO_CONSTRUCTOR.newInstance(player.getPlayerListName(), !removeFromPlayerList,
|
||||||
!removeFromPlayerList, removeFromPlayerList ? 9999 : ping);
|
removeFromPlayerList ? 9999 : ping);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
return (Packet) (removeFromPlayerList ? PLAYER_INFO_REMOVE_METHOD.invoke(null, getBukkitEntity()
|
return (Packet) (removeFromPlayerList ? PLAYER_INFO_REMOVE_METHOD.invoke(null,
|
||||||
.getHandle()) : PLAYER_INFO_ADD_METHOD.invoke(null, getBukkitEntity().getHandle()));
|
((CraftPlayer) player).getHandle()) : PLAYER_INFO_ADD_METHOD.invoke(null,
|
||||||
|
((CraftPlayer) player).getHandle()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,19 +299,16 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
|
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
|
||||||
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
|
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
|
||||||
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
|
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
|
||||||
int useListName = removeFromPlayerList ? 0 : 1;
|
Player otherOnline = null;
|
||||||
if (useListName != this.useListName || this.useListName == -1) {
|
|
||||||
this.useListName = useListName;
|
|
||||||
}
|
|
||||||
boolean sendListPacket = true;
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (player.getName().equalsIgnoreCase(getName())) {
|
if (player.getName().equalsIgnoreCase(getName()) && !(player instanceof NPCHolder)) {
|
||||||
sendListPacket = false;
|
otherOnline = player;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sendListPacket) {
|
NMS.sendToOnline(getListPacket(getBukkitEntity(), true));
|
||||||
NMS.sendToOnline(getListPacket(removeFromPlayerList));
|
if (otherOnline != null) {
|
||||||
|
NMS.sendToOnline(getListPacket(otherOnline, false));
|
||||||
}
|
}
|
||||||
NMS.sendPacketsNearby(getBukkitEntity(), current, packets);
|
NMS.sendPacketsNearby(getBukkitEntity(), current, packets);
|
||||||
}
|
}
|
||||||
|
@ -247,9 +247,8 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL)
|
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL || !npc.isSpawned()
|
||||||
return;
|
|| event.getPlayer().getWorld() != npc.getEntity().getWorld())
|
||||||
if (event.getPlayer().getWorld() != npc.getEntity().getWorld())
|
|
||||||
return;
|
return;
|
||||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
|
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||||
if (event.getClickedBlock() == null)
|
if (event.getClickedBlock() == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user