Search in sources :

Example 1 with EntityCleanupTask

use of com.skelril.nitro.entity.EntityCleanupTask in project Skree by Skelril.

the class DropClearServiceImpl method dropClear.

private boolean dropClear(World world, int seconds, boolean overwrite) {
    TimedRunnable<EntityCleanupTask> runnable = getActiveTask(world);
    // Check for old task, and overwrite if allowed
    if (runnable != null) {
        if (overwrite) {
            runnable.setTimes(seconds);
            return true;
        }
        return false;
    }
    EntityCleanupTask cleanupTask = pickDropClear(world);
    // Setup new task
    runnable = new TimedRunnable<EntityCleanupTask>(cleanupTask, seconds) {

        @Override
        public void cancel(boolean withEnd) {
            super.cancel(withEnd);
            if (withEnd) {
                entityCount.put(world, 0L);
            // TODO send to the yet to be made, Entity Stats service
            // lastClear.put(world, getBaseTask().getLastProfile());
            }
            timers.remove(world);
        }
    };
    // Offset this by one to prevent the drop clear from triggering twice
    Task task = Task.builder().execute(runnable).delayTicks(1).interval(1, TimeUnit.SECONDS).submit(SkreePlugin.inst());
    runnable.setTask(task);
    timers.put(world, runnable);
    return true;
}
Also used : EntityCleanupTask(com.skelril.nitro.entity.EntityCleanupTask) Task(org.spongepowered.api.scheduler.Task) EntityCleanupTask(com.skelril.nitro.entity.EntityCleanupTask)

Aggregations

EntityCleanupTask (com.skelril.nitro.entity.EntityCleanupTask)1 Task (org.spongepowered.api.scheduler.Task)1