Last active
November 28, 2015 05:31
-
-
Save SocraticPhoenix/074d7e9c81788e51ea38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gmail.socraticphoenix.teamfight.weapon.ability; | |
import com.flowpowered.math.vector.Vector3d; | |
import com.gmail.socraticphoenix.sponge.star.scheduler.SpongeRunnable; | |
import java.util.Collection; | |
import org.spongepowered.api.data.key.Keys; | |
import org.spongepowered.api.entity.Entity; | |
import org.spongepowered.api.entity.Item; | |
import org.spongepowered.api.entity.living.player.Player; | |
import org.spongepowered.api.world.Location; | |
import org.spongepowered.api.world.World; | |
public class ShieldMaintainer extends SpongeRunnable { | |
private Player shielded; | |
private long times; | |
private int radius; | |
public ShieldMaintainer(Player shielded, long times, int radius) { | |
this.shielded = shielded; | |
this.times = times; | |
this.radius = radius; | |
} | |
@Override | |
public void run() { | |
if(this.times >= 0) { | |
Vector3d playerVec = this.shielded.getLocation().getPosition(); | |
this.getNearbyEntities(this.shielded.getLocation(), this.radius).stream().filter(entity -> !(entity instanceof Item) && !(entity instanceof Player)).forEach(entity -> { | |
System.out.println(entity); //Prints once for each entity near me when the scheduler is activated, only on one iteration | |
entity.offer(Keys.VELOCITY, entity.getLocation().getPosition().sub(playerVec).mul(0.1, 0, 0.1)); | |
}); | |
} else { | |
System.out.println("cancelled"); //Never printed | |
this.cancel(); | |
} | |
System.out.println(times); //Output was '200' | |
this.times = this.times - 1; | |
} | |
private Collection<Entity> getNearbyEntities(Location<World> location, int radius) { | |
return location.getExtent().getEntities(entity -> location.getPosition().distance(entity.getLocation().getPosition()) <= radius); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment