mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-14 04:02:01 +01:00
Refactor
Move the playerlsit packet handling to the NMS class
This commit is contained in:
parent
33ef7d2a55
commit
ab67c208d1
@ -276,9 +276,7 @@ public class EventListen implements Listener {
|
|||||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||||
for (NPC npc : getAllNPCs()) {
|
for (NPC npc : getAllNPCs()) {
|
||||||
if (npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
if (npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
||||||
((CraftPlayer)event.getPlayer()).getHandle().playerConnection.sendPacket(
|
NMS.sendPlayerlistPacket(true, event.getPlayer(), npc);
|
||||||
new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, ((CraftPlayer) npc
|
|
||||||
.getEntity()).getHandle()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
@ -286,9 +284,7 @@ public class EventListen implements Listener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
for (NPC npc : getAllNPCs()) {
|
for (NPC npc : getAllNPCs()) {
|
||||||
if (npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
if (npc.isSpawned() && npc.getEntity().getType() == EntityType.PLAYER) {
|
||||||
((CraftPlayer)event.getPlayer()).getHandle().playerConnection.sendPacket(
|
NMS.sendPlayerlistPacket(false, event.getPlayer(), npc);
|
||||||
new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, ((CraftPlayer) npc
|
|
||||||
.getEntity()).getHandle()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,27 +16,7 @@ import net.citizensnpcs.api.util.Messaging;
|
|||||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
import net.citizensnpcs.npc.entity.EntityHumanNPC;
|
import net.citizensnpcs.npc.entity.EntityHumanNPC;
|
||||||
import net.citizensnpcs.npc.network.EmptyChannel;
|
import net.citizensnpcs.npc.network.EmptyChannel;
|
||||||
import net.minecraft.server.v1_8_R1.AttributeInstance;
|
import net.minecraft.server.v1_8_R1.*;
|
||||||
import net.minecraft.server.v1_8_R1.Block;
|
|
||||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_8_R1.ControllerJump;
|
|
||||||
import net.minecraft.server.v1_8_R1.DamageSource;
|
|
||||||
import net.minecraft.server.v1_8_R1.EnchantmentManager;
|
|
||||||
import net.minecraft.server.v1_8_R1.Entity;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityHorse;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityHuman;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityInsentient;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityLiving;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityMinecartAbstract;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityTypes;
|
|
||||||
import net.minecraft.server.v1_8_R1.GenericAttributes;
|
|
||||||
import net.minecraft.server.v1_8_R1.MathHelper;
|
|
||||||
import net.minecraft.server.v1_8_R1.NavigationAbstract;
|
|
||||||
import net.minecraft.server.v1_8_R1.NetworkManager;
|
|
||||||
import net.minecraft.server.v1_8_R1.Packet;
|
|
||||||
import net.minecraft.server.v1_8_R1.PathfinderGoalSelector;
|
|
||||||
import net.minecraft.server.v1_8_R1.World;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -47,6 +27,7 @@ import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
|
|||||||
import org.bukkit.craftbukkit.v1_8_R1.CraftSound;
|
import org.bukkit.craftbukkit.v1_8_R1.CraftSound;
|
||||||
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
|
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Horse;
|
import org.bukkit.entity.Horse;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
@ -519,6 +500,12 @@ public class NMS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sendPlayerlistPacket(boolean showInPlayerlist, Player player, NPC npc) {
|
||||||
|
((CraftPlayer)player).getHandle().playerConnection.sendPacket(
|
||||||
|
new PacketPlayOutPlayerInfo(showInPlayerlist ? EnumPlayerInfoAction.ADD_PLAYER:
|
||||||
|
EnumPlayerInfoAction.REMOVE_PLAYER, ((CraftPlayer) npc.getEntity()).getHandle()));
|
||||||
|
}
|
||||||
|
|
||||||
public static void updatePathfindingRange(NPC npc, float pathfindingRange) {
|
public static void updatePathfindingRange(NPC npc, float pathfindingRange) {
|
||||||
if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
|
if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user