From 6dde2cf3fc57d638238b736bd31836d9165885a6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 12 Jan 2023 21:54:10 +0100 Subject: [PATCH 1/4] NodeMember: Move Member Schematics --- .../schematicsystem/SafeSchematicNode.java | 37 +++--- .../schematicsystem/commands/GUI.java | 69 ++++++----- .../commands/SchematicCommand.java | 115 ++++++++++-------- .../commands/SchematicCommandUtils.java | 78 ++++++------ 4 files changed, 162 insertions(+), 137 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java index ec0c117..95e2e72 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java @@ -1,24 +1,25 @@ /* - This file is a part of the SteamWar software. + This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2023 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 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. + 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 . -*/ + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ package de.steamwar.schematicsystem; +import de.steamwar.sql.EffectiveSchematicNode; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import lombok.AllArgsConstructor; @@ -32,8 +33,8 @@ public class SafeSchematicNode { return Result.NOT_OWNER; } if(newParent == null) { - if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0) - .stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) { + if(EffectiveSchematicNode.list(user, 0) + .stream().map(EffectiveSchematicNode::getNodeName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) { return Result.ALREADY_IN_DIRECTORY; } @@ -43,8 +44,8 @@ public class SafeSchematicNode { return Result.NOT_A_DIR; } - if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), newParent.getId()) - .stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) { + if(EffectiveSchematicNode.list(user, newParent.getId()) + .stream().map(EffectiveSchematicNode::getNodeName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) { return Result.ALREADY_IN_DIRECTORY; } @@ -62,7 +63,7 @@ public class SafeSchematicNode { return Result.INVALID_NAME; } - if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), node.getParent()).stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(name))) { + if(EffectiveSchematicNode.list(user, node.getParent()).stream().map(EffectiveSchematicNode::getNodeName).anyMatch(s -> s.equalsIgnoreCase(name))) { return Result.ALREADY_IN_DIRECTORY; } diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java index 0dbfc95..22f583f 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java @@ -1,21 +1,21 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam +/* + This file is a part of the SteamWar software. - 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. + Copyright (C) 2023 SteamWar.de-Serverteam - 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. + 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. - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ package de.steamwar.schematicsystem.commands; @@ -50,7 +50,7 @@ public class GUI { } @Override - public void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) { + public void onListRender(SchematicSelector selector, SWListInv inv, EffectiveSchematicNode parent) { inv.setCallback(-999, (ClickType click) -> { if(parent == null) { player.closeInventory(); @@ -62,7 +62,7 @@ public class GUI { inv.setItem(49, Material.AIR, "", clickType -> {}); } else { inv.setItem(49, Material.ANVIL, SchematicSystem.MESSAGE.parse("GUI_FOLDER_PROPERTIES", player), clickType -> { - info(selector.getPlayer(), parent, selector); + info(selector.getPlayer(), parent.toSchematicNode(), selector); }); } } @@ -72,7 +72,7 @@ public class GUI { return AnvilInvCloseAction.REOPEN; } }, node -> {}); - selector.setCallback(node -> info(player, node, selector)); + selector.setCallback(node -> info(player, node.toSchematicNode(), selector)); selector.setSingleDirOpen(false); selector.open(); } @@ -154,17 +154,6 @@ public class GUI { }); skull.setName(SchematicSystem.MESSAGE.parse("GUI_INFO_MEMBER", player)); inv.setItem(8, skull); - inv.setItem(15, Material.ARROW, SchematicSystem.MESSAGE.parse("GUI_INFO_MOVE", player), clickType -> { - SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectDirectory(), npar -> { - SafeSchematicNode.Result result = SafeSchematicNode.setParent(user, node, npar); - if(result.isSuccessful()) { - info(player, SchematicNode.getSchematicNode(node.getId()), back); - } else { - result.sendError(player); - } - }); - selector.open(); - }); inv.setItem(16, Material.NAME_TAG, SchematicSystem.MESSAGE.parse("GUI_INFO_RENAME", player), clickType -> { SWAnvilInv anvilInv = new SWAnvilInv(player, SchematicSystem.MESSAGE.parse("GUI_INFO_RENAME_TITLE", player, node.getName()), node.getName()); anvilInv.setItem(mat, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false); @@ -199,6 +188,28 @@ public class GUI { } } + if(node.getOwner() == user.getId() || NodeMember.getNodeMember(node.getId(), user.getId()) != null) { + inv.setItem(15, Material.ARROW, SchematicSystem.MESSAGE.parse("GUI_INFO_MOVE", player), clickType -> { + SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectDirectory(), npar -> { + if(npar != null && EffectiveSchematicNode.parentsOfNode(user, npar.getNodeId()).stream().anyMatch(n -> n.getNodeId() == node.getId())) { + SchematicSystem.MESSAGE.send("COMMAND_MOVE_RECURSIVE", player); + return; + } + if(node.getOwner() == user.getId()) { + SafeSchematicNode.Result result = SafeSchematicNode.setParent(user, node, Optional.ofNullable(npar).map(EffectiveSchematicNode::toSchematicNode).orElse(null)); + if(result.isSuccessful()) { + info(player, SchematicNode.getSchematicNode(node.getId()), back); + } else { + result.sendError(player); + } + } else { + NodeMember.getNodeMember(node.getId(), user.getId()).setParentId(Optional.ofNullable(npar).map(EffectiveSchematicNode::getNodeId).orElse(null)); + } + }); + selector.open(); + }); + } + inv.setCallback(-999, click -> back.reOpen()); inv.open(); } diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index d347a21..dbd3403 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -1,21 +1,21 @@ /* - This file is a part of the SteamWar software. + This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2023 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 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. + 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 . -*/ + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ package de.steamwar.schematicsystem.commands; @@ -99,7 +99,7 @@ public class SchematicCommand extends SWCommand { @Register("list") @Register({"list", "/"}) public void schemList(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) { - createCachedSchemList(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), 0), Math.max(page - 1, 0), null, SchematicListBehavior.DEFAULT); + createCachedSchemList(player, EffectiveSchematicNode.list(getUser(player), 0), Math.max(page - 1, 0), null, SchematicListBehavior.DEFAULT); } @Register({"list", "public"}) @@ -110,13 +110,13 @@ public class SchematicCommand extends SWCommand { @Register({"list", "public"}) @Register({"list", "public", "/"}) public void schemListPublic(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) { - createCachedSchemList(player, SchematicNode.getSchematicsAccessibleByUser(0, 0), Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(true).setPageCommandGen(integer -> "/schem list public " + integer).build()); + createCachedSchemList(player, EffectiveSchematicNode.list(SteamwarUser.get(0), 0), Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(true).setPageCommandGen(integer -> "/schem list public " + integer).build()); } @Register("list") public void schemList(Player player, @Validator("isDirValidator") @Mapper("dirMapper") SchematicNode node, @OptionalValue("1") int page) { SteamwarUser user = getUser(player); - createCachedSchemList(player, SchematicNode.getSchematicNodeInNode(node), Math.max(page - 1, 0), node, SchematicListBehavior.builder().setPublics(node.getOwner() == 0).setPageCommandGen(value -> "/schem list " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs(user) + " " + value).build()); + createCachedSchemList(player, EffectiveSchematicNode.list(user, node.getId()), Math.max(page - 1, 0), EffectiveSchematicNode.byIdAndUser(user, node.getId()).orElse(null), SchematicListBehavior.builder().setPublics(node.getOwner() == 0).setPageCommandGen(value -> "/schem list " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs(user) + " " + value).build()); } @Register({"info", "public"}) @@ -148,11 +148,11 @@ public class SchematicCommand extends SWCommand { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); if(schematicNode == null || schematicNode.isDir()) { SWAnvilInv anvilInv = new SWAnvilInv(player, SchematicSystem.MESSAGE.parse("COMMAND_ENTER_NAME", player)); - anvilInv.setCallback(s -> saveSchem(player, schematicNode==null?s:(schematicNode.generateBreadcrumbs(user) + s))); + anvilInv.setCallback(s -> saveSchem(player, schematicNode==null?s:(schematicNode.generateBreadcrumbs() + s))); anvilInv.setItem(Material.CAULDRON); anvilInv.open(); } else { - saveSchem(player, schematicNode.generateBreadcrumbs(user)); + saveSchem(player, schematicNode.generateBreadcrumbs()); } }); selector.setSingleDirOpen(false); @@ -289,7 +289,7 @@ public class SchematicCommand extends SWCommand { public void schemSearch(Player player, @OptionalValue("1") int page, @Mapper("searchMapper") String... query) { SteamwarUser user = getUser(player); int userId = user.getId(); - List> predicates = new ArrayList<>(); + List> predicates = new ArrayList<>(); List nameList = new ArrayList<>(); int i = 0; while (i < query.length) { @@ -303,10 +303,10 @@ public class SchematicCommand extends SWCommand { int finalI = i; switch (current) { case "-type": - predicates.add(node -> node.getSchemtype().name().equalsIgnoreCase(query[finalI + 1])); + predicates.add(node -> node.getNodeType().name().equalsIgnoreCase(query[finalI + 1])); break; case "-item": - predicates.add(node -> node.getItem().equalsIgnoreCase(query[finalI + 1])); + predicates.add(node -> node.getNodeItem().equalsIgnoreCase(query[finalI + 1])); break; case "-owner": SteamwarUser steamwarUser = SteamwarUser.get(query[finalI + 1]); @@ -314,13 +314,13 @@ public class SchematicCommand extends SWCommand { SchematicSystem.MESSAGE.send("COMMAND_SEARCH_NOT_A_PLAYER", player, query[finalI + 1]); return; } - predicates.add(node -> node.getOwner() == steamwarUser.getId()); + predicates.add(node -> node.getNodeOwner() == steamwarUser.getId()); break; case "-exclude": - predicates.add(node -> !node.getName().contains(query[finalI + 1])); + predicates.add(node -> !node.getNodeName().contains(query[finalI + 1])); break; case "-excludeType": - predicates.add(node -> !node.getSchemtype().name().equalsIgnoreCase(query[finalI + 1])); + predicates.add(node -> !node.getNodeType().name().equalsIgnoreCase(query[finalI + 1])); break; case "-excludeOwner": SteamwarUser steamwarUser1 = SteamwarUser.get(query[finalI + 1]); @@ -328,26 +328,26 @@ public class SchematicCommand extends SWCommand { SchematicSystem.MESSAGE.send("COMMAND_SEARCH_NOT_A_PLAYER", player, query[finalI + 1]); return; } - predicates.add(node -> node.getOwner() != steamwarUser1.getId()); + predicates.add(node -> node.getNodeOwner() != steamwarUser1.getId()); break; } i++; } } else { - predicates.add(node -> node.getName().contains(current)); + predicates.add(node -> node.getNodeName().contains(current)); nameList.add(current); } i++; } - List nodes = SchematicNode.filterSchems(userId, node -> { - for (Predicate predicate : predicates) { + List nodes = EffectiveSchematicNode.getAll(user).stream().filter(node -> { + for (Predicate predicate : predicates) { if (!predicate.test(node)) { return false; } } return true; - }); + }).collect(Collectors.toList()); createCachedSchemList(player, nodes, Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(userId == 0).setShowPath(false).setRenderHook(s -> { for (String ss : nameList) { s = s.replace(ss, "§e§l" + ss + "§7"); @@ -427,29 +427,46 @@ public class SchematicCommand extends SWCommand { } @Register("move") - public void moveToNull(Player player, @Validator("isOwnerValidator") SchematicNode node) { + public void moveToNull(Player player, @ErrorMessage("COMMAND_INVALID_NODE") SchematicNode node) { move(player, node, "/"); } @Register("move") - public void move(Player player, @Validator("isOwnerValidator") SchematicNode node, @Mapper("dirStringMapper") String name) { + public void move(Player player, @ErrorMessage("COMMAND_INVALID_NODE") SchematicNode node, @Mapper("dirStringMapper") String name) { SteamwarUser user = getUser(player); if (name.equals("/")) { - node.setParent(null); + if(node.getOwner() == user.getId()) { + node.setParent(null); + } else if(NodeMember.getNodeMember(node.getId(), user.getId()) != null) { + NodeMember member = NodeMember.getNodeMember(node.getId(), user.getId()); + member.setParentId(null); + } else { + SchematicSystem.MESSAGE.send("COMMAND_NOT_OWN", player); + return; + } } else { if (name.startsWith("/")) name = name.substring(1); if (name.endsWith("/")) name = name.substring(0, name.length() - 1); String[] layers = name.split("/"); if (invalidSchemName(player, layers)) return; SchematicNode newNode = mkdirs(layers, user, 0); - if(SchematicNode.getAllParentsOfNode(newNode).contains(node)) { + if(EffectiveSchematicNode.parentsOfNode(user, newNode.getId()).stream().anyMatch(n -> n.getNodeId() == node.getId())) { SchematicSystem.MESSAGE.send("COMMAND_MOVE_RECURSIVE", player); return; } - SafeSchematicNode.Result result = SafeSchematicNode.setParent(user, node, newNode); - if(!result.isSuccessful()) { - result.sendError(player); + + if(node.getOwner() == user.getId()) { + SafeSchematicNode.Result result = SafeSchematicNode.setParent(user, node, newNode); + if(!result.isSuccessful()) { + result.sendError(player); + return; + } + } else if(NodeMember.getNodeMember(node.getId(), user.getId()) != null) { + NodeMember member = NodeMember.getNodeMember(node.getId(), user.getId()); + member.setParentId(newNode.getId()); + } else { + SchematicSystem.MESSAGE.send("COMMAND_NOT_OWN", player); return; } } @@ -651,12 +668,12 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return SchematicNode.getNodeTabcomplete(SteamwarUser.get(0), s); + return EffectiveSchematicNode.getNodeTabcomplete(SteamwarUser.get(0), s); } @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return SchematicNode.getNodeFromPath(SteamwarUser.get(0), s); + return EffectiveSchematicNode.getNodeFromPath(SteamwarUser.get(0), s).map(EffectiveSchematicNode::toSchematicNode).orElse(null); } }; } @@ -673,13 +690,11 @@ public class SchematicCommand extends SWCommand { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - List list = new ArrayList<>(); - SchematicNode node = SchematicNode.getNodeFromPath(getUser((Player) commandSender), strings[strings.length - 1]); - if (node == null) { - return list; - } - node.getMembers().forEach(nodeMember -> list.add(SteamwarUser.get(nodeMember.getMember()).getUserName())); - return list; + return EffectiveSchematicNode.getNodeFromPath(getUser((Player) commandSender), strings[strings.length - 1]) + .map(EffectiveSchematicNode::toSchematicNode) + .map(SchematicNode::getMembers) + .map(nodeMembers -> nodeMembers.stream().map(NodeMember::getMember).map(SteamwarUser::get).map(SteamwarUser::getUserName).collect(Collectors.toList())) + .orElse(Collections.emptyList()); } }; } @@ -689,14 +704,14 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - List list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); + List list = EffectiveSchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); list.removeIf(s1 -> !s1.endsWith("/")); return list; } @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s); + return EffectiveSchematicNode.getNodeFromPath(getUser((Player) commandSender), s).map(EffectiveSchematicNode::toSchematicNode).orElse(null); } }; } @@ -723,7 +738,7 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - List list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); + List list = EffectiveSchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); list.removeIf(s1 -> !s1.endsWith("/")); return list; } @@ -755,12 +770,12 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); + return EffectiveSchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); } @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s); + return EffectiveSchematicNode.getNodeFromPath(getUser((Player) commandSender), s).map(EffectiveSchematicNode::toSchematicNode).orElse(null); } }; } diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index de38e56..1f756f3 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -1,21 +1,21 @@ /* - This file is a part of the SteamWar software. + This file is a part of the SteamWar software. - Copyright (C) 2020 SteamWar.de-Serverteam + Copyright (C) 2023 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 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. + 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 . -*/ + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ package de.steamwar.schematicsystem.commands; @@ -90,7 +90,7 @@ public class SchematicCommandUtils { return false; } - public static void createCachedSchemList(Player player, List nodes, int chunk, SchematicNode parent, SchematicListBehavior behavior) { + public static void createCachedSchemList(Player player, List nodes, int chunk, EffectiveSchematicNode parent, SchematicListBehavior behavior) { CachedSchematicList cachedSchematicList = new CachedSchematicList(nodes, chunk, (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE), parent, behavior.withPageCommandGen((page) -> "/schematic page " + (page - 1))); CACHED_LISTS.put(player, cachedSchematicList); renderSchemlist(player, cachedSchematicList.nodes, chunk, parent, cachedSchematicList.behavior); @@ -104,62 +104,62 @@ public class SchematicCommandUtils { } public static void renderSchemlist(Player player, - List nodes, + List nodes, int chunk, - SchematicNode parent, + EffectiveSchematicNode parent, SchematicListBehavior behavior) { SteamwarUser user = getUser(player); int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE); SchematicSystem.MESSAGE.sendPrefixless("UTIL_LIST_HEAD", player, nodes.size()); - String breadcrumbs = parent == null ? "" : parent.generateBreadcrumbs(user); + String breadcrumbs = parent == null ? "" : parent.generateBreadcrumbs(); SchematicSystem.MESSAGE.sendPrefixless("UTIL_LIST_PATH", player, (breadcrumbs.isEmpty() ? "/" : breadcrumbs)); if (!breadcrumbs.isEmpty()) { String str = breadcrumbs.substring(0, Math.max(0, breadcrumbs.substring(0, breadcrumbs.length() - 1).lastIndexOf("/"))); SchematicSystem.MESSAGE.sendPrefixless("UTIL_LIST_BACK", player, SchematicSystem.MESSAGE.parse("UTIL_LIST_BACK_HOVER", player, str), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (behavior.isPublics() ? "public" : "") + " " + str)); } for (int i = chunk * CHUNK_SIZE; i < nodes.size() && i < (chunk + 1) * CHUNK_SIZE; i++) { - SchematicNode node = nodes.get(i); + EffectiveSchematicNode node = nodes.get(i); StringBuilder nodeString = new StringBuilder(); if (node.isDir()) { nodeString.append(SchematicSystem.MESSAGE.parse("UTIL_LIST_DIR", player)).append(" "); } else { - SchematicType type = node.getSchemtype(); + SchematicType type = node.getNodeType(); if (type != SchematicType.Normal) { nodeString.append(SchematicSystem.MESSAGE.parse("UTIL_LIST_TYPE", player, type.getKuerzel())).append(" "); } } nodeString.append(SchematicSystem.MESSAGE.parse("UTIL_LIST_BASE", player)); - nodeString.append(behavior.getRenderHook().apply(node.getName())); + nodeString.append(behavior.getRenderHook().apply(node.getNodeName())); if (node.isDir()) { nodeString.append("/"); } - if (node.getOwner() != user.getId()) { - nodeString.append(" ").append(SchematicSystem.MESSAGE.parse("UTIL_LIST_FROM", player, SteamwarUser.get(node.getOwner()).getUserName())); + if (node.getNodeOwner() != user.getId()) { + nodeString.append(" ").append(SchematicSystem.MESSAGE.parse("UTIL_LIST_FROM", player, SteamwarUser.get(node.getNodeOwner()).getUserName())); } TextComponent schematics = new TextComponent(nodeString.toString()); if (node.isDir()) { schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(SchematicSystem.MESSAGE.parse("UTIL_LIST_OPEN_DIR", player)).create())); - schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (behavior.isPublics() ? "public " : "") + breadcrumbs + node.getName() + "/")); + schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (behavior.isPublics() ? "public " : "") + breadcrumbs + node.getNodeName() + "/")); } else { schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(SchematicSystem.MESSAGE.parse("UTIL_LIST_OPEN_SCHEM", player)).create())); - schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (behavior.isPublics() ? "public " : "") + breadcrumbs + node.getName())); + schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (behavior.isPublics() ? "public " : "") + breadcrumbs + node.getNodeName())); } player.spigot().sendMessage(schematics); } - if (parent != null && parent.getOwner() != user.getId() && NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { + if (parent != null && parent.getNodeOwner() != user.getId() && NodeMember.getNodeMember(parent.getNodeId(), user.getId()) != null) { TextComponent deadd = SchematicSystem.MESSAGE.parseToComponent("UTIL_LIST_REMOVE", false, player); deadd.setColor(ChatColor.RED); deadd.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[] {SchematicSystem.MESSAGE.parseToComponent("UTIL_LIST_REMOVE_HOVER", false, player)})); - deadd.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + parent.generateBreadcrumbs(user))); + deadd.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + parent.generateBreadcrumbs())); player.spigot().sendMessage(deadd); } @@ -315,25 +315,23 @@ public class SchematicCommandUtils { } public static SchematicNode mkdirs(String[] layers, SteamwarUser user, int minus) { - SchematicNode currentNode = null; + Optional currentNode = Optional.empty(); for (int i = 0; i < layers.length - minus; i++) { int finalI = i; - List nodes; - if (currentNode == null) { - nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList()); - } else { - nodes = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList()); - } + List nodes = EffectiveSchematicNode.list(user, currentNode.map(EffectiveSchematicNode::getNodeId).orElse(0)).stream() + .filter(effectiveSchematicNode -> effectiveSchematicNode.getNodeName().equalsIgnoreCase(layers[finalI])) + .collect(Collectors.toList()); if (nodes.isEmpty()) { - currentNode = SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode == null ? 0 : currentNode.getId()); + currentNode = EffectiveSchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode.map(EffectiveSchematicNode::getNodeId).orElse(0)).getId()); } else { - if (!nodes.get(0).isDir()) { - nodes.set(0, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode == null ? 0 : currentNode.getId())); + if(nodes.stream().anyMatch(EffectiveSchematicNode::isDir)) { + currentNode = nodes.stream().filter(EffectiveSchematicNode::isDir).findFirst(); + } else { + currentNode = EffectiveSchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode.map(EffectiveSchematicNode::getNodeId).orElse(0)).getId()); } - currentNode = nodes.get(0); } } - return currentNode; + return currentNode.map(EffectiveSchematicNode::toSchematicNode).orElseThrow(() -> new IllegalStateException("Could not create schematic directory")); } public static SteamwarUser getUser(Player player) { @@ -497,10 +495,10 @@ public class SchematicCommandUtils { @AllArgsConstructor @With static class CachedSchematicList { - private List nodes; + private List nodes; private int page; private int maxPage; - private SchematicNode parent; + private EffectiveSchematicNode parent; private SchematicListBehavior behavior; } } -- 2.39.2 From 174808befc6c23cda0a763a6f2fcd6dfb5dd434a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 15 Jan 2023 18:31:50 +0100 Subject: [PATCH 2/4] NodeMember: Move Member Schematics --- .../schematicsystem/SafeSchematicNode.java | 11 ++-- .../schematicsystem/commands/GUI.java | 12 ++-- .../commands/SchematicCommand.java | 57 +++++++++++-------- .../commands/SchematicCommandUtils.java | 42 +++++++------- 4 files changed, 65 insertions(+), 57 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java index 95e2e72..d097509 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java @@ -19,7 +19,6 @@ package de.steamwar.schematicsystem; -import de.steamwar.sql.EffectiveSchematicNode; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import lombok.AllArgsConstructor; @@ -33,8 +32,8 @@ public class SafeSchematicNode { return Result.NOT_OWNER; } if(newParent == null) { - if(EffectiveSchematicNode.list(user, 0) - .stream().map(EffectiveSchematicNode::getNodeName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) { + if(SchematicNode.list(user, 0) + .stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) { return Result.ALREADY_IN_DIRECTORY; } @@ -44,8 +43,8 @@ public class SafeSchematicNode { return Result.NOT_A_DIR; } - if(EffectiveSchematicNode.list(user, newParent.getId()) - .stream().map(EffectiveSchematicNode::getNodeName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) { + if(SchematicNode.list(user, newParent.getId()) + .stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) { return Result.ALREADY_IN_DIRECTORY; } @@ -63,7 +62,7 @@ public class SafeSchematicNode { return Result.INVALID_NAME; } - if(EffectiveSchematicNode.list(user, node.getParent()).stream().map(EffectiveSchematicNode::getNodeName).anyMatch(s -> s.equalsIgnoreCase(name))) { + if(SchematicNode.list(user, node.getParent()).stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(name))) { return Result.ALREADY_IN_DIRECTORY; } diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java index 22f583f..aced87a 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/GUI.java @@ -50,7 +50,7 @@ public class GUI { } @Override - public void onListRender(SchematicSelector selector, SWListInv inv, EffectiveSchematicNode parent) { + public void onListRender(SchematicSelector selector, SWListInv inv, SchematicNode parent) { inv.setCallback(-999, (ClickType click) -> { if(parent == null) { player.closeInventory(); @@ -62,7 +62,7 @@ public class GUI { inv.setItem(49, Material.AIR, "", clickType -> {}); } else { inv.setItem(49, Material.ANVIL, SchematicSystem.MESSAGE.parse("GUI_FOLDER_PROPERTIES", player), clickType -> { - info(selector.getPlayer(), parent.toSchematicNode(), selector); + info(selector.getPlayer(), parent, selector); }); } } @@ -72,7 +72,7 @@ public class GUI { return AnvilInvCloseAction.REOPEN; } }, node -> {}); - selector.setCallback(node -> info(player, node.toSchematicNode(), selector)); + selector.setCallback(node -> info(player, node, selector)); selector.setSingleDirOpen(false); selector.open(); } @@ -191,19 +191,19 @@ public class GUI { if(node.getOwner() == user.getId() || NodeMember.getNodeMember(node.getId(), user.getId()) != null) { inv.setItem(15, Material.ARROW, SchematicSystem.MESSAGE.parse("GUI_INFO_MOVE", player), clickType -> { SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectDirectory(), npar -> { - if(npar != null && EffectiveSchematicNode.parentsOfNode(user, npar.getNodeId()).stream().anyMatch(n -> n.getNodeId() == node.getId())) { + if(npar != null && SchematicNode.parentsOfNode(user, npar.getId()).stream().anyMatch(n -> n.getId() == node.getId())) { SchematicSystem.MESSAGE.send("COMMAND_MOVE_RECURSIVE", player); return; } if(node.getOwner() == user.getId()) { - SafeSchematicNode.Result result = SafeSchematicNode.setParent(user, node, Optional.ofNullable(npar).map(EffectiveSchematicNode::toSchematicNode).orElse(null)); + SafeSchematicNode.Result result = SafeSchematicNode.setParent(user, node, npar); if(result.isSuccessful()) { info(player, SchematicNode.getSchematicNode(node.getId()), back); } else { result.sendError(player); } } else { - NodeMember.getNodeMember(node.getId(), user.getId()).setParentId(Optional.ofNullable(npar).map(EffectiveSchematicNode::getNodeId).orElse(null)); + NodeMember.getNodeMember(node.getId(), user.getId()).setParentId(Optional.ofNullable(npar).map(SchematicNode::getId).orElse(null)); } }); selector.open(); diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index dbd3403..21f9e6e 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -99,7 +99,7 @@ public class SchematicCommand extends SWCommand { @Register("list") @Register({"list", "/"}) public void schemList(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) { - createCachedSchemList(player, EffectiveSchematicNode.list(getUser(player), 0), Math.max(page - 1, 0), null, SchematicListBehavior.DEFAULT); + createCachedSchemList(player, SchematicNode.list(getUser(player), 0), Math.max(page - 1, 0), null, SchematicListBehavior.DEFAULT); } @Register({"list", "public"}) @@ -110,13 +110,13 @@ public class SchematicCommand extends SWCommand { @Register({"list", "public"}) @Register({"list", "public", "/"}) public void schemListPublic(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) { - createCachedSchemList(player, EffectiveSchematicNode.list(SteamwarUser.get(0), 0), Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(true).setPageCommandGen(integer -> "/schem list public " + integer).build()); + createCachedSchemList(player, SchematicNode.list(SteamwarUser.get(0), 0), Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(true).setPageCommandGen(integer -> "/schem list public " + integer).build()); } @Register("list") public void schemList(Player player, @Validator("isDirValidator") @Mapper("dirMapper") SchematicNode node, @OptionalValue("1") int page) { SteamwarUser user = getUser(player); - createCachedSchemList(player, EffectiveSchematicNode.list(user, node.getId()), Math.max(page - 1, 0), EffectiveSchematicNode.byIdAndUser(user, node.getId()).orElse(null), SchematicListBehavior.builder().setPublics(node.getOwner() == 0).setPageCommandGen(value -> "/schem list " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs(user) + " " + value).build()); + createCachedSchemList(player, SchematicNode.list(user, node.getId()), Math.max(page - 1, 0), SchematicNode.byIdAndUser(user, node.getId()), SchematicListBehavior.builder().setPublics(node.getOwner() == 0).setPageCommandGen(value -> "/schem list " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs(user) + " " + value).build()); } @Register({"info", "public"}) @@ -289,7 +289,7 @@ public class SchematicCommand extends SWCommand { public void schemSearch(Player player, @OptionalValue("1") int page, @Mapper("searchMapper") String... query) { SteamwarUser user = getUser(player); int userId = user.getId(); - List> predicates = new ArrayList<>(); + List> predicates = new ArrayList<>(); List nameList = new ArrayList<>(); int i = 0; while (i < query.length) { @@ -303,10 +303,10 @@ public class SchematicCommand extends SWCommand { int finalI = i; switch (current) { case "-type": - predicates.add(node -> node.getNodeType().name().equalsIgnoreCase(query[finalI + 1])); + predicates.add(node -> node.getSchemtype().name().equalsIgnoreCase(query[finalI + 1])); break; case "-item": - predicates.add(node -> node.getNodeItem().equalsIgnoreCase(query[finalI + 1])); + predicates.add(node -> node.getItem().equalsIgnoreCase(query[finalI + 1])); break; case "-owner": SteamwarUser steamwarUser = SteamwarUser.get(query[finalI + 1]); @@ -314,13 +314,13 @@ public class SchematicCommand extends SWCommand { SchematicSystem.MESSAGE.send("COMMAND_SEARCH_NOT_A_PLAYER", player, query[finalI + 1]); return; } - predicates.add(node -> node.getNodeOwner() == steamwarUser.getId()); + predicates.add(node -> node.getOwner() == steamwarUser.getId()); break; case "-exclude": - predicates.add(node -> !node.getNodeName().contains(query[finalI + 1])); + predicates.add(node -> !node.getName().contains(query[finalI + 1])); break; case "-excludeType": - predicates.add(node -> !node.getNodeType().name().equalsIgnoreCase(query[finalI + 1])); + predicates.add(node -> !node.getSchemtype().name().equalsIgnoreCase(query[finalI + 1])); break; case "-excludeOwner": SteamwarUser steamwarUser1 = SteamwarUser.get(query[finalI + 1]); @@ -328,20 +328,20 @@ public class SchematicCommand extends SWCommand { SchematicSystem.MESSAGE.send("COMMAND_SEARCH_NOT_A_PLAYER", player, query[finalI + 1]); return; } - predicates.add(node -> node.getNodeOwner() != steamwarUser1.getId()); + predicates.add(node -> node.getOwner() != steamwarUser1.getId()); break; } i++; } } else { - predicates.add(node -> node.getNodeName().contains(current)); + predicates.add(node -> node.getName().contains(current)); nameList.add(current); } i++; } - List nodes = EffectiveSchematicNode.getAll(user).stream().filter(node -> { - for (Predicate predicate : predicates) { + List nodes = SchematicNode.getAll(user).stream().filter(node -> { + for (Predicate predicate : predicates) { if (!predicate.test(node)) { return false; } @@ -451,7 +451,7 @@ public class SchematicCommand extends SWCommand { String[] layers = name.split("/"); if (invalidSchemName(player, layers)) return; SchematicNode newNode = mkdirs(layers, user, 0); - if(EffectiveSchematicNode.parentsOfNode(user, newNode.getId()).stream().anyMatch(n -> n.getNodeId() == node.getId())) { + if(SchematicNode.parentsOfNode(user, newNode.getId()).stream().anyMatch(n -> n.getId() == node.getId())) { SchematicSystem.MESSAGE.send("COMMAND_MOVE_RECURSIVE", player); return; } @@ -668,12 +668,12 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return EffectiveSchematicNode.getNodeTabcomplete(SteamwarUser.get(0), s); + return SchematicNode.getNodeTabcomplete(SteamwarUser.get(0), s); } @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return EffectiveSchematicNode.getNodeFromPath(SteamwarUser.get(0), s).map(EffectiveSchematicNode::toSchematicNode).orElse(null); + return SchematicNode.getNodeFromPath(SteamwarUser.get(0), s); } }; } @@ -690,8 +690,7 @@ public class SchematicCommand extends SWCommand { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return EffectiveSchematicNode.getNodeFromPath(getUser((Player) commandSender), strings[strings.length - 1]) - .map(EffectiveSchematicNode::toSchematicNode) + return Optional.ofNullable(SchematicNode.getNodeFromPath(getUser((Player) commandSender), strings[strings.length - 1])) .map(SchematicNode::getMembers) .map(nodeMembers -> nodeMembers.stream().map(NodeMember::getMember).map(SteamwarUser::get).map(SteamwarUser::getUserName).collect(Collectors.toList())) .orElse(Collections.emptyList()); @@ -704,14 +703,19 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - List list = EffectiveSchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); + List list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); list.removeIf(s1 -> !s1.endsWith("/")); return list; } @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return EffectiveSchematicNode.getNodeFromPath(getUser((Player) commandSender), s).map(EffectiveSchematicNode::toSchematicNode).orElse(null); + SchematicNode node = SchematicNode.getNodeFromPath(getUser((Player) commandSender), s); + if(node.isDir()) { + return node; + } else { + return null; + } } }; } @@ -728,7 +732,12 @@ public class SchematicCommand extends SWCommand { @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return publicCommandTypeMapper.map(commandSender, previousArguments, s); + SchematicNode node = publicCommandTypeMapper.map(commandSender, previousArguments, s); + if(node.isDir()) { + return node; + } else { + return null; + } } }; } @@ -738,7 +747,7 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - List list = EffectiveSchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); + List list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); list.removeIf(s1 -> !s1.endsWith("/")); return list; } @@ -770,12 +779,12 @@ public class SchematicCommand extends SWCommand { return new TypeMapper() { @Override public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return EffectiveSchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); + return SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s); } @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { - return EffectiveSchematicNode.getNodeFromPath(getUser((Player) commandSender), s).map(EffectiveSchematicNode::toSchematicNode).orElse(null); + return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s); } }; } diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index 1f756f3..7fde1f6 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -90,7 +90,7 @@ public class SchematicCommandUtils { return false; } - public static void createCachedSchemList(Player player, List nodes, int chunk, EffectiveSchematicNode parent, SchematicListBehavior behavior) { + public static void createCachedSchemList(Player player, List nodes, int chunk, SchematicNode parent, SchematicListBehavior behavior) { CachedSchematicList cachedSchematicList = new CachedSchematicList(nodes, chunk, (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE), parent, behavior.withPageCommandGen((page) -> "/schematic page " + (page - 1))); CACHED_LISTS.put(player, cachedSchematicList); renderSchemlist(player, cachedSchematicList.nodes, chunk, parent, cachedSchematicList.behavior); @@ -104,9 +104,9 @@ public class SchematicCommandUtils { } public static void renderSchemlist(Player player, - List nodes, + List nodes, int chunk, - EffectiveSchematicNode parent, + SchematicNode parent, SchematicListBehavior behavior) { SteamwarUser user = getUser(player); int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE); @@ -119,43 +119,43 @@ public class SchematicCommandUtils { SchematicSystem.MESSAGE.sendPrefixless("UTIL_LIST_BACK", player, SchematicSystem.MESSAGE.parse("UTIL_LIST_BACK_HOVER", player, str), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (behavior.isPublics() ? "public" : "") + " " + str)); } for (int i = chunk * CHUNK_SIZE; i < nodes.size() && i < (chunk + 1) * CHUNK_SIZE; i++) { - EffectiveSchematicNode node = nodes.get(i); + SchematicNode node = nodes.get(i); StringBuilder nodeString = new StringBuilder(); if (node.isDir()) { nodeString.append(SchematicSystem.MESSAGE.parse("UTIL_LIST_DIR", player)).append(" "); } else { - SchematicType type = node.getNodeType(); + SchematicType type = node.getSchemtype(); if (type != SchematicType.Normal) { nodeString.append(SchematicSystem.MESSAGE.parse("UTIL_LIST_TYPE", player, type.getKuerzel())).append(" "); } } nodeString.append(SchematicSystem.MESSAGE.parse("UTIL_LIST_BASE", player)); - nodeString.append(behavior.getRenderHook().apply(node.getNodeName())); + nodeString.append(behavior.getRenderHook().apply(node.getName())); if (node.isDir()) { nodeString.append("/"); } - if (node.getNodeOwner() != user.getId()) { - nodeString.append(" ").append(SchematicSystem.MESSAGE.parse("UTIL_LIST_FROM", player, SteamwarUser.get(node.getNodeOwner()).getUserName())); + if (node.getOwner() != user.getId()) { + nodeString.append(" ").append(SchematicSystem.MESSAGE.parse("UTIL_LIST_FROM", player, SteamwarUser.get(node.getOwner()).getUserName())); } TextComponent schematics = new TextComponent(nodeString.toString()); if (node.isDir()) { schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(SchematicSystem.MESSAGE.parse("UTIL_LIST_OPEN_DIR", player)).create())); - schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (behavior.isPublics() ? "public " : "") + breadcrumbs + node.getNodeName() + "/")); + schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (behavior.isPublics() ? "public " : "") + breadcrumbs + node.getName() + "/")); } else { schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(SchematicSystem.MESSAGE.parse("UTIL_LIST_OPEN_SCHEM", player)).create())); - schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (behavior.isPublics() ? "public " : "") + breadcrumbs + node.getNodeName())); + schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (behavior.isPublics() ? "public " : "") + breadcrumbs + node.getName())); } player.spigot().sendMessage(schematics); } - if (parent != null && parent.getNodeOwner() != user.getId() && NodeMember.getNodeMember(parent.getNodeId(), user.getId()) != null) { + if (parent != null && parent.getOwner() != user.getId() && NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { TextComponent deadd = SchematicSystem.MESSAGE.parseToComponent("UTIL_LIST_REMOVE", false, player); deadd.setColor(ChatColor.RED); deadd.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[] {SchematicSystem.MESSAGE.parseToComponent("UTIL_LIST_REMOVE_HOVER", false, player)})); @@ -315,23 +315,23 @@ public class SchematicCommandUtils { } public static SchematicNode mkdirs(String[] layers, SteamwarUser user, int minus) { - Optional currentNode = Optional.empty(); + Optional currentNode = Optional.empty(); for (int i = 0; i < layers.length - minus; i++) { int finalI = i; - List nodes = EffectiveSchematicNode.list(user, currentNode.map(EffectiveSchematicNode::getNodeId).orElse(0)).stream() - .filter(effectiveSchematicNode -> effectiveSchematicNode.getNodeName().equalsIgnoreCase(layers[finalI])) + List nodes = SchematicNode.list(user, currentNode.map(SchematicNode::getId).orElse(0)).stream() + .filter(node -> node.getName().equalsIgnoreCase(layers[finalI])) .collect(Collectors.toList()); if (nodes.isEmpty()) { - currentNode = EffectiveSchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode.map(EffectiveSchematicNode::getNodeId).orElse(0)).getId()); + currentNode = Optional.ofNullable(SchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode.map(SchematicNode::getId).orElse(0)).getId())); } else { - if(nodes.stream().anyMatch(EffectiveSchematicNode::isDir)) { - currentNode = nodes.stream().filter(EffectiveSchematicNode::isDir).findFirst(); + if(nodes.stream().anyMatch(SchematicNode::isDir)) { + currentNode = nodes.stream().filter(SchematicNode::isDir).findFirst(); } else { - currentNode = EffectiveSchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode.map(EffectiveSchematicNode::getNodeId).orElse(0)).getId()); + currentNode = Optional.ofNullable(SchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode.map(SchematicNode::getId).orElse(0)).getId())); } } } - return currentNode.map(EffectiveSchematicNode::toSchematicNode).orElseThrow(() -> new IllegalStateException("Could not create schematic directory")); + return currentNode.orElse(null); } public static SteamwarUser getUser(Player player) { @@ -495,10 +495,10 @@ public class SchematicCommandUtils { @AllArgsConstructor @With static class CachedSchematicList { - private List nodes; + private List nodes; private int page; private int maxPage; - private EffectiveSchematicNode parent; + private SchematicNode parent; private SchematicListBehavior behavior; } } -- 2.39.2 From a2ccc6ce4340dcdb2e69f6be5ea961bbb03935d8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 16 Jan 2023 16:52:32 +0100 Subject: [PATCH 3/4] NodeMember: Move Member Schematics --- .../steamwar/schematicsystem/commands/SchematicCommand.java | 6 +++--- .../schematicsystem/commands/SchematicCommandUtils.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 21f9e6e..2199788 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -99,7 +99,7 @@ public class SchematicCommand extends SWCommand { @Register("list") @Register({"list", "/"}) public void schemList(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) { - createCachedSchemList(player, SchematicNode.list(getUser(player), 0), Math.max(page - 1, 0), null, SchematicListBehavior.DEFAULT); + createCachedSchemList(player, SchematicNode.list(getUser(player), null), Math.max(page - 1, 0), null, SchematicListBehavior.DEFAULT); } @Register({"list", "public"}) @@ -110,7 +110,7 @@ public class SchematicCommand extends SWCommand { @Register({"list", "public"}) @Register({"list", "public", "/"}) public void schemListPublic(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) { - createCachedSchemList(player, SchematicNode.list(SteamwarUser.get(0), 0), Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(true).setPageCommandGen(integer -> "/schem list public " + integer).build()); + createCachedSchemList(player, SchematicNode.list(SteamwarUser.get(0), null), Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(true).setPageCommandGen(integer -> "/schem list public " + integer).build()); } @Register("list") @@ -272,7 +272,7 @@ public class SchematicCommand extends SWCommand { if(SchematicNode.getSchematicNode(schematicNode.getName(), newNode == null ? 0 : newNode.getId()) != null) { schematicNode.setName(schematicNode.getName() + "-" + Instant.now().getEpochSecond() % 1000); } - schematicNode.setParent(newNode == null ? 0 : newNode.getId()); + schematicNode.setParent(newNode == null ? null : newNode.getId()); } } diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index 7fde1f6..340a828 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -318,16 +318,16 @@ public class SchematicCommandUtils { Optional currentNode = Optional.empty(); for (int i = 0; i < layers.length - minus; i++) { int finalI = i; - List nodes = SchematicNode.list(user, currentNode.map(SchematicNode::getId).orElse(0)).stream() + List nodes = SchematicNode.list(user, currentNode.map(SchematicNode::getId).orElse(null)).stream() .filter(node -> node.getName().equalsIgnoreCase(layers[finalI])) .collect(Collectors.toList()); if (nodes.isEmpty()) { - currentNode = Optional.ofNullable(SchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode.map(SchematicNode::getId).orElse(0)).getId())); + currentNode = Optional.ofNullable(SchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode.map(SchematicNode::getId).orElse(null)).getId())); } else { if(nodes.stream().anyMatch(SchematicNode::isDir)) { currentNode = nodes.stream().filter(SchematicNode::isDir).findFirst(); } else { - currentNode = Optional.ofNullable(SchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode.map(SchematicNode::getId).orElse(0)).getId())); + currentNode = Optional.ofNullable(SchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode.map(SchematicNode::getId).orElse(null)).getId())); } } } -- 2.39.2 From ee259e28b676d774152e13e7b54c393fa15da359 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 17 Jan 2023 18:13:16 +0100 Subject: [PATCH 4/4] NodeMember: Move Member Schematics --- .../src/de/steamwar/schematicsystem/SafeSchematicNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java index d097509..449d59d 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SafeSchematicNode.java @@ -32,7 +32,7 @@ public class SafeSchematicNode { return Result.NOT_OWNER; } if(newParent == null) { - if(SchematicNode.list(user, 0) + if(SchematicNode.list(user, null) .stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) { return Result.ALREADY_IN_DIRECTORY; } -- 2.39.2