cn.nukkit.scheduler.AsyncTask Java Examples

The following examples show how to use cn.nukkit.scheduler.AsyncTask. 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: Level.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
private void processChunkRequest() {
    if (!this.chunkSendQueue.isEmpty()) {
        this.timings.syncChunkSendTimer.startTiming();
        for (Long index : new ArrayList<>(this.chunkSendQueue.keySet())) {
            if (this.chunkSendTasks.containsKey(index)) {
                continue;
            }
            int x = getHashX(index);
            int z = getHashZ(index);
            this.chunkSendTasks.put(index, true);
            if (this.chunkCache.containsKey(index)) {
                this.sendChunkFromCache(x, z);
                continue;
            }
            this.timings.syncChunkSendPrepareTimer.startTiming();
            AsyncTask task = this.provider.requestChunkTask(x, z);
            if (task != null) {
                this.server.getScheduler().scheduleAsyncTask(task);
            }
            this.timings.syncChunkSendPrepareTimer.stopTiming();
        }
        this.timings.syncChunkSendTimer.stopTiming();
    }
}
 
Example #2
Source File: Level.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private void processChunkRequest() {
    this.timings.syncChunkSendTimer.startTiming();
    for (long index : this.chunkSendQueue.keySet()) {
        if (this.chunkSendTasks.contains(index)) {
            continue;
        }
        int x = getHashX(index);
        int z = getHashZ(index);
        this.chunkSendTasks.add(index);
        BaseFullChunk chunk = getChunk(x, z);
        if (chunk != null) {
            BatchPacket packet = chunk.getChunkPacket();
            if (packet != null) {
                this.sendChunk(x, z, index, packet);
                continue;
            }
        }
        this.timings.syncChunkSendPrepareTimer.startTiming();
        AsyncTask task = this.provider.requestChunkTask(x, z);
        if (task != null) {
            this.server.getScheduler().scheduleAsyncTask(task);
        }
        this.timings.syncChunkSendPrepareTimer.stopTiming();
    }
    this.timings.syncChunkSendTimer.stopTiming();
}
 
Example #3
Source File: Level.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private void processChunkRequest() {
    this.timings.syncChunkSendTimer.startTiming();
    for (Long index : ImmutableList.copyOf(this.chunkSendQueue.keySet())) {
        if (this.chunkSendTasks.containsKey(index)) {
            continue;
        }
        int x = getHashX(index);
        int z = getHashZ(index);
        this.chunkSendTasks.put(index, Boolean.TRUE);
        BaseFullChunk chunk = getChunk(x, z);
        if (chunk != null) {
            BatchPacket packet = chunk.getChunkPacket();
            if (packet != null) {
                this.sendChunk(x, z, index, packet);
                continue;
            }
        }
        this.timings.syncChunkSendPrepareTimer.startTiming();
        AsyncTask task = this.provider.requestChunkTask(x, z);
        if (task != null) {
            this.server.getScheduler().scheduleAsyncTask(task);
        }
        this.timings.syncChunkSendPrepareTimer.stopTiming();
    }
    this.timings.syncChunkSendTimer.stopTiming();
}
 
Example #4
Source File: LevelDB.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AsyncTask requestChunkTask(int x, int z) {
    Chunk chunk = this.getChunk(x, z, false);
    if (chunk == null) {
        throw new ChunkException("Invalid Chunk sent");
    }

    long timestamp = chunk.getChanges();

    BinaryStream stream = new BinaryStream();
    stream.putByte((byte) 0); // subchunk version

    stream.put(chunk.getBlockIdArray());
    stream.put(chunk.getBlockDataArray());
    stream.put(chunk.getBlockSkyLightArray());
    stream.put(chunk.getBlockLightArray());
    stream.put(chunk.getHeightMapArray());
    stream.put(chunk.getBiomeIdArray());

    Map<Integer, Integer> extra = chunk.getBlockExtraDataArray();
    stream.putLInt(extra.size());
    if (!extra.isEmpty()) {
        for (Integer key : extra.values()) {
            stream.putLInt(key);
            stream.putLShort(extra.get(key));
        }
    }

    if (!chunk.getBlockEntities().isEmpty()) {
        List<CompoundTag> tagList = new ArrayList<>();

        for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
            if (blockEntity instanceof BlockEntitySpawnable) {
                tagList.add(((BlockEntitySpawnable) blockEntity).getSpawnCompound());
            }
        }

        try {
            stream.put(NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    this.getLevel().chunkRequestCallback(timestamp, x, z, 16, stream.getBuffer());

    return null;
}
 
Example #5
Source File: McRegion.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AsyncTask requestChunkTask(int x, int z) throws ChunkException {
    BaseFullChunk chunk = this.getChunk(x, z, false);
    if (chunk == null) {
        throw new ChunkException("Invalid Chunk Sent");
    }

    long timestamp = chunk.getChanges();

    BinaryStream stream = new BinaryStream();
    stream.putByte((byte) 0); // subchunk version

    stream.put(chunk.getBlockIdArray());
    stream.put(chunk.getBlockDataArray());
    stream.put(chunk.getBlockSkyLightArray());
    stream.put(chunk.getBlockLightArray());
    stream.put(chunk.getHeightMapArray());
    stream.put(chunk.getBiomeIdArray());

    Map<Integer, Integer> extra = chunk.getBlockExtraDataArray();
    stream.putLInt(extra.size());
    if (!extra.isEmpty()) {
        for (Integer key : extra.values()) {
            stream.putLInt(key);
            stream.putLShort(extra.get(key));
        }
    }

    if (!chunk.getBlockEntities().isEmpty()) {
        List<CompoundTag> tagList = new ArrayList<>();

        for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
            if (blockEntity instanceof BlockEntitySpawnable) {
                tagList.add(((BlockEntitySpawnable) blockEntity).getSpawnCompound());
            }
        }

        try {
            stream.put(NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    return null;
}
 
Example #6
Source File: DebugPasteCommand.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    Server server = Server.getInstance();
    server.getScheduler().scheduleAsyncTask(new AsyncTask() {
        @Override
        public void onRun() {
            try {
                new StatusCommand("status").execute(server.getConsoleSender(), "status", new String[]{});
                String dataPath = server.getDataPath();
                String nukkitYML = HastebinUtility.upload(new File(dataPath, "nukkit.yml"));
                String serverProperties = HastebinUtility.upload(new File(dataPath, "server.properties"));
                String latestLog = HastebinUtility.upload(new File(dataPath, "/logs/server.log"));
                String threadDump = HastebinUtility.upload(Utils.getAllThreadDumps());

                StringBuilder b = new StringBuilder();
                b.append("# Files\n");
                b.append("links.nukkit_yml: ").append(nukkitYML).append('\n');
                b.append("links.server_properties: ").append(serverProperties).append('\n');
                b.append("links.server_log: ").append(latestLog).append('\n');
                b.append("links.thread_dump: ").append(threadDump).append('\n');
                b.append("\n# Server Information\n");

                b.append("version.api: ").append(server.getApiVersion()).append('\n');
                b.append("version.nukkit: ").append(server.getNukkitVersion()).append('\n');
                b.append("version.minecraft: ").append(server.getVersion()).append('\n');
                b.append("version.protocol: ").append(ProtocolInfo.CURRENT_PROTOCOL).append('\n');
                b.append("plugins:");
                for (Plugin plugin : server.getPluginManager().getPlugins().values()) {
                    boolean enabled = plugin.isEnabled();
                    String name = plugin.getName();
                    PluginDescription desc = plugin.getDescription();
                    String version = desc.getVersion();
                    b.append("\n  ")
                            .append(name)
                            .append(":\n    ")
                            .append("version: '")
                            .append(version)
                            .append('\'')
                            .append("\n    enabled: ")
                            .append(enabled);
                }
                b.append("\n\n# Java Details\n");
                Runtime runtime = Runtime.getRuntime();
                b.append("memory.free: ").append(runtime.freeMemory()).append('\n');
                b.append("memory.max: ").append(runtime.maxMemory()).append('\n');
                b.append("cpu.runtime: ").append(ManagementFactory.getRuntimeMXBean().getUptime()).append('\n');
                b.append("cpu.processors: ").append(runtime.availableProcessors()).append('\n');
                b.append("java.specification.version: '").append(System.getProperty("java.specification.version")).append("'\n");
                b.append("java.vendor: '").append(System.getProperty("java.vendor")).append("'\n");
                b.append("java.version: '").append(System.getProperty("java.version")).append("'\n");
                b.append("os.arch: '").append(System.getProperty("os.arch")).append("'\n");
                b.append("os.name: '").append(System.getProperty("os.name")).append("'\n");
                b.append("os.version: '").append(System.getProperty("os.version")).append("'\n\n");
                b.append("\n# Create a ticket: https://github.com/NukkitX/Nukkit/issues/new");
                String link = HastebinUtility.upload(b.toString());
                sender.sendMessage(link);
            } catch (IOException e) {
                MainLogger.getLogger().logException(e);
            }
        }
    });
    return true;
}
 
Example #7
Source File: LevelDB.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AsyncTask requestChunkTask(int x, int z) {
    Chunk chunk = this.getChunk(x, z, false);
    if (chunk == null) {
        throw new ChunkException("Invalid Chunk sent");
    }

    long timestamp = chunk.getChanges();

    byte[] tiles = new byte[0];

    if (!chunk.getBlockEntities().isEmpty()) {
        List<CompoundTag> tagList = new ArrayList<>();

        for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
            if (blockEntity instanceof BlockEntitySpawnable) {
                tagList.add(((BlockEntitySpawnable) blockEntity).getSpawnCompound());
            }
        }

        try {
            tiles = NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    Map<Integer, Integer> extra = chunk.getBlockExtraDataArray();
    BinaryStream extraData;
    if (!extra.isEmpty()) {
        extraData = new BinaryStream();
        extraData.putLInt(extra.size());
        for (Integer key : extra.values()) {
            extraData.putLInt(key);
            extraData.putLShort(extra.get(key));
        }
    } else {
        extraData = null;
    }

    BinaryStream stream = new BinaryStream();
    stream.put(chunk.getBlockIdArray());
    stream.put(chunk.getBlockDataArray());
    stream.put(chunk.getBlockSkyLightArray());
    stream.put(chunk.getBlockLightArray());
    stream.put(chunk.getHeightMapArray());
    for (int color : chunk.getBiomeColorArray()) {
        stream.put(Binary.writeInt(color));
    }
    if (extraData != null) {
        stream.put(extraData.getBuffer());
    } else {
        stream.putLInt(0);
    }
    stream.put(tiles);

    this.getLevel().chunkRequestCallback(timestamp, x, z, stream.getBuffer());

    return null;
}
 
Example #8
Source File: DebugPasteCommand.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    Server server = Server.getInstance();
    server.getScheduler().scheduleAsyncTask(new AsyncTask() {
        @Override
        public void onRun() {
            try {
                new StatusCommand("status").execute(server.getConsoleSender(), "status", new String[]{});
                String dataPath = server.getDataPath();
                String nukkitYML = HastebinUtility.upload(new File(dataPath, "nukkit.yml"));
                String serverProperties = HastebinUtility.upload(new File(dataPath, "server.properties"));
                String latestLog = HastebinUtility.upload(new File(dataPath, "server.log"));
                String threadDump = HastebinUtility.upload(Utils.getAllThreadDumps());

                StringBuilder b = new StringBuilder();
                b.append("# Files\n");
                b.append("links.nukkit_yml: ").append(nukkitYML).append('\n');
                b.append("links.server_properties: ").append(serverProperties).append('\n');
                b.append("links.server_log: ").append(latestLog).append('\n');
                b.append("links.thread_dump: ").append(threadDump).append('\n');
                b.append("\n# Server Information\n");

                b.append("version.api: ").append(server.getApiVersion()).append('\n');
                b.append("version.nukkit: ").append(server.getNukkitVersion()).append('\n');
                b.append("version.minecraft: ").append(server.getVersion()).append('\n');
                b.append("version.protocol: ").append(ProtocolInfo.CURRENT_PROTOCOL).append('\n');
                b.append("plugins:");
                for (Plugin plugin : server.getPluginManager().getPlugins().values()) {
                    boolean enabled = plugin.isEnabled();
                    String name = plugin.getName();
                    PluginDescription desc = plugin.getDescription();
                    String version = desc.getVersion();
                    b.append("\n  ")
                            .append(name)
                            .append(":\n    ")
                            .append("version: '")
                            .append(version)
                            .append('\'')
                            .append("\n    enabled: ")
                            .append(enabled);
                }
                b.append("\n\n# Java Details\n");
                Runtime runtime = Runtime.getRuntime();
                b.append("memory.free: ").append(runtime.freeMemory()).append('\n');
                b.append("memory.max: ").append(runtime.maxMemory()).append('\n');
                b.append("cpu.runtime: ").append(ManagementFactory.getRuntimeMXBean().getUptime()).append('\n');
                b.append("cpu.processors: ").append(runtime.availableProcessors()).append('\n');
                b.append("java.specification.version: '").append(System.getProperty("java.specification.version")).append("'\n");
                b.append("java.vendor: '").append(System.getProperty("java.vendor")).append("'\n");
                b.append("java.version: '").append(System.getProperty("java.version")).append("'\n");
                b.append("os.arch: '").append(System.getProperty("os.arch")).append("'\n");
                b.append("os.name: '").append(System.getProperty("os.name")).append("'\n");
                b.append("os.version: '").append(System.getProperty("os.version")).append("'\n\n");
                b.append("\n# Create a ticket: https://github.com/NukkitX/Nukkit/issues/new");
                String link = HastebinUtility.upload(b.toString());
                sender.sendMessage(link);
            } catch (IOException e) {
                MainLogger.getLogger().logException(e);
            }
        }
    });
    return true;
}
 
Example #9
Source File: LevelProvider.java    From Jupiter with GNU General Public License v3.0 votes vote down vote up
AsyncTask requestChunkTask(int x, int z); 
Example #10
Source File: LevelProvider.java    From Nukkit with GNU General Public License v3.0 votes vote down vote up
AsyncTask requestChunkTask(int X, int Z); 
Example #11
Source File: LevelProvider.java    From Nukkit with GNU General Public License v3.0 votes vote down vote up
AsyncTask requestChunkTask(int X, int Z);