feat: /close
This commit is contained in:
parent
1aa618865c
commit
e5a28d45a3
|
@ -40,6 +40,7 @@ public class Camera extends JavaPlugin implements Listener {
|
||||||
this.getCommand("reset").setExecutor(new ClearPoints());
|
this.getCommand("reset").setExecutor(new ClearPoints());
|
||||||
this.getCommand("exec").setExecutor(new ExecuteTraveling());
|
this.getCommand("exec").setExecutor(new ExecuteTraveling());
|
||||||
this.getCommand("show").setExecutor(new ShowCurve());
|
this.getCommand("show").setExecutor(new ShowCurve());
|
||||||
|
this.getCommand("close").setExecutor(new ClosePath());
|
||||||
|
|
||||||
// Eventhandlers
|
// Eventhandlers
|
||||||
getServer().getPluginManager().registerEvents(this, this);
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
|
|
@ -26,6 +26,7 @@ public class ClearPoints implements CommandExecutor {
|
||||||
|
|
||||||
Camera.controlPoints = new ArrayList<>();
|
Camera.controlPoints = new ArrayList<>();
|
||||||
Camera.compute();
|
Camera.compute();
|
||||||
|
ClosePath.closed = false;
|
||||||
Camera.broadlog("All cleared !");
|
Camera.broadlog("All cleared !");
|
||||||
|
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
|
40
src/main/java/com/tocard/cam/ClosePath.java
Normal file
40
src/main/java/com/tocard/cam/ClosePath.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package com.tocard.cam;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class ClosePath implements CommandExecutor {
|
||||||
|
|
||||||
|
public static boolean closed = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
if (!closed && Camera.controlPoints.size() >= 4) {
|
||||||
|
closed = true;
|
||||||
|
NewPoint.add(null, Camera.controlPoints.get(0), player.getWorld());
|
||||||
|
NewPoint.set(new String[] { "", "" + (Camera.controlPoints.size() - 2) },
|
||||||
|
Camera.controlPoints.get(0).clone().multiply(2)
|
||||||
|
.subtract(Camera.controlPoints.get(1)),
|
||||||
|
player.getWorld());
|
||||||
|
} else if (closed) {
|
||||||
|
closed = false;
|
||||||
|
NewPoint.rm(new String[] { "", "" + (Camera.controlPoints.size() - 1) }, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera.compute();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,31 +10,46 @@ import java.util.Iterator;
|
||||||
|
|
||||||
public class ExecuteTraveling implements CommandExecutor {
|
public class ExecuteTraveling implements CommandExecutor {
|
||||||
|
|
||||||
|
private static int taskID = -1;
|
||||||
|
private static Iterator<Location> curveIterator;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
try {
|
Player player = (Player) sender;
|
||||||
Bukkit.getScheduler().cancelTask(Integer.parseInt(args[0]));
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
if (taskID >= 0) {
|
||||||
Player player = (Player) sender;
|
// Cancel show task
|
||||||
|
Bukkit.getScheduler().cancelTask(taskID);
|
||||||
|
taskID = -1;
|
||||||
|
|
||||||
Iterator<Location> curveIterator = Camera.curve.iterator();
|
return true;
|
||||||
|
|
||||||
int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Camera.plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
player.teleport(curveIterator.next());
|
|
||||||
} catch (Exception e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0, 0);
|
|
||||||
Bukkit.broadcastMessage("" + taskID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
curveIterator = Camera.curve.iterator();
|
||||||
|
|
||||||
|
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Camera.plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// Teleport to next point
|
||||||
|
if (curveIterator.hasNext()) {
|
||||||
|
player.teleport(curveIterator.next());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No more point, end traveling
|
||||||
|
if (!ClosePath.closed) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regenerate traveling and begin
|
||||||
|
curveIterator = Camera.curve.iterator();
|
||||||
|
player.teleport(curveIterator.next());
|
||||||
|
}
|
||||||
|
}, 0, 0);
|
||||||
|
Bukkit.broadcastMessage("Traveling : " + taskID);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,24 +9,20 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class NewPoint implements CommandExecutor {
|
public class NewPoint implements CommandExecutor {
|
||||||
|
|
||||||
private static Location location;
|
|
||||||
private static Player player;
|
|
||||||
private static int index;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
try {
|
try {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "add":
|
case "add":
|
||||||
add(args);
|
add(args, player.getLocation(), player.getWorld());
|
||||||
break;
|
break;
|
||||||
case "rm":
|
case "rm":
|
||||||
rm(args);
|
rm(args, player.getLocation(), player.getWorld());
|
||||||
break;
|
break;
|
||||||
case "set":
|
case "set":
|
||||||
set(args);
|
set(args, player.getLocation(), player.getWorld());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -55,14 +51,12 @@ public class NewPoint implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rmPoint(int index) {
|
public static void rmPoint(int index) {
|
||||||
location = Camera.controlPoints.remove(index);
|
Location location = Camera.controlPoints.remove(index);
|
||||||
ShowCurve.rm(index);
|
ShowCurve.rm(index);
|
||||||
Camera.broadlog("Point deleted: " + Camera.prettyLocation(location));
|
Camera.broadlog("Point deleted: " + Camera.prettyLocation(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void add(String[] args) {
|
public static void add(String[] args, Location location, World world) {
|
||||||
World world = player.getWorld();
|
|
||||||
location = player.getLocation();
|
|
||||||
int n = Camera.controlPoints.size();
|
int n = Camera.controlPoints.size();
|
||||||
|
|
||||||
if (n < 4) {
|
if (n < 4) {
|
||||||
|
@ -80,16 +74,15 @@ public class NewPoint implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void ins(String[] args) {
|
public static void ins(String[] args, Location location, World world) {
|
||||||
index = Integer.parseInt(args[1]);
|
int index = Integer.parseInt(args[1]);
|
||||||
location = player.getLocation();
|
|
||||||
Camera.controlPoints.add(index, location);
|
Camera.controlPoints.add(index, location);
|
||||||
Camera.broadlog("Point added: " + Camera.prettyLocation(location));
|
Camera.broadlog("Point added: " + Camera.prettyLocation(location));
|
||||||
ShowCurve.insert(index, location, player.getWorld());
|
ShowCurve.insert(index, location, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rm(String[] args) {
|
public static void rm(String[] args, Location location, World world) {
|
||||||
index = Integer.parseInt(args[1]);
|
int index = Integer.parseInt(args[1]);
|
||||||
int n = Camera.controlPoints.size();
|
int n = Camera.controlPoints.size();
|
||||||
|
|
||||||
if (n <= 4) {
|
if (n <= 4) {
|
||||||
|
@ -109,13 +102,13 @@ public class NewPoint implements CommandExecutor {
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
rmPoint(indMin);
|
rmPoint(indMin);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void set(String[] args) {
|
public static void set(String[] args, Location location, World world) {
|
||||||
World world = player.getWorld();
|
|
||||||
int n = Camera.controlPoints.size();
|
int n = Camera.controlPoints.size();
|
||||||
index = Integer.parseInt(args[1]);
|
int index = Integer.parseInt(args[1]);
|
||||||
location = player.getLocation();
|
|
||||||
|
|
||||||
if (n <= 4) {
|
if (n <= 4) {
|
||||||
setPoint(index, location, world);
|
setPoint(index, location, world);
|
||||||
|
|
|
@ -22,80 +22,77 @@ public class ShowCurve implements CommandExecutor {
|
||||||
public static List<ArmorStand> controlPointsArmorStands = new ArrayList<>();
|
public static List<ArmorStand> controlPointsArmorStands = new ArrayList<>();
|
||||||
private static ItemStack cameraHeadAnchor = new ItemStack(Material.OBSERVER);
|
private static ItemStack cameraHeadAnchor = new ItemStack(Material.OBSERVER);
|
||||||
private static ItemStack cameraHeadControl = new ItemStack(Material.DISPENSER);
|
private static ItemStack cameraHeadControl = new ItemStack(Material.DISPENSER);
|
||||||
public static int showTaskID = -1;
|
private static int taskID = -1;
|
||||||
|
|
||||||
// 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) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
try {
|
Player player = (Player) sender;
|
||||||
Bukkit.getScheduler().cancelTask(Integer.parseInt(args[0]));
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
if (taskID >= 0) {
|
||||||
Player player = (Player) sender;
|
// Cancel show task
|
||||||
|
Bukkit.getScheduler().cancelTask(taskID);
|
||||||
|
taskID = -1;
|
||||||
|
|
||||||
if (ShowCurve.showTaskID < 0) {
|
// Kill control points' armorstand
|
||||||
// Show control points
|
for (ArmorStand as : controlPointsArmorStands) {
|
||||||
int i = 0;
|
as.getEquipment().setHelmet(new ItemStack(Material.AIR));
|
||||||
for (ArmorStand as : controlPointsArmorStands) {
|
}
|
||||||
if (i % 3 == 0)
|
return true;
|
||||||
as.getEquipment().setHelmet(cameraHeadAnchor);
|
}
|
||||||
else
|
|
||||||
as.getEquipment().setHelmet(cameraHeadControl);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start showing curve
|
// Show control points
|
||||||
ShowCurve.showTaskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Camera.plugin,
|
int i = 0;
|
||||||
new Runnable() {
|
for (ArmorStand as : controlPointsArmorStands) {
|
||||||
@Override
|
if (i % 3 == 0)
|
||||||
public void run() {
|
as.getEquipment().setHelmet(cameraHeadAnchor);
|
||||||
// Get curve iterator
|
else
|
||||||
Iterator<Location> curveIterator = Camera.curve.iterator();
|
as.getEquipment().setHelmet(cameraHeadControl);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
// Draw path
|
// Start showing curve
|
||||||
while (curveIterator.hasNext()) {
|
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Camera.plugin,
|
||||||
player.getWorld().spawnParticle(Particle.ELECTRIC_SPARK,
|
new Runnable() {
|
||||||
curveIterator.next().clone().add(0, 1.8, 0), 1,
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// Get curve iterator
|
||||||
|
Iterator<Location> curveIterator = Camera.curve.iterator();
|
||||||
|
|
||||||
|
// Draw path
|
||||||
|
while (curveIterator.hasNext()) {
|
||||||
|
player.getWorld().spawnParticle(Particle.ELECTRIC_SPARK,
|
||||||
|
curveIterator.next().clone().add(0, 1.8, 0), 1,
|
||||||
|
0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw control lines
|
||||||
|
if (Camera.controlPoints.size() >= 4) {
|
||||||
|
int nAnchor = (Camera.controlPoints.size() - 1) / 3 + 1;
|
||||||
|
for (int i = 0; i < nAnchor; i++) {
|
||||||
|
int indMin = Math.max(3 * i - 1, 0);
|
||||||
|
int indMax = Math.min(3 * i + 1, Camera.controlPoints.size() - 1);
|
||||||
|
|
||||||
|
for (float t = 0; t < 1; t += 0.05) {
|
||||||
|
player.getWorld().spawnParticle(Particle.COMPOSTER,
|
||||||
|
Camera.controlPoints.get(indMin).clone().multiply(1 - t)
|
||||||
|
.add(Camera.controlPoints.get(indMax).clone()
|
||||||
|
.multiply(t))
|
||||||
|
.add(0, 1.8, 0),
|
||||||
|
1,
|
||||||
0, 0, 0, 0);
|
0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw control lines
|
|
||||||
if (Camera.controlPoints.size() >= 4) {
|
|
||||||
int nAnchor = (Camera.controlPoints.size() - 1) / 3 + 1;
|
|
||||||
for (int i = 0; i < nAnchor; i++) {
|
|
||||||
int indMin = Math.max(3 * i - 1, 0);
|
|
||||||
int indMax = Math.min(3 * i + 1, Camera.controlPoints.size() - 1);
|
|
||||||
|
|
||||||
for (float t = 0; t < 1; t += 0.05) {
|
|
||||||
player.getWorld().spawnParticle(Particle.COMPOSTER,
|
|
||||||
Camera.controlPoints.get(indMin).clone().multiply(1 - t)
|
|
||||||
.add(Camera.controlPoints.get(indMax).clone()
|
|
||||||
.multiply(t))
|
|
||||||
.add(0, 1.8, 0),
|
|
||||||
1,
|
|
||||||
0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 0, 0);
|
}
|
||||||
|
}
|
||||||
|
}, 0, 0);
|
||||||
|
|
||||||
// Broadcast TaskID
|
// Broadcast TaskID
|
||||||
Bukkit.broadcastMessage("Show curve : " + ShowCurve.showTaskID);
|
Bukkit.broadcastMessage("Show curve : " + taskID);
|
||||||
|
|
||||||
} else {
|
|
||||||
// Cancel show task
|
|
||||||
Bukkit.getScheduler().cancelTask(ShowCurve.showTaskID);
|
|
||||||
ShowCurve.showTaskID = -1;
|
|
||||||
|
|
||||||
// Kill control points' armorstand
|
|
||||||
for (ArmorStand as : controlPointsArmorStands) {
|
|
||||||
as.getEquipment().setHelmet(new ItemStack(Material.AIR));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +102,7 @@ public class ShowCurve implements CommandExecutor {
|
||||||
as.setVisible(false);
|
as.setVisible(false);
|
||||||
as.setMarker(true);
|
as.setMarker(true);
|
||||||
as.addScoreboardTag("controlPoint");
|
as.addScoreboardTag("controlPoint");
|
||||||
if (showTaskID > 0)
|
if (taskID > 0)
|
||||||
if ((Camera.controlPoints.size() - 1) % 3 == 0)
|
if ((Camera.controlPoints.size() - 1) % 3 == 0)
|
||||||
as.getEquipment().setHelmet(cameraHeadAnchor);
|
as.getEquipment().setHelmet(cameraHeadAnchor);
|
||||||
else
|
else
|
||||||
|
@ -119,7 +116,7 @@ public class ShowCurve implements CommandExecutor {
|
||||||
as.setVisible(false);
|
as.setVisible(false);
|
||||||
as.setMarker(true);
|
as.setMarker(true);
|
||||||
as.addScoreboardTag("controlPoint");
|
as.addScoreboardTag("controlPoint");
|
||||||
if (showTaskID > 0)
|
if (taskID > 0)
|
||||||
if ((Camera.controlPoints.size() - 1) % 3 == 0)
|
if ((Camera.controlPoints.size() - 1) % 3 == 0)
|
||||||
as.getEquipment().setHelmet(cameraHeadAnchor);
|
as.getEquipment().setHelmet(cameraHeadAnchor);
|
||||||
else
|
else
|
||||||
|
|
|
@ -24,4 +24,8 @@ commands:
|
||||||
show:
|
show:
|
||||||
description: Show the traveling path
|
description: Show the traveling path
|
||||||
usage: /show
|
usage: /show
|
||||||
permission: com.tocard.cam.showCurve
|
permission: com.tocard.cam.showPath
|
||||||
|
close:
|
||||||
|
description: Close path
|
||||||
|
usage: /close
|
||||||
|
permission: com.tocard.cam.closeMath
|
||||||
|
|
Loading…
Reference in a new issue