mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-28 15:17:43 +02:00
Fix bugs
This commit is contained in:
parent
2688ae902f
commit
34622b0ba3
@ -15,6 +15,7 @@ import net.citizensnpcs.api.trait.trait.Spawned;
|
||||
import net.citizensnpcs.command.Command;
|
||||
import net.citizensnpcs.command.CommandContext;
|
||||
import net.citizensnpcs.command.Requirements;
|
||||
import net.citizensnpcs.command.ServerCommand;
|
||||
import net.citizensnpcs.command.exception.CommandException;
|
||||
import net.citizensnpcs.command.exception.NoPermissionsException;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
@ -32,6 +33,7 @@ import net.citizensnpcs.util.Paginator;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -140,6 +142,7 @@ public class NPCCommands {
|
||||
type = EntityType.PLAYER;
|
||||
}
|
||||
}
|
||||
Messaging.log(type);
|
||||
npc = npcManager.createNPC(type, name);
|
||||
String msg = ChatColor.GREEN + "You created " + StringHelper.wrap(npc.getName());
|
||||
if (args.hasValueFlag("char")) {
|
||||
@ -216,15 +219,16 @@ public class NPCCommands {
|
||||
max = 2,
|
||||
permission = "npc.list")
|
||||
@Requirements
|
||||
public void list(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||
@ServerCommand
|
||||
public void list(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
List<NPC> npcs = new ArrayList<NPC>();
|
||||
|
||||
if (args.hasFlag('a')) {
|
||||
for (NPC add : npcManager)
|
||||
npcs.add(add);
|
||||
} else if (args.getValueFlags().size() == 0 && args.argsLength() == 1 || args.argsLength() == 2) {
|
||||
} else if (args.getValueFlags().size() == 0 && sender instanceof Player) {
|
||||
for (NPC add : npcManager) {
|
||||
if (!npcs.contains(add) && add.getTrait(Owner.class).isOwner(player))
|
||||
if (!npcs.contains(add) && add.getTrait(Owner.class).isOwner((Player) sender))
|
||||
npcs.add(add);
|
||||
}
|
||||
} else {
|
||||
@ -270,7 +274,7 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
int page = args.getInteger(1, 1);
|
||||
if (!paginator.sendPage(player, page))
|
||||
if (!paginator.sendPage(sender, page))
|
||||
throw new CommandException("The page '" + page + "' does not exist.");
|
||||
}
|
||||
|
||||
@ -364,16 +368,20 @@ public class NPCCommands {
|
||||
min = 1,
|
||||
max = 2)
|
||||
@Requirements
|
||||
public void remove(CommandContext args, Player player, NPC npc) throws CommandException {
|
||||
@ServerCommand
|
||||
public void remove(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
if (args.argsLength() == 2) {
|
||||
if (!args.getString(1).equals("all"))
|
||||
if (!args.getString(1).equalsIgnoreCase("all"))
|
||||
throw new CommandException("Incorrect syntax. /npc remove (all)");
|
||||
if (!player.hasPermission("citizens.npc.remove.all") && !player.hasPermission("citizens.admin"))
|
||||
if (!sender.hasPermission("citizens.npc.remove.all") && !sender.hasPermission("citizens.admin"))
|
||||
throw new NoPermissionsException();
|
||||
npcManager.removeAll();
|
||||
Messaging.send(player, "<a>You permanently removed all NPCs.");
|
||||
Messaging.send(sender, "<a>You permanently removed all NPCs.");
|
||||
return;
|
||||
}
|
||||
if (!(sender instanceof Player))
|
||||
throw new CommandException("You must be ingame to use this command");
|
||||
Player player = (Player) sender;
|
||||
if (npc == null)
|
||||
throw new CommandException("You must have an NPC selected to execute that command.");
|
||||
if (!npc.getTrait(Owner.class).isOwner(player))
|
||||
|
@ -38,6 +38,8 @@ public class CitizensNPCManager implements NPCManager {
|
||||
|
||||
public NPC createNPC(EntityType type, int id, String name, Character character) {
|
||||
CitizensNPC npc = npcBuilder.getByType(type, this, id, name);
|
||||
if (npc == null)
|
||||
throw new IllegalStateException("could not create npc");
|
||||
if (character != null)
|
||||
npc.setCharacter(character);
|
||||
npcs.put(npc.getId(), npc);
|
||||
@ -106,14 +108,22 @@ public class CitizensNPCManager implements NPCManager {
|
||||
|
||||
public void remove(NPC npc) {
|
||||
npcs.remove(npc.getId());
|
||||
saves.getKey("npc").removeKey(String.valueOf(npc.getId()));
|
||||
removeMetadata(npc);
|
||||
removeData(npc);
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
Iterator<NPC> itr = iterator();
|
||||
while (itr.hasNext())
|
||||
itr.next().remove();
|
||||
while (itr.hasNext()) {
|
||||
NPC npc = itr.next();
|
||||
npc.despawn();
|
||||
removeData(npc);
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private void removeData(NPC npc) {
|
||||
saves.getKey("npc").removeKey(String.valueOf(npc.getId()));
|
||||
removeMetadata(npc);
|
||||
}
|
||||
|
||||
private void removeMetadata(NPC npc) {
|
||||
|
@ -33,7 +33,8 @@ public class CitizensZombieNPC extends CitizensMobNPC {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void d_() {
|
||||
public void z_() {
|
||||
super.z_();
|
||||
npc.update();
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
private int size;
|
||||
|
||||
public ByIdArray() {
|
||||
this(1000);
|
||||
this(100);
|
||||
}
|
||||
|
||||
public ByIdArray(int capacity) {
|
||||
@ -138,22 +138,16 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
recalcHighest();
|
||||
if (lowest == Integer.MAX_VALUE || elementData[lowest] == null)
|
||||
recalcLowest();
|
||||
idx = lowest;
|
||||
if (elementData[lowest] == null) {
|
||||
idx = 0;
|
||||
while (elementData.length > idx && elementData[idx++] == null)
|
||||
;
|
||||
if (elementData[idx] == null)
|
||||
Messaging.debug("idx is still null!");
|
||||
}
|
||||
idx = lowest - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (modCount != expected)
|
||||
if (modCount != expected) {
|
||||
throw new ConcurrentModificationException();
|
||||
return size > 0 && highest + 1 > idx;
|
||||
}
|
||||
return size > 0 && highest > idx;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -161,12 +155,14 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
public T next() {
|
||||
if (modCount != expected)
|
||||
throw new ConcurrentModificationException();
|
||||
T next = (T) elementData[idx];
|
||||
if (next == null || idx > highest)
|
||||
if (idx > highest)
|
||||
throw new NoSuchElementException();
|
||||
do
|
||||
idx++;
|
||||
while (idx != highest + 1 && elementData[idx] == null);
|
||||
T next = (T) elementData[idx];
|
||||
if (next == null)
|
||||
throw new NoSuchElementException();
|
||||
return next;
|
||||
}
|
||||
|
||||
@ -176,11 +172,6 @@ public class ByIdArray<T> implements Iterable<T> {
|
||||
throw new ConcurrentModificationException();
|
||||
fastRemove(idx);
|
||||
expected = modCount;
|
||||
if (hasNext()) {
|
||||
do
|
||||
idx++;
|
||||
while (idx != highest + 1 && elementData[idx] == null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user