From fa7f4ef00d6318d6f1be14d3bae322f8b0c6e051 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 18 Sep 2022 21:04:47 +0200 Subject: [PATCH] Add Lockschem TabComplete --- .../features/team/LockSchemCommand.java | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/team/LockSchemCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/team/LockSchemCommand.java index daa5200f..87e4e6f2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/team/LockSchemCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/team/LockSchemCommand.java @@ -23,12 +23,18 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.Collection; +import java.util.Collections; + @Linked(LinkageType.COMMAND) public class LockSchemCommand extends SWCommand { @@ -37,49 +43,18 @@ public class LockSchemCommand extends SWCommand { } @Register(help = true) - public void genericHelp(Player p, String... args) { - SteamwarUser steamwarUser = SteamwarUser.get(p.getUniqueId()); - UserGroup userGroup = steamwarUser.getUserGroup(); - - if (userGroup != UserGroup.Admin && - userGroup != UserGroup.Developer && - userGroup != UserGroup.Moderator && - userGroup != UserGroup.Supporter) { - return; - } - + public void genericHelp(@Validator Player p, String... args) { sendHelp(p); } @Register - public void genericCommand(Player p, String owner, String schematicName) { - SteamwarUser steamwarUser = SteamwarUser.get(p.getUniqueId()); - UserGroup userGroup = steamwarUser.getUserGroup(); - - if (userGroup != UserGroup.Admin && - userGroup != UserGroup.Developer && - userGroup != UserGroup.Moderator && - userGroup != UserGroup.Supporter) { - return; - } - - SteamwarUser schemOwner = SteamwarUser.get(owner); - if (schemOwner == null) { - BauSystem.MESSAGE.send("LOCK_SCHEM_NO_USER", p); - return; - } - SchematicNode schematic = SchematicNode.getNodeFromPath(schemOwner, schematicName); - if (schematic == null) { - BauSystem.MESSAGE.send("LOCK_SCHEM_NO_SCHEM", p); - return; - } - + public void genericCommand(@Validator Player p, @ErrorMessage("LOCK_SCHEM_NO_USER") SteamwarUser owner, @ErrorMessage("LOCK_SCHEM_NO_SCHEM") SchematicNode schematic) { if(schematic.isDir()) { BauSystem.MESSAGE.send("LOCK_SCHEM_DIR", p); return; } - BauSystem.MESSAGE.send("LOCK_SCHEM_LOCKED", p, schematic.getName(), schemOwner.getUserName(), schematic.getSchemtype().name()); + BauSystem.MESSAGE.send("LOCK_SCHEM_LOCKED", p, schematic.getName(), owner.getUserName(), schematic.getSchemtype().name()); schematic.setSchemtype(SchematicType.Normal); } @@ -87,4 +62,33 @@ public class LockSchemCommand extends SWCommand { BauSystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", player, "Lock Schem"); BauSystem.MESSAGE.sendPrefixless("LOCK_SCHEM_HELP", player); } + + @ClassValidator(value = Player.class, local = true) + public TypeValidator permission() { + return (commandSender, player, messageSender) -> { + SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); + UserGroup userGroup = steamwarUser.getUserGroup(); + + return userGroup.isCheckSchematics(); + }; + } + + @ClassMapper(value = SchematicNode.class, local = true) + public TypeMapper getMapper() { + return new TypeMapper() { + @Override + public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { + SteamwarUser owner = SteamwarUser.get(strings[1]); + if(owner == null) return Collections.emptyList(); + return SchematicNode.getNodeTabcomplete(owner, s); + } + + @Override + public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { + SteamwarUser owner = SteamwarUser.get(previousArguments[1]); + if(owner == null) return null; + return SchematicNode.getNodeFromPath(owner, s); + } + }; + } } \ No newline at end of file