本文整理汇总了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());
}
示例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);
}
示例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."));
}
示例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!"));
}
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
示例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);
}
示例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));
}
}
示例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);
}
示例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));
}
示例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));
}
示例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;
}