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


Java Task.Builder方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: executeAsync

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	Player p = ctx.<Player> getOne("player").get();

	// Uses the TimespanParser.
	Optional<Long> time = ctx.<Long> getOne("time");

	if (time.isPresent())
	{
		Task.Builder taskBuilder = game.getScheduler().createTaskBuilder();
		taskBuilder.execute(() -> {
			if (EssentialCmds.muteList.contains(p.getUniqueId()))
				EssentialCmds.muteList.remove(p.getUniqueId());
		}).delay(time.get(), TimeUnit.SECONDS).name("EssentialCmds - Remove previous mutes").submit(EssentialCmds.getEssentialCmds());
	}

	EssentialCmds.muteList.add(p.getUniqueId());
	Utils.addMute(p.getUniqueId());
	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Player muted."));
}
 
開發者ID:hsyyid,項目名稱:EssentialCmds,代碼行數:23,代碼來源:MuteExecutor.java

示例4: attack

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
public static void attack(Player player, Vector3i attackedChunk, int seconds)
{
    if(attackedChunk.toString().equals(player.getLocation().getChunkPosition().toString()))
    {
        if(seconds == MainLogic.getAttackTime())
        {
               player.sendMessage(Text.of(PluginInfo.PluginPrefix, TextColors.GREEN, "Claim destroyed!"));
               FactionLogic.removeClaim(FactionLogic.getFactionNameByChunk(player.getWorld().getUniqueId(), attackedChunk), player.getWorld().getUniqueId(), attackedChunk);
        }
        else
        {
            player.sendMessage(Text.of(PluginInfo.PluginPrefix, TextColors.RESET, seconds));
            Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();
            taskBuilder.execute(new Runnable()
            {
                 @Override
                 public void run()
                 {
                              attack(player, attackedChunk, seconds + 1);
                 }

            }).delay(1, TimeUnit.SECONDS).name("EagleFactions - Attack").submit(Sponge.getPluginManager().getPlugin(PluginInfo.Id).get().getInstance().get());
        }
    }
    else
    {
        player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You moved from the chunk!"));
    }
}
 
開發者ID:Aquerr,項目名稱:EagleFactions,代碼行數:30,代碼來源:AttackLogic.java

示例5: RouletteCrateView

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
public RouletteCrateView(HuskyCrates plugin, Player runner, VirtualCrate virtualCrate){
    this.plugin = plugin;
    vc = virtualCrate;
    ourplr = runner;
    items = vc.getItemSet();
    if(virtualCrate.scrambleRewards){
        scrambleRewards();
    }
    disp = Inventory.builder()
            .of(InventoryArchetypes.DISPENSER)
            .listener(InteractInventoryEvent.class, evt ->{
                if(!(evt instanceof InteractInventoryEvent.Open) && !(evt instanceof  InteractInventoryEvent.Close)){
                    evt.setCancelled(true);
                    if(!stopped && evt instanceof ClickInventoryEvent){
                        ourplr.playSound(SoundTypes.ENTITY_FIREWORK_LAUNCH,ourplr.getLocation().getPosition(),1);
                    }
                    stopped = true;
                }

            })
            .property(InventoryTitle.PROPERTY_NAME,InventoryTitle.of(TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName)))
            .build(plugin);
    updateInv(0);
    Scheduler scheduler = Sponge.getScheduler();
    Task.Builder taskBuilder = scheduler.createTaskBuilder();
    updater = taskBuilder.execute(this::updateTick).intervalTicks(1).submit(plugin);
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:28,代碼來源:RouletteCrateView.java

示例6: InstantGUIView

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
public InstantGUIView(HuskyCrates plugin, Player runner, VirtualCrate virtualCrate){
    //System.out.println("AA");
    this.plugin = plugin;
    vc = virtualCrate;
    ourplr = runner;
    items = vc.getItemSet();
    if(virtualCrate.scrambleRewards){
        scrambleRewards();
    }
    disp = Inventory.builder()
            .of(InventoryArchetypes.DISPENSER)
            .listener(InteractInventoryEvent.class, evt ->{
                if(!(evt instanceof InteractInventoryEvent.Open) && !(evt instanceof  InteractInventoryEvent.Close)){
                    evt.setCancelled(true);
                }

            })
            .property(InventoryTitle.PROPERTY_NAME,InventoryTitle.of(TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName)))
            .build(plugin);
    updateInv(0);
    Scheduler scheduler = Sponge.getScheduler();
    Task.Builder taskBuilder = scheduler.createTaskBuilder();
    updater = taskBuilder.execute(this::updateTick).intervalTicks(1).submit(plugin);
    scheduler.createTaskBuilder().execute(() -> {
        updater.cancel();
        ourplr.closeInventory();
        handleReward(holder);
        ourplr.playSound(SoundTypes.ENTITY_EXPERIENCE_ORB_PICKUP,ourplr.getLocation().getPosition(),1);
    }).delay(3, TimeUnit.SECONDS).submit(HuskyCrates.instance);
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:31,代碼來源:InstantGUIView.java

示例7: startParticleEffects

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
public void startParticleEffects(){
    if(runner != null){
        runner.cancel();
    }
    Scheduler scheduler = Sponge.getScheduler();
    Task.Builder taskBuilder = scheduler.createTaskBuilder();
    runner = taskBuilder.execute(this::particleRunner).intervalTicks(1).submit(plugin);
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:9,代碼來源:CrateUtilities.java

示例8: startTeleportTask

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
private void startTeleportTask(Player player, ClanPlayerImpl clanPlayer, Location<World> teleportLocation, Location<World> currentPlayerLocation) {
    clanPlayer.setLastTeleportInitiationLocation(currentPlayerLocation);
    Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();
    taskBuilder.interval(1, TimeUnit.SECONDS).execute(
            new ClanHomeTeleportTask(player, clanPlayer, teleportLocation, Config.getInteger(Config.TELEPORT_DELAY_SECONDS), false)
    ).submit(MCClans.getPlugin());
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:8,代碼來源:ClanCommands.java

示例9: backup

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
public void backup() {
    MCClans.getPlugin().getLogger().info("System backup commencing...", false);

    List<ClanImpl> retrievedClans = ClansImpl.getInstance().getClanImpls();
    List<ClanPlayerImpl> retrievedClanPlayers = ClansImpl.getInstance().getClanPlayerImpls();

    final List<ClanImpl> clans = new ArrayList<ClanImpl>();
    final List<ClanPlayerImpl> clanPlayers = new ArrayList<ClanPlayerImpl>();

    for (ClanImpl retrievedClan : retrievedClans) {
        clans.add(retrievedClan.clone());
    }

    for (ClanPlayerImpl retrievedclanPlayers : retrievedClanPlayers) {
        clanPlayers.add(retrievedclanPlayers.clone());
    }

    Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();
    taskBuilder.execute(new Runnable() {
        @Override
        public void run() {
            JsonSaver jsonSaver = new JsonSaver();
            jsonSaver.useBackupLocation();
            jsonSaver.save(clans, clanPlayers);
            MCClans.getPlugin().getLogger().info("System backup finished", false);
        }
    });
    taskBuilder.async().submit(MCClans.getPlugin());
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:30,代碼來源:DatabaseHandler.java

示例10: registerBackupTask

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
private void registerBackupTask() {
    File backupFolder = new File(getDataFolder(), "backup");
    File lastBackup = FileUtils.getLastModifiedFileInFolder(backupFolder);
    long nextBackupInTicks;
    if (lastBackup != null) {
        long milisSinceLastBackup = System.currentTimeMillis() - lastBackup.lastModified();
        long milisTillNextBackup = (Config.getInteger(Config.CREATE_BACKUP_AFTER_HOURS) * 3600000) - milisSinceLastBackup;
        if (milisTillNextBackup < 50) {
            milisTillNextBackup = 50;
        }
        nextBackupInTicks = milisTillNextBackup / 50;
    } else {
        nextBackupInTicks = 1;
    }

    long delayBetweenBackupsInTicks = Config.getInteger(Config.CREATE_BACKUP_AFTER_HOURS) * 72000; // hours * 3600 * 20 = ticks

    Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();
    taskBuilder.execute(new Runnable() {
        @Override
        public void run() {
            DatabaseHandler.getInstance().backup();
        }
    });
    taskBuilder.delayTicks(nextBackupInTicks).intervalTicks(delayBetweenBackupsInTicks).submit(MCClans.getPlugin());

    getLogger().info("Registered backup task to run every " + delayBetweenBackupsInTicks / 20 + "s (" + delayBetweenBackupsInTicks / 72000 + "h), starting in " + nextBackupInTicks / 20 + "s", false);

}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:30,代碼來源:MCClans.java

示例11: fireOpenEvent

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
private void fireOpenEvent(InteractInventoryEvent.Open e)
{
    Optional<Player> optional = Sponge.getServer().getPlayer(playerUniqueId);
    if (optional.isPresent())
    {
        Player player = optional.get();
        Container targetContainer = e.getTargetInventory();
        Inventory targetInventory = targetContainer.first();
        plugin.getVirtualChestActions().submitCommands(player, parsedOpenAction, ImmutableList.of());
        if (updateIntervalTick > 0)
        {
            Task.Builder builder = Sponge.getScheduler().createTaskBuilder().execute(task ->
            {
                if (player.getOpenInventory().filter(targetContainer::equals).isPresent())
                {
                    refreshMappingFrom(targetInventory, updateInventory(player, targetInventory));
                }
                else
                {
                    task.cancel();
                }
            });
            builder.delayTicks(updateIntervalTick).intervalTicks(updateIntervalTick).submit(plugin);
        }
        logger.debug("Player {} opens the chest GUI", player.getName());
        plugin.getScriptManager().onOpeningInventory(player);
        refreshMappingFrom(targetInventory, updateInventory(player, targetInventory));
    }
}
 
開發者ID:ustc-zzzz,項目名稱:VirtualChest,代碼行數:30,代碼來源:VirtualChestInventory.java

示例12: VirtualChestActions

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
public VirtualChestActions(VirtualChestPlugin plugin)
{
    this.plugin = plugin;
    this.queuedCallbacks = new ArrayDeque<>();
    this.permissionMap = Multimaps.newSortedSetMultimap(new IdentityHashMap<>(), TreeSet::new);

    Task.Builder taskBuilder = this.scheduler.createTaskBuilder().intervalTicks(1);
    taskBuilder.name("VirtualChestActionExecutor").execute(this::tick).submit(plugin);

    registerPrefix("console", this::processConsole);
    registerPrefix("tell", this::processTell);
    registerPrefix("tellraw", this::processTellraw);
    registerPrefix("broadcast", this::processBroadcast);
    registerPrefix("title", this::processTitle);
    registerPrefix("bigtitle", this::processBigtitle);
    registerPrefix("subtitle", this::processSubtitle);
    registerPrefix("delay", this::processDelay);
    registerPrefix("connect", this::processConnect);
    registerPrefix("cost", this::processCost);
    registerPrefix("cost-item", this::processCostItem);
    registerPrefix("sound", this::processSound);
    registerPrefix("sound-with-pitch", this::processSoundWithPitch);

    registerPrefix("", this::process);

    TitleManager.enable(plugin);
}
 
開發者ID:ustc-zzzz,項目名稱:VirtualChest,代碼行數:28,代碼來源:VirtualChestActions.java

示例13: onReload

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
@Listener
public void onReload(GameReloadEvent event) {
    cfgLoader = new ConfigLoader(this);
    if (cfgLoader.loadConfig()) cclConfig = cfgLoader.getCclConfig();
    if (cfgLoader.loadMessages()) messages = cfgLoader.getMessagesConfig();
    for (Task task : tasks) {
        task.cancel();
    }
    tasks = new ArrayList<>();
    Task.Builder builder = getGame().getScheduler().createTaskBuilder();
    tasks.add(builder.execute(new ItemClearer())
            .async()
            .delay(cclConfig.interval, TimeUnit.MINUTES)
            .interval(cclConfig.interval, TimeUnit.MINUTES)
            .name("CatClearLag Item Remover")
            .submit(this));
    cclConfig.warnings.forEach((d) ->
            tasks.add(builder.execute(new ItemClearingWarning(((cclConfig.interval * 60) - d)))
                    .async()
                    .delay(d, TimeUnit.SECONDS)
                    .interval(cclConfig.interval, TimeUnit.MINUTES)
                    .name("CatClearLag Removal Warnings")
                    .submit(this)));
    tasks.add(builder.execute(new EntityChecker())
            .async()
            .delay(cclConfig.limits.entityCheckInterval, TimeUnit.MINUTES)
            .interval(cclConfig.limits.entityCheckInterval, TimeUnit.MINUTES)
            .name("CatClearLag hostile checker")
            .submit(this));
}
 
開發者ID:Time6628,項目名稱:CatClearLag,代碼行數:31,代碼來源:CatClearLag.java

示例14: onInit

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
@Listener
public void onInit(GameInitializationEvent event) {
    getLogger().info("Starting plugin...");
    registerCommands();
    registerEvents();
    tasks = new ArrayList<>();
    Task.Builder builder = getGame().getScheduler().createTaskBuilder();
    tasks.add(builder.execute(new ItemClearer())
            .async()
            .delay(cclConfig.interval, TimeUnit.MINUTES)
            .interval(cclConfig.interval, TimeUnit.MINUTES)
            .name("CatClearLag Item Remover")
            .submit(this));
    cclConfig.warnings.forEach((d) ->
            tasks.add(builder.execute(new ItemClearingWarning(((cclConfig.interval * 60) - d)))
                    .async()
                    .delay(d, TimeUnit.SECONDS)
                    .interval(cclConfig.interval, TimeUnit.MINUTES)
                    .name("CatClearLag Removal Warnings")
                    .submit(this)));
    tasks.add(builder.execute(new EntityChecker())
            .async()
            .delay(cclConfig.limits.entityCheckInterval, TimeUnit.MINUTES)
            .interval(cclConfig.limits.entityCheckInterval, TimeUnit.MINUTES)
            .name("CatClearLag hostile checker")
            .submit(this));
}
 
開發者ID:Time6628,項目名稱:CatClearLag,代碼行數:28,代碼來源:CatClearLag.java

示例15: repeat

import org.spongepowered.api.scheduler.Task; //導入方法依賴的package包/類
@Override
public int repeat(Runnable runnable, int interval) {
    int val = this.i.incrementAndGet();
    Task.Builder builder = Sponge.getGame().getScheduler().createTaskBuilder();
    Task.Builder built = builder.delayTicks(interval).intervalTicks(interval).execute(runnable);
    Task task = built.submit(plugin);
    this.tasks.put(val, task);
    return val;
}
 
開發者ID:boy0001,項目名稱:FastAsyncWorldedit,代碼行數:10,代碼來源:SpongeTaskMan.java


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