當前位置: 首頁>>代碼示例>>Java>>正文


Java Task類代碼示例

本文整理匯總了Java中org.spongepowered.api.scheduler.Task的典型用法代碼示例。如果您正苦於以下問題:Java Task類的具體用法?Java Task怎麽用?Java Task使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Task類屬於org.spongepowered.api.scheduler包,在下文中一共展示了Task類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startSubmitting

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
private void startSubmitting() {
    // We use a timer cause want to be independent from the server tps
    final Timer timer = new Timer(true);
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            // Plugin was disabled, e.g. because of a reload (is this even possible in Sponge?)
            if (!Sponge.getPluginManager().isLoaded(plugin.getId())) {
                timer.cancel();
                return;
            }
            // The data collection (e.g. for custom graphs) is done sync
            // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
            Scheduler scheduler = Sponge.getScheduler();
            Task.Builder taskBuilder = scheduler.createTaskBuilder();
            taskBuilder.execute(() -> submitData()).submit(plugin);
        }
    }, 1000*60*5, 1000*60*30);
    // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
    // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
    // WARNING: Just don't do it!
}
 
開發者ID:codeHusky,項目名稱:HuskyUI-Plugin,代碼行數:23,代碼來源:Metrics.java

示例2: increasePower

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
public static void increasePower(UUID playerUUID)
{
    Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();

    taskBuilder.execute(new Runnable()
    {
        @Override
        public void run()
        {
            if(!PlayerService.isPlayerOnline(playerUUID)) return;

            if(PowerService.getPlayerPower(playerUUID).add(MainLogic.getPowerIncrement()).doubleValue() < PowerService.getPlayerMaxPower(playerUUID).doubleValue())
            {
                PowerService.addPower(playerUUID, false);
                increasePower(playerUUID);
            }
            else
            {
                PowerService.setPower(playerUUID, PowerService.getPlayerMaxPower(playerUUID));
                increasePower(playerUUID);
            }
        }
    }).delay(1, TimeUnit.MINUTES).name("Eaglefactions - Increase power scheduler").submit(Sponge.getPluginManager().getPlugin(PluginInfo.Id).get().getInstance().get());
}
 
開發者ID:Aquerr,項目名稱:EagleFactions,代碼行數:25,代碼來源:PowerService.java

示例3: registerTasks

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
@Override
public void registerTasks() {
    Task.builder()
            .interval(1, TimeUnit.SECONDS)
            .execute(new TpsCollector(core.getConnector(), Sponge.getServer()::getTicksPerSecond))
            .submit(this);

    Task.builder()
            .interval(2, TimeUnit.SECONDS)
            .execute(new PingCollector(core.getConnector(), () -> Sponge.getServer().getOnlinePlayers().stream()
                    .mapToInt(player -> player.getConnection().getLatency())
                    .average().orElse(0)))
            .submit(this);

    Task.builder()
            .interval(5, TimeUnit.MINUTES)
            .execute(injector.getInstance(SpongeWorldCollector.class))
            .submit(this);

    Task.builder()
            .interval(15, TimeUnit.MINUTES)
            .execute(playerCollector)
            .submit(this);
}
 
開發者ID:games647,項目名稱:Minefana,代碼行數:25,代碼來源:MinefanaSponge.java

示例4: registerDatabasePollingTask

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
private void registerDatabasePollingTask() {
    int delayInSeconds = 3600;
    int delayInTicks = delayInSeconds * 20;

    Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();
    taskBuilder.execute(new Runnable() {
        @Override
        public void run() {
            if (!DatabaseConnectionOwner.getInstance().isValid()) {
                DatabaseConnectionOwner.getInstance().setupConnection();
            }
        }
    });
    taskBuilder.delayTicks(delayInTicks).intervalTicks(delayInTicks).submit(MCClans.getPlugin());

    getLogger().info("Registered database polling task to run every " + delayInSeconds + "s (" + delayInSeconds / 3600 + "h)", false);
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:18,代碼來源:MCClans.java

示例5: execute

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
@Override
public boolean execute(CommandSource source, String[] args) {
    if (args.length != 2) {
        source.sendMessage(TextUtil.of("§c/" + McrmbPluginInfo.config.command + " setup <SID> <KEY>"));
        return true;
    }
    String sid = args[0];
    String key = args[1];
    McrmbPluginInfo.config.sid = sid;
    McrmbPluginInfo.config.key = key;
    McrmbPluginInfo.save();
    source.sendMessages(
            TextUtil.of("§2已將SID設置為§a" + sid + ", §2KEY設置為§a" + key + "."),
            TextUtil.of("§2正在為您重新獲取卡種...")
    );
    Task.builder().name("reload-card-types").execute(() -> {
        CardTypesManager.init();
        source.sendMessage(TextUtil.of("§2卡種重新獲取完成, 詳情請查看後台輸出."));
    }).submit(McrmbCoreMain.instance());

    return true;
}
 
開發者ID:txgs888,項目名稱:McrmbCore_Sponge,代碼行數:23,代碼來源:SetupCommand.java

示例6: execute

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
@Override
public boolean execute(CommandSource source, String[] args) {
    if ((args.length != 2 && args.length != 3) || !StringUtils.isNumeric(args[1])) {
        source.sendMessage(TextUtil.of("§c/" + McrmbPluginInfo.config.command + " give <玩家> <增加數量> [理由]"));
        return true;
    }
    if (source instanceof Player && !McrmbPluginInfo.config.opModifyWhiteList.contains(source.getName())) {
        source.sendMessage(TextUtil.of("§c你無法執行該操作,你可以在後台輸入/" + McrmbPluginInfo.config.command + " adminwhite add <你的ID> 來添加你到操作點券白名單"));
        return true;
    }
    Task.builder().name("manual-give")
            .execute(() -> {
                ManualResult result = McrmbCoreAPI.manual(args[0], ManualType.ADD, Integer.parseInt(args[1]), args.length == 3 ? args[2] : source.getName() + "加款");
                if (result == null) {
                    source.sendMessage(TextUtil.of("§c加款失敗"));
                    return;
                }
                source.sendMessage(TextUtil.of("§2加款成功,返回信息: §a" + result.getMsg()));
            }).submit(McrmbCoreMain.instance());
    return true;
}
 
開發者ID:txgs888,項目名稱:McrmbCore_Sponge,代碼行數:22,代碼來源:GiveCommand.java

示例7: execute

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
@Override
public boolean execute(CommandSource source, String[] args) {
    Task.builder().name("check-money")
            .execute(() -> {
                CheckMoneyResult result = McrmbCoreAPI.checkMoney(source.getName());
                if (result == null) {
                    source.sendMessage(TextUtil.of("§c查詢餘額失敗."));
                    return;
                }
                source.sendMessages(
                        TextUtil.of("§2當前餘額: " + result.getMoney()),
                        TextUtil.of("§2曆史消費: " + result.getAllCharge()),
                        TextUtil.of("§2曆史充值: " + result.getAllPay())
                );
            }).submit(McrmbCoreMain.instance());


    return true;
}
 
開發者ID:txgs888,項目名稱:McrmbCore_Sponge,代碼行數:20,代碼來源:MoneyCommand.java

示例8: execute

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
@Override
public boolean execute(CommandSource source, String[] args) {
    if ((args.length != 2 && args.length != 3) || !StringUtils.isNumeric(args[1])) {
        source.sendMessage(TextUtil.of("§c/" + McrmbPluginInfo.config.command + " set <玩家> <設置數量> [理由]"));
        return true;
    }
    if (source instanceof Player && !McrmbPluginInfo.config.opModifyWhiteList.contains(source.getName())) {
        source.sendMessage(TextUtil.of("§c你無法執行該操作,你可以在後台輸入/" + McrmbPluginInfo.config.command + " adminwhite add <你的ID> 來添加你到操作點券白名單"));
        return true;
    }
    Task.builder().name("manual-reset")
            .execute(() -> {
                ManualResult result = McrmbCoreAPI.manual(args[0], ManualType.RESET, Integer.parseInt(args[1]), args.length == 3 ? args[2] : source.getName() + "重設");
                if (result == null) {
                    source.sendMessage(TextUtil.of("§c重設點券失敗"));
                    return;
                }
                source.sendMessage(TextUtil.of("§2重設點券成功,返回信息: §a" + result.getMsg()));
            }).submit(McrmbCoreMain.instance());
    return true;
}
 
開發者ID:txgs888,項目名稱:McrmbCore_Sponge,代碼行數:22,代碼來源:SetCommand.java

示例9: execute

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
@Override
public boolean execute(CommandSource source, String[] args) {
    if ((args.length != 2 && args.length != 3) || !StringUtils.isNumeric(args[1])) {
        source.sendMessage(TextUtil.of("§c/" + McrmbPluginInfo.config.command + " take <玩家> <扣除數量> [理由]"));
        return true;
    }
    if (source instanceof Player && !McrmbPluginInfo.config.opModifyWhiteList.contains(source.getName())) {
        source.sendMessage(TextUtil.of("§c你無法執行該操作,你可以在後台輸入/" + McrmbPluginInfo.config.command + " adminwhite add <你的ID> 來添加你到操作點券白名單"));
        return true;
    }
    Task.builder().name("manual-take")
            .execute(() -> {
                ManualResult result = McrmbCoreAPI.manual(args[0], ManualType.TAKE, Integer.parseInt(args[1]), args.length == 3 ? args[2] : source.getName() + "扣款");
                if (result == null) {
                    source.sendMessage(TextUtil.of("§c扣款失敗"));
                    return;
                }
                source.sendMessage(TextUtil.of("§2扣款成功,返回信息: §a" + result.getMsg()));
            }).submit(McrmbCoreMain.instance());
    return true;
}
 
開發者ID:txgs888,項目名稱:McrmbCore_Sponge,代碼行數:22,代碼來源:TakeCommand.java

示例10: registerPlayer

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
private void registerPlayer(Player player) {
    player.setSleepingIgnored(true); // Turn off vanilla sleeping to prevent a bug where the time advances (or doesn't, if /gamerule doDaylightCycle false, in which case it just kicks players out of bed without doing anything) but the plugin doesn't display the wakeup message.
    SVPlayerData svPlayerData = getSVPlayerData(player);

    svPlayerData.getSleepTask().ifPresent(Task::cancel);
    svPlayerData.setSleepTask(Task.builder().execute(() -> {
        if (isInBed(player) && !isIgnored(player)) {
            World world = player.getWorld();
            SVWorldData svWorldData = getSVWorldData(world);
            svWorldData.getSleepingPlayers().add(player.getUniqueId());

            Text text = messenger.parseMessage(enterBedMessage,
                    svWorldData.getSleepingPlayers().size(),
                    getRequiredPlayerCount(world),
                    player.getName(),
                    enablePrefix);
            messenger.sendWorldMessage(world, text);
            messenger.playWorldSound(world, SoundTypes.BLOCK_NOTE_HAT);

            if (messageLogging) {
                logger.info("[" + world.getName() + "] " + text.toPlain());
            }
        }
    }).async().delayTicks(80).submit(sleepVote));
}
 
開發者ID:Icohedron,項目名稱:SleepVote,代碼行數:26,代碼來源:SleepVoteManager.java

示例11: onServerSTarted

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
@Listener
public void onServerSTarted(GameStartedServerEvent event) {
    Task.builder()
            .delay(5, TimeUnit.SECONDS)
            .interval(1, TimeUnit.SECONDS)
            .name("Disco Changer")
            .execute(() -> {
                // DISCO DISCO TIME
                ImmutableList<Aspect> aspects = ImmutableList.copyOf(Sponge.getRegistry().getAllOf(Aspect.class));
                for (Map.Entry<UUID, UUID> entry : this.auraMap.entrySet()) {
                    Optional<World> world = Sponge.getServer().getWorld(entry.getKey());
                    world.ifPresent(spongeWorld -> {
                        Optional<Entity> aura = spongeWorld.getEntity(entry.getValue());
                        aura.ifPresent(auraNode -> {
                            AuraNodeData nodeData = ((AuraNode) auraNode).auraNodeData();
                            Aspect value = aspects.get(RANDOM.nextInt(aspects.size()));
                            nodeData.set(ThaumicKeys.AURA_NODE_ASPECT, value);
                            nodeData.set(ThaumicKeys.AURA_NODE_SIZE, RANDOM.nextInt(400));
                            auraNode.offer(nodeData);
                        });
                    });
                }

            })
            .submit(this);
}
 
開發者ID:gabizou,項目名稱:ThaumicSponge,代碼行數:27,代碼來源:ThaumicSpongeMod.java

示例12: onServerStarting

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
@Listener
public void onServerStarting(GameStartedServerEvent event) {

    // Delay loading shops so mods can register items
    shopManager = configManager.loadShops();
    shopTypeManager = configManager.loadShopTypes();
    shopRentManager = ShopRentManager.getInstance();
    shopRentManager.init(this, configManager.loadShopRent());

    // Register Commands
    CommandRegister.registerCommands(this);

    Task.builder()
            .async()
            .execute(() -> {
                logger.info("Saving Shops to DB");
                configManager.saveShops();
                configManager.saveShopRent();
            })
            .interval(5, TimeUnit.MINUTES)
            .name("PlayerShop Save Task")
            .submit(this);

}
 
開發者ID:Zerthick,項目名稱:PlayerShopsRPG,代碼行數:25,代碼來源:PlayerShopsRPG.java

示例13: startSubmitting

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
private void startSubmitting() {
	// We use a timer cause want to be independent from the server tps
	final Timer timer = new Timer(true);
	timer.scheduleAtFixedRate(new TimerTask() {
		@Override
		public void run() {
			// Plugin was disabled, e.g. because of a reload (is this even
			// possible in Sponge?)
			if (!Sponge.getPluginManager().isLoaded(plugin.getId())) {
				timer.cancel();
				return;
			}
			// The data collection (e.g. for custom graphs) is done sync
			// Don't be afraid! The connection to the bStats server is still
			// async, only the stats collection is sync ;)
			Scheduler scheduler = Sponge.getScheduler();
			Task.Builder taskBuilder = scheduler.createTaskBuilder();
			taskBuilder.execute(() -> submitData()).submit(plugin);
		}
	}, 1000 * 60 * 5, 1000 * 60 * 30);
	// Submit the data every 30 minutes, first time after 5 minutes to give
	// other plugins enough time to start
	// WARNING: Changing the frequency has no effect but your plugin WILL be
	// blocked/deleted!
	// WARNING: Just don't do it!
}
 
開發者ID:rojo8399,項目名稱:PlaceholderAPI,代碼行數:27,代碼來源:Metrics.java

示例14: addURLspam

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
private static void addURLspam(final Player p){
	if (UChat.get().getConfig().protections().anti_ip.punish.enable){
		if (!UrlSpam.containsKey(p)){
			UrlSpam.put(p, 1);
		} else {
			UrlSpam.put(p, UrlSpam.get(p)+1);
			if (UrlSpam.get(p) >= UChat.get().getConfig().protections().anti_ip.punish.max_attempts){
				if (UChat.get().getConfig().protections().anti_ip.punish.mute_or_cmd.equalsIgnoreCase("mute")){
					
					int time = UChat.get().getConfig().protections().anti_ip.punish.mute_duration;
					UChat.get().mutes.add(p.getName());
					UChat.get().muteInAllChannels(p.getName());
					p.sendMessage(UCUtil.toText(UChat.get().getConfig().protections().anti_ip.punish.mute_msg));
					
					//mute counter
					Task.builder().execute(new MuteCountDown(p.getName(), time)).interval(1, TimeUnit.SECONDS).name("Chat Protection Mute Counter").submit(UChat.get().instance());								
				} else {
					Sponge.getCommandManager().process(Sponge.getServer().getConsole(), UChat.get().getConfig().protections().anti_ip.punish.cmd_punish.replace("{player}", p.getName()));
				}	
				UrlSpam.remove(p);
			}
		}
	}		
}
 
開發者ID:FabioZumbi12,項目名稱:UltimateChat,代碼行數:25,代碼來源:UCChatProtection.java

示例15: accept

import org.spongepowered.api.scheduler.Task; //導入依賴的package包/類
@Override
public void accept(Task t) {
	if (UChat.get().timeMute.containsKey(p)) {
		time = UChat.get().timeMute.get(p)-1;
	}
	if (UChat.get().mutes.contains(p)){
		if (time > 0) {
			UChat.get().timeMute.put(p, time);
		} else {
			UChat.get().timeMute.remove(p);
			UChat.get().mutes.remove(p);
			UChat.get().unMuteInAllChannels(p);
			if (Sponge.getServer().getPlayer(p).isPresent()){
				UChat.get().getLang().sendMessage(Sponge.getServer().getPlayer(p).get(), UChat.get().getLang().get("channel.player.unmuted.all"));
			}
			t.cancel();
		}
	} else {
		t.cancel();
	}
}
 
開發者ID:FabioZumbi12,項目名稱:UltimateChat,代碼行數:22,代碼來源:MuteCountDown.java


注:本文中的org.spongepowered.api.scheduler.Task類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。