mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-23 07:41:29 +01:00
formatting fun
This commit is contained in:
parent
8ffc62a9a0
commit
2a99446bd5
Binary file not shown.
@ -32,7 +32,7 @@ public class CitizensNPC implements NPC {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.character = character;
|
this.character = character;
|
||||||
manager = (CitizensNPCManager) CitizensAPI.getNPCManager();
|
manager = (CitizensNPCManager) CitizensAPI.getNPCManager();
|
||||||
id = manager.getUniqueID();
|
id = manager.generateUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CitizensNPC(int id, String name, Character character) {
|
public CitizensNPC(int id, String name, Character character) {
|
||||||
@ -59,11 +59,10 @@ public class CitizensNPC implements NPC {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTrait(Trait trait) {
|
public void addTrait(Trait trait) {
|
||||||
if (!hasTrait(trait.getClass())) {
|
if (!hasTrait(trait.getClass()))
|
||||||
traits.put(trait.getClass(), trait);
|
traits.put(trait.getClass(), trait);
|
||||||
} else {
|
else
|
||||||
Messaging.debug("The NPC already has the trait '" + getTrait(trait.getClass()).getName() + "'.");
|
Messaging.debug("The NPC already has the trait '" + getTrait(trait.getClass()).getName() + "'.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -134,11 +133,10 @@ public class CitizensNPC implements NPC {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mcEntity == null) {
|
if (mcEntity == null)
|
||||||
mcEntity = manager.spawn(this, loc);
|
mcEntity = manager.spawn(this, loc);
|
||||||
} else {
|
else
|
||||||
manager.spawn(this, loc);
|
manager.spawn(this, loc);
|
||||||
}
|
|
||||||
|
|
||||||
// Set the location
|
// Set the location
|
||||||
addTrait(new SpawnLocation(loc));
|
addTrait(new SpawnLocation(loc));
|
||||||
@ -162,9 +160,8 @@ public class CitizensNPC implements NPC {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if (isSpawned()) {
|
if (isSpawned())
|
||||||
despawn();
|
despawn();
|
||||||
}
|
|
||||||
manager.remove(this);
|
manager.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
return spawned.contains(entity.getEntityId());
|
return spawned.contains(entity.getEntityId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUniqueID() {
|
public int generateUniqueId() {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (getNPC(count) == null)
|
if (getNPC(count) == null)
|
||||||
@ -89,7 +89,7 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
|
|
||||||
public CraftNPC spawn(NPC npc, Location loc) {
|
public CraftNPC spawn(NPC npc, Location loc) {
|
||||||
if (spawned.contains(npc.getBukkitEntity().getEntityId()))
|
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());
|
WorldServer ws = getWorldServer(loc.getWorld());
|
||||||
CraftNPC mcEntity = new CraftNPC(getMinecraftServer(ws.getServer()), ws, npc.getFullName(),
|
CraftNPC mcEntity = new CraftNPC(getMinecraftServer(ws.getServer()), ws, npc.getFullName(),
|
||||||
new ItemInWorldManager(ws));
|
new ItemInWorldManager(ws));
|
||||||
@ -104,11 +104,10 @@ public class CitizensNPCManager implements NPCManager {
|
|||||||
|
|
||||||
public void despawn(NPC npc) {
|
public void despawn(NPC npc) {
|
||||||
if (!spawned.contains(npc.getBukkitEntity().getEntityId()))
|
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();
|
CraftNPC mcEntity = ((CitizensNPC) npc).getHandle();
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
((CraftPlayer) player).getHandle().netServerHandler.sendPacket(new Packet29DestroyEntity(mcEntity.id));
|
((CraftPlayer) player).getHandle().netServerHandler.sendPacket(new Packet29DestroyEntity(mcEntity.id));
|
||||||
}
|
|
||||||
Location loc = npc.getBukkitEntity().getLocation();
|
Location loc = npc.getBukkitEntity().getLocation();
|
||||||
getWorldServer(loc.getWorld()).removeEntity(mcEntity);
|
getWorldServer(loc.getWorld()).removeEntity(mcEntity);
|
||||||
npc.getTrait(SpawnLocation.class).setLocation(loc);
|
npc.getTrait(SpawnLocation.class).setLocation(loc);
|
||||||
|
@ -13,9 +13,8 @@ public class CitizensTraitManager implements TraitManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Trait getTrait(String name) {
|
public Trait getTrait(String name) {
|
||||||
if (registered.get(name) == null) {
|
if (registered.get(name) == null)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
return registered.get(name).create();
|
return registered.get(name).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ public class CitizensTraitManager implements TraitManager {
|
|||||||
@Override
|
@Override
|
||||||
public void registerTraitWithFactory(String name, Factory<? extends Trait> factory) {
|
public void registerTraitWithFactory(String name, Factory<? extends Trait> factory) {
|
||||||
if (registered.get(name) != null)
|
if (registered.get(name) != null)
|
||||||
throw new IllegalArgumentException("trait factory already registered");
|
throw new IllegalArgumentException("Trait factory already registered.");
|
||||||
registered.put(name, factory);
|
registered.put(name, factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,4 +8,4 @@ public class StorageTest {
|
|||||||
public void testYaml() {
|
public void testYaml() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -49,17 +49,13 @@ public class ByIdArray<T> implements Iterable<T> {
|
|||||||
return (T) elementData[index];
|
return (T) elementData[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@SuppressWarnings("unchecked")
|
/*
|
||||||
public T[] toArray(T[] a) {
|
* @SuppressWarnings("unchecked") public T[] toArray(T[] a) { if (a.length <
|
||||||
if (a.length < size)
|
* size) // Make a new array of a's runtime type, but my contents: return
|
||||||
// Make a new array of a's runtime type, but my contents:
|
* (T[]) Arrays.copyOf(elementData, size, a.getClass());
|
||||||
return (T[]) Arrays.copyOf(elementData, size, a.getClass());
|
* System.arraycopy(elementData, 0, a, 0, size); if (a.length > size)
|
||||||
System.arraycopy(elementData, 0, a, 0, size);
|
* a[size] = null; return a; }
|
||||||
if (a.length > size)
|
*/
|
||||||
a[size] = null;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<T> iterator() {
|
public Iterator<T> iterator() {
|
||||||
@ -136,4 +132,4 @@ public class ByIdArray<T> implements Iterable<T> {
|
|||||||
public boolean contains(int index) {
|
public boolean contains(int index) {
|
||||||
return elementData.length > index && elementData[index] != null;
|
return elementData.length > index && elementData[index] != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user