Search in sources :

Example 1 with TopicPaginator

use of net.countercraft.movecraft.util.TopicPaginator in project Movecraft by APDevTeam.

the class ContactsCommand method onCommand.

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
    if (!command.getName().equalsIgnoreCase("contacts")) {
        return false;
    }
    if (!(commandSender instanceof Player)) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Contacts - Must Be Player"));
        return true;
    }
    Player player = (Player) commandSender;
    if (CraftManager.getInstance().getCraftByPlayer(player) == null) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("You must be piloting a craft"));
        return true;
    }
    int page;
    try {
        if (args.length == 0)
            page = 1;
        else
            page = Integer.parseInt(args[0]);
    } catch (NumberFormatException e) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Paginator - Invalid Page") + " \"" + args[0] + "\"");
        return true;
    }
    TopicPaginator pageinator = new TopicPaginator(I18nSupport.getInternationalisedString("Contacts"));
    Craft ccraft = CraftManager.getInstance().getCraftByPlayer(player);
    HitBox hitBox = ccraft.getHitBox();
    MovecraftLocation center = hitBox.getMidPoint();
    for (Craft tcraft : ccraft.getContacts()) {
        HitBox tHitBox = tcraft.getHitBox();
        if (tHitBox.isEmpty())
            continue;
        MovecraftLocation tCenter = tHitBox.getMidPoint();
        int distsquared = center.distanceSquared(tCenter);
        String notification = I18nSupport.getInternationalisedString("Contact");
        notification += ": ";
        notification += tcraft instanceof SinkingCraft ? ChatColor.RED : tcraft.getDisabled() ? ChatColor.BLUE : "";
        notification += tcraft.getName().length() >= 1 ? tcraft.getName() + " (" : "";
        notification += tcraft.getType().getStringProperty(CraftType.NAME);
        notification += tcraft.getName().length() >= 1 ? ") " : " ";
        notification += ChatColor.RESET;
        notification += I18nSupport.getInternationalisedString("Contact - Commanded By") + ", ";
        notification += tcraft instanceof PilotedCraft ? ((PilotedCraft) tcraft).getPilot().getDisplayName() : "null";
        notification += " ";
        notification += I18nSupport.getInternationalisedString("Contact - Size") + " ";
        notification += tcraft.getOrigBlockCount();
        notification += ", " + I18nSupport.getInternationalisedString("Contact - Range") + " ";
        notification += (int) Math.sqrt(distsquared);
        notification += " " + I18nSupport.getInternationalisedString("Contact - To The");
        int diffx = center.getX() - tCenter.getX();
        int diffz = center.getZ() - tCenter.getZ();
        if (Math.abs(diffx) > Math.abs(diffz))
            if (diffx < 0)
                notification += " " + I18nSupport.getInternationalisedString("Contact/Subcraft Rotate - East") + ".";
            else
                notification += " " + I18nSupport.getInternationalisedString("Contact/Subcraft Rotate - West") + ".";
        else if (diffz < 0)
            notification += " " + I18nSupport.getInternationalisedString("Contact/Subcraft Rotate - South") + ".";
        else
            notification += " " + I18nSupport.getInternationalisedString("Contact/Subcraft Rotate - North") + ".";
        pageinator.addLine(notification);
    }
    if (pageinator.isEmpty()) {
        player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Contacts - None Found"));
        return true;
    }
    if (!pageinator.isInBounds(page)) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Paginator - Invalid page") + "\"" + page + "\"");
        return true;
    }
    for (String line : pageinator.getPage(page)) commandSender.sendMessage(line);
    return true;
}
Also used : SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) Player(org.bukkit.entity.Player) HitBox(net.countercraft.movecraft.util.hitboxes.HitBox) TopicPaginator(net.countercraft.movecraft.util.TopicPaginator) SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) Craft(net.countercraft.movecraft.craft.Craft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation)

Example 2 with TopicPaginator

use of net.countercraft.movecraft.util.TopicPaginator in project Movecraft by APDevTeam.

the class CraftReportCommand method onCommand.

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
    if (commandSender.getName().equalsIgnoreCase("craftreport"))
        return false;
    if (!commandSender.hasPermission("movecraft.commands") && !commandSender.hasPermission("movecraft.commands.craftreport")) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
        return true;
    }
    int page;
    try {
        if (args.length == 0)
            page = 1;
        else
            page = Integer.parseInt(args[0]);
    } catch (NumberFormatException e) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Paginator - Invalid Page") + "\"" + args[0] + "\"");
        return true;
    }
    if (CraftManager.getInstance().isEmpty()) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Craft Report - None Found"));
        return true;
    }
    TopicPaginator paginator = new TopicPaginator(I18nSupport.getInternationalisedString("Craft Report"));
    for (Craft craft : CraftManager.getInstance()) {
        HitBox hitBox = craft.getHitBox();
        paginator.addLine((craft instanceof SinkingCraft ? ChatColor.RED : craft.getDisabled() ? ChatColor.BLUE : "") + craft.getType().getStringProperty(CraftType.NAME) + " " + ChatColor.RESET + (craft instanceof PilotedCraft ? ((PilotedCraft) craft).getPilot().getName() : I18nSupport.getInternationalisedString("None")) + " " + hitBox.size() + " @ " + hitBox.getMinX() + "," + hitBox.getMinY() + "," + hitBox.getMinZ() + " - " + String.format("%.2f", 1000 * craft.getMeanCruiseTime()) + "ms");
    }
    if (!paginator.isInBounds(page)) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Paginator - Invalid page") + "\"" + page + "\"");
        return true;
    }
    for (String line : paginator.getPage(page)) commandSender.sendMessage(line);
    return true;
}
Also used : SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) HitBox(net.countercraft.movecraft.util.hitboxes.HitBox) TopicPaginator(net.countercraft.movecraft.util.TopicPaginator) SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) Craft(net.countercraft.movecraft.craft.Craft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft)

Example 3 with TopicPaginator

use of net.countercraft.movecraft.util.TopicPaginator in project Movecraft by APDevTeam.

the class CraftTypeCommand method sendTypePage.

private void sendTypePage(@NotNull CraftType type, int page, @NotNull CommandSender commandSender) {
    TopicPaginator paginator = new TopicPaginator("Type Info");
    for (var field : craftTypeFields) {
        if (field.getName().equals("data")) {
            // don't include the backing data object
            continue;
        }
        Object value;
        try {
            value = field.get(type);
        } catch (IllegalAccessException e) {
            paginator.addLine(field.getName() + ": failed to access");
            continue;
        }
        var repr = field.getName() + ": " + value;
        if (repr.length() > ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH) {
            paginator.addLine(field.getName() + ": too long");
        } else {
            paginator.addLine(field.getName() + ": " + value);
        }
    }
    if (!paginator.isInBounds(page)) {
        commandSender.sendMessage(String.format("Page %d is out of bounds.", page));
        return;
    }
    for (String line : paginator.getPage(page)) commandSender.sendMessage(line);
}
Also used : TopicPaginator(net.countercraft.movecraft.util.TopicPaginator)

Aggregations

TopicPaginator (net.countercraft.movecraft.util.TopicPaginator)3 Craft (net.countercraft.movecraft.craft.Craft)2 PilotedCraft (net.countercraft.movecraft.craft.PilotedCraft)2 SinkingCraft (net.countercraft.movecraft.craft.SinkingCraft)2 HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)2 MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)1 Player (org.bukkit.entity.Player)1