mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 21:29:14 +01:00
Remove usage of location.getChunk()
This commit is contained in:
parent
01ae2eca46
commit
6406e1c2e3
@ -187,7 +187,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
Bukkit.getPluginManager().callEvent(new CitizensDisableEvent());
|
||||
Editor.leaveAll();
|
||||
CitizensAPI.shutdown();
|
||||
metrics.stopTask();
|
||||
metrics.stop();
|
||||
|
||||
tearDownScripting();
|
||||
// Don't bother with this part if MC versions are not compatible
|
||||
|
@ -87,8 +87,7 @@ public class EventListen implements Listener {
|
||||
if (!npc.isSpawned())
|
||||
continue;
|
||||
Location loc = npc.getBukkitEntity().getLocation();
|
||||
Chunk chunk = loc.getChunk();
|
||||
boolean sameChunkCoordinates = coord.z == chunk.getZ() && coord.x == chunk.getX();
|
||||
boolean sameChunkCoordinates = coord.z == loc.getBlockZ() >> 4 && coord.x == loc.getBlockX() >> 4;
|
||||
if (event.getWorld().equals(loc.getWorld()) && sameChunkCoordinates) {
|
||||
npc.despawn();
|
||||
toRespawn.put(coord, npc.getId());
|
||||
@ -264,7 +263,11 @@ public class EventListen implements Listener {
|
||||
}
|
||||
|
||||
private void storeForRespawn(NPC npc) {
|
||||
toRespawn.put(toCoord(npc.getBukkitEntity().getLocation().getChunk()), npc.getId());
|
||||
toRespawn.put(toCoord(npc.getBukkitEntity().getLocation()), npc.getId());
|
||||
}
|
||||
|
||||
private ChunkCoord toCoord(Location loc) {
|
||||
return new ChunkCoord(loc.getWorld().getName(), loc.getBlockX() >> 4, loc.getBlockZ() >> 4);
|
||||
}
|
||||
|
||||
private ChunkCoord toCoord(Chunk chunk) {
|
||||
@ -320,9 +323,9 @@ public class EventListen implements Listener {
|
||||
|
||||
private static EventListen instance;
|
||||
|
||||
public static void add(Location loc, int id) {
|
||||
public static void addForRespawn(Location loc, int id) {
|
||||
if (instance == null)
|
||||
return;
|
||||
instance.toRespawn.put(instance.toCoord(loc.getChunk()), id);
|
||||
instance.toRespawn.put(instance.toCoord(loc), id);
|
||||
}
|
||||
}
|
@ -459,10 +459,10 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
public void stopTask() {
|
||||
public void stop() {
|
||||
synchronized (optOutLock) {
|
||||
if (taskId > 0) {
|
||||
this.plugin.getServer().getScheduler().cancelTask(taskId);
|
||||
plugin.getServer().getScheduler().cancelTask(taskId);
|
||||
taskId = -1;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class NPCDataStore {
|
||||
}
|
||||
|
||||
public void loadInto(CitizensNPCRegistry registry) {
|
||||
int created = 0, spawned = 0;
|
||||
int created = 0;
|
||||
for (DataKey key : root.getKey("npc").getIntegerSubKeys()) {
|
||||
int id = Integer.parseInt(key.name());
|
||||
if (!key.keyExists("name")) {
|
||||
@ -44,10 +44,8 @@ public class NPCDataStore {
|
||||
((CitizensNPC) npc).load(key);
|
||||
|
||||
created++;
|
||||
if (npc.isSpawned())
|
||||
spawned++;
|
||||
}
|
||||
Messaging.logTr(Messages.NUM_LOADED_NOTIFICATION, created, spawned);
|
||||
Messaging.logTr(Messages.NUM_LOADED_NOTIFICATION, created);
|
||||
}
|
||||
|
||||
public void remove(NPC npc) {
|
||||
|
@ -605,11 +605,13 @@ public class NPCCommands {
|
||||
Messaging.sendTr(sender, Messages.MOVETO_TELEPORTED, npc.getName(), to);
|
||||
}
|
||||
|
||||
@Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0)
|
||||
@Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0, permission = "npc.info")
|
||||
public void npc(CommandContext args, CommandSender sender, final NPC npc) {
|
||||
Messaging.send(sender, StringHelper.wrapHeader(npc.getName()));
|
||||
Messaging.send(sender, " <a>ID: <e>" + npc.getId());
|
||||
Messaging.send(sender, " <a>Type: <e>" + npc.getTrait(MobType.class).getType());
|
||||
if (npc.isSpawned())
|
||||
Messaging.send(sender, " <a>Spawned at: <e>" + npc.getBukkitEntity().getLocation());
|
||||
Messaging.send(sender, " <a>Traits<e>");
|
||||
for (Trait trait : npc.getTraits()) {
|
||||
if (CitizensAPI.getTraitFactory().isInternalTrait(trait))
|
||||
|
@ -184,7 +184,7 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
if (!couldSpawn) {
|
||||
// we need to wait for a chunk load before trying to spawn
|
||||
mcEntity = null;
|
||||
EventListen.add(loc, getId());
|
||||
EventListen.addForRespawn(loc, getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.ItemInWorldManager;
|
||||
import net.minecraft.server.WorldServer;
|
||||
@ -31,18 +32,15 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
|
||||
final EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws,
|
||||
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws), this);
|
||||
handle.getBukkitEntity().teleport(loc);
|
||||
NMS.setHeadYaw(handle, loc.getYaw() % 360);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handle.yaw = loc.getYaw();
|
||||
NMS.setHeadYaw(handle, loc.getYaw() % 360);
|
||||
// set the yaw in another tick - if done immediately,
|
||||
// minecraft will not update it.
|
||||
boolean removeFromPlayerList = Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean();
|
||||
NMS.addOrRemoveFromPlayerList(getBukkitEntity(),
|
||||
data().get("removefromplayerlist", removeFromPlayerList));
|
||||
}
|
||||
}, 5);
|
||||
}, 1);
|
||||
handle.getBukkitEntity().setSleepingIgnored(true);
|
||||
return handle;
|
||||
}
|
||||
@ -140,7 +138,7 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
if (isSpawned() && getBukkitEntity().getLocation().getChunk().isLoaded()) {
|
||||
if (isSpawned() && Util.isLoaded(getBukkitEntity().getLocation())) {
|
||||
if (!getNavigator().isNavigating() && !NMS.inWater(mcEntity))
|
||||
mcEntity.move(0, -0.2, 0);
|
||||
// gravity. also works around an entity.onGround not updating issue
|
||||
|
@ -56,10 +56,10 @@ public class Util {
|
||||
double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
|
||||
double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);
|
||||
|
||||
double yaw = (Math.acos(xDiff / distanceXZ) * 180 / Math.PI);
|
||||
double pitch = (Math.acos(yDiff / distanceY) * 180 / Math.PI) - 90;
|
||||
double yaw = Math.toDegrees(Math.acos(xDiff / distanceXZ));
|
||||
double pitch = Math.toDegrees(Math.acos(yDiff / distanceY)) - 90;
|
||||
if (zDiff < 0.0)
|
||||
yaw = yaw + (Math.abs(180 - yaw) * 2);
|
||||
yaw += Math.abs(180 - yaw) * 2;
|
||||
|
||||
EntityLiving handle = ((CraftLivingEntity) from).getHandle();
|
||||
NMS.look(handle, (float) yaw - 90, (float) pitch);
|
||||
|
Loading…
Reference in New Issue
Block a user