13
0

Refactor Schematic Command

Dieser Commit ist enthalten in:
Chaoscaot 2023-02-20 12:59:50 +01:00
Ursprung 12ab5b4652
Commit 3abbac1547
20 geänderte Dateien mit 1428 neuen und 993 gelöschten Zeilen

Datei anzeigen

@ -34,6 +34,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.schematicsystem.autocheck.BlockPos;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import org.bukkit.Material;
import java.util.*;

Datei anzeigen

@ -26,6 +26,7 @@ import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
public class SchematicCommand8 implements SchematicCommand.ISchematicCommand {

Datei anzeigen

@ -1,7 +1,7 @@
/*
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
@ -15,13 +15,14 @@
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;
import de.steamwar.message.Message;
import de.steamwar.schematicsystem.commands.DownloadCommand;
import de.steamwar.schematicsystem.commands.SchematicCommand;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandInitializer;
import de.steamwar.schematicsystem.listener.PlayerEventListener;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@ -35,7 +36,7 @@ public class SchematicSystem extends JavaPlugin {
public void onEnable() {
instance = this;
new SchematicCommand();
SchematicCommandInitializer.init();
new DownloadCommand();
Bukkit.getPluginManager().registerEvents(new PlayerEventListener(), this);

Datei anzeigen

@ -1,7 +1,7 @@
/*
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
@ -15,12 +15,13 @@
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;
import de.steamwar.command.SWCommand;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils;
import de.steamwar.sql.*;
import org.bukkit.entity.Player;

Datei anzeigen

@ -1,944 +0,0 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.session.ClipboardHolder;
import de.steamwar.command.*;
import de.steamwar.core.Core;
import de.steamwar.core.VersionDependent;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SchematicSelector;
import de.steamwar.providers.BauServerInfo;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SafeSchematicNode;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.sql.*;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.time.Instant;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.stream.Collectors;
import static de.steamwar.schematicsystem.commands.SchematicCommandHelp.*;
import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*;
@SuppressWarnings("unused")
public class SchematicCommand extends SWCommand {
private static final Map<String, AbstractTypeMapper<CommandSender, ?>> searchMapper = new HashMap<>();
static {
searchMapper.put("-type", SWCommandUtils.createMapper(SchematicType.values().stream().map(SchematicType::name).toArray(String[]::new)));
searchMapper.put("-owner", SWCommandUtils.createMapper(Function.identity(), (commandSender, s) -> Collections.singletonList(s)));
Class<?> clazz = Material.class;
searchMapper.put("-item", SWCommandUtils.createEnumMapper((Class<Enum<?>>) clazz));
searchMapper.put("-public", null);
searchMapper.put("-exclude", SWCommandUtils.createMapper(Function.identity(), (commandSender, s) -> Collections.singletonList(s)));
searchMapper.put("-excludeType", SWCommandUtils.createMapper(SchematicType.values().stream().map(SchematicType::name).toArray(String[]::new)));
searchMapper.put("-excludeOwner", SWCommandUtils.createMapper(Function.identity(), (commandSender, s) -> Collections.singletonList(s)));
}
public SchematicCommand() {
super("schematic", Bukkit.getPluginManager().getPlugin("Teamserver") == null ? new String[] {"schem", "/schem", "/schematic"} : new String[]{"schem"});
setMessage(SchematicSystem.MESSAGE);
}
@Register("help")
public void pagedHelp(Player player, HelpPage page) {
printHelpPage(player, page);
}
@Register(help = true)
public void genericHelp(Player player, String... args) {
printHelpMainPage(player);
}
@Register("gui")
public void gui(Player player) {
GUI.list(player);
}
@Register("list")
@Register({"list", "/"})
public void schemList(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) {
createCachedSchemList(player, SchematicNode.list(getUser(player), null), Math.max(page - 1, 0), null, SchematicListBehavior.DEFAULT);
}
@Register({"list", "public"})
public void schemListPublic(Player player, @Validator("isDirValidator") @Mapper("publicDirMapper") SchematicNode node, @OptionalValue("1") int page) {
schemList(player, node, page);
}
@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), null), 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.list(user, node.getId()), Math.max(page - 1, 0), node, SchematicListBehavior.builder().setPublics(node.getOwner() == 0).setPageCommandGen(value -> "/schem list " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs() + " " + value).build());
}
@Register({"info", "public"})
public void schemInfoPublic(Player player, @Mapper("publicMapper") SchematicNode node) {
schemInfo(player, SchematicNode.getSchematicNode(node.getId()));
}
@Register({"l", "public"})
@Register({"load", "public"})
public void loadSchemPublic(Player player, @Validator("isSchemValidator") @Mapper("publicMapper") SchematicNode node) {
loadSchem(player, node);
}
@Register("info")
public void schemInfo(Player player, @ErrorMessage("COMMAND_INVALID_NODE") SchematicNode node) {
printSchemInfo(player, node);
}
@Register("l")
@Register("load")
public void loadSchem(Player player, @Validator("isSchemValidator") SchematicNode node) {
SchematicCommandUtils.loadSchem(player, node);
}
@Register("save")
@Register("s")
public void saveSchem(Player player) {
SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematicNode(), schematicNode -> {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(schematicNode == 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() + s), true));
anvilInv.setItem(Material.CAULDRON);
anvilInv.open();
} else {
saveSchem(player, schematicNode.generateBreadcrumbs(), true);
}
});
selector.setSingleDirOpen(false);
selector.open();
}
@Register("save")
@Register("s")
public void saveSchem(Player player, @Mapper("stringMapper") String name, @StaticValue(value = {"", "-f"}, allowISE=true) @OptionalValue("") boolean overwrite) {
SteamwarUser user = getUser(player);
if(BauServerInfo.isBauServer() && BauServerInfo.getOwnerId() != user.getId() &&
(Punishment.isPunished(user, Punishment.PunishmentType.NoSchemReceiving, punishment ->
SchematicSystem.MESSAGE.send("COMMAND_PUNISHMENT_NO_SAVE_EXTERNAL", player)) ||
Punishment.isPunished(SteamwarUser.get(BauServerInfo.getOwnerId()), Punishment.PunishmentType.NoSchemSharing, punishment ->
SchematicSystem.MESSAGE.send("COMMAND_PUNISHMENT_NO_SAVE", player)))) {
return;
}
if (name.endsWith("/")) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_NO_NAME", player);
return;
}
if (name.startsWith("/")) name = name.substring(1);
String[] layers = name.split("/");
if (invalidSchemName(player, layers)) return;
SchematicNode currentNode = mkdirs(layers, user, 1);
SchematicNode node = SchematicNode.getNodeFromPath(user, String.join("/", layers));
if (node != null) {
if(node.isDir()) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_FOLDER", player);
return;
} else if (!node.getSchemtype().writeable() || node.getOwner() != user.getId()) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_NO_OVERWRITE", player);
return;
} else if(!overwrite) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_OVERWRITE_CONFIRM", player, SchematicSystem.MESSAGE.parse("COMMAND_SAVE_OVERWRITE_CONFIRM_HOVER", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem s " + name + " -f"), node.generateBreadcrumbs());
return;
}
}
boolean newSchem = false;
if (node == null) {
newSchem = true;
node = SchematicNode.createSchematic(user.getId(), layers[layers.length - 1], currentNode == null ? 0 : currentNode.getId());
}
try {
new SchematicData(node).saveFromPlayer(player);
} catch (NoClipboardException e) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_CLIPBOARD_EMPTY", player);
if (newSchem)
node.delete();
return;
} catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "Could not save schematic", ex);
SchematicSystem.MESSAGE.send("COMMAND_SAVE_ERROR", player);
if (newSchem)
node.delete();
return;
}
SchematicSystem.MESSAGE.send(newSchem?"COMMAND_SAVE_DONE":"COMMAND_SAVE_OVERWRITE", player, node.generateBreadcrumbs());
}
@Register("addmember")
public void addMember(Player player, @Validator("isOwnerValidator") SchematicNode node, SteamwarUser... targets) {
SteamwarUser user = getUser(player);
if(Punishment.isPunished(user, Punishment.PunishmentType.NoSchemSharing, punishment -> SchematicSystem.MESSAGE.send("COMMAND_ADD_PUNISH", player, punishment.getReason()))) {
return;
}
List<SteamwarUser> added = new ArrayList<>();
for (SteamwarUser target: targets) {
if(Punishment.isPunished(target,
Punishment.PunishmentType.NoSchemReceiving,
punishment -> SchematicSystem.MESSAGE.send("COMMAND_ADD_USER_PUNISHED", player, target.getUserName()))) {
continue;
}
if (user.getId() == target.getId()) {
SchematicSystem.MESSAGE.send("COMMAND_ADD_OWN", player);
continue;
}
if (target.getId() == 0) {
SchematicSystem.MESSAGE.send("COMMAND_ADD_PUBLIC", player);
continue;
}
if (NodeMember.getNodeMember(node.getId(), target.getId()) != null) {
SchematicSystem.MESSAGE.send("COMMAND_ADD_ALREADY", player, target.getUserName());
continue;
}
NodeMember.createNodeMember(node.getId(), target.getId());
added.add(target);
Player t = Bukkit.getPlayer(target.getUUID());
if (t != null) {
SchematicSystem.MESSAGE.send("COMMAND_ADD_ADDED", t, node.generateBreadcrumbs(), player.getName());
}
}
Optional<String> reduced = added.stream().map(SteamwarUser::getUserName).reduce((s, s2) -> s + ", " + s2);
if (reduced.isPresent()) {
SchematicSystem.MESSAGE.send(added.size()>1?"COMMAND_ADD_MANY":"COMMAND_ADD_ONE", player, reduced.get());
} else {
SchematicSystem.MESSAGE.send("COMMAND_ADD_NONE", player);
}
}
@Register("delmember")
public void delMember(Player player, @Validator("isOwnerValidator") SchematicNode node, @Mapper("memberMapper") NodeMember member) {
SteamwarUser user = getUser(player);
SteamwarUser target = SteamwarUser.get(member.getMember());
List<SchematicNode> nodes = SchematicNode.deepGet(node.getId(), node1 -> node1.getOwner() != user.getId());
if (!nodes.isEmpty()) {
for (SchematicNode schematicNode : nodes) {
SchematicNode newNode = mkdirs(schematicNode.generateBreadcrumbs().split("/"), target, 1);
if(SchematicNode.getSchematicNode(schematicNode.getName(), newNode == null ? 0 : newNode.getId()) != null) {
schematicNode.setName(schematicNode.getName() + "-" + Instant.now().getEpochSecond() % 1000);
}
schematicNode.setParent(newNode == null ? null : newNode.getId());
}
}
member.delete();
SchematicSystem.MESSAGE.send("COMMAND_DELMEM_DONE", player, target.getUserName(), node.generateBreadcrumbs());
Player t = Bukkit.getPlayer(target.getUUID());
if (t != null) {
SchematicSystem.MESSAGE.send("COMMAND_DELMEM_DELETED", t, node.getName(), player.getName());
}
}
@Register("search")
public void schemSearch(Player player, @OptionalValue("1") int page, @Mapper("searchMapper") String... query) {
SteamwarUser user = getUser(player);
int userId = user.getId();
List<Predicate<SchematicNode>> predicates = new ArrayList<>();
List<String> nameList = new ArrayList<>();
int i = 0;
while (i < query.length) {
String current = query[i];
if (searchMapper.containsKey(current)) {
if (searchMapper.get(current) == null) {
if (current.equals("-public")) {
userId = 0;
}
} else if (i + 1 < query.length) {
int finalI = i;
switch (current) {
case "-type":
predicates.add(node -> !node.isDir() && node.getSchemtype().name().equalsIgnoreCase(query[finalI + 1]));
break;
case "-item":
predicates.add(node -> node.getItem().equalsIgnoreCase(query[finalI + 1]));
break;
case "-owner":
SteamwarUser steamwarUser = SteamwarUser.get(query[finalI + 1]);
if (steamwarUser == null) {
SchematicSystem.MESSAGE.send("COMMAND_SEARCH_NOT_A_PLAYER", player, query[finalI + 1]);
return;
}
predicates.add(node -> node.getOwner() == steamwarUser.getId());
break;
case "-exclude":
predicates.add(node -> !node.getName().contains(query[finalI + 1]));
break;
case "-excludeType":
predicates.add(node -> !node.isDir() && !node.getSchemtype().name().equalsIgnoreCase(query[finalI + 1]));
break;
case "-excludeOwner":
SteamwarUser steamwarUser1 = SteamwarUser.get(query[finalI + 1]);
if (steamwarUser1 == null) {
SchematicSystem.MESSAGE.send("COMMAND_SEARCH_NOT_A_PLAYER", player, query[finalI + 1]);
return;
}
predicates.add(node -> node.getOwner() != steamwarUser1.getId());
break;
}
i++;
}
} else {
predicates.add(node -> node.getName().contains(current));
nameList.add(current);
}
i++;
}
List<SchematicNode> nodes = SchematicNode.getAll(SteamwarUser.get(userId)).stream().filter(node -> {
for (Predicate<SchematicNode> 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");
}
return "§7" + s;
}).build());
}
@Register("download")
public void download(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node) {
SchematicCommandUtils.download(player, node);
}
@Register("lockreplay")
public void lockreplay(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node) {
node.setAllowReplay(false);
SchematicSystem.MESSAGE.send("COMMAND_LOCKREPLAY", player, node.getName());
}
@Register("replacecolor")
public void replacecolor(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node) {
boolean state = !node.replaceColor();
node.setReplaceColor(state);
SchematicSystem.MESSAGE.send(state?"COMMAND_REPLACE_COLOR_ON":"COMMAND_REPLACE_COLOR_OFF", player, node.getName());
}
@Register("dir")
@Register("ordner")
@Register("mkdir")
public void mkdir(Player player, @Mapper("dirStringMapper") String name) {
SteamwarUser user = getUser(player);
if (name.startsWith("/")) name = name.substring(1);
if (name.endsWith("/")) name = name.substring(0, name.length() - 1);
String[] layers = name.split("/");
if (invalidSchemName(player, layers)) return;
SchematicNode node = mkdirs(layers, user, 0);
SchematicSystem.MESSAGE.send("COMMAND_DIR_DONE", player, node.generateBreadcrumbs());
}
@Register("changetype")
public void changeType(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node) {
SteamwarUser user = getUser(player);
TextComponent base = new TextComponent();
Clipboard clipboard = null;
try {
clipboard = new SchematicData(node).load();
} catch (IOException ignored) { }
Clipboard finalClipboard = clipboard;
String breadcrumb = node.generateBreadcrumbs();
SchematicType.values().parallelStream()
.filter(SchematicType::isAssignable)
.filter(type -> finalClipboard == null || CheckSchemType.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemType.get(type)).fastOk())
.forEach(type -> {
TextComponent component = new TextComponent(type.name() + " ");
component.setColor(ChatColor.GRAY);
component.setBold(true);
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(SchematicSystem.MESSAGE.parse("COMMAND_CHANGE_TYPE_SELECT", player))));
component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem changetype " + breadcrumb + " " + type.name()));
base.addExtra(component);
});
player.spigot().sendMessage(base);
}
@Register("changetype")
public void changeType(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, SchematicType type) {
changeType(player, node, type, null);
}
@Register("changetype")
public void changeType(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, SchematicType type, Extend extend) {
SchematicCommandUtils.changeType(player, node, type, extend);
}
@Register("move")
public void moveToNull(Player player, @ErrorMessage("COMMAND_INVALID_NODE") SchematicNode node) {
move(player, node, "/");
}
@Register("move")
public void move(Player player, @ErrorMessage("COMMAND_INVALID_NODE") SchematicNode node, @Mapper("dirStringMapper") String name) {
SteamwarUser user = getUser(player);
if (name.equals("/")) {
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.parentsOfNode(user, newNode.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, 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;
}
}
SchematicSystem.MESSAGE.send("COMMAND_MOVE_DONE", player, SchematicNode.byIdAndUser(user, node.getId()).generateBreadcrumbs());
}
@Register("rename")
public void rename(Player player, @Validator("isOwnerValidator") SchematicNode node, String name) {
SteamwarUser user = getUser(player);
if (invalidSchemName(player, new String[]{name})) {
return;
}
SafeSchematicNode.Result result = SafeSchematicNode.setName(user, node, name);
if(!result.isSuccessful()) {
result.sendError(player);
return;
}
SchematicSystem.MESSAGE.send("COMMAND_RENAME_DONE", player, node.generateBreadcrumbs());
}
@Register("addteam")
public void addTeam(Player player, @Validator("isOwnerValidator") SchematicNode node) {
SteamwarUser user = getUser(player);
Team team = Team.get(user.getTeam());
if (team == null) {
SchematicSystem.MESSAGE.send("COMMAND_ADD_TEAM_NOT_IN_TEAM", player);
return;
}
addMember(player, node, team.getMembers().stream().map(SteamwarUser::get).filter(steamwarUser -> steamwarUser.getId() != user.getId()).toArray(SteamwarUser[]::new));
}
@Register("delteam")
public void remTeam(Player player, @Validator("isOwnerValidator") SchematicNode node) {
SteamwarUser user = getUser(player);
Team team = Team.get(user.getTeam());
if (team == null) {
SchematicSystem.MESSAGE.send("COMMAND_DEL_TEAM_NOT_IN_TEAM", player);
return;
}
List<String> removed = new ArrayList<>();
for (Integer member : team.getMembers()) {
if (user.getId() == member) continue;
NodeMember nodeMember = NodeMember.getNodeMember(node.getId(), member);
if (nodeMember != null) {
nodeMember.delete();
removed.add(SteamwarUser.get(member).getUserName());
}
}
Optional<String> reduced = removed.stream().reduce((s, s2) -> s + ", " + s2);
if (reduced.isPresent()) {
SchematicSystem.MESSAGE.send("COMMAND_DEL_TEAM_DONE", player, reduced.get());
} else {
SchematicSystem.MESSAGE.send("COMMAND_DEL_TEAM_NONE", player);
}
}
@Register("clearmember")
public void clearMember(Player player, @Validator("isOwnerValidator") SchematicNode node) {
node.getMembers().forEach(NodeMember::delete);
SchematicSystem.MESSAGE.send("COMMAND_CLEAR_MEMBER_DONE", player);
}
@Register("delallmember")
public void delAllMember(Player player, SteamwarUser target) {
SteamwarUser user = getUser(player);
int i = 0;
for (NodeMember nodeMember : NodeMember.getSchematics(target.getId())) {
SchematicNode node = SchematicNode.getSchematicNode(nodeMember.getNode());
if (node.getOwner() == user.getId()) {
nodeMember.delete();
i++;
}
}
SchematicSystem.MESSAGE.send("COMMAND_DEL_ALL_MEMBER", player, target.getUserName(), i);
}
@Register(value = "togglepublic", noTabComplete = true)
public void togglePublicMode(Player player) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (!user.getUserGroup().isAdminGroup()) {
genericHelp(player);
return;
}
if (togglePublic(player)) {
SchematicSystem.MESSAGE.send("COMMAND_PUBLIC_ON", player);
} else {
SchematicSystem.MESSAGE.send("COMMAND_PUBLIC_OFF", player);
}
}
@Register("delete")
public void deleteSchem(Player player, SchematicNode node) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (node.getOwner() != user.getId()) {
NodeMember member = NodeMember.getNodeMember(node.getId(), user.getId());
if (member == null) {
SchematicSystem.MESSAGE.send("COMMAND_DELETE_NOT_OWN", player);
return;
}
member.delete();
SchematicSystem.MESSAGE.send("COMMAND_DELETE_MEMBER", player);
return;
}
if (node.isDir()) {
if (SchematicNode.getSchematicNodeInNode(node).isEmpty()) {
SchematicSystem.MESSAGE.send("COMMAND_DELETE_DIR", player, node.generateBreadcrumbs());
node.delete();
} else {
SchematicSystem.MESSAGE.send("COMMAND_DELETE_DIR_FULL", player);
}
} else {
SchematicSystem.MESSAGE.send("COMMAND_DELETE_SCHEM", player, node.generateBreadcrumbs());
node.delete();
}
}
@Register("check")
public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, CheckSchemType type) {
try {
check(player, new SchematicData(node).load(), type, node.getName(), false);
} catch (IOException e) {
SchematicSystem.MESSAGE.send("UTIL_LOAD_ERROR", player);
}
}
@Register(value = {"check", "clipboard"})
public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) {
try {
check(player, WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getClipboard().getClipboard(), type, "clipboard", false);
} catch (EmptyClipboardException e) {
SchematicSystem.MESSAGE.send("COMMAND_CHECK_CLIPBOARD_EMPTY", player);
}
}
@Register(value = {"check", "selection"})
public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) {
try {
Clipboard clipboard = new BlockArrayClipboard(WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getSelection(new BukkitWorld(player.getWorld())));
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(player.getWorld()), -1);
impl.createCopy(editSession, clipboard);
check(player, clipboard, type, "selection", false);
} catch (IncompleteRegionException e) {
SchematicSystem.MESSAGE.send("COMMAND_CHECK_SELECTION_INCOMPLETE", player);
} catch (WorldEditException e) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_ERROR", player);
}
}
@Register("fix")
public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) {
if(Core.getVersion() < 15) {
SchematicSystem.MESSAGE.send("COMMAND_FIX_WRONG_VERSION", player);
return;
}
Clipboard clipboard;
try {
clipboard = WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getClipboard().getClipboard();
} catch (EmptyClipboardException e) {
SchematicSystem.MESSAGE.send("COMMAND_CHECK_CLIPBOARD_EMPTY", player);
return;
}
AutoCheckerResult result = AutoChecker.check(clipboard, type);
if(result.isOk()) {
SchematicSystem.MESSAGE.send("COMMAND_FIX_OK", player);
return;
}
try {
clipboard = impl.fixClipboard(clipboard, result, type);
WorldEdit.getInstance().getSessionManager().get(new BukkitPlayer(player)).setClipboard(new ClipboardHolder(clipboard));
AutoCheckerResult after = AutoChecker.check(clipboard, type);
if(after.isOk()) {
SchematicSystem.MESSAGE.send("COMMAND_FIX_DONE", player);
} else {
after.sendErrorMessage(player, SchematicSystem.MESSAGE.parse("COMMAND_FIX_MANUAL", player));
SchematicSystem.MESSAGE.send("COMMAND_FIX_COULD_NOT_FIX", player);
}
} catch (Exception e) {
SchematicSystem.MESSAGE.send("COMMAND_FIX_ERROR", player);
SchematicSystem.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e);
}
}
@Register(value = "page", noTabComplete = true)
public void pageCommand(Player player, int page) {
cachedSchemList(player, page);
}
private final TypeMapper<SchematicNode> publicCommandTypeMapper = publicNodeTypeMapper();
@Mapper("publicMapper")
public TypeMapper<SchematicNode> publicNodeTypeMapper() {
return new TypeMapper<SchematicNode>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return SchematicNode.getNodeTabcomplete(SteamwarUser.get(0), s);
}
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicNode.getNodeFromPath(SteamwarUser.get(0), s);
}
};
}
@Mapper("memberMapper")
public TypeMapper<NodeMember> nodeMemberTypeMapper() {
return new TypeMapper<NodeMember>() {
@Override
public NodeMember map(CommandSender commandSender, String[] previousArguments, String s) {
SchematicNode node = SchematicNode.getNodeFromPath(getUser((Player) commandSender), previousArguments[previousArguments.length - 1]);
SteamwarUser user = SteamwarUser.get(s);
return NodeMember.getNodeMember(node.getId(), user.getId());
}
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
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());
}
};
}
@Mapper("dirMapper")
public TypeMapper<SchematicNode> dirNodeTypeMapper() {
return new TypeMapper<SchematicNode>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
List<String> list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s);
list.removeIf(s1 -> !s1.endsWith("/"));
return list;
}
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
SchematicNode node = SchematicNode.getNodeFromPath(getUser((Player) commandSender), s);
if(node.isDir()) {
return node;
} else {
return null;
}
}
};
}
@Mapper("publicDirMapper")
public TypeMapper<SchematicNode> publicDirNodeTypeMapper() {
return new TypeMapper<SchematicNode>() {
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
Collection<String> list = publicCommandTypeMapper.tabCompletes(commandSender, strings, s);
list.removeIf(s1 -> !s1.endsWith("/"));
return list;
}
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
SchematicNode node = publicCommandTypeMapper.map(commandSender, previousArguments, s);
if(node.isDir()) {
return node;
} else {
return null;
}
}
};
}
@Mapper("dirStringMapper")
public TypeMapper<String> stringTabMapper() {
return new TypeMapper<String>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
List<String> list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s);
list.removeIf(s1 -> !s1.endsWith("/"));
return list;
}
@Override
public String map(CommandSender commandSender, String[] previousArguments, String s) {
return s;
}
};
}
@Mapper("stringMapper")
public TypeMapper<String> stringMapper() {
return new TypeMapper<String>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
List<String> list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s);
list.add(s);
return list;
}
@Override
public String map(CommandSender commandSender, String[] previousArguments, String s) {
return s;
}
};
}
@ClassMapper(SchematicType.class)
public TypeMapper<SchematicType> typeTypeMapper() {
return new TypeMapper<SchematicType>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return SchematicType.values().stream().filter(SchematicType::isAssignable).map(SchematicType::name).collect(Collectors.toList());
}
@Override
public SchematicType map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicType.values().stream().filter(type -> type.name().equals(s)).collect(Collectors.toList()).get(0);
}
};
}
@ClassMapper(value = SchematicNode.class, local = true)
public TypeMapper<SchematicNode> nodeTypeMapper() {
return new TypeMapper<SchematicNode>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s);
}
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s);
}
};
}
@ClassMapper(value = CheckSchemType.class, local = true)
public TypeMapper<CheckSchemType> checkSchemTypeTypeMapper() {
return new TypeMapper<CheckSchemType>() {
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return SchematicType.values().stream().filter(type -> CheckSchemType.get(type) != null).map(SchematicType::name).collect(Collectors.toList());
}
@Override
public CheckSchemType map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(CheckSchemType::get).findAny().orElse(null);
}
};
}
@Mapper(value = "searchMapper", local = true)
public TypeMapper<String> searchTypeMapper() {
return new TypeMapper<String>() {
@Override
public String map(CommandSender commandSender, String[] previousArguments, String s) {
return s;
}
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
if (strings.length == 0) {
List<String> list = new ArrayList<>();
list.add(s);
list.addAll(searchMapper.keySet());
return list;
}
String last = strings[strings.length - 1];
if (searchMapper.containsKey(last)) {
AbstractTypeMapper<CommandSender, ?> mapper = searchMapper.get(last);
if (mapper == null) {
List<String> list = new ArrayList<>(searchMapper.keySet());
list.add(s);
return list;
}
return mapper.tabCompletes(commandSender, strings, s);
}
List<String> list = new ArrayList<>(searchMapper.keySet());
list.add(s);
return list;
}
};
}
private boolean nodeNullCheck(AbstractValidator.MessageSender messageSender, SchematicNode node) {
if (node == null) {
messageSender.send("COMMAND_INVALID_NODE");
return false;
}
return true;
}
@Validator(value = "isSchemValidator", local = true)
public TypeValidator<SchematicNode> isSchemValidator() {
return (commandSender, schematicNode, messageSender) -> {
if(!nodeNullCheck(messageSender, schematicNode)) {
return false;
}
if(schematicNode.isDir()) {
messageSender.send("COMMAND_MUST_SCHEM");
return false;
}
return true;
};
}
@Validator(value = "isDirValidator", local = true)
public TypeValidator<SchematicNode> isDirValidator() {
return (commandSender, schematicNode, messageSender) -> {
if(!nodeNullCheck(messageSender, schematicNode)) {
return false;
}
if(!schematicNode.isDir()) {
messageSender.send("COMMAND_MUST_DIR");
return false;
}
return true;
};
}
@Validator(value = "isOwnerValidator", local = true)
public TypeValidator<SchematicNode> isOwnerValidator() {
return (commandSender, schematicNode, messageSender) -> {
if(!nodeNullCheck(messageSender, schematicNode)) {
return false;
}
if(schematicNode.getOwner() != SteamwarUser.get(((Player) commandSender).getUniqueId()).getId()) {
messageSender.send("COMMAND_NOT_OWN");
return false;
}
return true;
};
}
@Validator(value = "isOwnerSchematicValidator", local = true)
public TypeValidator<SchematicNode> isOwnerSchematicValidator() {
return (commandSender, schematicNode, messageSender) -> {
if(!nodeNullCheck(messageSender, schematicNode)) {
return false;
}
if(schematicNode.getOwner() != SteamwarUser.get(((Player) commandSender).getUniqueId()).getId()) {
messageSender.send("COMMAND_NOT_OWN");
return false;
}
if(schematicNode.isDir()) {
messageSender.send("COMMAND_MUST_SCHEM");
return false;
}
return true;
};
}
@Override
protected void sendMessage(CommandSender sender, String message, Object[] args) {
SchematicSystem.MESSAGE.send(message, sender, args);
}
enum Extend {
AUSFAHREN,
NORMAL
}
private static final ISchematicCommand impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance());
public static interface ISchematicCommand {
Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, CheckSchemType type) throws Exception;
void createCopy(EditSession editSession, Clipboard clipboard) throws WorldEditException;
}
}

Datei anzeigen

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands;
package de.steamwar.schematicsystem.commands.schematiccommand;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.Core;
@ -26,6 +26,7 @@ import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SafeSchematicNode;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils;
import de.steamwar.sql.*;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -37,7 +38,7 @@ import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.*;
public class GUI {
private GUI() {}

Datei anzeigen

@ -0,0 +1,151 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands.schematiccommand;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.command.*;
import de.steamwar.core.VersionDependent;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.sql.*;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandHelp.*;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.*;
@SuppressWarnings("unused")
public class SchematicCommand extends SWCommand {
public SchematicCommand() {
super("schematic", Bukkit.getPluginManager().getPlugin("Teamserver") == null ? new String[] {"schem", "/schem", "/schematic"} : new String[]{"schem"});
setMessage(SchematicSystem.MESSAGE);
}
@Register("help")
public void pagedHelp(Player player, HelpPage page) {
printHelpPage(player, page);
}
@Register
public void genericHelp(Player player, String... args) {
printHelpMainPage(player);
}
@Register(value = "togglepublic", noTabComplete = true)
public void togglePublicMode(Player player) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (!user.getUserGroup().isAdminGroup()) {
genericHelp(player);
return;
}
if (togglePublic(player)) {
SchematicSystem.MESSAGE.send("COMMAND_PUBLIC_ON", player);
} else {
SchematicSystem.MESSAGE.send("COMMAND_PUBLIC_OFF", player);
}
}
@Mapper("publicMapper")
public TypeMapper<SchematicNode> publicNodeTypeMapper() {
return SchematicMapper.publicNodeTypeMapper();
}
@Mapper("memberMapper")
public static TypeMapper<NodeMember> nodeMemberTypeMapper() {
return SchematicMapper.nodeMemberTypeMapper();
}
@Mapper("dirMapper")
public static TypeMapper<SchematicNode> dirNodeTypeMapper() {
return SchematicMapper.dirNodeTypeMapper();
}
@Mapper("publicDirMapper")
public static TypeMapper<SchematicNode> publicDirNodeTypeMapper() {
return SchematicMapper.publicDirNodeTypeMapper();
}
@Mapper("dirStringMapper")
public static TypeMapper<String> stringTabMapper() {
return SchematicMapper.stringTabMapper();
}
@Mapper("stringMapper")
public static TypeMapper<String> stringMapper() {
return SchematicMapper.stringMapper();
}
@ClassMapper(SchematicType.class)
public static TypeMapper<SchematicType> typeTypeMapper() {
return SchematicMapper.typeTypeMapper();
}
@AbstractSWCommand.ClassMapper(value = SchematicNode.class, local = true)
public static TypeMapper<SchematicNode> nodeTypeMapper() {
return SchematicMapper.nodeTypeMapper();
}
@ClassMapper(value = CheckSchemType.class, local = true)
public static TypeMapper<CheckSchemType> checkSchemTypeTypeMapper() {
return SchematicMapper.checkSchemTypeTypeMapper();
}
@Override
protected void sendMessage(CommandSender sender, String message, Object[] args) {
SchematicSystem.MESSAGE.send(message, sender, args);
}
@Validator(value = "isSchemValidator", local = true)
public static TypeValidator<SchematicNode> isSchemValidator() {
return SchematicValidator.isSchemValidator();
}
@Validator(value = "isDirValidator", local = true)
public static TypeValidator<SchematicNode> isDirValidator() {
return SchematicValidator.isDirValidator();
}
@Validator(value = "isOwnerValidator", local = true)
public static TypeValidator<SchematicNode> isOwnerValidator() {
return SchematicValidator.isOwnerValidator();
}
@Validator(value = "isOwnerSchematicValidator", local = true)
public static TypeValidator<SchematicNode> isOwnerSchematicValidator() {
return SchematicValidator.isOwnerSchematicValidator();
}
public enum Extend {
AUSFAHREN,
NORMAL
}
public static final ISchematicCommand impl = VersionDependent.getVersionImpl(SchematicSystem.getInstance());
public interface ISchematicCommand {
Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, CheckSchemType type) throws Exception;
void createCopy(EditSession editSession, Clipboard clipboard) throws WorldEditException;
}
}

Datei anzeigen

@ -1,7 +1,7 @@
/*
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
@ -15,9 +15,9 @@
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.schematiccommand;
import de.steamwar.schematicsystem.SchematicSystem;
import net.md_5.bungee.api.ChatColor;

Datei anzeigen

@ -0,0 +1,35 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands.schematiccommand;
import de.steamwar.schematicsystem.commands.schematiccommand.parts.*;
public class SchematicCommandInitializer {
public static void init() {
new SchematicCommand();
new CheckPart();
new MemberPart();
new ModifyPart();
new SavePart();
new SearchPart();
new ViewPart();
}
}

Datei anzeigen

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands;
package de.steamwar.schematicsystem.commands.schematiccommand;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.inventory.SWInventory;

Datei anzeigen

@ -0,0 +1,191 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands.schematiccommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.sql.NodeMember;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.getUser;
public class SchematicMapper {
private static final TypeMapper<SchematicNode> publicCommandTypeMapper = publicNodeTypeMapper();
public static TypeMapper<SchematicNode> publicNodeTypeMapper() {
return new TypeMapper<SchematicNode>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return SchematicNode.getNodeTabcomplete(SteamwarUser.get(0), s);
}
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicNode.getNodeFromPath(SteamwarUser.get(0), s);
}
};
}
public static TypeMapper<NodeMember> nodeMemberTypeMapper() {
return new TypeMapper<NodeMember>() {
@Override
public NodeMember map(CommandSender commandSender, String[] previousArguments, String s) {
SchematicNode node = SchematicNode.getNodeFromPath(getUser((Player) commandSender), previousArguments[previousArguments.length - 1]);
SteamwarUser user = SteamwarUser.get(s);
return NodeMember.getNodeMember(node.getId(), user.getId());
}
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
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());
}
};
}
public static TypeMapper<SchematicNode> dirNodeTypeMapper() {
return new TypeMapper<SchematicNode>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
List<String> list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s);
list.removeIf(s1 -> !s1.endsWith("/"));
return list;
}
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
SchematicNode node = SchematicNode.getNodeFromPath(getUser((Player) commandSender), s);
if(node.isDir()) {
return node;
} else {
return null;
}
}
};
}
public static TypeMapper<SchematicNode> publicDirNodeTypeMapper() {
return new TypeMapper<SchematicNode>() {
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
Collection<String> list = publicCommandTypeMapper.tabCompletes(commandSender, strings, s);
list.removeIf(s1 -> !s1.endsWith("/"));
return list;
}
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
SchematicNode node = publicCommandTypeMapper.map(commandSender, previousArguments, s);
if(node.isDir()) {
return node;
} else {
return null;
}
}
};
}
public static TypeMapper<String> stringTabMapper() {
return new TypeMapper<String>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
List<String> list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s);
list.removeIf(s1 -> !s1.endsWith("/"));
return list;
}
@Override
public String map(CommandSender commandSender, String[] previousArguments, String s) {
return s;
}
};
}
public static TypeMapper<String> stringMapper() {
return new TypeMapper<String>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
List<String> list = SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s);
list.add(s);
return list;
}
@Override
public String map(CommandSender commandSender, String[] previousArguments, String s) {
return s;
}
};
}
public static TypeMapper<SchematicType> typeTypeMapper() {
return new TypeMapper<SchematicType>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return SchematicType.values().stream().filter(SchematicType::isAssignable).map(SchematicType::name).collect(Collectors.toList());
}
@Override
public SchematicType map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicType.values().stream().filter(type -> type.name().equals(s)).collect(Collectors.toList()).get(0);
}
};
}
public static TypeMapper<SchematicNode> nodeTypeMapper() {
return new TypeMapper<SchematicNode>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return SchematicNode.getNodeTabcomplete(getUser((Player) commandSender), s);
}
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s);
}
};
}
public static TypeMapper<CheckSchemType> checkSchemTypeTypeMapper() {
return new TypeMapper<CheckSchemType>() {
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return SchematicType.values().stream().filter(type -> CheckSchemType.get(type) != null).map(SchematicType::name).collect(Collectors.toList());
}
@Override
public CheckSchemType map(CommandSender commandSender, String[] previousArguments, String s) {
return SchematicType.values().stream().filter(type -> type.name().equalsIgnoreCase(s)).map(CheckSchemType::get).findAny().orElse(null);
}
};
}
}

Datei anzeigen

@ -0,0 +1,94 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands.schematiccommand;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.command.AbstractValidator;
import de.steamwar.command.TypeValidator;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.entity.Player;
public class SchematicValidator {
private static boolean nodeNullCheck(AbstractValidator.MessageSender messageSender, SchematicNode node) {
if (node == null) {
messageSender.send("COMMAND_INVALID_NODE");
return false;
}
return true;
}
public static TypeValidator<SchematicNode> isSchemValidator() {
return (commandSender, schematicNode, messageSender) -> {
if(!nodeNullCheck(messageSender, schematicNode)) {
return false;
}
if(schematicNode.isDir()) {
messageSender.send("COMMAND_MUST_SCHEM");
return false;
}
return true;
};
}
public static TypeValidator<SchematicNode> isDirValidator() {
return (commandSender, schematicNode, messageSender) -> {
if(!nodeNullCheck(messageSender, schematicNode)) {
return false;
}
if(!schematicNode.isDir()) {
messageSender.send("COMMAND_MUST_DIR");
return false;
}
return true;
};
}
public static TypeValidator<SchematicNode> isOwnerValidator() {
return (commandSender, schematicNode, messageSender) -> {
if(!nodeNullCheck(messageSender, schematicNode)) {
return false;
}
if(schematicNode.getOwner() != SteamwarUser.get(((Player) commandSender).getUniqueId()).getId()) {
messageSender.send("COMMAND_NOT_OWN");
return false;
}
return true;
};
}
public static TypeValidator<SchematicNode> isOwnerSchematicValidator() {
return (commandSender, schematicNode, messageSender) -> {
if(!nodeNullCheck(messageSender, schematicNode)) {
return false;
}
if(schematicNode.getOwner() != SteamwarUser.get(((Player) commandSender).getUniqueId()).getId()) {
messageSender.send("COMMAND_NOT_OWN");
return false;
}
if(schematicNode.isDir()) {
messageSender.send("COMMAND_MUST_SCHEM");
return false;
}
return true;
};
}
}

Datei anzeigen

@ -0,0 +1,119 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands.schematiccommand.parts;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.session.ClipboardHolder;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.command.SWCommand;
import de.steamwar.core.Core;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.logging.Level;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.check;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand.impl;
@AbstractSWCommand.PartOf(SchematicCommand.class)
public class CheckPart extends SWCommand {
public CheckPart() {
super(null);
}
@Register("check")
public void checkCommand(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, CheckSchemType type) {
try {
check(player, new SchematicData(node).load(), type, node.getName(), false);
} catch (IOException e) {
SchematicSystem.MESSAGE.send("UTIL_LOAD_ERROR", player);
}
}
@Register(value = {"check", "clipboard"})
public void checkClipboardCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) {
try {
check(player, WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getClipboard().getClipboard(), type, "clipboard", false);
} catch (EmptyClipboardException e) {
SchematicSystem.MESSAGE.send("COMMAND_CHECK_CLIPBOARD_EMPTY", player);
}
}
@Register(value = {"check", "selection"})
public void checkSelectionCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) {
try {
Clipboard clipboard = new BlockArrayClipboard(WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getSelection(new BukkitWorld(player.getWorld())));
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(player.getWorld()), -1);
impl.createCopy(editSession, clipboard);
check(player, clipboard, type, "selection", false);
} catch (IncompleteRegionException e) {
SchematicSystem.MESSAGE.send("COMMAND_CHECK_SELECTION_INCOMPLETE", player);
} catch (WorldEditException e) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_ERROR", player);
}
}
@Register("fix")
public void fixSchematicCommand(Player player, @ErrorMessage("UTIL_CHECK_TYPE_NOT_FOUND") CheckSchemType type) {
if(Core.getVersion() < 15) {
SchematicSystem.MESSAGE.send("COMMAND_FIX_WRONG_VERSION", player);
return;
}
Clipboard clipboard;
try {
clipboard = WorldEdit.getInstance().getSessionManager().findByName(player.getName()).getClipboard().getClipboard();
} catch (EmptyClipboardException e) {
SchematicSystem.MESSAGE.send("COMMAND_CHECK_CLIPBOARD_EMPTY", player);
return;
}
AutoCheckerResult result = AutoChecker.check(clipboard, type);
if(result.isOk()) {
SchematicSystem.MESSAGE.send("COMMAND_FIX_OK", player);
return;
}
try {
clipboard = impl.fixClipboard(clipboard, result, type);
WorldEdit.getInstance().getSessionManager().get(new BukkitPlayer(player)).setClipboard(new ClipboardHolder(clipboard));
AutoCheckerResult after = AutoChecker.check(clipboard, type);
if(after.isOk()) {
SchematicSystem.MESSAGE.send("COMMAND_FIX_DONE", player);
} else {
after.sendErrorMessage(player, SchematicSystem.MESSAGE.parse("COMMAND_FIX_MANUAL", player));
SchematicSystem.MESSAGE.send("COMMAND_FIX_COULD_NOT_FIX", player);
}
} catch (Exception e) {
SchematicSystem.MESSAGE.send("COMMAND_FIX_ERROR", player);
SchematicSystem.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e);
}
}
}

Datei anzeigen

@ -0,0 +1,173 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands.schematiccommand.parts;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.command.SWCommand;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.sql.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.getUser;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.mkdirs;
@AbstractSWCommand.PartOf(SchematicCommand.class)
public class MemberPart extends SWCommand {
public MemberPart() {
super(null);
}
@Register("addmember")
public void addMember(Player player, @Validator("isOwnerValidator") SchematicNode node, SteamwarUser... targets) {
SteamwarUser user = getUser(player);
if(Punishment.isPunished(user, Punishment.PunishmentType.NoSchemSharing, punishment -> SchematicSystem.MESSAGE.send("COMMAND_ADD_PUNISH", player, punishment.getReason()))) {
return;
}
List<SteamwarUser> added = new ArrayList<>();
for (SteamwarUser target: targets) {
if(Punishment.isPunished(target,
Punishment.PunishmentType.NoSchemReceiving,
punishment -> SchematicSystem.MESSAGE.send("COMMAND_ADD_USER_PUNISHED", player, target.getUserName()))) {
continue;
}
if (user.getId() == target.getId()) {
SchematicSystem.MESSAGE.send("COMMAND_ADD_OWN", player);
continue;
}
if (target.getId() == 0) {
SchematicSystem.MESSAGE.send("COMMAND_ADD_PUBLIC", player);
continue;
}
if (NodeMember.getNodeMember(node.getId(), target.getId()) != null) {
SchematicSystem.MESSAGE.send("COMMAND_ADD_ALREADY", player, target.getUserName());
continue;
}
NodeMember.createNodeMember(node.getId(), target.getId());
added.add(target);
Player t = Bukkit.getPlayer(target.getUUID());
if (t != null) {
SchematicSystem.MESSAGE.send("COMMAND_ADD_ADDED", t, node.generateBreadcrumbs(), player.getName());
}
}
Optional<String> reduced = added.stream().map(SteamwarUser::getUserName).reduce((s, s2) -> s + ", " + s2);
if (reduced.isPresent()) {
SchematicSystem.MESSAGE.send(added.size()>1?"COMMAND_ADD_MANY":"COMMAND_ADD_ONE", player, reduced.get());
} else {
SchematicSystem.MESSAGE.send("COMMAND_ADD_NONE", player);
}
}
@Register("delmember")
public void delMember(Player player, @Validator("isOwnerValidator") SchematicNode node, @Mapper("memberMapper") NodeMember member) {
SteamwarUser user = getUser(player);
SteamwarUser target = SteamwarUser.get(member.getMember());
List<SchematicNode> nodes = SchematicNode.deepGet(node.getId(), node1 -> node1.getOwner() != user.getId());
if (!nodes.isEmpty()) {
for (SchematicNode schematicNode : nodes) {
SchematicNode newNode = mkdirs(schematicNode.generateBreadcrumbs().split("/"), target, 1);
if(SchematicNode.getSchematicNode(schematicNode.getName(), newNode == null ? 0 : newNode.getId()) != null) {
schematicNode.setName(schematicNode.getName() + "-" + Instant.now().getEpochSecond() % 1000);
}
schematicNode.setParent(newNode == null ? null : newNode.getId());
}
}
member.delete();
SchematicSystem.MESSAGE.send("COMMAND_DELMEM_DONE", player, target.getUserName(), node.generateBreadcrumbs());
Player t = Bukkit.getPlayer(target.getUUID());
if (t != null) {
SchematicSystem.MESSAGE.send("COMMAND_DELMEM_DELETED", t, node.getName(), player.getName());
}
}
@Register("addteam")
public void addTeam(Player player, @Validator("isOwnerValidator") SchematicNode node) {
SteamwarUser user = getUser(player);
Team team = Team.get(user.getTeam());
if (team == null) {
SchematicSystem.MESSAGE.send("COMMAND_ADD_TEAM_NOT_IN_TEAM", player);
return;
}
addMember(player, node, team.getMembers().stream().map(SteamwarUser::get).filter(steamwarUser -> steamwarUser.getId() != user.getId()).toArray(SteamwarUser[]::new));
}
@Register("delteam")
public void remTeam(Player player, @Validator("isOwnerValidator") SchematicNode node) {
SteamwarUser user = getUser(player);
Team team = Team.get(user.getTeam());
if (team == null) {
SchematicSystem.MESSAGE.send("COMMAND_DEL_TEAM_NOT_IN_TEAM", player);
return;
}
List<String> removed = new ArrayList<>();
for (Integer member : team.getMembers()) {
if (user.getId() == member) continue;
NodeMember nodeMember = NodeMember.getNodeMember(node.getId(), member);
if (nodeMember != null) {
nodeMember.delete();
removed.add(SteamwarUser.get(member).getUserName());
}
}
Optional<String> reduced = removed.stream().reduce((s, s2) -> s + ", " + s2);
if (reduced.isPresent()) {
SchematicSystem.MESSAGE.send("COMMAND_DEL_TEAM_DONE", player, reduced.get());
} else {
SchematicSystem.MESSAGE.send("COMMAND_DEL_TEAM_NONE", player);
}
}
@Register("clearmember")
public void clearMember(Player player, @Validator("isOwnerValidator") SchematicNode node) {
node.getMembers().forEach(NodeMember::delete);
SchematicSystem.MESSAGE.send("COMMAND_CLEAR_MEMBER_DONE", player);
}
@Register("delallmember")
public void delAllMember(Player player, SteamwarUser target) {
SteamwarUser user = getUser(player);
int i = 0;
for (NodeMember nodeMember : NodeMember.getSchematics(target.getId())) {
SchematicNode node = SchematicNode.getSchematicNode(nodeMember.getNode());
if (node.getOwner() == user.getId()) {
nodeMember.delete();
i++;
}
}
SchematicSystem.MESSAGE.send("COMMAND_DEL_ALL_MEMBER", player, target.getUserName(), i);
}
}

Datei anzeigen

@ -0,0 +1,187 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands.schematiccommand.parts;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.command.SWCommand;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SafeSchematicNode;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.autocheck.AutoChecker;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.sql.*;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;
import java.io.IOException;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.*;
@AbstractSWCommand.PartOf(SchematicCommand.class)
public class ModifyPart extends SWCommand {
public ModifyPart() {
super(null);
}
@Register("changetype")
public void changeType(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node) {
SteamwarUser user = getUser(player);
TextComponent base = new TextComponent();
Clipboard clipboard = null;
try {
clipboard = new SchematicData(node).load();
} catch (IOException ignored) { }
Clipboard finalClipboard = clipboard;
String breadcrumb = node.generateBreadcrumbs();
SchematicType.values().parallelStream()
.filter(SchematicType::isAssignable)
.filter(type -> finalClipboard == null || CheckSchemType.get(type) == null || AutoChecker.sizeCheck(finalClipboard, CheckSchemType.get(type)).fastOk())
.forEach(type -> {
TextComponent component = new TextComponent(type.name() + " ");
component.setColor(ChatColor.GRAY);
component.setBold(true);
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(SchematicSystem.MESSAGE.parse("COMMAND_CHANGE_TYPE_SELECT", player))));
component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem changetype " + breadcrumb + " " + type.name()));
base.addExtra(component);
});
player.spigot().sendMessage(base);
}
@Register("changetype")
public void changeType(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, SchematicType type) {
changeType(player, node, type, null);
}
@Register("changetype")
public void changeType(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node, SchematicType type, SchematicCommand.Extend extend) {
SchematicCommandUtils.changeType(player, node, type, extend);
}
@Register("move")
public void moveToNull(Player player, @ErrorMessage("COMMAND_INVALID_NODE") SchematicNode node) {
move(player, node, "/");
}
@Register("move")
public void move(Player player, @ErrorMessage("COMMAND_INVALID_NODE") SchematicNode node, @Mapper("dirStringMapper") String name) {
SteamwarUser user = getUser(player);
if (name.equals("/")) {
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.parentsOfNode(user, newNode.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, 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;
}
}
SchematicSystem.MESSAGE.send("COMMAND_MOVE_DONE", player, SchematicNode.byIdAndUser(user, node.getId()).generateBreadcrumbs());
}
@Register("rename")
public void rename(Player player, @Validator("isOwnerValidator") SchematicNode node, String name) {
SteamwarUser user = getUser(player);
if (invalidSchemName(player, new String[]{name})) {
return;
}
SafeSchematicNode.Result result = SafeSchematicNode.setName(user, node, name);
if (!result.isSuccessful()) {
result.sendError(player);
return;
}
SchematicSystem.MESSAGE.send("COMMAND_RENAME_DONE", player, node.generateBreadcrumbs());
}
@Register("delete")
public void deleteSchem(Player player, SchematicNode node) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (node.getOwner() != user.getId()) {
NodeMember member = NodeMember.getNodeMember(node.getId(), user.getId());
if (member == null) {
SchematicSystem.MESSAGE.send("COMMAND_DELETE_NOT_OWN", player);
return;
}
member.delete();
SchematicSystem.MESSAGE.send("COMMAND_DELETE_MEMBER", player);
return;
}
if (node.isDir()) {
if (SchematicNode.getSchematicNodeInNode(node).isEmpty()) {
SchematicSystem.MESSAGE.send("COMMAND_DELETE_DIR", player, node.generateBreadcrumbs());
node.delete();
} else {
SchematicSystem.MESSAGE.send("COMMAND_DELETE_DIR_FULL", player);
}
} else {
SchematicSystem.MESSAGE.send("COMMAND_DELETE_SCHEM", player, node.generateBreadcrumbs());
node.delete();
}
}
@Register("lockreplay")
public void lockreplay(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node) {
node.setAllowReplay(false);
SchematicSystem.MESSAGE.send("COMMAND_LOCKREPLAY", player, node.getName());
}
@Register("replacecolor")
public void replacecolor(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node) {
boolean state = !node.replaceColor();
node.setReplaceColor(state);
SchematicSystem.MESSAGE.send(state?"COMMAND_REPLACE_COLOR_ON":"COMMAND_REPLACE_COLOR_OFF", player, node.getName());
}
}

Datei anzeigen

@ -0,0 +1,133 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands.schematiccommand.parts;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.command.SWCommand;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SchematicSelector;
import de.steamwar.providers.BauServerInfo;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.sql.*;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.logging.Level;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.*;
@AbstractSWCommand.PartOf(SchematicCommand.class)
public class SavePart extends SWCommand {
public SavePart() {
super(null);
}
@Register("save")
@Register("s")
public void saveSchem(Player player) {
SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematicNode(), schematicNode -> {
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() + s), true));
anvilInv.setItem(Material.CAULDRON);
anvilInv.open();
} else {
saveSchem(player, schematicNode.generateBreadcrumbs(), true);
}
});
selector.setSingleDirOpen(false);
selector.open();
}
@Register("save")
@Register("s")
public void saveSchem(Player player, @AbstractSWCommand.Mapper("stringMapper") String name, @AbstractSWCommand.StaticValue(value = {"", "-f"}, allowISE=true) @AbstractSWCommand.OptionalValue("") boolean overwrite) {
SteamwarUser user = getUser(player);
if(BauServerInfo.isBauServer() && BauServerInfo.getOwnerId() != user.getId() &&
(Punishment.isPunished(user, Punishment.PunishmentType.NoSchemReceiving, punishment ->
SchematicSystem.MESSAGE.send("COMMAND_PUNISHMENT_NO_SAVE_EXTERNAL", player)) ||
Punishment.isPunished(SteamwarUser.get(BauServerInfo.getOwnerId()), Punishment.PunishmentType.NoSchemSharing, punishment ->
SchematicSystem.MESSAGE.send("COMMAND_PUNISHMENT_NO_SAVE", player)))) {
return;
}
if (name.endsWith("/")) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_NO_NAME", player);
return;
}
if (name.startsWith("/")) name = name.substring(1);
String[] layers = name.split("/");
if (invalidSchemName(player, layers)) return;
SchematicNode currentNode = mkdirs(layers, user, 1);
SchematicNode node = SchematicNode.getNodeFromPath(user, String.join("/", layers));
if (node != null) {
if(node.isDir()) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_FOLDER", player);
return;
} else if (!node.getSchemtype().writeable() || node.getOwner() != user.getId()) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_NO_OVERWRITE", player);
return;
} else if(!overwrite) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_OVERWRITE_CONFIRM", player, SchematicSystem.MESSAGE.parse("COMMAND_SAVE_OVERWRITE_CONFIRM_HOVER", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem s " + name + " -f"), node.generateBreadcrumbs());
return;
}
}
boolean newSchem = false;
if (node == null) {
newSchem = true;
node = SchematicNode.createSchematic(user.getId(), layers[layers.length - 1], currentNode == null ? 0 : currentNode.getId());
}
try {
new SchematicData(node).saveFromPlayer(player);
} catch (NoClipboardException e) {
SchematicSystem.MESSAGE.send("COMMAND_SAVE_CLIPBOARD_EMPTY", player);
if (newSchem)
node.delete();
return;
} catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "Could not save schematic", ex);
SchematicSystem.MESSAGE.send("COMMAND_SAVE_ERROR", player);
if (newSchem)
node.delete();
return;
}
SchematicSystem.MESSAGE.send(newSchem?"COMMAND_SAVE_DONE":"COMMAND_SAVE_OVERWRITE", player, node.generateBreadcrumbs());
}
@Register("dir")
@Register("ordner")
@Register("mkdir")
public void mkdir(Player player, @Mapper("dirStringMapper") String name) {
SteamwarUser user = getUser(player);
if (name.startsWith("/")) name = name.substring(1);
if (name.endsWith("/")) name = name.substring(0, name.length() - 1);
String[] layers = name.split("/");
if (invalidSchemName(player, layers)) return;
SchematicNode node = mkdirs(layers, user, 0);
SchematicSystem.MESSAGE.send("COMMAND_DIR_DONE", player, node.generateBreadcrumbs());
}
}

Datei anzeigen

@ -0,0 +1,165 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands.schematiccommand.parts;
import de.steamwar.command.*;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.createCachedSchemList;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.getUser;
@AbstractSWCommand.PartOf(SchematicCommand.class)
public class SearchPart extends SWCommand {
private static final Map<String, AbstractTypeMapper<CommandSender, ?>> searchMapper = new HashMap<>();
static {
searchMapper.put("-type", SWCommandUtils.createMapper(SchematicType.values().stream().map(SchematicType::name).toArray(String[]::new)));
searchMapper.put("-owner", SWCommandUtils.createMapper(Function.identity(), (commandSender, s) -> Collections.singletonList(s)));
Class<?> clazz = Material.class;
searchMapper.put("-item", SWCommandUtils.createEnumMapper((Class<Enum<?>>) clazz));
searchMapper.put("-public", null);
searchMapper.put("-exclude", SWCommandUtils.createMapper(Function.identity(), (commandSender, s) -> Collections.singletonList(s)));
searchMapper.put("-excludeType", SWCommandUtils.createMapper(SchematicType.values().stream().map(SchematicType::name).toArray(String[]::new)));
searchMapper.put("-excludeOwner", SWCommandUtils.createMapper(Function.identity(), (commandSender, s) -> Collections.singletonList(s)));
}
public SearchPart() {
super(null);
}
@Register("search")
public void schemSearch(Player player, @OptionalValue("1") int page, @Mapper("searchMapper") String... query) {
SteamwarUser user = getUser(player);
int userId = user.getId();
List<Predicate<SchematicNode>> predicates = new ArrayList<>();
List<String> nameList = new ArrayList<>();
int i = 0;
while (i < query.length) {
String current = query[i];
if (searchMapper.containsKey(current)) {
if (searchMapper.get(current) == null) {
if (current.equals("-public")) {
userId = 0;
}
} else if (i + 1 < query.length) {
int finalI = i;
switch (current) {
case "-type":
predicates.add(node -> !node.isDir() && node.getSchemtype().name().equalsIgnoreCase(query[finalI + 1]));
break;
case "-item":
predicates.add(node -> node.getItem().equalsIgnoreCase(query[finalI + 1]));
break;
case "-owner":
SteamwarUser steamwarUser = SteamwarUser.get(query[finalI + 1]);
if (steamwarUser == null) {
SchematicSystem.MESSAGE.send("COMMAND_SEARCH_NOT_A_PLAYER", player, query[finalI + 1]);
return;
}
predicates.add(node -> node.getOwner() == steamwarUser.getId());
break;
case "-exclude":
predicates.add(node -> !node.getName().contains(query[finalI + 1]));
break;
case "-excludeType":
predicates.add(node -> !node.isDir() && !node.getSchemtype().name().equalsIgnoreCase(query[finalI + 1]));
break;
case "-excludeOwner":
SteamwarUser steamwarUser1 = SteamwarUser.get(query[finalI + 1]);
if (steamwarUser1 == null) {
SchematicSystem.MESSAGE.send("COMMAND_SEARCH_NOT_A_PLAYER", player, query[finalI + 1]);
return;
}
predicates.add(node -> node.getOwner() != steamwarUser1.getId());
break;
}
i++;
}
} else {
predicates.add(node -> node.getName().contains(current));
nameList.add(current);
}
i++;
}
List<SchematicNode> nodes = SchematicNode.getAll(SteamwarUser.get(userId)).stream().filter(node -> {
for (Predicate<SchematicNode> predicate : predicates) {
if (!predicate.test(node)) {
return false;
}
}
return true;
}).collect(Collectors.toList());
createCachedSchemList(player, nodes, Math.max(page - 1, 0), null, SchematicCommandUtils.SchematicListBehavior.builder().setPublics(userId == 0).setShowPath(false).setRenderHook(s -> {
for (String ss : nameList) {
s = s.replace(ss, "§e§l" + ss + "§7");
}
return "§7" + s;
}).build());
}
@Mapper(value = "searchMapper", local = true)
public TypeMapper<String> searchTypeMapper() {
return new TypeMapper<String>() {
@Override
public String map(CommandSender commandSender, String[] previousArguments, String s) {
return s;
}
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
if (strings.length == 0) {
List<String> list = new ArrayList<>();
list.add(s);
list.addAll(searchMapper.keySet());
return list;
}
String last = strings[strings.length - 1];
if (searchMapper.containsKey(last)) {
AbstractTypeMapper<CommandSender, ?> mapper = searchMapper.get(last);
if (mapper == null) {
List<String> list = new ArrayList<>(searchMapper.keySet());
list.add(s);
return list;
}
return mapper.tabCompletes(commandSender, strings, s);
}
List<String> list = new ArrayList<>(searchMapper.keySet());
list.add(s);
return list;
}
};
}
}

Datei anzeigen

@ -0,0 +1,98 @@
/*
This file is a part of the SteamWar software.
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 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands.schematiccommand.parts;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.command.SWCommand;
import de.steamwar.schematicsystem.commands.schematiccommand.GUI;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommand;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.entity.Player;
import static de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils.*;
@AbstractSWCommand.PartOf(SchematicCommand.class)
public class ViewPart extends SWCommand {
public ViewPart() {
super(null);
}
@Register("list")
@Register({"list", "/"})
public void schemList(Player player, @OptionalValue(value = "1", onlyUINIG = true) int page) {
createCachedSchemList(player, SchematicNode.list(getUser(player), null), Math.max(page - 1, 0), null, SchematicCommandUtils.SchematicListBehavior.DEFAULT);
}
@Register({"list", "public"})
public void schemListPublic(Player player, @Validator("isDirValidator") @Mapper("publicDirMapper") SchematicNode node, @OptionalValue("1") int page) {
schemList(player, node, page);
}
@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), null), Math.max(page - 1, 0), null, SchematicCommandUtils.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.list(user, node.getId()), Math.max(page - 1, 0), node, SchematicCommandUtils.SchematicListBehavior.builder().setPublics(node.getOwner() == 0).setPageCommandGen(value -> "/schem list " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs() + " " + value).build());
}
@Register({"info", "public"})
public void schemInfoPublic(Player player, @Mapper("publicMapper") SchematicNode node) {
schemInfo(player, SchematicNode.getSchematicNode(node.getId()));
}
@Register("info")
public void schemInfo(Player player, @ErrorMessage("COMMAND_INVALID_NODE") SchematicNode node) {
printSchemInfo(player, node);
}
@Register(value = "page", noTabComplete = true)
public void pageCommand(Player player, int page) {
cachedSchemList(player, page);
}
@Register({"l", "public"})
@Register({"load", "public"})
public void loadSchemPublic(Player player, @Validator("isSchemValidator") @Mapper("publicMapper") SchematicNode node) {
loadSchem(player, node);
}
@Register("l")
@Register("load")
public void loadSchem(Player player, @Validator("isSchemValidator") SchematicNode node) {
SchematicCommandUtils.loadSchem(player, node);
}
@Register("gui")
public void gui(Player player) {
GUI.list(player);
}
@Register("download")
public void download(Player player, @Validator("isOwnerSchematicValidator") SchematicNode node) {
SchematicCommandUtils.download(player, node);
}
}

Datei anzeigen

@ -0,0 +1,28 @@
CheckPart:
- fix
- check
MemberPart:
- addmember
- delmember
- addteam
- delteam
- clearmember
- delallmember
ModifyPart:
- changetype
- move
- rename
- delete
- lockreplay
- replacecolor
SavePart:
- save
- ordner
SearchPart:
- search
ViewPart:
- list
- info
- load
- gui
- download

Datei anzeigen

@ -1,7 +1,7 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2022 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
@ -19,7 +19,7 @@
package de.steamwar.schematicsystem.listener;
import de.steamwar.schematicsystem.commands.SchematicCommandUtils;
import de.steamwar.schematicsystem.commands.schematiccommand.SchematicCommandUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;