Added ability to modify NPC age. This addresses CITIZENS-10.

This commit is contained in:
aPunch 2012-03-18 16:14:17 -05:00
parent 8683d6b033
commit 114c83ecdd
7 changed files with 146 additions and 172 deletions

View File

@ -24,21 +24,14 @@ public class AdminCommands {
@Command(aliases = { "citizens" }, desc = "Show basic plugin information", max = 0, permission = "admin") @Command(aliases = { "citizens" }, desc = "Show basic plugin information", max = 0, permission = "admin")
public void citizens(CommandContext args, Player player, NPC npc) { public void citizens(CommandContext args, Player player, NPC npc) {
Messaging.send(player, " " Messaging.send(player,
+ StringHelper.wrapHeader("<e>Citizens v" + plugin.getDescription().getVersion())); " " + StringHelper.wrapHeader("<e>Citizens v" + plugin.getDescription().getVersion()));
Messaging.send(player, " <7>-- <c>Written by fullwall and aPunch"); Messaging.send(player, " <7>-- <c>Written by fullwall and aPunch");
Messaging.send(player, " <7>-- <c>Source: http://github.com/CitizensDev"); Messaging.send(player, " <7>-- <c>Source: http://github.com/CitizensDev");
Messaging.send(player, " <7>-- <c>Website: " + plugin.getDescription().getWebsite()); Messaging.send(player, " <7>-- <c>Website: " + plugin.getDescription().getWebsite());
} }
@Command( @Command(aliases = { "citizens" }, usage = "reload", desc = "Reload Citizens", modifiers = { "reload" }, min = 1, max = 1, permission = "admin")
aliases = { "citizens" },
usage = "reload",
desc = "Reload Citizens",
modifiers = { "reload" },
min = 1,
max = 1,
permission = "admin")
@ServerCommand @ServerCommand
public void reload(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void reload(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Messaging.send(sender, "<e>Reloading Citizens..."); Messaging.send(sender, "<e>Reloading Citizens...");
@ -51,14 +44,7 @@ public class AdminCommands {
} }
} }
@Command( @Command(aliases = { "citizens" }, usage = "save", desc = "Save NPCs", modifiers = { "save" }, min = 1, max = 1, permission = "admin")
aliases = { "citizens" },
usage = "save",
desc = "Save NPCs",
modifiers = { "save" },
min = 1,
max = 1,
permission = "admin")
@ServerCommand @ServerCommand
public void save(CommandContext args, CommandSender sender, NPC npc) { public void save(CommandContext args, CommandSender sender, NPC npc) {
Messaging.send(sender, "<e>Saving Citizens..."); Messaging.send(sender, "<e>Saving Citizens...");

View File

@ -15,40 +15,19 @@ import org.bukkit.entity.Player;
@Requirements(selected = true, ownership = true) @Requirements(selected = true, ownership = true)
public class EditorCommands { public class EditorCommands {
@Command( @Command(aliases = { "npc" }, usage = "equip", desc = "Toggle the equipment editor", modifiers = { "equip" }, min = 1, max = 1, permission = "npc.edit.equip")
aliases = { "npc" },
usage = "equip",
desc = "Toggle the equipment editor",
modifiers = { "equip" },
min = 1,
max = 1,
permission = "npc.edit.equip")
@Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER, EntityType.PIG, @Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER, EntityType.PIG,
EntityType.SHEEP }) EntityType.SHEEP })
public void equip(CommandContext args, Player player, NPC npc) { public void equip(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, new EquipmentEditor(player, npc)); Editor.enterOrLeave(player, new EquipmentEditor(player, npc));
} }
@Command( @Command(aliases = { "npc" }, usage = "path", desc = "Toggle the waypoint editor", modifiers = { "path" }, min = 1, max = 1, permission = "npc.edit.path")
aliases = { "npc" },
usage = "path",
desc = "Toggle the waypoint editor",
modifiers = { "path" },
min = 1,
max = 1,
permission = "npc.edit.path")
public void path(CommandContext args, Player player, NPC npc) { public void path(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player)); Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player));
} }
@Command( @Command(aliases = { "npc" }, usage = "text", desc = "Toggle the text editor", modifiers = { "text" }, min = 1, max = 1, permission = "npc.edit.text")
aliases = { "npc" },
usage = "text",
desc = "Toggle the text editor",
modifiers = { "text" },
min = 1,
max = 1,
permission = "npc.edit.text")
public void text(CommandContext args, Player player, NPC npc) { public void text(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, npc.getTrait(Text.class).getEditor(player)); Editor.enterOrLeave(player, npc.getTrait(Text.class).getEditor(player));
} }

View File

@ -25,14 +25,7 @@ public class HelpCommands {
cmdManager = plugin.getCommandManager(); cmdManager = plugin.getCommandManager();
} }
@Command( @Command(aliases = { "citizens" }, usage = "help (page)", desc = "Citizens help menu", modifiers = { "help" }, min = 1, max = 2, permission = "help")
aliases = { "citizens" },
usage = "help (page)",
desc = "Citizens help menu",
modifiers = { "help" },
min = 1,
max = 2,
permission = "help")
@Requirements @Requirements
@ServerCommand @ServerCommand
public void citizensHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void citizensHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
@ -45,14 +38,7 @@ public class HelpCommands {
throw new CommandException("The page '" + page + "' does not exist."); throw new CommandException("The page '" + page + "' does not exist.");
} }
@Command( @Command(aliases = { "npc" }, usage = "help (page)", desc = "NPC help menu", modifiers = { "help" }, min = 1, max = 2, permission = "npc.help")
aliases = { "npc" },
usage = "help (page)",
desc = "NPC help menu",
modifiers = { "help" },
min = 1,
max = 2,
permission = "npc.help")
@Requirements @Requirements
@ServerCommand @ServerCommand
public void npcHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void npcHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {

View File

@ -19,6 +19,7 @@ import net.citizensnpcs.command.exception.CommandException;
import net.citizensnpcs.command.exception.NoPermissionsException; import net.citizensnpcs.command.exception.NoPermissionsException;
import net.citizensnpcs.npc.CitizensNPCManager; import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.CitizensTraitManager; import net.citizensnpcs.npc.CitizensTraitManager;
import net.citizensnpcs.trait.Age;
import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Powered; import net.citizensnpcs.trait.Powered;
@ -29,6 +30,7 @@ import net.citizensnpcs.util.Paginator;
import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.StringHelper;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Animals;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Villager.Profession;
@ -44,13 +46,7 @@ public class NPCCommands {
npcManager = plugin.getNPCManager(); npcManager = plugin.getNPCManager();
} }
@Command( @Command(aliases = { "npc" }, usage = "character [character]", desc = "Set the character of a NPC", modifiers = { "character" }, min = 2, max = 2)
aliases = { "npc" },
usage = "character [character]",
desc = "Set the character of a NPC",
modifiers = { "character" },
min = 2,
max = 2)
public void character(CommandContext args, Player player, NPC npc) throws CommandException { public void character(CommandContext args, Player player, NPC npc) throws CommandException {
String name = args.getString(1).toLowerCase(); String name = args.getString(1).toLowerCase();
Character character = characterManager.getCharacter(name); Character character = characterManager.getCharacter(name);
@ -73,14 +69,7 @@ public class NPCCommands {
npc.setCharacter(character); npc.setCharacter(character);
} }
@Command( @Command(aliases = { "npc" }, usage = "create [name] (--type (type) --char (char))", desc = "Create a new NPC", flags = "b", modifiers = { "create" }, min = 2, max = 5, permission = "npc.create")
aliases = { "npc" },
usage = "create [name] (--type (type) --char (char))",
desc = "Create a new NPC",
modifiers = { "create" },
min = 2,
max = 5,
permission = "npc.create")
@Requirements @Requirements
public void create(CommandContext args, Player player, NPC npc) { public void create(CommandContext args, Player player, NPC npc) {
String name = args.getString(1); String name = args.getString(1);
@ -115,7 +104,21 @@ public class NPCCommands {
msg += " with the character " + StringHelper.wrap(character); msg += " with the character " + StringHelper.wrap(character);
} }
} }
msg += " at your location."; msg += " at your location";
int age = 0;
if (args.hasFlag('b')) {
// TODO: Use Ageable when it is implemented
if (!Animals.class.isAssignableFrom(type.getEntityClass()))
Messaging.sendError(player, "The mob type '" + type.name().toLowerCase().replace("_", "-")
+ "' cannot be aged.");
else {
age = -24000;
msg += " as a baby";
}
}
msg += ".";
// Initialize necessary traits // Initialize necessary traits
npc.getTrait(Owner.class).setOwner(player.getName()); npc.getTrait(Owner.class).setOwner(player.getName());
@ -124,33 +127,22 @@ public class NPCCommands {
npc.addTrait(traitManager.getTrait(Text.class, npc)); npc.addTrait(traitManager.getTrait(Text.class, npc));
npc.spawn(player.getLocation()); npc.spawn(player.getLocation());
// Set age after entity spawns
npc.getTrait(Age.class).setAge(age);
npcManager.selectNPC(player, npc); npcManager.selectNPC(player, npc);
Messaging.send(player, msg); Messaging.send(player, msg);
} }
@Command( @Command(aliases = { "npc" }, usage = "despawn", desc = "Despawn a NPC", modifiers = { "despawn" }, min = 1, max = 1, permission = "npc.despawn")
aliases = { "npc" },
usage = "despawn",
desc = "Despawn a NPC",
modifiers = { "despawn" },
min = 1,
max = 1,
permission = "npc.despawn")
public void despawn(CommandContext args, Player player, NPC npc) { public void despawn(CommandContext args, Player player, NPC npc) {
npc.getTrait(Spawned.class).setSpawned(false); npc.getTrait(Spawned.class).setSpawned(false);
npc.despawn(); npc.despawn();
Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + "."); Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + ".");
} }
@Command( @Command(aliases = { "npc" }, usage = "list (page) ((-a) --owner (owner) --type (type) --char (char))", desc = "List NPCs", flags = "a", modifiers = { "list" }, min = 1, max = 2, permission = "npc.list")
aliases = { "npc" },
usage = "list (page) ((-a) --owner (owner) --type (type) --char (char))",
desc = "List NPCs",
flags = "a",
modifiers = { "list" },
min = 1,
max = 2,
permission = "npc.list")
@Requirements @Requirements
public void list(CommandContext args, Player player, NPC npc) throws CommandException { public void list(CommandContext args, Player player, NPC npc) throws CommandException {
List<NPC> npcs = new ArrayList<NPC>(); List<NPC> npcs = new ArrayList<NPC>();
@ -214,14 +206,8 @@ public class NPCCommands {
throw new CommandException("The page '" + page + "' does not exist."); throw new CommandException("The page '" + page + "' does not exist.");
} }
@Command( @Command(aliases = { "npc" }, usage = "lookclose", desc = "Toggle whether a NPC will look when a player is near", modifiers = {
aliases = { "npc" }, "lookclose", "look", "rotate" }, min = 1, max = 1, permission = "npc.lookclose")
usage = "lookclose",
desc = "Toggle whether a NPC will look when a player is near",
modifiers = { "lookclose", "look", "rotate" },
min = 1,
max = 1,
permission = "npc.lookclose")
public void lookClose(CommandContext args, Player player, NPC npc) { public void lookClose(CommandContext args, Player player, NPC npc) {
String msg = StringHelper.wrap(npc.getName()) + " will " String msg = StringHelper.wrap(npc.getName()) + " will "
+ (npc.getTrait(LookClose.class).toggle() ? "now rotate" : "no longer rotate"); + (npc.getTrait(LookClose.class).toggle() ? "now rotate" : "no longer rotate");
@ -237,14 +223,7 @@ public class NPCCommands {
Messaging.send(player, " <a>Type: <e>" + npc.getTrait(MobType.class).getType()); Messaging.send(player, " <a>Type: <e>" + npc.getTrait(MobType.class).getType());
} }
@Command( @Command(aliases = { "npc" }, usage = "owner [name]", desc = "Set the owner of an NPC", modifiers = { "owner" }, min = 2, max = 2, permission = "npc.owner")
aliases = { "npc" },
usage = "owner [name]",
desc = "Set the owner of an NPC",
modifiers = { "owner" },
min = 2,
max = 2,
permission = "npc.owner")
public void owner(CommandContext args, Player player, NPC npc) throws CommandException { public void owner(CommandContext args, Player player, NPC npc) throws CommandException {
String name = args.getString(1); String name = args.getString(1);
if (npc.getTrait(Owner.class).getOwner().equals(name)) if (npc.getTrait(Owner.class).getOwner().equals(name))
@ -254,13 +233,7 @@ public class NPCCommands {
+ "."); + ".");
} }
@Command( @Command(aliases = { "npc" }, usage = "remove (all)", desc = "Remove a NPC", modifiers = { "remove" }, min = 1, max = 2)
aliases = { "npc" },
usage = "remove (all)",
desc = "Remove a NPC",
modifiers = { "remove" },
min = 1,
max = 2)
@Requirements @Requirements
public void remove(CommandContext args, Player player, NPC npc) throws CommandException { public void remove(CommandContext args, Player player, NPC npc) throws CommandException {
if (args.argsLength() == 2) { if (args.argsLength() == 2) {
@ -282,14 +255,7 @@ public class NPCCommands {
Messaging.send(player, "<a>You permanently removed " + StringHelper.wrap(npc.getName()) + "."); Messaging.send(player, "<a>You permanently removed " + StringHelper.wrap(npc.getName()) + ".");
} }
@Command( @Command(aliases = { "npc" }, usage = "rename [name]", desc = "Rename a NPC", modifiers = { "rename" }, min = 2, max = 2, permission = "npc.rename")
aliases = { "npc" },
usage = "rename [name]",
desc = "Rename a NPC",
modifiers = { "rename" },
min = 2,
max = 2,
permission = "npc.rename")
public void rename(CommandContext args, Player player, NPC npc) { public void rename(CommandContext args, Player player, NPC npc) {
String oldName = npc.getName(); String oldName = npc.getName();
String newName = args.getString(1); String newName = args.getString(1);
@ -303,14 +269,7 @@ public class NPCCommands {
+ "."); + ".");
} }
@Command( @Command(aliases = { "npc" }, usage = "select [id]", desc = "Select a NPC with the given ID", modifiers = { "select" }, min = 2, max = 2, permission = "npc.select")
aliases = { "npc" },
usage = "select [id]",
desc = "Select a NPC with the given ID",
modifiers = { "select" },
min = 2,
max = 2,
permission = "npc.select")
@Requirements(ownership = true) @Requirements(ownership = true)
public void select(CommandContext args, Player player, NPC npc) throws CommandException { public void select(CommandContext args, Player player, NPC npc) throws CommandException {
NPC toSelect = npcManager.getNPC(args.getInteger(1)); NPC toSelect = npcManager.getNPC(args.getInteger(1));
@ -322,14 +281,7 @@ public class NPCCommands {
Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.asString(), toSelect); Messaging.sendWithNPC(player, Setting.SELECTION_MESSAGE.asString(), toSelect);
} }
@Command( @Command(aliases = { "npc" }, usage = "spawn [id]", desc = "Spawn an existing NPC", modifiers = { "spawn" }, min = 2, max = 2, permission = "npc.spawn")
aliases = { "npc" },
usage = "spawn [id]",
desc = "Spawn an existing NPC",
modifiers = { "spawn" },
min = 2,
max = 2,
permission = "npc.spawn")
@Requirements @Requirements
public void spawn(CommandContext args, Player player, NPC npc) throws CommandException { public void spawn(CommandContext args, Player player, NPC npc) throws CommandException {
NPC respawn = npcManager.getNPC(args.getInteger(1)); NPC respawn = npcManager.getNPC(args.getInteger(1));
@ -348,14 +300,7 @@ public class NPCCommands {
+ " Use '/npc tphere' to teleport the NPC to your location."); + " Use '/npc tphere' to teleport the NPC to your location.");
} }
@Command( @Command(aliases = { "npc" }, usage = "tp", desc = "Teleport to a NPC", modifiers = { "tp", "teleport" }, min = 1, max = 1, permission = "npc.tp")
aliases = { "npc" },
usage = "tp",
desc = "Teleport to a NPC",
modifiers = { "tp", "teleport" },
min = 1,
max = 1,
permission = "npc.tp")
public void tp(CommandContext args, Player player, NPC npc) { public void tp(CommandContext args, Player player, NPC npc) {
// Spawn the NPC if it isn't spawned to prevent NPEs // Spawn the NPC if it isn't spawned to prevent NPEs
if (!npc.isSpawned()) if (!npc.isSpawned())
@ -364,14 +309,7 @@ public class NPCCommands {
Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + "."); Messaging.send(player, ChatColor.GREEN + "You teleported to " + StringHelper.wrap(npc.getName()) + ".");
} }
@Command( @Command(aliases = { "npc" }, usage = "tphere", desc = "Teleport a NPC to your location", modifiers = { "tphere" }, min = 1, max = 1, permission = "npc.tphere")
aliases = { "npc" },
usage = "tphere",
desc = "Teleport a NPC to your location",
modifiers = { "tphere" },
min = 1,
max = 1,
permission = "npc.tphere")
public void tphere(CommandContext args, Player player, NPC npc) { public void tphere(CommandContext args, Player player, NPC npc) {
// Spawn the NPC if it isn't spawned to prevent NPEs // Spawn the NPC if it isn't spawned to prevent NPEs
if (!npc.isSpawned()) if (!npc.isSpawned())
@ -380,14 +318,7 @@ public class NPCCommands {
Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location."); Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location.");
} }
@Command( @Command(aliases = { "npc" }, usage = "power", desc = "Toggle a creeper NPC as powered", modifiers = { "power" }, min = 1, max = 1, permission = "npc.power")
aliases = { "npc" },
usage = "power",
desc = "Toggle a creeper NPC as powered",
modifiers = { "power" },
min = 1,
max = 1,
permission = "npc.power")
@Requirements(selected = true, ownership = true, types = { EntityType.CREEPER }) @Requirements(selected = true, ownership = true, types = { EntityType.CREEPER })
public void power(CommandContext args, Player player, NPC npc) { public void power(CommandContext args, Player player, NPC npc) {
String msg = StringHelper.wrap(npc.getName()) + " will " String msg = StringHelper.wrap(npc.getName()) + " will "
@ -395,23 +326,48 @@ public class NPCCommands {
Messaging.send(player, msg += " be powered."); Messaging.send(player, msg += " be powered.");
} }
@Command( @Command(aliases = { "npc" }, usage = "profession [profession]", desc = "Set a NPC's profession", modifiers = { "profession" }, min = 2, max = 2, permission = "npc.profession")
aliases = { "npc" },
usage = "profession [profession]",
desc = "Set a NPC's profession",
modifiers = { "profession" },
min = 2,
max = 2,
permission = "npc.profession")
@Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER }) @Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER })
public void profession(CommandContext args, Player player, NPC npc) throws CommandException { public void profession(CommandContext args, Player player, NPC npc) throws CommandException {
String profession = args.getString(1); String profession = args.getString(1);
try { try {
npc.getTrait(VillagerProfession.class).setProfession(Profession.valueOf(profession.toUpperCase())); npc.getTrait(VillagerProfession.class).setProfession(Profession.valueOf(profession.toUpperCase()));
Messaging.send(player, StringHelper.wrap(npc.getName()) + " is now the profession " Messaging.send(
+ StringHelper.wrap(profession.toUpperCase()) + "."); player,
StringHelper.wrap(npc.getName()) + " is now the profession "
+ StringHelper.wrap(profession.toUpperCase()) + ".");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
throw new CommandException("'" + profession + "' is not a valid profession."); throw new CommandException("'" + profession + "' is not a valid profession.");
} }
} }
@Command(aliases = { "npc" }, usage = "age [age] (-l)", desc = "Set the age of a NPC", flags = "l", modifiers = { "age" }, min = 1, max = 2, permission = "npc.age")
@Requirements(selected = true, ownership = true, types = { EntityType.CHICKEN, EntityType.COW, EntityType.OCELOT,
EntityType.PIG, EntityType.SHEEP, EntityType.VILLAGER, EntityType.WOLF })
public void age(CommandContext args, Player player, NPC npc) throws CommandException {
Age trait = npc.getTrait(Age.class);
if (args.argsLength() > 1) {
int age = 0;
String ageStr = "an adult";
try {
age = args.getInteger(1);
if (age < -24000 || age > 0)
throw new CommandException("Invalid age. Valid: adult, baby, number between -24000 and 0");
ageStr = "age " + age;
} catch (NumberFormatException ex) {
if (args.getString(1).equalsIgnoreCase("baby")) {
age = -24000;
ageStr = "a baby";
} else if (!args.getString(1).equalsIgnoreCase("adult"))
throw new CommandException("Invalid age. Valid: adult, baby, number between -24000 and 0");
}
trait.setAge(age);
Messaging.send(player, StringHelper.wrap(npc.getName()) + " is now " + ageStr + ".");
}
if (args.hasFlag('l'))
Messaging.send(player, "<a>Age " + (trait.toggle() ? "locked" : "unlocked") + ".");
}
} }

View File

@ -14,6 +14,7 @@ import net.citizensnpcs.api.trait.trait.Inventory;
import net.citizensnpcs.api.trait.trait.MobType; import net.citizensnpcs.api.trait.trait.MobType;
import net.citizensnpcs.api.trait.trait.Owner; import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.api.trait.trait.Spawned; import net.citizensnpcs.api.trait.trait.Spawned;
import net.citizensnpcs.trait.Age;
import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Powered; import net.citizensnpcs.trait.Powered;
@ -29,6 +30,7 @@ public class CitizensTraitManager implements TraitManager {
public CitizensTraitManager() { public CitizensTraitManager() {
// Register Citizens traits // Register Citizens traits
registerTrait(new TraitFactory(Age.class).withName("age"));
registerTrait(new TraitFactory(CurrentLocation.class).withName("location")); registerTrait(new TraitFactory(CurrentLocation.class).withName("location"));
registerTrait(new TraitFactory(Equipment.class).withName("equipment")); registerTrait(new TraitFactory(Equipment.class).withName("equipment"));
registerTrait(new TraitFactory(Inventory.class).withName("inventory")); registerTrait(new TraitFactory(Inventory.class).withName("inventory"));

View File

@ -0,0 +1,64 @@
package net.citizensnpcs.trait;
import org.bukkit.entity.Animals;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
public class Age extends Trait implements Runnable, Toggleable {
private int age = 0;
private boolean locked = true;
private final NPC npc;
public Age(NPC npc) {
this.npc = npc;
}
@Override
public void load(DataKey key) throws NPCLoadException {
age = key.getInt("age");
locked = key.getBoolean("locked");
}
@Override
public void save(DataKey key) {
key.setInt("age", age);
key.setBoolean("locked", locked);
}
@Override
public void onNPCSpawn() {
// TODO: Switch to use Ageable when that is implemented
if (npc.getBukkitEntity() instanceof Animals) {
Animals animal = (Animals) npc.getBukkitEntity();
animal.setAge(age);
animal.setAgeLock(locked);
}
}
@Override
public void run() {
if (!locked)
age = ((Animals) npc.getBukkitEntity()).getAge();
}
@Override
public boolean toggle() {
locked = !locked;
((Animals) npc.getBukkitEntity()).setAgeLock(locked);
return locked;
}
public void setAge(int age) {
this.age = age;
if (npc.getBukkitEntity() instanceof Animals)
((Animals) npc.getBukkitEntity()).setAge(age);
}
@Override
public String toString() {
return "Age{age=" + age + ",locked=" + locked + "}";
}
}

View File

@ -16,6 +16,7 @@ permissions:
citizens.help: true citizens.help: true
citizens.npc.*: citizens.npc.*:
children: children:
citizens.npc.age: true
citizens.npc.character.*: true citizens.npc.character.*: true
citizens.npc.create: true citizens.npc.create: true
citizens.npc.despawn: true citizens.npc.despawn: true