From 64a12b2dd7e7f462cdf5470ff7e150b393b754dd Mon Sep 17 00:00:00 2001 From: gdamms Date: Fri, 13 May 2022 20:56:06 +0200 Subject: [PATCH] feat: ca marche --- src/main/java/com/tocard/cam/Camera.java | 4 +-- src/main/java/com/tocard/cam/Test.java | 39 +++++++++++++++--------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/tocard/cam/Camera.java b/src/main/java/com/tocard/cam/Camera.java index 71c61d6..eeff79e 100644 --- a/src/main/java/com/tocard/cam/Camera.java +++ b/src/main/java/com/tocard/cam/Camera.java @@ -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 locations; public static Logger logger; - public static Camera plugin; - public static float t; + public static Plugin plugin; @Override public void onEnable() { diff --git a/src/main/java/com/tocard/cam/Test.java b/src/main/java/com/tocard/cam/Test.java index 26c36ef..8452630 100644 --- a/src/main/java/com/tocard/cam/Test.java +++ b/src/main/java/com/tocard/cam/Test.java @@ -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 bezier = new ArrayList<>(); - int taskID = Bukkit.getScheduler().scheduleSyncDelayedTask(Camera.plugin, new Runnable() { + for (float t = 0; t < 1; t += 0.1) { + ArrayList 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 bezierIt = bezier.iterator(); + + int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Camera.plugin, new Runnable() { @Override public void run() { - ArrayList 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))); - } + try { + player.teleport(bezierIt.next()); + } catch (Exception e) { + Thread.currentThread().interrupt(); } - - player.teleport(P.get(0)); - - Camera.t += 0.01; - Camera.t %= 1; } }, 0, 0); Bukkit.broadcastMessage("" + taskID);