diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 4bd5af01..805dfaf5 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -1011,6 +1011,12 @@ LOCK_SCHEM_HELP=§8/§eschemlock §8[§7Owner§8] [§7Schematic§8] [§7Grund§8 AFK_KICK_MESSAGE=§cAuf diesem Server ist seit 5 Minuten nichts passiert. AFK_WARNING_MESSAGE=§cDieser Server wird bei weiterer Inaktivität in einer Minute gestoppt +SKIN_HELP = §8/§eskin §8[§7Kuerzel§8] §8[§7Creator§8|§epublic§8] §8[§7Name...§8] §8- §7Erstellt die Skin Schematics. 'public' als Creator nutzen für keinen Creator, danach die nachricht an YoyoNow kopieren (mit Click kopieren) +SKIN_NO_REGION=§7Du steht in keiner Region, welche mit einem Skin versehen werden kann +SKIN_ALREADY_EXISTS=§cDieser Skin existiert in der Form bereits +SKIN_MESSAGE=§7Skin erstellt +SKIN_MESSAGE_HOVER=§eKlicken zum kopieren für YoyoNow und an diesen senden + # Panzern PANZERN_HELP = §8/§epanzern §8[§7Block§8] §8[§7Slab§8] §8- §7Panzer deine WorldEdit Auswahl PANZERN_PREPARE1 = §71. Gucke nochmal nach, ob Läufe auch bis zur Panzergrenze führen. diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java new file mode 100644 index 00000000..99723f7b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java @@ -0,0 +1,184 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.team; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.UserGroup; +import net.md_5.bungee.api.chat.ClickEvent; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import yapion.hierarchy.output.StringOutput; +import yapion.hierarchy.types.YAPIONObject; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Linked(LinkageType.COMMAND) +public class SkinCommand extends SWCommand { + + public SkinCommand() { + super("skin"); + } + + @Register(help = true) + public void genericHelp(Player p, String... args) { + SteamwarUser steamwarUser = SteamwarUser.get(p.getUniqueId()); + UserGroup userGroup = steamwarUser.getUserGroup(); + + if (!userGroup.isAdminGroup() && steamwarUser.getId() != 571) { + return; + } + + BauSystem.MESSAGE.send("SKIN_HELP", p); + } + + @Register + public void createCommand(Player p, @OptionalValue("") @Mapper("force") String force, @Mapper("kuerzel") String typeKuerzel, @Mapper("creator") String creator, String... names) { + SteamwarUser steamwarUser = SteamwarUser.get(p.getUniqueId()); + UserGroup userGroup = steamwarUser.getUserGroup(); + + if (!userGroup.isAdminGroup() && steamwarUser.getId() != 571) { + return; + } + Region region = Region.getRegion(p.getLocation()); + if (region.isGlobal()) { + BauSystem.MESSAGE.send("SKIN_NO_REGION", p); + return; + } + + String name = String.join(" ", names); + File arenaFile = new File("sections4/custom/" + name + "/" + typeKuerzel + "Arena.schem"); + File testblockFile = region.hasType(RegionType.TESTBLOCK) ? new File("sections4/custom/" + name + "/" + typeKuerzel + "Testblock.schem") : null; + + arenaFile.getParentFile().mkdirs(); + if (testblockFile != null) { + testblockFile.getParentFile().mkdirs(); + } + if (arenaFile.exists() && force.equals("")) { + BauSystem.MESSAGE.send("SKIN_ALREADY_EXISTS", p); + return; + } + if (testblockFile != null && testblockFile.exists() && force.equals("")) { + BauSystem.MESSAGE.send("SKIN_ALREADY_EXISTS", p); + return; + } + + Region.copy(region.getMinPoint(), region.getMaxPoint(), arenaFile); + if (testblockFile != null) { + Region.copy(region.getMinPointTestblock(), region.getMaxPointTestblock(), testblockFile); + } + + YAPIONObject yapionObject = new YAPIONObject(); + yapionObject.add("name", name); + if (!creator.equals("public")) { + yapionObject.add("creator", creator); + } + yapionObject.add("type", typeKuerzel); + yapionObject.add("schematic", arenaFile.getPath()); + if (testblockFile != null) { + yapionObject.add("testblockSchematic", testblockFile.getPath()); + } + BauSystem.MESSAGE.send("SKIN_MESSAGE", p, BauSystem.MESSAGE.parse("SKIN_MESSAGE_HOVER", p), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, yapionObject.toYAPION(new StringOutput(true)).getResult())); + } + + @Mapper(value = "kuerzel", local = true) + public static TypeMapper kurzelMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + List current = new ArrayList<>(); + current.add("WG"); + current.add("MWG"); + current.add("AS"); + current.add("WS"); + current.add("WSInner"); + current.add("WG35"); + return current; + } + + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + return s; + } + }; + } + + @Mapper(value = "force", local = true) + public static TypeMapper forceMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + List current = new ArrayList<>(); + current.add("-f"); + return current; + } + + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + if (s.equals("-f")) { + return s; + } + if (s.equals("")) { + return ""; + } + return null; + } + }; + } + + @Mapper(value = "creator", local = true) + public static TypeMapper creatorMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + List current = new ArrayList<>(); + current.add("public"); + Bukkit.getOnlinePlayers().forEach(player -> { + current.add(player.getName()); + }); + return current; + } + + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + Set current = new HashSet<>(); + current.add("public"); + Bukkit.getOnlinePlayers().forEach(player -> { + current.add(player.getName()); + }); + if (current.contains(s)) { + return s; + } + return null; + } + }; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java index 4e5108b6..43ed5749 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java @@ -45,6 +45,7 @@ public class Prototype { @Getter public static class Skin { private final String name; + private final String creator; // Nullable private final File schematicFile; private final File testblockSchematicFile; // Nullable private final File buildSchematicFile; // Nullable @@ -100,17 +101,18 @@ public class Prototype { yapionObject.getArray("skins").forEach(yapionAnyType -> { YAPIONObject skinObject = (YAPIONObject) yapionAnyType; String skinName = skinObject.getPlainValue("name"); + String skinCreator = skinObject.getPlainValueOrDefault("creator", null); String schematicFileName = skinObject.getPlainValue("schematic"); String testblockSchematicFileName = skinObject.getPlainValueOrDefault("testblockSchematic", null); String buildSchematicFileName = skinObject.getPlainValueOrDefault("buildSchematic", null); - skinMap.put(skinName, new Skin(skinName, new File(schematicFileName), testblockSchematicFileName == null ? null : new File(testblockSchematicFileName), buildSchematicFileName == null ? null : new File(buildSchematicFileName))); + skinMap.put(skinName, new Skin(skinName, skinCreator, new File(schematicFileName), testblockSchematicFileName == null ? null : new File(testblockSchematicFileName), buildSchematicFileName == null ? null : new File(buildSchematicFileName))); }); } else { String s = yapionObject.getPlainValueOrDefault("schematic", null); File schematicFile = s == null ? null : new File(s); File testblockSchematicFile = testblock != null ? testblock.getSchematicFile() : null; File buildSchematicFile = build != null ? build.getSchematicFile() : null; - skinMap.put(displayName, new Skin(defaultSkin, schematicFile, testblockSchematicFile, buildSchematicFile)); + skinMap.put(displayName, new Skin(defaultSkin, null, schematicFile, testblockSchematicFile, buildSchematicFile)); } if (PROTOTYPE_MAP.containsKey(name)) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 952f35cb..6880ddd8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -547,6 +547,10 @@ public class Region { return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.backup(minPoint, maxPoint, backupFile), 15)); } + public static boolean copy(Point minPoint, Point maxPoint, File file) { + return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.backup(minPoint, maxPoint, file), 15)); + } + public List listBackup() { final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name); //noinspection ResultOfMethodCallIgnored