mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-24 09:02:01 +01:00
fixes and changes
This commit is contained in:
parent
7fc22a2e27
commit
8dd91596ae
Binary file not shown.
@ -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);
|
||||
|
@ -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()) {
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -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<T> implements Iterable<T> {
|
||||
|
||||
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<T> implements Iterable<T> {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
private final int expected = ByIdArray.this.modCount;
|
||||
private int idx = lowest;
|
||||
|
||||
@Override
|
||||
@ -91,6 +93,8 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
@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();
|
||||
|
Loading…
Reference in New Issue
Block a user