From 8dd91596ae5c26d18c814c9388aa81da2b794a19 Mon Sep 17 00:00:00 2001 From: aPunch Date: Thu, 26 Jan 2012 08:45:42 -0600 Subject: [PATCH] fixes and changes --- lib/CitizensAPI.jar | Bin 17709 -> 17709 bytes src/net/citizensnpcs/Citizens.java | 4 ++-- src/net/citizensnpcs/EventListen.java | 2 +- .../command/command/NPCCommands.java | 10 ++++++---- src/net/citizensnpcs/npc/CitizensNPC.java | 12 +++++++----- src/net/citizensnpcs/util/ByIdArray.java | 6 +++++- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/CitizensAPI.jar b/lib/CitizensAPI.jar index 9018a757de4c03bdba39e1d43c095757b45d6135..33c46ed91e0859d5aba2d4adb21cc6b1cb2a8ffc 100644 GIT binary patch delta 257 zcmZ46#kjVMkvG7bnT3l11m-$hP2|;Jp5tt_(c-DJAdu^z*TO&L8zTe5UKR!hrOAw% zGMl|*;u!1G<~E-3So-Bpl&+*^g|nk^oRaf~>x{`)6&AI&rA zv%ML_xKvAC&h)<8X@#5iw-xvfe>!?<-xvQS>0UfM#UAT^vl_KBIYhXeTr@dRl3PqX zaAU+#*-Lj-ugXl*h|#_yAjgKmGgM%>ZEHgSu82+G~IQS#rA_fd0RWKAD$_v{;+ zekgUvKbm^<`po{^9aFl+(vA21-=!MCDEG$4?+H7v=&c*@r)8;n&<*Wcv CS7+k@ delta 257 zcmZ46#kjVMkvG7bnT3l11WY?DC-Q1An{-%iw0J5lD5hlTplcML{*94=VJ`~>n&Wq2Kx0P-x(VV?yedVvIF*;?7 z3*Vfa#--u;^TUdtW|3?s|J`IOl$fR;_HAjsl5KEO!VKr4yZRHXMHmh#d5O*CIUTWK zM@QFDt#=dN>8*UW!R4dTyQhVdo-<}u?s594CHL&3)Y1MAH=Zd~HkEe!e?0T3I49!H zk!eT8D>6TZwyigozg?gyu6r)6=Ck-_Pq__J%s?Ma{$pVQ^3rB=OLsO7n4dPc*)L}W E0F)DJU;qFB diff --git a/src/net/citizensnpcs/Citizens.java b/src/net/citizensnpcs/Citizens.java index 8f9d35c1a..ea6f5e13f 100644 --- a/src/net/citizensnpcs/Citizens.java +++ b/src/net/citizensnpcs/Citizens.java @@ -113,10 +113,10 @@ public class Citizens extends JavaPlugin { @Override public void onDisable() { - // Save an despawn all NPCs + // Save and despawn all NPCs config.save(); saveNPCs(); - for (NPC npc : npcManager.getSpawnedNPCs()) + for (NPC npc : npcManager.getAllNPCs()) npc.despawn(); Bukkit.getScheduler().cancelTasks(this); diff --git a/src/net/citizensnpcs/EventListen.java b/src/net/citizensnpcs/EventListen.java index d63a64929..baf88691b 100644 --- a/src/net/citizensnpcs/EventListen.java +++ b/src/net/citizensnpcs/EventListen.java @@ -49,7 +49,7 @@ public class EventListen implements Listener { if (event.isCancelled()) return; - for (NPC npc : npcManager.getSpawnedNPCs()) { + for (NPC npc : npcManager.getAllNPCs()) { Location loc = npc.getBukkitEntity().getLocation(); if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX() && event.getChunk().getZ() == loc.getChunk().getZ()) { diff --git a/src/net/citizensnpcs/command/command/NPCCommands.java b/src/net/citizensnpcs/command/command/NPCCommands.java index 49343d825..8f3aed9db 100644 --- a/src/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/net/citizensnpcs/command/command/NPCCommands.java @@ -61,10 +61,12 @@ public class NPCCommands { return; } - respawn.spawn(player.getLocation()); - npcManager.selectNPC(player, respawn); - Messaging.send(player, ChatColor.GREEN + "You respawned " + StringHelper.wrap(respawn.getName()) - + " at your location."); + if (respawn.spawn(player.getLocation())) { + npcManager.selectNPC(player, respawn); + Messaging.send(player, ChatColor.GREEN + "You respawned " + StringHelper.wrap(respawn.getName()) + + " at your location."); + } else + Messaging.sendError(player, respawn.getName() + " is already spawned at another location."); } @Command( diff --git a/src/net/citizensnpcs/npc/CitizensNPC.java b/src/net/citizensnpcs/npc/CitizensNPC.java index 156a4f637..4d099fdc1 100644 --- a/src/net/citizensnpcs/npc/CitizensNPC.java +++ b/src/net/citizensnpcs/npc/CitizensNPC.java @@ -29,10 +29,10 @@ public class CitizensNPC extends AbstractNPC { } @Override - public void despawn() { + public boolean despawn() { if (!isSpawned()) { Messaging.debug("The NPC with the ID '" + getId() + "' is already despawned."); - return; + return false; } Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this)); @@ -42,6 +42,7 @@ public class CitizensNPC extends AbstractNPC { spawned = false; save(); + return true; } @Override @@ -71,16 +72,16 @@ public class CitizensNPC extends AbstractNPC { } @Override - public void spawn(Location loc) { + public boolean spawn(Location loc) { if (isSpawned()) { Messaging.debug("The NPC with the ID '" + getId() + "' is already spawned."); - return; + return false; } NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, loc); Bukkit.getPluginManager().callEvent(spawnEvent); if (spawnEvent.isCancelled()) - return; + return false; if (mcEntity == null) mcEntity = manager.spawn(this, loc); @@ -92,6 +93,7 @@ public class CitizensNPC extends AbstractNPC { spawned = true; save(); + return true; } @Override diff --git a/src/net/citizensnpcs/util/ByIdArray.java b/src/net/citizensnpcs/util/ByIdArray.java index 2f6709d54..bf9ed4fcc 100644 --- a/src/net/citizensnpcs/util/ByIdArray.java +++ b/src/net/citizensnpcs/util/ByIdArray.java @@ -1,6 +1,7 @@ package net.citizensnpcs.util; import java.util.Arrays; +import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.NoSuchElementException; @@ -18,7 +19,7 @@ public class ByIdArray implements Iterable { public ByIdArray(int capacity) { if (capacity < 0) - throw new IllegalArgumentException("illegal capacity"); + throw new IllegalArgumentException("Capacity cannot be less than 0."); this.capacity = capacity; elementData = new Object[capacity]; } @@ -81,6 +82,7 @@ public class ByIdArray implements Iterable { @Override public Iterator iterator() { return new Iterator() { + private final int expected = ByIdArray.this.modCount; private int idx = lowest; @Override @@ -91,6 +93,8 @@ public class ByIdArray implements Iterable { @Override @SuppressWarnings("unchecked") public T next() { + if (ByIdArray.this.modCount != expected) + throw new ConcurrentModificationException(); T next = (T) elementData[idx]; if (next == null || idx > highest) throw new NoSuchElementException();