From a20b9fd2aaea90a6b5bb30b1706dc0c2c2302eea Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sat, 30 Mar 2019 10:47:18 +0100 Subject: [PATCH] fixed some methods Signed-off-by: yaruma3341 --- .../commands/SchematicCommand.java | 92 ++++++++++++------- .../listener/PlayerJoinListener.java | 2 +- src/plugin.yml | 7 +- 3 files changed, 68 insertions(+), 33 deletions(-) diff --git a/src/de/warking/schematicsystem/commands/SchematicCommand.java b/src/de/warking/schematicsystem/commands/SchematicCommand.java index 8314d0c..a253323 100644 --- a/src/de/warking/schematicsystem/commands/SchematicCommand.java +++ b/src/de/warking/schematicsystem/commands/SchematicCommand.java @@ -60,8 +60,8 @@ public class SchematicCommand implements CommandExecutor { } if(args[0].equalsIgnoreCase("load")) { - if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) { - if(isSchematicNameAllowed(args[1])) { + if(isSchematicNameAllowed(args[1])) { + if (Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) { try { Actor actor = SchematicSystem.getWorldEditPlugin().wrapCommandSender(player); @@ -73,25 +73,30 @@ public class SchematicCommand implements CommandExecutor { return false; } else { - player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematic Name enthält verbotene Zeichen!"); + player.sendMessage(SchematicSystem.PREFIX + "§cDie angegebene Schematic existiert nicht!"); return false; } } else { - player.sendMessage(SchematicSystem.PREFIX + "§cDie angegebene Schematic existiert nicht!"); + player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematic Name enthält verbotene Zeichen!"); return false; } } if(args[0].equalsIgnoreCase("delete")) { - Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); - if(schematic != null) { - File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/" + args[1] + ".schematic"); - file.delete(); - schematic.remove(); - player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7gelöscht."); - return false; + if(isSchematicNameAllowed(args[1])) { + Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); + if(schematic != null) { + File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/" + args[1] + ".schematic"); + file.delete(); + schematic.remove(); + player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7gelöscht."); + return false; + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDiese Schematic existiert nicht!"); + return false; + } } else { - player.sendMessage(SchematicSystem.PREFIX + "§cDiese Schematic existiert nicht!"); + player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematic Name enthält verbotene Zeichen!"); return false; } } @@ -106,12 +111,16 @@ public class SchematicCommand implements CommandExecutor { return false; } } - File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/", args[1]); - ClipboardWriter writer = ClipboardFormat.findByFile(file).getWriter(new FileOutputStream(file)); + if(Schematic.getSchemFromDB(args[1], player.getUniqueId()) != null) + Schematic.getSchemFromDB(args[1], player.getUniqueId()).remove(); + + File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/" + args[1] + ".schematic"); + file.createNewFile(); + ClipboardWriter writer = ClipboardFormat.SCHEMATIC.getWriter(new FileOutputStream(file)); writer.write(FaweAPI.wrapPlayer(player).getSession().getClipboard().getClipboard(), FaweAPI.wrapPlayer(player).getSession().getClipboard().getWorldData()); Schematic schematic = new Schematic(args[1], player.getUniqueId(), "", SchematicType.normal); player.sendMessage(SchematicSystem.PREFIX + "§Schematic §6" + args[1] + " §7gespeichert!"); - } catch (IOException ex) { ex.printStackTrace(); } catch (EmptyClipboardException ex) { ex.printStackTrace(); } + } catch (IOException ex) { ex.printStackTrace(); } catch (EmptyClipboardException ex) { ex.printStackTrace(); player.sendMessage(SchematicSystem.PREFIX + "§cBeim Speichern der Schematic ist ein Fehler aufgetreten!");} } else { player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematic Name enthält verbotene Zeichen!"); return false; @@ -124,17 +133,22 @@ public class SchematicCommand implements CommandExecutor { if(!player.hasPermission("bau.team")) return false; WarkingUser warkingUser = WarkingUser.get(args[2]); if(warkingUser != null) { - File file = new File(SchematicSystem.SCHEM_DIR + warkingUser.getUUID().toString() + "/", args[1] + ".schematic"); - if(file.exists()) { - try { - Actor actor = SchematicSystem.getWorldEditPlugin().wrapCommandSender(player); - SchematicSystem.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard((ClipboardHolder) FaweAPI.load(new File(SchematicSystem.SCHEM_DIR + warkingUser.getUUID().toString() + "/", args[1] + ".schematic")).getClipboard()); - player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7von §6" + warkingUser.getUserName() + "§7geladen."); - } catch (IOException ex) { - ex.printStackTrace(); + if(isSchematicNameAllowed(args[1])) { + File file = new File(SchematicSystem.SCHEM_DIR + warkingUser.getUUID().toString() + "/" + args[1] + ".schematic"); + if(file.exists()) { + try { + Actor actor = SchematicSystem.getWorldEditPlugin().wrapCommandSender(player); + SchematicSystem.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard((ClipboardHolder) FaweAPI.load(new File(SchematicSystem.SCHEM_DIR + warkingUser.getUUID().toString() + "/", args[1] + ".schematic")).getClipboard()); + player.sendMessage(SchematicSystem.PREFIX + "Schematic §6" + args[1] + " §7von §6" + warkingUser.getUserName() + "§7geladen."); + } catch (IOException ex) { + ex.printStackTrace(); + } + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDiese Schematic existiert nicht!"); + return false; } } else { - player.sendMessage(SchematicSystem.PREFIX + "§cDiese Schematic existiert nicht!"); + player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematic Name enthält verbotene Zeichen!"); return false; } } else { @@ -180,9 +194,16 @@ public class SchematicCommand implements CommandExecutor { if(schematic != null) { WarkingUser warkingUser = WarkingUser.get(args[2]); if(warkingUser != null) { - SchematicMember schematicMember = new SchematicMember(schematic.getSchemName(), player.getUniqueId(), warkingUser.getUUID()); - player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §6" + warkingUser.getUserName() + " §7hat nun Zugriff auf die Schematic §6" + schematic.getSchemName() + "§7."); - return false; + if(schematic.getSchemOwner() != warkingUser.getId()) { + + SchematicMember schematicMember = new SchematicMember(schematic.getSchemName(), player.getUniqueId(), warkingUser.getUUID()); + player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §6" + warkingUser.getUserName() + " §7hat nun Zugriff auf die Schematic §6" + schematic.getSchemName() + "§7."); + return false; + + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst dich nicht auf deine eigenen Schematics adden!"); + return false; + } } else { player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler existiert nicht!"); return false; @@ -198,9 +219,16 @@ public class SchematicCommand implements CommandExecutor { if(schematic != null) { WarkingUser warkingUser = WarkingUser.get(args[2]); if(warkingUser != null) { - SchematicMember.getSchemMemberFromDB(schematic.getSchemName(), player.getUniqueId(), warkingUser.getUUID()).remove(); - player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §6" + warkingUser.getUserName() + " §7hat keinen Zugriff mehr auf die Schematic §6" + schematic.getSchemName() + "§7."); - return false; + if(schematic.getSchemOwner() != warkingUser.getId()) { + + SchematicMember.getSchemMemberFromDB(schematic.getSchemName(), player.getUniqueId(), warkingUser.getUUID()).remove(); + player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §6" + warkingUser.getUserName() + " §7hat keinen Zugriff mehr auf die Schematic §6" + schematic.getSchemName() + "§7."); + return false; + + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst dich nicht von deiner eigenen Schematic removen!"); + return false; + } } else { player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler existiert nicht!"); return false; @@ -246,6 +274,7 @@ public class SchematicCommand implements CommandExecutor { public static void sendPlayerSchematicList(int currentPage, int filesPerPage, Player player) { List schematicList = Schematic.getSchemsAccessibleByUser(player.getUniqueId()); + int pages = schematicList.size() / filesPerPage; int currPage = currentPage; if(currPage > pages) { @@ -253,6 +282,7 @@ public class SchematicCommand implements CommandExecutor { } for(int i = currPage * filesPerPage; i < (currPage * filesPerPage) + filesPerPage; i++) { + if(schematicList.get(i) == null) return; TextComponent schematics = new TextComponent(schematicList.get(i).getSchemName()); schematics.setColor(ChatColor.AQUA); @@ -268,7 +298,7 @@ public class SchematicCommand implements CommandExecutor { nextPage.setColor(ChatColor.RED); nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Naechste Seite...").create())); - nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "schematic list " + currentPage + 1)); //COMMAND MISSING + nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "schematic list " + currentPage + 1)); player.spigot().sendMessage(nextPage); } diff --git a/src/de/warking/schematicsystem/listener/PlayerJoinListener.java b/src/de/warking/schematicsystem/listener/PlayerJoinListener.java index 3281233..c01caaf 100644 --- a/src/de/warking/schematicsystem/listener/PlayerJoinListener.java +++ b/src/de/warking/schematicsystem/listener/PlayerJoinListener.java @@ -17,7 +17,7 @@ public class PlayerJoinListener implements Listener { Player player = event.getPlayer(); File file = new File(SchematicSystem.SCHEM_DIR + player.getUniqueId() + "/"); File[] files = file.listFiles(); - for(int i = 0; i <= files.length; i++) { + for(int i = 0; i < files.length; i++) { if(Schematic.getSchemFromDB(files[i].getName(), player.getUniqueId()) != null) { Schematic schematic = new Schematic(files[i].getName(), player.getUniqueId(), "", SchematicType.normal); } diff --git a/src/plugin.yml b/src/plugin.yml index dc24153..b1cdf32 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -2,5 +2,10 @@ name: SchematicSystem version: 1.0 author: [Yaruma3341, Lixfel] depend: [CoreSystem, WorldEdit, FastAsyncWorldEdit] +main: de.warking.schematicsystem.SchematicSystem -main: de.warking.schematicsystem.SchematicSystem \ No newline at end of file +commands: + schematic: + /schematic: + schem: + /schem: \ No newline at end of file