2021-05-24 18:39:16 +02:00
|
|
|
package de.jeff_media.bettertridents.tasks;
|
2021-05-24 13:46:25 +02:00
|
|
|
|
2021-05-24 18:39:16 +02:00
|
|
|
import de.jeff_media.bettertridents.Main;
|
2021-05-24 13:46:25 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.entity.Trident;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
|
|
|
public class WatchTrident extends BukkitRunnable {
|
|
|
|
|
|
|
|
private static final int MAX_TICKS = 1200;
|
|
|
|
private final Trident trident;
|
|
|
|
private int ticks = 0;
|
|
|
|
|
|
|
|
public WatchTrident(Trident trident) {
|
|
|
|
this.trident = trident;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
ticks++;
|
|
|
|
if(ticks >= MAX_TICKS || trident == null || trident.isDead() || !trident.isValid() || trident.getVelocity().length() == 0) {
|
|
|
|
cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Location nextLocation = trident.getLocation().add(trident.getVelocity());
|
|
|
|
|
|
|
|
if(nextLocation.getBlockY() > 1) return;
|
|
|
|
if(!nextLocation.getBlock().getType().isAir()) return;
|
|
|
|
|
|
|
|
if(nextLocation.getBlockY() < 0) {
|
|
|
|
nextLocation.setY(0);
|
|
|
|
trident.teleport(nextLocation.clone().add(0,1,0));
|
|
|
|
trident.setVelocity(new Vector(0,-1,0));
|
|
|
|
}
|
|
|
|
|
|
|
|
nextLocation.getBlock().setType(Main.SAFETY_MATERIAL);
|
2021-05-24 18:39:16 +02:00
|
|
|
Main.getInstance().debug("New Task: RemoveBarrier");
|
2021-05-24 13:46:25 +02:00
|
|
|
new RemoveBarrier(trident, nextLocation.getBlock()).runTaskTimer(Main.getInstance(), 1, 1);
|
|
|
|
cancel();
|
|
|
|
}
|
|
|
|
}
|