feat: stay C1 (/point set fully op)

This commit is contained in:
gdamms 2022-05-14 17:41:44 +02:00
parent efc83b6dfa
commit 929cdc5967
2 changed files with 65 additions and 29 deletions

View file

@ -102,9 +102,9 @@ public class NewPoint implements CommandExecutor {
if (n <= 4) { if (n <= 4) {
setPoint(index, location, world); setPoint(index, location, world);
} else { } else {
if (index % 3 == 0) { switch (index % 3) {
// Anchor control point case 0:
location = player.getLocation(); // Anchor point
Location shift = location.clone().subtract(Camera.controlPoints.get(index)); Location shift = location.clone().subtract(Camera.controlPoints.get(index));
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
try { try {
@ -113,7 +113,45 @@ public class NewPoint implements CommandExecutor {
// First or last anchor // First or last anchor
} }
} }
} else { break;
case 1:
// Control point after an anchor
if (index - 2 >= 0) {
// Get anchor-location direction
Location anchor = Camera.controlPoints.get(index - 1);
double currentDistance = anchor.distance(location);
Location currentVect = anchor.clone().subtract(location).multiply(1 / currentDistance);
// Get anchor-corresponding distance
Location correspondingControl = Camera.controlPoints.get(index - 2);
double correspondingDistance = anchor.distance(correspondingControl);
// Keep correcponding at the same distance
// but along the anchor-location direction
setPoint(index - 2, anchor.clone().add(currentVect.multiply(correspondingDistance)), world);
}
// Move control point
setPoint(index, location, world);
break;
case 2:
// Control point before an anchor
if (index + 2 < n) {
// Get anchor-location direction
Location anchor = Camera.controlPoints.get(index + 1);
double currentDistance = anchor.distance(location);
Location currentVect = anchor.clone().subtract(location).multiply(1 / currentDistance);
// Get anchor-corresponding distance
Location correspondingControl = Camera.controlPoints.get(index + 2);
double correspondingDistance = anchor.distance(correspondingControl);
// Keep correcponding at the same distance
// but along the anchor-location direction
setPoint(index + 2, anchor.clone().add(currentVect.multiply(correspondingDistance)), world);
}
// Move control point
setPoint(index, location, world);
break;
} }
} }

View file

@ -23,23 +23,10 @@ import org.bukkit.Material;
public class ShowCurve implements CommandExecutor { public class ShowCurve implements CommandExecutor {
public static List<ArmorStand> controlPointsArmorStands = new ArrayList<>(); public static List<ArmorStand> controlPointsArmorStands = new ArrayList<>();
private static ItemStack cameraHead = initCameraHead(); private static ItemStack cameraHeadAnchor = new ItemStack(Material.OBSERVER);
private static ItemStack cameraHeadControl = new ItemStack(Material.DISPENSER);
public static int showTaskID = -1; 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.OBSERVER);
return cameraHead;
}
// c9560dfb-a792-4226-ad06-db1b6dc40b95
// c9560dfba7924226ad06db1b6dc40b95
// This method is called, when somebody uses our command // This method is called, when somebody uses our command
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -52,8 +39,13 @@ public class ShowCurve implements CommandExecutor {
if (ShowCurve.showTaskID < 0) { if (ShowCurve.showTaskID < 0) {
// Show control points // Show control points
int i = 0;
for (ArmorStand as : controlPointsArmorStands) { for (ArmorStand as : controlPointsArmorStands) {
as.getEquipment().setHelmet(cameraHead); if (i % 3 == 0)
as.getEquipment().setHelmet(cameraHeadAnchor);
else
as.getEquipment().setHelmet(cameraHeadControl);
i++;
} }
// Start showing curve // Start showing curve
@ -98,7 +90,10 @@ public class ShowCurve implements CommandExecutor {
as.setMarker(true); as.setMarker(true);
as.addScoreboardTag("controlPoint"); as.addScoreboardTag("controlPoint");
if (showTaskID > 0) if (showTaskID > 0)
as.getEquipment().setHelmet(cameraHead); if ((Camera.controlPoints.size() - 1) % 3 == 0)
as.getEquipment().setHelmet(cameraHeadAnchor);
else
as.getEquipment().setHelmet(cameraHeadControl);
controlPointsArmorStands.add(as); controlPointsArmorStands.add(as);
} }
@ -109,7 +104,10 @@ public class ShowCurve implements CommandExecutor {
as.setMarker(true); as.setMarker(true);
as.addScoreboardTag("controlPoint"); as.addScoreboardTag("controlPoint");
if (showTaskID > 0) if (showTaskID > 0)
as.getEquipment().setHelmet(cameraHead); if ((Camera.controlPoints.size() - 1) % 3 == 0)
as.getEquipment().setHelmet(cameraHeadAnchor);
else
as.getEquipment().setHelmet(cameraHeadControl);
controlPointsArmorStands.add(index, as); controlPointsArmorStands.add(index, as);
} }