diff --git a/src/main/java/com/tocard/cam/Camera.java b/src/main/java/com/tocard/cam/Camera.java index ea0a727..3c84094 100644 --- a/src/main/java/com/tocard/cam/Camera.java +++ b/src/main/java/com/tocard/cam/Camera.java @@ -40,6 +40,8 @@ public class Camera extends JavaPlugin implements Listener { this.getCommand("exec").setExecutor(new ExecuteTraveling()); this.getCommand("show").setExecutor(new ShowCurve()); this.getCommand("close").setExecutor(new ClosePath()); + this.getCommand("load").setExecutor(new LoadPath()); + this.getCommand("save").setExecutor(new SavePath()); // Eventhandlers getServer().getPluginManager().registerEvents(this, this); diff --git a/src/main/java/com/tocard/cam/LoadPath.java b/src/main/java/com/tocard/cam/LoadPath.java new file mode 100644 index 0000000..7779737 --- /dev/null +++ b/src/main/java/com/tocard/cam/LoadPath.java @@ -0,0 +1,51 @@ +package com.tocard.cam; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class LoadPath implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + load(args[0]); + } + return true; + } + + public static void load(String file) { + ClearPoints.clear(); + World world = Bukkit.getWorlds().get(0); + + BufferedReader reader; + try { + reader = new BufferedReader(new FileReader("plugins/tocard-cam/paths/" + file)); + String line = reader.readLine(); + while (line != null) { + String[] coords = line.split(","); + ExtendedLocation location = new ExtendedLocation( + new Location(world, + Float.parseFloat(coords[0]), Float.parseFloat(coords[1]), Float.parseFloat(coords[2]), + Float.parseFloat(coords[3]), Float.parseFloat(coords[4]))); + NewPoint.addPoint(location, world); + + line = reader.readLine(); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + Camera.compute(); + } + +} diff --git a/src/main/java/com/tocard/cam/SavePath.java b/src/main/java/com/tocard/cam/SavePath.java new file mode 100644 index 0000000..de6f5e0 --- /dev/null +++ b/src/main/java/com/tocard/cam/SavePath.java @@ -0,0 +1,36 @@ +package com.tocard.cam; + +import java.io.IOException; +import java.io.PrintWriter; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class SavePath implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + save(args[0]); + } + return true; + } + + public static void save(String file) { + try { + PrintWriter writer = new PrintWriter("plugins/tocard-cam/paths/" + file, "UTF-8"); + for (Location loc : Camera.controlPoints) { + writer.println( + loc.getX() + "," + loc.getY() + "," + loc.getZ() + + "," + loc.getYaw() + "," + loc.getPitch()); + } + writer.close(); + } catch (IOException e) { + // do something + } + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5e66a71..f9eb614 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -29,3 +29,11 @@ commands: description: Close path usage: /close permission: com.tocard.cam.closeMath + load: + description: Load a path + usage: /load + permission: com.tocard.cam.loadPath + save: + description: Save current path + usage: /save + permission: com.tocard.cam.savePath