From df2db0d63dbbe0efc2f5b3d688b43674d5f1ed2a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 13 Jul 2021 15:46:40 +0200 Subject: [PATCH 01/28] 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 From ad5e7f977b722ca66f2b2bb52a8c86f539c62fce Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 13 Jul 2021 15:47:56 +0200 Subject: [PATCH 02/28] Imports --- .../src/de/steamwar/schematicsystem/CheckSchemType_12.java | 1 - .../src/de/steamwar/schematicsystem/CheckSchemType_15.java | 1 - 2 files changed, 2 deletions(-) diff --git a/SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java b/SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java index 8b7af2e..9839d29 100644 --- a/SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java +++ b/SchematicSystem_12/src/de/steamwar/schematicsystem/CheckSchemType_12.java @@ -25,7 +25,6 @@ import com.sk89q.worldedit.blocks.BaseBlock; 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; diff --git a/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java b/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java index 18f4b06..c3b32f3 100644 --- a/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java +++ b/SchematicSystem_15/src/de/steamwar/schematicsystem/CheckSchemType_15.java @@ -25,7 +25,6 @@ import com.sk89q.worldedit.math.BlockVector3; 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; From 2f9cdff26dffb558481ed771f8f2e4eb84461677 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 25 Jul 2021 18:50:31 +0200 Subject: [PATCH 03/28] More Refactoring Signed-off-by: Chaoscaot --- .../commands/SchematicCommand.java | 647 +++++++++++------- 1 file changed, 386 insertions(+), 261 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 8422601..527c23e 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -39,7 +39,6 @@ import org.bukkit.entity.Player; import java.time.format.DateTimeFormatter; import java.util.*; -import java.util.List; import java.util.logging.Level; import java.util.stream.Collectors; @@ -51,23 +50,24 @@ public class SchematicCommand extends SWCommand { super("schematic", "/schematic", "schem", "/schem"); } - @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"); + 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; } @Register("gui") @@ -87,24 +87,66 @@ public class SchematicCommand extends SWCommand { 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"); + 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 { - renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), 0, node.generateBreadcrumbs(user), node.getOwner()==0); + 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); + } } } - @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(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 clearmember §8[§7Schematic§8] - §7Entfernt alle Spieler von der Schematic"); + player.sendMessage("§8/§eschem mkdir §8[§7Ordner§8] - §7Erstelle einen Leeren Ordner"); + player.sendMessage("§8/§eschem move §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic"); + player.sendMessage("§8/§eschem rename §8[§7Schematic§8] [§7Neuer Name§8] - §7Gib der Schematic einen neuen Namen"); + player.sendMessage("§8/§eschem addteam §8[§7Schematic§8] - §7Füge jeden aus deinem Team auf die Schematic hinzu"); + player.sendMessage("§8/§eschem remteam §8[§7Schematic§8] - §7Entferne jeden aus deinem Team von der Schematic"); } @Register({"list", "public"}) @@ -135,20 +177,54 @@ public class SchematicCommand extends SWCommand { schemInfo(player, node); } + @Register("list") + public void schemList(Player player, @Mapper("dirMapper") SchematicNode node) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (!node.isDir()) { + player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner"); + } else { + renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), 0, node.generateBreadcrumbs(user), node.getOwner() == 0); + } + } + + @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("list") + public void schemList(Player player, @Mapper("dirMapper") SchematicNode node, int page) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (!node.isDir()) { + player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner"); + } else { + renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), page, node.generateBreadcrumbs(user), node.getOwner() == 0); + } + } + + @Register({"l", "public"}) + @Register({"load", "public"}) + public void loadSchemPublic(Player player, @Mapper("publicMapper") SchematicNode node) { + loadSchem(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("§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("§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")); + player.sendMessage("§7Format: §e" + (node.getSchemFormat() ? ".schem" : ".schematic")); List checkedSchematics = CheckedSchematic.getLastDeclined(player.getUniqueId()); for (CheckedSchematic checkedSchematic : checkedSchematics) { if (checkedSchematic.getSchemName().equals(node.getName()) && @@ -160,29 +236,35 @@ public class SchematicCommand extends SWCommand { } 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 (!schematicMembers.isEmpty()) { + player.sendMessage("§7Mitglieder: §e" + schematicMembers); } TextComponent base = new TextComponent(); - if(!node.isDir()) { + 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))); + 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()) { + 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); + + TextComponent changeTyp = new TextComponent("[Typ ändern] "); + changeTyp.setColor(ChatColor.BLUE); + changeTyp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eSchematic Typ ändern"))); + changeTyp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem changetype " + node.generateBreadcrumbs(user))); + base.addExtra(changeTyp); } } - if(node.getOwner() == user.getId()) { + 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"))); @@ -195,30 +277,32 @@ public class SchematicCommand extends SWCommand { delMember.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem delmember " + node.generateBreadcrumbs(user) + " ")); base.addExtra(delMember); - TextComponent delete = new TextComponent("[Delete] "); + TextComponent move = new TextComponent("[Verschieben] "); + move.setColor(ChatColor.DARK_PURPLE); + move.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " verschieben"))); + move.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem move " + node.generateBreadcrumbs(user) + " " + node.generateBreadcrumbs(user).replace("/" + node.getName(), ""))); + base.addExtra(move); + + TextComponent rename = new TextComponent("[Umbenennen] "); + rename.setColor(ChatColor.LIGHT_PURPLE); + rename.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " umbenennen"))); + rename.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem rename " + node.generateBreadcrumbs(user) + " [Neuer Name]")); + base.addExtra(rename); + + TextComponent delete = new TextComponent("[Löschen] "); delete.setColor(ChatColor.DARK_RED); - delete.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir()?"Ordner":"Schematic") + " Löschen"))); + 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()) { + if (node.isDir()) { player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst keine Ordner Laden"); return; } @@ -226,7 +310,7 @@ public class SchematicCommand extends SWCommand { try { 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()}); + 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) { @@ -235,78 +319,73 @@ public class SchematicCommand extends SWCommand { } } - @Register({"l", "public"}) - @Register({"load", "public"}) - public void loadSchemPublic(Player player, @Mapper("publicMapper") SchematicNode node) { - loadSchem(player, node); - } - @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); + if (name.startsWith("/")) name = name.substring(1); String[] layers = name.split("/"); - if(invalidSchemName(player, layers)) return; + if (invalidSchemName(player, layers)) return; SchematicNode currentNode = mkdirs(layers, user, 1); - SchematicNode node = SchematicNode.getSchematicInParent(layers[layers.length-1], currentNode==null?0:currentNode.getId()); - if(node != null && !node.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(node == null) { + if (node == null) { newSchem = true; - node = SchematicNode.createSchematic(user.getId(), layers[layers.length-1], currentNode==null?0:currentNode.getId()); + node = SchematicNode.createSchematic(user.getId(), layers[layers.length - 1], currentNode == null ? 0 : currentNode.getId()); } try { node.saveFromPlayer(player); - }catch (NoClipboardException e) { + } catch (NoClipboardException e) { player.sendMessage(SchematicSystem.PREFIX + "§cDein Clipboard ist leer"); - if(newSchem) + if (newSchem) node.delete(); return; - }catch(Exception ex){ + } catch (Exception ex) { Bukkit.getLogger().log(Level.SEVERE, "Could not save schematic", ex); player.sendMessage(SchematicSystem.PREFIX + "§cFehler beim Speichern der Schematic."); - if(newSchem) + if (newSchem) node.delete(); return; } - if (newSchem) + if (newSchem) { player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + node.getName() + " §7gespeichert"); - else + } else { player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + node.getName() + " §7überschrieben"); + } } @Register("addmember") public void addMember(Player player, SchematicNode node, SteamwarUser target) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if(node.getOwner() != user.getId()) { + if (node.getOwner() != user.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur auf deine eigenen Sachen jemanden hinzufügen."); return; } - if(user.getId() == target.getId()) { + if (user.getId() == target.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cAlso bitte: Das ist deine eigene Schematic!"); return; } - NodeMember member = NodeMember.getNodeMember(node.getId(), target.getId()); - if(member != null) { + if (NodeMember.getNodeMember(node.getId(), target.getId()) != null) { player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler ist bereits auf diese Schematic geaddet"); return; } - member = NodeMember.createNodeMember(node.getId(), target.getId()); + 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)); Player t = Bukkit.getPlayer(target.getUUID()); - if(t != null) + if (t != null) { t.sendMessage(SchematicSystem.PREFIX + "Du hast nun Zugriff auf die Schematic §e" + node.getName() + " §7von §e" + player.getName()); + } } @Register("delmember") @@ -314,7 +393,7 @@ public class SchematicCommand extends SWCommand { public void delMember(Player player, SchematicNode node, @Mapper("memberMapper") NodeMember member) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if(node.getOwner() != user.getId()) { + if (node.getOwner() != user.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur auf deine eigenen Sachen jemanden entfernen."); return; } @@ -322,40 +401,15 @@ public class SchematicCommand extends SWCommand { member.delete(); List nodes = SchematicNode.deepGet(node.getId(), node1 -> node1.getOwner() != user.getId()); - if(!nodes.isEmpty()) { + 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()); + 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()); @@ -371,13 +425,38 @@ public class SchematicCommand extends SWCommand { }); } + @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("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; + if (!type.isAssignable()) return; TextComponent component = new TextComponent(type.name() + " "); component.setColor(ChatColor.GRAY); @@ -392,90 +471,186 @@ public class SchematicCommand extends SWCommand { @Register("changetype") public void changeType(Player player, SchematicNode node, SchematicType type) { - if(node.isDir()) { + changeType(player, node, type, null); + } + + @Register("changetype") + public void changeType(Player player, SchematicNode node, SchematicType type, Extend extend) { + if (node.isDir()) { player.sendMessage(SchematicSystem.PREFIX + "§cOrdner haben keinen Typen."); return; } - if(node.getType().equals(type.toDB())) { + if (node.getType().equals(type.toDB())) { player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic hat schon diesen Typen"); return; } - if(type.writeable()) { + if (type.writeable()) { node.setType(type.toDB()); player.sendMessage(SchematicSystem.PREFIX + "§aSchematictyp geändert"); - } else if(type.fightType()) { - if(node.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(node); Collection errors = result.errors(); - for(String warning : result.warnings()){ + for (String warning : result.warnings()) { player.sendMessage(" §e" + warning); } - for(String error : errors){ + for (String error : errors) { player.sendMessage(" §c" + error); } - if(!errors.isEmpty()){ + if (!errors.isEmpty()) { player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic ist nicht regelkonform"); return; } - SWInventory inv = new SWInventory(player, 9, "Schematic ausfahren"); - inv.setItem(0, SWItem.getDye(10), (byte)10, "§eSchematic ausfahren", click -> { + if (extend == null) { + 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()), 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 -> { + node.setType(type.checkType().toDB()); + player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft"); + player.closeInventory(); + }); + inv.setCallback(-999, click -> player.closeInventory()); + inv.open(); + } else if (extend == Extend.AUSFAHREN) { 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 -> { - node.setType(type.checkType().toDB()); - player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft"); - player.closeInventory(); - }); - inv.setCallback(-999, click -> player.closeInventory()); - inv.open(); + } } } @Register("move") - public void renameMove(Player player, SchematicNode node, @Mapper("dirStringMapper") String name) { + public void move(Player player, SchematicNode node, @Mapper("dirStringMapper") String name) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if(node.getOwner() != user.getId()) { + 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 { + if (name.equals("/")) { node.setParent(0); + } else { + 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 newNode = mkdirs(layers, user, 0); + node.setParent(newNode.getId()); } - String schemName = layers[layers.length-1]; - node.setName(schemName); - player.sendMessage(SchematicSystem.PREFIX + "§7Die Schematic heist nun §7" + node.generateBreadcrumbs(user)); + player.sendMessage(SchematicSystem.PREFIX + "§7Die Schematic ist nun unter §e" + node.generateBreadcrumbs(user) + " §7zu finden"); } - private boolean invalidSchemName(Player player, String[] layers){ + @Register("rename") + public void rename(Player player, SchematicNode node, String name) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); + return; + } + if (invalidSchemName(player, new String[]{name})) { + return; + } + node.setName(name); + player.sendMessage(SchematicSystem.PREFIX + "§7Die Schematic heist nun §e" + node.generateBreadcrumbs(user)); + } + + @Register("addteam") + public void addTeam(Player player, SchematicNode node) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); + return; + } + Team team = Team.get(user.getTeam()); + if (team == null) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu bist in keinem Team"); + return; + } + + List added = new ArrayList<>(); + for (Integer member : team.getMembers()) { + if (user.getId() == member) continue; + if (NodeMember.getNodeMember(node.getId(), member) == null) { + NodeMember.createNodeMember(node.getId(), member); + added.add(SteamwarUser.get(member).getUserName()); + } + } + + Optional reduced = added.stream().reduce((s, s2) -> s + ", " + s2); + if (reduced.isPresent()) { + player.sendMessage(SchematicSystem.PREFIX + "§7Die Spieler §e" + reduced.get() + " §7wurden auf die Schematic hinzugefügt"); + } else { + player.sendMessage(SchematicSystem.PREFIX + "§7Es wurde kein Spieler hinzugefügt"); + } + } + + @Register("remteam") + public void remTeam(Player player, SchematicNode node) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); + return; + } + Team team = Team.get(user.getTeam()); + if (team == null) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu bist in keinem Team"); + return; + } + + List removed = new ArrayList<>(); + for (Integer member : team.getMembers()) { + if (user.getId() == member) continue; + NodeMember nodeMember = NodeMember.getNodeMember(node.getId(), member); + if (nodeMember != null) { + nodeMember.delete(); + removed.add(SteamwarUser.get(member).getUserName()); + } + } + + Optional reduced = removed.stream().reduce((s, s2) -> s + ", " + s2); + if (reduced.isPresent()) { + player.sendMessage(SchematicSystem.PREFIX + "§7Die Spieler §e" + reduced.get() + " §7wurden von der Schematic entfernt"); + } else { + player.sendMessage(SchematicSystem.PREFIX + "§7Es wurde kein Spieler entfernt"); + } + } + + @Register("remallmember") + @Register("clearmember") + public void clearMember(Player player, SchematicNode node) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); + return; + } + + node.getMembers().forEach(NodeMember::delete); + player.sendMessage(SchematicSystem.PREFIX + "§7Alle Spieler wurden von der Schematic entfernt"); + } + + private boolean invalidSchemName(Player player, String[] layers) { for (String layer : layers) { - if(layer.isEmpty()) { + if (layer.isEmpty()) { player.sendMessage(SchematicSystem.PREFIX + "§cDeine Ordner brauchen schon einen Namen!"); return true; } - if(layer.contains("/") || + if (layer.contains("/") || 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; } @@ -488,13 +663,13 @@ public class SchematicCommand extends SWCommand { for (int i = 0; i < layers.length - minus; i++) { int finalI = i; List nodes; - if(currentNode == null) { + 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()); + if (nodes.isEmpty()) { + currentNode = SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode == null ? 0 : currentNode.getId()); } else { currentNode = nodes.get(0); } @@ -502,18 +677,21 @@ public class SchematicCommand extends SWCommand { return currentNode; } + private final TypeMapper schematicCommandTypeMapper = nodeTypeMapper(); + private final TypeMapper publicCommandTypeMapper = publicNodeTypeMapper(); + 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); player.sendMessage("§7--==( §eSchematics §8(§e" + nodes.size() + "§8) §7)==--"); - player.sendMessage("§7Aktueller Pfad: §e" + (breadcrumbs.isEmpty()?"/":breadcrumbs)); - if(!breadcrumbs.isEmpty()) { + 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)); + back.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + str)); player.spigot().sendMessage(back); } @@ -522,11 +700,11 @@ public class SchematicCommand extends SWCommand { StringBuilder nodeString = new StringBuilder(); - if(node.isDir()) { + if (node.isDir()) { nodeString.append("§9DIR §e"); } else { SchematicType type = node.getSchemtype(); - if(type != SchematicType.Normal) { + if (type != SchematicType.Normal) { nodeString.append("§8§l") .append(type.getKuerzel().toUpperCase()) .append(" "); @@ -536,73 +714,49 @@ public class SchematicCommand extends SWCommand { nodeString.append(node.getName()); - if(node.isDir()) { + if (node.isDir()) { nodeString.append("/"); } - if(node.getOwner() != user.getId()) { + if (node.getOwner() != user.getId()) { nodeString.append(" §8von §7") .append(SteamwarUser.get(node.getOwner()).getUserName()); } TextComponent schematics = new TextComponent(nodeString.toString()); - if(node.isDir()) { + 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() + "/")); + 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())); + schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (isPublic ? "public" : "") + " " + breadcrumbs + node.getName())); } player.spigot().sendMessage(schematics); } TextComponent beforePage = new TextComponent("««"); - if(chunk > 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, "/schem list " + (isPublic?"public":"") + " " + breadcrumbs + " " + (chunk - 1))); - }else + 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 (" + (chunk + 1) + "/" + Math.max(pageCount, 1) + ") »»"); - if(chunk < 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, "/schem list " + (isPublic?"public":"") + " " + breadcrumbs + " " + (chunk + 1))); - }else + 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() { @@ -618,6 +772,29 @@ public class SchematicCommand extends SWCommand { }; } + @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("dirMapper") public TypeMapper dirNodeTypeMapper() { return new TypeMapper() { @@ -631,7 +808,7 @@ public class SchematicCommand extends SWCommand { @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { SchematicNode result = schematicCommandTypeMapper.map(commandSender, previousArguments, s); - if(result == null || !result.isDir()) { + if (result == null || !result.isDir()) { return null; } else { return result; @@ -653,7 +830,7 @@ public class SchematicCommand extends SWCommand { @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { SchematicNode result = publicCommandTypeMapper.map(commandSender, previousArguments, s); - if(result == null || !result.isDir()) { + if (result == null || !result.isDir()) { return null; } else { return result; @@ -662,63 +839,21 @@ public class SchematicCommand extends SWCommand { }; } - 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; - } + @Mapper("dirStringMapper") + public TypeMapper stringTabMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + List list = getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), strings, s); + list.removeIf(s1 -> !s1.endsWith("/")); + 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; - } - } + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + return s; } - 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) @@ -751,19 +886,9 @@ public class SchematicCommand extends SWCommand { }; } - @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; - } - }; + enum Extend { + AUSFAHREN, + NORMAL } } From d59dc62284d6097f84b05b76f60de0c88be95442 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 25 Jul 2021 20:15:49 +0200 Subject: [PATCH 04/28] Some more refactor Signed-off-by: Chaoscaot --- SchematicSystem_Main/pom.xml | 1 + .../steamwar/schematicsystem/commands/SchematicCommand.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/SchematicSystem_Main/pom.xml b/SchematicSystem_Main/pom.xml index cae6f72..17cb6e0 100644 --- a/SchematicSystem_Main/pom.xml +++ b/SchematicSystem_Main/pom.xml @@ -19,6 +19,7 @@ jar + clean verify -U src diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 527c23e..61b6aff 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -671,6 +671,9 @@ public class SchematicCommand extends SWCommand { if (nodes.isEmpty()) { currentNode = SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode == null ? 0 : currentNode.getId()); } else { + if (!nodes.get(0).isDir()) { + nodes.set(0, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode == null ? 0 : currentNode.getId())); + } currentNode = nodes.get(0); } } @@ -890,5 +893,4 @@ public class SchematicCommand extends SWCommand { AUSFAHREN, NORMAL } - } From 1758b4b9aa47f06fceb01ac3aab0129345820407 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 26 Jul 2021 19:57:00 +0200 Subject: [PATCH 05/28] More [TM] Signed-off-by: Chaoscaot --- SchematicSystem_Main/pom.xml | 9 -- .../schematicsystem/CheckSchemType.java | 1 - .../commands/SchematicCommand.java | 118 +++++++++--------- SchematicSystem_Main/src/plugin.yml | 5 - 4 files changed, 59 insertions(+), 74 deletions(-) diff --git a/SchematicSystem_Main/pom.xml b/SchematicSystem_Main/pom.xml index 17cb6e0..4b5ab42 100644 --- a/SchematicSystem_Main/pom.xml +++ b/SchematicSystem_Main/pom.xml @@ -48,15 +48,6 @@ schematicsystem - - - - maven-restlet - Public online Restlet repository - http://maven.restlet.org - - - steamwar diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java index 4858dfe..1cfb616 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/CheckSchemType.java @@ -20,7 +20,6 @@ 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; diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 61b6aff..9da5f6a 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -50,26 +50,6 @@ public class SchematicCommand extends SWCommand { super("schematic", "/schematic", "schem", "/schem"); } - 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; - } - @Register("gui") public void gui(Player player) { GUI.open(player); @@ -87,45 +67,6 @@ public class SchematicCommand extends SWCommand { renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId(), 0), page, "", false); } - 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); - } - } - } - @Register(help = true) public void genericHelp(Player player, String... args) { player.sendMessage(SchematicSystem.PREFIX + "Befehle§8:"); @@ -893,4 +834,63 @@ public class SchematicCommand extends SWCommand { AUSFAHREN, NORMAL } + + 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); + } + } + } } diff --git a/SchematicSystem_Main/src/plugin.yml b/SchematicSystem_Main/src/plugin.yml index 3855305..9670206 100644 --- a/SchematicSystem_Main/src/plugin.yml +++ b/SchematicSystem_Main/src/plugin.yml @@ -7,9 +7,4 @@ website: steamwar.de api-version: "1.13" commands: - #schem: - # aliases: - # - schematic - # - /schematic - # - /schem check: \ No newline at end of file From 7c300f366fa66b16bb1fc8873c4a0ac9ccb18527 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 27 Jul 2021 11:56:42 +0200 Subject: [PATCH 06/28] Refactoring!!!11 Signed-off-by: Chaoscaot --- .../schematicsystem/SchematicSystem.java | 12 +- .../commands/SchematicCommand.java | 359 +++--------------- .../commands/SchematicCommandHelp.java | 89 +++++ .../commands/SchematicCommandUtils.java | 332 ++++++++++++++++ 4 files changed, 487 insertions(+), 305 deletions(-) create mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java create mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java index f83a249..9c77aaa 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/SchematicSystem.java @@ -20,13 +20,17 @@ package de.steamwar.schematicsystem; import de.steamwar.schematicsystem.commands.SchematicCommand; +import de.steamwar.schematicsystem.commands.SchematicCommandUtils; import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.util.logging.Level; -public class SchematicSystem extends JavaPlugin { +public class SchematicSystem extends JavaPlugin implements Listener { public static final String PREFIX = "§eSchematic§8» §7"; public static SchematicSystem INSTANCE; @@ -41,6 +45,12 @@ public class SchematicSystem extends JavaPlugin { } CheckSchemType.init(getConfig()); + Bukkit.getPluginManager().registerEvents(this, this); SCHEMATIC_COMMAND = new SchematicCommand(); } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + SchematicCommandUtils.turnOffPublic(event.getPlayer()); + } } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 9da5f6a..21e3e8e 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -37,19 +37,30 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.time.format.DateTimeFormatter; import java.util.*; import java.util.logging.Level; import java.util.stream.Collectors; -public class SchematicCommand extends SWCommand { +import static de.steamwar.schematicsystem.commands.SchematicCommandHelp.*; +import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*; - private static final int CHUNK_SIZE = 15; +public class SchematicCommand extends SWCommand { public SchematicCommand() { super("schematic", "/schematic", "schem", "/schem"); } + @Register(help = true) + @Register("help") + public void genericHelp(Player player, String... args) { + printHelpMainPage(player); + } + + @Register("help") + public void pagedHelp(Player player, HelpPage page) { + printHelpPage(player, page); + } + @Register("gui") public void gui(Player player) { GUI.open(player); @@ -58,36 +69,13 @@ public class SchematicCommand extends SWCommand { @Register("list") @Register({"list", "/"}) public void schemList(Player player) { - renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId(), 0), 0, "", false); + renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).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(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 clearmember §8[§7Schematic§8] - §7Entfernt alle Spieler von der Schematic"); - player.sendMessage("§8/§eschem mkdir §8[§7Ordner§8] - §7Erstelle einen Leeren Ordner"); - player.sendMessage("§8/§eschem move §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic"); - player.sendMessage("§8/§eschem rename §8[§7Schematic§8] [§7Neuer Name§8] - §7Gib der Schematic einen neuen Namen"); - player.sendMessage("§8/§eschem addteam §8[§7Schematic§8] - §7Füge jeden aus deinem Team auf die Schematic hinzu"); - player.sendMessage("§8/§eschem remteam §8[§7Schematic§8] - §7Entferne jeden aus deinem Team von der Schematic"); + renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), 0), page, "", false); } @Register({"list", "public"}) @@ -120,7 +108,7 @@ public class SchematicCommand extends SWCommand { @Register("list") public void schemList(Player player, @Mapper("dirMapper") SchematicNode node) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (!node.isDir()) { player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner"); } else { @@ -132,13 +120,13 @@ public class SchematicCommand extends SWCommand { 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("§7Von dir einsehbar: §e" + SchematicNode.getAllSchematicsAccessibleByUser(getUser(player).getId()).size()); player.sendMessage("§7Autoren: §e" + Arrays.toString(SchematicSystem.INSTANCE.getDescription().getAuthors().toArray())); } @Register("list") public void schemList(Player player, @Mapper("dirMapper") SchematicNode node, int page) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (!node.isDir()) { player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner"); } else { @@ -154,90 +142,7 @@ public class SchematicCommand extends SWCommand { @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); - } - - TextComponent base = new TextComponent(); - - 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); - - TextComponent changeTyp = new TextComponent("[Typ ändern] "); - changeTyp.setColor(ChatColor.BLUE); - changeTyp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eSchematic Typ ändern"))); - changeTyp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem changetype " + node.generateBreadcrumbs(user))); - base.addExtra(changeTyp); - } - } - - 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 move = new TextComponent("[Verschieben] "); - move.setColor(ChatColor.DARK_PURPLE); - move.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " verschieben"))); - move.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem move " + node.generateBreadcrumbs(user) + " " + node.generateBreadcrumbs(user).replace("/" + node.getName(), ""))); - base.addExtra(move); - - TextComponent rename = new TextComponent("[Umbenennen] "); - rename.setColor(ChatColor.LIGHT_PURPLE); - rename.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " umbenennen"))); - rename.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem rename " + node.generateBreadcrumbs(user) + " [Neuer Name]")); - base.addExtra(rename); - - TextComponent delete = new TextComponent("[Löschen] "); - 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); + printSchemInfo(player, node); } @Register("l") @@ -263,7 +168,7 @@ public class SchematicCommand extends SWCommand { @Register("save") @Register("s") public void saveSchem(Player player, @Mapper("dirStringMapper") String name) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (name.startsWith("/")) name = name.substring(1); String[] layers = name.split("/"); if (invalidSchemName(player, layers)) return; @@ -305,7 +210,7 @@ public class SchematicCommand extends SWCommand { @Register("addmember") public void addMember(Player player, SchematicNode node, SteamwarUser target) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur auf deine eigenen Sachen jemanden hinzufügen."); return; @@ -332,7 +237,7 @@ public class SchematicCommand extends SWCommand { @Register("delmember") @Register("remmember") public void delMember(Player player, SchematicNode node, @Mapper("memberMapper") NodeMember member) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur auf deine eigenen Sachen jemanden entfernen."); @@ -353,7 +258,7 @@ public class SchematicCommand extends SWCommand { @Register("search") public void schemSearch(Player player, String quarry) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); List nodes = SchematicNode.filterSchems(user.getId(), node -> node.getName().contains(quarry)); player.sendMessage("§7--==( §eSchematics §8(§e" + nodes.size() + "§8) §7)==--"); nodes.forEach(node -> { @@ -368,7 +273,7 @@ public class SchematicCommand extends SWCommand { @Register("download") public void download(Player player, SchematicNode node) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { player.sendMessage("§cDu darfst nur deine eigenen Schematics herunterladen!"); return; @@ -382,7 +287,7 @@ public class SchematicCommand extends SWCommand { @Register("ordner") @Register("mkdir") public void mkdir(Player player, @Mapper("dirStringMapper") String name) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (name.startsWith("/")) name = name.substring(1); if (name.endsWith("/")) name = name.substring(0, name.length() - 1); String[] layers = name.split("/"); @@ -393,7 +298,11 @@ public class SchematicCommand extends SWCommand { @Register("changetype") public void changeType(Player player, SchematicNode node) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); + if (node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur deine eigenen Schematics einsenden."); + return; + } TextComponent base = new TextComponent(); SchematicType.values().forEach(type -> { @@ -417,6 +326,12 @@ public class SchematicCommand extends SWCommand { @Register("changetype") public void changeType(Player player, SchematicNode node, SchematicType type, Extend extend) { + SteamwarUser user = getUser(player); + if (node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur deine eigenen Schematics einsenden."); + return; + } + if (node.isDir()) { player.sendMessage(SchematicSystem.PREFIX + "§cOrdner haben keinen Typen."); return; @@ -472,7 +387,7 @@ public class SchematicCommand extends SWCommand { @Register("move") public void move(Player player, SchematicNode node, @Mapper("dirStringMapper") String name) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); return; @@ -492,7 +407,7 @@ public class SchematicCommand extends SWCommand { @Register("rename") public void rename(Player player, SchematicNode node, String name) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); return; @@ -506,7 +421,7 @@ public class SchematicCommand extends SWCommand { @Register("addteam") public void addTeam(Player player, SchematicNode node) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); return; @@ -536,7 +451,7 @@ public class SchematicCommand extends SWCommand { @Register("remteam") public void remTeam(Player player, SchematicNode node) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); return; @@ -568,7 +483,7 @@ public class SchematicCommand extends SWCommand { @Register("remallmember") @Register("clearmember") public void clearMember(Player player, SchematicNode node) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); return; @@ -578,129 +493,24 @@ public class SchematicCommand extends SWCommand { player.sendMessage(SchematicSystem.PREFIX + "§7Alle Spieler wurden von der Schematic entfernt"); } - 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; - } + @Register("togglepublic") + public void togglePublicMode(Player player) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (!user.getUserGroup().isAdminGroup()) { + genericHelp(player); + return; } - return false; - } - 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 { - if (!nodes.get(0).isDir()) { - nodes.set(0, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode == null ? 0 : currentNode.getId())); - } - currentNode = nodes.get(0); - } + if (togglePublic(player)) { + player.sendMessage(SchematicSystem.PREFIX + "§aDu bist nun der Public User"); + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDu bist nun nicht mehr der Public User"); } - return currentNode; } private final TypeMapper schematicCommandTypeMapper = nodeTypeMapper(); private final TypeMapper publicCommandTypeMapper = publicNodeTypeMapper(); - 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); - - 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.spigot().sendMessage(back); - } - for (int i = chunk * CHUNK_SIZE; i < nodes.size() && i < (chunk + 1) * CHUNK_SIZE; i++) { - SchematicNode node = nodes.get(i); - - StringBuilder nodeString = new StringBuilder(); - - 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"); - } - - nodeString.append(node.getName()); - - if (node.isDir()) { - nodeString.append("/"); - } - - 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); - } - - TextComponent beforePage = new TextComponent("««"); - 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, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk - 1))); - } else { - beforePage.setColor(ChatColor.RED); - } - - 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, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk + 1))); - } else { - nextPage.setColor(ChatColor.RED); - } - - beforePage.addExtra(nextPage); - player.spigot().sendMessage(beforePage); - } - @Mapper("publicMapper") public TypeMapper publicNodeTypeMapper() { return new TypeMapper() { @@ -788,7 +598,7 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - List list = getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), strings, s); + List list = getNodeTabcomplete(getUser((Player) commandSender), strings, s); list.removeIf(s1 -> !s1.endsWith("/")); return list; } @@ -805,12 +615,12 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), strings, s); + return getNodeTabcomplete(getUser((Player) commandSender), strings, s); } @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return mapNode(SteamwarUser.get(((Player) commandSender).getUniqueId()), previousArguments, s); + return mapNode(getUser((Player) commandSender), previousArguments, s); } }; } @@ -834,63 +644,4 @@ public class SchematicCommand extends SWCommand { AUSFAHREN, NORMAL } - - 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); - } - } - } } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java new file mode 100644 index 0000000..e582128 --- /dev/null +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java @@ -0,0 +1,89 @@ +/* + 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 + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.schematicsystem.commands; + +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.entity.Player; + +public class SchematicCommandHelp { + + private SchematicCommandHelp() { + } + + public static void printHelpMainPage(Player player) { + player.sendMessage("§7---===( §eSchematicSystem Hilfe §7)===---"); + player.sendMessage("§eKategorien: "); + for (HelpPage page : HelpPage.values()) { + TextComponent pageComp = new TextComponent(page.mainText); + pageComp.setColor(ChatColor.GRAY); + pageComp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + page.hover))); + pageComp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem help " + page.name())); + player.spigot().sendMessage(pageComp); + } + } + + public static void printHelpPage(Player player, HelpPage page) { + player.sendMessage("§7---===( §eSchematicSystem Hilfe §7)===---"); + for (String s : page.content) { + player.sendMessage(s); + } + } + + public enum HelpPage { + + ANSICHT("Ansichtbefehle", "Schaue dir deine oder dir Freigegebene Schematics an", new String[]{ + "§8/§eschem info §8[§7Schematic§8] - §7Zeigt dir Informationen zur Schematic", + "§8/§eschem list §8- §7Zeigt dir deine Schematics an", + "§8/§eschem list public §8- §7Zeigt alle Public-Schematics", + "§8/§eschem search §8[§7Stichwort§8] - §7Sucht nach passenden Schematics", + "§8/§eschem load §8[§7Schematic§8] - §7Lädt eine Schematic", + "§8/§eschem download §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig)" + }), + BEARBEITUNG("Bearbeitungsbefehle", "Modifizierung von Schematics und Ordnern", new String[]{ + "§8/§eschem save §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic", + "§8/§eschem mkdir §8[§7Ordner§8] - §7Erstelle einen Leeren Ordner", + "§8/§eschem move §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic", + "§8/§eschem rename §8[§7Schematic§8] [§7Neuer Name§8] - §7Gib der Schematic einen neuen Namen", + "§8/§eschem changetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic", + "§8/§eschem delete §8[§7Schematic§8] - §7Löscht eine Schematic" + }), + MEMBER("Memberbefehle", "Schematics mit anderen teilen", new String[]{ + "§8/§eschem addmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Fügt einen Spieler zu einer Schematic hinzu", + "§8/§eschem delmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic", + "§8/§eschem clearmember §8[§7Schematic§8] - §7Entfernt alle Spieler von der Schematic", + "§8/§eschem addteam §8[§7Schematic§8] - §7Füge jeden aus deinem Team auf die Schematic hinzu", + "§8/§eschem remteam §8[§7Schematic§8] - §7Entferne jeden aus deinem Team von der Schematic" + }); + + + private final String mainText; + private final String[] content; + private final String hover; + + HelpPage(String mainText, String hover, String[] content) { + this.mainText = mainText; + this.hover = hover; + this.content = content; + } + } +} diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java new file mode 100644 index 0000000..0a41b7f --- /dev/null +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -0,0 +1,332 @@ +/* + 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 + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.schematicsystem.commands; + +import de.steamwar.schematicsystem.SchematicSystem; +import de.steamwar.sql.*; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +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.entity.Player; + +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; + +public class SchematicCommandUtils { + + private static final int CHUNK_SIZE = 15; + private static final List PUBLIC_TOGGLED = new ArrayList<>(); + + private SchematicCommandUtils() { + } + + public 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); + } + } + } + + public 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; + } + + public static 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; + } + + public static void renderSchemlist(Player player, List nodes, int chunk, String breadcrumbs, boolean isPublic) { + nodes.sort(Comparator.comparing(SchematicNode::getName)); + SteamwarUser user = getUser(player); + int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE); + + 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.spigot().sendMessage(back); + } + for (int i = chunk * CHUNK_SIZE; i < nodes.size() && i < (chunk + 1) * CHUNK_SIZE; i++) { + SchematicNode node = nodes.get(i); + + StringBuilder nodeString = new StringBuilder(); + + 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"); + } + + nodeString.append(node.getName()); + + if (node.isDir()) { + nodeString.append("/"); + } + + 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); + } + + TextComponent beforePage = new TextComponent("««"); + 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, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk - 1))); + } else { + beforePage.setColor(ChatColor.RED); + } + + 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, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk + 1))); + } else { + nextPage.setColor(ChatColor.RED); + } + + beforePage.addExtra(nextPage); + player.spigot().sendMessage(beforePage); + } + + public static void printSchemInfo(Player player, SchematicNode node) { + SteamwarUser user = getUser(player); + 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); + } + + TextComponent base = new TextComponent(); + + 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); + + TextComponent changeTyp = new TextComponent("[Typ ändern] "); + changeTyp.setColor(ChatColor.BLUE); + changeTyp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eSchematic Typ ändern"))); + changeTyp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem changetype " + node.generateBreadcrumbs(user))); + base.addExtra(changeTyp); + } + } + + 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 move = new TextComponent("[Verschieben] "); + move.setColor(ChatColor.DARK_PURPLE); + move.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " verschieben"))); + move.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem move " + node.generateBreadcrumbs(user) + " " + node.generateBreadcrumbs(user).replace("/" + node.getName(), ""))); + base.addExtra(move); + + TextComponent rename = new TextComponent("[Umbenennen] "); + rename.setColor(ChatColor.LIGHT_PURPLE); + rename.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " umbenennen"))); + rename.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem rename " + node.generateBreadcrumbs(user) + " [Neuer Name]")); + base.addExtra(rename); + + TextComponent delete = new TextComponent("[Löschen] "); + 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); + } + + if (!base.getExtra().isEmpty()) { + player.spigot().sendMessage(base); + } + } + + public static 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 { + if (!nodes.get(0).isDir()) { + nodes.set(0, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode == null ? 0 : currentNode.getId())); + } + currentNode = nodes.get(0); + } + } + return currentNode; + } + + public static SteamwarUser getUser(Player player) { + if (PUBLIC_TOGGLED.contains(player)) { + return SteamwarUser.get(0); + } else { + return SteamwarUser.get(player.getUniqueId()); + } + } + + public static boolean togglePublic(Player player) { + if (PUBLIC_TOGGLED.contains(player)) { + PUBLIC_TOGGLED.remove(player); + return false; + } else { + PUBLIC_TOGGLED.add(player); + return true; + } + } + + public static void turnOffPublic(Player player) { + PUBLIC_TOGGLED.remove(player); + } +} From b59ff373b13409030294469ab12bf22bd58467c7 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 27 Jul 2021 12:14:57 +0200 Subject: [PATCH 07/28] More Public Signed-off-by: Chaoscaot --- .../de/steamwar/schematicsystem/commands/GUI.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index 33a5f8d..38c3cd7 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -32,10 +32,12 @@ import org.bukkit.event.inventory.ClickType; import java.util.*; +import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.getUser; + public class GUI { public static void open(Player player) { - list(player, SchematicNode.getSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId(), null), false, "/"); + list(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), null), false, "/"); } private static void list(Player player, List schems, boolean publics, String path) { @@ -48,7 +50,8 @@ public class GUI { 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 -> {}); + SWItem item = new SWItem(m, "§e" + schem.getName(), Collections.singletonList(schem.isDir() ? "§9Ordner" : "§7" + schem.getSchemtype().name()), !schem.isDir() && !schem.getSchemtype().writeable(), click -> { + }); if(!schem.isDir()) { if(schem.getRank() > 0) item.setLore(Lists.newArrayList("§7" + schem.getSchemtype().name(), "§8Rang " + schem.getRank())); @@ -66,7 +69,7 @@ public class GUI { } private static void info(Player player, SchematicNode node) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); if(node.isDir()) { list(player, SchematicNode.getSchematicNodeInNode(node), node.getOwner() == 0, node.generateBreadcrumbs(user)); } else { @@ -156,7 +159,7 @@ public class GUI { } private static void deleteOwn(Player p, SchematicNode schem){ - SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + SteamwarUser user = getUser(p); SWInventory inv = new SWInventory(p, 9, schem.generateBreadcrumbs(user) + " löschen"); inv.setItem(0, SWItem.getDye(1), (byte) 1, "§eLöschen", click -> { schem.delete(); @@ -174,7 +177,7 @@ public class GUI { } private static void deleteMembership(Player p, SchematicNode schem){ - SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + SteamwarUser user = getUser(p); SWInventory inv = new SWInventory(p, 9, schem.generateBreadcrumbs(user) + " entfernen"); inv.setItem(0, SWItem.getDye(1), (byte) 1, "§eZugriff entfernen", click -> { NodeMember member = NodeMember.getNodeMember(schem.getId(), user.getId()); @@ -232,7 +235,7 @@ public class GUI { SWAnvilInv inv = new SWAnvilInv(player, "Schematics suchen"); inv.setItem(SWItem.getMaterial("CAULDRON_ITEM")); inv.setCallback(s -> { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = getUser(player); list(player, SchematicNode.filterSchems(publics?0:user.getId(), node -> node.getName().contains(s)), publics, "/"); }); inv.open(); From 1ff74f7ab8d5539f9260ab9585424fab1fe2a993 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 11 Oct 2021 11:36:14 +0200 Subject: [PATCH 08/28] Add Schem Delete Signed-off-by: Chaoscaot --- .../commands/SchematicCommand.java | 44 ++++++++++++++++--- .../commands/SchematicCommandUtils.java | 10 ++++- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 21e3e8e..fb88de4 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -69,13 +69,13 @@ public class SchematicCommand extends SWCommand { @Register("list") @Register({"list", "/"}) public void schemList(Player player) { - renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), 0), 0, "", false); + renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), 0), 0, "", false, null); } @Register("list") @Register({"list", "/"}) public void schemList(Player player, int page) { - renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), 0), page, "", false); + renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), 0), page, "", false, null); } @Register({"list", "public"}) @@ -91,13 +91,13 @@ public class SchematicCommand extends SWCommand { @Register({"list", "public"}) @Register({"list", "public", "/"}) public void schemListPublic(Player player) { - renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), 0, "", true); + renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), 0, "", true, null); } @Register({"list", "public"}) @Register({"list", "public", "/"}) public void schemListPublic(Player player, int page) { - renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), page, "", true); + renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), page, "", true, null); } @@ -112,7 +112,7 @@ public class SchematicCommand extends SWCommand { if (!node.isDir()) { player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner"); } else { - renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), 0, node.generateBreadcrumbs(user), node.getOwner() == 0); + renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), 0, node.generateBreadcrumbs(user), node.getOwner() == 0, node); } } @@ -130,7 +130,7 @@ public class SchematicCommand extends SWCommand { if (!node.isDir()) { player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner"); } else { - renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), page, node.generateBreadcrumbs(user), node.getOwner() == 0); + renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), page, node.generateBreadcrumbs(user), node.getOwner() == 0, node); } } @@ -221,6 +221,11 @@ public class SchematicCommand extends SWCommand { return; } + if (target.getId() == 0) { + player.sendMessage(SchematicSystem.PREFIX + "§cFür Public-Anträge bitte bei der Moderation melden"); + return; + } + if (NodeMember.getNodeMember(node.getId(), target.getId()) != null) { player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler ist bereits auf diese Schematic geaddet"); return; @@ -508,6 +513,33 @@ public class SchematicCommand extends SWCommand { } } + @Register("delete") + public void deleteSchem(Player player, SchematicNode node) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (node.getOwner() != user.getId()) { + NodeMember member = NodeMember.getNodeMember(node.getId(), user.getId()); + if (member == null) { + player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic gehört dir nicht"); + return; + } + member.delete(); + player.sendMessage(SchematicSystem.PREFIX + "§aDu hast dich von der Schematic entfernt"); + return; + } + + if (node.isDir()) { + if (SchematicNode.getSchematicNodeInNode(node).isEmpty()) { + player.sendMessage(SchematicSystem.PREFIX + "§aDer Ordner §e" + node.generateBreadcrumbs(user) + "§a wird gelöcht..."); + node.delete(); + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cDer Ordner muss leer sein, um ihn zu löchen!"); + } + } else { + player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic §e" + node.generateBreadcrumbs(user) + "§a wird gelöcht..."); + node.delete(); + } + } + private final TypeMapper schematicCommandTypeMapper = nodeTypeMapper(); private final TypeMapper publicCommandTypeMapper = publicNodeTypeMapper(); diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index 0a41b7f..c4eb43c 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -120,7 +120,7 @@ public class SchematicCommandUtils { return false; } - public static void renderSchemlist(Player player, List nodes, int chunk, String breadcrumbs, boolean isPublic) { + public static void renderSchemlist(Player player, List nodes, int chunk, String breadcrumbs, boolean isPublic, SchematicNode parent) { nodes.sort(Comparator.comparing(SchematicNode::getName)); SteamwarUser user = getUser(player); int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE); @@ -175,6 +175,14 @@ public class SchematicCommandUtils { player.spigot().sendMessage(schematics); } + if (parent != null && parent.getOwner() != user.getId() && NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { + TextComponent deadd = new TextComponent("[Entfernen]"); + deadd.setColor(ChatColor.RED); + deadd.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7Entferne dich von dem Ordner"))); + deadd.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + parent.generateBreadcrumbs(user))); + player.spigot().sendMessage(deadd); + } + TextComponent beforePage = new TextComponent("««"); if (chunk > 0) { beforePage.setColor(ChatColor.YELLOW); From 4f8e527201bb8a3929f0858bb4ad67bf225664da Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 14 Nov 2021 11:23:52 +0100 Subject: [PATCH 09/28] Soem New Things Signed-off-by: Chaoscaot --- .../schematicsystem/commands/GUI.java | 126 ++++++++++-------- .../commands/SchematicCommand.java | 10 +- .../commands/SchematicCommandUtils.java | 2 +- 3 files changed, 83 insertions(+), 55 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index 38c3cd7..0ab051d 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -33,6 +33,7 @@ import org.bukkit.event.inventory.ClickType; import java.util.*; import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.getUser; +import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.invalidSchemName; public class GUI { @@ -46,7 +47,7 @@ public class GUI { for(SchematicNode schem : schems) { Material m; if (schem.getItem().isEmpty()) - m = SWItem.getMaterial("CAULDRON_ITEM"); + m = schem.isDir()?SWItem.getMaterial("CHEST"):SWItem.getMaterial("CAULDRON_ITEM"); else m = SWItem.getMaterial(schem.getItem()); @@ -59,46 +60,57 @@ public class GUI { 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) + SWListInv inv = new SWListInv<>(player, "§eSchematicliste §8- §r" + path, false, schemList, (clickType, schem) -> { + if(schem.isDir()) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + list(player, SchematicNode.getSchematicNodeInNode(schem), schem.getOwner() == 0, schem.generateBreadcrumbs(user)); + } else { + info(player, schem); + } + }); + if(publics) { inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> open(player)); - else + } else { inv.setItem(48, Material.GLASS, "§7Public Schematics", clickType -> list(player, SchematicNode.getSchematicsAccessibleByUser(0, null), true, "/")); + } + if(!publics && !path.equals("/")) { + inv.setItem(49, Material.ANVIL, "§7Ordner-Info", clickType -> info(player, SchematicSystem.SCHEMATIC_COMMAND.nodeTypeMapper().map(player, new String[0], path))); + } inv.setItem(50, Material.NAME_TAG, "§7Suche", clickType -> search(player, publics)); inv.open(); } private static void info(Player player, SchematicNode node) { SteamwarUser user = getUser(player); - if(node.isDir()) { - list(player, SchematicNode.getSchematicNodeInNode(node), node.getOwner() == 0, node.generateBreadcrumbs(user)); - } else { - SWInventory inv = new SWInventory(player, 9, node.generateBreadcrumbs(user)); + SWInventory inv = new SWInventory(player, 9, node.generateBreadcrumbs(user)); + if(!node.isDir()) { 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; - } + if(node.getOwner() == user.getId()){ + if(!node.isDir() && 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()); + } + Material mat = node.isDir()?SWItem.getMaterial("CHEST"):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(2, mat, "§e" + mat.name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> { + player.closeInventory(); + changeItem(player, node); + }); + if(!node.isDir()) { inv.setItem(4, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + node.getSchemtype().name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> { player.closeInventory(); changeType(player, node); @@ -107,34 +119,48 @@ public class GUI { player.closeInventory(); SchematicSystem.SCHEMATIC_COMMAND.download(player, node); }); - SWItem skull = SWItem.getPlayerSkull("MHF_STEVE"); - skull.setCallback(click -> { - player.closeInventory(); - delmembers(player, node); + } + SWItem skull = SWItem.getPlayerSkull("MHF_STEVE"); + skull.setCallback(click -> { + player.closeInventory(); + delmembers(player, node); + }); + skull.setName("§eMitglieder"); + inv.setItem(6, skull); + Material finalMat = mat; + inv.setItem(7, Material.NAME_TAG, "§eUmbenennen", clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, node.getName() + " umbenennen"); + anvilInv.setItem(finalMat); + anvilInv.setCallback(s -> { + if (!invalidSchemName(player, new String[]{s})) { + node.setName(s); + } + info(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{ + anvilInv.open(); + }); + inv.setItem(8, SWItem.getDye(1), (byte) 1, "§cLöschen", click -> { + player.closeInventory(); + delete(player, node); + }); + }else{ + if(!node.isDir()) { 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(); + 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){ @@ -164,10 +190,6 @@ public class GUI { inv.setItem(0, SWItem.getDye(1), (byte) 1, "§eLöschen", click -> { schem.delete(); - List checkedSchematics = CheckedSchematic.getLastDeclined(schem); - for(CheckedSchematic checkedSchematic : checkedSchematics) { - checkedSchematic.remove(); - } p.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + schem.generateBreadcrumbs(user) + " §7gelöscht"); p.closeInventory(); }); diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index fb88de4..2f73a49 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -174,7 +174,7 @@ public class SchematicCommand extends SWCommand { if (invalidSchemName(player, layers)) return; SchematicNode currentNode = mkdirs(layers, user, 1); - SchematicNode node = SchematicNode.getSchematicInParent(layers[layers.length - 1], currentNode == null ? 0 : currentNode.getId()); + SchematicNode node = SchematicNode.getSchematicNode(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; @@ -285,7 +285,7 @@ public class SchematicCommand extends SWCommand { } player.sendMessage(SchematicSystem.PREFIX + "Dein Download Link:"); - player.sendMessage(DownloadSchematic.getLink(node)); + player.sendMessage(NodeDownload.getLink(node)); } @Register("dir") @@ -397,6 +397,12 @@ public class SchematicCommand extends SWCommand { player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); return; } + + if(SchematicNode.getAllParentsOfNode(node).contains(node)) { + player.sendMessage(SchematicSystem.PREFIX + "§cDas kann nur Fehler machen, vertrau mir!"); + return; + } + if (name.equals("/")) { node.setParent(0); } else { diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index c4eb43c..930a85c 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -90,7 +90,7 @@ public class SchematicCommandUtils { 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))); + nodes.forEach(node -> list.add((sws ? "/" : "") + node.generateBreadcrumbs(user))); } else { List nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0); nodes.forEach(node -> list.add((sws ? "/" : "") + node.getName() + (node.isDir() ? "/" : ""))); From 0d10aedd81dec33b55d17adbe8e8928c1ad2a20a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 14 Nov 2021 11:26:57 +0100 Subject: [PATCH 10/28] Schem Load Message Fix Signed-off-by: Chaoscaot --- .../de/steamwar/schematicsystem/commands/SchematicCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 2f73a49..19fdedf 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -156,7 +156,7 @@ public class SchematicCommand extends SWCommand { try { 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()}); + Bukkit.getLogger().log(Level.INFO, "{0} has loaded Schematic {1} {2}", 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) { From 1918c96816e057902b096c6ca04fc79417c35f34 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 18 Nov 2021 22:17:21 +0100 Subject: [PATCH 11/28] Add new Schem GUI and some Util Stuff Signed-off-by: Chaoscaot --- .../schematicsystem/commands/GUI.java | 93 ++--- .../commands/SchematicCommand.java | 11 +- .../util/SchematicSelector.java | 381 ++++++++++++++++++ .../util/SchematicSelectorInjectable.java | 21 + .../SchematicSelectorInjectableAdapter.java | 33 ++ .../schematicsystem/util/UtilGui.java | 34 ++ pom.xml | 6 + 7 files changed, 516 insertions(+), 63 deletions(-) create mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java create mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java create mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java create mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index 0ab051d..37cb1e3 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -19,12 +19,15 @@ package de.steamwar.schematicsystem.commands; -import com.google.common.collect.Lists; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import de.steamwar.schematicsystem.SchematicSystem; +import de.steamwar.schematicsystem.util.SchematicSelector; +import de.steamwar.schematicsystem.util.SchematicSelectorInjectable; +import de.steamwar.schematicsystem.util.SchematicSelectorInjectableAdapter; +import de.steamwar.schematicsystem.util.UtilGui; import de.steamwar.sql.*; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -38,46 +41,26 @@ import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.invalid public class GUI { public static void open(Player player) { - list(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), null), false, "/"); + list(player); } - 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 = schem.isDir()?SWItem.getMaterial("CHEST"):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() && !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) -> { - if(schem.isDir()) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - list(player, SchematicNode.getSchematicNodeInNode(schem), schem.getOwner() == 0, schem.generateBreadcrumbs(user)); - } else { - info(player, schem); + private static void list(Player player) { + SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectableAdapter() { + @Override + public void onListRender(SWListInv inv, SchematicNode parent) { + if(parent == null) { + inv.setItem(49, Material.AIR, "", clickType -> {}); + } else { + inv.setItem(49, Material.ANVIL, "§7Ordner Eigenschaften", clickType -> { + info(player, parent); + }); + } } + }, node -> { + info(player, node); }); - 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, "/")); - } - if(!publics && !path.equals("/")) { - inv.setItem(49, Material.ANVIL, "§7Ordner-Info", clickType -> info(player, SchematicSystem.SCHEMATIC_COMMAND.nodeTypeMapper().map(player, new String[0], path))); - } - inv.setItem(50, Material.NAME_TAG, "§7Suche", clickType -> search(player, publics)); - inv.open(); + selector.setTitle("Schematic GUI"); + selector.open(); } private static void info(Player player, SchematicNode node) { @@ -111,11 +94,11 @@ public class GUI { changeItem(player, node); }); if(!node.isDir()) { - inv.setItem(4, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + node.getSchemtype().name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> { + inv.setItem(3, 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 -> { + inv.setItem(4, SWItem.getMaterial("MAGENTA_GLAZED_TERRACOTTA"), "§eDownload", click -> { player.closeInventory(); SchematicSystem.SCHEMATIC_COMMAND.download(player, node); }); @@ -126,10 +109,17 @@ public class GUI { delmembers(player, node); }); skull.setName("§eMitglieder"); - inv.setItem(6, skull); + inv.setItem(5, skull); + inv.setItem(6, Material.ARROW, "§eVerschieben", clickType -> { + SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectDirectory(), npar -> { + node.setParent(npar==null?null:npar.getId()); + info(player, SchematicNode.getSchematicNode(node.getId())); + }); + selector.open(); + }); Material finalMat = mat; inv.setItem(7, Material.NAME_TAG, "§eUmbenennen", clickType -> { - SWAnvilInv anvilInv = new SWAnvilInv(player, node.getName() + " umbenennen"); + SWAnvilInv anvilInv = new SWAnvilInv(player, node.getName() + " umbenennen", node.getName()); anvilInv.setItem(finalMat); anvilInv.setCallback(s -> { if (!invalidSchemName(player, new String[]{s})) { @@ -237,29 +227,10 @@ public class GUI { } 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()); - if(item.getItemMeta() != null && material.isItem()) - materials.add(new SWListInv.SWListEntry<>(item, material)); - } - - SWListInv inv = new SWListInv<>(p, "Item ändern", materials, (clickType, material) -> { + UtilGui.openMaterialSelector(p, "Item ändern", material -> { schem.setItem(material.name()); p.closeInventory(); info(p, schem); }); - inv.setCallback(-999, (ClickType click) -> p.closeInventory()); - inv.open(); - } - - 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 = getUser(player); - 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 19fdedf..b0480cf 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -249,16 +249,23 @@ public class SchematicCommand extends SWCommand { return; } - member.delete(); + SteamwarUser target = SteamwarUser.get(member.getMember()); 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()); } } + + member.delete(); + player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §e" + target.getUserName() + " §7hat nun keinen zugriff mehr auf die Schematic §e" + node.generateBreadcrumbs(user)); + + Player t = Bukkit.getPlayer(target.getUUID()); + if (t != null) { + t.sendMessage(SchematicSystem.PREFIX + "Du hast nun keinen zugriff mehr auf die Schematic §e" + node.getName() + " §7von §e" + player.getName()); + } } @Register("search") diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java new file mode 100644 index 0000000..d8818b1 --- /dev/null +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java @@ -0,0 +1,381 @@ +package de.steamwar.schematicsystem.util; + +import com.google.common.collect.Lists; +import de.steamwar.inventory.*; +import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SchematicType; +import de.steamwar.sql.SteamwarUser; +import lombok.*; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + +public class SchematicSelector { + + private final Player player; + private final SteamwarUser user; + private final Consumer callback; + private final SelectorTarget target; + private final SelectorFilter filter = new SelectorFilter(); + private SchematicSelectorInjectable injectable; + private boolean useHooks; + @Setter + @Getter + private boolean allowPublics = true; + @Setter + private String title = "{0} auswahl"; + + public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { + this.player = player; + this.user = SteamwarUser.get(player.getUniqueId()); + this.target = target; + this.callback = callback; + } + + public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer callback) { + this(player, target, callback); + this.useHooks = true; + this.injectable = injectable; + } + + public void open() { + if(useHooks) { + injectable.onSelectorCreate(player); + } + openList(null, false); + } + + private void openList(SchematicNode parent, boolean publics) { + List> list = new ArrayList<>(); + + if(parent != null) { + list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, "§eZurück", clickType -> {}), null)); + } + + List nodes = new ArrayList<>(); + + if(filter.isFilter()) { + nodes.addAll(SchematicNode.getAllSchematicsAccessibleByUser(publics?0:user.getId())); + nodes.removeIf(node -> { + if(useHooks) { + injectable.onNodeFilter(node); + } + return !filter.matches(node); + }); + if(target.target == SelectorTarget.Target.DIRECTORY) { + nodes.removeIf(node -> !node.isDir()); + } + } else { + switch (target.target) { + case DIRECTORY: + if(parent == null) { + nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), null)); + nodes.removeIf(node -> !node.isDir()); + } else { + nodes.addAll(SchematicNode.getSchematicDirectoryInNode(parent.getId())); + } + break; + case SCHEMATIC_TYPE: + nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(publics?0:user.getId(), target.type.toDB(), parent==null?0:parent.getId())); + break; + default: + nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), parent == null?0:parent.getId())); + } + } + + for (SchematicNode node : nodes) { + Material m; + if (node.getItem().isEmpty()) + m = node.isDir()?SWItem.getMaterial("CHEST"):SWItem.getMaterial("CAULDRON_ITEM"); + else + m = SWItem.getMaterial(node.getItem()); + + String name = "§" + (filter.getName().isEmpty()?"e":"7") + node.getName(); + + if(!filter.getName().isEmpty()) { + name = name.replace(filter.getName(), "§e" + filter.getName() + "§7"); + } + + SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? "§9Ordner" : "§7" + node.getSchemtype().name()), !node.isDir() && !node.getSchemtype().writeable(), click -> { + }); + if(!node.isDir()) { + if(node.getRank() > 0) + item.setLore(Lists.newArrayList("§7" + node.getSchemtype().name(), "§8Rang " + node.getRank())); + } + list.add(new SWListInv.SWListEntry<>(item, node)); + } + + SWListInv inv = new SWListInv<>(player, MessageFormat.format(title, target.target.getName()), false, list, (clickType, node) -> { + if(node == null) { + openList(getParent(parent), publics); + return; + } + if(node.isDir()) { + if(filter.isFilter() && target.target.isDirs()) { + player.closeInventory(); + callback.accept(node); + return; + } + filter.reset(); + openList(node, publics); + return; + } + player.closeInventory(); + callback.accept(node); + }); + if(allowPublics) { + if(publics) { + inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> openList(null, false)); + } else { + inv.setItem(48, Material.GLASS, "§7Public Schematics", clickType -> openList(null, true)); + } + } + if(target.target.isDirs()) { + inv.setItem(49, SWItem.getDye(10), "§7Ordner auswählen", clickType -> { + player.closeInventory(); + callback.accept(parent); + }); + } + if(!publics) { + inv.setItem(50, Material.CHEST, "§7Neuer Ordner", clickType -> createFolderIn(parent)); + } + inv.setItem(51, Material.NAME_TAG, "§7Filter", clickType -> openFilter(publics)); + + if(useHooks) { + injectable.onListRender(inv, parent); + } + inv.open(); + } + + private void createFolderIn(SchematicNode parent) { + SWAnvilInv inv = new SWAnvilInv(player, "Ordner Erstellen"); + inv.setItem(Material.CHEST); + inv.setCallback(s -> { + if(useHooks) { + if(injectable.onFolderCreate(s)) { + SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId()); + openList(parent, false); + } + } else { + SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId()); + openList(parent, false); + } + }); + inv.open(); + } + + private void openFilter(boolean publics) { + SWInventory inv = new SWInventory(player, 9, "Filter"); + InvCallback nameCallback = clickType -> { + if(clickType.isRightClick()) { + filter.setName(""); + openFilter(publics); + } else { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Name eingeben"); + swAnvilInv.setItem(Material.NAME_TAG); + swAnvilInv.setCallback(s -> { + filter.setName(s); + openFilter(publics); + }); + swAnvilInv.open(); + } + }; + if(filter.getName().isEmpty()) { + inv.setItem(0, Material.NAME_TAG, "§7Nach namen suchen...", nameCallback); + } else { + inv.setItem(0, Material.NAME_TAG, "§7Nach namen suchen...", Collections.singletonList("§7Suchwort: §e" + filter.getName()), true, nameCallback); + } + + InvCallback ownerCallback = clickType -> { + if(clickType.isRightClick()) { + filter.setOwner(null); + openFilter(publics); + } else { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Besitzer eingeben"); + swAnvilInv.setItem(Material.PLAYER_HEAD); + swAnvilInv.setCallback(s -> { + filter.setOwner(SteamwarUser.get(s).getId()); + openFilter(publics); + }); + swAnvilInv.open(); + } + }; + if(filter.getOwner() == null) { + inv.setItem(1, Material.PLAYER_HEAD, "§7Nach Besitzer suchen...", ownerCallback); + } else { + SteamwarUser user = SteamwarUser.get(filter.getOwner()); + SWItem item = SWItem.getPlayerSkull(user.getUserName()); + item.setName("§7Nach Besitzer suchen..."); + item.setEnchanted(true); + item.setLore(Collections.singletonList("§7Besitzer: §e" + user.getUserName())); + item.setCallback(ownerCallback); + inv.setItem(1, item); + } + + InvCallback schemTypeCallback = clickType -> { + if(clickType.isRightClick()) { + filter.setType(null); + openFilter(publics); + } else { + List> types = new ArrayList<>(); + SchematicType.values().forEach(schematicType -> { + types.add(new SWListInv.SWListEntry<>(new SWItem(SWItem.getMaterial("STONE_BUTTON"), "§e" + schematicType.name(), Collections.emptyList(), schematicType.fightType(), n -> {}), schematicType)); + }); + SWListInv listInv = new SWListInv<>(player, "Typ wählen...", types, (clickType1, schematicType) -> { + filter.setType(schematicType); + openFilter(publics); + }); + listInv.open(); + } + }; + + if(filter.getType() == null) { + inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", schemTypeCallback); + } else { + inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", Collections.singletonList("§7Typ: §e" + filter.getType().name()), true, schemTypeCallback); + } + + InvCallback materialCallback = clickType -> { + if(clickType.isRightClick()) { + filter.setItem(null); + openFilter(publics); + } else { + UtilGui.openMaterialSelector(player, material -> { + filter.setItem(material); + openFilter(publics); + }); + } + }; + + if(filter.getItem() == null) { + inv.setItem(3, Material.STONE, "§7Nach Item Filtern...", materialCallback); + } else { + inv.setItem(3, filter.getItem(), "§7Nach Item Filtern...", Collections.singletonList("§7Item: §e" + filter.getItem().name()), true, materialCallback); + } + + inv.setItem(7, SWItem.getDye(1), "§eAbbrechen", clickType -> { + filter.reset(); + openList(null, publics); + }); + inv.setItem(8, SWItem.getDye(10), "§eSuchen...", clickType -> { + filter.setFilter(true); + if(useHooks) { + injectable.onFilterApply(filter); + } + openList(null, publics); + }); + + if(useHooks) { + injectable.onFilterRender(inv); + } + + inv.open(); + } + + private static SchematicNode getParent(SchematicNode node) { + if(node.getParent() == null) { + return null; + } + return node.getParentNode(); + } + + public static SelectorTarget selectSchematic() { + return new SelectorTarget(SelectorTarget.Target.SCHEMATIC, null); + } + + public static SelectorTarget selectDirectory() { + return new SelectorTarget(SelectorTarget.Target.DIRECTORY, null); + } + + public static SelectorTarget selectSchematicNode() { + return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_NODE, null); + } + + public static SelectorTarget selectSchematicType(SchematicType type) { + return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_TYPE, type); + } + + private static class SelectorTarget { + + private final Target target; + private final SchematicType type; + + private SelectorTarget(Target target, SchematicType type) { + this.target = target; + this.type = type; + } + + @AllArgsConstructor + private enum Target { + SCHEMATIC("Schematic", false), + DIRECTORY("Ordner", true), + SCHEMATIC_NODE("Schematic/Ordner", true), + SCHEMATIC_TYPE("Schematic", false); + + @Getter + private String name; + @Getter + private boolean dirs; + } + } + + @NoArgsConstructor + @Getter + @Setter + public static class SelectorFilter { + + private boolean filter; + + private String name = ""; + private Integer owner = null; + private SchematicType type = null; + private Material item = null; + + public void reset() { + name = ""; + owner = null; + type = null; + item = null; + filter = false; + } + + public boolean matches(SchematicNode node) { + boolean matches = true; + if(!name.isEmpty()) { + if(!node.getName().contains(name)) { + matches = false; + } + } + + if(owner != null) { + if(node.getOwner() != owner) { + matches = false; + } + } + + if(type != null) { + if(node.isDir() || !node.getType().equals(type.toDB())) { + matches = false; + } + } + + if(item != null) { + String i; + if(node.getItem().isEmpty()) { + i = node.isDir()?"CHEST":"CAULDRON"; + } else { + i = node.getItem(); + } + if(!item.name().equals(i)) { + matches = false; + } + } + return matches; + } + } +} diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java new file mode 100644 index 0000000..9f99b4e --- /dev/null +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java @@ -0,0 +1,21 @@ +package de.steamwar.schematicsystem.util; + +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWListInv; +import de.steamwar.sql.SchematicNode; +import org.bukkit.entity.Player; + +public interface SchematicSelectorInjectable { + + void onSelectorCreate(Player player); + + void onListRender(SWListInv inv, SchematicNode parent); + + void onFilterRender(SWInventory inventory); + + void onFilterApply(SchematicSelector.SelectorFilter filter); + + boolean onFolderCreate(String name); + + void onNodeFilter(SchematicNode node); +} diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java new file mode 100644 index 0000000..6025ad8 --- /dev/null +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java @@ -0,0 +1,33 @@ +package de.steamwar.schematicsystem.util; + +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWListInv; +import de.steamwar.sql.SchematicNode; +import org.bukkit.entity.Player; + +public abstract class SchematicSelectorInjectableAdapter implements SchematicSelectorInjectable { + + private Player player; + + @Override + public void onSelectorCreate(Player player) { + this.player = player; + } + + @Override + public void onListRender(SWListInv inv, SchematicNode parent) {} + + @Override + public void onFilterRender(SWInventory inventory) {} + + @Override + public void onFilterApply(SchematicSelector.SelectorFilter filter) {} + + @Override + public boolean onFolderCreate(String name) { + return true; + } + + @Override + public void onNodeFilter(SchematicNode node) {} +} diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java new file mode 100644 index 0000000..e32d2ca --- /dev/null +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java @@ -0,0 +1,34 @@ +package de.steamwar.schematicsystem.util; + +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import lombok.experimental.UtilityClass; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.LinkedList; +import java.util.List; +import java.util.function.Consumer; + +@UtilityClass +public class UtilGui { + + public static void openMaterialSelector(Player player, Consumer callback) { + openMaterialSelector(player, "Material auswählen", callback); + } + + public static void openMaterialSelector(Player player, String title, Consumer callback) { + List> materials = new LinkedList<>(); + for(Material material : Material.values()){ + if(material.name().startsWith(Material.LEGACY_PREFIX)) + continue; + SWItem item = new SWItem(material, "§7" + material.name()); + if(item.getItemMeta() != null && material.isItem()) { + materials.add(new SWListInv.SWListEntry<>(item, material)); + } + } + + SWListInv swListInv = new SWListInv<>(player, title, materials, (clickType3, material) -> callback.accept(material)); + swListInv.open(); + } +} diff --git a/pom.xml b/pom.xml index 6d47c51..1d72398 100644 --- a/pom.xml +++ b/pom.xml @@ -44,5 +44,11 @@ system ${main.basedir}/lib/SpigotCore.jar + + org.projectlombok + lombok + 1.18.22 + provided + \ No newline at end of file From 8fe2a4f6484e0bccd260e2a361deec405e385802 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 18 Nov 2021 23:56:16 +0100 Subject: [PATCH 12/28] Add Copyright and Some Injectable Adjustments Signed-off-by: Chaoscaot --- .../schematicsystem/commands/GUI.java | 4 +- .../util/SchematicSelector.java | 37 +++++++++++++++--- .../util/SchematicSelectorInjectable.java | 32 ++++++++++++---- .../SchematicSelectorInjectableAdapter.java | 38 +++++++++++++------ .../schematicsystem/util/UtilGui.java | 19 ++++++++++ 5 files changed, 103 insertions(+), 27 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index 37cb1e3..37bd232 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -47,12 +47,12 @@ public class GUI { private static void list(Player player) { SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectableAdapter() { @Override - public void onListRender(SWListInv inv, SchematicNode parent) { + public void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) { if(parent == null) { inv.setItem(49, Material.AIR, "", clickType -> {}); } else { inv.setItem(49, Material.ANVIL, "§7Ordner Eigenschaften", clickType -> { - info(player, parent); + info(selector.getPlayer(), parent); }); } } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java index d8818b1..57000d6 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.schematicsystem.util; import com.google.common.collect.Lists; @@ -17,10 +36,15 @@ import java.util.function.Consumer; public class SchematicSelector { + @Getter private final Player player; + @Getter private final SteamwarUser user; + @Getter private final Consumer callback; + @Getter private final SelectorTarget target; + @Getter private final SelectorFilter filter = new SelectorFilter(); private SchematicSelectorInjectable injectable; private boolean useHooks; @@ -28,6 +52,7 @@ public class SchematicSelector { @Getter private boolean allowPublics = true; @Setter + @Getter private String title = "{0} auswahl"; public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { @@ -45,7 +70,7 @@ public class SchematicSelector { public void open() { if(useHooks) { - injectable.onSelectorCreate(player); + injectable.onSelectorCreate(this); } openList(null, false); } @@ -63,7 +88,7 @@ public class SchematicSelector { nodes.addAll(SchematicNode.getAllSchematicsAccessibleByUser(publics?0:user.getId())); nodes.removeIf(node -> { if(useHooks) { - injectable.onNodeFilter(node); + injectable.onNodeFilter(this, node); } return !filter.matches(node); }); @@ -147,7 +172,7 @@ public class SchematicSelector { inv.setItem(51, Material.NAME_TAG, "§7Filter", clickType -> openFilter(publics)); if(useHooks) { - injectable.onListRender(inv, parent); + injectable.onListRender(this, inv, parent); } inv.open(); } @@ -157,7 +182,7 @@ public class SchematicSelector { inv.setItem(Material.CHEST); inv.setCallback(s -> { if(useHooks) { - if(injectable.onFolderCreate(s)) { + if(injectable.onFolderCreate(this, s)) { SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId()); openList(parent, false); } @@ -265,13 +290,13 @@ public class SchematicSelector { inv.setItem(8, SWItem.getDye(10), "§eSuchen...", clickType -> { filter.setFilter(true); if(useHooks) { - injectable.onFilterApply(filter); + injectable.onFilterApply(this); } openList(null, publics); }); if(useHooks) { - injectable.onFilterRender(inv); + injectable.onFilterRender(this, inv); } inv.open(); diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java index 9f99b4e..aa8768f 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java @@ -1,21 +1,39 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.schematicsystem.util; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWListInv; import de.steamwar.sql.SchematicNode; -import org.bukkit.entity.Player; public interface SchematicSelectorInjectable { - void onSelectorCreate(Player player); + void onSelectorCreate(SchematicSelector selector); - void onListRender(SWListInv inv, SchematicNode parent); + void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent); - void onFilterRender(SWInventory inventory); + void onFilterRender(SchematicSelector selector, SWInventory inventory); - void onFilterApply(SchematicSelector.SelectorFilter filter); + void onFilterApply(SchematicSelector selector); - boolean onFolderCreate(String name); + boolean onFolderCreate(SchematicSelector selector, String name); - void onNodeFilter(SchematicNode node); + void onNodeFilter(SchematicSelector selector, SchematicNode node); } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java index 6025ad8..046e99b 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.schematicsystem.util; import de.steamwar.inventory.SWInventory; @@ -6,28 +25,23 @@ import de.steamwar.sql.SchematicNode; import org.bukkit.entity.Player; public abstract class SchematicSelectorInjectableAdapter implements SchematicSelectorInjectable { - - private Player player; + @Override + public void onSelectorCreate(SchematicSelector selector) {} @Override - public void onSelectorCreate(Player player) { - this.player = player; - } + public void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) {} @Override - public void onListRender(SWListInv inv, SchematicNode parent) {} + public void onFilterRender(SchematicSelector selector, SWInventory inventory) {} @Override - public void onFilterRender(SWInventory inventory) {} + public void onFilterApply(SchematicSelector selector) {} @Override - public void onFilterApply(SchematicSelector.SelectorFilter filter) {} - - @Override - public boolean onFolderCreate(String name) { + public boolean onFolderCreate(SchematicSelector selector, String name) { return true; } @Override - public void onNodeFilter(SchematicNode node) {} + public void onNodeFilter(SchematicSelector selector, SchematicNode node) {} } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java index e32d2ca..709f0c8 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java @@ -1,3 +1,22 @@ +/* + 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 + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.schematicsystem.util; import de.steamwar.inventory.SWItem; From e28d01ca055b393916a29aa31d58b903e289b9a4 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 20 Nov 2021 11:10:36 +0100 Subject: [PATCH 13/28] Add Copyright and Some Injectable Adjustments Signed-off-by: Chaoscaot --- .../util/SchematicSelector.java | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java index 57000d6..d69bc2c 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java @@ -95,6 +95,9 @@ public class SchematicSelector { if(target.target == SelectorTarget.Target.DIRECTORY) { nodes.removeIf(node -> !node.isDir()); } + if(target.target == SelectorTarget.Target.SCHEMATIC_TYPE) { + nodes.removeIf(node -> node.isDir() || !node.getType().equals(target.type.toDB())); + } } else { switch (target.target) { case DIRECTORY: @@ -242,27 +245,29 @@ public class SchematicSelector { inv.setItem(1, item); } - InvCallback schemTypeCallback = clickType -> { - if(clickType.isRightClick()) { - filter.setType(null); - openFilter(publics); - } else { - List> types = new ArrayList<>(); - SchematicType.values().forEach(schematicType -> { - types.add(new SWListInv.SWListEntry<>(new SWItem(SWItem.getMaterial("STONE_BUTTON"), "§e" + schematicType.name(), Collections.emptyList(), schematicType.fightType(), n -> {}), schematicType)); - }); - SWListInv listInv = new SWListInv<>(player, "Typ wählen...", types, (clickType1, schematicType) -> { - filter.setType(schematicType); + if(target.target == SelectorTarget.Target.SCHEMATIC_TYPE) { + InvCallback schemTypeCallback = clickType -> { + if(clickType.isRightClick()) { + filter.setType(null); openFilter(publics); - }); - listInv.open(); - } - }; + } else { + List> types = new ArrayList<>(); + SchematicType.values().forEach(schematicType -> { + types.add(new SWListInv.SWListEntry<>(new SWItem(SWItem.getMaterial("STONE_BUTTON"), "§e" + schematicType.name(), Collections.emptyList(), schematicType.fightType(), n -> {}), schematicType)); + }); + SWListInv listInv = new SWListInv<>(player, "Typ wählen...", types, (clickType1, schematicType) -> { + filter.setType(schematicType); + openFilter(publics); + }); + listInv.open(); + } + }; - if(filter.getType() == null) { - inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", schemTypeCallback); - } else { - inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", Collections.singletonList("§7Typ: §e" + filter.getType().name()), true, schemTypeCallback); + if(filter.getType() == null) { + inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", schemTypeCallback); + } else { + inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", Collections.singletonList("§7Typ: §e" + filter.getType().name()), true, schemTypeCallback); + } } InvCallback materialCallback = clickType -> { @@ -277,10 +282,12 @@ public class SchematicSelector { } }; + final int iSlot = target.target== SelectorTarget.Target.SCHEMATIC_TYPE?2:3; + if(filter.getItem() == null) { - inv.setItem(3, Material.STONE, "§7Nach Item Filtern...", materialCallback); + inv.setItem(iSlot, Material.STONE, "§7Nach Item Filtern...", materialCallback); } else { - inv.setItem(3, filter.getItem(), "§7Nach Item Filtern...", Collections.singletonList("§7Item: §e" + filter.getItem().name()), true, materialCallback); + inv.setItem(iSlot, filter.getItem(), "§7Nach Item Filtern...", Collections.singletonList("§7Item: §e" + filter.getItem().name()), true, materialCallback); } inv.setItem(7, SWItem.getDye(1), "§eAbbrechen", clickType -> { From 441bc4ee6c6d9d1c34a174e71ff92a0de8d43c79 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 Nov 2021 10:56:57 +0100 Subject: [PATCH 14/28] Move SchematicSelector.java to SpigotCore Signed-off-by: Chaoscaot --- .../schematicsystem/commands/GUI.java | 9 +- .../util/SchematicSelector.java | 413 ------------------ .../util/SchematicSelectorInjectable.java | 39 -- .../SchematicSelectorInjectableAdapter.java | 47 -- .../schematicsystem/util/UtilGui.java | 53 --- 5 files changed, 4 insertions(+), 557 deletions(-) delete mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java delete mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java delete mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java delete mode 100644 SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index 37bd232..8183e09 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -24,11 +24,10 @@ import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import de.steamwar.schematicsystem.SchematicSystem; -import de.steamwar.schematicsystem.util.SchematicSelector; -import de.steamwar.schematicsystem.util.SchematicSelectorInjectable; -import de.steamwar.schematicsystem.util.SchematicSelectorInjectableAdapter; -import de.steamwar.schematicsystem.util.UtilGui; import de.steamwar.sql.*; +import de.steamwar.util.SchematicSelector; +import de.steamwar.util.SchematicSelectorInjectableAdapter; +import de.steamwar.util.UtilGui; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -59,7 +58,7 @@ public class GUI { }, node -> { info(player, node); }); - selector.setTitle("Schematic GUI"); + selector.setTitle("Schematic GUI: {1}"); selector.open(); } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java deleted file mode 100644 index d69bc2c..0000000 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelector.java +++ /dev/null @@ -1,413 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.schematicsystem.util; - -import com.google.common.collect.Lists; -import de.steamwar.inventory.*; -import de.steamwar.sql.SchematicNode; -import de.steamwar.sql.SchematicType; -import de.steamwar.sql.SteamwarUser; -import lombok.*; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; - -public class SchematicSelector { - - @Getter - private final Player player; - @Getter - private final SteamwarUser user; - @Getter - private final Consumer callback; - @Getter - private final SelectorTarget target; - @Getter - private final SelectorFilter filter = new SelectorFilter(); - private SchematicSelectorInjectable injectable; - private boolean useHooks; - @Setter - @Getter - private boolean allowPublics = true; - @Setter - @Getter - private String title = "{0} auswahl"; - - public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { - this.player = player; - this.user = SteamwarUser.get(player.getUniqueId()); - this.target = target; - this.callback = callback; - } - - public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer callback) { - this(player, target, callback); - this.useHooks = true; - this.injectable = injectable; - } - - public void open() { - if(useHooks) { - injectable.onSelectorCreate(this); - } - openList(null, false); - } - - private void openList(SchematicNode parent, boolean publics) { - List> list = new ArrayList<>(); - - if(parent != null) { - list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, "§eZurück", clickType -> {}), null)); - } - - List nodes = new ArrayList<>(); - - if(filter.isFilter()) { - nodes.addAll(SchematicNode.getAllSchematicsAccessibleByUser(publics?0:user.getId())); - nodes.removeIf(node -> { - if(useHooks) { - injectable.onNodeFilter(this, node); - } - return !filter.matches(node); - }); - if(target.target == SelectorTarget.Target.DIRECTORY) { - nodes.removeIf(node -> !node.isDir()); - } - if(target.target == SelectorTarget.Target.SCHEMATIC_TYPE) { - nodes.removeIf(node -> node.isDir() || !node.getType().equals(target.type.toDB())); - } - } else { - switch (target.target) { - case DIRECTORY: - if(parent == null) { - nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), null)); - nodes.removeIf(node -> !node.isDir()); - } else { - nodes.addAll(SchematicNode.getSchematicDirectoryInNode(parent.getId())); - } - break; - case SCHEMATIC_TYPE: - nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(publics?0:user.getId(), target.type.toDB(), parent==null?0:parent.getId())); - break; - default: - nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), parent == null?0:parent.getId())); - } - } - - for (SchematicNode node : nodes) { - Material m; - if (node.getItem().isEmpty()) - m = node.isDir()?SWItem.getMaterial("CHEST"):SWItem.getMaterial("CAULDRON_ITEM"); - else - m = SWItem.getMaterial(node.getItem()); - - String name = "§" + (filter.getName().isEmpty()?"e":"7") + node.getName(); - - if(!filter.getName().isEmpty()) { - name = name.replace(filter.getName(), "§e" + filter.getName() + "§7"); - } - - SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? "§9Ordner" : "§7" + node.getSchemtype().name()), !node.isDir() && !node.getSchemtype().writeable(), click -> { - }); - if(!node.isDir()) { - if(node.getRank() > 0) - item.setLore(Lists.newArrayList("§7" + node.getSchemtype().name(), "§8Rang " + node.getRank())); - } - list.add(new SWListInv.SWListEntry<>(item, node)); - } - - SWListInv inv = new SWListInv<>(player, MessageFormat.format(title, target.target.getName()), false, list, (clickType, node) -> { - if(node == null) { - openList(getParent(parent), publics); - return; - } - if(node.isDir()) { - if(filter.isFilter() && target.target.isDirs()) { - player.closeInventory(); - callback.accept(node); - return; - } - filter.reset(); - openList(node, publics); - return; - } - player.closeInventory(); - callback.accept(node); - }); - if(allowPublics) { - if(publics) { - inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> openList(null, false)); - } else { - inv.setItem(48, Material.GLASS, "§7Public Schematics", clickType -> openList(null, true)); - } - } - if(target.target.isDirs()) { - inv.setItem(49, SWItem.getDye(10), "§7Ordner auswählen", clickType -> { - player.closeInventory(); - callback.accept(parent); - }); - } - if(!publics) { - inv.setItem(50, Material.CHEST, "§7Neuer Ordner", clickType -> createFolderIn(parent)); - } - inv.setItem(51, Material.NAME_TAG, "§7Filter", clickType -> openFilter(publics)); - - if(useHooks) { - injectable.onListRender(this, inv, parent); - } - inv.open(); - } - - private void createFolderIn(SchematicNode parent) { - SWAnvilInv inv = new SWAnvilInv(player, "Ordner Erstellen"); - inv.setItem(Material.CHEST); - inv.setCallback(s -> { - if(useHooks) { - if(injectable.onFolderCreate(this, s)) { - SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId()); - openList(parent, false); - } - } else { - SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId()); - openList(parent, false); - } - }); - inv.open(); - } - - private void openFilter(boolean publics) { - SWInventory inv = new SWInventory(player, 9, "Filter"); - InvCallback nameCallback = clickType -> { - if(clickType.isRightClick()) { - filter.setName(""); - openFilter(publics); - } else { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Name eingeben"); - swAnvilInv.setItem(Material.NAME_TAG); - swAnvilInv.setCallback(s -> { - filter.setName(s); - openFilter(publics); - }); - swAnvilInv.open(); - } - }; - if(filter.getName().isEmpty()) { - inv.setItem(0, Material.NAME_TAG, "§7Nach namen suchen...", nameCallback); - } else { - inv.setItem(0, Material.NAME_TAG, "§7Nach namen suchen...", Collections.singletonList("§7Suchwort: §e" + filter.getName()), true, nameCallback); - } - - InvCallback ownerCallback = clickType -> { - if(clickType.isRightClick()) { - filter.setOwner(null); - openFilter(publics); - } else { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Besitzer eingeben"); - swAnvilInv.setItem(Material.PLAYER_HEAD); - swAnvilInv.setCallback(s -> { - filter.setOwner(SteamwarUser.get(s).getId()); - openFilter(publics); - }); - swAnvilInv.open(); - } - }; - if(filter.getOwner() == null) { - inv.setItem(1, Material.PLAYER_HEAD, "§7Nach Besitzer suchen...", ownerCallback); - } else { - SteamwarUser user = SteamwarUser.get(filter.getOwner()); - SWItem item = SWItem.getPlayerSkull(user.getUserName()); - item.setName("§7Nach Besitzer suchen..."); - item.setEnchanted(true); - item.setLore(Collections.singletonList("§7Besitzer: §e" + user.getUserName())); - item.setCallback(ownerCallback); - inv.setItem(1, item); - } - - if(target.target == SelectorTarget.Target.SCHEMATIC_TYPE) { - InvCallback schemTypeCallback = clickType -> { - if(clickType.isRightClick()) { - filter.setType(null); - openFilter(publics); - } else { - List> types = new ArrayList<>(); - SchematicType.values().forEach(schematicType -> { - types.add(new SWListInv.SWListEntry<>(new SWItem(SWItem.getMaterial("STONE_BUTTON"), "§e" + schematicType.name(), Collections.emptyList(), schematicType.fightType(), n -> {}), schematicType)); - }); - SWListInv listInv = new SWListInv<>(player, "Typ wählen...", types, (clickType1, schematicType) -> { - filter.setType(schematicType); - openFilter(publics); - }); - listInv.open(); - } - }; - - if(filter.getType() == null) { - inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", schemTypeCallback); - } else { - inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", Collections.singletonList("§7Typ: §e" + filter.getType().name()), true, schemTypeCallback); - } - } - - InvCallback materialCallback = clickType -> { - if(clickType.isRightClick()) { - filter.setItem(null); - openFilter(publics); - } else { - UtilGui.openMaterialSelector(player, material -> { - filter.setItem(material); - openFilter(publics); - }); - } - }; - - final int iSlot = target.target== SelectorTarget.Target.SCHEMATIC_TYPE?2:3; - - if(filter.getItem() == null) { - inv.setItem(iSlot, Material.STONE, "§7Nach Item Filtern...", materialCallback); - } else { - inv.setItem(iSlot, filter.getItem(), "§7Nach Item Filtern...", Collections.singletonList("§7Item: §e" + filter.getItem().name()), true, materialCallback); - } - - inv.setItem(7, SWItem.getDye(1), "§eAbbrechen", clickType -> { - filter.reset(); - openList(null, publics); - }); - inv.setItem(8, SWItem.getDye(10), "§eSuchen...", clickType -> { - filter.setFilter(true); - if(useHooks) { - injectable.onFilterApply(this); - } - openList(null, publics); - }); - - if(useHooks) { - injectable.onFilterRender(this, inv); - } - - inv.open(); - } - - private static SchematicNode getParent(SchematicNode node) { - if(node.getParent() == null) { - return null; - } - return node.getParentNode(); - } - - public static SelectorTarget selectSchematic() { - return new SelectorTarget(SelectorTarget.Target.SCHEMATIC, null); - } - - public static SelectorTarget selectDirectory() { - return new SelectorTarget(SelectorTarget.Target.DIRECTORY, null); - } - - public static SelectorTarget selectSchematicNode() { - return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_NODE, null); - } - - public static SelectorTarget selectSchematicType(SchematicType type) { - return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_TYPE, type); - } - - private static class SelectorTarget { - - private final Target target; - private final SchematicType type; - - private SelectorTarget(Target target, SchematicType type) { - this.target = target; - this.type = type; - } - - @AllArgsConstructor - private enum Target { - SCHEMATIC("Schematic", false), - DIRECTORY("Ordner", true), - SCHEMATIC_NODE("Schematic/Ordner", true), - SCHEMATIC_TYPE("Schematic", false); - - @Getter - private String name; - @Getter - private boolean dirs; - } - } - - @NoArgsConstructor - @Getter - @Setter - public static class SelectorFilter { - - private boolean filter; - - private String name = ""; - private Integer owner = null; - private SchematicType type = null; - private Material item = null; - - public void reset() { - name = ""; - owner = null; - type = null; - item = null; - filter = false; - } - - public boolean matches(SchematicNode node) { - boolean matches = true; - if(!name.isEmpty()) { - if(!node.getName().contains(name)) { - matches = false; - } - } - - if(owner != null) { - if(node.getOwner() != owner) { - matches = false; - } - } - - if(type != null) { - if(node.isDir() || !node.getType().equals(type.toDB())) { - matches = false; - } - } - - if(item != null) { - String i; - if(node.getItem().isEmpty()) { - i = node.isDir()?"CHEST":"CAULDRON"; - } else { - i = node.getItem(); - } - if(!item.name().equals(i)) { - matches = false; - } - } - return matches; - } - } -} diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java deleted file mode 100644 index aa8768f..0000000 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectable.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.schematicsystem.util; - -import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWListInv; -import de.steamwar.sql.SchematicNode; - -public interface SchematicSelectorInjectable { - - void onSelectorCreate(SchematicSelector selector); - - void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent); - - void onFilterRender(SchematicSelector selector, SWInventory inventory); - - void onFilterApply(SchematicSelector selector); - - boolean onFolderCreate(SchematicSelector selector, String name); - - void onNodeFilter(SchematicSelector selector, SchematicNode node); -} diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java deleted file mode 100644 index 046e99b..0000000 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/SchematicSelectorInjectableAdapter.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.schematicsystem.util; - -import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWListInv; -import de.steamwar.sql.SchematicNode; -import org.bukkit.entity.Player; - -public abstract class SchematicSelectorInjectableAdapter implements SchematicSelectorInjectable { - @Override - public void onSelectorCreate(SchematicSelector selector) {} - - @Override - public void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) {} - - @Override - public void onFilterRender(SchematicSelector selector, SWInventory inventory) {} - - @Override - public void onFilterApply(SchematicSelector selector) {} - - @Override - public boolean onFolderCreate(SchematicSelector selector, String name) { - return true; - } - - @Override - public void onNodeFilter(SchematicSelector selector, SchematicNode node) {} -} diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java deleted file mode 100644 index 709f0c8..0000000 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/util/UtilGui.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - 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 - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.schematicsystem.util; - -import de.steamwar.inventory.SWItem; -import de.steamwar.inventory.SWListInv; -import lombok.experimental.UtilityClass; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.LinkedList; -import java.util.List; -import java.util.function.Consumer; - -@UtilityClass -public class UtilGui { - - public static void openMaterialSelector(Player player, Consumer callback) { - openMaterialSelector(player, "Material auswählen", callback); - } - - public static void openMaterialSelector(Player player, String title, Consumer callback) { - List> materials = new LinkedList<>(); - for(Material material : Material.values()){ - if(material.name().startsWith(Material.LEGACY_PREFIX)) - continue; - SWItem item = new SWItem(material, "§7" + material.name()); - if(item.getItemMeta() != null && material.isItem()) { - materials.add(new SWListInv.SWListEntry<>(item, material)); - } - } - - SWListInv swListInv = new SWListInv<>(player, title, materials, (clickType3, material) -> callback.accept(material)); - swListInv.open(); - } -} From c22109daa9155274c1caa49aa0dd02e248ffb92b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 26 Nov 2021 16:35:30 +0100 Subject: [PATCH 15/28] Update to new SchematicSelector Signed-off-by: Chaoscaot --- .../schematicsystem/commands/GUI.java | 10 ++-- .../commands/SchematicCommand.java | 6 +-- .../commands/SchematicCommandUtils.java | 53 +++---------------- 3 files changed, 15 insertions(+), 54 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index 8183e09..4ec155e 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -26,7 +26,7 @@ import de.steamwar.inventory.SWListInv; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.*; import de.steamwar.util.SchematicSelector; -import de.steamwar.util.SchematicSelectorInjectableAdapter; +import de.steamwar.util.SchematicSelectorInjectable; import de.steamwar.util.UtilGui; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -34,8 +34,7 @@ import org.bukkit.event.inventory.ClickType; import java.util.*; -import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.getUser; -import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.invalidSchemName; +import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*; public class GUI { @@ -44,7 +43,7 @@ public class GUI { } private static void list(Player player) { - SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectableAdapter() { + SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectable() { @Override public void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) { if(parent == null) { @@ -58,7 +57,8 @@ public class GUI { }, node -> { info(player, node); }); - selector.setTitle("Schematic GUI: {1}"); + selector.setSingleDirOpen(false); + selector.setTitle(player1 -> "Schematic GUI: {1}"); selector.open(); } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index b0480cf..6ce9eb8 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -384,7 +384,7 @@ public class SchematicCommand extends SWCommand { player.closeInventory(); }); inv.setItem(8, SWItem.getDye(7), (byte) 7, "§eDirekt einsenden", click -> { - node.setType(type.checkType().toDB()); + node.setSchemtype(type.checkType()); player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft"); player.closeInventory(); }); @@ -566,7 +566,7 @@ public class SchematicCommand extends SWCommand { @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return mapNode(SteamwarUser.get(0), previousArguments, s); + return SchematicNode.getNodeFromPath(SteamwarUser.get(0), s); } }; } @@ -665,7 +665,7 @@ public class SchematicCommand extends SWCommand { @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return mapNode(getUser((Player) commandSender), previousArguments, s); + return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s); } }; } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index 930a85c..3431aa5 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -40,45 +40,6 @@ public class SchematicCommandUtils { private SchematicCommandUtils() { } - public 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); - } - } - } - public static List getNodeTabcomplete(SteamwarUser user, String[] strings, String s) { List list = new ArrayList<>(); boolean sws = s.startsWith("/"); @@ -87,7 +48,7 @@ public class SchematicCommandUtils { } if (s.contains("/")) { String preTab = s.substring(0, s.lastIndexOf("/") + 1); - SchematicNode pa = mapNode(user, strings, preTab); + SchematicNode pa = SchematicNode.getNodeFromPath(user, preTab); if (pa == null) return Collections.emptyList(); List nodes = SchematicNode.getSchematicNodeInNode(pa); nodes.forEach(node -> list.add((sws ? "/" : "") + node.generateBreadcrumbs(user))); @@ -281,14 +242,14 @@ public class SchematicCommandUtils { rename.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " umbenennen"))); rename.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem rename " + node.generateBreadcrumbs(user) + " [Neuer Name]")); base.addExtra(rename); - - TextComponent delete = new TextComponent("[Löschen] "); - 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); } + TextComponent delete = new TextComponent("[" + (node.getOwner()==user.getId()?"Löschen":"Entfernen") + "] "); + 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); + if (!base.getExtra().isEmpty()) { player.spigot().sendMessage(base); } From 82fb26592cf0f9d2c2ff725e968d97755bee2e19 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 27 Nov 2021 10:41:47 +0100 Subject: [PATCH 16/28] Update Signed-off-by: Chaoscaot --- .../src/de/steamwar/schematicsystem/commands/GUI.java | 10 ++++++---- .../schematicsystem/commands/SchematicCommand.java | 9 ++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index 4ec155e..4721c79 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -44,6 +44,11 @@ public class GUI { private static void list(Player player) { SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectable() { + @Override + public String createTitle(Player player) { + return "Schematic GUI: {1}"; + } + @Override public void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) { if(parent == null) { @@ -54,11 +59,8 @@ public class GUI { }); } } - }, node -> { - info(player, node); - }); + }, node -> info(player, node)); selector.setSingleDirOpen(false); - selector.setTitle(player1 -> "Schematic GUI: {1}"); selector.open(); } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 6ce9eb8..b1ffb30 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -405,11 +405,6 @@ public class SchematicCommand extends SWCommand { return; } - if(SchematicNode.getAllParentsOfNode(node).contains(node)) { - player.sendMessage(SchematicSystem.PREFIX + "§cDas kann nur Fehler machen, vertrau mir!"); - return; - } - if (name.equals("/")) { node.setParent(0); } else { @@ -418,6 +413,10 @@ public class SchematicCommand extends SWCommand { String[] layers = name.split("/"); if (invalidSchemName(player, layers)) return; SchematicNode newNode = mkdirs(layers, user, 0); + if(SchematicNode.getAllParentsOfNode(newNode).contains(node)) { + player.sendMessage(SchematicSystem.PREFIX + "§cDas kann nur Fehler machen, vertrau mir!"); + return; + } node.setParent(newNode.getId()); } player.sendMessage(SchematicSystem.PREFIX + "§7Die Schematic ist nun unter §e" + node.generateBreadcrumbs(user) + " §7zu finden"); From f87bf8d90292929628fad823a26d75a3d1b84aad Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 3 Dec 2021 15:09:58 +0100 Subject: [PATCH 17/28] Many Updates Signed-off-by: Chaoscaot --- .../schematicsystem/commands/GUI.java | 8 +-- .../commands/SchematicCommand.java | 51 ++++++++++--------- .../commands/SchematicCommandHelp.java | 2 +- .../commands/SchematicCommandUtils.java | 20 -------- 4 files changed, 30 insertions(+), 51 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index 4721c79..0d7a153 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -19,15 +19,9 @@ package de.steamwar.schematicsystem.commands; -import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWItem; -import de.steamwar.inventory.SWListInv; +import de.steamwar.inventory.*; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.*; -import de.steamwar.util.SchematicSelector; -import de.steamwar.util.SchematicSelectorInjectable; -import de.steamwar.util.UtilGui; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index b1ffb30..ab58ddb 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -22,8 +22,10 @@ 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.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SchematicSelector; import de.steamwar.schematicsystem.AutoCheckResult; import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.SchematicSystem; @@ -34,6 +36,7 @@ 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.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -165,6 +168,24 @@ public class SchematicCommand extends SWCommand { } } + @Register("save") + @Register("s") + public void saveSchem(Player player) { + SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematicNode(), schematicNode -> { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(schematicNode.isDir()) { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Namen eingeben"); + anvilInv.setCallback(s -> saveSchem(player, schematicNode.generateBreadcrumbs(user) + s)); + anvilInv.setItem(Material.CAULDRON); + anvilInv.open(); + } else { + saveSchem(player, schematicNode.generateBreadcrumbs(user)); + } + }); + selector.setSingleDirOpen(false); + selector.open(); + } + @Register("save") @Register("s") public void saveSchem(Player player, @Mapper("dirStringMapper") String name) { @@ -355,7 +376,7 @@ public class SchematicCommand extends SWCommand { } if (type.writeable()) { - node.setType(type.toDB()); + node.setSchemtype(type); player.sendMessage(SchematicSystem.PREFIX + "§aSchematictyp geändert"); } else if (type.fightType()) { if (node.getSchemtype().check()) { @@ -552,7 +573,6 @@ public class SchematicCommand extends SWCommand { } } - private final TypeMapper schematicCommandTypeMapper = nodeTypeMapper(); private final TypeMapper publicCommandTypeMapper = publicNodeTypeMapper(); @Mapper("publicMapper") @@ -560,7 +580,7 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return getNodeTabcomplete(SteamwarUser.get(0), strings, s); + return SchematicNode.getNodeTabcomplete(SteamwarUser.get(0), s); } @Override @@ -575,7 +595,7 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public NodeMember map(CommandSender commandSender, String[] previousArguments, String s) { - SchematicNode node = schematicCommandTypeMapper.map(commandSender, previousArguments, previousArguments[previousArguments.length - 1]); + SchematicNode node = SchematicNode.getNodeFromPath(getUser((Player) commandSender), previousArguments[previousArguments.length - 1]); SteamwarUser user = SteamwarUser.get(s); return NodeMember.getNodeMember(node.getId(), user.getId()); } @@ -583,7 +603,7 @@ public class SchematicCommand extends SWCommand { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { List list = new ArrayList<>(); - SchematicNode node = schematicCommandTypeMapper.map(commandSender, strings, strings[strings.length - 1]); + SchematicNode node = SchematicNode.getNodeFromPath(getUser((Player) commandSender), strings[strings.length - 1]); if (node == null) { return list; } @@ -598,14 +618,14 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - List list = schematicCommandTypeMapper.tabCompletes(commandSender, strings, s); + List list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), 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); + SchematicNode result = SchematicNode.getNodeFromPath(getUser((Player) commandSender), s); if (result == null || !result.isDir()) { return null; } else { @@ -642,7 +662,7 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - List list = getNodeTabcomplete(getUser((Player) commandSender), strings, s); + List list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); list.removeIf(s1 -> !s1.endsWith("/")); return list; } @@ -654,21 +674,6 @@ public class SchematicCommand extends SWCommand { }; } - @ClassMapper(SchematicNode.class) - public TypeMapper nodeTypeMapper() { - return new TypeMapper() { - @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return getNodeTabcomplete(getUser((Player) commandSender), strings, s); - } - - @Override - public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s); - } - }; - } - @ClassMapper(SchematicType.class) public TypeMapper typeTypeMapper() { return new TypeMapper() { diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java index e582128..7f49b91 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java @@ -61,7 +61,7 @@ public class SchematicCommandHelp { }), BEARBEITUNG("Bearbeitungsbefehle", "Modifizierung von Schematics und Ordnern", new String[]{ "§8/§eschem save §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic", - "§8/§eschem mkdir §8[§7Ordner§8] - §7Erstelle einen Leeren Ordner", + "§8/§eschem ordner §8[§7Ordner§8] - §7Erstelle einen Leeren Ordner", "§8/§eschem move §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic", "§8/§eschem rename §8[§7Schematic§8] [§7Neuer Name§8] - §7Gib der Schematic einen neuen Namen", "§8/§eschem changetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic", diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index 3431aa5..ebcb408 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -40,26 +40,6 @@ public class SchematicCommandUtils { private SchematicCommandUtils() { } - public 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 = SchematicNode.getNodeFromPath(user, preTab); - if (pa == null) return Collections.emptyList(); - List nodes = SchematicNode.getSchematicNodeInNode(pa); - nodes.forEach(node -> list.add((sws ? "/" : "") + 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; - } - public static boolean invalidSchemName(Player player, String[] layers) { for (String layer : layers) { if (layer.isEmpty()) { From cfacfce82ea552aa33a89c137cef2a9c7cf2a985 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 3 Dec 2021 15:55:39 +0100 Subject: [PATCH 18/28] Merge Master ._. Signed-off-by: Chaoscaot --- .../schematicsystem/CheckSchemType.java | 4 +- .../schematicsystem/commands/GUI.java | 6 +- .../commands/SchematicCommand.java | 2 +- .../commands/SchematicCommandHelp.java | 0 .../commands/SchematicCommandUtils.java | 0 SchematicSystem_Main/pom.xml | 60 ------------------- pom.xml | 1 - 7 files changed, 6 insertions(+), 67 deletions(-) rename {SchematicSystem_Main => SchematicSystem_Core}/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java (100%) rename {SchematicSystem_Main => SchematicSystem_Core}/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java (100%) delete mode 100644 SchematicSystem_Main/pom.xml diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java index f3c3a01..6a929a3 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/CheckSchemType.java @@ -23,7 +23,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; import de.steamwar.core.VersionDependent; import de.steamwar.sql.NoClipboardException; -import de.steamwar.sql.Schematic; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; @@ -88,7 +88,7 @@ public class CheckSchemType { return types.get(type); } - public AutoCheckResult autoCheck(Schematic schematic) { + public AutoCheckResult autoCheck(SchematicNode schematic) { AutoCheckResult result = new AutoCheckResult(this); Clipboard clipboard; try { diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java index 0d7a153..514e4b9 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java @@ -64,7 +64,7 @@ public class GUI { if(!node.isDir()) { inv.setItem(0, SWItem.getMaterial("WOOD_AXE"), "§eLaden", click -> { player.closeInventory(); - SchematicSystem.SCHEMATIC_COMMAND.loadSchem(player, node); + SchematicSystem.getInstance().SCHEMATIC_COMMAND.loadSchem(player, node); }); } @@ -95,7 +95,7 @@ public class GUI { }); inv.setItem(4, SWItem.getMaterial("MAGENTA_GLAZED_TERRACOTTA"), "§eDownload", click -> { player.closeInventory(); - SchematicSystem.SCHEMATIC_COMMAND.download(player, node); + SchematicSystem.getInstance().SCHEMATIC_COMMAND.download(player, node); }); } SWItem skull = SWItem.getPlayerSkull("MHF_STEVE"); @@ -163,7 +163,7 @@ public class GUI { SWListInv inv = new SWListInv<>(p, "Typ ändern", types, (clickType, schematicType) -> { p.closeInventory(); - SchematicSystem.SCHEMATIC_COMMAND.changeType(p, schem, schematicType); + SchematicSystem.getInstance().SCHEMATIC_COMMAND.changeType(p, schem, schematicType); }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index ab58ddb..847f1fa 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -124,7 +124,7 @@ public class SchematicCommand extends SWCommand { player.sendMessage("§7--==( §eSteam§8War §eSchematic-System §7)==--"); player.sendMessage("§7Anzahl an Schematics: §e" + SchematicNode.countNodes()); player.sendMessage("§7Von dir einsehbar: §e" + SchematicNode.getAllSchematicsAccessibleByUser(getUser(player).getId()).size()); - player.sendMessage("§7Autoren: §e" + Arrays.toString(SchematicSystem.INSTANCE.getDescription().getAuthors().toArray())); + player.sendMessage("§7Autoren: §e" + Arrays.toString(SchematicSystem.getInstance().getDescription().getAuthors().toArray())); } @Register("list") diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java similarity index 100% rename from SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java rename to SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java similarity index 100% rename from SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java rename to SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java diff --git a/SchematicSystem_Main/pom.xml b/SchematicSystem_Main/pom.xml deleted file mode 100644 index fef4162..0000000 --- a/SchematicSystem_Main/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - 4.0.0 - - - steamwar - SchematicSystem - 1.0 - - - - ${project.basedir}/.. - - - SchematicSystem_Main - 1.0 - - - clean verify -U - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.1 - - - package - - shade - - - - - - schematicsystem - - - - - steamwar - SchematicSystem_15 - 1.0 - compile - - - steamwar - SchematicSystem_8 - 1.0 - compile - - - steamwar - SchematicSystem_Core - 1.0 - compile - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8973ac5..60ec21a 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,6 @@ SchematicSystem_8 SchematicSystem_15 - SchematicSystem_Main SchematicSystem_Core From 70ca0c5574ff63c3ae21386b17bae1835beaa777 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 4 Dec 2021 12:08:07 +0100 Subject: [PATCH 19/28] PR Stuff Signed-off-by: Chaoscaot --- .../schematicsystem/commands/GUI.java | 22 ++-- .../commands/SchematicCommand.java | 87 +-------------- .../commands/SchematicCommandHelp.java | 42 +++---- .../commands/SchematicCommandUtils.java | 104 +++++++++++++++++- SchematicSystem_Main/pom.xml | 59 ++++++++++ pom.xml | 2 + 6 files changed, 196 insertions(+), 120 deletions(-) create mode 100644 SchematicSystem_Main/pom.xml diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java index 514e4b9..a05f3bf 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java @@ -22,6 +22,7 @@ package de.steamwar.schematicsystem.commands; import de.steamwar.inventory.*; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.*; +import lombok.experimental.UtilityClass; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -31,16 +32,13 @@ import java.util.*; import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*; public class GUI { + private GUI() {} - public static void open(Player player) { - list(player); - } - - private static void list(Player player) { + public static void list(Player player) { SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectable() { @Override public String createTitle(Player player) { - return "Schematic GUI: {1}"; + return "Schematics {1}"; } @Override @@ -48,7 +46,7 @@ public class GUI { if(parent == null) { inv.setItem(49, Material.AIR, "", clickType -> {}); } else { - inv.setItem(49, Material.ANVIL, "§7Ordner Eigenschaften", clickType -> { + inv.setItem(49, Material.ANVIL, "§7Ordnereigenschaften", clickType -> { info(selector.getPlayer(), parent); }); } @@ -64,7 +62,7 @@ public class GUI { if(!node.isDir()) { inv.setItem(0, SWItem.getMaterial("WOOD_AXE"), "§eLaden", click -> { player.closeInventory(); - SchematicSystem.getInstance().SCHEMATIC_COMMAND.loadSchem(player, node); + SchematicCommandUtils.loadSchem(player, node); }); } @@ -80,9 +78,7 @@ public class GUI { } } } - Material mat = node.isDir()?SWItem.getMaterial("CHEST"):SWItem.getMaterial("CAULDRON_ITEM"); - if(node.getItem() != null && !node.getItem().equals("")) - mat = SWItem.getMaterial(node.getItem()); + Material mat = SWItem.getMaterial(node.getItem()); inv.setItem(2, mat, "§e" + mat.name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> { player.closeInventory(); @@ -95,7 +91,7 @@ public class GUI { }); inv.setItem(4, SWItem.getMaterial("MAGENTA_GLAZED_TERRACOTTA"), "§eDownload", click -> { player.closeInventory(); - SchematicSystem.getInstance().SCHEMATIC_COMMAND.download(player, node); + SchematicCommandUtils.download(player, node); }); } SWItem skull = SWItem.getPlayerSkull("MHF_STEVE"); @@ -163,7 +159,7 @@ public class GUI { SWListInv inv = new SWListInv<>(p, "Typ ändern", types, (clickType, schematicType) -> { p.closeInventory(); - SchematicSystem.getInstance().SCHEMATIC_COMMAND.changeType(p, schem, schematicType); + SchematicCommandUtils.changeType(p, schem, schematicType, null); }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 847f1fa..b527779 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -66,7 +66,7 @@ public class SchematicCommand extends SWCommand { @Register("gui") public void gui(Player player) { - GUI.open(player); + GUI.list(player); } @Register("list") @@ -121,7 +121,7 @@ public class SchematicCommand extends SWCommand { @Register({"info", "/"}) public void schemInfoSecret(Player player) { - player.sendMessage("§7--==( §eSteam§8War §eSchematic-System §7)==--"); + player.sendMessage("§eSteam§8War §eSchematic-System"); player.sendMessage("§7Anzahl an Schematics: §e" + SchematicNode.countNodes()); player.sendMessage("§7Von dir einsehbar: §e" + SchematicNode.getAllSchematicsAccessibleByUser(getUser(player).getId()).size()); player.sendMessage("§7Autoren: §e" + Arrays.toString(SchematicSystem.getInstance().getDescription().getAuthors().toArray())); @@ -151,21 +151,7 @@ public class SchematicCommand extends SWCommand { @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 { - node.loadToPlayer(player); - player.sendMessage(SchematicSystem.PREFIX + "§7Schematic §e" + node.getName() + " §7geladen!"); - Bukkit.getLogger().log(Level.INFO, "{0} has loaded Schematic {1} {2}", 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); - } + SchematicCommandUtils.loadSchem(player, node); } @Register("save") @@ -306,14 +292,7 @@ public class SchematicCommand extends SWCommand { @Register("download") public void download(Player player, SchematicNode node) { - SteamwarUser user = getUser(player); - if (node.getOwner() != user.getId()) { - player.sendMessage("§cDu darfst nur deine eigenen Schematics herunterladen!"); - return; - } - - player.sendMessage(SchematicSystem.PREFIX + "Dein Download Link:"); - player.sendMessage(NodeDownload.getLink(node)); + SchematicCommandUtils.download(player, node); } @Register("dir") @@ -359,63 +338,7 @@ public class SchematicCommand extends SWCommand { @Register("changetype") public void changeType(Player player, SchematicNode node, SchematicType type, Extend extend) { - SteamwarUser user = getUser(player); - if (node.getOwner() != user.getId()) { - player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur deine eigenen Schematics einsenden."); - return; - } - - 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.setSchemtype(type); - player.sendMessage(SchematicSystem.PREFIX + "§aSchematictyp geändert"); - } 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(node); - Collection errors = result.errors(); - for (String warning : result.warnings()) { - player.sendMessage(" §e" + warning); - } - for (String error : errors) { - player.sendMessage(" §c" + error); - } - if (!errors.isEmpty()) { - player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic ist nicht regelkonform"); - return; - } - - if (extend == null) { - 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()), 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 -> { - node.setSchemtype(type.checkType()); - player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft"); - player.closeInventory(); - }); - inv.setCallback(-999, click -> player.closeInventory()); - inv.open(); - } else if (extend == Extend.AUSFAHREN) { - new PrepareSchemPacket(SteamwarUser.get(player.getUniqueId()), node, type).send(player); - player.sendMessage(SchematicSystem.PREFIX + "§aDer Vorbereitungsserver wird gestartet"); - } - } + SchematicCommandUtils.changeType(player, node, type, extend); } @Register("move") diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java index 7f49b91..2f96d3a 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java @@ -31,8 +31,8 @@ public class SchematicCommandHelp { } public static void printHelpMainPage(Player player) { - player.sendMessage("§7---===( §eSchematicSystem Hilfe §7)===---"); - player.sendMessage("§eKategorien: "); + player.sendMessage("§e§lSchematicSystem §8§lHilfe"); + player.sendMessage("§7Kategorien§8:"); for (HelpPage page : HelpPage.values()) { TextComponent pageComp = new TextComponent(page.mainText); pageComp.setColor(ChatColor.GRAY); @@ -43,7 +43,7 @@ public class SchematicCommandHelp { } public static void printHelpPage(Player player, HelpPage page) { - player.sendMessage("§7---===( §eSchematicSystem Hilfe §7)===---"); + player.sendMessage("§e§lSchematicSystem §8§lHilfe"); for (String s : page.content) { player.sendMessage(s); } @@ -51,28 +51,28 @@ public class SchematicCommandHelp { public enum HelpPage { - ANSICHT("Ansichtbefehle", "Schaue dir deine oder dir Freigegebene Schematics an", new String[]{ - "§8/§eschem info §8[§7Schematic§8] - §7Zeigt dir Informationen zur Schematic", - "§8/§eschem list §8- §7Zeigt dir deine Schematics an", - "§8/§eschem list public §8- §7Zeigt alle Public-Schematics", - "§8/§eschem search §8[§7Stichwort§8] - §7Sucht nach passenden Schematics", - "§8/§eschem load §8[§7Schematic§8] - §7Lädt eine Schematic", - "§8/§eschem download §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig)" + ANSICHT("Ansichtbefehle", "Suche oder lade Schematics", new String[]{ + "§8/§7schem §einfo §8[§7Schematic§8] - §7Zeigt dir Informationen zur Schematic", + "§8/§7schem §elist §8- §7Zeigt dir deine Schematics an", + "§8/§7schem §elist public §8- §7Zeigt alle Public-Schematics", + "§8/§7schem §esearch §8[§7Stichwort§8] - §7Sucht nach passenden Schematics", + "§8/§7schem §eload §8[§7Schematic§8] - §7Lädt eine Schematic", + "§8/§7schem §edownload §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig)" }), BEARBEITUNG("Bearbeitungsbefehle", "Modifizierung von Schematics und Ordnern", new String[]{ - "§8/§eschem save §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic", - "§8/§eschem ordner §8[§7Ordner§8] - §7Erstelle einen Leeren Ordner", - "§8/§eschem move §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic", - "§8/§eschem rename §8[§7Schematic§8] [§7Neuer Name§8] - §7Gib der Schematic einen neuen Namen", - "§8/§eschem changetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic", - "§8/§eschem delete §8[§7Schematic§8] - §7Löscht eine Schematic" + "§8/§7schem §esave §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic", + "§8/§7schem §eordner §8[§7Ordner§8] - §7Erstelle einen leeren Ordner", + "§8/§7schem §emove §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic", + "§8/§7schem §erename §8[§7Schematic§8] [§7Neuer Name§8] - §7Gib der Schematic einen neuen Namen", + "§8/§7schem §echangetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic", + "§8/§7schem §edelete §8[§7Schematic§8] - §7Löscht eine Schematic" }), MEMBER("Memberbefehle", "Schematics mit anderen teilen", new String[]{ - "§8/§eschem addmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Fügt einen Spieler zu einer Schematic hinzu", - "§8/§eschem delmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic", - "§8/§eschem clearmember §8[§7Schematic§8] - §7Entfernt alle Spieler von der Schematic", - "§8/§eschem addteam §8[§7Schematic§8] - §7Füge jeden aus deinem Team auf die Schematic hinzu", - "§8/§eschem remteam §8[§7Schematic§8] - §7Entferne jeden aus deinem Team von der Schematic" + "§8/§7schem §eaddmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Fügt einen Spieler zu einer Schematic hinzu", + "§8/§7schem §edelmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic", + "§8/§7schem §eclearmember §8[§7Schematic§8] - §7Entfernt alle Spieler von der Schematic", + "§8/§7schem §eaddteam §8[§7Schematic§8] - §7Füge jeden aus deinem Team auf die Schematic hinzu", + "§8/§7schem §eremteam §8[§7Schematic§8] - §7Entferne jeden aus deinem Team von der Schematic" }); diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index ebcb408..b36d5ad 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -19,6 +19,11 @@ package de.steamwar.schematicsystem.commands; +import de.steamwar.comms.packets.PrepareSchemPacket; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import de.steamwar.schematicsystem.AutoCheckResult; +import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.*; import net.md_5.bungee.api.ChatColor; @@ -26,10 +31,12 @@ import net.md_5.bungee.api.chat.ClickEvent; 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.entity.Player; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.logging.Level; import java.util.stream.Collectors; public class SchematicCommandUtils { @@ -66,7 +73,7 @@ public class SchematicCommandUtils { SteamwarUser user = getUser(player); int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE); - player.sendMessage("§7--==( §eSchematics §8(§e" + nodes.size() + "§8) §7)==--"); + player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)"); player.sendMessage("§7Aktueller Pfad: §e" + (breadcrumbs.isEmpty() ? "/" : breadcrumbs)); if (!breadcrumbs.isEmpty()) { TextComponent back = new TextComponent("§e../"); @@ -82,7 +89,7 @@ public class SchematicCommandUtils { StringBuilder nodeString = new StringBuilder(); if (node.isDir()) { - nodeString.append("§9DIR §e"); + nodeString.append("§7§lDIR §e"); } else { SchematicType type = node.getSchemtype(); if (type != SchematicType.Normal) { @@ -148,12 +155,12 @@ public class SchematicCommandUtils { public static void printSchemInfo(Player player, SchematicNode node) { SteamwarUser user = getUser(player); - player.sendMessage("§7--==( §e" + node.getName() + " §7)==--"); + player.sendMessage("§7Schematic: §e" + node.getName()); 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())); + player.sendMessage("§7Typ: §e" + (node.isDir() ? "§7DIR" : node.getSchemtype().name())); if (!node.isDir()) { if (node.getRank() > 0) { player.sendMessage("§7Rang: §e" + node.getRank()); @@ -278,4 +285,93 @@ public class SchematicCommandUtils { public static void turnOffPublic(Player player) { PUBLIC_TOGGLED.remove(player); } + + public static void loadSchem(Player player, SchematicNode node) { + if (node.isDir()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst keine Ordner Laden"); + return; + } + + try { + node.loadToPlayer(player); + player.sendMessage(SchematicSystem.PREFIX + "§7Schematic §e" + node.getName() + " §7geladen!"); + Bukkit.getLogger().log(Level.INFO, "{0} has loaded Schematic {1} {2}", 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); + } + } + + public static void download(Player player, SchematicNode node) { + SteamwarUser user = getUser(player); + if (node.getOwner() != user.getId()) { + player.sendMessage("§cDu darfst nur deine eigenen Schematics herunterladen!"); + return; + } + + player.sendMessage(SchematicSystem.PREFIX + "Dein Download Link:"); + player.sendMessage(NodeDownload.getLink(node)); + } + + public static void changeType(Player player, SchematicNode node, SchematicType type, SchematicCommand.Extend extend) { + SteamwarUser user = getUser(player); + if (node.getOwner() != user.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur deine eigenen Schematics einsenden."); + return; + } + + 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.setSchemtype(type); + player.sendMessage(SchematicSystem.PREFIX + "§aSchematictyp geändert"); + } 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(node); + Collection errors = result.errors(); + for (String warning : result.warnings()) { + player.sendMessage(" §e" + warning); + } + for (String error : errors) { + player.sendMessage(" §c" + error); + } + if (!errors.isEmpty()) { + player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic ist nicht regelkonform"); + return; + } + + if (extend == null) { + 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()), 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 -> { + node.setSchemtype(type.checkType()); + player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft"); + player.closeInventory(); + }); + inv.setCallback(-999, click -> player.closeInventory()); + inv.open(); + } else if (extend == SchematicCommand.Extend.AUSFAHREN) { + new PrepareSchemPacket(SteamwarUser.get(player.getUniqueId()), node, type).send(player); + player.sendMessage(SchematicSystem.PREFIX + "§aDer Vorbereitungsserver wird gestartet"); + } + } + } } diff --git a/SchematicSystem_Main/pom.xml b/SchematicSystem_Main/pom.xml new file mode 100644 index 0000000..154470e --- /dev/null +++ b/SchematicSystem_Main/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + + steamwar + SchematicSystem + 1.0 + + + + ${project.basedir}/.. + + + SchematicSystem_Main + 1.0 + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + + schematicsystem + + + + + steamwar + SchematicSystem_15 + 1.0 + compile + + + steamwar + SchematicSystem_8 + 1.0 + compile + + + steamwar + SchematicSystem_Core + 1.0 + compile + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 60ec21a..9a6ee7a 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ + clean package org.apache.maven.plugins @@ -32,6 +33,7 @@ SchematicSystem_8 SchematicSystem_15 + SchematicSystem_Main SchematicSystem_Core From 322c0530a15a6a1e4a759813f7c73c21484cfb61 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 4 Dec 2021 12:08:22 +0100 Subject: [PATCH 20/28] PR Stuff Signed-off-by: Chaoscaot --- .../de/steamwar/schematicsystem/commands/SchematicCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index b527779..e5c40a8 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -279,7 +279,7 @@ public class SchematicCommand extends SWCommand { public void schemSearch(Player player, String quarry) { SteamwarUser user = getUser(player); List nodes = SchematicNode.filterSchems(user.getId(), node -> node.getName().contains(quarry)); - player.sendMessage("§7--==( §eSchematics §8(§e" + nodes.size() + "§8) §7)==--"); + player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)"); nodes.forEach(node -> { String br = node.generateBreadcrumbs(user); TextComponent schematics = new TextComponent("§7" + br.replace(quarry, "§e§l" + quarry + "§7")); From e4194b46b027e379cea005664e9ae4a4f9c2a84f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 4 Dec 2021 12:28:33 +0100 Subject: [PATCH 21/28] Yeet Lombok Signed-off-by: Chaoscaot --- pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pom.xml b/pom.xml index 9a6ee7a..b1a8c5c 100644 --- a/pom.xml +++ b/pom.xml @@ -45,11 +45,5 @@ system ${main.basedir}/lib/SpigotCore.jar - - org.projectlombok - lombok - 1.18.22 - provided - \ No newline at end of file From 9a59c903fee4a185c52ed22742abb88f7845227e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 4 Dec 2021 12:29:08 +0100 Subject: [PATCH 22/28] Yeet Lombok Signed-off-by: Chaoscaot --- .../src/de/steamwar/schematicsystem/commands/GUI.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java index a05f3bf..267fa19 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java @@ -22,7 +22,6 @@ package de.steamwar.schematicsystem.commands; import de.steamwar.inventory.*; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.*; -import lombok.experimental.UtilityClass; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; From 7c12b381740408cac5c4c3e115f01d4f47e062f7 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 4 Dec 2021 21:30:50 +0100 Subject: [PATCH 23/28] Remove Unused Variable Signed-off-by: Chaoscaot --- .../src/de/steamwar/schematicsystem/SchematicSystem.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java index ff6702f..de7ec61 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java @@ -26,13 +26,12 @@ public class SchematicSystem extends JavaPlugin { public static final String PREFIX = "§eSchematic§8» §7"; private static SchematicSystem instance; - public SchematicCommand SCHEMATIC_COMMAND; @Override public void onEnable() { instance = this; - SCHEMATIC_COMMAND = new SchematicCommand(); + new SchematicCommand(); } public static SchematicSystem getInstance() { From cd3915bb895e7bd0acc38fdad239fe8b90a51c32 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 8 Dec 2021 18:55:07 +0100 Subject: [PATCH 24/28] Some Fixes Signed-off-by: Chaoscaot --- .../schematicsystem/commands/GUI.java | 2 +- .../commands/SchematicCommand.java | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java index 267fa19..d3c96ab 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java @@ -131,7 +131,7 @@ public class GUI { SteamwarUser owneruser = SteamwarUser.get(node.getOwner()); SWItem skull = SWItem.getPlayerSkull(owneruser.getUserName()); skull.setName("§7von §e" + owneruser.getUserName()); - inv.setItem(6, skull); + inv.setItem(6, skull.getItemStack(), clickType -> {}); inv.setItem(8, SWItem.getDye(1), (byte) 1, "§cZugriff entfernen", click -> { player.closeInventory(); diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index e5c40a8..a9a83c8 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -341,6 +341,11 @@ public class SchematicCommand extends SWCommand { SchematicCommandUtils.changeType(player, node, type, extend); } + @Register("move") + public void moveToNull(Player player, SchematicNode node) { + move(player, node, "/"); + } + @Register("move") public void move(Player player, SchematicNode node, @Mapper("dirStringMapper") String name) { SteamwarUser user = getUser(player); @@ -350,7 +355,7 @@ public class SchematicCommand extends SWCommand { } if (name.equals("/")) { - node.setParent(0); + node.setParent(null); } else { if (name.startsWith("/")) name = name.substring(1); if (name.endsWith("/")) name = name.substring(0, name.length() - 1); @@ -612,6 +617,21 @@ public class SchematicCommand extends SWCommand { }; } + @ClassMapper(value = SchematicNode.class, local = true) + public TypeMapper nodeTypeMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); + } + + @Override + public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { + return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s); + } + }; + } + enum Extend { AUSFAHREN, NORMAL From 4f0bbecc3677ca15bfb34997ce60db79cd27dff5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 11 Dec 2021 16:35:16 +0100 Subject: [PATCH 25/28] More Features, Language and Fixes Signed-off-by: Chaoscaot --- .../commands/SchematicCommand.java | 45 +++++++++++-------- .../commands/SchematicCommandHelp.java | 7 ++- .../commands/SchematicCommandUtils.java | 8 +++- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index a9a83c8..76a1ce6 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -216,33 +216,40 @@ public class SchematicCommand extends SWCommand { } @Register("addmember") - public void addMember(Player player, SchematicNode node, SteamwarUser target) { + public void addMember(Player player, SchematicNode node, SteamwarUser... targets) { SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur auf deine eigenen Sachen jemanden hinzufügen."); return; } + List added = new ArrayList<>(); + for (SteamwarUser target: targets) { + if (user.getId() == target.getId()) { + player.sendMessage(SchematicSystem.PREFIX + "§cAlso bitte: Das ist deine eigene Schematic!"); + continue; + } - if (user.getId() == target.getId()) { - player.sendMessage(SchematicSystem.PREFIX + "§cAlso bitte: Das ist deine eigene Schematic!"); - return; + if (target.getId() == 0) { + player.sendMessage(SchematicSystem.PREFIX + "§cFür Public-Anträge bitte bei der Moderation melden"); + continue; + } + + if (NodeMember.getNodeMember(node.getId(), target.getId()) != null) { + player.sendMessage(SchematicSystem.PREFIX + "§c" + target.getUserName() + " ist bereits auf diese Schematic geaddet"); + continue; + } + + NodeMember.createNodeMember(node.getId(), target.getId()); + added.add(target); + + 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()); + } } - if (target.getId() == 0) { - player.sendMessage(SchematicSystem.PREFIX + "§cFür Public-Anträge bitte bei der Moderation melden"); - return; - } - - if (NodeMember.getNodeMember(node.getId(), target.getId()) != null) { - player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler ist bereits auf diese Schematic geaddet"); - return; - } - 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)); - - 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()); + if(!added.isEmpty()) { + player.sendMessage(SchematicSystem.PREFIX + (added.size()>1?"Die":"Der") + " Spieler §e" + added.stream().map(SteamwarUser::getUserName).reduce((s, s2) -> s + ", " + s2).get() + " §7" + (added.size()>1?"haben":"hat") + " nun Zugriff auf die Schematic §e" + node.generateBreadcrumbs(user)); } } diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java index 2f96d3a..5d48306 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandHelp.java @@ -32,7 +32,6 @@ public class SchematicCommandHelp { public static void printHelpMainPage(Player player) { player.sendMessage("§e§lSchematicSystem §8§lHilfe"); - player.sendMessage("§7Kategorien§8:"); for (HelpPage page : HelpPage.values()) { TextComponent pageComp = new TextComponent(page.mainText); pageComp.setColor(ChatColor.GRAY); @@ -51,7 +50,7 @@ public class SchematicCommandHelp { public enum HelpPage { - ANSICHT("Ansichtbefehle", "Suche oder lade Schematics", new String[]{ + ANSICHT("Finden & Laden", "Suche oder lade Schematics", new String[]{ "§8/§7schem §einfo §8[§7Schematic§8] - §7Zeigt dir Informationen zur Schematic", "§8/§7schem §elist §8- §7Zeigt dir deine Schematics an", "§8/§7schem §elist public §8- §7Zeigt alle Public-Schematics", @@ -59,7 +58,7 @@ public class SchematicCommandHelp { "§8/§7schem §eload §8[§7Schematic§8] - §7Lädt eine Schematic", "§8/§7schem §edownload §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig)" }), - BEARBEITUNG("Bearbeitungsbefehle", "Modifizierung von Schematics und Ordnern", new String[]{ + BEARBEITUNG("Speichern & Bearbeiten", "Modifizierung von Schematics und Ordnern", new String[]{ "§8/§7schem §esave §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic", "§8/§7schem §eordner §8[§7Ordner§8] - §7Erstelle einen leeren Ordner", "§8/§7schem §emove §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic", @@ -67,7 +66,7 @@ public class SchematicCommandHelp { "§8/§7schem §echangetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic", "§8/§7schem §edelete §8[§7Schematic§8] - §7Löscht eine Schematic" }), - MEMBER("Memberbefehle", "Schematics mit anderen teilen", new String[]{ + MEMBER("Besitzrechte", "Schematics mit anderen teilen", new String[]{ "§8/§7schem §eaddmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Fügt einen Spieler zu einer Schematic hinzu", "§8/§7schem §edelmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic", "§8/§7schem §eclearmember §8[§7Schematic§8] - §7Entfernt alle Spieler von der Schematic", diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index b36d5ad..a283ff4 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -43,9 +43,9 @@ public class SchematicCommandUtils { private static final int CHUNK_SIZE = 15; private static final List PUBLIC_TOGGLED = new ArrayList<>(); + private static final List FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public")); - private SchematicCommandUtils() { - } + private SchematicCommandUtils() {} public static boolean invalidSchemName(Player player, String[] layers) { for (String layer : layers) { @@ -64,6 +64,10 @@ public class SchematicCommandUtils { player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematicname enthält verbotene Zeichen"); return true; } + if(FORBIDDEN_NAMES.contains(layer.toLowerCase())) { + player.sendMessage(SchematicSystem.PREFIX + "§cDer Pfad darf nicht \"§l" + layer + "§c\" enthalten"); + return true; + } } return false; } From fed00014bc31b4826d649c3ed2f44a4d30eb04d1 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 22 Dec 2021 23:05:06 +0100 Subject: [PATCH 26/28] Fixing PR(TM) Stuff Signed-off-by: Chaoscaot --- .../commands/SchematicCommand.java | 19 ++++++------------- .../commands/SchematicCommandUtils.java | 6 +++++- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 76a1ce6..d4491f6 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -21,13 +21,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.SWAnvilInv; -import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SchematicSelector; -import de.steamwar.schematicsystem.AutoCheckResult; -import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.sql.*; import net.md_5.bungee.api.ChatColor; @@ -254,7 +249,6 @@ public class SchematicCommand extends SWCommand { } @Register("delmember") - @Register("remmember") public void delMember(Player player, SchematicNode node, @Mapper("memberMapper") NodeMember member) { SteamwarUser user = getUser(player); @@ -274,22 +268,22 @@ public class SchematicCommand extends SWCommand { } member.delete(); - player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §e" + target.getUserName() + " §7hat nun keinen zugriff mehr auf die Schematic §e" + node.generateBreadcrumbs(user)); + player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §e" + target.getUserName() + " §7hat nun keinen Zugriff mehr auf die Schematic §e" + node.generateBreadcrumbs(user)); Player t = Bukkit.getPlayer(target.getUUID()); if (t != null) { - t.sendMessage(SchematicSystem.PREFIX + "Du hast nun keinen zugriff mehr auf die Schematic §e" + node.getName() + " §7von §e" + player.getName()); + t.sendMessage(SchematicSystem.PREFIX + "Du hast nun keinen Zugriff mehr auf die Schematic §e" + node.getName() + " §7von §e" + player.getName()); } } @Register("search") - public void schemSearch(Player player, String quarry) { + public void schemSearch(Player player, String query) { SteamwarUser user = getUser(player); - List nodes = SchematicNode.filterSchems(user.getId(), node -> node.getName().contains(quarry)); + List nodes = SchematicNode.filterSchems(user.getId(), node -> node.getName().contains(query)); player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)"); nodes.forEach(node -> { String br = node.generateBreadcrumbs(user); - TextComponent schematics = new TextComponent("§7" + br.replace(quarry, "§e§l" + quarry + "§7")); + TextComponent schematics = new TextComponent("§7" + br.replace(query, "§e§l" + query + "§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)); @@ -422,7 +416,7 @@ public class SchematicCommand extends SWCommand { } } - @Register("remteam") + @Register("delteam") public void remTeam(Player player, SchematicNode node) { SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { @@ -453,7 +447,6 @@ public class SchematicCommand extends SWCommand { } } - @Register("remallmember") @Register("clearmember") public void clearMember(Player player, SchematicNode node) { SteamwarUser user = getUser(player); diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index a283ff4..92d099f 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -331,7 +331,11 @@ public class SchematicCommandUtils { return; } - if (node.getType().equals(type.toDB())) { + if(!type.isAssignable()) { + player.sendMessage(SchematicSystem.PREFIX + "§cZu diesem Typen können keine Schematics geändert werden."); + } + + if (node.getSchemtype().equals(type)) { player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic hat schon diesen Typen"); return; } From d6f4de67f578e1312d10164f3aeb345ffbdd9d0d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 22 Dec 2021 23:05:18 +0100 Subject: [PATCH 27/28] Fixing PR(TM) Stuff Signed-off-by: Chaoscaot --- .../schematicsystem/commands/SchematicCommand.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index d4491f6..3f6d7ee 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -114,14 +114,6 @@ public class SchematicCommand extends SWCommand { } } - @Register({"info", "/"}) - public void schemInfoSecret(Player player) { - player.sendMessage("§eSteam§8War §eSchematic-System"); - player.sendMessage("§7Anzahl an Schematics: §e" + SchematicNode.countNodes()); - player.sendMessage("§7Von dir einsehbar: §e" + SchematicNode.getAllSchematicsAccessibleByUser(getUser(player).getId()).size()); - player.sendMessage("§7Autoren: §e" + Arrays.toString(SchematicSystem.getInstance().getDescription().getAuthors().toArray())); - } - @Register("list") public void schemList(Player player, @Mapper("dirMapper") SchematicNode node, int page) { SteamwarUser user = getUser(player); From 48a10b0b9b76f2925cef94fe250e22c48dc59f1f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 27 Dec 2021 02:25:16 +0100 Subject: [PATCH 28/28] Fixing PR(TM) Stuff Signed-off-by: Chaoscaot --- .../commands/SchematicCommand.java | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 3f6d7ee..ae6db12 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -235,8 +235,11 @@ public class SchematicCommand extends SWCommand { } } - if(!added.isEmpty()) { - player.sendMessage(SchematicSystem.PREFIX + (added.size()>1?"Die":"Der") + " Spieler §e" + added.stream().map(SteamwarUser::getUserName).reduce((s, s2) -> s + ", " + s2).get() + " §7" + (added.size()>1?"haben":"hat") + " nun Zugriff auf die Schematic §e" + node.generateBreadcrumbs(user)); + Optional reduced = added.stream().map(SteamwarUser::getUserName).reduce((s, s2) -> s + ", " + s2); + if (reduced.isPresent()) { + player.sendMessage(SchematicSystem.PREFIX + "§7" + (added.size()>1?"Die":"Der") + " Spieler §e" + reduced.get() + " §7" + (added.size()>1?"wurden":"wurde") + " auf die Schematic hinzugefügt"); + } else { + player.sendMessage(SchematicSystem.PREFIX + "§cEs wurde kein Spieler hinzugefügt"); } } @@ -343,7 +346,7 @@ public class SchematicCommand extends SWCommand { public void move(Player player, SchematicNode node, @Mapper("dirStringMapper") String name) { SteamwarUser user = getUser(player); if (node.getOwner() != user.getId()) { - player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); + player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur deine eigenen Schems verschieben."); return; } @@ -356,7 +359,7 @@ public class SchematicCommand extends SWCommand { if (invalidSchemName(player, layers)) return; SchematicNode newNode = mkdirs(layers, user, 0); if(SchematicNode.getAllParentsOfNode(newNode).contains(node)) { - player.sendMessage(SchematicSystem.PREFIX + "§cDas kann nur Fehler machen, vertrau mir!"); + player.sendMessage(SchematicSystem.PREFIX + "§cDas gibt nur Fehler, vertrau mir."); return; } node.setParent(newNode.getId()); @@ -391,21 +394,7 @@ public class SchematicCommand extends SWCommand { return; } - List added = new ArrayList<>(); - for (Integer member : team.getMembers()) { - if (user.getId() == member) continue; - if (NodeMember.getNodeMember(node.getId(), member) == null) { - NodeMember.createNodeMember(node.getId(), member); - added.add(SteamwarUser.get(member).getUserName()); - } - } - - Optional reduced = added.stream().reduce((s, s2) -> s + ", " + s2); - if (reduced.isPresent()) { - player.sendMessage(SchematicSystem.PREFIX + "§7Die Spieler §e" + reduced.get() + " §7wurden auf die Schematic hinzugefügt"); - } else { - player.sendMessage(SchematicSystem.PREFIX + "§7Es wurde kein Spieler hinzugefügt"); - } + addMember(player, node, team.getMembers().stream().map(SteamwarUser::get).toArray(SteamwarUser[]::new)); } @Register("delteam")