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