mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-27 19:47:51 +01:00
Cure NPCs of skin loss once and for all
...hopefully.
This commit is contained in:
parent
bdade4a077
commit
54abeece09
@ -1,5 +1,6 @@
|
|||||||
package net.citizensnpcs;
|
package net.citizensnpcs;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -279,33 +280,38 @@ public class EventListen implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
Location location = player.getLocation().getBlock().getLocation();
|
||||||
|
final List<EntityPlayer> nearbyNPCs = new ArrayList<EntityPlayer>();
|
||||||
|
for (NPC npc : getAllNPCs()) {
|
||||||
|
Entity npcEntity = npc.getEntity();
|
||||||
|
if (npcEntity instanceof Player && player.canSee((Player) npcEntity)) {
|
||||||
|
nearbyNPCs.add(((CraftPlayer) npcEntity).getHandle());
|
||||||
|
}
|
||||||
|
}
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final Player player = event.getPlayer();
|
if (!player.isValid())
|
||||||
if (player == null || !player.isValid())
|
|
||||||
return;
|
return;
|
||||||
Location location = player.getLocation().getBlock().getLocation();
|
for (EntityPlayer nearbyNPC : nearbyNPCs) {
|
||||||
for (NPC npc : getAllNPCs()) {
|
NMS.sendPacket(player, new PacketPlayOutPlayerInfo(
|
||||||
Entity entity = npc.getEntity();
|
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, nearbyNPC));
|
||||||
if (entity instanceof Player && entity.getLocation().distanceSquared(location) < 200*200) {
|
|
||||||
final EntityPlayer entitynpc = ((CraftPlayer) entity).getHandle();
|
|
||||||
NMS.sendPacket(player, new PacketPlayOutPlayerInfo(
|
|
||||||
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entitynpc));
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!player.isValid())
|
|
||||||
return;
|
|
||||||
NMS.sendPacket(player, new PacketPlayOutPlayerInfo(
|
|
||||||
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entitynpc));
|
|
||||||
}
|
|
||||||
}.runTaskLater(CitizensAPI.getPlugin(), 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!player.isValid())
|
||||||
|
return;
|
||||||
|
for (EntityPlayer nearbyNPC : nearbyNPCs) {
|
||||||
|
NMS.sendPacket(player, new PacketPlayOutPlayerInfo(
|
||||||
|
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, nearbyNPC));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(CitizensAPI.getPlugin(), 2);
|
||||||
}
|
}
|
||||||
}.runTaskLater(CitizensAPI.getPlugin(), 30);
|
}.runTaskLater(CitizensAPI.getPlugin(), 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.citizensnpcs.npc;
|
package net.citizensnpcs.npc;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -23,12 +24,15 @@ import net.citizensnpcs.trait.CurrentLocation;
|
|||||||
import net.citizensnpcs.util.Messages;
|
import net.citizensnpcs.util.Messages;
|
||||||
import net.citizensnpcs.util.NMS;
|
import net.citizensnpcs.util.NMS;
|
||||||
import net.citizensnpcs.util.Util;
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_8_R2.Packet;
|
||||||
import net.minecraft.server.v1_8_R2.PacketPlayOutEntityTeleport;
|
import net.minecraft.server.v1_8_R2.PacketPlayOutEntityTeleport;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftLivingEntity;
|
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftLivingEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
@ -38,6 +42,7 @@ import org.bukkit.metadata.FixedMetadataValue;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class CitizensNPC extends AbstractNPC {
|
public class CitizensNPC extends AbstractNPC {
|
||||||
private EntityController entityController;
|
private EntityController entityController;
|
||||||
@ -216,7 +221,22 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
NMS.setStepHeight(NMS.getHandle(entity), 1);
|
NMS.setStepHeight(NMS.getHandle(entity), 1);
|
||||||
}
|
}
|
||||||
if (getEntity() instanceof Player) {
|
if (getEntity() instanceof Player) {
|
||||||
NMS.replaceTrackerEntry((Player) getEntity());
|
final CraftPlayer player = (CraftPlayer) getEntity();
|
||||||
|
NMS.replaceTrackerEntry(player);
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
NMS.sendPacketsNearby(player, player.getLocation(), Arrays.asList((Packet) new PacketPlayOutPlayerInfo(
|
||||||
|
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, player.getHandle())), 200.0);
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
NMS.sendPacketsNearby(player, player.getLocation(), Arrays.asList((Packet) new PacketPlayOutPlayerInfo(
|
||||||
|
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, player.getHandle())), 200.0);
|
||||||
|
}
|
||||||
|
}.runTaskLater(CitizensAPI.getPlugin(), 2);
|
||||||
|
}
|
||||||
|
}.runTaskLater(CitizensAPI.getPlugin(), 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user