From 3bc7057c59e4b42981044afda9eef1f515781ac3 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Thu, 28 Mar 2019 15:39:27 +0100 Subject: [PATCH] reworked some methods Signed-off-by: yaruma3341 --- .../commands/SchematicCommand.java | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/src/de/warking/schematicsystem/commands/SchematicCommand.java b/src/de/warking/schematicsystem/commands/SchematicCommand.java index 2fa7aee..fe4c48e 100644 --- a/src/de/warking/schematicsystem/commands/SchematicCommand.java +++ b/src/de/warking/schematicsystem/commands/SchematicCommand.java @@ -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,17 +54,18 @@ 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); - SchematicSystem.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard((ClipboardHolder) FaweAPI.load(new File(SchematicSystem.PREFIX + args[1])).getClipboard()); - player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7geladen."); - } catch (IOException ex) { - ex.printStackTrace(); + try { + Actor actor = SchematicSystem.getWorldEditPlugin().wrapCommandSender(sender); + SchematicSystem.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard((ClipboardHolder) FaweAPI.load(new File(SchematicSystem.PREFIX + args[1])).getClipboard()); + player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7geladen."); + } catch (IOException ex) { + ex.printStackTrace(); + } + + break; } - - 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"); - file.delete(); - player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + "§7gelöscht."); - break; + 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; + } }