more stubborn formatting

This commit is contained in:
aPunch 2012-01-22 08:23:25 -06:00
parent 0a5e84b1f0
commit 3ec65fb8ef
8 changed files with 26 additions and 48 deletions

View File

@ -83,9 +83,8 @@ public class Citizens extends JavaPlugin {
NPC npc = npcManager.createNPC("aPunch");
npc.spawn(((Player) sender).getLocation());
} else if (args[0].equals("despawn")) {
for (NPC npc : npcManager.getSpawnedNPCs()) {
for (NPC npc : npcManager.getSpawnedNPCs())
npc.despawn();
}
}
return true;
}
@ -101,9 +100,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() + "'.");

View File

@ -39,9 +39,8 @@ public class EventListen implements Listener {
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());
}
}
}
}

View File

@ -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
@ -130,15 +129,13 @@ public class CitizensNPC implements NPC {
NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, loc);
Bukkit.getPluginManager().callEvent(spawnEvent);
if (spawnEvent.isCancelled()) {
if (spawnEvent.isCancelled())
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 +159,8 @@ public class CitizensNPC implements NPC {
@Override
public void remove() {
if (isSpawned()) {
if (isSpawned())
despawn();
}
manager.remove(this);
}

View File

@ -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("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("already despawned");
CraftNPC mcEntity = ((CitizensNPC) npc).getHandle();
for (Player player : Bukkit.getOnlinePlayers()) {
((CraftPlayer) player).getHandle().netServerHandler.sendPacket(new Packet29DestroyEntity(mcEntity.id));

View File

@ -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);
}

View File

@ -9,7 +9,7 @@ import org.junit.Test;
public class ByIdArrayTest {
@Test
public void testInsert() {
ByIdArray<String> test = ByIdArray.create();
ByIdArray<String> test = new ByIdArray<String>();
test.put(0, "one");
assert (test.get(0).equals("one"));
assert (test.contains(0));
@ -22,19 +22,16 @@ public class ByIdArrayTest {
@Test
public void testIteration() {
int iterations = 1000;
ByIdArray<String> test = ByIdArray.create();
ByIdArray<String> test = new ByIdArray<String>();
String[] values = new String[iterations];
for (int i = 0; i < values.length; ++i) {
for (int i = 0; i < values.length; ++i)
values[i] = Integer.toString(i);
}
Random random = new Random(100);
int index = 0;
for (String value : values) {
for (String value : values)
test.put((index += random.nextInt(10) + 1), value);
}
index = 0;
for (String value : test) {
for (String value : test)
assert (value.equals(values[index++]));
}
}
}
}

View File

@ -1,11 +1,11 @@
package net.citizensnpcs.test;
//import org.junit.Test;
import org.junit.Test;
public class StorageTest {
// @Test
@Test
public void testYaml() {
}
}
}

View File

@ -73,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;
}
@ -88,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("The variable 't' cannot be null.");
++modCount;
if (index > highest)
highest = index;
@ -130,16 +130,8 @@ public class ByIdArray<T> implements Iterable<T> {
if (elementData.length > highest)
elementData = Arrays.copyOf(elementData, highest + 1);
}
public boolean contains(int index) {
return elementData.length > index && elementData[index] != null;
}
public static <T> ByIdArray<T> create() {
return new ByIdArray<T>();
}
public static <T> ByIdArray<T> create(int capacity) {
return new ByIdArray<T>(capacity);
}
}
}