mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-01 07:03:34 +01:00
Fix pitch and yaw not saving properly. This fixes CITIZENS-22.
This commit is contained in:
parent
111ea65551
commit
1082f57938
Binary file not shown.
@ -5,10 +5,10 @@ import net.citizensnpcs.api.event.NPCLeftClickEvent;
|
|||||||
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.api.trait.trait.Owner;
|
import net.citizensnpcs.api.trait.trait.Owner;
|
||||||
import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
|
||||||
import net.citizensnpcs.editor.Editor;
|
import net.citizensnpcs.editor.Editor;
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.npc.entity.EntityHumanNPC;
|
import net.citizensnpcs.npc.entity.EntityHumanNPC;
|
||||||
|
import net.citizensnpcs.trait.CurrentLocation;
|
||||||
import net.citizensnpcs.trait.text.Text;
|
import net.citizensnpcs.trait.text.Text;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ public class EventListen implements Listener {
|
|||||||
return;
|
return;
|
||||||
for (int id : toRespawn.get(coord)) {
|
for (int id : toRespawn.get(coord)) {
|
||||||
NPC npc = npcManager.getNPC(id);
|
NPC npc = npcManager.getNPC(id);
|
||||||
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
|
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
|
||||||
}
|
}
|
||||||
toRespawn.removeAll(coord);
|
toRespawn.removeAll(coord);
|
||||||
}
|
}
|
||||||
@ -71,7 +71,6 @@ public class EventListen implements Listener {
|
|||||||
Location loc = npc.getBukkitEntity().getLocation();
|
Location loc = npc.getBukkitEntity().getLocation();
|
||||||
if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX()
|
if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX()
|
||||||
&& event.getChunk().getZ() == loc.getChunk().getZ()) {
|
&& event.getChunk().getZ() == loc.getChunk().getZ()) {
|
||||||
npc.getTrait(SpawnLocation.class).setLocation(loc);
|
|
||||||
npc.despawn();
|
npc.despawn();
|
||||||
toRespawn.put(coord, npc.getId());
|
toRespawn.put(coord, npc.getId());
|
||||||
}
|
}
|
||||||
@ -175,7 +174,7 @@ public class EventListen implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
for (int id : toRespawn.get(chunk)) {
|
for (int id : toRespawn.get(chunk)) {
|
||||||
NPC npc = npcManager.getNPC(id);
|
NPC npc = npcManager.getNPC(id);
|
||||||
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
|
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
|
||||||
}
|
}
|
||||||
toRespawn.removeAll(chunk);
|
toRespawn.removeAll(chunk);
|
||||||
}
|
}
|
||||||
@ -189,10 +188,9 @@ public class EventListen implements Listener {
|
|||||||
for (NPC npc : npcManager) {
|
for (NPC npc : npcManager) {
|
||||||
if (!npc.isSpawned() || !npc.getBukkitEntity().getWorld().equals(event.getWorld()))
|
if (!npc.isSpawned() || !npc.getBukkitEntity().getWorld().equals(event.getWorld()))
|
||||||
continue;
|
continue;
|
||||||
Location loc = npc.getBukkitEntity().getLocation();
|
|
||||||
npc.getTrait(SpawnLocation.class).setLocation(loc);
|
|
||||||
npc.despawn();
|
npc.despawn();
|
||||||
toRespawn.put(toIntPair(loc.getChunk()), npc.getId());
|
toRespawn.put(toIntPair(npc.getBukkitEntity().getLocation().getChunk()), npc.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ import net.citizensnpcs.api.npc.character.Character;
|
|||||||
import net.citizensnpcs.api.npc.character.CharacterManager;
|
import net.citizensnpcs.api.npc.character.CharacterManager;
|
||||||
import net.citizensnpcs.api.trait.trait.MobType;
|
import net.citizensnpcs.api.trait.trait.MobType;
|
||||||
import net.citizensnpcs.api.trait.trait.Owner;
|
import net.citizensnpcs.api.trait.trait.Owner;
|
||||||
import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
|
||||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.command.Command;
|
import net.citizensnpcs.command.Command;
|
||||||
import net.citizensnpcs.command.CommandContext;
|
import net.citizensnpcs.command.CommandContext;
|
||||||
@ -19,6 +18,7 @@ import net.citizensnpcs.command.Requirements;
|
|||||||
import net.citizensnpcs.command.exception.CommandException;
|
import net.citizensnpcs.command.exception.CommandException;
|
||||||
import net.citizensnpcs.command.exception.NoPermissionsException;
|
import net.citizensnpcs.command.exception.NoPermissionsException;
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
|
import net.citizensnpcs.trait.CurrentLocation;
|
||||||
import net.citizensnpcs.trait.LookClose;
|
import net.citizensnpcs.trait.LookClose;
|
||||||
import net.citizensnpcs.trait.Powered;
|
import net.citizensnpcs.trait.Powered;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
@ -347,7 +347,7 @@ public class NPCCommands {
|
|||||||
public void tp(CommandContext args, Player player, NPC npc) {
|
public void tp(CommandContext args, Player player, NPC npc) {
|
||||||
// Spawn the NPC if it isn't spawned to prevent NPEs
|
// Spawn the NPC if it isn't spawned to prevent NPEs
|
||||||
if (!npc.isSpawned())
|
if (!npc.isSpawned())
|
||||||
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
|
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
|
||||||
player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND);
|
player.teleport(npc.getBukkitEntity(), TeleportCause.COMMAND);
|
||||||
Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + ".");
|
Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + ".");
|
||||||
}
|
}
|
||||||
@ -363,9 +363,8 @@ public class NPCCommands {
|
|||||||
public void tphere(CommandContext args, Player player, NPC npc) {
|
public void tphere(CommandContext args, Player player, NPC npc) {
|
||||||
// Spawn the NPC if it isn't spawned to prevent NPEs
|
// Spawn the NPC if it isn't spawned to prevent NPEs
|
||||||
if (!npc.isSpawned())
|
if (!npc.isSpawned())
|
||||||
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
|
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
|
||||||
npc.getBukkitEntity().teleport(player, TeleportCause.COMMAND);
|
npc.getBukkitEntity().teleport(player, TeleportCause.COMMAND);
|
||||||
npc.getTrait(SpawnLocation.class).setLocation(npc.getBukkitEntity().getLocation());
|
|
||||||
Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location.");
|
Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,12 +10,13 @@ import net.citizensnpcs.api.exception.NPCLoadException;
|
|||||||
import net.citizensnpcs.api.npc.AbstractNPC;
|
import net.citizensnpcs.api.npc.AbstractNPC;
|
||||||
import net.citizensnpcs.api.npc.character.Character;
|
import net.citizensnpcs.api.npc.character.Character;
|
||||||
import net.citizensnpcs.api.trait.Trait;
|
import net.citizensnpcs.api.trait.Trait;
|
||||||
import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
|
||||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.api.util.DataKey;
|
import net.citizensnpcs.api.util.DataKey;
|
||||||
import net.citizensnpcs.npc.ai.CitizensAI;
|
import net.citizensnpcs.npc.ai.CitizensAI;
|
||||||
|
import net.citizensnpcs.trait.CurrentLocation;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.citizensnpcs.util.StringHelper;
|
import net.citizensnpcs.util.StringHelper;
|
||||||
|
|
||||||
import net.minecraft.server.EntityLiving;
|
import net.minecraft.server.EntityLiving;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -128,7 +129,7 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
mcEntity.world.players.remove(mcEntity);
|
mcEntity.world.players.remove(mcEntity);
|
||||||
|
|
||||||
// Set the location
|
// Set the location
|
||||||
getTrait(SpawnLocation.class).setLocation(loc);
|
getTrait(CurrentLocation.class).spawn(loc);
|
||||||
// Set the spawned state
|
// Set the spawned state
|
||||||
getTrait(Spawned.class).setSpawned(true);
|
getTrait(Spawned.class).setSpawned(true);
|
||||||
|
|
||||||
@ -173,7 +174,7 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
|
|
||||||
// Spawn the NPC
|
// Spawn the NPC
|
||||||
if (getTrait(Spawned.class).shouldSpawn())
|
if (getTrait(Spawned.class).shouldSpawn())
|
||||||
spawn(getTrait(SpawnLocation.class).getLocation());
|
spawn(getTrait(CurrentLocation.class).getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(DataKey root) {
|
public void save(DataKey root) {
|
||||||
|
@ -11,7 +11,6 @@ import net.citizensnpcs.api.exception.NPCLoadException;
|
|||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.api.npc.NPCManager;
|
import net.citizensnpcs.api.npc.NPCManager;
|
||||||
import net.citizensnpcs.api.npc.character.Character;
|
import net.citizensnpcs.api.npc.character.Character;
|
||||||
import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
|
||||||
import net.citizensnpcs.api.util.Storage;
|
import net.citizensnpcs.api.util.Storage;
|
||||||
import net.citizensnpcs.editor.Editor;
|
import net.citizensnpcs.editor.Editor;
|
||||||
import net.citizensnpcs.util.ByIdArray;
|
import net.citizensnpcs.util.ByIdArray;
|
||||||
@ -53,7 +52,6 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void despawn(NPC npc, boolean keepSelected) {
|
public void despawn(NPC npc, boolean keepSelected) {
|
||||||
npc.getTrait(SpawnLocation.class).setLocation(npc.getBukkitEntity().getLocation());
|
|
||||||
if (!keepSelected)
|
if (!keepSelected)
|
||||||
npc.removeMetadata("selectors", plugin);
|
npc.removeMetadata("selectors", plugin);
|
||||||
npc.getBukkitEntity().remove();
|
npc.getBukkitEntity().remove();
|
||||||
|
@ -14,7 +14,7 @@ import net.citizensnpcs.api.trait.trait.Inventory;
|
|||||||
import net.citizensnpcs.api.trait.trait.MobType;
|
import net.citizensnpcs.api.trait.trait.MobType;
|
||||||
import net.citizensnpcs.api.trait.trait.Owner;
|
import net.citizensnpcs.api.trait.trait.Owner;
|
||||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
import net.citizensnpcs.trait.CurrentLocation;
|
||||||
import net.citizensnpcs.trait.LookClose;
|
import net.citizensnpcs.trait.LookClose;
|
||||||
import net.citizensnpcs.trait.Powered;
|
import net.citizensnpcs.trait.Powered;
|
||||||
import net.citizensnpcs.trait.text.Text;
|
import net.citizensnpcs.trait.text.Text;
|
||||||
@ -32,7 +32,7 @@ public class CitizensTraitManager implements TraitManager {
|
|||||||
registerTrait(new TraitFactory(Owner.class).withName("owner"));
|
registerTrait(new TraitFactory(Owner.class).withName("owner"));
|
||||||
registerTrait(new TraitFactory(Powered.class).withName("powered"));
|
registerTrait(new TraitFactory(Powered.class).withName("powered"));
|
||||||
registerTrait(new TraitFactory(Spawned.class).withName("spawned"));
|
registerTrait(new TraitFactory(Spawned.class).withName("spawned"));
|
||||||
registerTrait(new TraitFactory(SpawnLocation.class).withName("location"));
|
registerTrait(new TraitFactory(CurrentLocation.class).withName("location"));
|
||||||
registerTrait(new TraitFactory(Text.class).withName("text"));
|
registerTrait(new TraitFactory(Text.class).withName("text"));
|
||||||
registerTrait(new TraitFactory(Waypoints.class).withName("waypoints"));
|
registerTrait(new TraitFactory(Waypoints.class).withName("waypoints"));
|
||||||
}
|
}
|
||||||
|
58
src/main/java/net/citizensnpcs/trait/CurrentLocation.java
Normal file
58
src/main/java/net/citizensnpcs/trait/CurrentLocation.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package net.citizensnpcs.trait;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.api.trait.Trait;
|
||||||
|
import net.citizensnpcs.api.util.DataKey;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class CurrentLocation extends Trait implements Runnable {
|
||||||
|
private Location loc;
|
||||||
|
private final NPC npc;
|
||||||
|
|
||||||
|
public CurrentLocation(NPC npc) {
|
||||||
|
this.npc = npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (npc.getBukkitEntity() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
loc = npc.getBukkitEntity().getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(DataKey key) throws NPCLoadException {
|
||||||
|
if (Bukkit.getWorld(key.getString("world")) == null)
|
||||||
|
throw new NPCLoadException("'" + key.getString("world") + "' is not a valid world.");
|
||||||
|
|
||||||
|
loc = new Location(Bukkit.getWorld(key.getString("world")), key.getDouble("x"), key.getDouble("y"), key
|
||||||
|
.getDouble("z"), (float) key.getDouble("yaw"), (float) key.getDouble("pitch"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(DataKey key) {
|
||||||
|
key.setString("world", loc.getWorld().getName());
|
||||||
|
key.setDouble("x", loc.getX());
|
||||||
|
key.setDouble("y", loc.getY());
|
||||||
|
key.setDouble("z", loc.getZ());
|
||||||
|
key.setDouble("yaw", loc.getYaw());
|
||||||
|
key.setDouble("pitch", loc.getPitch());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawn(Location loc) {
|
||||||
|
this.loc = loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "SpawnLocation{" + loc + "}";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user