Search in sources :

Example 1 with HitBox

use of net.countercraft.movecraft.util.hitboxes.HitBox 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 HitBox

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

the class DetectionTask method water.

@Deprecated
@NotNull
private Effect water(@NotNull Craft craft) {
    final int waterLine = WorldManager.INSTANCE.executeMain(craft::getWaterLine);
    if (craft.getType().getBoolProperty(CraftType.BLOCKED_BY_WATER) || craft.getHitBox().getMinY() > waterLine)
        return () -> {
        };
    var badWorld = WorldManager.INSTANCE.executeMain(craft::getWorld);
    // The subtraction of the set of coordinates in the HitBox cube and the HitBox itself
    final HitBox invertedHitBox = new BitmapHitBox(craft.getHitBox().boundingHitBox()).difference(craft.getHitBox());
    // A set of locations that are confirmed to be "exterior" locations
    final SetHitBox confirmed = new SetHitBox();
    final SetHitBox entireHitbox = new SetHitBox(craft.getHitBox());
    // place phased blocks
    final Set<Location> overlap = new HashSet<>(craft.getPhaseBlocks().keySet());
    overlap.retainAll(craft.getHitBox().asSet().stream().map(l -> l.toBukkit(badWorld)).collect(Collectors.toSet()));
    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(new BitmapHitBox(hitBox).difference(craft.getHitBox()));
    }
    // Check to see which locations in the from set are actually outside of the craft
    // use a modified BFS for multiple origin elements
    SetHitBox visited = new SetHitBox();
    Queue<MovecraftLocation> queue = Lists.newLinkedList(validExterior);
    while (!queue.isEmpty()) {
        MovecraftLocation node = queue.poll();
        if (visited.contains(node))
            continue;
        visited.add(node);
        // If the node is already a valid member of the exterior of the HitBox, continued search is unitary.
        for (MovecraftLocation neighbor : CollectionUtils.neighbors(invertedHitBox, node)) {
            queue.add(neighbor);
        }
    }
    confirmed.addAll(visited);
    entireHitbox.addAll(invertedHitBox.difference(confirmed));
    var waterData = Bukkit.createBlockData(Material.WATER);
    return () -> {
        for (MovecraftLocation location : entireHitbox) {
            if (location.getY() <= waterLine) {
                craft.getPhaseBlocks().put(location.toBukkit(badWorld), waterData);
            }
        }
    };
}
Also used : BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) 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) Movecraft(net.countercraft.movecraft.Movecraft) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) Location(org.bukkit.Location) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with HitBox

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

the class DetectionTask method get.

@Override
public Effect get() {
    frontier();
    if (!illegal.isEmpty())
        return null;
    var result = COMPLETION_VALIDATORS.stream().reduce(DetectionPredicate::and).orElse((a, b, c, d) -> Result.fail()).validate(materials, type, movecraftWorld, player);
    result = result.isSucess() ? VISITED_VALIDATORS.stream().reduce(DetectionPredicate::and).orElse((a, b, c, d) -> Result.fail()).validate(visitedMaterials, type, movecraftWorld, player) : result;
    if (!result.isSucess()) {
        String message = result.getMessage();
        return () -> audience.sendMessage(Component.text(message));
    }
    var hitbox = new BitmapHitBox(legal);
    var parents = findParents(hitbox);
    var supplied = supplier.apply(type, world, player, parents);
    result = supplied.getLeft();
    Craft craft = supplied.getRight();
    if (type.getBoolProperty(CraftType.MUST_BE_SUBCRAFT) && !(craft instanceof SubCraft)) {
        result = Result.failWithMessage(I18nSupport.getInternationalisedString("Detection - Must Be Subcraft"));
    }
    if (!result.isSucess()) {
        String message = result.getMessage();
        return () -> audience.sendMessage(Component.text(message));
    }
    craft.setAudience(audience);
    craft.setHitBox(hitbox);
    craft.setFluidLocations(new BitmapHitBox(fluid));
    craft.setOrigBlockCount(craft.getHitBox().size());
    final CraftDetectEvent event = new CraftDetectEvent(craft, startLocation);
    WorldManager.INSTANCE.executeMain(() -> Bukkit.getPluginManager().callEvent(event));
    if (event.isCancelled())
        return () -> craft.getAudience().sendMessage(Component.text(event.getFailMessage()));
    return ((Effect) () -> {
        // Notify player and console
        craft.getAudience().sendMessage(Component.text(String.format("%s Size: %s", I18nSupport.getInternationalisedString("Detection - Successfully piloted craft"), craft.getHitBox().size())));
        Movecraft.getInstance().getLogger().info(String.format(I18nSupport.getInternationalisedString("Detection - Success - Log Output"), player == null ? "null" : player.getName(), craft.getType().getStringProperty(CraftType.NAME), craft.getHitBox().size(), craft.getHitBox().getMinX(), craft.getHitBox().getMinZ()));
    }).andThen(// TODO: Remove
    water(craft)).andThen(// Fire off pilot event
    () -> Bukkit.getServer().getPluginManager().callEvent(new CraftPilotEvent(craft, CraftPilotEvent.Reason.PLAYER))).andThen(// Apply post detection effect
    postDetection.apply(craft)).andThen(// Add craft to CraftManager
    () -> CraftManager.getInstance().add(craft));
}
Also used : AllowedBlockValidator(net.countercraft.movecraft.processing.tasks.detection.validators.AllowedBlockValidator) Arrays(java.util.Arrays) CraftDetectEvent(net.countercraft.movecraft.events.CraftDetectEvent) MovecraftWorld(net.countercraft.movecraft.processing.MovecraftWorld) Player(org.bukkit.entity.Player) Location(org.bukkit.Location) World(org.bukkit.World) Map(java.util.Map) FlyBlockValidator(net.countercraft.movecraft.processing.tasks.detection.validators.FlyBlockValidator) CraftManager(net.countercraft.movecraft.craft.CraftManager) Material(org.bukkit.Material) Effect(net.countercraft.movecraft.processing.effects.Effect) Bukkit(org.bukkit.Bukkit) Result(net.countercraft.movecraft.processing.functions.Result) CraftType(net.countercraft.movecraft.craft.type.CraftType) PilotSignValidator(net.countercraft.movecraft.processing.tasks.detection.validators.PilotSignValidator) Craft(net.countercraft.movecraft.craft.Craft) BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) AtomicLocationSet(net.countercraft.movecraft.util.AtomicLocationSet) Movecraft(net.countercraft.movecraft.Movecraft) I18nSupport(net.countercraft.movecraft.localisation.I18nSupport) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CraftSupplier(net.countercraft.movecraft.processing.functions.CraftSupplier) WaterContactValidator(net.countercraft.movecraft.processing.tasks.detection.validators.WaterContactValidator) Queue(java.util.Queue) DetectionPredicate(net.countercraft.movecraft.processing.functions.DetectionPredicate) NotNull(org.jetbrains.annotations.NotNull) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) SubCraft(net.countercraft.movecraft.craft.SubCraft) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) LongAdder(java.util.concurrent.atomic.LongAdder) CollectionUtils(net.countercraft.movecraft.util.CollectionUtils) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) Deque(java.util.Deque) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CraftPilotEvent(net.countercraft.movecraft.events.CraftPilotEvent) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) NameSignValidator(net.countercraft.movecraft.processing.tasks.detection.validators.NameSignValidator) Component(net.kyori.adventure.text.Component) WorldManager(net.countercraft.movecraft.processing.WorldManager) HitBox(net.countercraft.movecraft.util.hitboxes.HitBox) Functions(com.google.common.base.Functions) ForkJoinTask(java.util.concurrent.ForkJoinTask) ForbiddenSignStringValidator(net.countercraft.movecraft.processing.tasks.detection.validators.ForbiddenSignStringValidator) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) ForbiddenBlockValidator(net.countercraft.movecraft.processing.tasks.detection.validators.ForbiddenBlockValidator) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Tags(net.countercraft.movecraft.util.Tags) Audience(net.kyori.adventure.audience.Audience) ForkJoinPool(java.util.concurrent.ForkJoinPool) SizeValidator(net.countercraft.movecraft.processing.tasks.detection.validators.SizeValidator) Comparator(java.util.Comparator) Collections(java.util.Collections) Craft(net.countercraft.movecraft.craft.Craft) SubCraft(net.countercraft.movecraft.craft.SubCraft) CraftDetectEvent(net.countercraft.movecraft.events.CraftDetectEvent) SubCraft(net.countercraft.movecraft.craft.SubCraft) DetectionPredicate(net.countercraft.movecraft.processing.functions.DetectionPredicate) BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) CraftPilotEvent(net.countercraft.movecraft.events.CraftPilotEvent)

Example 4 with HitBox

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

the class CraftRotateCommand 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();
    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()) {
        SetHitBox originalLocations = new SetHitBox();
        final MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE;
        for (MovecraftLocation movecraftLocation : craft.getHitBox()) {
            originalLocations.add(MathUtils.rotateVec(counterRotation, movecraftLocation.subtract(originLocation)).add(originLocation));
        }
        final HitBox to = craft.getHitBox().difference(originalLocations);
        for (MovecraftLocation location : to) {
            var data = location.toBukkit(craft.getWorld()).getBlock().getBlockData();
            if (passthroughBlocks.contains(data.getMaterial())) {
                craft.getPhaseBlocks().put(location.toBukkit(craft.getWorld()), data);
            }
        }
        // The subtraction of the set of coordinates in the HitBox cube and the HitBox itself
        final HitBox invertedHitBox = new SetHitBox(craft.getHitBox().boundingHitBox()).difference(craft.getHitBox());
        // A set of locations that are confirmed to be "exterior" locations
        final SetHitBox exterior = new SetHitBox();
        final SetHitBox interior = new SetHitBox();
        // place phased blocks
        final Set<Location> overlap = new HashSet<>(craft.getPhaseBlocks().keySet());
        overlap.retainAll(craft.getHitBox().asSet().stream().map(l -> l.toBukkit(craft.getWorld())).collect(Collectors.toSet()));
        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)) };
        // Valid exterior starts as the 6 surface planes of the HitBox with the locations that lie in the HitBox removed
        final SetHitBox validExterior = new SetHitBox();
        for (HitBox hitBox : surfaces) {
            validExterior.addAll(hitBox.difference(craft.getHitBox()));
        }
        // Check to see which locations in the from set are actually outside of the craft
        for (MovecraftLocation location : validExterior) {
            if (craft.getHitBox().contains(location) || exterior.contains(location)) {
                continue;
            }
            // use a modified BFS for multiple origin elements
            SetHitBox visited = new SetHitBox();
            Queue<MovecraftLocation> queue = new LinkedList<>();
            queue.add(location);
            while (!queue.isEmpty()) {
                MovecraftLocation node = queue.poll();
                // If the node is already a valid member of the exterior of the HitBox, continued search is unitary.
                for (MovecraftLocation neighbor : CollectionUtils.neighbors(invertedHitBox, node)) {
                    if (visited.contains(neighbor)) {
                        continue;
                    }
                    visited.add(neighbor);
                    queue.add(neighbor);
                }
            }
            exterior.addAll(visited);
        }
        interior.addAll(invertedHitBox.difference(exterior));
        final WorldHandler handler = Movecraft.getInstance().getWorldHandler();
        for (MovecraftLocation location : invertedHitBox.difference(exterior)) {
            var data = location.toBukkit(craft.getWorld()).getBlock().getBlockData();
            if (!passthroughBlocks.contains(data.getMaterial())) {
                continue;
            }
            craft.getPhaseBlocks().put(location.toBukkit(craft.getWorld()), data);
        }
        // translate the craft
        handler.rotateCraft(craft, originLocation, rotation);
        // trigger sign events
        sendSignEvents();
        // place confirmed blocks if they have been un-phased
        for (MovecraftLocation location : exterior) {
            Location bukkit = location.toBukkit(craft.getWorld());
            if (!craft.getPhaseBlocks().containsKey(bukkit)) {
                continue;
            }
            var phaseBlock = craft.getPhaseBlocks().remove(bukkit);
            handler.setBlockFast(bukkit, phaseBlock);
            craft.getPhaseBlocks().remove(bukkit);
        }
        for (MovecraftLocation location : originalLocations.boundingHitBox()) {
            Location bukkit = location.toBukkit(craft.getWorld());
            if (!craft.getHitBox().inBounds(location) && craft.getPhaseBlocks().containsKey(bukkit)) {
                var phaseBlock = craft.getPhaseBlocks().remove(bukkit);
                handler.setBlockFast(bukkit, phaseBlock);
            }
        }
        for (MovecraftLocation location : interior) {
            Location bukkit = location.toBukkit(craft.getWorld());
            var data = bukkit.getBlock().getBlockData();
            if (passthroughBlocks.contains(data.getMaterial())) {
                craft.getPhaseBlocks().put(bukkit, data);
                handler.setBlockFast(bukkit, Material.AIR.createBlockData());
            }
        }
    } else {
        // translate the craft
        Movecraft.getInstance().getWorldHandler().rotateCraft(craft, originLocation, rotation);
        // trigger sign events
        sendSignEvents();
    }
    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()));
}
Also used : 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) WorldHandler(net.countercraft.movecraft.WorldHandler) LinkedList(java.util.LinkedList) MovecraftRotation(net.countercraft.movecraft.MovecraftRotation) SinkingCraft(net.countercraft.movecraft.craft.SinkingCraft) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) HashSet(java.util.HashSet) Location(org.bukkit.Location) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation)

Example 5 with HitBox

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

the class AsyncManager method processFadingBlocks.

private void processFadingBlocks() {
    if (Settings.FadeWrecksAfter == 0)
        return;
    long ticksElapsed = (System.currentTimeMillis() - lastFadeCheck) / 50;
    if (ticksElapsed <= Settings.FadeTickCooldown)
        return;
    List<HitBox> processed = new ArrayList<>();
    for (Map.Entry<HitBox, Long> entry : wrecks.entrySet()) {
        if (Settings.FadeWrecksAfter * 1000L > System.currentTimeMillis() - entry.getValue())
            continue;
        final HitBox hitBox = entry.getKey();
        final Map<Location, BlockData> phaseBlocks = wreckPhases.get(hitBox);
        final World world = wreckWorlds.get(hitBox);
        List<UpdateCommand> commands = new ArrayList<>();
        int fadedBlocks = 0;
        if (!processedFadeLocs.containsKey(world))
            processedFadeLocs.put(world, new HashSet<>());
        int maxFadeBlocks = (int) (hitBox.size() * (Settings.FadePercentageOfWreckPerCycle / 100.0));
        // Iterate hitbox as a set to get more random locations
        for (MovecraftLocation location : hitBox.asSet()) {
            if (processedFadeLocs.get(world).contains(location))
                continue;
            if (fadedBlocks >= maxFadeBlocks)
                break;
            final Location bLoc = location.toBukkit(world);
            if ((Settings.FadeWrecksAfter + Settings.ExtraFadeTimePerBlock.getOrDefault(bLoc.getBlock().getType(), 0)) * 1000L > System.currentTimeMillis() - entry.getValue())
                continue;
            fadedBlocks++;
            processedFadeLocs.get(world).add(location);
            BlockData phaseBlock = phaseBlocks.getOrDefault(bLoc, Material.AIR.createBlockData());
            commands.add(new BlockCreateCommand(world, location, phaseBlock));
        }
        MapUpdateManager.getInstance().scheduleUpdates(commands);
        if (!processedFadeLocs.get(world).containsAll(hitBox.asSet()))
            continue;
        processed.add(hitBox);
        processedFadeLocs.get(world).removeAll(hitBox.asSet());
    }
    for (HitBox hitBox : processed) {
        wrecks.remove(hitBox);
        wreckPhases.remove(hitBox);
        wreckWorlds.remove(hitBox);
    }
    lastFadeCheck = System.currentTimeMillis();
}
Also used : HitBox(net.countercraft.movecraft.util.hitboxes.HitBox) ArrayList(java.util.ArrayList) World(org.bukkit.World) UpdateCommand(net.countercraft.movecraft.mapUpdater.update.UpdateCommand) BlockData(org.bukkit.block.data.BlockData) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) BlockCreateCommand(net.countercraft.movecraft.mapUpdater.update.BlockCreateCommand) HashMap(java.util.HashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) Location(org.bukkit.Location) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) HashSet(java.util.HashSet)

Aggregations

HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)8 MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)7 HashSet (java.util.HashSet)5 SetHitBox (net.countercraft.movecraft.util.hitboxes.SetHitBox)5 SolidHitBox (net.countercraft.movecraft.util.hitboxes.SolidHitBox)5 Location (org.bukkit.Location)5 Craft (net.countercraft.movecraft.craft.Craft)4 SinkingCraft (net.countercraft.movecraft.craft.SinkingCraft)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Movecraft (net.countercraft.movecraft.Movecraft)3 Lists (com.google.common.collect.Lists)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Queue (java.util.Queue)2 Set (java.util.Set)2