NodeMember: SchematicSystem #137
@ -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
|
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
|
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
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU Affero General Public License for more details.
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.schematicsystem;
|
package de.steamwar.schematicsystem;
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ public class SafeSchematicNode {
|
|||||||
return Result.NOT_OWNER;
|
return Result.NOT_OWNER;
|
||||||
}
|
}
|
||||||
if(newParent == null) {
|
if(newParent == null) {
|
||||||
if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0)
|
if(SchematicNode.list(user, null)
|
||||||
.stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) {
|
.stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) {
|
||||||
return Result.ALREADY_IN_DIRECTORY;
|
return Result.ALREADY_IN_DIRECTORY;
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ public class SafeSchematicNode {
|
|||||||
return Result.NOT_A_DIR;
|
return Result.NOT_A_DIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), newParent.getId())
|
if(SchematicNode.list(user, newParent.getId())
|
||||||
.stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) {
|
.stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) {
|
||||||
return Result.ALREADY_IN_DIRECTORY;
|
return Result.ALREADY_IN_DIRECTORY;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ public class SafeSchematicNode {
|
|||||||
return Result.INVALID_NAME;
|
return Result.INVALID_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), node.getParent()).stream().map(SchematicNode::getName).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;
|
return Result.ALREADY_IN_DIRECTORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
Copyright (C) 2023 SteamWar.de-Serverteam
|
||||||
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,
|
This program is free software: you can redistribute it and/or modify
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
GNU Affero General Public License for more details.
|
(at your option) any later version.
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
This program is distributed in the hope that it will be useful,
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package de.steamwar.schematicsystem.commands;
|
package de.steamwar.schematicsystem.commands;
|
||||||
|
|
||||||
@ -154,17 +154,6 @@ public class GUI {
|
|||||||
});
|
});
|
||||||
skull.setName(SchematicSystem.MESSAGE.parse("GUI_INFO_MEMBER", player));
|
skull.setName(SchematicSystem.MESSAGE.parse("GUI_INFO_MEMBER", player));
|
||||||
inv.setItem(8, skull);
|
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 -> {
|
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());
|
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);
|
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 && 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, 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(SchematicNode::getId).orElse(null));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
selector.open();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
inv.setCallback(-999, click -> back.reOpen());
|
inv.setCallback(-999, click -> back.reOpen());
|
||||||
inv.open();
|
inv.open();
|
||||||
}
|
}
|
||||||
|
@ -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
|
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
|
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
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU Affero General Public License for more details.
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.schematicsystem.commands;
|
package de.steamwar.schematicsystem.commands;
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ public class SchematicCommand extends SWCommand {
|
|||||||
@Register("list")
|
@Register("list")
|
||||||
@Register({"list", "/"})
|
@Register({"list", "/"})
|
||||||
public void schemList(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) {
|
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, SchematicNode.list(getUser(player), null), Math.max(page - 1, 0), null, SchematicListBehavior.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register({"list", "public"})
|
@Register({"list", "public"})
|
||||||
@ -110,13 +110,13 @@ public class SchematicCommand extends SWCommand {
|
|||||||
@Register({"list", "public"})
|
@Register({"list", "public"})
|
||||||
@Register({"list", "public", "/"})
|
@Register({"list", "public", "/"})
|
||||||
public void schemListPublic(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) {
|
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, 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")
|
@Register("list")
|
||||||
public void schemList(Player player, @Validator("isDirValidator") @Mapper("dirMapper") SchematicNode node, @OptionalValue("1") int page) {
|
public void schemList(Player player, @Validator("isDirValidator") @Mapper("dirMapper") SchematicNode node, @OptionalValue("1") int page) {
|
||||||
SteamwarUser user = getUser(player);
|
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, 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"})
|
@Register({"info", "public"})
|
||||||
@ -148,11 +148,11 @@ public class SchematicCommand extends SWCommand {
|
|||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||||
if(schematicNode == null || schematicNode.isDir()) {
|
if(schematicNode == null || schematicNode.isDir()) {
|
||||||
SWAnvilInv anvilInv = new SWAnvilInv(player, SchematicSystem.MESSAGE.parse("COMMAND_ENTER_NAME", player));
|
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.setItem(Material.CAULDRON);
|
||||||
anvilInv.open();
|
anvilInv.open();
|
||||||
} else {
|
} else {
|
||||||
saveSchem(player, schematicNode.generateBreadcrumbs(user));
|
saveSchem(player, schematicNode.generateBreadcrumbs());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
selector.setSingleDirOpen(false);
|
selector.setSingleDirOpen(false);
|
||||||
@ -272,7 +272,7 @@ public class SchematicCommand extends SWCommand {
|
|||||||
if(SchematicNode.getSchematicNode(schematicNode.getName(), newNode == null ? 0 : newNode.getId()) != null) {
|
if(SchematicNode.getSchematicNode(schematicNode.getName(), newNode == null ? 0 : newNode.getId()) != null) {
|
||||||
schematicNode.setName(schematicNode.getName() + "-" + Instant.now().getEpochSecond() % 1000);
|
schematicNode.setName(schematicNode.getName() + "-" + Instant.now().getEpochSecond() % 1000);
|
||||||
}
|
}
|
||||||
schematicNode.setParent(newNode == null ? 0 : newNode.getId());
|
schematicNode.setParent(newNode == null ? null : newNode.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,14 +340,14 @@ public class SchematicCommand extends SWCommand {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SchematicNode> nodes = SchematicNode.filterSchems(userId, node -> {
|
List<SchematicNode> nodes = SchematicNode.getAll(user).stream().filter(node -> {
|
||||||
for (Predicate<SchematicNode> predicate : predicates) {
|
for (Predicate<SchematicNode> predicate : predicates) {
|
||||||
if (!predicate.test(node)) {
|
if (!predicate.test(node)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
}).collect(Collectors.toList());
|
||||||
createCachedSchemList(player, nodes, Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(userId == 0).setShowPath(false).setRenderHook(s -> {
|
createCachedSchemList(player, nodes, Math.max(page - 1, 0), null, SchematicListBehavior.builder().setPublics(userId == 0).setShowPath(false).setRenderHook(s -> {
|
||||||
for (String ss : nameList) {
|
for (String ss : nameList) {
|
||||||
s = s.replace(ss, "§e§l" + ss + "§7");
|
s = s.replace(ss, "§e§l" + ss + "§7");
|
||||||
@ -427,29 +427,46 @@ public class SchematicCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Register("move")
|
@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, "/");
|
move(player, node, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register("move")
|
@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);
|
SteamwarUser user = getUser(player);
|
||||||
|
|
||||||
if (name.equals("/")) {
|
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 {
|
} else {
|
||||||
if (name.startsWith("/")) name = name.substring(1);
|
if (name.startsWith("/")) name = name.substring(1);
|
||||||
if (name.endsWith("/")) name = name.substring(0, name.length() - 1);
|
if (name.endsWith("/")) name = name.substring(0, name.length() - 1);
|
||||||
String[] layers = name.split("/");
|
String[] layers = name.split("/");
|
||||||
if (invalidSchemName(player, layers)) return;
|
if (invalidSchemName(player, layers)) return;
|
||||||
SchematicNode newNode = mkdirs(layers, user, 0);
|
SchematicNode newNode = mkdirs(layers, user, 0);
|
||||||
if(SchematicNode.getAllParentsOfNode(newNode).contains(node)) {
|
if(SchematicNode.parentsOfNode(user, newNode.getId()).stream().anyMatch(n -> n.getId() == node.getId())) {
|
||||||
SchematicSystem.MESSAGE.send("COMMAND_MOVE_RECURSIVE", player);
|
SchematicSystem.MESSAGE.send("COMMAND_MOVE_RECURSIVE", player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SafeSchematicNode.Result result = SafeSchematicNode.setParent(user, node, newNode);
|
|
||||||
if(!result.isSuccessful()) {
|
if(node.getOwner() == user.getId()) {
|
||||||
result.sendError(player);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -673,13 +690,10 @@ public class SchematicCommand extends SWCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
||||||
List<String> list = new ArrayList<>();
|
return Optional.ofNullable(SchematicNode.getNodeFromPath(getUser((Player) commandSender), strings[strings.length - 1]))
|
||||||
SchematicNode node = SchematicNode.getNodeFromPath(getUser((Player) commandSender), strings[strings.length - 1]);
|
.map(SchematicNode::getMembers)
|
||||||
if (node == null) {
|
.map(nodeMembers -> nodeMembers.stream().map(NodeMember::getMember).map(SteamwarUser::get).map(SteamwarUser::getUserName).collect(Collectors.toList()))
|
||||||
return list;
|
.orElse(Collections.emptyList());
|
||||||
}
|
|
||||||
node.getMembers().forEach(nodeMember -> list.add(SteamwarUser.get(nodeMember.getMember()).getUserName()));
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -696,7 +710,12 @@ public class SchematicCommand extends SWCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
|
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s);
|
SchematicNode node = SchematicNode.getNodeFromPath(getUser((Player) commandSender), s);
|
||||||
|
if(node.isDir()) {
|
||||||
|
return node;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -713,7 +732,12 @@ public class SchematicCommand extends SWCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -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
|
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
|
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
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU Affero General Public License for more details.
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.schematicsystem.commands;
|
package de.steamwar.schematicsystem.commands;
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ public class SchematicCommandUtils {
|
|||||||
int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE);
|
int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE);
|
||||||
|
|
||||||
SchematicSystem.MESSAGE.sendPrefixless("UTIL_LIST_HEAD", player, nodes.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));
|
SchematicSystem.MESSAGE.sendPrefixless("UTIL_LIST_PATH", player, (breadcrumbs.isEmpty() ? "/" : breadcrumbs));
|
||||||
if (!breadcrumbs.isEmpty()) {
|
if (!breadcrumbs.isEmpty()) {
|
||||||
String str = breadcrumbs.substring(0, Math.max(0, breadcrumbs.substring(0, breadcrumbs.length() - 1).lastIndexOf("/")));
|
String str = breadcrumbs.substring(0, Math.max(0, breadcrumbs.substring(0, breadcrumbs.length() - 1).lastIndexOf("/")));
|
||||||
@ -159,7 +159,7 @@ public class SchematicCommandUtils {
|
|||||||
TextComponent deadd = SchematicSystem.MESSAGE.parseToComponent("UTIL_LIST_REMOVE", false, player);
|
TextComponent deadd = SchematicSystem.MESSAGE.parseToComponent("UTIL_LIST_REMOVE", false, player);
|
||||||
deadd.setColor(ChatColor.RED);
|
deadd.setColor(ChatColor.RED);
|
||||||
deadd.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[] {SchematicSystem.MESSAGE.parseToComponent("UTIL_LIST_REMOVE_HOVER", false, player)}));
|
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);
|
player.spigot().sendMessage(deadd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,25 +315,23 @@ public class SchematicCommandUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode mkdirs(String[] layers, SteamwarUser user, int minus) {
|
public static SchematicNode mkdirs(String[] layers, SteamwarUser user, int minus) {
|
||||||
SchematicNode currentNode = null;
|
Optional<SchematicNode> currentNode = Optional.empty();
|
||||||
for (int i = 0; i < layers.length - minus; i++) {
|
for (int i = 0; i < layers.length - minus; i++) {
|
||||||
int finalI = i;
|
int finalI = i;
|
||||||
List<SchematicNode> nodes;
|
List<SchematicNode> nodes = SchematicNode.list(user, currentNode.map(SchematicNode::getId).orElse(null)).stream()
|
||||||
if (currentNode == null) {
|
.filter(node -> node.getName().equalsIgnoreCase(layers[finalI]))
|
||||||
nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} else {
|
|
||||||
nodes = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
if (nodes.isEmpty()) {
|
if (nodes.isEmpty()) {
|
||||||
currentNode = SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode == null ? 0 : currentNode.getId());
|
currentNode = Optional.ofNullable(SchematicNode.byIdAndUser(user, SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode.map(SchematicNode::getId).orElse(null)).getId()));
|
||||||
} else {
|
} else {
|
||||||
if (!nodes.get(0).isDir()) {
|
if(nodes.stream().anyMatch(SchematicNode::isDir)) {
|
||||||
nodes.set(0, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode == null ? 0 : currentNode.getId()));
|
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(null)).getId()));
|
||||||
}
|
}
|
||||||
currentNode = nodes.get(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return currentNode;
|
return currentNode.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser getUser(Player player) {
|
public static SteamwarUser getUser(Player player) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren