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; package de.warking.schematicsystem.commands;
import com.boydti.fawe.FaweAPI; import com.boydti.fawe.FaweAPI;
import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.extension.platform.Actor; 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 com.sk89q.worldedit.session.ClipboardHolder;
import de.warking.hunjy.MySQL.Schematic; import de.warking.hunjy.MySQL.Schematic;
import de.warking.schematicsystem.SchematicSystem; import de.warking.schematicsystem.SchematicSystem;
@ -16,6 +19,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -50,17 +54,18 @@ public class SchematicCommand implements CommandExecutor {
if(args[0].equalsIgnoreCase("load")) { if(args[0].equalsIgnoreCase("load")) {
if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) { if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) {
//load schematic to player clipboard if(isSchematicNameAllowed(args[1])) {
try { try {
Actor actor = SchematicSystem.getWorldEditPlugin().wrapCommandSender(sender); Actor actor = SchematicSystem.getWorldEditPlugin().wrapCommandSender(sender);
SchematicSystem.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard((ClipboardHolder) FaweAPI.load(new File(SchematicSystem.PREFIX + args[1])).getClipboard()); 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."); player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7geladen.");
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
}
break;
} }
break;
} else { } else {
player.sendMessage(SchematicSystem.PREFIX + "§cDie angegebene Schematic existiert nicht!"); player.sendMessage(SchematicSystem.PREFIX + "§cDie angegebene Schematic existiert nicht!");
break; break;
@ -69,13 +74,22 @@ public class SchematicCommand implements CommandExecutor {
if(args[0].equalsIgnoreCase("delete")) { if(args[0].equalsIgnoreCase("delete")) {
File file = new File(SchematicSystem.SCHEM_DIR + args[1] + ".schematic"); File file = new File(SchematicSystem.SCHEM_DIR + args[1] + ".schematic");
file.delete(); if(file.exists()) {
player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + "§7gelöscht."); file.delete();
break; 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")) { 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; break;
} }
@ -132,4 +146,16 @@ public class SchematicCommand implements CommandExecutor {
player.spigot().sendMessage(nextPage); 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;
}
} }