feat: ca marche

This commit is contained in:
gdamms 2022-05-13 20:56:06 +02:00
parent c849f9d12c
commit 64a12b2dd7
2 changed files with 27 additions and 16 deletions

View file

@ -5,14 +5,14 @@ import java.util.List;
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class Camera extends JavaPlugin {
public static List<Location> locations;
public static Logger logger;
public static Camera plugin;
public static float t;
public static Plugin plugin;
@Override
public void onEnable() {

View file

@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.Iterator;
public class Test implements CommandExecutor {
@ -22,24 +23,34 @@ public class Test implements CommandExecutor {
} catch (Exception e) {
Player player = (Player) sender;
Camera.t = 0;
ArrayList<Location> bezier = new ArrayList<>();
int taskID = Bukkit.getScheduler().scheduleSyncDelayedTask(Camera.plugin, new Runnable() {
@Override
public void run() {
for (float t = 0; t < 1; t += 0.1) {
ArrayList<Location> P = new ArrayList<>(Camera.locations);
int N = P.size();
for (int k = N - 1; k > 0; k--) {
for (int i = 0; i < k; i++) {
P.set(i, P.get(i).multiply(1 - Camera.t).add(P.get(i + 1).multiply(Camera.t)));
P.set(i, P.get(i).clone().multiply(1 - t)
.add(P.get(i + 1).clone().multiply(t)));
}
}
player.teleport(P.get(0));
bezier.add(P.get(0));
Camera.t += 0.01;
Camera.t %= 1;
t += 0.01;
}
Iterator<Location> bezierIt = bezier.iterator();
int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Camera.plugin, new Runnable() {
@Override
public void run() {
try {
player.teleport(bezierIt.next());
} catch (Exception e) {
Thread.currentThread().interrupt();
}
}
}, 0, 0);
Bukkit.broadcastMessage("" + taskID);