feat: load save
This commit is contained in:
parent
e848a242e7
commit
1638d4be32
|
@ -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);
|
||||
|
|
51
src/main/java/com/tocard/cam/LoadPath.java
Normal file
51
src/main/java/com/tocard/cam/LoadPath.java
Normal file
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
36
src/main/java/com/tocard/cam/SavePath.java
Normal file
36
src/main/java/com/tocard/cam/SavePath.java
Normal file
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue