Skip to content

Commit

Permalink
cancel the task
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed Jul 9, 2017
1 parent c0b7a7a commit 1bbb080
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Plugin/src/main/java/cz/neumimto/rpg/gui/VanilaMessaging.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import org.spongepowered.api.Game;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.ArmorEquipable;
import org.spongepowered.api.entity.living.monster.ZombiePigman;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.cause.Cause;
Expand Down
12 changes: 0 additions & 12 deletions Skills/src/main/java/cz/neumimto/SkillListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,4 @@ public void onBlockInteract(InteractBlockEvent event, @First(typeFilter = Player
}
}

@Listener
public void onArrowFire(LaunchProjectileEvent event, @First(typeFilter = Entity.class) Entity e ){

Decorator.createTrajectory(
event.getTargetEntity(),
1,
1,
new ParticleDecorator.SIMPLE_TRAJECTORY(
ParticleEffect.builder()
.quantity(5).type(ParticleTypes.AMBIENT_MOB_SPELL).build()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ public void strikeLightning(Location<World> location) {

@Override
public void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer<Task, Entity> e) {
Sponge.getScheduler()
Task submit = Sponge.getScheduler()
.createTaskBuilder()
.delay(1L, TimeUnit.MILLISECONDS)
.interval(interval, TimeUnit.MILLISECONDS)
.execute((task -> {
if (!entity.isRemoved()) {
e.accept(task, entity);
}
})).submit(plugin);
if (!entity.isRemoved()) {
e.accept(task, entity);
} else {
task.cancel();
}
})).submit(plugin);
}

public static class SIMPLE_TRAJECTORY implements BiConsumer<Task, Entity> {
Expand Down

0 comments on commit 1bbb080

Please sign in to comment.