From df2db0d63dbbe0efc2f5b3d688b43674d5f1ed2a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 13 Jul 2021 15:46:40 +0200 Subject: [PATCH] Some new Implementations --- .../schematicsystem/CheckSchemType_12.java | 3 +- .../schematicsystem/CheckSchemType_15.java | 3 +- SchematicSystem_Main/pom.xml | 10 - .../schematicsystem/CheckSchemType.java | 3 +- .../schematicsystem/SchematicSystem.java | 6 +- .../schematicsystem/commands/GUI.java | 258 +++-- .../commands/SchematicCommand.java | 1025 ++++++++++------- SchematicSystem_Main/src/plugin.yml | 15 +- 8 files changed, 762 insertions(+), 561 deletions(-) diff --git a/SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java b/SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java index 45d198a..8b7af2e 100644 --- a/SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java +++ b/SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.regions.Region; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -90,7 +91,7 @@ class CheckSchemType_12 { private CheckSchemType_12(){} - static AutoCheckResult autoCheck(Schematic schematic, ICheckSchemType type) { + static AutoCheckResult autoCheck(SchematicNode schematic, ICheckSchemType type) { AutoCheckResult result = new AutoCheckResult(type); Clipboard clipboard; try { diff --git a/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java b/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java index dbfe37a..18f4b06 100644 --- a/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java +++ b/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.block.BaseBlock; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -91,7 +92,7 @@ class CheckSchemType_15 { private CheckSchemType_15(){} - static AutoCheckResult autoCheck(Schematic schematic, ICheckSchemType type) { + static AutoCheckResult autoCheck(SchematicNode schematic, ICheckSchemType type) { AutoCheckResult result = new AutoCheckResult(type); Clipboard clipboard; try { diff --git a/SchematicSystem_Main/pom.xml b/SchematicSystem_Main/pom.xml index ef5a40d..cae6f72 100644 --- a/SchematicSystem_Main/pom.xml +++ b/SchematicSystem_Main/pom.xml @@ -82,15 +82,5 @@ 1.0 compile - - org.apache.httpcomponents - httpclient - 4.5.13 - - - org.apache.httpcomponents - httpmime - 4.5.13 - \ No newline at end of file diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java index 9ed619a..4858dfe 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java @@ -21,6 +21,7 @@ package de.steamwar.schematicsystem; import de.steamwar.core.VersionedCallable; import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import org.bukkit.configuration.ConfigurationSection; @@ -74,7 +75,7 @@ public class CheckSchemType implements ICheckSchemType { return types.get(type); } - public AutoCheckResult autoCheck(Schematic schematic) { + public AutoCheckResult autoCheck(SchematicNode schematic) { return VersionedCallable.call(new VersionedCallable<>(AutoCheckResult::new, 8), new VersionedCallable<>(() -> CheckSchemType_12.autoCheck(schematic, this), 12), new VersionedCallable<>(AutoCheckResult::new, 13), diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java index ddb8d6c..f83a249 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java @@ -29,14 +29,18 @@ import java.util.logging.Level; public class SchematicSystem extends JavaPlugin { public static final String PREFIX = "§eSchematic§8» §7"; + public static SchematicSystem INSTANCE; + public static SchematicCommand SCHEMATIC_COMMAND; + @Override public void onEnable() { + INSTANCE = this; if (!new File(getDataFolder(), "config.yml").exists()) { saveDefaultConfig(); Bukkit.getLogger().log(Level.SEVERE, "config.yml erstellt und geladen!"); } CheckSchemType.init(getConfig()); - getCommand("schem").setExecutor(new SchematicCommand()); + SCHEMATIC_COMMAND = new SchematicCommand(); } } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index 6533cfb..33a5f8d 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -32,10 +32,109 @@ import org.bukkit.event.inventory.ClickType; import java.util.*; -class GUI { - private GUI(){} +public class GUI { - static void changeType(Player p, Schematic schem){ + public static void open(Player player) { + list(player, SchematicNode.getSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId(), null), false, "/"); + } + + private static void list(Player player, List schems, boolean publics, String path) { + List> schemList = new ArrayList<>(); + + for(SchematicNode schem : schems) { + Material m; + if (schem.getItem().isEmpty()) + m = SWItem.getMaterial("CAULDRON_ITEM"); + else + m = SWItem.getMaterial(schem.getItem()); + + SWItem item = new SWItem(m, "§e" + schem.getName(), Collections.singletonList(schem.isDir()?"§9Ordner":"§7" + schem.getSchemtype().name()), schem.isDir()?false:!schem.getSchemtype().writeable(), click -> {}); + if(!schem.isDir()) { + if(schem.getRank() > 0) + item.setLore(Lists.newArrayList("§7" + schem.getSchemtype().name(), "§8Rang " + schem.getRank())); + } + schemList.add(new SWListInv.SWListEntry<>(item, schem)); + } + + SWListInv inv = new SWListInv<>(player, "§eSchematicliste §8- §r" + path, false, schemList, (clickType, schem) -> info(player, schem)); + if(publics) + inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> open(player)); + else + inv.setItem(48, Material.GLASS, "§7Public Schematics", clickType -> list(player, SchematicNode.getSchematicsAccessibleByUser(0, null), true, "/")); + inv.setItem(50, Material.NAME_TAG, "§7Suche", clickType -> search(player, publics)); + inv.open(); + } + + private static void info(Player player, SchematicNode node) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(node.isDir()) { + list(player, SchematicNode.getSchematicNodeInNode(node), node.getOwner() == 0, node.generateBreadcrumbs(user)); + } else { + SWInventory inv = new SWInventory(player, 9, node.generateBreadcrumbs(user)); + inv.setItem(0, SWItem.getMaterial("WOOD_AXE"), "§eLaden", click -> { + player.closeInventory(); + SchematicSystem.SCHEMATIC_COMMAND.loadSchem(player, node); + }); + + if(node.getOwner() == user.getId()){ + if(node.getSchemtype().writeable()){ + List checkedSchematics = CheckedSchematic.getLastDeclined(player.getUniqueId()); + ListIterator i = checkedSchematics.listIterator(checkedSchematics.size()); + while(i.hasPrevious()) { + CheckedSchematic checkedSchematic = i.previous(); + if(checkedSchematic.getNode() == node.getId()) { + inv.setItem(1, SWItem.getDye(10), (byte) 10, "§eStatus " + node.getSchemtype().name(), Collections.singletonList("§7" + checkedSchematic.getDeclineReason()), false, click -> {}); + break; + } + } + } + Material mat = SWItem.getMaterial("CAULDRON_ITEM"); + if(node.getItem() != null && !node.getItem().equals("")) + mat = SWItem.getMaterial(node.getItem()); + + inv.setItem(2, mat, "§e" + mat.name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> { + player.closeInventory(); + changeItem(player, node); + }); + inv.setItem(4, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + node.getSchemtype().name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> { + player.closeInventory(); + changeType(player, node); + }); + inv.setItem(5, SWItem.getMaterial("MAGENTA_GLAZED_TERRACOTTA"), "§eDownload", click -> { + player.closeInventory(); + SchematicSystem.SCHEMATIC_COMMAND.download(player, node); + }); + SWItem skull = SWItem.getPlayerSkull("MHF_STEVE"); + skull.setCallback(click -> { + player.closeInventory(); + delmembers(player, node); + }); + skull.setName("§eMitglieder"); + inv.setItem(6, skull); + inv.setItem(8, SWItem.getDye(1), (byte) 1, "§cLöschen", click -> { + player.closeInventory(); + delete(player, node); + }); + }else{ + inv.setItem(4, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + node.getSchemtype().name(), click -> {}); + + SteamwarUser owneruser = SteamwarUser.get(node.getOwner()); + SWItem skull = SWItem.getPlayerSkull(owneruser.getUserName()); + skull.setName("§7von §e" + owneruser.getUserName()); + inv.setItem(6, skull); + + inv.setItem(8, SWItem.getDye(1), (byte) 1, "§cZugriff entfernen", click -> { + player.closeInventory(); + delete(player, node); + }); + } + + inv.setCallback(-999, click -> player.closeInventory()); + inv.open(); + } + } + + static void changeType(Player p, SchematicNode schem){ List> types = new LinkedList<>(); for(SchematicType type : SchematicType.values()){ if(!type.isAssignable()) @@ -49,24 +148,24 @@ class GUI { } SWListInv inv = new SWListInv<>(p, "Typ ändern", types, (clickType, schematicType) -> { - SchematicCommand.changetype(p, schem, schematicType); + p.closeInventory(); + SchematicSystem.SCHEMATIC_COMMAND.changeType(p, schem, schematicType); }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); } - private static void deleteOwn(Player p, Schematic schem){ - SWInventory inv = new SWInventory(p, 9, schem.getSchemName() + " löschen"); + private static void deleteOwn(Player p, SchematicNode schem){ + SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + SWInventory inv = new SWInventory(p, 9, schem.generateBreadcrumbs(user) + " löschen"); inv.setItem(0, SWItem.getDye(1), (byte) 1, "§eLöschen", click -> { - schem.remove(); + schem.delete(); - List checkedSchematics = CheckedSchematic.getLastDeclined(p.getUniqueId()); + List checkedSchematics = CheckedSchematic.getLastDeclined(schem); for(CheckedSchematic checkedSchematic : checkedSchematics) { - if(checkedSchematic.getSchemOwner() == schem.getSchemOwner() && - checkedSchematic.getSchemName().equals(schem.getSchemName())) - checkedSchematic.remove(); + checkedSchematic.remove(); } - p.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + schem.getSchemName() + " §7gelöscht"); + p.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + schem.generateBreadcrumbs(user) + " §7gelöscht"); p.closeInventory(); }); inv.setItem(8, SWItem.getDye(14), (byte) 14, "§cAbbruch", click -> p.closeInventory()); @@ -74,13 +173,14 @@ class GUI { inv.open(); } - private static void deleteMembership(Player p, Schematic schem){ - SWInventory inv = new SWInventory(p, 9, schem.getSchemName() + " entfernen"); + private static void deleteMembership(Player p, SchematicNode schem){ + SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + SWInventory inv = new SWInventory(p, 9, schem.generateBreadcrumbs(user) + " entfernen"); inv.setItem(0, SWItem.getDye(1), (byte) 1, "§eZugriff entfernen", click -> { - SchematicMember member = SchematicMember.getSchemMemberFromDB(schem.getSchemName(), schem.getSchemOwner(), SteamwarUser.get(p.getUniqueId()).getId()); + NodeMember member = NodeMember.getNodeMember(schem.getId(), user.getId()); if(member != null) - member.remove(); - p.sendMessage(SchematicSystem.PREFIX + "Zugriff zu Schematic §e" + schem.getSchemName() + " §7entfernt"); + member.delete(); + p.sendMessage(SchematicSystem.PREFIX + "Zugriff zu Schematic §e" + schem.generateBreadcrumbs(user) + " §7entfernt"); p.closeInventory(); }); inv.setItem(8, SWItem.getDye(14), (byte) 14, "§cAbbruch", click -> p.closeInventory()); @@ -88,22 +188,22 @@ class GUI { inv.open(); } - static void delete(Player p, Schematic schem){ - if(SteamwarUser.get(p.getUniqueId()).getId() == schem.getSchemOwner()) + static void delete(Player p, SchematicNode schem){ + if(SteamwarUser.get(p.getUniqueId()).getId() == schem.getOwner()) deleteOwn(p, schem); else deleteMembership(p, schem); } - static void delmembers(Player p, Schematic schem){ - List> members = new LinkedList<>(); - for(SchematicMember member : SchematicMember.getSchemMembers(schem.getSchemName(), schem.getSchemOwner())){ + static void delmembers(Player p, SchematicNode schem){ + List> members = new LinkedList<>(); + for(NodeMember member : schem.getMembers()){ SteamwarUser user = SteamwarUser.get(member.getMember()); members.add(new SWListInv.SWListEntry<>(SWItem.getPlayerSkull(user.getUserName()), member)); } - SWListInv inv = new SWListInv<>(p, "Mitglieder entfernen", members, (clickType, member) -> { - member.remove(); + SWListInv inv = new SWListInv<>(p, "Mitglieder entfernen", members, (clickType, member) -> { + member.delete(); p.closeInventory(); delmembers(p, schem); }); @@ -111,7 +211,7 @@ class GUI { inv.open(); } - private static void changeItem(Player p, Schematic schem){ + private static void changeItem(Player p, SchematicNode schem){ List> materials = new LinkedList<>(); for(Material material : Material.values()){ SWItem item = new SWItem(material, "§7" + material.name()); @@ -128,108 +228,12 @@ class GUI { inv.open(); } - private static void info(Player p, Schematic schem){ - SWInventory inv = new SWInventory(p, 9, schem.getSchemName()); - if(schem.availible()) - inv.setItem(0, SWItem.getMaterial("WOOD_AXE"), "§eLaden", click -> { - SchematicCommand.load(p, schem); - p.closeInventory(); - }); - - if(schem.getSchemOwner() == SteamwarUser.get(p.getUniqueId()).getId()){ - if(schem.getSchemType().writeable()){ - List checkedSchematics = CheckedSchematic.getLastDeclined(p.getUniqueId()); - ListIterator i = checkedSchematics.listIterator(checkedSchematics.size()); - while(i.hasPrevious()) { - CheckedSchematic checkedSchematic = i.previous(); - if(checkedSchematic.getSchemName().equals(schem.getSchemName()) && - checkedSchematic.getSchemOwner() == schem.getSchemOwner()) { - inv.setItem(1, SWItem.getDye(10), (byte) 10, "§eStatus " + schem.getSchemType().name(), Collections.singletonList("§7" + checkedSchematic.getDeclineReason()), false, click -> {}); - break; - } - } - } - Material mat = SWItem.getMaterial("CAULDRON_ITEM"); - if(schem.getItem() != null && !schem.getItem().equals("")) - mat = SWItem.getMaterial(schem.getItem()); - - inv.setItem(2, mat, "§e" + mat.name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> { - p.closeInventory(); - changeItem(p, schem); - }); - if(schem.availible()) - inv.setItem(4, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + schem.getSchemType().name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> { - p.closeInventory(); - changeType(p, schem); - }); - inv.setItem(5, SWItem.getMaterial("MAGENTA_GLAZED_TERRACOTTA"), "§eDownload", click -> { - p.closeInventory(); - SchematicCommand.download(p, schem); - }); - SWItem skull = SWItem.getPlayerSkull("MHF_STEVE"); - skull.setCallback(click -> { - p.closeInventory(); - delmembers(p, schem); - }); - skull.setName("§eMitglieder"); - inv.setItem(6, skull); - inv.setItem(8, SWItem.getDye(1), (byte) 1, "§cLöschen", click -> { - p.closeInventory(); - delete(p, schem); - }); - }else{ - inv.setItem(4, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + schem.getSchemType().name(), click -> {}); - - SteamwarUser owneruser = SteamwarUser.get(schem.getSchemOwner()); - SWItem skull = SWItem.getPlayerSkull(owneruser.getUserName()); - skull.setName("§7von §e" + owneruser.getUserName()); - inv.setItem(6, skull); - - inv.setItem(8, SWItem.getDye(1), (byte) 1, "§cZugriff entfernen", click -> { - p.closeInventory(); - delete(p, schem); - }); - } - - inv.setCallback(-999, click -> p.closeInventory()); - inv.open(); - } - - static void list(Player p){ - list(p, Schematic.getSchemsAccessibleByUser(SteamwarUser.get(p.getUniqueId()).getId()), false); - } - - private static void list(Player p, List schems, boolean publics){ - List> schemList = new ArrayList<>(); - - for(Schematic schem : schems) { - Material m; - if (schem.getItem().isEmpty()) - m = SWItem.getMaterial("CAULDRON_ITEM"); - else - m = SWItem.getMaterial(schem.getItem()); - - SWItem item = new SWItem(m, "§e" + schem.getSchemName(), Collections.singletonList("§7" + schem.getSchemType().name()), !schem.getSchemType().writeable(), click -> {}); - if(schem.getRank() > 0) - item.setLore(Lists.newArrayList("§7" + schem.getSchemType().name(), "§8Rang " + schem.getRank())); - schemList.add(new SWListInv.SWListEntry<>(item, schem)); - } - - SWListInv inv = new SWListInv<>(p, "§eSchematicliste", false, schemList, (clickType, schem) -> info(p, schem)); - if(publics) - inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> list(p)); - else - inv.setItem(48, Material.GLASS, "§7Public Schematics", clickType -> list(p, Schematic.getSchemsAccessibleByUser(0), true)); - inv.setItem(50, Material.NAME_TAG, "§7Suche", clickType -> search(p, schems)); - inv.open(); - } - - static void search(Player p, List schems){ - SWAnvilInv inv = new SWAnvilInv(p, "§7Schematicsuche"); - inv.setCallback(term -> { - ArrayList schemCopy = new ArrayList<>(schems); - schemCopy.removeIf(schem -> !schem.getSchemName().toLowerCase().contains(term.toLowerCase())); - list(p, schemCopy, false); + private static void search(Player player, boolean publics) { + SWAnvilInv inv = new SWAnvilInv(player, "Schematics suchen"); + inv.setItem(SWItem.getMaterial("CAULDRON_ITEM")); + inv.setCallback(s -> { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + list(player, SchematicNode.filterSchems(publics?0:user.getId(), node -> node.getName().contains(s)), publics, "/"); }); inv.open(); } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 1760e60..8422601 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -1,6 +1,6 @@ -/* +/* This file is a part of the SteamWar software. - + Copyright (C) 2020 SteamWar.de-Serverteam This program is free software: you can redistribute it and/or modify @@ -19,6 +19,8 @@ package de.steamwar.schematicsystem.commands; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; import de.steamwar.comms.packets.PrepareSchemPacket; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -32,253 +34,384 @@ import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Collection; +import java.time.format.DateTimeFormatter; +import java.util.*; import java.util.List; import java.util.logging.Level; +import java.util.stream.Collectors; -public class SchematicCommand implements CommandExecutor { +public class SchematicCommand extends SWCommand { - private static final int FILES_PER_PAGE = 15; + private static final int CHUNK_SIZE = 15; - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) - return false; - Player player = (Player) sender; - - if(args.length == 0){ - help(player); - return false; - } - - switch(args[0].toLowerCase()){ - case "gui": - GUI.list(player); - break; - case "list": - list(player, args); - break; - case "load": - load(player, args); - break; - case "delete": - delete(player, args); - break; - case "save": - save(player, args); - break; - case "info": - info(player, args); - break; - case "changetype": - changetype(player, args); - break; - case "addmember": - addmember(player, args); - break; - case "delmember": - delmember(player, args); - break; - case "download": - download(player, args); - break; - case "search": - search(player, args); - break; - default: - help(player); - } - return false; + public SchematicCommand() { + super("schematic", "/schematic", "schem", "/schem"); } - private void list(Player player, String[] args){ - if(args.length <= 1){ - sendPlayerSchematicList(0, player, "/schem list ", Schematic.getSchemsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId())); - return; + @Register(help = true) + public void genericHelp(Player player, String... args) { + player.sendMessage(SchematicSystem.PREFIX + "Befehle§8:"); + player.sendMessage("§8/§eschem gui §8- §7Öffnet die Schematic-GUI"); + player.sendMessage("§8/§eschem list §8- §7Zeigt dir deine Schematics an"); + player.sendMessage("§8/§eschem list public §8- §7Zeigt alle Public-Schematics"); + player.sendMessage("§8/§eschem search §8[§7Stichwort§8] - §7Sucht nach passenden Schematics"); + player.sendMessage("§8/§eschem load §8[§7Schematic§8] - §7Lädt eine Schematic"); + player.sendMessage("§8/§eschem save §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic"); + player.sendMessage("§8/§eschem changetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic"); + player.sendMessage("§8/§eschem delete §8[§7Schematic§8] - §7Löscht eine Schematic"); + player.sendMessage("§8/§eschem info §8[§7Schematic§8] - §7Zeigt dir Informationen zur Schematic"); + player.sendMessage("§8/§eschem download §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig)"); + player.sendMessage("§8/§eschem addmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Fügt einen Spieler zu einer Schematic hinzu"); + player.sendMessage("§8/§eschem delmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic"); + player.sendMessage("§8/§eschem mkdirs §8[§7Ordner§8] - §7Erstelle einen Leeren Ordner"); + player.sendMessage("§8/§eschem move §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic"); + } + + @Register("gui") + public void gui(Player player) { + GUI.open(player); + } + + @Register("list") + @Register({"list", "/"}) + public void schemList(Player player) { + renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId(), 0), 0, "", false); + } + + @Register("list") + @Register({"list", "/"}) + public void schemList(Player player, int page) { + renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId(), 0), page, "", false); + } + + @Register("list") + public void schemList(Player player, @Mapper("dirMapper") SchematicNode node) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(!node.isDir()) { + player.sendMessage("haethate"); + } else { + renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), 0, node.generateBreadcrumbs(user), node.getOwner()==0); + } + } + + @Register("list") + public void schemList(Player player, @Mapper("dirMapper") SchematicNode node, int page) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(!node.isDir()) { + player.sendMessage("haethate"); + } else { + renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), page, node.generateBreadcrumbs(user), node.getOwner()==0); + } + } + + @Register({"list", "public"}) + public void schemListPublic(Player player, @Mapper("publicDirMapper") SchematicNode node) { + schemList(player, node); + } + + @Register({"list", "public"}) + public void schemListPublic(Player player, @Mapper("publicDirMapper") SchematicNode node, int page) { + schemList(player, node, page); + } + + @Register({"list", "public"}) + @Register({"list", "public", "/"}) + public void schemListPublic(Player player) { + renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), 0, "", true); + } + + @Register({"list", "public"}) + @Register({"list", "public", "/"}) + public void schemListPublic(Player player, int page) { + renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), page, "", true); + } + + + @Register({"info", "public"}) + public void schemInfoPublic(Player player, @Mapper("publicMapper") SchematicNode node) { + schemInfo(player, node); + } + + @Register("info") + public void schemInfo(Player player, SchematicNode node) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + player.sendMessage("§7--==( §e" + node.getName() + " §7)==--"); + player.sendMessage("§7Name: §e" + node.generateBreadcrumbs(user)); + player.sendMessage("§7Besitzer: §e" + SteamwarUser.get(node.getOwner()).getUserName()); + player.sendMessage("§7Ordner: §e" + (node.getParent() == null || node.getParent() == 0?"/":node.getParentNode().generateBreadcrumbs(user))); + player.sendMessage("§7Letzes Update: §e" + node.getLastUpdate().toLocalDateTime().format(DateTimeFormatter.ofPattern("HH:mm dd.MM.yyyy", Locale.GERMAN))); + player.sendMessage("§7Typ: §e" + (node.isDir()?"§9DIR":node.getSchemtype().name())); + if(!node.isDir()) { + if(node.getRank() > 0) { + player.sendMessage("§7Rang: §e" + node.getRank()); + } + player.sendMessage("§7Format: §e" + (node.getSchemFormat()?".schem":".schematic")); + List checkedSchematics = CheckedSchematic.getLastDeclined(player.getUniqueId()); + for (CheckedSchematic checkedSchematic : checkedSchematics) { + if (checkedSchematic.getSchemName().equals(node.getName()) && + checkedSchematic.getSchemOwner() == node.getOwner()) { + player.sendMessage("§cStatus: §c" + checkedSchematic.getStartTime() + " : " + checkedSchematic.getDeclineReason()); + break; + } + } + } + List schematicMembers = new ArrayList<>(); + NodeMember.getNodeMembers(node.getId()).forEach(nodeMember -> schematicMembers.add(SteamwarUser.get(nodeMember.getMember()).getUserName())); + if(!schematicMembers.isEmpty()) { + player.sendMessage("§7Mitglieder: §e" + schematicMembers.toString()); } - if("public".equalsIgnoreCase(args[1])){ - if(args.length == 2){ - sendPlayerSchematicList(0, player, "/schem list public ", Schematic.getSchemsAccessibleByUser(0)); - return; - } + TextComponent base = new TextComponent(); - try { - sendPlayerSchematicList(Integer.parseInt(args[2]), player, "/schem list public ", Schematic.getSchemsAccessibleByUser(0)); - } catch (NumberFormatException ex) { - player.sendMessage(SchematicSystem.PREFIX + "§cUngültige Seitenzahl"); + if(!node.isDir()) { + TextComponent load = new TextComponent("[Laden] "); + load.setColor(ChatColor.GREEN); + load.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eSchematic laden"))); + load.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem load " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs(user))); + base.addExtra(load); + + if(node.getOwner() == user.getId()) { + TextComponent download = new TextComponent("[Download] "); + download.setColor(ChatColor.GOLD); + download.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eSchematic downloaden"))); + download.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem download " + node.generateBreadcrumbs(user))); + base.addExtra(download); } + } + + if(node.getOwner() == user.getId()) { + TextComponent addMember = new TextComponent("[Hinzufügen] "); + addMember.setColor(ChatColor.AQUA); + addMember.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eMember hinzufügen"))); + addMember.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem addmember " + node.generateBreadcrumbs(user) + " ")); + base.addExtra(addMember); + + TextComponent delMember = new TextComponent("[Entfernen] "); + delMember.setColor(ChatColor.RED); + delMember.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eMember entfernen"))); + delMember.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem delmember " + node.generateBreadcrumbs(user) + " ")); + base.addExtra(delMember); + + TextComponent delete = new TextComponent("[Delete] "); + delete.setColor(ChatColor.DARK_RED); + delete.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir()?"Ordner":"Schematic") + " Löschen"))); + delete.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + node.generateBreadcrumbs(user))); + base.addExtra(delete); + } + + + + player.spigot().sendMessage(base); + } + + @Register({"info", "/"}) + public void schemInfoSecret(Player player) { + player.sendMessage("§7--==( §eSteam§8War §eSchematic-System §7)==--"); + player.sendMessage("§7Anzahl an Schematics: §e" + SchematicNode.countNodes()); + player.sendMessage("§7Von dir einsehbar: §e" + SchematicNode.getAllSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId()).size()); + player.sendMessage("§7Autoren: §e" + Arrays.toString(SchematicSystem.INSTANCE.getDescription().getAuthors().toArray())); + } + + @Register("l") + @Register("load") + public void loadSchem(Player player, SchematicNode node) { + if(node.isDir()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst keine Ordner Laden"); return; } try { - sendPlayerSchematicList(Integer.parseInt(args[1]), player, "/schem list ", Schematic.getSchemsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId())); - } catch (NumberFormatException ex) { - player.sendMessage(SchematicSystem.PREFIX + "§cUngültige Seitenzahl"); + node.loadToPlayer(player); + player.sendMessage(SchematicSystem.PREFIX + "§7Schematic §e" + node.getName() + " §7geladen!"); + Bukkit.getLogger().log(Level.INFO, "{} has loaded Schematic {} {}", new Object[] {player.getName(), node.getId(), node.getName()}); + } catch (NoClipboardException e) { + player.sendMessage(SchematicSystem.PREFIX + "§cEs konnte keine Daten in der Schematic gefunden werden."); + } catch (Exception e) { + player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic konnte nicht geladen werden."); + throw new SecurityException(e); } } - private boolean invalidSchemName(Player player, String name){ - if(name.contains("/") || - name.contains("\\") || - name.contains("<") || - name.contains(">") || - name.contains("^") || - name.contains("°") || - name.contains("'") || - name.contains("\"")){ - player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematicname enthält verbotene Zeichen"); - return true; - } - return false; + @Register({"l", "public"}) + @Register({"load", "public"}) + public void loadSchemPublic(Player player, @Mapper("publicMapper") SchematicNode node) { + loadSchem(player, node); } - private Schematic getSchem(Player player, String name){ - if(invalidSchemName(player, name)) - return null; + @Register("save") + @Register("s") + public void saveSchem(Player player, @Mapper("dirStringMapper") String name) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(name.startsWith("/")) name = name.substring(1); + String[] layers = name.split("/"); + if(invalidSchemName(player, layers)) return; + SchematicNode currentNode = mkdirs(layers, user, 1); - Schematic schematic = Schematic.getSchemFromDB(name, player.getUniqueId()); - if(schematic == null) - schematic = Schematic.getSchemFromDB(name, 0); //public schematic - - if (schematic == null) { - player.sendMessage(SchematicSystem.PREFIX + "§cDie angegebene Schematic existiert nicht"); - return null; - } - - return schematic; - } - - private void load(Player player, String[] args){ - if(args.length < 2){ - help(player); - return; - } - - Schematic schematic = getSchem(player, args[1]); - if(schematic == null) - return; - - load(player, schematic); - } - - static void load(Player player, Schematic schematic){ - try { - schematic.loadToPlayer(player); - player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + schematic.getSchemName() + " §7geladen"); - }catch (Exception e){ - Bukkit.getLogger().log(Level.SEVERE, "Schematic konnte nicht geladen werden", e); - player.sendMessage(SchematicSystem.PREFIX + "§cFehler beim Laden der Schematic. Dies liegt wahrscheinlich an einer defekten Schematic."); - } - } - - private void delete(Player player, String[] args){ - if(args.length < 2){ - help(player); - return; - } - - Schematic schematic = getSchem(player, args[1]); - if(schematic == null) - return; - - GUI.delete(player, schematic); - } - - private void save(Player player, String[] args){ - if(args.length < 2){ - help(player); - return; - } - - if(invalidSchemName(player, args[1])) - return; - - if(args[1].length() > 64){ - player.sendMessage(SchematicSystem.PREFIX + "§cDer Name der Schematic ist zu lang"); - return; - } - - Schematic schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); - if(schematic != null && !schematic.getSchemType().writeable()) { + SchematicNode node = SchematicNode.getSchematicInParent(layers[layers.length-1], currentNode==null?0:currentNode.getId()); + if(node != null && !node.getSchemtype().writeable()) { player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst diese Schematic nicht überschreiben"); return; } boolean newSchem = false; - if(schematic == null || schematic.getSchemOwner() != SteamwarUser.get(player.getUniqueId()).getId()){ + if(node == null) { newSchem = true; - Schematic.createSchem(args[1], player.getUniqueId(), "", SchematicType.Normal); - schematic = Schematic.getSchemFromDB(args[1], player.getUniqueId()); + node = SchematicNode.createSchematic(user.getId(), layers[layers.length-1], currentNode==null?0:currentNode.getId()); } try { - schematic.saveFromPlayer(player); + node.saveFromPlayer(player); }catch (NoClipboardException e) { player.sendMessage(SchematicSystem.PREFIX + "§cDein Clipboard ist leer"); if(newSchem) - schematic.remove(); + node.delete(); return; }catch(Exception ex){ Bukkit.getLogger().log(Level.SEVERE, "Could not save schematic", ex); player.sendMessage(SchematicSystem.PREFIX + "§cFehler beim Speichern der Schematic."); if(newSchem) - schematic.remove(); + node.delete(); return; } if (newSchem) - player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + args[1] + " §7gespeichert"); + player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + node.getName() + " §7gespeichert"); else - player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + args[1] + " §7überschrieben"); + player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + node.getName() + " §7überschrieben"); } - private void changetype(Player player, String[] args){ - if(args.length < 2){ - help(player); + @Register("addmember") + public void addMember(Player player, SchematicNode node, SteamwarUser target) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur auf deine eigenen Sachen jemanden hinzufügen."); return; } - Schematic schematic = getSchem(player, args[1]); - if(schematic == null) - return; - - if(args.length < 3) { - GUI.changeType(player, schematic); + if(user.getId() == target.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cAlso bitte: Das ist deine eigene Schematic!"); return; } - SchematicType type = SchematicType.fromDB(args[2]); - if(type == null || !type.isAssignable()){ - player.sendMessage(SchematicSystem.PREFIX + "§cDiesen Schematictypen gibt es nicht"); + NodeMember member = NodeMember.getNodeMember(node.getId(), target.getId()); + if(member != null) { + player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler ist bereits auf diese Schematic geaddet"); return; } + member = NodeMember.createNodeMember(node.getId(), target.getId()); + player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §e" + target.getUserName() + " §7hat nun Zugriff auf die Schematic §e" + node.generateBreadcrumbs(user)); - changetype(player, schematic, type); + Player t = Bukkit.getPlayer(target.getUUID()); + if(t != null) + t.sendMessage(SchematicSystem.PREFIX + "Du hast nun Zugriff auf die Schematic §e" + node.getName() + " §7von §e" + player.getName()); } - static void changetype(Player player, Schematic schematic, SchematicType type){ - if(schematic.getSchemType() == type){ - player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic hat bereits diesen Typen"); + @Register("delmember") + @Register("remmember") + public void delMember(Player player, SchematicNode node, @Mapper("memberMapper") NodeMember member) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + + if(node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur auf deine eigenen Sachen jemanden entfernen."); return; } - if(type.writeable()){ - schematic.setSchemType(type); + member.delete(); + + List nodes = SchematicNode.deepGet(node.getId(), node1 -> node1.getOwner() != user.getId()); + if(!nodes.isEmpty()) { + SteamwarUser target = SteamwarUser.get(member.getMember()); + for (SchematicNode schematicNode : nodes) { + SchematicNode newNode = mkdirs(schematicNode.generateBreadcrumbs(user).split("/"), target, 1); + schematicNode.setParent(newNode==null?0:newNode.getId()); + } + } + } + + @Register("download") + public void download(Player player, SchematicNode node) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(node.getOwner() != user.getId()) { + player.sendMessage("§cDu darfst nur deine eigenen Schematics herunterladen!"); + return; + } + + player.sendMessage(SchematicSystem.PREFIX + "Dein Download Link:"); + player.sendMessage(DownloadSchematic.getLink(node)); + } + + @Register("dir") + @Register("ordner") + @Register("mkdir") + public void mkdir(Player player, @Mapper("dirStringMapper") String name) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(name.startsWith("/")) name = name.substring(1); + if(name.endsWith("/")) name = name.substring(0, name.length()-1); + String[] layers = name.split("/"); + if(invalidSchemName(player, layers)) return; + SchematicNode node = mkdirs(layers, user, 0); + player.sendMessage(SchematicSystem.PREFIX + "§7Ordner §e" + node.generateBreadcrumbs(user) + " §7erstellt"); + } + + @Register("search") + public void schemSearch(Player player, String quarry) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + List nodes = SchematicNode.filterSchems(user.getId(), node -> node.getName().contains(quarry)); + player.sendMessage("§7--==( §eSchematics §8(§e" + nodes.size() + "§8) §7)==--"); + nodes.forEach(node -> { + String br = node.generateBreadcrumbs(user); + TextComponent schematics = new TextComponent("§7" + br.replace(quarry, "§e§l" + quarry + "§7")); + schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create())); + schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + br)); + + player.spigot().sendMessage(schematics); + }); + } + + @Register("changetype") + public void changeType(Player player, SchematicNode node) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + TextComponent base = new TextComponent(); + + SchematicType.values().forEach(type -> { + if(!type.isAssignable()) return; + + TextComponent component = new TextComponent(type.name() + " "); + component.setColor(ChatColor.GRAY); + component.setBold(true); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eTyp auswählen"))); + component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem changetype " + node.generateBreadcrumbs(user) + " " + type.name())); + base.addExtra(component); + }); + + player.spigot().sendMessage(base); + } + + @Register("changetype") + public void changeType(Player player, SchematicNode node, SchematicType type) { + if(node.isDir()) { + player.sendMessage(SchematicSystem.PREFIX + "§cOrdner haben keinen Typen."); + return; + } + + if(node.getType().equals(type.toDB())) { + player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic hat schon diesen Typen"); + return; + } + + if(type.writeable()) { + node.setType(type.toDB()); player.sendMessage(SchematicSystem.PREFIX + "§aSchematictyp geändert"); - }else if(type.fightType()){ - if(schematic.getSchemType().check()){ + } else if(type.fightType()) { + if(node.getSchemtype().check()){ player.sendMessage(SchematicSystem.PREFIX + "§cDu hast diese Schematic bereits eingesendet"); return; } - AutoCheckResult result = CheckSchemType.get(type).autoCheck(schematic); + AutoCheckResult result = CheckSchemType.get(type).autoCheck(node); Collection errors = result.errors(); for(String warning : result.warnings()){ player.sendMessage(" §e" + warning); @@ -293,12 +426,12 @@ public class SchematicCommand implements CommandExecutor { SWInventory inv = new SWInventory(player, 9, "Schematic ausfahren"); inv.setItem(0, SWItem.getDye(10), (byte)10, "§eSchematic ausfahren", click -> { - new PrepareSchemPacket(SteamwarUser.get(player.getUniqueId()), schematic, type).send(player); + new PrepareSchemPacket(SteamwarUser.get(player.getUniqueId()), node, type).send(player); player.sendMessage(SchematicSystem.PREFIX + "§aDer Vorbereitungsserver wird gestartet"); player.closeInventory(); }); inv.setItem(8, SWItem.getDye(7), (byte)7, "§eDirekt einsenden", click -> { - schematic.setSchemType(type.checkType()); + node.setType(type.checkType().toDB()); player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft"); player.closeInventory(); }); @@ -307,264 +440,330 @@ public class SchematicCommand implements CommandExecutor { } } - private void info(Player player, String[] args){ - if(args.length < 2){ - help(player); - return; - } - - Schematic schematic = getSchem(player, args[1]); - if(schematic == null) - return; - - player.sendMessage("§eName: §7" + schematic.getSchemName()); - - TextComponent type = new TextComponent("§eTyp: §7" + schematic.getSchemType().name()); - if(SteamwarUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId()) && schematic.availible()){ - type.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eTyp ändern"))); - type.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem changetype " + schematic.getSchemName())); - } - if(schematic.getRank() > 0){ - type.addExtra("§8Rang " + schematic.getRank()); - } - player.spigot().sendMessage(type); - - if(SteamwarUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())){ - TextComponent download = new TextComponent("§eDownload Schematic"); - download.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eGeneriere Downloadlink"))); - download.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem download " + schematic.getSchemName())); - player.spigot().sendMessage(download); - } - - List checkedSchematics = CheckedSchematic.getLastDeclined(player.getUniqueId()); - for (CheckedSchematic checkedSchematic : checkedSchematics) { - if (checkedSchematic.getSchemName().equals(schematic.getSchemName()) && - checkedSchematic.getSchemOwner() == schematic.getSchemOwner()) { - player.sendMessage("§cStatus: §c" + checkedSchematic.getStartTime() + " : " + checkedSchematic.getDeclineReason()); - break; - } - } - - if(!SteamwarUser.get(schematic.getSchemOwner()).getUUID().equals(player.getUniqueId())) { - player.sendMessage("§eBesitzer: §7" + SteamwarUser.get(schematic.getSchemOwner()).getUserName()); - } else { - List schematicMembers = new ArrayList<>(); - for(SchematicMember schematicMember : SchematicMember.getSchemMembers(schematic.getSchemName(), schematic.getSchemOwner())) { - schematicMembers.add(SteamwarUser.get(schematicMember.getMember()).getUserName()); - } - player.sendMessage("§eMitglieder: §7" + schematicMembers.toString()); - } - - if(schematic.availible()){ - TextComponent loadSchematic = new TextComponent("LADEN"); - loadSchematic.setColor(ChatColor.DARK_GREEN); - loadSchematic.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem load " + schematic.getSchemName())); - player.spigot().sendMessage(loadSchematic); - } - } - - private void download(Player player, String[] args){ - if(args.length < 2){ - help(player); - return; - } - - Schematic schematic = getSchem(player, args[1]); - if(schematic == null) - return; - - download(player, schematic); - } - - private void search(Player player, String[] args) { - if(args.length < 2) { - help(player); - return; - } - - List schems = Schematic.getSchemsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId()); - schems.removeIf(schem -> !schem.getSchemName().toLowerCase().contains(args[1].toLowerCase())); - - if(args.length == 2){ - sendPlayerSchematicList(0, player, "/schem search " + args[1] + " ", schems); - return; - } - - try { - sendPlayerSchematicList(Integer.parseInt(args[2]), player, "/schem search " + args[1] + " ", schems); - } catch (NumberFormatException ex) { - player.sendMessage(SchematicSystem.PREFIX + "§cUngültige Seitenzahl"); - } - } - - static void download(Player player, Schematic schematic){ - if(schematic.getSchemOwner() != SteamwarUser.get(player.getUniqueId()).getId()){ - player.sendMessage("§cDu darfst nur deine eigenen Schematics herunterladen!"); - return; - } - - player.sendMessage(DownloadSchematic.getLink(schematic)); - } - - private void addmember(Player player, String[] args){ - if(args.length < 3){ - help(player); - return; - } - - Schematic schematic = getSchem(player, args[1]); - if(schematic == null) - return; - - if(schematic.getSchemOwner() != SteamwarUser.get(player.getUniqueId()).getId()) { - player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst nur auf deine eigene Schematic Mitglieder hinzufügen"); - return; - } - - SteamwarUser warkingUser = SteamwarUser.get(args[2]); - if(warkingUser == null){ - player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler existiert nicht"); - return; - } - if(schematic.getSchemOwner() == warkingUser.getId()){ - player.sendMessage(SchematicSystem.PREFIX + "§cAlso bitte: Das ist deine eigene Schematic!"); - return; - } - - if(SchematicMember.getSchemMemberFromDB(schematic.getSchemName(), SteamwarUser.get(schematic.getSchemOwner()).getUUID(), warkingUser.getUUID()) != null){ - player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler ist bereits auf diese Schematic geaddet"); - return; - } - - new SchematicMember(schematic.getSchemName(), SteamwarUser.get(schematic.getSchemOwner()).getUUID(), warkingUser.getUUID()); - player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §e" + warkingUser.getUserName() + " §7hat nun Zugriff auf die Schematic §e" + schematic.getSchemName()); - - Player target = Bukkit.getPlayer(warkingUser.getUUID()); - if(target != null) - target.sendMessage(SchematicSystem.PREFIX + "Du hast nun Zugriff auf die Schematic §e" + schematic.getSchemName() + " §7von §e" + SteamwarUser.get(schematic.getSchemOwner()).getUserName()); - } - - private void delmember(Player player, String[] args){ - if(args.length < 2){ - help(player); - return; - } - - Schematic schematic = getSchem(player, args[1]); - if(schematic == null) - return; - - if(schematic.getSchemOwner() != SteamwarUser.get(player.getUniqueId()).getId()) { - player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst nur von deinen eigenen Schematics Mitglieder entfernen"); - return; - } - - if(args.length < 3){ - GUI.delmembers(player, schematic); - return; - } - - SteamwarUser user = SteamwarUser.get(args[2]); - if(user == null){ - player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler existiert nicht"); - return; - } - if(schematic.getSchemOwner() == user.getId()){ - player.sendMessage(SchematicSystem.PREFIX + "§cAlso bitte: Das ist deine eigene Schematic!"); - return; - } - - SchematicMember schematicMember = SchematicMember.getSchemMemberFromDB(schematic.getSchemName(), SteamwarUser.get(schematic.getSchemOwner()).getUUID(), user.getUUID()); - if(schematicMember == null) { - player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler ist nicht auf die Schematic hinzugefügt"); - return; - } - - schematicMember.remove(); - player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §e" + user.getUserName() + " §7hat keinen Zugriff mehr auf die Schematic §e" + schematic.getSchemName()); - - Player target = Bukkit.getPlayer(user.getUUID()); - if(target != null) - target.sendMessage(SchematicSystem.PREFIX + "Du hast keinen Zugriff mehr auf die Schematic §e" + schematic.getSchemName() + "§7von §e" + SteamwarUser.get(schematic.getSchemOwner()).getUserName()); - } - - private void help(Player player) { - player.sendMessage(SchematicSystem.PREFIX + "Befehle§8:"); - player.sendMessage("§8/§eschem gui §8- §7Öffnet die Schematic-GUI"); - player.sendMessage("§8/§eschem list §8- §7Zeigt dir deine Schematics an"); - player.sendMessage("§8/§eschem list public §8- §7Zeigt alle Public-Schematics"); - player.sendMessage("§8/§eschem search §8[§7Stichwort§8] - §7Sucht nach passenden Schematics"); - player.sendMessage("§8/§eschem load §8[§7Schematic§8] - §7Lädt eine Schematic"); - player.sendMessage("§8/§eschem save §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic"); - player.sendMessage("§8/§eschem changetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic"); - player.sendMessage("§8/§eschem delete §8[§7Schematic§8] - §7Löscht eine Schematic"); - player.sendMessage("§8/§eschem info §8[§7Schematic§8] - §7Zeigt dir Informationen zur Schematic"); - player.sendMessage("§8/§eschem download §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig)"); - player.sendMessage("§8/§eschem addmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Fügt einen Spieler zu einer Schematic hinzu"); - player.sendMessage("§8/§eschem delmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic"); - } - - private void sendPlayerSchematicList(int currentPage, Player player, String precommand, List schematicList) { + @Register("move") + public void renameMove(Player player, SchematicNode node, @Mapper("dirStringMapper") String name) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - - if(schematicList.isEmpty()) { - player.sendMessage(SchematicSystem.PREFIX + "§cKeine Schematics gefunden"); + if(node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); return; } + if(name.startsWith("/")) name = name.substring(1); + if(name.endsWith("/")) name = name.substring(0, name.length()-1); + String[] layers = name.split("/"); + if(invalidSchemName(player, layers)) return; + if(name.contains("/")) { + SchematicNode newNode = mkdirs(layers, user, 1); + node.setParent(newNode.getId()); + } else { + node.setParent(0); + } + String schemName = layers[layers.length-1]; + node.setName(schemName); + player.sendMessage(SchematicSystem.PREFIX + "§7Die Schematic heist nun §7" + node.generateBreadcrumbs(user)); + } - int pages; + private boolean invalidSchemName(Player player, String[] layers){ + for (String layer : layers) { + if(layer.isEmpty()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDeine Ordner brauchen schon einen Namen!"); + return true; + } + if(layer.contains("/") || + layer.contains("\\") || + layer.contains("<") || + layer.contains(">") || + layer.contains("^") || + layer.contains("°") || + layer.contains("'") || + layer.contains("\"")){ + player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematicname enthält verbotene Zeichen"); + return true; + } + } + return false; + } - double doublePages = schematicList.size() / (double) FILES_PER_PAGE; - int intPages = schematicList.size() / FILES_PER_PAGE; + private SchematicNode mkdirs(String[] layers, SteamwarUser user, int minus) { + SchematicNode currentNode = null; + for (int i = 0; i < layers.length - minus; i++) { + int finalI = i; + List nodes; + if(currentNode == null) { + nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList()); + } else { + nodes = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList()); + } + if(nodes.isEmpty()) { + currentNode = SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode==null?0:currentNode.getId()); + } else { + currentNode = nodes.get(0); + } + } + return currentNode; + } - if(schematicList.size() <= FILES_PER_PAGE) { - pages = 1; - }else if(doublePages > intPages){ - pages = (intPages + 1); - }else - pages = intPages; + private void renderSchemlist(Player player, List nodes, int chunk, String breadcrumbs, boolean isPublic) { + nodes.sort(Comparator.comparing(SchematicNode::getName)); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE); - if(currentPage >= pages || currentPage < 0) return; + player.sendMessage("§7--==( §eSchematics §8(§e" + nodes.size() + "§8) §7)==--"); + player.sendMessage("§7Aktueller Pfad: §e" + (breadcrumbs.isEmpty()?"/":breadcrumbs)); + if(!breadcrumbs.isEmpty()) { + TextComponent back = new TextComponent("§e../"); + String str = breadcrumbs.substring(0, Math.max(0, breadcrumbs.substring(0, breadcrumbs.length() - 1).lastIndexOf("/"))); + back.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eZurück gehen" + str).create())); + back.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic?"public":"") + " " + str)); - player.sendMessage("§eSeite " + (currentPage + 1) + " §8/ " + pages + " §8| §e" + schematicList.size() + " Schematics"); + player.spigot().sendMessage(back); + } + for (int i = chunk * CHUNK_SIZE; i < nodes.size() && i < (chunk + 1) * CHUNK_SIZE; i++) { + SchematicNode node = nodes.get(i); - for(int i = currentPage * FILES_PER_PAGE; i < (currentPage * FILES_PER_PAGE) + FILES_PER_PAGE; i++) { - if(schematicList.size() <= i) break; + StringBuilder nodeString = new StringBuilder(); - Schematic schematic = schematicList.get(i); + if(node.isDir()) { + nodeString.append("§9DIR §e"); + } else { + SchematicType type = node.getSchemtype(); + if(type != SchematicType.Normal) { + nodeString.append("§8§l") + .append(type.getKuerzel().toUpperCase()) + .append(" "); + } + nodeString.append("§e"); + } - String schematicPlayer = ""; - if(schematic.getSchemOwner() != user.getId()) - schematicPlayer = " §8von §7" + SteamwarUser.get(schematic.getSchemOwner()).getUserName(); + nodeString.append(node.getName()); - TextComponent schematics = new TextComponent("§e" + schematic.getSchemType().getKuerzel() + " §7" + schematic.getSchemName() + schematicPlayer); - schematics.setBold(true); + if(node.isDir()) { + nodeString.append("/"); + } - schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create())); - schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + schematic.getSchemName())); + if(node.getOwner() != user.getId()) { + nodeString.append(" §8von §7") + .append(SteamwarUser.get(node.getOwner()).getUserName()); + } + TextComponent schematics = new TextComponent(nodeString.toString()); + + if(node.isDir()) { + schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eOrdner anzeigen").create())); + schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic?"public":"") + " " + breadcrumbs + node.getName() + "/")); + } else { + schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create())); + schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (isPublic?"public":"") + " " + breadcrumbs + node.getName())); + } player.spigot().sendMessage(schematics); } - if(pages <= 1) return; - TextComponent beforePage = new TextComponent("««"); - if(currentPage > 0){ + if(chunk > 0){ beforePage.setColor(ChatColor.YELLOW); beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eVorherige Seite").create())); - beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, precommand + (currentPage - 1))); + beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic?"public":"") + " " + breadcrumbs + " " + (chunk - 1))); }else beforePage.setColor(ChatColor.RED); - TextComponent nextPage = new TextComponent(" Seite »»"); - if(currentPage < pages-1){ + TextComponent nextPage = new TextComponent(" Seite (" + (chunk + 1) + "/" + Math.max(pageCount, 1) + ") »»"); + if(chunk < pageCount-1){ nextPage.setColor(ChatColor.YELLOW); nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eNächste Seite").create())); - nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, precommand + (currentPage + 1))); + nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic?"public":"") + " " + breadcrumbs + " " + (chunk + 1))); }else nextPage.setColor(ChatColor.RED); beforePage.addExtra(nextPage); player.spigot().sendMessage(beforePage); } + + private final TypeMapper schematicCommandTypeMapper = nodeTypeMapper(); + private final TypeMapper publicCommandTypeMapper = publicNodeTypeMapper(); + + @Mapper("memberMapper") + public TypeMapper nodeMemberTypeMapper() { + return new TypeMapper() { + @Override + public NodeMember map(CommandSender commandSender, String[] previousArguments, String s) { + SchematicNode node = schematicCommandTypeMapper.map(commandSender, previousArguments, previousArguments[previousArguments.length - 1]); + SteamwarUser user = SteamwarUser.get(s); + return NodeMember.getNodeMember(node.getId(), user.getId()); + } + + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + List list = new ArrayList<>(); + SchematicNode node = schematicCommandTypeMapper.map(commandSender, strings, strings[strings.length - 1]); + if(node == null) { + return list; + } + node.getMembers().forEach(nodeMember -> list.add(SteamwarUser.get(nodeMember.getMember()).getUserName())); + return list; + } + }; + } + + @Mapper("publicMapper") + public TypeMapper publicNodeTypeMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return getNodeTabcomplete(SteamwarUser.get(0), strings, s); + } + + @Override + public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { + return mapNode(SteamwarUser.get(0), previousArguments, s); + } + }; + } + + @Mapper("dirMapper") + public TypeMapper dirNodeTypeMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + List list = schematicCommandTypeMapper.tabCompletes(commandSender, strings, s); + list.removeIf(s1 -> !s1.endsWith("/")); + return list; + } + + @Override + public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { + SchematicNode result = schematicCommandTypeMapper.map(commandSender, previousArguments, s); + if(result == null || !result.isDir()) { + return null; + } else { + return result; + } + } + }; + } + + @Mapper("publicDirMapper") + public TypeMapper publicDirNodeTypeMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + List list = publicCommandTypeMapper.tabCompletes(commandSender, strings, s); + list.removeIf(s1 -> !s1.endsWith("/")); + return list; + } + + @Override + public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { + SchematicNode result = publicCommandTypeMapper.map(commandSender, previousArguments, s); + if(result == null || !result.isDir()) { + return null; + } else { + return result; + } + } + }; + } + + private static List getNodeTabcomplete(SteamwarUser user, String[] strings, String s) { + List list = new ArrayList<>(); + boolean sws = s.startsWith("/"); + if(sws) { + s = s.substring(1); + } + if(s.contains("/")) { + String preTab = s.substring(0, s.lastIndexOf("/") + 1); + SchematicNode pa = mapNode(user, strings, preTab); + if(pa == null) return Collections.emptyList(); + List nodes = SchematicNode.getSchematicNodeInNode(pa); + nodes.forEach(node -> list.add(node.generateBreadcrumbs(user))); + } else { + List nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0); + nodes.forEach(node -> list.add((sws ?"/":"") + node.getName() + (node.isDir()?"/":""))); + } + list.remove("//copy"); + return list; + } + + private static SchematicNode mapNode(SteamwarUser user, String[] previousArguments, String s) { + if(s.startsWith("/")) { + s = s.substring(1); + } + if(s.isEmpty()) { + return null; + } + if(s.contains("/")) { + String[] layers = s.split("/"); + SchematicNode currentNode = null; + for (int i = 0; i < layers.length; i++) { + int finalI = i; + List nodes; + if(currentNode == null) { + nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList()); + } else { + nodes = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList()); + } + if(nodes.isEmpty()) { + return null; + } else { + currentNode = nodes.get(0); + if(!currentNode.isDir() && i != layers.length-1) { + return null; + } + } + } + return currentNode; + } else { + String finalS = s; + List nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(finalS)).collect(Collectors.toList()); + if(nodes.isEmpty()) { + return null; + } else { + return nodes.get(0); + } + } + } + + @ClassMapper(SchematicNode.class) + public TypeMapper nodeTypeMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), strings, s); + } + + @Override + public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { + return mapNode(SteamwarUser.get(((Player) commandSender).getUniqueId()), previousArguments, s); + } + }; + } + + @ClassMapper(SchematicType.class) + public TypeMapper typeTypeMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return SchematicType.values().stream().filter(SchematicType::isAssignable).map(SchematicType::name).collect(Collectors.toList()); + } + + @Override + public SchematicType map(CommandSender commandSender, String[] previousArguments, String s) { + return SchematicType.values().stream().filter(type -> type.name().equals(s)).collect(Collectors.toList()).get(0); + } + }; + } + + @Mapper("dirStringMapper") + public TypeMapper stringTabMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), strings, s); + } + + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + return s; + } + }; + } + } diff --git a/SchematicSystem_Main/src/plugin.yml b/SchematicSystem_Main/src/plugin.yml index 654bc59..3855305 100644 --- a/SchematicSystem_Main/src/plugin.yml +++ b/SchematicSystem_Main/src/plugin.yml @@ -1,14 +1,15 @@ name: SchematicSystem -version: "1.0" -authors: [Yaruma3341, Lixfel] +version: "2.0" +authors: [Yaruma3341, Lixfel, Chaoscaot] depend: [SpigotCore, WorldEdit] main: de.steamwar.schematicsystem.SchematicSystem +website: steamwar.de api-version: "1.13" commands: - schem: - aliases: - - schematic - - /schematic - - /schem + #schem: + # aliases: + # - schematic + # - /schematic + # - /schem check: \ No newline at end of file