Search in sources :

Example 1 with Scheduler

use of org.spongepowered.api.scheduler.Scheduler in project TotalEconomy by Erigitic.

the class TEJobManager method startSalaryTask.

/**
     * Start the timer that pays out the salary to each player after a specified time in seconds
     */
private void startSalaryTask() {
    Scheduler scheduler = totalEconomy.getGame().getScheduler();
    Task.Builder payTask = scheduler.createTaskBuilder();
    payTask.execute(() -> {
        for (Player player : totalEconomy.getServer().getOnlinePlayers()) {
            Optional<TEJob> optJob = getJob(getPlayerJob(player), true);
            if (!optJob.isPresent()) {
                player.sendMessage(Text.of(TextColors.RED, "[TE] Cannot pay your salary! Contact your administrator!"));
                return;
            }
            if (optJob.get().salaryEnabled()) {
                BigDecimal salary = optJob.get().getSalary();
                TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
                TransactionResult result = playerAccount.deposit(totalEconomy.getDefaultCurrency(), salary, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
                if (result.getResult() == ResultType.SUCCESS) {
                    player.sendMessage(Text.of(TextColors.GRAY, "Your salary of ", TextColors.GOLD, totalEconomy.getDefaultCurrency().format(salary), TextColors.GRAY, " has just been paid."));
                } else {
                    player.sendMessage(Text.of(TextColors.RED, "[TE] Failed to pay your salary! You may want to contact your admin - TransactionResult: ", result.getResult().toString()));
                }
            }
        }
    }).delay(jobsConfig.getNode("salarydelay").getInt(), TimeUnit.SECONDS).interval(jobsConfig.getNode("salarydelay").getInt(), TimeUnit.SECONDS).name("Pay Day").submit(totalEconomy);
}
Also used : Task(org.spongepowered.api.scheduler.Task) Player(org.spongepowered.api.entity.living.player.Player) TransactionResult(org.spongepowered.api.service.economy.transaction.TransactionResult) Scheduler(org.spongepowered.api.scheduler.Scheduler) TEAccount(com.erigitic.config.TEAccount) BigDecimal(java.math.BigDecimal)

Example 2 with Scheduler

use of org.spongepowered.api.scheduler.Scheduler in project HuskyCrates-Sponge by codeHusky.

the class CrateUtilities method startParticleEffects.

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);
}
Also used : Task(org.spongepowered.api.scheduler.Task) Scheduler(org.spongepowered.api.scheduler.Scheduler)

Aggregations

Scheduler (org.spongepowered.api.scheduler.Scheduler)2 Task (org.spongepowered.api.scheduler.Task)2 TEAccount (com.erigitic.config.TEAccount)1 BigDecimal (java.math.BigDecimal)1 Player (org.spongepowered.api.entity.living.player.Player)1 TransactionResult (org.spongepowered.api.service.economy.transaction.TransactionResult)1