From 05cd8fd6486aa9b80a8d99c93a2baf589daa3acb Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 12 Nov 2021 14:57:12 +0100 Subject: [PATCH 01/31] New config --- .../src/de/steamwar/sql/SchematicType.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java index 569727b..6914f4c 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java @@ -20,7 +20,6 @@ package de.steamwar.sql; import de.steamwar.core.Core; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; @@ -32,13 +31,8 @@ public class SchematicType { private static final Map fromDB; private static final List types; - static{ - File file = new File(Core.getInstance().getDataFolder(), "SchematicTypes.yml"); - - if(!file.exists()) - throw new SecurityException("SchematicType-ConfigFile not found!"); - - YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + static { + File folder = new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem"); List tmpTypes = new LinkedList<>(); Map tmpFromDB = new HashMap<>(); @@ -46,13 +40,30 @@ public class SchematicType { tmpTypes.add(Normal); tmpFromDB.put(Normal.name().toLowerCase(), Normal); - for(String type : config.getKeys(false)){ - ConfigurationSection section = config.getConfigurationSection(type); - assert section != null; - String checktype = section.getString("checktype"); - SchematicType current = new SchematicType(type, section.getString("kuerzel"), Type.valueOf(section.getString("type")), checktype != null ? tmpFromDB.get(checktype.toLowerCase()) : null); - tmpTypes.add(current); - tmpFromDB.put(type.toLowerCase(), current); + if(folder.exists()) { + for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { + YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + if(!config.isConfigurationSection("Schematic")) + continue; + + String type = config.getString("Schematic.Type"); + assert type != null; + String shortcut = config.getString("Schematic.Shortcut"); + if(tmpFromDB.containsKey(type.toLowerCase())) + continue; + + SchematicType checktype = null; + + if(!config.getStringList("CheckQuestions").isEmpty()) { + checktype = new SchematicType("C" + type, "C" + shortcut, Type.CHECK_TYPE, null); + tmpTypes.add(checktype); + tmpFromDB.put(checktype.toDB(), checktype); + } + + SchematicType current = new SchematicType(type, shortcut, config.isConfigurationSection("Server") ? Type.FIGHT_TYPE : Type.NORMAL, checktype); + tmpTypes.add(current); + tmpFromDB.put(type.toLowerCase(), current); + } } fromDB = Collections.unmodifiableMap(tmpFromDB); @@ -62,7 +73,7 @@ public class SchematicType { private final String name; private final String kuerzel; private final Type type; - private SchematicType checkType; + private final SchematicType checkType; private SchematicType(String name, String kuerzel, Type type, SchematicType checkType){ this.name = name; From 0f917ac4f68abcba4b515032e4ad4ec164118a5c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 20 Nov 2021 14:43:09 +0100 Subject: [PATCH 02/31] Hotfix Member Schematics Info Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/Schematic.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java index efe4b66..ac3cd46 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java @@ -28,7 +28,9 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; @Deprecated public class Schematic { @@ -61,6 +63,11 @@ public class Schematic { SchematicNode node = SchematicNode.getSchematicNode(schemOwner, schemName, 0); if(node != null) { return new Schematic(node); + } else { + Optional n = SchematicNode.getSchematicsAccessibleByUser(schemOwner, 0).stream().filter(node1 -> node1.getName().equals(schemName)).findAny(); + if(n.isPresent()) { + return new Schematic(n.get()); + } } return null; } From 0ff834a4d0ad653e0f0415f6843d08878c792801 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 20 Nov 2021 17:39:30 +0100 Subject: [PATCH 03/31] Hotfix Update ParentNode FK Fail Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 70a4b8a..a50b48d 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -94,6 +94,9 @@ public class SchematicNode { owner = set.getInt("NodeOwner"); name = set.getString("NodeName"); parent = set.getInt("ParentNode"); + if(set.wasNull()) { + parent = null; + } item = set.getString("NodeItem"); type = set.getString("NodeType"); lastUpdate = set.getTimestamp("LastUpdate"); @@ -417,6 +420,7 @@ public class SchematicNode { } public SchematicNode getParentNode() { + if(parent == null) return null; return SchematicNode.getSchematicNode(parent); } From f1e5e39156b889169135eed1aad113430826397c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 20 Nov 2021 18:56:38 +0100 Subject: [PATCH 04/31] Add SWCommand.Register.description to simplify help commands --- SpigotCore_Main/build.gradle | 5 ++ .../src/de/steamwar/command/SWCommand.java | 76 ++++++++++++++++++- .../src/de/steamwar/command/SubCommand.java | 8 +- 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/SpigotCore_Main/build.gradle b/SpigotCore_Main/build.gradle index 59c9f89..7a48ea5 100644 --- a/SpigotCore_Main/build.gradle +++ b/SpigotCore_Main/build.gradle @@ -46,6 +46,11 @@ dependencies { compileOnly files("${project.rootDir}/lib/Spigot-1.15.jar") compileOnly files("${project.rootDir}/lib/WorldEdit-1.12.jar") implementation 'net.wesjd:anvilgui:1.4.0-SNAPSHOT' + + compileOnly 'org.projectlombok:lombok:1.18.6' + testCompileOnly 'org.projectlombok:lombok:1.18.6' + annotationProcessor 'org.projectlombok:lombok:1.18.6' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.6' } processResources { diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 99864c2..f04cf62 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -19,14 +19,18 @@ package de.steamwar.command; +import de.steamwar.message.Message; +import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.lang.annotation.*; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiConsumer; import java.util.function.IntPredicate; import java.util.logging.Level; @@ -41,6 +45,9 @@ public abstract class SWCommand { private final Map> localTypeMapper = new HashMap<>(); private final Map localGuardChecker = new HashMap<>(); + @Setter + private Message message = null; + protected SWCommand(String command) { this(command, new String[0]); } @@ -82,7 +89,7 @@ public abstract class SWCommand { } private synchronized void createMapping() { - Method[] methods = getClass().getDeclaredMethods(); + List methods = methods(); for (Method method : methods) { addMapper(Mapper.class, method, i -> i == 0, false, TypeMapper.class, (anno, typeMapper) -> { (anno.local() ? localTypeMapper : SWCommandUtils.MAPPER_FUNCTIONS).putIfAbsent(anno.value(), typeMapper); @@ -109,7 +116,7 @@ public abstract class SWCommand { Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument"); return; } - commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>(), localGuardChecker, true)); + commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>(), localGuardChecker, true, null)); }); } for (Method method : methods) { @@ -131,7 +138,7 @@ public abstract class SWCommand { return; } } - commandList.add(new SubCommand(this, method, anno.value(), localTypeMapper, localGuardChecker, false)); + commandList.add(new SubCommand(this, method, anno.value(), localTypeMapper, localGuardChecker, false, anno.description())); }); this.commandList.sort((o1, o2) -> { @@ -143,7 +150,15 @@ public abstract class SWCommand { o2.varArgType != null ? Integer.MAX_VALUE : o2.arguments.length); } }); - commandHelpList.sort(Comparator.comparingInt(o -> -o.subCommand.length)); + commandHelpList.sort((o1, o2) -> { + int compare = Integer.compare(-o1.subCommand.length, -o2.subCommand.length); + if (compare != 0) { + return compare; + } else { + return Integer.compare(o1.method.getDeclaringClass() == SWCommand.class ? 1 : 0, + o2.method.getDeclaringClass() == SWCommand.class ? 1 : 0); + } + }); } initialized = true; } @@ -190,6 +205,12 @@ public abstract class SWCommand { }); } + private List methods() { + List methods = new ArrayList<>(Arrays.asList(getClass().getDeclaredMethods())); + methods.addAll(Arrays.asList(SWCommand.class.getDeclaredMethods())); + return methods; + } + public void unregister() { SWCommandUtils.knownCommandMap.remove(command.getName()); command.getAliases().forEach(SWCommandUtils.knownCommandMap::remove); @@ -200,6 +221,51 @@ public abstract class SWCommand { SWCommandUtils.commandMap.register("steamwar", this.command); } + @Register(help = true) + private void internalHelp(Player p, String... args) { + if (message == null) { + return; + } + try { + message.sendPrefixless("COMMAND_HELP_HEAD", p, command.getName()); + } catch (Exception e) { + Bukkit.getLogger().log(Level.WARNING, "Failed to send help message", e); + return; + } + AtomicInteger atomicInteger = new AtomicInteger(); + if (args.length != 0) { + commandList.forEach(subCommand -> { + List tabCompletes = subCommand.tabComplete(p, args); + if (tabCompletes == null || tabCompletes.isEmpty()) { + atomicInteger.incrementAndGet(); + return; + } + boolean hasTabCompletes = tabCompletes.stream() + .anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())); + if (hasTabCompletes) { + try { + message.sendPrefixless(subCommand.description, p); + } catch (Exception e) { + Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); + } + } else { + atomicInteger.incrementAndGet(); + } + }); + } + if (args.length == 0 || atomicInteger.get() == commandList.size()) { + commandList.forEach(subCommand -> { + if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) { + try { + message.sendPrefixless(subCommand.description, p); + } catch (Exception e) { + Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); + } + } + }); + } + } + @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) @Repeatable(Register.Registeres.class) @@ -208,6 +274,8 @@ public abstract class SWCommand { boolean help() default false; + String description() default ""; + @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) @interface Registeres { diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index 3cd6778..4581c8d 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -35,20 +35,22 @@ import static de.steamwar.command.SWCommandUtils.*; class SubCommand { private SWCommand swCommand; - private Method method; + Method method; + String description; String[] subCommand; TypeMapper[] arguments; GuardChecker[] guards; private Predicate commandSenderPredicate; private Function commandSenderFunction; - private GuardChecker guardChecker; + GuardChecker guardChecker; Class varArgType = null; private boolean help; - SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map> localTypeMapper, Map localGuardChecker, boolean help) { + SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map> localTypeMapper, Map localGuardChecker, boolean help, String description) { this.swCommand = swCommand; this.method = method; this.help = help; + this.description = description; Parameter[] parameters = method.getParameters(); commandSenderPredicate = sender -> parameters[0].getType().isAssignableFrom(sender.getClass()); From 745ac401bb5eaf298ff19eaf5aefb36f436e05e0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 20 Nov 2021 19:10:22 +0100 Subject: [PATCH 05/31] Add SWCommand.Register.description to simplify help commands --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index f04cf62..4125bb7 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -47,6 +47,7 @@ public abstract class SWCommand { @Setter private Message message = null; + private List defaultHelpMessages = new ArrayList<>(); protected SWCommand(String command) { this(command, new String[0]); @@ -205,6 +206,10 @@ public abstract class SWCommand { }); } + public void addDefaultHelpMessage(String message) { + defaultHelpMessages.add(message); + } + private List methods() { List methods = new ArrayList<>(Arrays.asList(getClass().getDeclaredMethods())); methods.addAll(Arrays.asList(SWCommand.class.getDeclaredMethods())); @@ -228,6 +233,7 @@ public abstract class SWCommand { } try { message.sendPrefixless("COMMAND_HELP_HEAD", p, command.getName()); + defaultHelpMessages.forEach(s -> message.sendPrefixless(s, p)); } catch (Exception e) { Bukkit.getLogger().log(Level.WARNING, "Failed to send help message", e); return; From bd6e9a0246ad48e7775b21e6147308f2c398f176 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 Nov 2021 10:23:36 +0100 Subject: [PATCH 06/31] Add Back missing Function Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index a50b48d..1054b90 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -522,6 +522,14 @@ public class SchematicNode { schemFormat = newFormat; } + public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) { + try { + return WorldEditWrapper.impl.getClipboard(is, schemFormat); + } catch (IOException e) { + throw new SecurityException("Could not read schem", e); + } + } + @Override public boolean equals(Object obj) { if (!(obj instanceof SchematicNode)) From 22df0035c47ac5306310dd22f1fac3072035e82a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 Nov 2021 10:55:08 +0100 Subject: [PATCH 07/31] Add SchematicSelector Signed-off-by: Chaoscaot --- .../de/steamwar/util/SchematicSelector.java | 438 ++++++++++++++++++ .../util/SchematicSelectorInjectable.java | 39 ++ .../SchematicSelectorInjectableAdapter.java | 47 ++ .../src/de/steamwar/util/UtilGui.java | 53 +++ 4 files changed, 577 insertions(+) create mode 100644 SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java create mode 100644 SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java create mode 100644 SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectableAdapter.java create mode 100644 SpigotCore_Main/src/de/steamwar/util/UtilGui.java diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java new file mode 100644 index 0000000..5cd4ef7 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -0,0 +1,438 @@ +/* + * 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.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 PublicMode publicMode = PublicMode.ALL; + @Setter + @Getter + private String title = "{0} auswahl: {1}"; + @Setter + @Getter + private boolean singleDirOpen; + + public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { + this.player = player; + this.user = SteamwarUser.get(player.getUniqueId()); + this.target = target; + this.callback = callback; + this.singleDirOpen = !target.target.isDirs(); + } + + 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, publicMode == PublicMode.PUBLIC_ONLY); + } + + private void openList(SchematicNode parent, boolean publics) { + 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())); + if(target.rank >= 0) { + nodes.removeIf(node -> node.getRank() > target.rank); + } + break; + default: + nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), parent == null?0:parent.getId())); + } + + if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) { + openList(nodes.get(0), publics); + return; + } + } + + List> list = new ArrayList<>(); + + if(parent != null) { + list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, "§eZurück", clickType -> {}), null)); + } + + for (SchematicNode node : nodes) { + if(node.getName().equals("//copy")) continue; + 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(), filter.getName().isEmpty()?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.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(publicMode == PublicMode.ALL) { + 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, -1); + } + + public static SelectorTarget selectDirectory() { + return new SelectorTarget(SelectorTarget.Target.DIRECTORY, null, -1); + } + + public static SelectorTarget selectSchematicNode() { + return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_NODE, null, -1); + } + + public static SelectorTarget selectSchematicType(SchematicType type) { + return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_TYPE, type, -1); + } + + public static SelectorTarget selectSchematicTypeWithRank(SchematicType type, int rank) { + return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_TYPE, type, rank); + } + + private static class SelectorTarget { + + private final Target target; + private final SchematicType type; + private final int rank; + + private SelectorTarget(Target target, SchematicType type, int rank) { + this.target = target; + this.type = type; + this.rank = rank; + } + + @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; + } + } + + public enum PublicMode { + ALL, + PRIVATE_ONLY, + PUBLIC_ONLY + } +} diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java new file mode 100644 index 0000000..35629d0 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java @@ -0,0 +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.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/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectableAdapter.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectableAdapter.java new file mode 100644 index 0000000..883ac84 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectableAdapter.java @@ -0,0 +1,47 @@ +/* + * 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.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/SpigotCore_Main/src/de/steamwar/util/UtilGui.java b/SpigotCore_Main/src/de/steamwar/util/UtilGui.java new file mode 100644 index 0000000..cfb9012 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/util/UtilGui.java @@ -0,0 +1,53 @@ +/* + * 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.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 75c9c6bb1e4632bd8e9b178f978cbf4b45545c97 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 Nov 2021 11:23:12 +0100 Subject: [PATCH 08/31] Add Deprecation and NodePathParser Signed-off-by: Chaoscaot --- .../src/de/steamwar/sql/SchematicNode.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 1054b90..56dfcff 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -37,6 +37,7 @@ import java.time.Instant; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; +import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; public class SchematicNode { @@ -309,6 +310,45 @@ public class SchematicNode { }, node); } + public static SchematicNode getNodeFromPath(SteamwarUser user, 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; + Optional node; + if (currentNode == null) { + node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny(); + } else { + node = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny(); + } + if (!node.isPresent()) { + return null; + } else { + currentNode = node.get(); + 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); + } + } + } + private final int id; private final int owner; private String name; @@ -378,12 +418,14 @@ public class SchematicNode { updateDB(); } + @Deprecated public String getType() { if(isDir) throw new SecurityException("Node is Directory"); return type; } + @Deprecated public void setType(String type) { if(isDir) throw new SecurityException("Node is Directory"); @@ -419,6 +461,13 @@ public class SchematicNode { return SchematicType.fromDB(type); } + public void setSchemtype(SchematicType type) { + if(isDir()) + throw new RuntimeException("Is Directory"); + this.type = type.toDB(); + updateDB(); + } + public SchematicNode getParentNode() { if(parent == null) return null; return SchematicNode.getSchematicNode(parent); From 42b4ccad2257f3a080eca82e4968be78b3914760 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 Nov 2021 11:23:57 +0100 Subject: [PATCH 09/31] Remove Unused Imports Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 56dfcff..1ed2e94 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -21,8 +21,6 @@ package de.steamwar.sql; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; -import de.steamwar.core.VersionedCallable; -import de.steamwar.core.VersionedRunnable; import de.steamwar.core.WorldEditWrapper; import org.bukkit.entity.Player; @@ -35,7 +33,6 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.time.Instant; import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; From 802cd6c862c145e48f8682bcbdf8d94927dd29fa Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 Nov 2021 11:25:22 +0100 Subject: [PATCH 10/31] Remove Unused Imports Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 1ed2e94..82f1ad1 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -34,7 +34,6 @@ import java.sql.Timestamp; import java.time.Instant; import java.util.*; import java.util.function.Predicate; -import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; public class SchematicNode { @@ -337,12 +336,7 @@ public class SchematicNode { 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); - } + return SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(finalS)).findAny().orElse(null); } } From 83d7a4c9887129f66e5d5950927aaee897aa4333 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 22 Nov 2021 21:10:59 +0100 Subject: [PATCH 11/31] Fix Import for Lixfel Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java index 5cd4ef7..74059bc 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -19,7 +19,6 @@ package de.steamwar.util; -import com.google.common.collect.Lists; import de.steamwar.inventory.*; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; @@ -30,6 +29,7 @@ import org.bukkit.entity.Player; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.Consumer; @@ -146,7 +146,7 @@ public class SchematicSelector { }); if(!node.isDir()) { if(node.getRank() > 0) - item.setLore(Lists.newArrayList("§7" + node.getSchemtype().name(), "§8Rang " + node.getRank())); + item.setLore(Arrays.asList("§7" + node.getSchemtype().name(), "§8Rang " + node.getRank())); } list.add(new SWListInv.SWListEntry<>(item, node)); } From 9fe13610306c5ef0487783b7007ad37feaca0d24 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 23 Nov 2021 14:16:30 +0100 Subject: [PATCH 12/31] Add SWCommand.Register.description to simplify help commands --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 10 +++++++--- .../src/de/steamwar/command/SubCommand.java | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 4125bb7..bcf15da 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -250,7 +250,9 @@ public abstract class SWCommand { .anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())); if (hasTabCompletes) { try { - message.sendPrefixless(subCommand.description, p); + for (String s : subCommand.description) { + message.sendPrefixless(s, p); + } } catch (Exception e) { Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); } @@ -263,7 +265,9 @@ public abstract class SWCommand { commandList.forEach(subCommand -> { if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) { try { - message.sendPrefixless(subCommand.description, p); + for (String s : subCommand.description) { + message.sendPrefixless(s, p); + } } catch (Exception e) { Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); } @@ -280,7 +284,7 @@ public abstract class SWCommand { boolean help() default false; - String description() default ""; + String[] description() default {}; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index 4581c8d..05cba2d 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -36,7 +36,7 @@ class SubCommand { private SWCommand swCommand; Method method; - String description; + String[] description; String[] subCommand; TypeMapper[] arguments; GuardChecker[] guards; @@ -46,7 +46,7 @@ class SubCommand { Class varArgType = null; private boolean help; - SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map> localTypeMapper, Map localGuardChecker, boolean help, String description) { + SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map> localTypeMapper, Map localGuardChecker, boolean help, String[] description) { this.swCommand = swCommand; this.method = method; this.help = help; From f69f3b757213550de9d12c479a7a0542ec8c75eb Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 23 Nov 2021 17:35:05 +0100 Subject: [PATCH 13/31] Hotfix: Fix SchematicNode Order by Name Signed-off-by: Chaoscaot --- .../src/de/steamwar/sql/SchematicNode.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 82f1ad1..009920c 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -41,24 +41,24 @@ public class SchematicNode { private static final SQL.Statement createNode = new SQL.Statement("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)"); private static final SQL.Statement getSchematicNode_Null = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL"); private static final SQL.Statement getSchematicNode = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?"); - private static final SQL.Statement getSchematicsInNode_Null = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL"); - private static final SQL.Statement getSchematicsInNode = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ?"); - private static final SQL.Statement getDirsInNode_Null = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL AND NodeType is NULL"); - private static final SQL.Statement getDirsInNode = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? AND NodeType is NULL"); - private static final SQL.Statement getSchematicDirectory_Null = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL"); - private static final SQL.Statement getSchematicDirectory = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?"); - private static final SQL.Statement getSchematicNodeO_Null = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL"); - private static final SQL.Statement getSchematicNodeO = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ?"); + private static final SQL.Statement getSchematicsInNode_Null = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL ORDER BY NodeName"); + private static final SQL.Statement getSchematicsInNode = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? ORDER BY NodeName"); + private static final SQL.Statement getDirsInNode_Null = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL AND NodeType is NULL ORDER BY NodeName"); + private static final SQL.Statement getDirsInNode = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? AND NodeType is NULL ORDER BY NodeName"); + private static final SQL.Statement getSchematicDirectory_Null = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL ORDER BY NodeName"); + private static final SQL.Statement getSchematicDirectory = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName"); + private static final SQL.Statement getSchematicNodeO_Null = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL "); + private static final SQL.Statement getSchematicNodeO = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName"); private static final SQL.Statement getSchematicNodeId = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?"); - private static final SQL.Statement getAllSchemsOfTypeOwner = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ?"); - private static final SQL.Statement getAllSchemsOfType = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ?"); + private static final SQL.Statement getAllSchemsOfTypeOwner = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ? ORDER BY NodeName"); + private static final SQL.Statement getAllSchemsOfType = new SQL.Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ? ORDER BY NodeName"); private static final SQL.Statement getAccessibleByUser = new SQL.Statement("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND ((s.NodeOwner = ? AND s.ParentNode IS NULL) OR NOT s.NodeOwner = ?) GROUP BY s.NodeId ORDER BY s.NodeName"); - private static final SQL.Statement getAccessibleByUserByTypeInNode = new SQL.Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ?"); - private static final SQL.Statement getAccessibleByUserByTypeInNode_Null = new SQL.Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null"); - private static final SQL.Statement getAccessibleByUserByType = new SQL.Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ?"); - private static final SQL.Statement getAllSchematicsAccessibleByUser = new SQL.Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN"); - private static final SQL.Statement isSchematicAccessibleForUser = new SQL.Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1"); - private static final SQL.Statement getAllParentsOfNode = new SQL.Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN"); + private static final SQL.Statement getAccessibleByUserByTypeInNode = new SQL.Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ? ORDER BY NodeName"); + private static final SQL.Statement getAccessibleByUserByTypeInNode_Null = new SQL.Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName"); + private static final SQL.Statement getAccessibleByUserByType = new SQL.Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName"); + private static final SQL.Statement getAllSchematicsAccessibleByUser = new SQL.Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName"); + private static final SQL.Statement isSchematicAccessibleForUser = new SQL.Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1 ORDER BY NodeName"); + private static final SQL.Statement getAllParentsOfNode = new SQL.Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName"); private static final SQL.Statement countNodes = new SQL.Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode"); private static final SQL.Statement updateDB = new SQL.Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?"); private static final SQL.Statement updateDatabase = new SQL.Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?"); From bf796ebce3c1ddf759a52c8a4d6550637f8dc90f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 23 Nov 2021 19:01:28 +0100 Subject: [PATCH 14/31] Doing Lixfel Stuff Signed-off-by: Chaoscaot --- SpigotCore_Main/src/SpigotCore.properties | 51 ++++ SpigotCore_Main/src/SpigotCore_en.properties | 0 .../src/de/steamwar/core/Core.java | 4 + .../de/steamwar/util/SchematicSelector.java | 237 ++++++++++-------- .../util/SchematicSelectorInjectable.java | 12 +- .../SchematicSelectorInjectableAdapter.java | 47 ---- .../src/de/steamwar/util/UtilGui.java | 3 +- 7 files changed, 194 insertions(+), 160 deletions(-) create mode 100644 SpigotCore_Main/src/SpigotCore.properties create mode 100644 SpigotCore_Main/src/SpigotCore_en.properties delete mode 100644 SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectableAdapter.java diff --git a/SpigotCore_Main/src/SpigotCore.properties b/SpigotCore_Main/src/SpigotCore.properties new file mode 100644 index 0000000..53227e0 --- /dev/null +++ b/SpigotCore_Main/src/SpigotCore.properties @@ -0,0 +1,51 @@ +# +# 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 . +# + +SCHEM_SELECTOR_TITLE={0} auswählen: {1} +SCHEM_SELECTOR_BACK=§eZurück +SCHEM_SELECTOR_DIR=Ordner +SCHEM_SELECTOR_RANK=§8Rang {0} +SCHEM_SELECTOR_OWN=§7Eigene Schematics +SCHEM_SELECTOR_PUB=§7Public Schematics +SCHEM_SELECTOR_SEL_DIR=§7Ordner auswählen +SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner +SCHEM_SELECTOR_FILTER=§7Filter + +SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner Erstellen + +SCHEM_SELECTOR_FILTER_TITLE=Filter +SCHEM_SELECTOR_FILTER_ENTER_NAME=Name eingeben +SCHEM_SELECTOR_FILTER_NAME=§7Nach Namen suchen... +SCHEM_SELECTOR_FILTER_NAME_SEARCH=§7Suchwort: §e{0} +SCHEM_SELECTOR_FILTER_ENTER_OWNER=Besitzer eingeben +SCHEM_SELECTOR_FILTER_OWNER=§7Nach Besitzer suchen... +SCHEM_SELECTOR_FILTER_OWNER_SEARCH=§7Besitzer: §e{0} +SCHEM_SELECTOR_FILTER_SEL_TYPE=Typ wählen... +SCHEM_SELECTOR_FILTER_TYPE=§7Nach Typ Filtern... +SCHEM_SELECTOR_FILTER_TYPE_SEARCH=§7Typ: §e{0} +SCHEM_SELECTOR_FILTER_MAT=§7Nach Item Filtern... +SCHEM_SELECTOR_FILTER_MAT_SEARCH=§7Item: §e{0} +SCHEM_SELECTOR_CANCEL=§eAbbrechen +SCHEM_SELECTOR_GO=§eSuchen... + +SCHEM_SELECTOR_SCHEMATIC=Schematic +SCHEM_SELECTOR_DIRECTORY=Ordner +SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Ordner + +MATERIAL_SELECTOR_TITLE=Material auswählen \ No newline at end of file diff --git a/SpigotCore_Main/src/SpigotCore_en.properties b/SpigotCore_Main/src/SpigotCore_en.properties new file mode 100644 index 0000000..e69de29 diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 4c28502..b0fc18f 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -25,6 +25,7 @@ import de.steamwar.core.events.ChattingEvent; import de.steamwar.core.events.ChunkListener; import de.steamwar.core.events.PlayerJoinedEvent; import de.steamwar.core.events.WorldLoadEvent; +import de.steamwar.message.Message; import de.steamwar.sql.SQL; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -39,6 +40,7 @@ public class Core extends JavaPlugin{ private static Core instance; private static final int version; + public static Message MESSAGE; static{ String packageName = Bukkit.getServer().getClass().getPackage().getName(); @@ -79,6 +81,8 @@ public class Core extends JavaPlugin{ } catch (IOException e) { throw new SecurityException("Could not load Hostname", e); } + + MESSAGE = new Message("SpigotCore", getClassLoader()); } @Override diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java index 74059bc..a8c417d 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -19,10 +19,12 @@ package de.steamwar.util; +import de.steamwar.core.Core; import de.steamwar.inventory.*; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; +import jdk.nashorn.internal.runtime.doubleconv.CachedPowers; import lombok.*; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -33,9 +35,12 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.Consumer; +import java.util.function.Function; public class SchematicSelector { + public static final String DEFAULT_TITLE = "SCHEM_SELECTOR_TITLE"; + @Getter private final Player player; @Getter @@ -53,10 +58,11 @@ public class SchematicSelector { private PublicMode publicMode = PublicMode.ALL; @Setter @Getter - private String title = "{0} auswahl: {1}"; + private boolean singleDirOpen; @Setter @Getter - private boolean singleDirOpen; + private Function title; + private boolean sdoTrigger = false; public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { this.player = player; @@ -80,112 +86,42 @@ public class SchematicSelector { } private void openList(SchematicNode parent, boolean publics) { - List nodes = new ArrayList<>(); + List nodes = filter.isFilter()?getFilteredSchematics(publics):getSchematicList(publics, parent); - 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())); - if(target.rank >= 0) { - nodes.removeIf(node -> node.getRank() > target.rank); - } - break; - default: - nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), parent == null?0:parent.getId())); - } - - if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) { - openList(nodes.get(0), publics); - return; - } + if(sdoTrigger) { + sdoTrigger = false; + return; } List> list = new ArrayList<>(); if(parent != null) { - list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, "§eZurück", clickType -> {}), null)); + list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}), null)); } for (SchematicNode node : nodes) { if(node.getName().equals("//copy")) continue; - 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(Arrays.asList("§7" + node.getSchemtype().name(), "§8Rang " + node.getRank())); - } - list.add(new SWListInv.SWListEntry<>(item, node)); + list.add(renderItem(node)); } - SWListInv inv = new SWListInv<>(player, MessageFormat.format(title, target.target.getName(), filter.getName().isEmpty()?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.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); - }); + SWListInv inv = new SWListInv<>(player, MessageFormat.format(title==null?DEFAULT_TITLE:title.apply(player), target.target.getName(player), filter.getName().isEmpty()?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.getName()), false, list, (clickType, node) -> handleClick(publics, node, parent)); if(publicMode == PublicMode.ALL) { if(publics) { - inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> openList(null, false)); + inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> openList(null, false)); } else { - inv.setItem(48, Material.GLASS, "§7Public Schematics", clickType -> openList(null, true)); + inv.setItem(48, Material.GLASS, Core.MESSAGE.parse("SCHEM_SELECTOR_PUB", player), clickType -> openList(null, true)); } } if(target.target.isDirs()) { - inv.setItem(49, SWItem.getDye(10), "§7Ordner auswählen", clickType -> { + inv.setItem(49, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_SEL_DIR", player), clickType -> { player.closeInventory(); callback.accept(parent); }); } if(!publics) { - inv.setItem(50, Material.CHEST, "§7Neuer Ordner", clickType -> createFolderIn(parent)); + inv.setItem(50, Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent)); } - inv.setItem(51, Material.NAME_TAG, "§7Filter", clickType -> openFilter(publics)); + inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter(publics)); if(useHooks) { injectable.onListRender(this, inv, parent); @@ -193,8 +129,48 @@ public class SchematicSelector { inv.open(); } + private void handleClick(boolean publics, SchematicNode node, SchematicNode parent) { + 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); + } + + private SWListInv.SWListEntry renderItem(SchematicNode node) { + 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() ? ("§9" + Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : "§7" + node.getSchemtype().name()), !node.isDir() && !node.getSchemtype().writeable(), click -> { + }); + if(!node.isDir() && node.getRank() > 0) { + item.setLore(Arrays.asList("§7" + node.getSchemtype().name(), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player))); + } + return new SWListInv.SWListEntry<>(item, node); + } + private void createFolderIn(SchematicNode parent) { - SWAnvilInv inv = new SWAnvilInv(player, "Ordner Erstellen"); + SWAnvilInv inv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_CREATE_DIR_TITLE", player)); inv.setItem(Material.CHEST); inv.setCallback(s -> { if(useHooks) { @@ -211,13 +187,13 @@ public class SchematicSelector { } private void openFilter(boolean publics) { - SWInventory inv = new SWInventory(player, 9, "Filter"); + SWInventory inv = new SWInventory(player, 9, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE", player)); InvCallback nameCallback = clickType -> { if(clickType.isRightClick()) { filter.setName(""); openFilter(publics); } else { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Name eingeben"); + SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_NAME", player)); swAnvilInv.setItem(Material.NAME_TAG); swAnvilInv.setCallback(s -> { filter.setName(s); @@ -227,9 +203,9 @@ public class SchematicSelector { } }; if(filter.getName().isEmpty()) { - inv.setItem(0, Material.NAME_TAG, "§7Nach namen suchen...", nameCallback); + inv.setItem(0, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME", player), nameCallback); } else { - inv.setItem(0, Material.NAME_TAG, "§7Nach namen suchen...", Collections.singletonList("§7Suchwort: §e" + filter.getName()), true, nameCallback); + inv.setItem(0, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME", player), Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME_SEARCH", player, filter.getName())), true, nameCallback); } InvCallback ownerCallback = clickType -> { @@ -237,7 +213,7 @@ public class SchematicSelector { filter.setOwner(null); openFilter(publics); } else { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Besitzer eingeben"); + SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_OWNER", player)); swAnvilInv.setItem(Material.PLAYER_HEAD); swAnvilInv.setCallback(s -> { filter.setOwner(SteamwarUser.get(s).getId()); @@ -247,13 +223,13 @@ public class SchematicSelector { } }; if(filter.getOwner() == null) { - inv.setItem(1, Material.PLAYER_HEAD, "§7Nach Besitzer suchen...", ownerCallback); + inv.setItem(1, Material.PLAYER_HEAD, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_OWNER", player), ownerCallback); } else { - SteamwarUser user = SteamwarUser.get(filter.getOwner()); + SteamwarUser tUser = SteamwarUser.get(filter.getOwner()); SWItem item = SWItem.getPlayerSkull(user.getUserName()); - item.setName("§7Nach Besitzer suchen..."); + item.setName(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_OWNER", player)); item.setEnchanted(true); - item.setLore(Collections.singletonList("§7Besitzer: §e" + user.getUserName())); + item.setLore(Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_OWNER_SEARCH", player, tUser.getUserName()))); item.setCallback(ownerCallback); inv.setItem(1, item); } @@ -268,7 +244,7 @@ public class SchematicSelector { 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) -> { + SWListInv listInv = new SWListInv<>(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_SEL_TYPE", player), types, (clickType1, schematicType) -> { filter.setType(schematicType); openFilter(publics); }); @@ -277,9 +253,9 @@ public class SchematicSelector { }; if(filter.getType() == null) { - inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", schemTypeCallback); + inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE", player), schemTypeCallback); } else { - inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", Collections.singletonList("§7Typ: §e" + filter.getType().name()), true, schemTypeCallback); + inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE", player), Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE_SEARCH", player, filter.getType().name())), true, schemTypeCallback); } } @@ -298,16 +274,16 @@ public class SchematicSelector { final int iSlot = target.target== SelectorTarget.Target.SCHEMATIC_TYPE?2:3; if(filter.getItem() == null) { - inv.setItem(iSlot, Material.STONE, "§7Nach Item Filtern...", materialCallback); + inv.setItem(iSlot, Material.STONE, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_MAT", player), materialCallback); } else { - inv.setItem(iSlot, filter.getItem(), "§7Nach Item Filtern...", Collections.singletonList("§7Item: §e" + filter.getItem().name()), true, materialCallback); + inv.setItem(iSlot, filter.getItem(), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_MAT", player), Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_MAT_SEARCH", player, filter.getItem().name())), true, materialCallback); } - inv.setItem(7, SWItem.getDye(1), "§eAbbrechen", clickType -> { + inv.setItem(7, SWItem.getDye(1), Core.MESSAGE.parse("SCHEM_SELECTOR_CANCEL", player), clickType -> { filter.reset(); openList(null, publics); }); - inv.setItem(8, SWItem.getDye(10), "§eSuchen...", clickType -> { + inv.setItem(8, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_GO", player), clickType -> { filter.setFilter(true); if(useHooks) { injectable.onFilterApply(this); @@ -322,6 +298,51 @@ public class SchematicSelector { inv.open(); } + private List getFilteredSchematics(boolean publics) { + List nodes = new ArrayList<>(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())); + } + return nodes; + } + + private List getSchematicList(boolean publics, SchematicNode parent) { + List nodes = new ArrayList<>(); + 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())); + if(target.rank >= 0) { + nodes.removeIf(node -> node.getRank() > target.rank); + } + break; + default: + nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), parent == null?0:parent.getId())); + } + + if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) { + openList(nodes.get(0), publics); + sdoTrigger = true; + } + return nodes; + } + private static SchematicNode getParent(SchematicNode node) { if(node.getParent() == null) { return null; @@ -363,15 +384,19 @@ public class SchematicSelector { @AllArgsConstructor private enum Target { - SCHEMATIC("Schematic", false), - DIRECTORY("Ordner", true), - SCHEMATIC_NODE("Schematic/Ordner", true), - SCHEMATIC_TYPE("Schematic", false); + SCHEMATIC("SCHEM_SELECTOR_SCHEMATIC", false), + DIRECTORY("SCHEM_SELECTOR_DIRECTORY", true), + SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true), + SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false); @Getter - private String name; + private String rawName; @Getter private boolean dirs; + + public String getName(Player player) { + return Core.MESSAGE.parse(rawName, player); + } } } diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java index 35629d0..fabc33f 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java @@ -25,15 +25,15 @@ import de.steamwar.sql.SchematicNode; public interface SchematicSelectorInjectable { - void onSelectorCreate(SchematicSelector selector); + default void onSelectorCreate(SchematicSelector selector) {} - void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent); + default void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) {} - void onFilterRender(SchematicSelector selector, SWInventory inventory); + default void onFilterRender(SchematicSelector selector, SWInventory inventory) {} - void onFilterApply(SchematicSelector selector); + default void onFilterApply(SchematicSelector selector) {} - boolean onFolderCreate(SchematicSelector selector, String name); + default boolean onFolderCreate(SchematicSelector selector, String name) {return true;} - void onNodeFilter(SchematicSelector selector, SchematicNode node); + default void onNodeFilter(SchematicSelector selector, SchematicNode node) {} } diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectableAdapter.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectableAdapter.java deleted file mode 100644 index 883ac84..0000000 --- a/SpigotCore_Main/src/de/steamwar/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.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/SpigotCore_Main/src/de/steamwar/util/UtilGui.java b/SpigotCore_Main/src/de/steamwar/util/UtilGui.java index cfb9012..c653610 100644 --- a/SpigotCore_Main/src/de/steamwar/util/UtilGui.java +++ b/SpigotCore_Main/src/de/steamwar/util/UtilGui.java @@ -19,6 +19,7 @@ package de.steamwar.util; +import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import lombok.experimental.UtilityClass; @@ -33,7 +34,7 @@ import java.util.function.Consumer; public class UtilGui { public static void openMaterialSelector(Player player, Consumer callback) { - openMaterialSelector(player, "Material auswählen", callback); + openMaterialSelector(player, Core.MESSAGE.parse("MATERIAL_SELECTOR_TITLE", player), callback); } public static void openMaterialSelector(Player player, String title, Consumer callback) { From 74a4dba9f3b21b7bf66e99a6d7d2367db110b4cd Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 23 Nov 2021 19:02:23 +0100 Subject: [PATCH 15/31] Public Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java index a8c417d..0a4840c 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -370,7 +370,7 @@ public class SchematicSelector { return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_TYPE, type, rank); } - private static class SelectorTarget { + public static class SelectorTarget { private final Target target; private final SchematicType type; From 256e76f9bb7db8c70b79aa46a2e8702a364df28d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 23 Nov 2021 19:04:15 +0100 Subject: [PATCH 16/31] Enum in a class in a class Signed-off-by: Chaoscaot --- .../de/steamwar/util/SchematicSelector.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java index 0a4840c..dbde6ed 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -234,7 +234,7 @@ public class SchematicSelector { inv.setItem(1, item); } - if(target.target != SelectorTarget.Target.SCHEMATIC_TYPE) { + if(target.target != Target.SCHEMATIC_TYPE) { InvCallback schemTypeCallback = clickType -> { if(clickType.isRightClick()) { filter.setType(null); @@ -271,7 +271,7 @@ public class SchematicSelector { } }; - final int iSlot = target.target== SelectorTarget.Target.SCHEMATIC_TYPE?2:3; + final int iSlot = target.target == Target.SCHEMATIC_TYPE?2:3; if(filter.getItem() == null) { inv.setItem(iSlot, Material.STONE, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_MAT", player), materialCallback); @@ -306,10 +306,10 @@ public class SchematicSelector { } return !filter.matches(node); }); - if(target.target == SelectorTarget.Target.DIRECTORY) { + if(target.target == Target.DIRECTORY) { nodes.removeIf(node -> !node.isDir()); } - if(target.target == SelectorTarget.Target.SCHEMATIC_TYPE) { + if(target.target == Target.SCHEMATIC_TYPE) { nodes.removeIf(node -> node.isDir() || !node.getType().equals(target.type.toDB())); } return nodes; @@ -351,23 +351,23 @@ public class SchematicSelector { } public static SelectorTarget selectSchematic() { - return new SelectorTarget(SelectorTarget.Target.SCHEMATIC, null, -1); + return new SelectorTarget(Target.SCHEMATIC, null, -1); } public static SelectorTarget selectDirectory() { - return new SelectorTarget(SelectorTarget.Target.DIRECTORY, null, -1); + return new SelectorTarget(Target.DIRECTORY, null, -1); } public static SelectorTarget selectSchematicNode() { - return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_NODE, null, -1); + return new SelectorTarget(Target.SCHEMATIC_NODE, null, -1); } public static SelectorTarget selectSchematicType(SchematicType type) { - return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_TYPE, type, -1); + return new SelectorTarget(Target.SCHEMATIC_TYPE, type, -1); } public static SelectorTarget selectSchematicTypeWithRank(SchematicType type, int rank) { - return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_TYPE, type, rank); + return new SelectorTarget(Target.SCHEMATIC_TYPE, type, rank); } public static class SelectorTarget { @@ -381,22 +381,22 @@ public class SchematicSelector { this.type = type; this.rank = rank; } + } - @AllArgsConstructor - private enum Target { - SCHEMATIC("SCHEM_SELECTOR_SCHEMATIC", false), - DIRECTORY("SCHEM_SELECTOR_DIRECTORY", true), - SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true), - SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false); + @AllArgsConstructor + private enum Target { + SCHEMATIC("SCHEM_SELECTOR_SCHEMATIC", false), + DIRECTORY("SCHEM_SELECTOR_DIRECTORY", true), + SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true), + SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false); - @Getter - private String rawName; - @Getter - private boolean dirs; + @Getter + private String rawName; + @Getter + private boolean dirs; - public String getName(Player player) { - return Core.MESSAGE.parse(rawName, player); - } + public String getName(Player player) { + return Core.MESSAGE.parse(rawName, player); } } From fd420778c12d8c2ebb93df4a5cc0e9f7b8d2389d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 23 Nov 2021 19:05:14 +0100 Subject: [PATCH 17/31] Fix Build Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java index dbde6ed..f8a34db 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -24,7 +24,6 @@ import de.steamwar.inventory.*; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; -import jdk.nashorn.internal.runtime.doubleconv.CachedPowers; import lombok.*; import org.bukkit.Material; import org.bukkit.entity.Player; From edee75a522ddf22693d0300e8b556d124c24950e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 24 Nov 2021 17:32:09 +0100 Subject: [PATCH 18/31] Add SWCommand description hover and suggest part command on click --- .../src/de/steamwar/command/SWCommand.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index bcf15da..258ab5c 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -21,6 +21,7 @@ package de.steamwar.command; import de.steamwar.message.Message; import lombok.Setter; +import net.md_5.bungee.api.chat.ClickEvent; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -249,13 +250,7 @@ public abstract class SWCommand { boolean hasTabCompletes = tabCompletes.stream() .anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())); if (hasTabCompletes) { - try { - for (String s : subCommand.description) { - message.sendPrefixless(s, p); - } - } catch (Exception e) { - Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); - } + send(p, subCommand); } else { atomicInteger.incrementAndGet(); } @@ -264,18 +259,24 @@ public abstract class SWCommand { if (args.length == 0 || atomicInteger.get() == commandList.size()) { commandList.forEach(subCommand -> { if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) { - try { - for (String s : subCommand.description) { - message.sendPrefixless(s, p); - } - } catch (Exception e) { - Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); - } + send(p, subCommand); } }); } } + private void send(Player p, SubCommand subCommand) { + try { + for (String s : subCommand.description) { + String hover = "§8/§e" + command.getName() + " " + String.join(" ", subCommand.subCommand); + String suggest = "/" + command.getName() + " " + String.join(" ", subCommand.subCommand); + message.sendPrefixless(s, p, hover, new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest)); + } + } catch (Exception e) { + Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); + } + } + @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) @Repeatable(Register.Registeres.class) From 200a1a4718c5d02d04876298dcbffada6d43072f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 24 Nov 2021 17:40:49 +0100 Subject: [PATCH 19/31] Fix SubCommand.getGuardChecker --- SpigotCore_Main/src/de/steamwar/command/SubCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index 05cba2d..e18b5f8 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -101,7 +101,7 @@ class SubCommand { return localGuardChecker.getOrDefault(s, GUARD_FUNCTIONS.getOrDefault(s, null)); } GuardChecker current = localGuardChecker.getOrDefault(guard.value(), GUARD_FUNCTIONS.getOrDefault(guard.value(), null)); - if (guardChecker == null) { + if (current == null) { Bukkit.getLogger().log(Level.WARNING, () -> "The guard checker with name '" + guard.value() + "' is neither a local guard checker nor a global one"); } return current; From cf9f2a2375ac924b589244dbc6003e483bf5606c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 27 Nov 2021 10:13:19 +0100 Subject: [PATCH 20/31] Fix Language & more PR Stuff Signed-off-by: Chaoscaot --- SpigotCore_Main/src/SpigotCore.properties | 9 +- .../src/de/steamwar/sql/SchematicNode.java | 20 +-- .../de/steamwar/util/SchematicSelector.java | 146 +++++++----------- .../util/SchematicSelectorInjectable.java | 10 ++ 4 files changed, 84 insertions(+), 101 deletions(-) diff --git a/SpigotCore_Main/src/SpigotCore.properties b/SpigotCore_Main/src/SpigotCore.properties index 53227e0..8f75226 100644 --- a/SpigotCore_Main/src/SpigotCore.properties +++ b/SpigotCore_Main/src/SpigotCore.properties @@ -27,23 +27,22 @@ SCHEM_SELECTOR_SEL_DIR= SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner SCHEM_SELECTOR_FILTER=§7Filter -SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner Erstellen +SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner erstellen SCHEM_SELECTOR_FILTER_TITLE=Filter SCHEM_SELECTOR_FILTER_ENTER_NAME=Name eingeben SCHEM_SELECTOR_FILTER_NAME=§7Nach Namen suchen... -SCHEM_SELECTOR_FILTER_NAME_SEARCH=§7Suchwort: §e{0} +SCHEM_SELECTOR_FILTER_NAME_SEARCH=§7Suchbegriff: §e{0} SCHEM_SELECTOR_FILTER_ENTER_OWNER=Besitzer eingeben SCHEM_SELECTOR_FILTER_OWNER=§7Nach Besitzer suchen... SCHEM_SELECTOR_FILTER_OWNER_SEARCH=§7Besitzer: §e{0} SCHEM_SELECTOR_FILTER_SEL_TYPE=Typ wählen... -SCHEM_SELECTOR_FILTER_TYPE=§7Nach Typ Filtern... +SCHEM_SELECTOR_FILTER_TYPE=§7Nach Typ filtern... SCHEM_SELECTOR_FILTER_TYPE_SEARCH=§7Typ: §e{0} -SCHEM_SELECTOR_FILTER_MAT=§7Nach Item Filtern... +SCHEM_SELECTOR_FILTER_MAT=§7Nach Item filtern... SCHEM_SELECTOR_FILTER_MAT_SEARCH=§7Item: §e{0} SCHEM_SELECTOR_CANCEL=§eAbbrechen SCHEM_SELECTOR_GO=§eSuchen... - SCHEM_SELECTOR_SCHEMATIC=Schematic SCHEM_SELECTOR_DIRECTORY=Ordner SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Ordner diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 009920c..f850a03 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -57,7 +57,7 @@ public class SchematicNode { private static final SQL.Statement getAccessibleByUserByTypeInNode_Null = new SQL.Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName"); private static final SQL.Statement getAccessibleByUserByType = new SQL.Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName"); private static final SQL.Statement getAllSchematicsAccessibleByUser = new SQL.Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName"); - private static final SQL.Statement isSchematicAccessibleForUser = new SQL.Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1 ORDER BY NodeName"); + private static final SQL.Statement isSchematicAccessibleForUser = new SQL.Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1"); private static final SQL.Statement getAllParentsOfNode = new SQL.Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName"); private static final SQL.Statement countNodes = new SQL.Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode"); private static final SQL.Statement updateDB = new SQL.Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?"); @@ -80,8 +80,6 @@ public class SchematicNode { return getSchematicNode(owner, name, parent); } - private Timestamp lastUpdate; - public static SchematicNode getSchematicNode(int owner, String name, SchematicNode parent) { return getSchematicNode(owner, name, parent.getId()); } @@ -119,9 +117,8 @@ public class SchematicNode { parent = null; } SQL.Statement.ResultSetUser user = rs -> { - while (rs.next()) { - SchematicNode node = new SchematicNode(rs); - return node; + if (rs.next()) { + return new SchematicNode(rs); } return null; }; @@ -137,8 +134,9 @@ public class SchematicNode { parent = null; SQL.Statement.ResultSetUser> user = rs -> { List nodes = new ArrayList<>(); - while (rs.next()) + while (rs.next()) { nodes.add(new SchematicNode(rs)); + } return nodes; }; if(parent == null) { @@ -266,11 +264,12 @@ public class SchematicNode { public static List getSchematicsAccessibleByUser(int user, Integer parent) { if (parent != null && parent != 0) { - if(isSchematicAccessibleForUser.select(rs -> { + if(Boolean.TRUE.equals(isSchematicAccessibleForUser.select(rs -> { rs.next(); return rs.getInt("Accessible") > 0; - }, parent, user, user)) + }, parent, user, user))) { return getSchematicNodeInNode(parent); + } } else { return getAccessibleByUser.select(rs -> { List nodes = new ArrayList<>(); @@ -322,7 +321,7 @@ public class SchematicNode { if (currentNode == null) { node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny(); } else { - node = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny(); + node = Optional.of(SchematicNode.getSchematicNode(layers[i], currentNode.getId())); } if (!node.isPresent()) { return null; @@ -348,6 +347,7 @@ public class SchematicNode { private String type; private boolean schemFormat; private int rank; + private Timestamp lastUpdate; private final boolean isDir; private Map brCache = new HashMap<>(); diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java index f8a34db..f992c53 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -34,33 +34,27 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.Consumer; -import java.util.function.Function; public class SchematicSelector { - public static final String DEFAULT_TITLE = "SCHEM_SELECTOR_TITLE"; + protected static final String DEFAULT_TITLE = "SCHEM_SELECTOR_TITLE"; @Getter private final Player player; @Getter - private final SteamwarUser user; + private 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; + private SchematicSelectorInjectable injectable = SchematicSelectorInjectable.DEFAULT; @Setter @Getter private PublicMode publicMode = PublicMode.ALL; @Setter @Getter private boolean singleDirOpen; - @Setter - @Getter - private Function title; private boolean sdoTrigger = false; public SchematicSelector(Player player, SelectorTarget target, Consumer callback) { @@ -68,24 +62,24 @@ public class SchematicSelector { this.user = SteamwarUser.get(player.getUniqueId()); this.target = target; this.callback = callback; - this.singleDirOpen = !target.target.isDirs(); + this.singleDirOpen = !target.target.dirs; } 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); + injectable.onSelectorCreate(this); + if(publicMode == PublicMode.PUBLIC_ONLY) { + this.user = SteamwarUser.get(0); } - openList(null, publicMode == PublicMode.PUBLIC_ONLY); + openList(null); } - private void openList(SchematicNode parent, boolean publics) { - List nodes = filter.isFilter()?getFilteredSchematics(publics):getSchematicList(publics, parent); + private void openList(SchematicNode parent) { + List nodes = filter.isFilter()?getFilteredSchematics():getSchematicList(parent); if(sdoTrigger) { sdoTrigger = false; @@ -103,44 +97,48 @@ public class SchematicSelector { list.add(renderItem(node)); } - SWListInv inv = new SWListInv<>(player, MessageFormat.format(title==null?DEFAULT_TITLE:title.apply(player), target.target.getName(player), filter.getName().isEmpty()?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.getName()), false, list, (clickType, node) -> handleClick(publics, node, parent)); + SWListInv inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), filter.getName().isEmpty()?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent)); if(publicMode == PublicMode.ALL) { - if(publics) { - inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> openList(null, false)); + if(user.getId() == 0) { + inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> { + this.user = SteamwarUser.get(player.getUniqueId()); + openList(null); + }); } else { - inv.setItem(48, Material.GLASS, Core.MESSAGE.parse("SCHEM_SELECTOR_PUB", player), clickType -> openList(null, true)); + inv.setItem(48, Material.GLASS, Core.MESSAGE.parse("SCHEM_SELECTOR_PUB", player), clickType -> { + this.user = SteamwarUser.get(0); + openList(null); + }); } } - if(target.target.isDirs()) { + if(target.target.dirs) { inv.setItem(49, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_SEL_DIR", player), clickType -> { player.closeInventory(); callback.accept(parent); }); } - if(!publics) { + if(user.getId() != 0) { inv.setItem(50, Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent)); } - inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter(publics)); + inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter()); - if(useHooks) { - injectable.onListRender(this, inv, parent); - } + injectable.onListRender(this, inv, parent); inv.open(); } - private void handleClick(boolean publics, SchematicNode node, SchematicNode parent) { + private void handleClick(SchematicNode node, SchematicNode parent) { if(node == null) { - openList(getParent(parent), publics); + openList(getParent(parent)); return; } if(node.isDir()) { - if(filter.isFilter() && target.target.isDirs()) { + if(filter.isFilter() && target.target.dirs) { player.closeInventory(); callback.accept(node); return; } filter.reset(); - openList(node, publics); + openList(node); return; } player.closeInventory(); @@ -172,31 +170,26 @@ public class SchematicSelector { SWAnvilInv inv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_CREATE_DIR_TITLE", player)); 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 { + if(injectable.onFolderCreate(this, s)) { SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId()); - openList(parent, false); + openList(parent); } }); inv.open(); } - private void openFilter(boolean publics) { + private void openFilter() { SWInventory inv = new SWInventory(player, 9, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE", player)); InvCallback nameCallback = clickType -> { if(clickType.isRightClick()) { filter.setName(""); - openFilter(publics); + openFilter(); } else { SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_NAME", player)); swAnvilInv.setItem(Material.NAME_TAG); swAnvilInv.setCallback(s -> { filter.setName(s); - openFilter(publics); + openFilter(); }); swAnvilInv.open(); } @@ -210,13 +203,13 @@ public class SchematicSelector { InvCallback ownerCallback = clickType -> { if(clickType.isRightClick()) { filter.setOwner(null); - openFilter(publics); + openFilter(); } else { SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_OWNER", player)); swAnvilInv.setItem(Material.PLAYER_HEAD); swAnvilInv.setCallback(s -> { filter.setOwner(SteamwarUser.get(s).getId()); - openFilter(publics); + openFilter(); }); swAnvilInv.open(); } @@ -237,7 +230,7 @@ public class SchematicSelector { InvCallback schemTypeCallback = clickType -> { if(clickType.isRightClick()) { filter.setType(null); - openFilter(publics); + openFilter(); } else { List> types = new ArrayList<>(); SchematicType.values().forEach(schematicType -> { @@ -245,7 +238,7 @@ public class SchematicSelector { }); SWListInv listInv = new SWListInv<>(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_SEL_TYPE", player), types, (clickType1, schematicType) -> { filter.setType(schematicType); - openFilter(publics); + openFilter(); }); listInv.open(); } @@ -261,11 +254,11 @@ public class SchematicSelector { InvCallback materialCallback = clickType -> { if(clickType.isRightClick()) { filter.setItem(null); - openFilter(publics); + openFilter(); } else { UtilGui.openMaterialSelector(player, material -> { filter.setItem(material); - openFilter(publics); + openFilter(); }); } }; @@ -280,29 +273,23 @@ public class SchematicSelector { inv.setItem(7, SWItem.getDye(1), Core.MESSAGE.parse("SCHEM_SELECTOR_CANCEL", player), clickType -> { filter.reset(); - openList(null, publics); + openList(null); }); inv.setItem(8, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_GO", player), clickType -> { filter.setFilter(true); - if(useHooks) { - injectable.onFilterApply(this); - } - openList(null, publics); + injectable.onFilterApply(this); + openList(null); }); - if(useHooks) { - injectable.onFilterRender(this, inv); - } + injectable.onFilterRender(this, inv); inv.open(); } - private List getFilteredSchematics(boolean publics) { - List nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(publics ? 0 : user.getId())); + private List getFilteredSchematics() { + List nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(user.getId())); nodes.removeIf(node -> { - if(useHooks) { - injectable.onNodeFilter(this, node); - } + injectable.onNodeFilter(this, node); return !filter.matches(node); }); if(target.target == Target.DIRECTORY) { @@ -314,29 +301,29 @@ public class SchematicSelector { return nodes; } - private List getSchematicList(boolean publics, SchematicNode parent) { + private List getSchematicList(SchematicNode parent) { List nodes = new ArrayList<>(); switch (target.target) { case DIRECTORY: if(parent == null) { - nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), null)); + nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(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())); + nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(user.getId(), target.type.toDB(), parent==null?0:parent.getId())); if(target.rank >= 0) { nodes.removeIf(node -> node.getRank() > target.rank); } break; default: - nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), parent == null?0:parent.getId())); + nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(user.getId(), parent == null?0:parent.getId())); } if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) { - openList(nodes.get(0), publics); + openList(nodes.get(0)); sdoTrigger = true; } return nodes; @@ -369,17 +356,12 @@ public class SchematicSelector { return new SelectorTarget(Target.SCHEMATIC_TYPE, type, rank); } - public static class SelectorTarget { + @AllArgsConstructor + static class SelectorTarget { private final Target target; private final SchematicType type; private final int rank; - - private SelectorTarget(Target target, SchematicType type, int rank) { - this.target = target; - this.type = type; - this.rank = rank; - } } @AllArgsConstructor @@ -389,12 +371,10 @@ public class SchematicSelector { SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true), SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false); - @Getter private String rawName; - @Getter private boolean dirs; - public String getName(Player player) { + private String getName(Player player) { return Core.MESSAGE.parse(rawName, player); } } @@ -421,22 +401,16 @@ public class SchematicSelector { public boolean matches(SchematicNode node) { boolean matches = true; - if(!name.isEmpty()) { - if(!node.getName().contains(name)) { - matches = false; - } + if(!name.isEmpty() && !node.getName().contains(name)) { + matches = false; } - if(owner != null) { - if(node.getOwner() != owner) { - matches = false; - } + if(owner != null && node.getOwner() != owner) { + matches = false; } - if(type != null) { - if(node.isDir() || !node.getType().equals(type.toDB())) { - matches = false; - } + if(type != null && (node.isDir() || !node.getSchemtype().equals(type))) { + matches = false; } if(item != null) { diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java index fabc33f..d8a6193 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java @@ -19,12 +19,20 @@ package de.steamwar.util; +import de.steamwar.core.Core; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWListInv; import de.steamwar.sql.SchematicNode; +import org.bukkit.entity.Player; public interface SchematicSelectorInjectable { + SchematicSelectorInjectable DEFAULT = new DefaultSchematicSelectorInjectable(); + + default String createTitle(Player player) { + return Core.MESSAGE.parse("DEFAULT_TITLE", player); + } + default void onSelectorCreate(SchematicSelector selector) {} default void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) {} @@ -36,4 +44,6 @@ public interface SchematicSelectorInjectable { default boolean onFolderCreate(SchematicSelector selector, String name) {return true;} default void onNodeFilter(SchematicSelector selector, SchematicNode node) {} + + class DefaultSchematicSelectorInjectable implements SchematicSelectorInjectable {} } From 82421d95441b050a2a65573652962509933f4e03 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 27 Nov 2021 10:34:53 +0100 Subject: [PATCH 21/31] Fixing... Signed-off-by: Chaoscaot --- SpigotCore_Main/src/SpigotCore.properties | 2 +- .../de/steamwar/util/SchematicSelector.java | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/SpigotCore_Main/src/SpigotCore.properties b/SpigotCore_Main/src/SpigotCore.properties index 8f75226..66ec9a1 100644 --- a/SpigotCore_Main/src/SpigotCore.properties +++ b/SpigotCore_Main/src/SpigotCore.properties @@ -19,7 +19,7 @@ SCHEM_SELECTOR_TITLE={0} auswählen: {1} SCHEM_SELECTOR_BACK=§eZurück -SCHEM_SELECTOR_DIR=Ordner +SCHEM_SELECTOR_DIR=§9Ordner SCHEM_SELECTOR_RANK=§8Rang {0} SCHEM_SELECTOR_OWN=§7Eigene Schematics SCHEM_SELECTOR_PUB=§7Public Schematics diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java index f992c53..ba3ff0c 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -97,7 +97,7 @@ public class SchematicSelector { list.add(renderItem(node)); } - SWListInv inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), filter.getName().isEmpty()?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent)); + SWListInv inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), filter.getName() == null?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent)); if(publicMode == PublicMode.ALL) { if(user.getId() == 0) { inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> { @@ -152,13 +152,13 @@ public class SchematicSelector { else m = SWItem.getMaterial(node.getItem()); - String name = "§" + (filter.getName().isEmpty()?"e":"7") + node.getName(); + String name = "§" + (filter.getName() == null?"e":"7") + node.getName(); - if(!filter.getName().isEmpty()) { + if(filter.getName() != null) { name = name.replace(filter.getName(), "§e" + filter.getName() + "§7"); } - SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? ("§9" + Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : "§7" + node.getSchemtype().name()), !node.isDir() && !node.getSchemtype().writeable(), click -> { + SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? (Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : "§7" + node.getSchemtype().name()), !node.isDir() && !node.getSchemtype().writeable(), click -> { }); if(!node.isDir() && node.getRank() > 0) { item.setLore(Arrays.asList("§7" + node.getSchemtype().name(), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player))); @@ -182,7 +182,7 @@ public class SchematicSelector { SWInventory inv = new SWInventory(player, 9, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE", player)); InvCallback nameCallback = clickType -> { if(clickType.isRightClick()) { - filter.setName(""); + filter.setName(null); openFilter(); } else { SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_NAME", player)); @@ -194,7 +194,7 @@ public class SchematicSelector { swAnvilInv.open(); } }; - if(filter.getName().isEmpty()) { + if(filter.getName() == null) { inv.setItem(0, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME", player), nameCallback); } else { inv.setItem(0, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME", player), Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME_SEARCH", player, filter.getName())), true, nameCallback); @@ -386,13 +386,13 @@ public class SchematicSelector { private boolean filter; - private String name = ""; + private String name = null; private Integer owner = null; private SchematicType type = null; private Material item = null; public void reset() { - name = ""; + name = null; owner = null; type = null; item = null; @@ -401,7 +401,7 @@ public class SchematicSelector { public boolean matches(SchematicNode node) { boolean matches = true; - if(!name.isEmpty() && !node.getName().contains(name)) { + if(name != null && !node.getName().contains(name)) { matches = false; } From becee281f66932b6596e39e369548bf0c10ad4ce Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 27 Nov 2021 10:40:54 +0100 Subject: [PATCH 22/31] More Language Signed-off-by: Chaoscaot --- SpigotCore_Main/src/SpigotCore.properties | 5 +++++ .../src/de/steamwar/util/SchematicSelector.java | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/SpigotCore.properties b/SpigotCore_Main/src/SpigotCore.properties index 66ec9a1..e36969f 100644 --- a/SpigotCore_Main/src/SpigotCore.properties +++ b/SpigotCore_Main/src/SpigotCore.properties @@ -27,6 +27,11 @@ SCHEM_SELECTOR_SEL_DIR= SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner SCHEM_SELECTOR_FILTER=§7Filter +SCHEM_SELECTOR_ITEM_NAME=§e{0} +SCHEM_SELECTOR_ITEM_NAME_FILTER=§7{0} +SCHEM_SELECTOR_ITEM_REPLACE=§e{0}§7 +SCHEM_SELECTOR_ITEM_LORE_TYPE=§7{0} + SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner erstellen SCHEM_SELECTOR_FILTER_TITLE=Filter diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java index ba3ff0c..d1e3f01 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -152,16 +152,16 @@ public class SchematicSelector { else m = SWItem.getMaterial(node.getItem()); - String name = "§" + (filter.getName() == null?"e":"7") + node.getName(); + String name = Core.MESSAGE.parse(filter.name == null?"SCHEM_SELECTOR_ITEM_NAME":"SCHEM_SELECTOR_ITEM_NAME_FILTER", player, node.getName()); if(filter.getName() != null) { - name = name.replace(filter.getName(), "§e" + filter.getName() + "§7"); + name = name.replace(filter.getName(), Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_REPLACE", player, filter.getName())); } - SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? (Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : "§7" + node.getSchemtype().name()), !node.isDir() && !node.getSchemtype().writeable(), click -> { + SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? (Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getSchemtype().name())), !node.isDir() && !node.getSchemtype().writeable(), click -> { }); if(!node.isDir() && node.getRank() > 0) { - item.setLore(Arrays.asList("§7" + node.getSchemtype().name(), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player))); + item.setLore(Arrays.asList(Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_LORE_TYPE", player, node.getSchemtype().name()), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player))); } return new SWListInv.SWListEntry<>(item, node); } From f15e051d50a7a65a71e3878cc11cf544fbd34c39 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 27 Nov 2021 11:16:16 +0100 Subject: [PATCH 23/31] Fix Default Signed-off-by: Chaoscaot --- .../src/de/steamwar/util/SchematicSelectorInjectable.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java index d8a6193..fd8f4ce 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java @@ -27,7 +27,7 @@ import org.bukkit.entity.Player; public interface SchematicSelectorInjectable { - SchematicSelectorInjectable DEFAULT = new DefaultSchematicSelectorInjectable(); + SchematicSelectorInjectable DEFAULT = new SchematicSelectorInjectable() {}; default String createTitle(Player player) { return Core.MESSAGE.parse("DEFAULT_TITLE", player); @@ -44,6 +44,4 @@ public interface SchematicSelectorInjectable { default boolean onFolderCreate(SchematicSelector selector, String name) {return true;} default void onNodeFilter(SchematicSelector selector, SchematicNode node) {} - - class DefaultSchematicSelectorInjectable implements SchematicSelectorInjectable {} } From 117277c926992f2c3dd8b748deafc43b4ccb76a8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 27 Nov 2021 11:16:56 +0100 Subject: [PATCH 24/31] Fix Default Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java | 2 -- .../src/de/steamwar/util/SchematicSelectorInjectable.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java index d1e3f01..9518707 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -37,8 +37,6 @@ import java.util.function.Consumer; public class SchematicSelector { - protected static final String DEFAULT_TITLE = "SCHEM_SELECTOR_TITLE"; - @Getter private final Player player; @Getter diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java index fd8f4ce..4f2f63e 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java @@ -30,7 +30,7 @@ public interface SchematicSelectorInjectable { SchematicSelectorInjectable DEFAULT = new SchematicSelectorInjectable() {}; default String createTitle(Player player) { - return Core.MESSAGE.parse("DEFAULT_TITLE", player); + return Core.MESSAGE.parse("SCHEM_SELECTOR_TITLE", player); } default void onSelectorCreate(SchematicSelector selector) {} From e73ae9210ce9c59513796770257c8e90cda8314a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 27 Nov 2021 15:12:54 +0100 Subject: [PATCH 25/31] Fix Default Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java | 6 +++++- SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index f850a03..4e959a3 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -22,6 +22,7 @@ package de.steamwar.sql; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; import de.steamwar.core.WorldEditWrapper; +import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; import java.io.ByteArrayInputStream; @@ -321,7 +322,7 @@ public class SchematicNode { if (currentNode == null) { node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny(); } else { - node = Optional.of(SchematicNode.getSchematicNode(layers[i], currentNode.getId())); + node = Optional.ofNullable(SchematicNode.getSchematicNode(layers[i], currentNode.getId())); } if (!node.isPresent()) { return null; @@ -401,6 +402,9 @@ public class SchematicNode { } public String getItem() { + if (item.isEmpty()) { + return isDir ? "CHEST" : "CAULDRON_ITEM"; + } return item; } diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java index 9518707..90f62c7 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java @@ -144,11 +144,7 @@ public class SchematicSelector { } private SWListInv.SWListEntry renderItem(SchematicNode node) { - Material m; - if (node.getItem().isEmpty()) - m = node.isDir()?SWItem.getMaterial("CHEST"):SWItem.getMaterial("CAULDRON_ITEM"); - else - m = SWItem.getMaterial(node.getItem()); + Material m = SWItem.getMaterial(node.getItem()); String name = Core.MESSAGE.parse(filter.name == null?"SCHEM_SELECTOR_ITEM_NAME":"SCHEM_SELECTOR_ITEM_NAME_FILTER", player, node.getName()); From 4d40d1aa466adb2bc53ec91cb62c0f859f2485eb Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 30 Nov 2021 18:01:10 +0100 Subject: [PATCH 26/31] Move Files Signed-off-by: Chaoscaot --- .../de/steamwar/{util => inventory}/SchematicSelector.java | 3 +-- .../{util => inventory}/SchematicSelectorInjectable.java | 4 +--- .../src/de/steamwar/{util => inventory}/UtilGui.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) rename SpigotCore_Main/src/de/steamwar/{util => inventory}/SchematicSelector.java (99%) rename SpigotCore_Main/src/de/steamwar/{util => inventory}/SchematicSelectorInjectable.java (93%) rename SpigotCore_Main/src/de/steamwar/{util => inventory}/UtilGui.java (98%) diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java similarity index 99% rename from SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java rename to SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 90f62c7..83e8ef8 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -17,10 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.util; +package de.steamwar.inventory; import de.steamwar.core.Core; -import de.steamwar.inventory.*; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; diff --git a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java similarity index 93% rename from SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java rename to SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java index 4f2f63e..7c4d718 100644 --- a/SpigotCore_Main/src/de/steamwar/util/SchematicSelectorInjectable.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java @@ -17,11 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.util; +package de.steamwar.inventory; import de.steamwar.core.Core; -import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWListInv; import de.steamwar.sql.SchematicNode; import org.bukkit.entity.Player; diff --git a/SpigotCore_Main/src/de/steamwar/util/UtilGui.java b/SpigotCore_Main/src/de/steamwar/inventory/UtilGui.java similarity index 98% rename from SpigotCore_Main/src/de/steamwar/util/UtilGui.java rename to SpigotCore_Main/src/de/steamwar/inventory/UtilGui.java index c653610..298d0c0 100644 --- a/SpigotCore_Main/src/de/steamwar/util/UtilGui.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/UtilGui.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.util; +package de.steamwar.inventory; import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; From 646d9f7dab9c261cd93b6c8aff800a61072311a5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 30 Nov 2021 18:09:20 +0100 Subject: [PATCH 27/31] Add Command Mapper and some more Functions Signed-off-by: Chaoscaot --- .../de/steamwar/command/SWCommandUtils.java | 12 +++++++++++ .../src/de/steamwar/sql/SchematicNode.java | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index 52e362e..1d7110f 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -19,6 +19,7 @@ package de.steamwar.command; +import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -72,6 +73,17 @@ public class SWCommandUtils { return null; }, s -> Arrays.asList("s", "survival", "0", "c", "creative", "1", "sp", "spectator", "3", "a", "adventure", "2"))); MAPPER_FUNCTIONS.put(SteamwarUser.class.getTypeName(), createMapper(SteamwarUser::get, s -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()))); + MAPPER_FUNCTIONS.put(SchematicNode.class.getTypeName(), new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return SchematicNode.getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), s); + } + + @Override + public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { + return SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s); + } + }); } private static void addMapper(Class clazz, Class alternativeClazz, TypeMapper mapper) { diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index 4e959a3..faea608 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -582,4 +582,24 @@ public class SchematicNode { SchematicNode node = (SchematicNode) obj; return node.getId() == id; } + + public static List getNodeTabcomplete(SteamwarUser user, 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; + } } From 211bda39dc98e8db47fa745818bc1f2f9ba40cf1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 2 Dec 2021 14:34:29 +0100 Subject: [PATCH 28/31] Sort SchematicTypes --- SpigotCore_Main/src/de/steamwar/sql/SchematicType.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java index 6914f4c..5fe5715 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicType.java @@ -24,6 +24,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; import java.util.*; +import java.util.stream.Collectors; public class SchematicType { public static final SchematicType Normal = new SchematicType("Normal", "", Type.NORMAL, null); //Has to stay publicly availible @@ -41,7 +42,7 @@ public class SchematicType { tmpFromDB.put(Normal.name().toLowerCase(), Normal); if(folder.exists()) { - for(File configFile : folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))) { + for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) { YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); if(!config.isConfigurationSection("Schematic")) continue; From 618ce84278f8ee6205e2e60990211e3ba9ce9910 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 3 Dec 2021 16:56:44 +0100 Subject: [PATCH 29/31] Get Player Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java b/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java index f8f2bcb..900c118 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java @@ -21,6 +21,8 @@ package de.steamwar.sql; import de.steamwar.core.Core; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.sql.ResultSet; import java.sql.SQLException; @@ -122,4 +124,8 @@ public class SteamwarUser { }, id); return user; } + + public static SteamwarUser get(Player player) { + return get(player.getUniqueId()); + } } From bbdc8a52afac5974f3398250281a0fd082dabe1f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 3 Dec 2021 16:57:09 +0100 Subject: [PATCH 30/31] Get Player Signed-off-by: Chaoscaot --- SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java b/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java index 900c118..1a7ed6f 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java @@ -21,7 +21,6 @@ package de.steamwar.sql; import de.steamwar.core.Core; import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.sql.ResultSet; From 70fca0bab32e8a50e4df1f51ff80a4bdab77020c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 3 Dec 2021 20:16:21 +0100 Subject: [PATCH 31/31] Trigger rebuild --- SpigotCore_Main/src/de/steamwar/core/Core.java | 1 + 1 file changed, 1 insertion(+) diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index b0fc18f..82f0705 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -38,6 +38,7 @@ import java.util.logging.Level; public class Core extends JavaPlugin{ + private static Core instance; private static final int version; public static Message MESSAGE;