Search in sources :

Example 1 with Paginator

use of net.citizensnpcs.api.util.Paginator in project Denizen-For-Bukkit by DenizenScript.

the class ConstantsTrait method describe.

public void describe(CommandSender sender, int page) throws CommandException {
    Paginator paginator = new Paginator().header("Constants for " + npc.getName());
    paginator.addLine("<e>NPC-specific constants: " + (hasNPCConstants() ? "" : "None.") + "");
    if (hasNPCConstants()) {
        paginator.addLine("<e>Key: <a>Name  <b>Value");
    }
    for (Entry<String, String> constant : constants.entrySet()) {
        paginator.addLine("<a> " + String.valueOf(constant.getKey().charAt(0)).toUpperCase() + constant.getKey().substring(1) + "<b>  " + constant.getValue());
    }
    paginator.addLine("");
    if (npc.hasTrait(AssignmentTrait.class) && npc.getTrait(AssignmentTrait.class).hasAssignment()) {
        getAssignmentConstants();
        // List constants inherited from an Assignment.
        paginator.addLine("<e>Constants for assignment '" + assignment.toUpperCase() + "':");
        paginator.addLine("<e>Key: <a>Name  <b>Value");
        for (Entry<String, String> constant : getAssignmentConstants().entrySet()) {
            // change formatting to indicate so.
            if (constants.containsKey(constant.getKey())) {
                paginator.addLine("<m>" + String.valueOf(constant.getKey().charAt(0)).toUpperCase() + constant.getKey().substring(1) + "<r>  <m>" + constant.getValue());
            } else {
                paginator.addLine("<a>" + String.valueOf(constant.getKey().charAt(0)).toUpperCase() + constant.getKey().substring(1) + "<b>  " + constant.getValue());
            }
        }
        paginator.addLine("");
    }
    if (!paginator.sendPage(sender, page)) {
        throw new CommandException(Messages.COMMAND_PAGE_MISSING, page);
    }
}
Also used : CommandException(net.citizensnpcs.api.command.exception.CommandException) Paginator(net.citizensnpcs.api.util.Paginator)

Example 2 with Paginator

use of net.citizensnpcs.api.util.Paginator in project Denizen-For-Bukkit by DenizenScript.

the class TriggerTrait method describe.

public void describe(CommandSender sender, int page) throws CommandException {
    Paginator paginator = new Paginator().header("Triggers");
    paginator.addLine("<e>Key: <a>Name  <b>Status  <c>Cooldown  <d>Cooldown Type  <e>(Radius)");
    for (Entry<String, Boolean> entry : enabled.entrySet()) {
        String line = "<a> " + entry.getKey() + "<b> " + (entry.getValue() ? "Enabled" : "Disabled") + "<c> " + getCooldownDuration(entry.getKey()) + "<d> " + getCooldownType(entry.getKey()).name() + "<e> " + (getRadius(entry.getKey()) == -1 ? "" : getRadius(entry.getKey()));
        paginator.addLine(line);
    }
    if (!paginator.sendPage(sender, page)) {
        throw new CommandException(Messages.COMMAND_PAGE_MISSING, page);
    }
}
Also used : CommandException(net.citizensnpcs.api.command.exception.CommandException) Paginator(net.citizensnpcs.api.util.Paginator)

Example 3 with Paginator

use of net.citizensnpcs.api.util.Paginator in project Citizens2 by CitizensDev.

the class Poses method describe.

public void describe(CommandSender sender, int page) throws CommandException {
    Paginator paginator = new Paginator().header("Pose");
    paginator.addLine("<e>Key: <a>ID  <b>Name  <c>Pitch/Yaw");
    int i = 0;
    for (Pose pose : poses.values()) {
        String line = "<a>" + i + "<b>  " + pose.getName() + "<c>  " + pose.getPitch() + "/" + pose.getYaw();
        paginator.addLine(line);
        i++;
    }
    if (!paginator.sendPage(sender, page))
        throw new CommandException(Messages.COMMAND_PAGE_MISSING);
}
Also used : Pose(net.citizensnpcs.util.Pose) CommandException(net.citizensnpcs.api.command.exception.CommandException) Paginator(net.citizensnpcs.api.util.Paginator)

Example 4 with Paginator

use of net.citizensnpcs.api.util.Paginator in project Citizens2 by CitizensDev.

the class NPCCommands method anchor.

@Command(aliases = { "npc" }, usage = "anchor (--save [name]|--assume [name]|--remove [name]) (-a)(-c)", desc = "Changes/Saves/Lists NPC's location anchor(s)", flags = "ac", modifiers = { "anchor" }, min = 1, max = 3, permission = "citizens.npc.anchor")
public void anchor(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    Anchors trait = npc.getTrait(Anchors.class);
    if (args.hasValueFlag("save")) {
        if (args.getFlag("save").isEmpty())
            throw new CommandException(Messages.INVALID_ANCHOR_NAME);
        if (args.getSenderLocation() == null)
            throw new ServerCommandException();
        if (args.hasFlag('c')) {
            if (trait.addAnchor(args.getFlag("save"), args.getSenderTargetBlockLocation())) {
                Messaging.sendTr(sender, Messages.ANCHOR_ADDED);
            } else
                throw new CommandException(Messages.ANCHOR_ALREADY_EXISTS, args.getFlag("save"));
        } else {
            if (trait.addAnchor(args.getFlag("save"), args.getSenderLocation())) {
                Messaging.sendTr(sender, Messages.ANCHOR_ADDED);
            } else
                throw new CommandException(Messages.ANCHOR_ALREADY_EXISTS, args.getFlag("save"));
        }
    } else if (args.hasValueFlag("assume")) {
        if (args.getFlag("assume").isEmpty())
            throw new CommandException(Messages.INVALID_ANCHOR_NAME);
        Anchor anchor = trait.getAnchor(args.getFlag("assume"));
        if (anchor == null)
            throw new CommandException(Messages.ANCHOR_MISSING, args.getFlag("assume"));
        npc.teleport(anchor.getLocation(), TeleportCause.COMMAND);
    } else if (args.hasValueFlag("remove")) {
        if (args.getFlag("remove").isEmpty())
            throw new CommandException(Messages.INVALID_ANCHOR_NAME);
        if (trait.removeAnchor(trait.getAnchor(args.getFlag("remove"))))
            Messaging.sendTr(sender, Messages.ANCHOR_REMOVED);
        else
            throw new CommandException(Messages.ANCHOR_MISSING, args.getFlag("remove"));
    } else if (!args.hasFlag('a')) {
        Paginator paginator = new Paginator().header("Anchors");
        paginator.addLine("<e>Key: <a>ID  <b>Name  <c>World  <d>Location (X,Y,Z)");
        for (int i = 0; i < trait.getAnchors().size(); i++) {
            if (trait.getAnchors().get(i).isLoaded()) {
                String line = "<a>" + i + "<b>  " + trait.getAnchors().get(i).getName() + "<c>  " + trait.getAnchors().get(i).getLocation().getWorld().getName() + "<d>  " + trait.getAnchors().get(i).getLocation().getBlockX() + ", " + trait.getAnchors().get(i).getLocation().getBlockY() + ", " + trait.getAnchors().get(i).getLocation().getBlockZ();
                paginator.addLine(line);
            } else {
                String[] parts = trait.getAnchors().get(i).getUnloadedValue();
                String line = "<a>" + i + "<b>  " + trait.getAnchors().get(i).getName() + "<c>  " + parts[0] + "<d>  " + parts[1] + ", " + parts[2] + ", " + parts[3] + " <f>(unloaded)";
                paginator.addLine(line);
            }
        }
        int page = args.getInteger(1, 1);
        if (!paginator.sendPage(sender, page))
            throw new CommandException(Messages.COMMAND_PAGE_MISSING);
    }
    // Assume Player's position
    if (!args.hasFlag('a'))
        return;
    if (sender instanceof ConsoleCommandSender)
        throw new ServerCommandException();
    npc.teleport(args.getSenderLocation(), TeleportCause.COMMAND);
}
Also used : Anchors(net.citizensnpcs.trait.Anchors) Anchor(net.citizensnpcs.util.Anchor) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) Paginator(net.citizensnpcs.api.util.Paginator) Command(net.citizensnpcs.api.command.Command)

Example 5 with Paginator

use of net.citizensnpcs.api.util.Paginator in project Citizens2 by CitizensDev.

the class NPCCommands method list.

@Command(aliases = { "npc" }, usage = "list (page) ((-a) --owner (owner) --type (type) --char (char) --registry (name))", desc = "List NPCs", flags = "a", modifiers = { "list" }, min = 1, max = 2, permission = "citizens.npc.list")
@Requirements
public void list(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    NPCRegistry source = args.hasValueFlag("registry") ? CitizensAPI.getNamedNPCRegistry(args.getFlag("registry")) : npcRegistry;
    if (source == null)
        throw new CommandException();
    List<NPC> npcs = new ArrayList<NPC>();
    if (args.hasFlag('a')) {
        for (NPC add : source.sorted()) {
            npcs.add(add);
        }
    } else if (args.getValueFlags().size() == 0 && sender instanceof Player) {
        for (NPC add : source.sorted()) {
            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 : source.sorted()) {
                if (!npcs.contains(add) && add.getTrait(Owner.class).isOwnedBy(name)) {
                    npcs.add(add);
                }
            }
        }
        if (args.hasValueFlag("type")) {
            EntityType type = Util.matchEntityType(args.getFlag("type"));
            if (type == null)
                throw new CommandException(Messages.COMMAND_INVALID_MOBTYPE, type);
            for (NPC add : source) {
                if (!npcs.contains(add) && add.getTrait(MobType.class).getType() == type)
                    npcs.add(add);
            }
        }
    }
    Paginator paginator = new Paginator().header("NPCs");
    paginator.addLine("<e>Key: <a>ID  <b>Name");
    for (int i = 0; i < npcs.size(); i += 2) {
        String line = "<a>" + npcs.get(i).getId() + "<b>  " + npcs.get(i).getName();
        if (npcs.size() >= i + 2)
            line += "      " + "<a>" + npcs.get(i + 1).getId() + "<b>  " + npcs.get(i + 1).getName();
        paginator.addLine(line);
    }
    int page = args.getInteger(1, 1);
    if (!paginator.sendPage(sender, page))
        throw new CommandException(Messages.COMMAND_PAGE_MISSING);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) EntityType(org.bukkit.entity.EntityType) Player(org.bukkit.entity.Player) Owner(net.citizensnpcs.api.trait.trait.Owner) ArrayList(java.util.ArrayList) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Paginator(net.citizensnpcs.api.util.Paginator) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Aggregations

CommandException (net.citizensnpcs.api.command.exception.CommandException)7 Paginator (net.citizensnpcs.api.util.Paginator)7 Command (net.citizensnpcs.api.command.Command)2 ServerCommandException (net.citizensnpcs.api.command.exception.ServerCommandException)2 ArrayList (java.util.ArrayList)1 AssignmentScriptContainer (net.aufdemrand.denizen.scripts.containers.core.AssignmentScriptContainer)1 StringHolder (net.aufdemrand.denizencore.utilities.text.StringHolder)1 Requirements (net.citizensnpcs.api.command.Requirements)1 NPC (net.citizensnpcs.api.npc.NPC)1 NPCRegistry (net.citizensnpcs.api.npc.NPCRegistry)1 Owner (net.citizensnpcs.api.trait.trait.Owner)1 Anchors (net.citizensnpcs.trait.Anchors)1 Anchor (net.citizensnpcs.util.Anchor)1 Pose (net.citizensnpcs.util.Pose)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 EntityType (org.bukkit.entity.EntityType)1 Player (org.bukkit.entity.Player)1