本文整理汇总了Java中cn.nukkit.scheduler.AsyncTask类的典型用法代码示例。如果您正苦于以下问题:Java AsyncTask类的具体用法?Java AsyncTask怎么用?Java AsyncTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AsyncTask类属于cn.nukkit.scheduler包,在下文中一共展示了AsyncTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processChunkRequest
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
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();
}
}
示例2: onEnable
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
@Override
public void onEnable() {
i18n = new I18n(getLanguageFolder(), null);
i18n.onEnable();
reloadConfigs(null);
subCmds.add(new ApiKey(this));
subCmds.add(new Check(this));
subCmds.add(new UpdateSigns(this));
subCmds.add(new Reload(this));
subCmds.add(new Version(this));
getServer().getScheduler().scheduleAsyncTask(this, new AsyncTask() {
@Override
public void onRun() {
new UpdateChecker(getDescription().getVersion(), 44031, pluginURL -> {
getLogger().warning(I18n.tl("new_version"));
getLogger().warning(pluginURL);
});
}
});
}
示例3: setKey
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
public void setKey(String apiKey, boolean save, Response<Boolean> response) {
if (save) {
mainConfig.setApiKey(apiKey);
}
getServer().getScheduler().scheduleAsyncTask(this, new AsyncTask() {
@Override
public void onRun() {
marketApi = new MCMarketApi(apiKey, getUserAgent(), mainConfig.isDebug());
authenticated = marketApi.authAPI();
if (!authenticated) {
getLogger().warning(I18n.tl("invalid_key", "/MM apiKey <key>"));
}
if (response != null) {
response.done(authenticated);
}
}
});
}
示例4: processChunkRequest
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
private void processChunkRequest() {
if (!this.chunkSendQueue.isEmpty()) {
this.timings.syncChunkSendTimer.startTiming();
for (String index : new ArrayList<>(this.chunkSendQueue.keySet())) {
if (this.chunkSendTasks.containsKey(index)) {
continue;
}
Chunk.Entry chunkEntry = Level.getChunkXZ(index);
int x = chunkEntry.chunkX;
int z = chunkEntry.chunkZ;
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();
}
}
示例5: DeathTag
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
public DeathTag(Player player) {
this.tag = new Tag(player.getPosition(), "0분 전에 " + player.getName() + "이(가) 사망", new Long(60 * 10));
this.player = player;
DeathTag.tags.add(this);
Server.getInstance().getScheduler().scheduleRepeatingTask(new AsyncTask() {
@Override
public void onRun() {
for(DeathTag tag : DeathTag.tags) tag.onUpdate();
}
}, 20 * 60, true);
}
示例6: run
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
@Override
public void run(CommandSender sender, String[] args) {
if (MCMarket.isAuthenticated()) {
sender.sendMessage(Colors.color(I18n.tl("prefix") + " " + I18n.tl("cmd_check_purchases")));
plugin.getServer().getScheduler().scheduleAsyncTask(plugin, new AsyncTask() {
@Override
public void onRun() {
plugin.getPurchasesTask().updatePurchases();
}
});
} else {
sender.sendMessage(Colors.color(I18n.tl("prefix") + " " + I18n.tl("cmd_auth_key")));
}
}
示例7: runCommand
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
private void runCommand(Command command) {
Player player = Server.getInstance().getPlayerExact(command.getPlayer().getName());
if (command.isRequiredOnline() && (player == null || !player.isOnline())) {
return;
}
if (command.getRequiredSlots() > 0 && (player != null && player.isOnline())) {
if (getEmptySlots(player.getInventory()) < command.getRequiredSlots()) {
return;
}
}
if (MCMarket.getApi().setExecuted(command.getId())) {
plugin.getServer().getScheduler().scheduleDelayedTask(plugin, new AsyncTask() {
@Override
public void onRun() {
plugin.getServer().getScheduler().scheduleTask(plugin, () -> plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command.getCommand()));
if (command.isRepeat()) {
long period = command.getRepeatPeriod() > 0 ? 20 * 60 * 60 * command.getRepeatPeriod() : 1;
new NukkitRunnable() {
int executed = 0;
@Override
public void run() {
plugin.getServer().getScheduler().scheduleTask(plugin, () -> plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command.getCommand()));
executed++;
if (executed >= command.getRepeatCycles()) {
cancel();
}
}
}.runTaskTimerAsynchronously(plugin, (int) period, (int) period);
}
}
}, command.getDelay() > 0 ? (int) (20 * command.getDelay()) : 1, true);
}
}
示例8: executeAsync
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
@Override
public void executeAsync(Runnable runnable) {
plugin.getServer().getScheduler().scheduleAsyncTask(plugin, new AsyncTask() {
@Override
public void onRun() {
runnable.run();
}
});
}
示例9: executeAsyncLater
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
@Override
public void executeAsyncLater(Runnable runnable, long time, TimeUnit unit) {
plugin.getServer().getScheduler().scheduleDelayedTask(plugin, () -> {
plugin.getServer().getScheduler().scheduleAsyncTask(plugin, new AsyncTask() {
@Override
public void onRun() {
runnable.run();
}
});
}, (int) (unit.toMillis(time) / 50));
}
示例10: requestChunkTask
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
@Override
public AsyncTask requestChunkTask(int x, int z) {
FullChunk chunk = this.getChunk(x, z, false);
if (chunk == null) {
throw new ChunkException("Invalid Chunk sent");
}
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());
for (int height : chunk.getHeightMapArray()) {
stream.putByte((byte) height);
}
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(x, z, stream.getBuffer());
return null;
}
示例11: onCommand
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
@Override
public boolean onCommand(final CommandSender sender, Command command, String label, final String[] args) {
if (!this.testPermission(sender)) {
//sender.sendMessage(this.getPlugin().translateMessage("has-no-permission"));
return true;
}
Server.getInstance().getScheduler().scheduleAsyncTask(getPlugin(), new AsyncTask() {
@SuppressWarnings("Duplicates")
@Override
public void onRun() {
LinkedHashMap<String, String> linkedHashMap = Utils.sortMap(getPlugin().getDataMap(), "money1");
int pages = linkedHashMap.size() / 6;
int page = 1;
if (args.length > 0) {
try {
if (Integer.parseInt(args[0]) < 0) {
page = 1;
} else if (Integer.parseInt(args[0]) - 1 > pages) {
page = pages - 1;
} else {
page = Integer.parseInt(args[0]);
}
} catch (NumberFormatException ignored) {
}
}
int i;
StringBuilder msg = new StringBuilder(getPlugin().translateMessage("list",
"type", getPlugin().getCurrency1(),
"page", page,
"all", (pages + 1)
) + "\n");
for (i = 6 * (page - 1); i < 6 * page; i++) {
String value = Utils.getKeyByNumber(i, linkedHashMap);
String key = Utils.getValueByNumber(i, linkedHashMap);
if (key != null && value != null && !key.equals("") && !value.equals("")) {
msg.append(TextFormat.YELLOW).append("No.").append(i + 1).append(" ").append(TextFormat.GOLD)
.append(value).append(TextFormat.AQUA).append(" ").append(key).append(" \n");
}
}
sender.sendMessage(msg.toString());
}
});
sender.sendMessage(this.getPlugin().translateMessage("list-listing"));
return true;
}
示例12: onCommand
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
@Override
public boolean onCommand(final CommandSender sender, Command command, String label, final String[] args) {
if (!this.testPermission(sender)) {
//sender.sendMessage(this.getPlugin().translateMessage("has-no-permission"));
return true;
}
Server.getInstance().getScheduler().scheduleAsyncTask(getPlugin(), new AsyncTask() {
@SuppressWarnings("Duplicates") // TODO: 2017/5/3 analyze
@Override
public void onRun() {
LinkedHashMap<String, String> linkedHashMap = Utils.sortMap(getPlugin().getDataMap(), "money2");
int pages = linkedHashMap.size() / 6;
int page = 1;
if (args.length > 0) {
try {
if (Integer.parseInt(args[0]) < 0) {
page = 1;
} else if (Integer.parseInt(args[0]) - 1 > pages) {
page = pages - 1;
} else {
page = Integer.parseInt(args[0]);
}
} catch (NumberFormatException ignored) {
}
}
int i;
StringBuilder msg = new StringBuilder(
getPlugin().translateMessage("list",
"type", getPlugin().getCurrency2(),
"page", page,
"all", (pages + 1)
) + "\n");
for (i = 6 * (page - 1); i < 6 * page; i++) {
String value = Utils.getKeyByNumber(i, linkedHashMap);
String key = Utils.getValueByNumber(i, linkedHashMap);
if (key != null && value != null && !key.equals("") && !value.equals("")) {
msg.append(TextFormat.YELLOW).append("No.").append(i + 1).append(" ").append(TextFormat.GOLD)
.append(value).append(TextFormat.AQUA).append(" ").append(key).append(" \n");
}
}
sender.sendMessage(msg.toString());
}
});
sender.sendMessage(this.getPlugin().translateMessage("list-listing"));
return true;
}
示例13: requestChunkTask
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
@Override
public AsyncTask requestChunkTask(int x, int z) {
FullChunk chunk = this.getChunk(x, z, false);
if (chunk == null) {
throw new ChunkException("Invalid Chunk sent");
}
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);
}
}
BinaryStream extraData = new BinaryStream();
extraData.putLInt(chunk.getBlockExtraDataArray().size());
for (Integer key : chunk.getBlockExtraDataArray().values()) {
extraData.putLInt(key);
extraData.putLShort(chunk.getBlockExtraDataArray().get(key));
}
BinaryStream stream = new BinaryStream();
stream.put(chunk.getBlockIdArray());
stream.put(chunk.getBlockDataArray());
stream.put(chunk.getBlockSkyLightArray());
stream.put(chunk.getBlockLightArray());
for (int height : chunk.getHeightMapArray()) {
stream.putByte((byte) (height & 0xff));
}
for (int color : chunk.getBiomeColorArray()) {
stream.put(Binary.writeInt(color));
}
stream.put(extraData.getBuffer());
stream.put(tiles);
this.getLevel().chunkRequestCallback(x, z, stream.getBuffer());
return null;
}
示例14: requestChunkTask
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
@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");
}
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);
}
}
BinaryStream extraData = new BinaryStream();
extraData.putLInt(chunk.getBlockExtraDataArray().size());
for (Integer key : chunk.getBlockExtraDataArray().keySet()) {
extraData.putLInt(key);
extraData.putLShort(chunk.getBlockExtraDataArray().get(key));
}
BinaryStream stream = new BinaryStream();
stream.put(chunk.getBlockIdArray());
stream.put(chunk.getBlockDataArray());
stream.put(chunk.getBlockSkyLightArray());
stream.put(chunk.getBlockLightArray());
for (int height : chunk.getHeightMapArray()) {
stream.putByte((byte) (height & 0xff));
}
for (int color : chunk.getBiomeColorArray()) {
stream.put(Binary.writeInt(color));
}
stream.put(extraData.getBuffer());
stream.put(tiles);
this.getLevel().chunkRequestCallback(x, z, stream.getBuffer());
return null;
}
示例15: requestChunkTask
import cn.nukkit.scheduler.AsyncTask; //导入依赖的package包/类
@Override
public AsyncTask requestChunkTask(int x, int z) throws ChunkException {
FullChunk chunk = this.getChunk(x, z, false);
if (chunk == null) {
throw new ChunkException("Invalid Chunk Set");
}
byte[] blockEntities = 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 {
blockEntities = NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
BinaryStream extraData = new BinaryStream();
extraData.putLInt(chunk.getBlockExtraDataArray().size());
for (Integer key : chunk.getBlockExtraDataArray().values()) {
extraData.putLInt(key);
extraData.putLShort(chunk.getBlockExtraDataArray().get(key));
}
BinaryStream stream = new BinaryStream();
stream.put(chunk.getBlockIdArray());
stream.put(chunk.getBlockDataArray());
stream.put(chunk.getBlockSkyLightArray());
stream.put(chunk.getBlockLightArray());
for (int height : chunk.getHeightMapArray()) {
stream.putByte((byte) (height & 0xff));
}
for (int color : chunk.getBiomeColorArray()) {
stream.put(Binary.writeInt(color));
}
stream.put(extraData.getBuffer());
stream.put(blockEntities);
this.getLevel().chunkRequestCallback(x, z, stream.getBuffer(), FullChunkDataPacket.ORDER_LAYERED);
return null;
}