co.aikar.timings.Timings Java Examples

The following examples show how to use co.aikar.timings.Timings. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public boolean batchDataPacket(DataPacket packet) {
    if (!this.connected) {
        return false;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent event = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            timing.stopTiming();
            return false;
        }

        if (!this.batchedPackets.containsKey(packet.getChannel())) {
            this.batchedPackets.put(packet.getChannel(), new ArrayList<>());
        }

        this.batchedPackets.get(packet.getChannel()).add(packet.clone());
    }
    return true;
}
 
Example #2
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int directDataPacket(DataPacket packet, boolean needACK) {
    if (!this.connected) {
        return -1;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            return -1;
        }

        Integer identifier = this.interfaz.putPacket(this, packet, needACK, true);

        if (needACK && identifier != null) {
            this.needACK.put(identifier, Boolean.FALSE);
            return identifier;
        }
    }
    return 0;
}
 
Example #3
Source File: BlockEntity.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public BlockEntity(FullChunk chunk, CompoundTag nbt) {
    if (chunk == null || chunk.getProvider() == null) {
        throw new ChunkException("Invalid garbage Chunk given to Block Entity");
    }

    this.timing = Timings.getBlockEntityTiming(this);
    this.server = chunk.getProvider().getLevel().getServer();
    this.chunk = chunk;
    this.setLevel(chunk.getProvider().getLevel());
    this.namedTag = nbt;
    this.name = "";
    this.lastUpdate = System.currentTimeMillis();
    this.id = BlockEntity.count++;
    this.x = this.namedTag.getInt("x");
    this.y = this.namedTag.getInt("y");
    this.z = this.namedTag.getInt("z");
    this.movable = this.namedTag.getBoolean("isMovable");

    this.initBlockEntity();

    this.chunk.addBlockEntity(this);
    this.getLevel().addBlockEntity(this);
}
 
Example #4
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int dataPacket(DataPacket packet, boolean needACK) {
    if (!this.connected) {
        return -1;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            return -1;
        }

        if (log.isTraceEnabled() && !(packet instanceof BatchPacket)) {
            log.trace("Outbound {}: {}", this.getName(), packet);
        }

        Integer identifier = this.interfaz.putPacket(this, packet, needACK, false);

        if (needACK && identifier != null) {
            this.needACK.put(identifier, Boolean.FALSE);
            return identifier;
        }
    }
    return 0;
}
 
Example #5
Source File: BlockEntity.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public BlockEntity(FullChunk chunk, CompoundTag nbt) {
    if (chunk == null || chunk.getProvider() == null) {
        throw new ChunkException("Invalid garbage Chunk given to Block Entity");
    }

    this.timing = Timings.getBlockEntityTiming(this);
    this.server = chunk.getProvider().getLevel().getServer();
    this.chunk = chunk;
    this.setLevel(chunk.getProvider().getLevel());
    this.namedTag = nbt;
    this.name = "";
    this.lastUpdate = System.currentTimeMillis();
    this.id = BlockEntity.count++;
    this.x = this.namedTag.getInt("x");
    this.y = this.namedTag.getInt("y");
    this.z = this.namedTag.getInt("z");
    this.movable = this.namedTag.getBoolean("isMovable");

    this.initBlockEntity();

    this.chunk.addBlockEntity(this);
    this.getLevel().addBlockEntity(this);
}
 
Example #6
Source File: BlockEntity.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public BlockEntity(FullChunk chunk, CompoundTag nbt) {
    if (chunk == null || chunk.getProvider() == null) {
        throw new ChunkException("Invalid garbage Chunk given to Block Entity");
    }

    this.timing = Timings.getBlockEntityTiming(this);
    this.server = chunk.getProvider().getLevel().getServer();
    this.chunk = chunk;
    this.setLevel(chunk.getProvider().getLevel());
    this.namedTag = nbt;
    this.name = "";
    this.lastUpdate = System.currentTimeMillis();
    this.id = BlockEntity.count++;
    this.x = this.namedTag.getInt("x");
    this.y = this.namedTag.getInt("y");
    this.z = this.namedTag.getInt("z");
    this.movable = this.namedTag.getBoolean("isMovable");

    this.chunk.addBlockEntity(this);
    this.getLevel().addBlockEntity(this);
}
 
Example #7
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public boolean batchDataPacket(DataPacket packet) {
    if (!this.connected) {
        return false;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent event = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return false;
        }

        if (!this.batchedPackets.containsKey(packet.getChannel())) {
            this.batchedPackets.put(packet.getChannel(), new ArrayList<>());
        }

        this.batchedPackets.get(packet.getChannel()).add(packet.clone());
    }
    return true;
}
 
Example #8
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int directDataPacket(DataPacket packet, boolean needACK) {
    if (!this.connected) {
        return -1;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            timing.stopTiming();
            return -1;
        }

        Integer identifier = this.interfaz.putPacket(this, packet, needACK, true);

        if (needACK && identifier != null) {
            this.needACK.put(identifier, Boolean.FALSE);
            timing.stopTiming();
            return identifier;
        }
    }
    return 0;
}
 
Example #9
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public void doAutoSave() {
    if (this.getAutoSave()) {
        Timings.levelSaveTimer.startTiming();
        for (Player player : new ArrayList<>(this.players.values())) {
            if (player.isOnline()) {
                player.save(true);
            } else if (!player.isConnected()) {
                this.removePlayer(player);
            }
        }

        for (Level level : this.getLevels().values()) {
            level.save();
        }
        Timings.levelSaveTimer.stopTiming();
    }
}
 
Example #10
Source File: Server.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void doAutoSave() {
    if (this.getAutoSave()) {
        Timings.levelSaveTimer.startTiming();
        for (Player player : new ArrayList<>(this.players.values())) {
            if (player.isOnline()) {
                player.save(true);
            } else if (!player.isConnected()) {
                this.removePlayer(player);
            }
        }

        for (Level level : this.levelArray) {
            level.save();
        }
        Timings.levelSaveTimer.stopTiming();
    }
}
 
Example #11
Source File: PermissibleBase.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void recalculatePermissions() {
    Timings.permissibleCalculationTimer.startTiming();

    this.clearPermissions();
    Map<String, Permission> defaults = Server.getInstance().getPluginManager().getDefaultPermissions(this.isOp());
    Server.getInstance().getPluginManager().subscribeToDefaultPerms(this.isOp(), this.parent != null ? this.parent : this);

    for (Permission perm : defaults.values()) {
        String name = perm.getName();
        this.permissions.put(name, new PermissionAttachmentInfo(this.parent != null ? this.parent : this, name, null, true));
        Server.getInstance().getPluginManager().subscribeToPermission(name, this.parent != null ? this.parent : this);
        this.calculateChildPermissions(perm.getChildren(), false, null);
    }

    for (PermissionAttachment attachment : this.attachments) {
        this.calculateChildPermissions(attachment.getPermissions(), false, attachment);
    }
    Timings.permissibleCalculationTimer.stopTiming();
}
 
Example #12
Source File: NukkitConsole.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void runCommand(String command) {
    if (executingCommands.get()) {
        Timings.serverCommandTimer.startTiming();
        ServerCommandEvent event = new ServerCommandEvent(server.getConsoleSender(), command);
        if (server.getPluginManager() != null) {
            server.getPluginManager().callEvent(event);
        }
        if (!event.isCancelled()) {
            Server.getInstance().getScheduler().scheduleTask(() -> server.dispatchCommand(event.getSender(), event.getCommand()));
        }
        Timings.serverCommandTimer.stopTiming();
    } else {
        consoleQueue.add(command);
    }
}
 
Example #13
Source File: Server.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void doAutoSave() {
    if (this.getAutoSave()) {
        Timings.levelSaveTimer.startTiming();
        for (Player player : new ArrayList<>(this.players.values())) {
            if (player.isOnline()) {
                player.save(true);
            } else if (!player.isConnected()) {
                this.removePlayer(player);
            }
        }

        for (Level level : this.levelArray) {
            level.save();
        }
        Timings.levelSaveTimer.stopTiming();
    }
}
 
Example #14
Source File: PermissibleBase.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void recalculatePermissions() {
    Timings.permissibleCalculationTimer.startTiming();

    this.clearPermissions();
    Map<String, Permission> defaults = Server.getInstance().getPluginManager().getDefaultPermissions(this.isOp());
    Server.getInstance().getPluginManager().subscribeToDefaultPerms(this.isOp(), this.parent != null ? this.parent : this);

    for (Permission perm : defaults.values()) {
        String name = perm.getName();
        this.permissions.put(name, new PermissionAttachmentInfo(this.parent != null ? this.parent : this, name, null, true));
        Server.getInstance().getPluginManager().subscribeToPermission(name, this.parent != null ? this.parent : this);
        this.calculateChildPermissions(perm.getChildren(), false, null);
    }

    for (PermissionAttachment attachment : this.attachments) {
        this.calculateChildPermissions(attachment.getPermissions(), false, attachment);
    }
    Timings.permissibleCalculationTimer.stopTiming();
}
 
Example #15
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int dataPacket(DataPacket packet, boolean needACK) {
    if (!this.connected) {
        return -1;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            timing.stopTiming();
            return -1;
        }

        Integer identifier = this.interfaz.putPacket(this, packet, needACK, false);

        if (needACK && identifier != null) {
            this.needACK.put(identifier, Boolean.FALSE);
            timing.stopTiming();
            return identifier;
        }
    }
    return 0;
}
 
Example #16
Source File: PermissibleBase.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void recalculatePermissions() {
    Timings.permissibleCalculationTimer.startTiming();

    this.clearPermissions();
    Map<String, Permission> defaults = Server.getInstance().getPluginManager().getDefaultPermissions(this.isOp());
    Server.getInstance().getPluginManager().subscribeToDefaultPerms(this.isOp(), this.parent != null ? this.parent : this);

    for (Permission perm : defaults.values()) {
        String name = perm.getName();
        this.permissions.put(name, new PermissionAttachmentInfo(this.parent != null ? this.parent : this, name, null, true));
        Server.getInstance().getPluginManager().subscribeToPermission(name, this.parent != null ? this.parent : this);
        this.calculateChildPermissions(perm.getChildren(), false, null);
    }

    for (PermissionAttachment attachment : this.attachments) {
        this.calculateChildPermissions(attachment.getPermissions(), false, attachment);
    }
    Timings.permissibleCalculationTimer.stopTiming();
}
 
Example #17
Source File: PluginManager.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) throws PluginException {
    if (!plugin.isEnabled()) {
        throw new PluginException("Plugin attempted to register " + event + " while not enabled");
    }

    try {
        Timing timing = Timings.getPluginEventTiming(event, listener, executor, plugin);
        this.getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled, timing));
    } catch (IllegalAccessException e) {
        Server.getInstance().getLogger().logException(e);
    }
}
 
Example #18
Source File: Server.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void reload() {
    log.info("Reloading...");

    log.info("Saving levels...");

    for (Level level : this.levelArray) {
        level.save();
    }

    this.pluginManager.disablePlugins();
    this.pluginManager.clearPlugins();
    this.commandMap.clearCommands();

    log.info("Reloading properties...");
    this.properties.reload();
    this.maxPlayers = this.getPropertyInt("max-players", 20);

    if (this.getPropertyBoolean("hardcore", false) && this.getDifficulty() < 3) {
        this.setPropertyInt("difficulty", difficulty = 3);
    }

    this.banByIP.load();
    this.banByName.load();
    this.reloadWhitelist();
    this.operators.reload();

    for (BanEntry entry : this.getIPBans().getEntires().values()) {
        this.getNetwork().blockAddress(entry.getName(), -1);
    }

    this.pluginManager.registerInterface(JavaPluginLoader.class);
    this.pluginManager.loadPlugins(this.pluginPath);
    this.enablePlugins(PluginLoadOrder.STARTUP);
    this.enablePlugins(PluginLoadOrder.POSTWORLD);
    Timings.reset();
}
 
Example #19
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void generateChunkCallback(int x, int z, BaseFullChunk chunk, boolean isPopulated) {
    Timings.generationCallbackTimer.startTiming();
    long index = Level.chunkHash(x, z);
    if (this.chunkPopulationQueue.containsKey(index)) {
        FullChunk oldChunk = this.getChunk(x, z, false);
        for (int xx = -1; xx <= 1; ++xx) {
            for (int zz = -1; zz <= 1; ++zz) {
                this.chunkPopulationLock.remove(Level.chunkHash(x + xx, z + zz));
            }
        }
        this.chunkPopulationQueue.remove(index);
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
        chunk = this.getChunk(x, z, false);
        if (chunk != null && (oldChunk == null || !isPopulated) && chunk.isPopulated()
                && chunk.getProvider() != null) {
            this.server.getPluginManager().callEvent(new ChunkPopulateEvent(chunk));

            for (ChunkLoader loader : this.getChunkLoaders(x, z)) {
                loader.onChunkPopulated(chunk);
            }
        }
    } else if (this.chunkGenerationQueue.containsKey(index) || this.chunkPopulationLock.containsKey(index)) {
        this.chunkGenerationQueue.remove(index);
        this.chunkPopulationLock.remove(index);
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
    } else {
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
    }
    Timings.generationCallbackTimer.stopTiming();
}
 
Example #20
Source File: TaskHandler.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public TaskHandler(Plugin plugin, Runnable task, int taskId, boolean asynchronous) {
    this.asynchronous = asynchronous;
    this.plugin = plugin;
    this.task = task;
    this.taskId = taskId;
    this.timing = Timings.getTaskTiming(this, period);
}
 
Example #21
Source File: AsyncTask.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static void collectTask() {
    Timings.schedulerAsyncTimer.startTiming();
    while (!FINISHED_LIST.isEmpty()) {
        AsyncTask task = FINISHED_LIST.poll();
        try {
            task.onCompletion(Server.getInstance());
        } catch (Exception e) {
            Server.getInstance().getLogger().critical("Exception while async task "
                    + task.getTaskId()
                    + " invoking onCompletion", e);
        }
    }
    Timings.schedulerAsyncTimer.stopTiming();
}
 
Example #22
Source File: Command.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public Command(String name, String description, String usageMessage, String[] aliases) {
    this.commandData = new CommandData();
    this.name = name.toLowerCase(); // Uppercase letters crash the client?!?
    this.nextLabel = name;
    this.label = name;
    this.description = description;
    this.usageMessage = usageMessage == null ? "/" + name : usageMessage;
    this.aliases = aliases;
    this.activeAliases = aliases;
    this.timing = Timings.getCommandTiming(this);
    this.commandParameters.put("default", new CommandParameter[]{new CommandParameter("args", CommandParamType.RAWTEXT, true)});
}
 
Example #23
Source File: Command.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setLabel(String name) {
    this.nextLabel = name;
    if (!this.isRegistered()) {
        this.label = name;
        this.timing = Timings.getCommandTiming(this);
        return true;
    }
    return false;
}
 
Example #24
Source File: Server.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void reload() {
    this.logger.info("Reloading...");

    this.logger.info("Saving levels...");

    for (Level level : this.levelArray) {
        level.save();
    }

    this.pluginManager.disablePlugins();
    this.pluginManager.clearPlugins();
    this.commandMap.clearCommands();

    this.logger.info("Reloading properties...");
    this.properties.reload();
    this.maxPlayers = this.getPropertyInt("max-players", 20);

    if (this.getPropertyBoolean("hardcore", false) && this.getDifficulty() < 3) {
        this.setPropertyInt("difficulty", difficulty = 3);
    }

    this.banByIP.load();
    this.banByName.load();
    this.reloadWhitelist();
    this.operators.reload();

    for (BanEntry entry : this.getIPBans().getEntires().values()) {
        this.getNetwork().blockAddress(entry.getName(), -1);
    }

    this.pluginManager.registerInterface(JavaPluginLoader.class);
    this.pluginManager.loadPlugins(this.pluginPath);
    this.enablePlugins(PluginLoadOrder.STARTUP);
    this.enablePlugins(PluginLoadOrder.POSTWORLD);
    Timings.reset();
}
 
Example #25
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void generateChunk(int x, int z, boolean force) {
    if (this.chunkGenerationQueue.size() >= this.chunkGenerationQueueSize && !force) {
        return;
    }

    long index = Level.chunkHash(x, z);
    if (!this.chunkGenerationQueue.containsKey(index)) {
        Timings.generationTimer.startTiming();
        this.chunkGenerationQueue.put(index, Boolean.TRUE);
        GenerationTask task = new GenerationTask(this, this.getChunk(x, z, true));
        this.server.getScheduler().scheduleAsyncTask(task);
        Timings.generationTimer.stopTiming();
    }
}
 
Example #26
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean populateChunk(int x, int z, boolean force) {
    long index = Level.chunkHash(x, z);
    if (this.chunkPopulationQueue.containsKey(index) || this.chunkPopulationQueue.size() >= this.chunkPopulationQueueSize && !force) {
        return false;
    }

    BaseFullChunk chunk = this.getChunk(x, z, true);
    boolean populate;
    if (!chunk.isPopulated()) {
        Timings.populationTimer.startTiming();
        populate = true;
        for (int xx = -1; xx <= 1; ++xx) {
            for (int zz = -1; zz <= 1; ++zz) {
                if (this.chunkPopulationLock.containsKey(Level.chunkHash(x + xx, z + zz))) {

                    populate = false;
                    break;
                }
            }
        }

        if (populate) {
            if (!this.chunkPopulationQueue.containsKey(index)) {
                this.chunkPopulationQueue.put(index, Boolean.TRUE);
                for (int xx = -1; xx <= 1; ++xx) {
                    for (int zz = -1; zz <= 1; ++zz) {
                        this.chunkPopulationLock.put(Level.chunkHash(x + xx, z + zz), Boolean.TRUE);
                    }
                }

                PopulationTask task = new PopulationTask(this, chunk);
                this.server.getScheduler().scheduleAsyncTask(task);
            }
        }
        Timings.populationTimer.stopTiming();
        return false;
    }

    return true;
}
 
Example #27
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean fastMove(double dx, double dy, double dz) {
    if (dx == 0 && dy == 0 && dz == 0) {
        return true;
    }

    Timings.entityMoveTimer.startTiming();

    AxisAlignedBB newBB = this.boundingBox.getOffsetBoundingBox(dx, dy, dz);

    if (server.getAllowFlight() || !this.level.hasCollision(this, newBB, false)) {
        this.boundingBox = newBB;
    }

    this.x = (this.boundingBox.getMinX() + this.boundingBox.getMaxX()) / 2;
    this.y = this.boundingBox.getMinY() - this.ySize;
    this.z = (this.boundingBox.getMinZ() + this.boundingBox.getMaxZ()) / 2;

    this.checkChunks();

    if (!this.onGround || dy != 0) {
        AxisAlignedBB bb = this.boundingBox.clone();
        bb.setMinY(bb.getMinY() - 0.75);

        this.onGround = this.level.getCollisionBlocks(bb).length > 0;
    }
    this.isCollided = this.onGround;
    this.updateFallState(this.onGround);
    Timings.entityMoveTimer.stopTiming();
    return true;
}
 
Example #28
Source File: PluginManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private void calculatePermissionDefault(Permission permission) {
    Timings.permissionDefaultTimer.startTiming();
    if (permission.getDefault().equals(Permission.DEFAULT_OP) || permission.getDefault().equals(Permission.DEFAULT_TRUE)) {
        this.defaultPermsOp.put(permission.getName(), permission);
        this.dirtyPermissibles(true);
    }

    if (permission.getDefault().equals(Permission.DEFAULT_NOT_OP) || permission.getDefault().equals(Permission.DEFAULT_TRUE)) {
        this.defaultPerms.put(permission.getName(), permission);
        this.dirtyPermissibles(false);
    }
    Timings.permissionDefaultTimer.startTiming();
}
 
Example #29
Source File: PluginManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) throws PluginException {
    if (!plugin.isEnabled()) {
        throw new PluginException("Plugin attempted to register " + event + " while not enabled");
    }

    try {
        Timing timing = Timings.getPluginEventTiming(event, listener, executor, plugin);
        this.getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled, timing));
    } catch (IllegalAccessException e) {
        Server.getInstance().getLogger().logException(e);
    }
}
 
Example #30
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void generateChunkCallback(int x, int z, BaseFullChunk chunk) {
    Timings.generationCallbackTimer.startTiming();
    long index = Level.chunkHash(x, z);
    if (this.chunkPopulationQueue.containsKey(index)) {
        FullChunk oldChunk = this.getChunk(x, z, false);
        for (int xx = -1; xx <= 1; ++xx) {
            for (int zz = -1; zz <= 1; ++zz) {
                this.chunkPopulationLock.remove(Level.chunkHash(x + xx, z + zz));
            }
        }
        this.chunkPopulationQueue.remove(index);
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
        chunk = this.getChunk(x, z, false);
        if (chunk != null && (oldChunk == null || !oldChunk.isPopulated()) && chunk.isPopulated()
                && chunk.getProvider() != null) {
            this.server.getPluginManager().callEvent(new ChunkPopulateEvent(chunk));

            for (ChunkLoader loader : this.getChunkLoaders(x, z)) {
                loader.onChunkPopulated(chunk);
            }
        }
    } else if (this.chunkGenerationQueue.containsKey(index) || this.chunkPopulationLock.containsKey(index)) {
        this.chunkGenerationQueue.remove(index);
        this.chunkPopulationLock.remove(index);
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
    } else {
        chunk.setProvider(this.provider);
        this.setChunk(x, z, chunk, false);
    }
    Timings.generationCallbackTimer.stopTiming();
}