mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-04 01:39:54 +01:00
Handle all cases of the packet in NMS.java
This commit is contained in:
parent
ab67c208d1
commit
50fa13cef0
@ -326,8 +326,7 @@ public class EventListen implements Listener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (player.isOnline() && player.isValid()
|
if (player.isOnline() && player.isValid()
|
||||||
&& npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
&& npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo
|
NMS.sendPlayerlistPacket(true, player, npc);
|
||||||
(EnumPlayerInfoAction.ADD_PLAYER, ((CraftPlayer) npc.getEntity()).getHandle()));
|
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutNamedEntitySpawn
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutNamedEntitySpawn
|
||||||
(((CraftPlayer) npc.getEntity()).getHandle()));
|
(((CraftPlayer) npc.getEntity()).getHandle()));
|
||||||
}
|
}
|
||||||
@ -338,8 +337,7 @@ public class EventListen implements Listener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (player.isOnline() && player.isValid()
|
if (player.isOnline() && player.isValid()
|
||||||
&& npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
&& npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
||||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo
|
NMS.sendPlayerlistPacket(false, player, npc);
|
||||||
(EnumPlayerInfoAction.REMOVE_PLAYER, ((CraftPlayer) npc.getEntity()).getHandle()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 61);
|
}, 61);
|
||||||
@ -347,12 +345,8 @@ public class EventListen implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerTeleports(PlayerTeleportEvent event) {
|
public void onPlayerTeleports(PlayerTeleportEvent event) {
|
||||||
if (event.getFrom().getY() > 255 || event.getFrom().getY() < 0
|
Location from = roundLocation(event.getFrom());
|
||||||
|| event.getTo().getY() > 255 || event.getTo().getY() < 0) {
|
Location to = roundLocation(event.getTo());
|
||||||
return; // Don't fire if players go outside the world, as that would be more difficult to handle.
|
|
||||||
}
|
|
||||||
Location from = event.getFrom().getBlock().getLocation();
|
|
||||||
Location to = event.getTo().getBlock().getLocation();
|
|
||||||
if (from.equals(to)) {
|
if (from.equals(to)) {
|
||||||
return; // Don't fire on every movement, just full block+.
|
return; // Don't fire on every movement, just full block+.
|
||||||
}
|
}
|
||||||
|
@ -86,14 +86,13 @@ public class HumanController extends AbstractEntityController {
|
|||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
handle.getBukkitEntity().setSleepingIgnored(true);
|
handle.getBukkitEntity().setSleepingIgnored(true);
|
||||||
NMS.sendToOnline(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle));
|
NMS.sendPlayerlistPacket(true, null, handle.getBukkitEntity());
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Double check that we're still spawned and haven't changed type.
|
// Double check that we're still spawned and haven't changed type.
|
||||||
if (npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
if (npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
||||||
NMS.sendToOnline(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER,
|
NMS.sendPlayerlistPacket(false, null, npc);
|
||||||
((CraftPlayer) getBukkitEntity()).getHandle()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 60);
|
}, 60);
|
||||||
@ -107,8 +106,7 @@ public class HumanController extends AbstractEntityController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
NMS.sendToOnline(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER,
|
NMS.sendPlayerlistPacket(false, null, (CraftPlayer)getBukkitEntity());
|
||||||
((CraftPlayer) getBukkitEntity()).getHandle()));
|
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,10 +500,23 @@ public class NMS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a PlayerInfo packet (adds or removes the NPC to or from the tab list) to the player.
|
||||||
|
* @param player The player to send the packet to, or null for all players.
|
||||||
|
*/
|
||||||
public static void sendPlayerlistPacket(boolean showInPlayerlist, Player player, NPC npc) {
|
public static void sendPlayerlistPacket(boolean showInPlayerlist, Player player, NPC npc) {
|
||||||
((CraftPlayer)player).getHandle().playerConnection.sendPacket(
|
sendPlayerlistPacket(showInPlayerlist, player, (CraftPlayer)npc.getEntity());
|
||||||
new PacketPlayOutPlayerInfo(showInPlayerlist ? EnumPlayerInfoAction.ADD_PLAYER:
|
}
|
||||||
EnumPlayerInfoAction.REMOVE_PLAYER, ((CraftPlayer) npc.getEntity()).getHandle()));
|
|
||||||
|
public static void sendPlayerlistPacket(boolean showInPlayerlist, Player player, CraftPlayer npc) {
|
||||||
|
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(showInPlayerlist ? EnumPlayerInfoAction.ADD_PLAYER:
|
||||||
|
EnumPlayerInfoAction.REMOVE_PLAYER, npc.getHandle());
|
||||||
|
if (player == null) {
|
||||||
|
sendToOnline(packet);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updatePathfindingRange(NPC npc, float pathfindingRange) {
|
public static void updatePathfindingRange(NPC npc, float pathfindingRange) {
|
||||||
|
Loading…
Reference in New Issue
Block a user