mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-27 19:47:51 +01:00
Merge pull request #320 from mcmonkey4eva/EntityPatch
Fix EntityTypes usage, fixes #239
This commit is contained in:
commit
36cf6e8ea8
@ -52,10 +52,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
@ -279,22 +276,56 @@ public class EventListen implements Listener {
|
||||
Bukkit.getPluginManager().callEvent(rightClickEvent);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
recalculatePlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
recalculatePlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
|
||||
recalculatePlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
public void recalculatePlayer(final Player player) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final List<EntityPlayer> nearbyNPCs = new ArrayList<EntityPlayer>();
|
||||
for (NPC npc : getAllNPCs()) {
|
||||
Entity npcEntity = npc.getEntity();
|
||||
if (npcEntity instanceof Player && player.canSee((Player) npcEntity)) {
|
||||
if (npcEntity instanceof Player && player.canSee((Player) npcEntity)
|
||||
&& player.getWorld().equals(npcEntity.getWorld())
|
||||
&& player.getLocation().distanceSquared(npcEntity.getLocation()) < 100 * 100) {
|
||||
nearbyNPCs.add(((CraftPlayer) npcEntity).getHandle());
|
||||
}
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendToPlayer(player, nearbyNPCs);
|
||||
}
|
||||
}.runTaskLater(CitizensAPI.getPlugin(), 30);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendToPlayer(player, nearbyNPCs);
|
||||
}
|
||||
}.runTaskLater(CitizensAPI.getPlugin(), 70);
|
||||
}
|
||||
}.runTaskLater(CitizensAPI.getPlugin(), 10);
|
||||
|
||||
}
|
||||
|
||||
void sendToPlayer(final Player player, final List<EntityPlayer> nearbyNPCs) {
|
||||
if (!player.isValid())
|
||||
return;
|
||||
for (EntityPlayer nearbyNPC : nearbyNPCs) {
|
||||
if (nearbyNPC.isAlive())
|
||||
NMS.sendPacket(player, new PacketPlayOutPlayerInfo(
|
||||
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, nearbyNPC));
|
||||
}
|
||||
@ -304,14 +335,13 @@ public class EventListen implements Listener {
|
||||
if (!player.isValid())
|
||||
return;
|
||||
for (EntityPlayer nearbyNPC : nearbyNPCs) {
|
||||
if (nearbyNPC.isAlive())
|
||||
NMS.sendPacket(player, new PacketPlayOutPlayerInfo(
|
||||
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, nearbyNPC));
|
||||
}
|
||||
}
|
||||
}.runTaskLater(CitizensAPI.getPlugin(), 2);
|
||||
}
|
||||
}.runTaskLater(CitizensAPI.getPlugin(), 40);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
|
@ -666,7 +666,7 @@ public class NMS {
|
||||
try {
|
||||
Field field = getField(EntityTypes.class, "f");
|
||||
ENTITY_CLASS_TO_INT = (Map<Class<?>, Integer>) field.get(null);
|
||||
field = getField(EntityTypes.class, "c");
|
||||
field = getField(EntityTypes.class, "d");
|
||||
ENTITY_CLASS_TO_NAME = (Map<Class<?>, String>) field.get(null);
|
||||
} catch (Exception e) {
|
||||
Messaging.logTr(Messages.ERROR_GETTING_ID_MAPPING, e.getMessage());
|
||||
|
Loading…
Reference in New Issue
Block a user