Search in sources :

Example 1 with PilotedCraft

use of net.countercraft.movecraft.craft.PilotedCraft 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 PilotedCraft

use of net.countercraft.movecraft.craft.PilotedCraft in project Movecraft by APDevTeam.

the class ReleaseCommand method onCommand.

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
    if (!command.getName().equalsIgnoreCase("release"))
        return false;
    if (!commandSender.hasPermission("movecraft.commands") && !commandSender.hasPermission("movecraft.commands.release")) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
        return true;
    }
    if (args.length == 0) {
        if (!(commandSender instanceof Player)) {
            commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Player- Error - You do not have a craft to release!"));
            return true;
        }
        Player player = (Player) commandSender;
        final Craft pCraft = CraftManager.getInstance().getCraftByPlayerName(player.getName());
        if (pCraft == null) {
            player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Player- Error - You do not have a craft to release!"));
            return true;
        }
        CraftManager.getInstance().release(pCraft, CraftReleaseEvent.Reason.PLAYER, false);
        return true;
    }
    if (!commandSender.hasPermission("movecraft.commands.release.others")) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Release - No Force Release"));
        return true;
    }
    if (args[0].equalsIgnoreCase("-p")) {
        for (Player p : Bukkit.getOnlinePlayers()) {
            String name = p.getName();
            final Craft pCraft = CraftManager.getInstance().getCraftByPlayerName(name);
            if (pCraft != null)
                CraftManager.getInstance().release(pCraft, CraftReleaseEvent.Reason.FORCE, false);
        }
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Release - Released All Player Crafts"));
        return true;
    }
    if (args[0].equalsIgnoreCase("-a")) {
        final List<Craft> craftsToRelease = new ArrayList<>(CraftManager.getInstance().getCrafts());
        for (Craft craft : craftsToRelease) {
            CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.FORCE, false);
        }
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Release - Released All Crafts"));
        return true;
    }
    if (args[0].equalsIgnoreCase("-n")) {
        final List<Craft> craftsToRelease = new ArrayList<>(CraftManager.getInstance().getCrafts());
        for (Craft craft : craftsToRelease) {
            if (!(craft instanceof PilotedCraft))
                CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.FORCE, false);
        }
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Release - Released All Null Crafts"));
        return true;
    }
    Player target = Bukkit.getPlayer(args[0]);
    if (target == null) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Player - Not Found"));
        return true;
    }
    final Craft pCraft = CraftManager.getInstance().getCraftByPlayerName(args[0]);
    if (pCraft != null) {
        CraftManager.getInstance().release(pCraft, CraftReleaseEvent.Reason.FORCE, false);
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Release - Successful Force Release"));
        return true;
    }
    commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Player - Not Piloting"));
    return true;
}
Also used : Player(org.bukkit.entity.Player) Craft(net.countercraft.movecraft.craft.Craft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) ArrayList(java.util.ArrayList) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft)

Example 3 with PilotedCraft

use of net.countercraft.movecraft.craft.PilotedCraft in project Movecraft by APDevTeam.

the class AsyncManager method run.

public void run() {
    clearAll();
    processCruise();
    detectSinking();
    processSinking();
    processFadingBlocks();
    processDetection();
    processAlgorithmQueue();
    // but have no pilot or are still processing
    for (Craft craft : CraftManager.getInstance()) {
        if (!(craft instanceof PilotedCraft)) {
            if (craft.getLastCruiseUpdate() < System.currentTimeMillis() - 60000)
                CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.INACTIVE, true);
        }
        if (!craft.isNotProcessing()) {
            if (craft.getCruising()) {
                if (craft.getLastCruiseUpdate() < System.currentTimeMillis() - 5000)
                    craft.setProcessing(false);
            }
        }
    }
}
Also used : SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) PlayerCraft(net.countercraft.movecraft.craft.PlayerCraft) Craft(net.countercraft.movecraft.craft.Craft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft)

Example 4 with PilotedCraft

use of net.countercraft.movecraft.craft.PilotedCraft in project Movecraft by APDevTeam.

the class AsyncManager method processDetection.

private void processDetection() {
    long ticksElapsed = (System.currentTimeMillis() - lastContactCheck) / 50;
    if (ticksElapsed > 21) {
        for (World w : Bukkit.getWorlds()) {
            if (w == null)
                continue;
            for (Craft craft : CraftManager.getInstance().getPlayerCraftsInWorld(w)) {
                if (!recentContactTracking.containsKey(craft))
                    recentContactTracking.put(craft, new HashMap<>());
                for (Craft target : craft.getContacts()) {
                    MovecraftLocation craftCenter = craft.getHitBox().getMidPoint();
                    MovecraftLocation targetCenter = target.getHitBox().getMidPoint();
                    int diffx = craftCenter.getX() - targetCenter.getX();
                    int diffz = craftCenter.getZ() - targetCenter.getZ();
                    int distsquared = craftCenter.distanceSquared(targetCenter);
                    // minute, or is completely new?
                    if (System.currentTimeMillis() - recentContactTracking.get(craft).getOrDefault(target, 0L) <= 60000)
                        continue;
                    Component notification = I18nSupport.getInternationalisedComponent("Contact - New Contact").append(Component.text(": "));
                    if (target.getName().length() >= 1)
                        notification = notification.append(Component.text(target.getName() + " ("));
                    notification = notification.append(Component.text(target.getType().getStringProperty(CraftType.NAME)));
                    if (target.getName().length() >= 1)
                        notification = notification.append(Component.text(")"));
                    notification = notification.append(Component.text(" ")).append(I18nSupport.getInternationalisedComponent("Contact - Commanded By")).append(Component.text(" "));
                    if (target instanceof PilotedCraft)
                        notification = notification.append(Component.text(((PilotedCraft) target).getPilot().getDisplayName()));
                    else
                        notification = notification.append(Component.text("NULL"));
                    notification = notification.append(Component.text(", ")).append(I18nSupport.getInternationalisedComponent("Contact - Size")).append(Component.text(": ")).append(Component.text(target.getOrigBlockCount())).append(Component.text(", ")).append(I18nSupport.getInternationalisedComponent("Contact - Range")).append(Component.text(": ")).append(Component.text((int) Math.sqrt(distsquared))).append(Component.text(" ")).append(I18nSupport.getInternationalisedComponent("Contact - To The")).append(Component.text(" "));
                    if (Math.abs(diffx) > Math.abs(diffz)) {
                        if (diffx < 0)
                            notification = notification.append(I18nSupport.getInternationalisedComponent("Contact/Subcraft Rotate - East"));
                        else
                            notification = notification.append(I18nSupport.getInternationalisedComponent("Contact/Subcraft Rotate - West"));
                    } else if (diffz < 0)
                        notification = notification.append(I18nSupport.getInternationalisedComponent("Contact/Subcraft Rotate - South"));
                    else
                        notification = notification.append(I18nSupport.getInternationalisedComponent("Contact/Subcraft Rotate - North"));
                    notification = notification.append(Component.text("."));
                    craft.getAudience().sendMessage(notification);
                    var object = craft.getType().getObjectProperty(CraftType.COLLISION_SOUND);
                    if (!(object instanceof Sound))
                        throw new IllegalStateException("COLLISION_SOUND must be of type Sound");
                    craft.getAudience().playSound((Sound) object);
                    long timestamp = System.currentTimeMillis();
                    recentContactTracking.get(craft).put(target, timestamp);
                }
            }
        }
        lastContactCheck = System.currentTimeMillis();
    }
}
Also used : SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) PlayerCraft(net.countercraft.movecraft.craft.PlayerCraft) Craft(net.countercraft.movecraft.craft.Craft) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) PilotedCraft(net.countercraft.movecraft.craft.PilotedCraft) Sound(net.kyori.adventure.sound.Sound) World(org.bukkit.World) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) Component(net.kyori.adventure.text.Component)

Example 5 with PilotedCraft

use of net.countercraft.movecraft.craft.PilotedCraft 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)

Aggregations

Craft (net.countercraft.movecraft.craft.Craft)6 PilotedCraft (net.countercraft.movecraft.craft.PilotedCraft)6 SinkingCraft (net.countercraft.movecraft.craft.SinkingCraft)4 MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)3 PlayerCraft (net.countercraft.movecraft.craft.PlayerCraft)2 TopicPaginator (net.countercraft.movecraft.util.TopicPaginator)2 HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)2 World (org.bukkit.World)2 Player (org.bukkit.entity.Player)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 WeakHashMap (java.util.WeakHashMap)1 Collectors (java.util.stream.Collectors)1 Settings (net.countercraft.movecraft.config.Settings)1 CraftDetectEvent (net.countercraft.movecraft.events.CraftDetectEvent)1 ChatUtils (net.countercraft.movecraft.util.ChatUtils)1 Sound (net.kyori.adventure.sound.Sound)1 Component (net.kyori.adventure.text.Component)1 Tag (org.bukkit.Tag)1