mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 20:55:44 +01:00
possible fix and lots of other changes
This commit is contained in:
parent
6f155d21e0
commit
08e9a588b4
@ -14,6 +14,7 @@ import net.citizensnpcs.npc.trait.CitizensCharacterManager;
|
||||
import net.citizensnpcs.npc.trait.CitizensTraitManager;
|
||||
import net.citizensnpcs.storage.Storage;
|
||||
import net.citizensnpcs.storage.flatfile.YamlStorage;
|
||||
import net.citizensnpcs.util.ByIdArray;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -92,7 +93,6 @@ public class Citizens extends JavaPlugin {
|
||||
// TODO possibly separate this out some more
|
||||
private void setupNPCs() throws NPCLoadException {
|
||||
traitManager.registerTrait("location", SpawnLocation.class);
|
||||
int spawned = 0;
|
||||
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
|
||||
int id = Integer.parseInt(key.name());
|
||||
if (!key.keyExists("name"))
|
||||
@ -121,19 +121,18 @@ public class Citizens extends JavaPlugin {
|
||||
}
|
||||
|
||||
// Spawn the NPC
|
||||
if (key.getBoolean("spawned")) {
|
||||
if (key.getBoolean("spawned"))
|
||||
npc.spawn(npc.getTrait(SpawnLocation.class).getLocation());
|
||||
spawned++;
|
||||
}
|
||||
}
|
||||
Messaging.log("Loaded " + npcManager.size() + " NPCs (" + spawned + " spawned).");
|
||||
Messaging.log("Loaded " + ((ByIdArray<NPC>) npcManager.getAllNPCs()).size() + " NPCs ("
|
||||
+ ((ByIdArray<NPC>) npcManager.getSpawnedNPCs()).size() + " spawned).");
|
||||
}
|
||||
|
||||
private void saveNPCs() {
|
||||
for (NPC npc : npcManager.getAllNPCs()) {
|
||||
DataKey root = saves.getKey("npc." + npc.getId());
|
||||
root.setString("name", npc.getFullName());
|
||||
root.setBoolean("spawned", npc.isSpawned());
|
||||
root.setBoolean("spawned", npc.getBukkitEntity().isDead());
|
||||
|
||||
// Save the character if it exists
|
||||
if (npc.getCharacter() != null) {
|
||||
@ -142,9 +141,8 @@ public class Citizens extends JavaPlugin {
|
||||
}
|
||||
|
||||
// Save all existing traits
|
||||
for (Trait trait : npc.getTraits()) {
|
||||
for (Trait trait : npc.getTraits())
|
||||
trait.save(root.getRelative(trait.getName()));
|
||||
}
|
||||
}
|
||||
saves.save();
|
||||
}
|
||||
|
@ -51,7 +51,8 @@ public class EventListen implements Listener {
|
||||
return;
|
||||
|
||||
NPC npc = manager.getNPC(event.getEntity());
|
||||
npc.getCharacter().onRightClick(npc, (Player) event.getTarget());
|
||||
if (npc.getCharacter() != null)
|
||||
npc.getCharacter().onRightClick(npc, (Player) event.getTarget());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -27,8 +27,8 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CitizensNPCManager implements NPCManager {
|
||||
private final ByIdArray<NPC> spawned = ByIdArray.create();
|
||||
private final ByIdArray<NPC> byID = ByIdArray.create();
|
||||
private final ByIdArray<NPC> spawned = new ByIdArray<NPC>();
|
||||
private final ByIdArray<NPC> byID = new ByIdArray<NPC>();
|
||||
|
||||
@Override
|
||||
public NPC createNPC(String name) {
|
||||
@ -65,7 +65,7 @@ public class CitizensNPCManager implements NPCManager {
|
||||
@Override
|
||||
public Collection<NPC> getNPCs(Class<? extends Trait> trait) {
|
||||
List<NPC> npcs = new ArrayList<NPC>();
|
||||
for (NPC npc : byID) {
|
||||
for (NPC npc : getAllNPCs()) {
|
||||
if (npc.hasTrait(trait))
|
||||
npcs.add(npc);
|
||||
}
|
||||
@ -88,8 +88,6 @@ public class CitizensNPCManager implements NPCManager {
|
||||
}
|
||||
|
||||
public CraftNPC spawn(NPC npc, Location loc) {
|
||||
if (spawned.contains(npc.getBukkitEntity().getEntityId()))
|
||||
throw new IllegalStateException("The NPC with ID '" + npc.getId() + "' is already spawned.");
|
||||
WorldServer ws = getWorldServer(loc.getWorld());
|
||||
CraftNPC mcEntity = new CraftNPC(getMinecraftServer(ws.getServer()), ws, npc.getFullName(),
|
||||
new ItemInWorldManager(ws));
|
||||
@ -103,8 +101,6 @@ public class CitizensNPCManager implements NPCManager {
|
||||
}
|
||||
|
||||
public void despawn(NPC npc) {
|
||||
if (!spawned.contains(npc.getBukkitEntity().getEntityId()))
|
||||
throw new IllegalStateException("The NPC with ID '" + npc.getId() + "' is already despawned.");
|
||||
CraftNPC mcEntity = ((CitizensNPC) npc).getHandle();
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer) player).getHandle().netServerHandler.sendPacket(new Packet29DestroyEntity(mcEntity.id));
|
||||
@ -128,8 +124,4 @@ public class CitizensNPCManager implements NPCManager {
|
||||
private MinecraftServer getMinecraftServer(Server server) {
|
||||
return ((CraftServer) server).getServer();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return byID.size();
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package net.citizensnpcs.test;
|
||||
|
||||
import org.junit.Test;
|
||||
//import org.junit.Test;
|
||||
|
||||
public class StorageTest {
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
public void testYaml() {
|
||||
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
}
|
||||
|
||||
private void recalcLowest() {
|
||||
while (elementData.length > lowest && elementData[lowest++] == null)
|
||||
while (elementData.length > lowest && highest > lowest && elementData[lowest++] == null)
|
||||
;
|
||||
}
|
||||
|
||||
@ -129,10 +129,6 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
elementData = Arrays.copyOf(elementData, highest + 1);
|
||||
}
|
||||
|
||||
public static <T> ByIdArray<T> create() {
|
||||
return new ByIdArray<T>();
|
||||
}
|
||||
|
||||
public boolean contains(int index) {
|
||||
return elementData.length > index && elementData[index] != null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user