mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-30 06:33:56 +01:00
Merge branch 'master' of http://www.github.com/aPunch/Citizens2
This commit is contained in:
commit
6f155d21e0
Binary file not shown.
@ -101,9 +101,9 @@ public class Citizens extends JavaPlugin {
|
||||
NPC npc = npcManager.createNPC(key.getString("name"), character);
|
||||
|
||||
// Load the character if it exists, otherwise remove the character
|
||||
if (character != null) {
|
||||
if (character != null)
|
||||
character.load(key.getRelative(character.getName()));
|
||||
} else {
|
||||
else {
|
||||
if (key.keyExists("character")) {
|
||||
Messaging.debug("Character '" + key.getString("character")
|
||||
+ "' does not exist. Removing character from the NPC with ID '" + npc.getId() + "'.");
|
||||
|
@ -34,14 +34,13 @@ public class EventListen implements Listener {
|
||||
if (!manager.isNPC(event.getEntity()))
|
||||
return;
|
||||
|
||||
event.setCancelled(true); // TODO: implement damage handlers
|
||||
event.setCancelled(true);
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
|
||||
if (e.getDamager() instanceof Player) {
|
||||
NPC npc = manager.getNPC(event.getEntity());
|
||||
if (npc.getCharacter() != null) {
|
||||
if (npc.getCharacter() != null)
|
||||
npc.getCharacter().onLeftClick(npc, (Player) e.getDamager());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,14 +52,13 @@ public class Settings {
|
||||
}
|
||||
|
||||
private final YamlStorage config;
|
||||
private final DataKey root;
|
||||
|
||||
public Settings(Citizens plugin) {
|
||||
config = new YamlStorage(plugin.getDataFolder() + File.separator + "config.yml");
|
||||
root = config.getKey("");
|
||||
}
|
||||
|
||||
public void load() {
|
||||
DataKey root = config.getKey("");
|
||||
for (Setting setting : Setting.values()) {
|
||||
if (!root.keyExists(setting.getPath())) {
|
||||
Messaging.log("Writing default setting: '" + setting.getPath() + "'");
|
||||
|
@ -32,7 +32,7 @@ public class CitizensNPC implements NPC {
|
||||
this.name = name;
|
||||
this.character = character;
|
||||
manager = (CitizensNPCManager) CitizensAPI.getNPCManager();
|
||||
id = manager.getUniqueID();
|
||||
id = manager.generateUniqueId();
|
||||
}
|
||||
|
||||
public CitizensNPC(int id, String name, Character character) {
|
||||
@ -59,11 +59,10 @@ public class CitizensNPC implements NPC {
|
||||
|
||||
@Override
|
||||
public void addTrait(Trait trait) {
|
||||
if (!hasTrait(trait.getClass())) {
|
||||
if (!hasTrait(trait.getClass()))
|
||||
traits.put(trait.getClass(), trait);
|
||||
} else {
|
||||
else
|
||||
Messaging.debug("The NPC already has the trait '" + getTrait(trait.getClass()).getName() + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -134,11 +133,10 @@ public class CitizensNPC implements NPC {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mcEntity == null) {
|
||||
if (mcEntity == null)
|
||||
mcEntity = manager.spawn(this, loc);
|
||||
} else {
|
||||
else
|
||||
manager.spawn(this, loc);
|
||||
}
|
||||
|
||||
// Set the location
|
||||
addTrait(new SpawnLocation(loc));
|
||||
@ -162,9 +160,8 @@ public class CitizensNPC implements NPC {
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if (isSpawned()) {
|
||||
if (isSpawned())
|
||||
despawn();
|
||||
}
|
||||
manager.remove(this);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class CitizensNPCManager implements NPCManager {
|
||||
return spawned.contains(entity.getEntityId());
|
||||
}
|
||||
|
||||
public int getUniqueID() {
|
||||
public int generateUniqueId() {
|
||||
int count = 0;
|
||||
while (true) {
|
||||
if (getNPC(count) == null)
|
||||
@ -89,7 +89,7 @@ public class CitizensNPCManager implements NPCManager {
|
||||
|
||||
public CraftNPC spawn(NPC npc, Location loc) {
|
||||
if (spawned.contains(npc.getBukkitEntity().getEntityId()))
|
||||
throw new IllegalStateException("already spawned");
|
||||
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));
|
||||
@ -104,11 +104,10 @@ public class CitizensNPCManager implements NPCManager {
|
||||
|
||||
public void despawn(NPC npc) {
|
||||
if (!spawned.contains(npc.getBukkitEntity().getEntityId()))
|
||||
throw new IllegalStateException("already despawned");
|
||||
throw new IllegalStateException("The NPC with ID '" + npc.getId() + "' is already despawned.");
|
||||
CraftNPC mcEntity = ((CitizensNPC) npc).getHandle();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
((CraftPlayer) player).getHandle().netServerHandler.sendPacket(new Packet29DestroyEntity(mcEntity.id));
|
||||
}
|
||||
Location loc = npc.getBukkitEntity().getLocation();
|
||||
getWorldServer(loc.getWorld()).removeEntity(mcEntity);
|
||||
npc.getTrait(SpawnLocation.class).setLocation(loc);
|
||||
|
@ -13,9 +13,8 @@ public class CitizensTraitManager implements TraitManager {
|
||||
|
||||
@Override
|
||||
public Trait getTrait(String name) {
|
||||
if (registered.get(name) == null) {
|
||||
if (registered.get(name) == null)
|
||||
return null;
|
||||
}
|
||||
return registered.get(name).create();
|
||||
}
|
||||
|
||||
@ -27,7 +26,7 @@ public class CitizensTraitManager implements TraitManager {
|
||||
@Override
|
||||
public void registerTraitWithFactory(String name, Factory<? extends Trait> factory) {
|
||||
if (registered.get(name) != null)
|
||||
throw new IllegalArgumentException("trait factory already registered");
|
||||
throw new IllegalArgumentException("Trait factory already registered.");
|
||||
registered.put(name, factory);
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
|
||||
public ByIdArray(int capacity) {
|
||||
if (capacity < 0)
|
||||
throw new IllegalArgumentException("illegal capacity");
|
||||
throw new IllegalArgumentException("Illegal capacity: cannot be below 0.");
|
||||
elementData = new Object[capacity];
|
||||
}
|
||||
|
||||
@ -57,18 +57,6 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
return (T) elementData[index];
|
||||
}
|
||||
|
||||
/*@SuppressWarnings("unchecked")
|
||||
public T[] toArray(T[] a) {
|
||||
if (a.length < size)
|
||||
// Make a new array of a's runtime type, but my contents:
|
||||
return (T[]) Arrays.copyOf(elementData, size, a.getClass());
|
||||
System.arraycopy(elementData, 0, a, 0, size);
|
||||
if (a.length > size)
|
||||
a[size] = null;
|
||||
return a;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
@ -85,9 +73,9 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
T next = (T) elementData[idx];
|
||||
if (next == null || idx > highest)
|
||||
throw new NoSuchElementException();
|
||||
do {
|
||||
do
|
||||
idx++;
|
||||
} while (idx != highest + 1 && elementData[idx] == null);
|
||||
while (idx != highest + 1 && elementData[idx] == null);
|
||||
return next;
|
||||
}
|
||||
|
||||
@ -100,7 +88,7 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
|
||||
public void put(int index, T t) {
|
||||
if (t == null)
|
||||
throw new IllegalArgumentException("t cannot be null");
|
||||
throw new IllegalArgumentException("'t' cannot be null.");
|
||||
++modCount;
|
||||
if (index > highest)
|
||||
highest = index;
|
||||
|
Loading…
Reference in New Issue
Block a user