feat: exec with velocity
This commit is contained in:
parent
e9824aa78c
commit
43cdd95a33
|
@ -42,6 +42,7 @@ public class Camera extends JavaPlugin implements Listener {
|
||||||
this.getCommand("close").setExecutor(new ClosePath());
|
this.getCommand("close").setExecutor(new ClosePath());
|
||||||
this.getCommand("load").setExecutor(new LoadPath());
|
this.getCommand("load").setExecutor(new LoadPath());
|
||||||
this.getCommand("save").setExecutor(new SavePath());
|
this.getCommand("save").setExecutor(new SavePath());
|
||||||
|
this.getCommand("move").setExecutor(new Move());
|
||||||
|
|
||||||
// Eventhandlers
|
// Eventhandlers
|
||||||
getServer().getPluginManager().registerEvents(this, this);
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
|
|
@ -5,28 +5,34 @@ import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
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.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class ExecuteTraveling implements CommandExecutor {
|
public class ExecuteTraveling implements CommandExecutor {
|
||||||
|
|
||||||
private static int taskID = -1;
|
private static int taskID = -1;
|
||||||
private static Iterator<ExtendedLocation> curveIterator;
|
private static Iterator<ExtendedLocation> curveIterator;
|
||||||
|
private static boolean useVelocity = false;
|
||||||
|
|
||||||
@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) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
int fromIndex, toIndex;
|
int fromIndex = 0;
|
||||||
|
int toIndex = (Camera.controlPoints.size() - 1) / 3;
|
||||||
|
useVelocity = false;
|
||||||
|
if (args.length > 0) {
|
||||||
|
// Use moveTo intead of teleport
|
||||||
|
useVelocity = Boolean.parseBoolean(args[0]);
|
||||||
|
|
||||||
|
// Get starting and ending points
|
||||||
|
int ind = useVelocity ? 1 : 0;
|
||||||
try {
|
try {
|
||||||
fromIndex = Integer.parseInt(args[0]);
|
fromIndex = Integer.parseInt(args[ind]);
|
||||||
|
toIndex = Integer.parseInt(args[ind + 1]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fromIndex = 0;
|
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
toIndex = Integer.parseInt(args[1]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
toIndex = (Camera.controlPoints.size() - 1) / 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taskID >= 0) {
|
if (taskID >= 0) {
|
||||||
|
@ -39,14 +45,17 @@ public class ExecuteTraveling implements CommandExecutor {
|
||||||
|
|
||||||
curveIterator = Camera.curve.subList(fromIndex * (Camera.nbSubdiv + 1), toIndex * (Camera.nbSubdiv + 1))
|
curveIterator = Camera.curve.subList(fromIndex * (Camera.nbSubdiv + 1), toIndex * (Camera.nbSubdiv + 1))
|
||||||
.iterator();
|
.iterator();
|
||||||
|
player.teleport(curveIterator.next());
|
||||||
|
|
||||||
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Camera.plugin, new Runnable() {
|
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Camera.plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Teleport to next point
|
// Teleport to next point
|
||||||
if (curveIterator.hasNext()) {
|
if (curveIterator.hasNext()) {
|
||||||
ExtendedLocation loc = curveIterator.next();
|
if (useVelocity)
|
||||||
player.teleport(loc);
|
Move.moveTo(player, curveIterator.next());
|
||||||
|
else
|
||||||
|
player.teleport(curveIterator.next());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
74
src/main/java/com/tocard/cam/Move.java
Normal file
74
src/main/java/com/tocard/cam/Move.java
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
package com.tocard.cam;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class Move implements CommandExecutor {
|
||||||
|
|
||||||
|
public static int taskID = -1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
if (taskID >= 0) {
|
||||||
|
// Cancel show task
|
||||||
|
Bukkit.getScheduler().cancelTask(taskID);
|
||||||
|
taskID = -1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
double x = Float.parseFloat(args[0]);
|
||||||
|
double y = Float.parseFloat(args[1]);
|
||||||
|
double z = Float.parseFloat(args[2]);
|
||||||
|
|
||||||
|
// Start showing curve
|
||||||
|
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Camera.plugin,
|
||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
moveTo(player, x, y, z);
|
||||||
|
}
|
||||||
|
}, 0, 0);
|
||||||
|
|
||||||
|
// Broadcast TaskID
|
||||||
|
Bukkit.broadcastMessage("Show curve : " + taskID);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void moveTo(Player player, double x, double y, double z) {
|
||||||
|
Location delta = player.getLocation();
|
||||||
|
double dx = x - delta.getX();
|
||||||
|
double dy = y - delta.getY();
|
||||||
|
double dz = z - delta.getZ();
|
||||||
|
|
||||||
|
player.setVelocity(new Vector(dx, dy, dz).multiply(0.1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void moveTo(Player player, Location location) {
|
||||||
|
// rotateTo(player, location);
|
||||||
|
Location delta = location.clone().subtract(player.getLocation());
|
||||||
|
player.setVelocity(delta.toVector().multiply(0.1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void rotateTo(Player player, Location location) {
|
||||||
|
Location playerLocation = player.getLocation();
|
||||||
|
playerLocation.setYaw(location.getYaw());
|
||||||
|
playerLocation.setPitch(location.getPitch());
|
||||||
|
player.teleport(playerLocation);
|
||||||
|
Camera.broadlog(Camera.prettyLocation(playerLocation));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -37,3 +37,7 @@ commands:
|
||||||
description: Save current path
|
description: Save current path
|
||||||
usage: /save
|
usage: /save
|
||||||
permission: com.tocard.cam.savePath
|
permission: com.tocard.cam.savePath
|
||||||
|
move:
|
||||||
|
description: Move player to x y z
|
||||||
|
usage: /move
|
||||||
|
permission: com.tocard.cam.move
|
||||||
|
|
Loading…
Reference in a new issue