BREAKING: rename methods

This commit is contained in:
fullwall 2012-05-17 21:34:03 +08:00
parent 41ddb6851b
commit 22ced5b02b
15 changed files with 106 additions and 109 deletions

View File

@ -12,6 +12,7 @@ import net.citizensnpcs.api.CitizensPlugin;
import net.citizensnpcs.api.event.CitizensReloadEvent;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.npc.character.CharacterManager;
import net.citizensnpcs.api.scripting.EventRegistrar;
import net.citizensnpcs.api.scripting.ObjectProvider;
@ -37,7 +38,7 @@ import net.citizensnpcs.command.exception.WrappedCommandException;
import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.npc.CitizensCharacterManager;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.CitizensNPCRegistry;
import net.citizensnpcs.npc.CitizensTraitManager;
import net.citizensnpcs.npc.NPCSelector;
import net.citizensnpcs.util.Messaging;
@ -61,8 +62,8 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
private boolean compatible;
private Settings config;
private ClassLoader contextClassLoader;
private CitizensNPCManager npcManager;
private Storage saves;
private CitizensNPCRegistry npcRegistry;
private Storage saves; // TODO: refactor this, it's used in too many places
private NPCSelector selector;
private TraitManager traitManager;
@ -71,13 +72,13 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
return characterManager;
}
public CommandManager getCommandManager() {
return commands; // TODO: this doesn't need to be exposed.
public Iterable<net.citizensnpcs.command.Command> getCommands(String base) {
return commands.getCommands(base);
}
@Override
public CitizensNPCManager getNPCManager() {
return npcManager;
public NPCRegistry getNPCRegistry() {
return npcRegistry;
}
public NPCSelector getNPCSelector() {
@ -147,7 +148,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
if (compatible) {
save();
despawnNPCs();
npcManager = null;
npcRegistry = null;
getServer().getScheduler().cancelTasks(this);
}
@ -171,12 +172,12 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
setupStorage();
npcManager = new CitizensNPCManager(saves);
npcRegistry = new CitizensNPCRegistry(saves);
traitManager = new CitizensTraitManager(this);
selector = new NPCSelector(this);
CitizensAPI.setImplementation(this);
getServer().getPluginManager().registerEvents(new EventListen(npcManager), this);
getServer().getPluginManager().registerEvents(new EventListen(), this);
registerCommands();
@ -231,7 +232,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
}
private void despawnNPCs() {
Iterator<NPC> itr = npcManager.iterator();
Iterator<NPC> itr = npcRegistry.iterator();
while (itr.hasNext()) {
NPC npc = itr.next();
itr.remove();
@ -240,7 +241,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
}
public void save() {
for (NPC npc : npcManager)
for (NPC npc : npcRegistry)
((CitizensNPC) npc).save(saves.getKey("npc." + npc.getId()));
saves.save();
@ -267,7 +268,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
continue;
}
}
NPC npc = npcManager.createNPC(type, id, key.getString("name"), null);
NPC npc = npcRegistry.createNPC(type, id, key.getString("name"), null);
((CitizensNPC) npc).load(key);
++created;
@ -315,7 +316,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
metrics.addCustomData(new Metrics.Plotter("Total NPCs") {
@Override
public int getValue() {
return Iterators.size(npcManager.iterator());
return Iterators.size(npcRegistry.iterator());
}
});
Metrics.Graph graph = metrics.createGraph("Character Type Usage");

View File

@ -1,13 +1,14 @@
package net.citizensnpcs;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCDamageByEntityEvent;
import net.citizensnpcs.api.event.NPCDamageEvent;
import net.citizensnpcs.api.event.NPCLeftClickEvent;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.entity.EntityHumanNPC;
import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.trait.text.Text;
@ -39,13 +40,9 @@ import com.google.common.collect.ListMultimap;
import com.google.gson.internal.Pair;
public class EventListen implements Listener {
private volatile CitizensNPCManager npcManager;
private final NPCRegistry npcManager = CitizensAPI.getNPCRegistry();
private final ListMultimap<Pair<Integer, Integer>, Integer> toRespawn = ArrayListMultimap.create();
public EventListen(CitizensNPCManager npcManager) {
this.npcManager = npcManager;
}
/*
* Chunk events
*/

View File

@ -9,7 +9,6 @@ import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.command.Command;
import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.CommandManager;
import net.citizensnpcs.command.Requirements;
import net.citizensnpcs.command.ServerCommand;
import net.citizensnpcs.command.exception.CommandException;
@ -19,10 +18,10 @@ import org.bukkit.command.CommandSender;
@Requirements
public class HelpCommands {
private final CommandManager cmdManager;
private final Citizens plugin;
public HelpCommands(Citizens plugin) {
cmdManager = plugin.getCommandManager();
this.plugin = plugin;
}
@Command(
@ -48,7 +47,7 @@ public class HelpCommands {
// Ensures that commands with multiple modifiers are only added once
Set<Command> cmds = new HashSet<Command>();
List<String> lines = new ArrayList<String>();
for (Command cmd : cmdManager.getCommands(baseCommand)) {
for (Command cmd : plugin.getCommands(baseCommand)) {
if (cmds.contains(cmd)
|| (!sender.hasPermission("citizens.admin") && !sender
.hasPermission("citizens." + cmd.permission())))

View File

@ -7,6 +7,7 @@ import net.citizensnpcs.Citizens;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.npc.character.Character;
import net.citizensnpcs.api.npc.character.CharacterManager;
import net.citizensnpcs.api.trait.trait.MobType;
@ -18,7 +19,6 @@ 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;
import net.citizensnpcs.npc.NPCSelector;
import net.citizensnpcs.trait.Age;
import net.citizensnpcs.trait.Behaviour;
@ -46,11 +46,11 @@ import com.google.common.base.Splitter;
@Requirements(selected = true, ownership = true)
public class NPCCommands {
private final CharacterManager characterManager = CitizensAPI.getCharacterManager();
private final CitizensNPCManager npcManager;
private final NPCRegistry npcRegistry;
private final NPCSelector selector;
public NPCCommands(Citizens plugin) {
npcManager = plugin.getNPCManager();
npcRegistry = CitizensAPI.getNPCRegistry();
selector = plugin.getNPCSelector();
}
@ -154,7 +154,7 @@ public class NPCCommands {
type = EntityType.PLAYER;
}
}
npc = npcManager.createNPC(type, name);
npc = npcRegistry.createNPC(type, name);
String msg = ChatColor.GREEN + "You created " + StringHelper.wrap(npc.getName());
if (args.hasValueFlag("char")) {
String character = args.getFlag("char").toLowerCase();
@ -240,17 +240,17 @@ public class NPCCommands {
List<NPC> npcs = new ArrayList<NPC>();
if (args.hasFlag('a')) {
for (NPC add : npcManager)
for (NPC add : npcRegistry)
npcs.add(add);
} else if (args.getValueFlags().size() == 0 && sender instanceof Player) {
for (NPC add : npcManager) {
for (NPC add : npcRegistry) {
if (!npcs.contains(add) && add.getTrait(Owner.class).isOwnedBy(sender))
npcs.add(add);
}
} else {
if (args.hasValueFlag("owner")) {
String name = args.getFlag("owner");
for (NPC add : npcManager) {
for (NPC add : npcRegistry) {
if (!npcs.contains(add) && add.getTrait(Owner.class).isOwnedBy(name))
npcs.add(add);
}
@ -262,7 +262,7 @@ public class NPCCommands {
if (EntityType.fromName(type.replace('-', '_')) == null)
throw new CommandException("'" + type + "' is not a valid mob type.");
for (NPC add : npcManager) {
for (NPC add : npcRegistry) {
if (!npcs.contains(add) && add.getTrait(MobType.class).getType().equalsIgnoreCase(type))
npcs.add(add);
}
@ -273,7 +273,7 @@ public class NPCCommands {
if (characterManager.getCharacter(character) == null)
throw new CommandException("'" + character + "' is not a valid character.");
for (NPC add : npcManager.getNPCs(characterManager.getCharacter(character).getClass())) {
for (NPC add : npcRegistry.getNPCs(characterManager.getCharacter(character).getClass())) {
if (!npcs.contains(add))
npcs.add(add);
}
@ -394,7 +394,7 @@ public class NPCCommands {
throw new CommandException("Incorrect syntax. /npc remove (all)");
if (!sender.hasPermission("citizens.npc.remove.all") && !sender.hasPermission("citizens.admin"))
throw new NoPermissionsException();
npcManager.removeAll();
npcRegistry.deregisterAll();
Messaging.send(sender, "<a>You permanently removed all NPCs.");
return;
}
@ -443,7 +443,7 @@ public class NPCCommands {
@Requirements(ownership = true)
@ServerCommand
public void select(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
NPC toSelect = npcManager.getNPC(args.getInteger(1));
NPC toSelect = npcRegistry.getNPC(args.getInteger(1));
if (toSelect == null || !toSelect.getTrait(Spawned.class).shouldSpawn())
throw new CommandException("No NPC with the ID '" + args.getInteger(1) + "' is spawned.");
if (npc != null && toSelect.getId() == npc.getId())
@ -462,7 +462,7 @@ public class NPCCommands {
permission = "npc.spawn")
@Requirements
public void spawn(CommandContext args, Player player, NPC npc) throws CommandException {
NPC respawn = npcManager.getNPC(args.getInteger(1));
NPC respawn = npcRegistry.getNPC(args.getInteger(1));
if (respawn == null)
throw new CommandException("No NPC with the ID '" + args.getInteger(1) + "' exists.");

View File

@ -2,7 +2,6 @@ package net.citizensnpcs.editor;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.util.Messaging;
import org.bukkit.entity.Player;
@ -40,15 +39,12 @@ public class EquipmentEditor extends Editor {
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!CitizensAPI.getNPCManager().isNPC(event.getRightClicked())
|| !CitizensAPI.getNPCManager().getNPC(event.getRightClicked()).equals(npc)
if (!npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked()))
|| !event.getPlayer().equals(player))
return;
CitizensNPC handle = (CitizensNPC) npc;
if (!(handle instanceof Equipable))
return;
((Equipable) handle).equip(event.getPlayer());
if (npc instanceof Equipable) {
((Equipable) npc).equip(event.getPlayer());
}
}
}

View File

@ -37,7 +37,7 @@ public class CitizensCharacterManager implements CharacterManager {
graph.addPlotter(new Metrics.Plotter(StringHelper.capitalize(character.getName())) {
@Override
public int getValue() {
return CitizensAPI.getNPCManager().getNPCs(character.getClass()).size();
return CitizensAPI.getNPCRegistry().getNPCs(character.getClass()).size();
}
});
}

View File

@ -95,6 +95,13 @@ public abstract class CitizensNPC extends AbstractNPC {
}
public void load(DataKey root) {
// Spawn the NPC
if (getTrait(Spawned.class).shouldSpawn()) {
Location spawnLoc = getTrait(CurrentLocation.class).getLocation();
if (spawnLoc != null)
spawn(spawnLoc);
}
Character character = CitizensAPI.getCharacterManager().getCharacter(root.getString("character"));
// Load the character if it exists
@ -102,8 +109,8 @@ public abstract class CitizensNPC extends AbstractNPC {
try {
character.load(root.getRelative("characters." + character.getName()));
} catch (NPCLoadException e) {
Messaging.severe(String.format("Unable to load character '%s'.", character.getName()));
e.printStackTrace();
Messaging.severe(String.format("Unable to load character '%s': %s.", character.getName(),
e.getMessage()));
}
setCharacter(character);
}
@ -113,34 +120,25 @@ public abstract class CitizensNPC extends AbstractNPC {
Trait trait = traitManager.getTrait(traitKey.name(), this);
if (trait == null) {
Messaging.severe(String.format(
"Found missing trait '%s' while loading NPC ID: '%d' - skipped. Has the name changed?",
"Skipped missing trait '%s' while loading NPC ID: '%d'. Has the name changed?",
traitKey.name(), getId()));
continue;
}
addTrait(trait);
try {
getTrait(trait.getClass()).load(traitKey);
} catch (Exception ex) {
Messaging.log(String.format("The trait '%s' failed to load properly for NPC ID: '%d'.",
traitKey.name(), getId()), ex.getMessage());
ex.printStackTrace();
} catch (NPCLoadException ex) {
Messaging.log(
String.format("The trait '%s' failed to load for NPC ID: '%d'.", traitKey.name(), getId()),
ex.getMessage());
}
}
// Spawn the NPC
if (getTrait(Spawned.class).shouldSpawn()) {
Location spawnLoc = getTrait(CurrentLocation.class).getLocation();
if (spawnLoc != null)
spawn(spawnLoc);
}
}
@Override
public void remove() {
super.remove();
CitizensAPI.getNPCManager().deregister(this);
if (isSpawned())
despawn();
CitizensAPI.getNPCRegistry().deregister(this);
}
public void save(DataKey root) {

View File

@ -8,7 +8,7 @@ import java.util.List;
import java.util.Map;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCManager;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.npc.character.Character;
import net.citizensnpcs.api.util.Storage;
import net.citizensnpcs.npc.ai.NPCHandle;
@ -45,13 +45,13 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
public class CitizensNPCManager implements NPCManager {
public class CitizensNPCRegistry implements NPCRegistry {
private final ByIdArray<NPC> npcs = new ByIdArray<NPC>();
private final Storage saves;
private final Map<EntityType, Class<? extends CitizensNPC>> types = new EnumMap<EntityType, Class<? extends CitizensNPC>>(
EntityType.class);
public CitizensNPCManager(Storage saves) {
public CitizensNPCRegistry(Storage saves) {
this.saves = saves;
types.put(EntityType.BLAZE, CitizensBlazeNPC.class);
@ -152,9 +152,11 @@ public class CitizensNPCManager implements NPCManager {
public void deregister(NPC npc) {
npcs.remove(npc.getId());
saves.getKey("npc").removeKey(String.valueOf(npc.getId()));
npc.despawn();
}
public void removeAll() {
@Override
public void deregisterAll() {
Iterator<NPC> itr = iterator();
while (itr.hasNext()) {
NPC npc = itr.next();

View File

@ -98,8 +98,8 @@ public class CitizensTraitManager implements TraitManager {
Trait trait = create(subEntry.getValue(), npc);
if (trait == null)
return null;
trait.setName(subEntry.getKey());
trait.setPlugin(entry.getKey());
trait.setName(subEntry.getKey());
return (T) trait;
}
}

View File

@ -76,7 +76,7 @@ public class NPCSelector implements Listener {
// Remove editor if the player has one
Editor.leave(player);
} else {
this.consoleSelectedNPC = npc.getId();
consoleSelectedNPC = npc.getId();
npc.setMetadata("selectors", new FixedMetadataValue(plugin, "console"));
}
@ -88,11 +88,11 @@ public class NPCSelector implements Listener {
List<MetadataValue> metadata = ((Player) sender).getMetadata("selected");
if (metadata.size() == 0)
return null;
return CitizensAPI.getNPCManager().getNPC(metadata.get(0).asInt());
return CitizensAPI.getNPCRegistry().getNPC(metadata.get(0).asInt());
} else {
if (consoleSelectedNPC == -1)
return null;
return CitizensAPI.getNPCManager().getNPC(consoleSelectedNPC);
return CitizensAPI.getNPCRegistry().getNPC(consoleSelectedNPC);
}
}
}

View File

@ -1,12 +1,12 @@
package net.citizensnpcs.trait;
import org.bukkit.entity.Ageable;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import org.bukkit.entity.Ageable;
public class Age extends Trait implements Runnable, Toggleable {
private int age = 0;
private boolean locked = true;
@ -18,18 +18,18 @@ public class Age extends Trait implements Runnable, Toggleable {
@Override
public void load(DataKey key) throws NPCLoadException {
if (!(npc.getBukkitEntity() instanceof Ageable))
throw new NPCLoadException("NPC must be ageable");
age = key.getInt("age");
locked = key.getBoolean("locked");
}
@Override
public void onNPCSpawn() {
if (npc.getBukkitEntity() instanceof Ageable) {
Ageable entity = (Ageable) npc.getBukkitEntity();
entity.setAge(age);
entity.setAgeLock(locked);
}
}
@Override
public void run() {
@ -45,7 +45,6 @@ public class Age extends Trait implements Runnable, Toggleable {
public void setAge(int age) {
this.age = age;
if (npc.getBukkitEntity() instanceof Ageable)
((Ageable) npc.getBukkitEntity()).setAge(age);
}

View File

@ -1,11 +1,12 @@
package net.citizensnpcs.trait;
import org.bukkit.entity.Creeper;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import org.bukkit.entity.Creeper;
public class Powered extends Trait implements Toggleable {
private final NPC npc;
private boolean powered;
@ -15,13 +16,14 @@ public class Powered extends Trait implements Toggleable {
}
@Override
public void load(DataKey key) {
public void load(DataKey key) throws NPCLoadException {
if (!(npc.getBukkitEntity() instanceof Creeper))
throw new NPCLoadException("NPC must be a creeper");
powered = key.getBoolean("");
}
@Override
public void onNPCSpawn() {
if (npc.getBukkitEntity() instanceof Creeper)
((Creeper) npc.getBukkitEntity()).setPowered(powered);
}

View File

@ -1,16 +1,16 @@
package net.citizensnpcs.trait;
import org.bukkit.entity.Pig;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import org.bukkit.entity.Pig;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
public class Saddle extends Trait implements Toggleable, Listener {
private final NPC npc;
private boolean saddle;
@ -21,18 +21,19 @@ public class Saddle extends Trait implements Toggleable, Listener {
@Override
public void load(DataKey key) throws NPCLoadException {
if (!(npc.getBukkitEntity() instanceof Pig))
throw new NPCLoadException("NPC must be a pig to have this trait");
saddle = key.getBoolean("");
}
@Override
public void onNPCSpawn() {
if (npc.getBukkitEntity() instanceof Pig)
((Pig) npc.getBukkitEntity()).setSaddle(saddle);
}
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (CitizensAPI.getNPCManager().isNPC(event.getRightClicked()))
if (npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked())))
event.setCancelled(true);
}

View File

@ -1,16 +1,16 @@
package net.citizensnpcs.trait;
import org.bukkit.entity.Sheep;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerShearEntityEvent;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import org.bukkit.entity.Sheep;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerShearEntityEvent;
public class Sheared extends Trait implements Toggleable, Listener {
private final NPC npc;
private boolean sheared;
@ -21,18 +21,19 @@ public class Sheared extends Trait implements Toggleable, Listener {
@Override
public void load(DataKey key) throws NPCLoadException {
if (!(npc.getBukkitEntity() instanceof Sheep))
throw new NPCLoadException("NPC must be a sheep to be sheared");
sheared = key.getBoolean("");
}
@Override
public void onNPCSpawn() {
if (npc.getBukkitEntity() instanceof Sheep)
((Sheep) npc.getBukkitEntity()).setSheared(sheared);
}
@EventHandler
public void onPlayerShearEntityEvent(PlayerShearEntityEvent event) {
if (CitizensAPI.getNPCManager().isNPC(event.getEntity()))
if (npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getEntity())))
event.setCancelled(true);
}

View File

@ -1,17 +1,17 @@
package net.citizensnpcs.trait;
import org.bukkit.DyeColor;
import org.bukkit.entity.Sheep;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.SheepDyeWoolEvent;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import org.bukkit.DyeColor;
import org.bukkit.entity.Sheep;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.SheepDyeWoolEvent;
public class WoolColor extends Trait implements Listener {
private DyeColor color = DyeColor.WHITE;
private final NPC npc;
@ -22,6 +22,8 @@ public class WoolColor extends Trait implements Listener {
@Override
public void load(DataKey key) throws NPCLoadException {
if (!(npc.getBukkitEntity() instanceof Sheep))
throw new NPCLoadException("NPC must be a sheep");
try {
color = DyeColor.valueOf(key.getString(""));
} catch (Exception ex) {
@ -31,13 +33,12 @@ public class WoolColor extends Trait implements Listener {
@Override
public void onNPCSpawn() {
if (npc.getBukkitEntity() instanceof Sheep)
((Sheep) npc.getBukkitEntity()).setColor(color);
}
@EventHandler
public void onSheepDyeWool(SheepDyeWoolEvent event) {
if (CitizensAPI.getNPCManager().isNPC(event.getEntity()))
if (npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getEntity())))
event.setCancelled(true);
}