13
0

reworked some methods

Signed-off-by: yaruma3341 <yaruma3341@gmail.com>
Dieser Commit ist enthalten in:
Yaruma3341 2019-03-28 15:39:27 +01:00 committet von yaruma3341
Ursprung 9df919de52
Commit 3bc7057c59

Datei anzeigen

@ -1,7 +1,10 @@
package de.warking.schematicsystem.commands;
import com.boydti.fawe.FaweAPI;
import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.session.ClipboardHolder;
import de.warking.hunjy.MySQL.Schematic;
import de.warking.schematicsystem.SchematicSystem;
@ -16,6 +19,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
@ -50,7 +54,7 @@ public class SchematicCommand implements CommandExecutor {
if(args[0].equalsIgnoreCase("load")) {
if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) {
//load schematic to player clipboard
if(isSchematicNameAllowed(args[1])) {
try {
Actor actor = SchematicSystem.getWorldEditPlugin().wrapCommandSender(sender);
@ -61,6 +65,7 @@ public class SchematicCommand implements CommandExecutor {
}
break;
}
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cDie angegebene Schematic existiert nicht!");
break;
@ -69,13 +74,22 @@ public class SchematicCommand implements CommandExecutor {
if(args[0].equalsIgnoreCase("delete")) {
File file = new File(SchematicSystem.SCHEM_DIR + args[1] + ".schematic");
if(file.exists()) {
file.delete();
player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + "§7gelöscht.");
break;
} else {
player.sendMessage(SchematicSystem.PREFIX + "§cDiese Schematic existiert nicht!");
break;
}
}
if(args[0].equalsIgnoreCase("save")) {
//Save schematic
try {
File file = new File(SchematicSystem.SCHEM_DIR, args[1]);
ClipboardWriter writer = ClipboardFormat.findByFile(file).getWriter(new FileOutputStream(file));
writer.write(FaweAPI.wrapPlayer(player).getSession().getClipboard().getClipboard(), FaweAPI.wrapPlayer(player).getSession().getClipboard().getWorldData());
} catch (IOException ex) { } catch (EmptyClipboardException ex) { }
}
break;
}
@ -132,4 +146,16 @@ public class SchematicCommand implements CommandExecutor {
player.spigot().sendMessage(nextPage);
}
private boolean isSchematicNameAllowed(String schematicName) {
if(schematicName.contains("/") ||
schematicName.contains("\\") ||
schematicName.contains("<") ||
schematicName.contains(">") ||
schematicName.contains("^") ||
schematicName.contains("°")) {
return false;
} else
return true;
}
}