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 java.util.logging.Logger;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class Camera extends JavaPlugin { public class Camera extends JavaPlugin {
public static List<Location> locations; public static List<Location> locations;
public static Logger logger; public static Logger logger;
public static Camera plugin; public static Plugin plugin;
public static float t;
@Override @Override
public void onEnable() { public void onEnable() {

View file

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