Search in sources :

Example 11 with SinkingCraft

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

the class ScuttleCommand method onCommand.

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
    if (!command.getName().equalsIgnoreCase("scuttle")) {
        return false;
    }
    Craft craft = null;
    // Scuttle other player
    if (commandSender.hasPermission("movecraft.commands.scuttle.others") && strings.length >= 1) {
        Player player = Bukkit.getPlayer(strings[0]);
        if (player == null) {
            commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Scuttle - Must Be Online"));
            return true;
        }
        craft = CraftManager.getInstance().getCraftByPlayer(player);
    } else if (commandSender.hasPermission("movecraft.commands.scuttle.self") && strings.length == 0) {
        if (!(commandSender instanceof Player)) {
            commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Scuttle - Must Be Player"));
            return true;
        }
        craft = CraftManager.getInstance().getCraftByPlayer(Bukkit.getPlayer(commandSender.getName()));
    }
    if (craft == null) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("You must be piloting a craft"));
        return true;
    }
    if (craft instanceof SinkingCraft) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Scuttle - Craft Already Sinking"));
        return true;
    }
    if (!commandSender.hasPermission("movecraft." + craft.getType().getStringProperty(CraftType.NAME) + ".scuttle")) {
        commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
        return true;
    }
    CraftScuttleEvent e = new CraftScuttleEvent(craft, (Player) commandSender);
    Bukkit.getServer().getPluginManager().callEvent(e);
    if (e.isCancelled())
        return true;
    craft.setCruising(false);
    CraftManager.getInstance().sink(craft);
    commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Scuttle - Scuttle Activated"));
    return true;
}
Also used : SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) CraftScuttleEvent(net.countercraft.movecraft.events.CraftScuttleEvent) Player(org.bukkit.entity.Player) SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) Craft(net.countercraft.movecraft.craft.Craft)

Example 12 with SinkingCraft

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

the class CraftTranslateCommand method doUpdate.

@Override
public void doUpdate() {
    final Logger logger = Movecraft.getInstance().getLogger();
    if (craft.getHitBox().isEmpty()) {
        logger.warning("Attempted to move craft with empty HashHitBox!");
        CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.EMPTY, false);
        return;
    }
    long time = System.nanoTime();
    World oldWorld = craft.getWorld();
    final Set<Material> passthroughBlocks = new HashSet<>(craft.getType().getMaterialSetProperty(CraftType.PASSTHROUGH_BLOCKS));
    if (craft instanceof SinkingCraft) {
        passthroughBlocks.addAll(Tags.FLUID);
        passthroughBlocks.addAll(Tag.LEAVES.getValues());
        passthroughBlocks.addAll(Tags.SINKING_PASSTHROUGH);
    }
    if (passthroughBlocks.isEmpty()) {
        // translate the craft
        Movecraft.getInstance().getWorldHandler().translateCraft(craft, displacement, world);
        craft.setWorld(world);
        // trigger sign events
        sendSignEvents();
    } else {
        SetHitBox originalLocations = new SetHitBox();
        for (MovecraftLocation movecraftLocation : craft.getHitBox()) {
            originalLocations.add(movecraftLocation.subtract(displacement));
        }
        final Set<MovecraftLocation> to = Sets.difference(craft.getHitBox().asSet(), originalLocations.asSet());
        // place phased blocks
        for (MovecraftLocation location : to) {
            var data = location.toBukkit(world).getBlock().getBlockData();
            if (passthroughBlocks.contains(data.getMaterial())) {
                craft.getPhaseBlocks().put(location.toBukkit(world), data);
            }
        }
        // The subtraction of the set of coordinates in the HitBox cube and the HitBox itself
        final var invertedHitBox = Sets.difference(craft.getHitBox().boundingHitBox().asSet(), craft.getHitBox().asSet());
        // place phased blocks
        final Set<Location> overlap = new HashSet<>(craft.getPhaseBlocks().keySet());
        overlap.removeIf((location -> !craft.getHitBox().contains(MathUtils.bukkit2MovecraftLoc(location))));
        final int minX = craft.getHitBox().getMinX();
        final int maxX = craft.getHitBox().getMaxX();
        final int minY = craft.getHitBox().getMinY();
        final int maxY = overlap.isEmpty() ? craft.getHitBox().getMaxY() : Collections.max(overlap, Comparator.comparingInt(Location::getBlockY)).getBlockY();
        final int minZ = craft.getHitBox().getMinZ();
        final int maxZ = craft.getHitBox().getMaxZ();
        final HitBox[] surfaces = { new SolidHitBox(new MovecraftLocation(minX, minY, minZ), new MovecraftLocation(minX, maxY, maxZ)), new SolidHitBox(new MovecraftLocation(minX, minY, minZ), new MovecraftLocation(maxX, maxY, minZ)), new SolidHitBox(new MovecraftLocation(maxX, minY, maxZ), new MovecraftLocation(minX, maxY, maxZ)), new SolidHitBox(new MovecraftLocation(maxX, minY, maxZ), new MovecraftLocation(maxX, maxY, minZ)), new SolidHitBox(new MovecraftLocation(minX, minY, minZ), new MovecraftLocation(maxX, minY, maxZ)) };
        final SetHitBox validExterior = new SetHitBox();
        for (HitBox hitBox : surfaces) {
            validExterior.addAll(Sets.difference(hitBox.asSet(), craft.getHitBox().asSet()));
        }
        // Check to see which locations in the from set are actually outside of the craft
        final Set<MovecraftLocation> confirmed = craft instanceof SinkingCraft ? invertedHitBox.copyInto(new LinkedHashSet<>()) : verifyExterior(invertedHitBox, validExterior);
        // A set of locations that are confirmed to be "exterior" locations
        final Set<MovecraftLocation> failed = Sets.difference(invertedHitBox, confirmed).copyInto(new LinkedHashSet<>());
        final WorldHandler handler = Movecraft.getInstance().getWorldHandler();
        for (MovecraftLocation location : failed) {
            var data = location.toBukkit(world).getBlock().getBlockData();
            if (!passthroughBlocks.contains(data.getMaterial()))
                continue;
            craft.getPhaseBlocks().put(location.toBukkit(world), data);
        }
        // translate the craft
        handler.translateCraft(craft, displacement, world);
        craft.setWorld(world);
        // trigger sign events
        sendSignEvents();
        for (MovecraftLocation l : failed) {
            MovecraftLocation orig = l.subtract(displacement);
            if (craft.getHitBox().contains(orig) || failed.contains(orig)) {
                continue;
            }
            confirmed.add(orig);
        }
        // place confirmed blocks if they have been un-phased
        for (MovecraftLocation location : confirmed) {
            Location bukkit = location.toBukkit(craft.getWorld());
            if (!craft.getPhaseBlocks().containsKey(bukkit))
                continue;
            // Do not place if it is at a collapsed HitBox location
            if (!craft.getCollapsedHitBox().isEmpty() && craft.getCollapsedHitBox().contains(location))
                continue;
            var phaseBlock = craft.getPhaseBlocks().remove(bukkit);
            handler.setBlockFast(bukkit, phaseBlock);
            craft.getPhaseBlocks().remove(bukkit);
        }
        for (MovecraftLocation location : originalLocations) {
            Location bukkit = location.toBukkit(oldWorld);
            if (!craft.getHitBox().contains(location) && craft.getPhaseBlocks().containsKey(bukkit)) {
                var phaseBlock = craft.getPhaseBlocks().remove(bukkit);
                handler.setBlockFast(bukkit, phaseBlock);
            }
        }
        for (MovecraftLocation location : failed) {
            Location bukkit = location.toBukkit(oldWorld);
            var data = bukkit.getBlock().getBlockData();
            if (passthroughBlocks.contains(data.getMaterial())) {
                craft.getPhaseBlocks().put(bukkit, data);
                handler.setBlockFast(bukkit, Material.AIR.createBlockData());
            }
        }
    // waterlog();
    }
    if (!craft.isNotProcessing())
        craft.setProcessing(false);
    time = System.nanoTime() - time;
    if (Settings.Debug)
        logger.info("Total time: " + (time / 1e6) + " milliseconds. Moving with cooldown of " + craft.getTickCooldown() + ". Speed of: " + String.format("%.2f", craft.getSpeed()) + ". Displacement of: " + displacement);
    // Only add cruise time if cruising
    if (craft.getCruising() && displacement.getY() == 0 && (displacement.getX() == 0 || displacement.getZ() == 0))
        craft.addCruiseTime(time / 1e9f);
}
Also used : SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) Arrays(java.util.Arrays) Tag(org.bukkit.Tag) Hash(it.unimi.dsi.fastutil.Hash) Object2ObjectMap(it.unimi.dsi.fastutil.objects.Object2ObjectMap) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) Waterlogged(org.bukkit.block.data.Waterlogged) HashMap(java.util.HashMap) CraftReleaseEvent(net.countercraft.movecraft.events.CraftReleaseEvent) SignTranslateEvent(net.countercraft.movecraft.events.SignTranslateEvent) WorldHandler(net.countercraft.movecraft.WorldHandler) MathUtils(net.countercraft.movecraft.util.MathUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) Block(org.bukkit.block.Block) Location(org.bukkit.Location) World(org.bukkit.World) Map(java.util.Map) LinkedList(java.util.LinkedList) CraftManager(net.countercraft.movecraft.craft.CraftManager) Material(org.bukkit.Material) LinkedHashSet(java.util.LinkedHashSet) HitBox(net.countercraft.movecraft.util.hitboxes.HitBox) Bukkit(org.bukkit.Bukkit) Sign(org.bukkit.block.Sign) CraftType(net.countercraft.movecraft.craft.type.CraftType) Object2ObjectOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap) Craft(net.countercraft.movecraft.craft.Craft) BlockState(org.bukkit.block.BlockState) Set(java.util.Set) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) Logger(java.util.logging.Logger) Movecraft(net.countercraft.movecraft.Movecraft) Sets(com.google.common.collect.Sets) Settings(net.countercraft.movecraft.config.Settings) Objects(java.util.Objects) List(java.util.List) Tags(net.countercraft.movecraft.util.Tags) Queue(java.util.Queue) NotNull(org.jetbrains.annotations.NotNull) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) Collections(java.util.Collections) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) LinkedHashSet(java.util.LinkedHashSet) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) HitBox(net.countercraft.movecraft.util.hitboxes.HitBox) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) Material(org.bukkit.Material) Logger(java.util.logging.Logger) World(org.bukkit.World) WorldHandler(net.countercraft.movecraft.WorldHandler) SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Location(org.bukkit.Location) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation)

Example 13 with SinkingCraft

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

SinkingCraft (net.countercraft.movecraft.craft.SinkingCraft)13 Craft (net.countercraft.movecraft.craft.Craft)8 MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)7 Location (org.bukkit.Location)6 PilotedCraft (net.countercraft.movecraft.craft.PilotedCraft)5 Material (org.bukkit.Material)5 HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)4 EntityUpdateCommand (net.countercraft.movecraft.mapUpdater.update.EntityUpdateCommand)3 Block (org.bukkit.block.Block)3 Entity (org.bukkit.entity.Entity)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Logger (java.util.logging.Logger)2 WorldHandler (net.countercraft.movecraft.WorldHandler)2 PlayerCraft (net.countercraft.movecraft.craft.PlayerCraft)2 CraftScuttleEvent (net.countercraft.movecraft.events.CraftScuttleEvent)2 SetHitBox (net.countercraft.movecraft.util.hitboxes.SetHitBox)2 Player (org.bukkit.entity.Player)2