use of com.elmakers.mine.bukkit.citizens.CitizensTrait in project MagicPlugin by elBukkit.
the class MagicTraitCommandExecutor method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!api.hasPermission(sender, "Magic.commands.mtrait")) {
sendNoPermission(sender);
return true;
}
NPC npc = null;
Citizens citizens = citizensController.getCitizensPlugin();
// Did player specify a id?
if (args.length > 0) {
try {
int npcId = Integer.parseInt(args[0]);
npc = CitizensAPI.getNPCRegistry().getById(npcId);
args = Arrays.copyOfRange(args, 1, args.length);
} catch (Exception e) {
sender.sendMessage("Invalid NPC id: " + args[0]);
}
}
if (npc == null) {
npc = citizens.getNPCSelector().getSelected(sender);
}
if (npc == null) {
sender.sendMessage(ChatColor.RED + "Usage: mtrait <id#> <property> <value>");
return true;
}
CitizensTrait trait = null;
if (npc.hasTrait(MagicCitizensTrait.class)) {
trait = npc.getTrait(MagicCitizensTrait.class);
} else if (npc.hasTrait(CommandCitizensTrait.class)) {
trait = npc.getTrait(CommandCitizensTrait.class);
} else {
sender.sendMessage(ChatColor.RED + "You must add a \"magic\" or \"command\" trait first");
return true;
}
if (args.length == 0) {
trait.describe(sender);
} else {
String key = args[0];
String value = args.length > 1 ? args[1] : null;
for (int i = 2; i < args.length; i++) {
value = value + " " + args[i];
}
trait.configure(sender, key, value);
}
return true;
}
Aggregations