mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-24 17:11:31 +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
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Save an despawn all NPCs
|
// Save and despawn all NPCs
|
||||||
config.save();
|
config.save();
|
||||||
saveNPCs();
|
saveNPCs();
|
||||||
for (NPC npc : npcManager.getSpawnedNPCs())
|
for (NPC npc : npcManager.getAllNPCs())
|
||||||
npc.despawn();
|
npc.despawn();
|
||||||
|
|
||||||
Bukkit.getScheduler().cancelTasks(this);
|
Bukkit.getScheduler().cancelTasks(this);
|
||||||
|
@ -49,7 +49,7 @@ public class EventListen implements Listener {
|
|||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (NPC npc : npcManager.getSpawnedNPCs()) {
|
for (NPC npc : npcManager.getAllNPCs()) {
|
||||||
Location loc = npc.getBukkitEntity().getLocation();
|
Location loc = npc.getBukkitEntity().getLocation();
|
||||||
if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX()
|
if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX()
|
||||||
&& event.getChunk().getZ() == loc.getChunk().getZ()) {
|
&& event.getChunk().getZ() == loc.getChunk().getZ()) {
|
||||||
|
@ -61,10 +61,12 @@ public class NPCCommands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
respawn.spawn(player.getLocation());
|
if (respawn.spawn(player.getLocation())) {
|
||||||
npcManager.selectNPC(player, respawn);
|
npcManager.selectNPC(player, respawn);
|
||||||
Messaging.send(player, ChatColor.GREEN + "You respawned " + StringHelper.wrap(respawn.getName())
|
Messaging.send(player, ChatColor.GREEN + "You respawned " + StringHelper.wrap(respawn.getName())
|
||||||
+ " at your location.");
|
+ " at your location.");
|
||||||
|
} else
|
||||||
|
Messaging.sendError(player, respawn.getName() + " is already spawned at another location.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
|
@ -29,10 +29,10 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void despawn() {
|
public boolean despawn() {
|
||||||
if (!isSpawned()) {
|
if (!isSpawned()) {
|
||||||
Messaging.debug("The NPC with the ID '" + getId() + "' is already despawned.");
|
Messaging.debug("The NPC with the ID '" + getId() + "' is already despawned.");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this));
|
Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this));
|
||||||
@ -42,6 +42,7 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
|
|
||||||
spawned = false;
|
spawned = false;
|
||||||
save();
|
save();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,16 +72,16 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void spawn(Location loc) {
|
public boolean spawn(Location loc) {
|
||||||
if (isSpawned()) {
|
if (isSpawned()) {
|
||||||
Messaging.debug("The NPC with the ID '" + getId() + "' is already spawned.");
|
Messaging.debug("The NPC with the ID '" + getId() + "' is already spawned.");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, loc);
|
NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, loc);
|
||||||
Bukkit.getPluginManager().callEvent(spawnEvent);
|
Bukkit.getPluginManager().callEvent(spawnEvent);
|
||||||
if (spawnEvent.isCancelled())
|
if (spawnEvent.isCancelled())
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (mcEntity == null)
|
if (mcEntity == null)
|
||||||
mcEntity = manager.spawn(this, loc);
|
mcEntity = manager.spawn(this, loc);
|
||||||
@ -92,6 +93,7 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
|
|
||||||
spawned = true;
|
spawned = true;
|
||||||
save();
|
save();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.citizensnpcs.util;
|
package net.citizensnpcs.util;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.ConcurrentModificationException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ public class ByIdArray<T> implements Iterable<T> {
|
|||||||
|
|
||||||
public ByIdArray(int capacity) {
|
public ByIdArray(int capacity) {
|
||||||
if (capacity < 0)
|
if (capacity < 0)
|
||||||
throw new IllegalArgumentException("illegal capacity");
|
throw new IllegalArgumentException("Capacity cannot be less than 0.");
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
elementData = new Object[capacity];
|
elementData = new Object[capacity];
|
||||||
}
|
}
|
||||||
@ -81,6 +82,7 @@ public class ByIdArray<T> implements Iterable<T> {
|
|||||||
@Override
|
@Override
|
||||||
public Iterator<T> iterator() {
|
public Iterator<T> iterator() {
|
||||||
return new Iterator<T>() {
|
return new Iterator<T>() {
|
||||||
|
private final int expected = ByIdArray.this.modCount;
|
||||||
private int idx = lowest;
|
private int idx = lowest;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -91,6 +93,8 @@ public class ByIdArray<T> implements Iterable<T> {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public T next() {
|
public T next() {
|
||||||
|
if (ByIdArray.this.modCount != expected)
|
||||||
|
throw new ConcurrentModificationException();
|
||||||
T next = (T) elementData[idx];
|
T next = (T) elementData[idx];
|
||||||
if (next == null || idx > highest)
|
if (next == null || idx > highest)
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
|
Loading…
Reference in New Issue
Block a user