Search in sources :

Example 1 with UpdateCommand

use of net.countercraft.movecraft.mapUpdater.update.UpdateCommand in project Movecraft by APDevTeam.

the class MapUpdateManager method run.

public void run() {
    if (updates.isEmpty())
        return;
    Logger logger = Movecraft.getInstance().getLogger();
    long startTime = System.currentTimeMillis();
    // and set all crafts that were updated to not processing
    // updates.sort((o1, o2) -> o1.getClass().getName().compareToIgnoreCase(o2.getClass().getName()));
    UpdateCommand next = updates.poll();
    while (next != null) {
        next.doUpdate();
        next = updates.poll();
    }
    /*// queue chunks for lighting recalc
        if (!Settings.CompatibilityMode) {
            for (net.minecraft.server.v1_10_R1.Chunk c : chunksToRelight) {
                ChunkUpdater fChunk = FastBlockChanger.getInstance().getChunk(c.world, c.locX, c.locZ, true);
                for (int bx = 0; bx < 16; bx++) {
                    for (int bz = 0; bz < 16; bz++) {
                        for (int by = 0; by < 4; by++) {
                            fChunk.bits[bx][bz][by] = Long.MAX_VALUE;
                        }
                    }
                }
                fChunk.last_modified = System.currentTimeMillis();
                c.e();
            }
        }*/
    if (Settings.Debug) {
        long endTime = System.currentTimeMillis();
        logger.info("Map update took (ms): " + (endTime - startTime));
    }
}
Also used : UpdateCommand(net.countercraft.movecraft.mapUpdater.update.UpdateCommand) Logger(java.util.logging.Logger)

Example 2 with UpdateCommand

use of net.countercraft.movecraft.mapUpdater.update.UpdateCommand 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

UpdateCommand (net.countercraft.movecraft.mapUpdater.update.UpdateCommand)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 Logger (java.util.logging.Logger)1 MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)1 BlockCreateCommand (net.countercraft.movecraft.mapUpdater.update.BlockCreateCommand)1 HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 BlockData (org.bukkit.block.data.BlockData)1