Java Code Examples for org.spongepowered.api.scheduler.Task#cancel()

The following examples show how to use org.spongepowered.api.scheduler.Task#cancel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
public void unloadWorldData(World world) {
    final UUID worldUniqueId = world.getUniqueId();
    GDClaimManager claimWorldManager = this.getClaimWorldManager(worldUniqueId);
    for (Claim claim : claimWorldManager.getWorldClaims()) {
        ((GDClaim) claim).unload();
    }
    // Task must be cancelled before removing the claimWorldManager reference to avoid a memory leak
    Task cleanupTask = cleanupClaimTasks.get(worldUniqueId);
    if (cleanupTask != null) {
       cleanupTask.cancel();
       cleanupClaimTasks.remove(worldUniqueId);
    }

    claimWorldManager.unload();
    this.claimWorldManagers.remove(worldUniqueId);
    BaseStorage.dimensionConfigMap.remove(worldUniqueId);
    BaseStorage.worldConfigMap.remove(worldUniqueId);
}
 
Example 2
Source File: PowerIncrementTask.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public void accept(final Task task)
{
    if (!this.playerManager.isPlayerOnline(playerUUID))
        task.cancel();

    final Optional<FactionPlayer> optionalFactionPlayer = this.playerManager.getFactionPlayer(playerUUID);
    if (!optionalFactionPlayer.isPresent())
        return;

    final FactionPlayer factionPlayer=  optionalFactionPlayer.get();

    if(factionPlayer.getPower() + this.powerConfig.getPowerIncrement() < factionPlayer.getMaxPower())
        this.powerManager.addPower(playerUUID, false);
    else
        this.powerManager.setPlayerPower(playerUUID, factionPlayer.getMaxPower());
}
 
Example 3
Source File: ParticlesUtil.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
		public void accept(Task task)
		{
//			double x = this.location.getX() + r * Math.cos(Math.toDegrees(angle));
//			double z = this.location.getZ() + r * Math.sin(Math.toDegrees(angle));

			double x = this.location.getX() + r * Math.cos(angle);
			double z = this.location.getZ() + r * Math.sin(angle);


			world.spawnParticles(ParticleEffect.builder().type(ParticleTypes.END_ROD).quantity(5).offset(Vector3d.from(0, 0.5, 0)).build(), Vector3d.from(x, location.getY() + 0.5, z));

			if (angle + angleIncrement > 360)
			{
				angle = (angle + angleIncrement) - 360;
			}
			else
			{
				angle += angleIncrement;
			}

			//TODO: This code runs forever until player changes location. We should count delay seconds here as well maybe?
			if (!this.lastBlockPosition.equals(this.player.getLocation().getBlockPosition()))
				task.cancel();
		}
 
Example 4
Source File: MuteCountDown.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
@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();
    }
}
 
Example 5
Source File: FlatFileDataStore.java    From GriefPrevention with MIT License 6 votes vote down vote up
public void unloadWorldData(WorldProperties worldProperties) {
    GPClaimManager claimWorldManager = this.getClaimWorldManager(worldProperties);
    for (Claim claim : claimWorldManager.getWorldClaims()) {
        ((GPClaim) claim).unload();
    }
    // Task must be cancelled before removing the claimWorldManager reference to avoid a memory leak
    Task cleanupTask = cleanupClaimTasks.get(worldProperties.getUniqueId());
    if (cleanupTask != null) {
       cleanupTask.cancel();
       cleanupClaimTasks.remove(worldProperties.getUniqueId());
    }

    claimWorldManager.unload();
    this.claimWorldManagers.remove(worldProperties.getUniqueId());
    DataStore.dimensionConfigMap.remove(worldProperties.getUniqueId());
    DataStore.worldConfigMap.remove(worldProperties.getUniqueId());
}
 
Example 6
Source File: RedProtect.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
private void shutDown() {
    // Unregister commands
    commandHandler.unregisterAll();

    // Save and unload all regions
    rm.saveAll(true);
    rm.unloadAll();

    // Cancel tasks from sponge scheduler and save logs
    for (Task task : Sponge.getScheduler().getScheduledTasks(this)) task.cancel();
    logger.SaveLogs();

    // Unregister listeners
    logger.info("Unregistering listeners...");
    Sponge.getEventManager().unregisterPluginListeners(this.container);
    Sponge.getEventManager().unregisterPluginListeners(this.container);

    logger.info(container.getName() + " turned off...");
}
 
Example 7
Source File: DynmapProvider.java    From GriefDefender with MIT License 5 votes vote down vote up
@Override
public void accept(Task t) {
    if (!disabled) {
        updateClaims();
    } else {
        t.cancel();
    }
}
 
Example 8
Source File: ClaimDelayTask.java    From EagleFactions with MIT License 5 votes vote down vote up
@Override
public void accept(Task task)
{
    if(!chunkPosition.equals(player.getLocation().getChunkPosition()))
    {
        player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MOVED_FROM_THE_CHUNK));
        task.cancel();
    }

    if(currentWaitSeconds >= claimDelay)
    {
        final Optional<Faction> optionalFaction = this.factionLogic.getFactionByPlayerUUID(player.getUniqueId());
        if(!optionalFaction.isPresent())
        {
            player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_IN_FACTION_IN_ORDER_TO_USE_THIS_COMMAND));
            task.cancel();
        }

        if(shouldClaimByItems)
        {
            boolean didSucceed = this.factionLogic.addClaimByItems(player, optionalFaction.get(), player.getWorld().getUniqueId(), chunkPosition);
            if(didSucceed)
                player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, Messages.LAND + " ", TextColors.GOLD, chunkPosition.toString(), TextColors.WHITE, " " + Messages.HAS_BEEN_SUCCESSFULLY + " ", TextColors.GOLD, Messages.CLAIMED, TextColors.WHITE, "!"));
            else
                player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_DONT_HAVE_ENOUGH_RESOURCES_TO_CLAIM_A_TERRITORY));
        }
        else
        {
            factionLogic.addClaim(optionalFaction.get(), new Claim(player.getWorld().getUniqueId(), chunkPosition));
            player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, Messages.LAND + " ", TextColors.GOLD, chunkPosition.toString(), TextColors.WHITE, " " + Messages.HAS_BEEN_SUCCESSFULLY + " ", TextColors.GOLD, Messages.CLAIMED, TextColors.WHITE, "!"));
        }
        task.cancel();
    }
    else
    {
        player.sendMessage(ChatTypes.ACTION_BAR, Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.RESET, currentWaitSeconds));
        currentWaitSeconds++;
    }
}
 
Example 9
Source File: SpongeTaskSystem.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void disable() {
    super.disable();
    for (Task task : Sponge.getScheduler().getScheduledTasks(plugin)) {
        task.cancel();
    }
}
 
Example 10
Source File: SpongeTaskMan.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void cancel(int i) {
    Task task = this.tasks.remove(i);
    if (task != null) {
        task.cancel();
    }
}
 
Example 11
Source File: SpongeTaskMan.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void cancel(int i) {
    Task task = this.tasks.remove(i);
    if (task != null) {
        task.cancel();
    }
}
 
Example 12
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void accept(Task task) {
    float diff = boss.getPercent() - 0.2f;
    if (diff > 0) {
        boss.setPercent(diff);
    } else {
        boss.setVisible(false);
        boss.removePlayer(boss.getPlayers().stream().findFirst().get());
        task.cancel();
    }
}
 
Example 13
Source File: ClaimVisualApplyTask.java    From GriefDefender with MIT License 4 votes vote down vote up
@Override
public void run() {
    if (!this.player.isOnline()) {
        this.playerData.revertAllVisuals();
        return;
    }
    // Only revert active visual if we are not currently creating a claim
    if (!this.playerData.visualClaimBlocks.isEmpty() && this.playerData.lastShovelLocation == null) {
        if (this.resetActive) {
            this.playerData.revertAllVisuals();
        }
    }

    for (Transaction<BlockSnapshot> transaction : this.visualization.getVisualTransactions()) {
        this.playerData.queuedVisuals.add(transaction.getFinal());
    }

    if (this.visualization.getClaim() != null) {
        this.visualization.getClaim().playersWatching.add(this.player.getUniqueId());
    }

    UUID visualUniqueId = null;
    if (this.visualization.getClaim() == null) {
        visualUniqueId = UUID.randomUUID();
        playerData.tempVisualUniqueId = visualUniqueId;
    } else {
        visualUniqueId = this.visualization.getClaim().getUniqueId();
    }

    final List<Transaction<BlockSnapshot>> blockTransactions = this.playerData.visualClaimBlocks.get(visualUniqueId);
    if (blockTransactions == null) {
        this.playerData.visualClaimBlocks.put(visualUniqueId, new ArrayList<>(this.visualization.getVisualTransactions()));
    } else {
        // support multi layer visuals i.e. water
        blockTransactions.addAll(this.visualization.getVisualTransactions());
        // cancel existing task
        final Task task = this.playerData.claimVisualRevertTasks.get(visualUniqueId);
        if (task != null) {
            task.cancel();
            this.playerData.claimVisualRevertTasks.remove(visualUniqueId);
        }
    }

    int seconds = (this.playerData.lastShovelLocation != null && this.visualization.getClaim() == null ? GriefDefenderPlugin.getGlobalConfig().getConfig().visual.createBlockVisualTime : GriefDefenderPlugin.getGlobalConfig().getConfig().visual.claimVisualTime);
    if (seconds <= 0) {
        seconds = this.playerData.lastShovelLocation == null ? 60 : 180;
    }
    final ClaimVisualRevertTask runnable = new ClaimVisualRevertTask(visualUniqueId, this.player, this.playerData);
    if (this.playerData.lastShovelLocation != null && this.visualization.getClaim() == null) {
        this.playerData.createBlockVisualTransactions.put(visualUniqueId, new ArrayList<>(this.visualization.getVisualTransactions()));
        this.playerData.createBlockVisualRevertRunnables.put(visualUniqueId, runnable);
    }
    this.playerData.claimVisualRevertTasks.put(visualUniqueId, Sponge.getGame().getScheduler().createTaskBuilder().delay(seconds, TimeUnit.SECONDS)
            .execute(runnable).submit(GDBootstrap.getInstance()));
}