diff --git a/src/main/java/com/tocard/cam/NewPoint.java b/src/main/java/com/tocard/cam/NewPoint.java index 40265ff..6687f65 100644 --- a/src/main/java/com/tocard/cam/NewPoint.java +++ b/src/main/java/com/tocard/cam/NewPoint.java @@ -48,19 +48,24 @@ public class NewPoint implements CommandExecutor { public static void addPoint(Location point, World world) { Camera.controlPoints.add(point); - Camera.broadlog("Point added: " + Camera.prettyLocation(point)); ShowCurve.add(point, world); + Camera.broadlog("Point added: " + Camera.prettyLocation(point)); + } + + public static void setPoint(int index, Location point, World world) { + Camera.controlPoints.set(index, point); + ShowCurve.set(index, point, world); + Camera.broadlog("Point n°" + index + " set: " + Camera.prettyLocation(point)); } public static void add(String[] args) { World world = player.getWorld(); location = player.getLocation(); + int n = Camera.controlPoints.size(); - if (Camera.controlPoints.size() < 4) { + if (n < 4) { addPoint(location, world); } else { - int n = Camera.controlPoints.size(); - Location P2 = Camera.controlPoints.get(n - 2); Location P3 = Camera.controlPoints.get(n - 1); Location P4 = P3.clone().multiply(2).subtract(P2); @@ -89,10 +94,28 @@ public class NewPoint implements CommandExecutor { } public static void set(String[] args) { + World world = player.getWorld(); + int n = Camera.controlPoints.size(); index = Integer.parseInt(args[1]); location = player.getLocation(); - Camera.controlPoints.set(index, location); - Camera.broadlog("Point n°" + index + " set: " + Camera.prettyLocation(location)); - ShowCurve.set(index, location, player.getWorld()); + + if (n <= 4) { + setPoint(index, location, world); + } else { + if (index % 3 == 0) { + // Anchor control point + location = player.getLocation(); + Location shift = location.clone().subtract(Camera.controlPoints.get(index)); + for (int i = 0; i < 3; i++) { + try { + setPoint(index + i - 1, Camera.controlPoints.get(index + i - 1).clone().add(shift), world); + } catch (IndexOutOfBoundsException e) { + // First or last anchor + } + } + } else { + + } + } } } diff --git a/src/main/java/com/tocard/cam/ShowCurve.java b/src/main/java/com/tocard/cam/ShowCurve.java index 5997049..da08927 100644 --- a/src/main/java/com/tocard/cam/ShowCurve.java +++ b/src/main/java/com/tocard/cam/ShowCurve.java @@ -27,12 +27,13 @@ public class ShowCurve implements CommandExecutor { public static int showTaskID = -1; private static ItemStack initCameraHead() { - ItemStack cameraHead = new ItemStack(Material.PLAYER_HEAD); - SkullMeta skullMeta = (SkullMeta) cameraHead.getItemMeta(); - skullMeta.setOwningPlayer( - Bukkit.getOfflinePlayer( - UUID.fromString("c9560dfb-a792-4226-ad06-db1b6dc40b95"))); - cameraHead.setItemMeta(skullMeta); + // ItemStack cameraHead = new ItemStack(Material.PLAYER_HEAD); + // SkullMeta skullMeta = (SkullMeta) cameraHead.getItemMeta(); + // skullMeta.setOwningPlayer( + // Bukkit.getOfflinePlayer( + // UUID.fromString("c9560dfb-a792-4226-ad06-db1b6dc40b95"))); + // cameraHead.setItemMeta(skullMeta); + ItemStack cameraHead = new ItemStack(Material.OBSERVER); return cameraHead; } @@ -113,14 +114,7 @@ public class ShowCurve implements CommandExecutor { } public static void set(int index, Location point, World world) { - ArmorStand as = world.spawn(point, ArmorStand.class); - as.setGravity(false); - as.setVisible(false); - as.setMarker(true); - as.addScoreboardTag("controlPoint"); - if (showTaskID > 0) - as.getEquipment().setHelmet(cameraHead); - controlPointsArmorStands.set(index, as).remove(); + controlPointsArmorStands.get(index).teleport(point); } public static void rm(int index) {