From cb591fda59d8ba35e5919423d21bb5a65434d802 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Sep 2022 18:01:51 +0200 Subject: [PATCH] WIP --- CommonCore | 2 +- .../commands/BuilderCloudCommand.java | 18 +-- .../bungeecore/commands/ChallengeCommand.java | 121 ++++++++++-------- 3 files changed, 79 insertions(+), 62 deletions(-) diff --git a/CommonCore b/CommonCore index 3701f6f..6e6d349 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 3701f6f5ff10fa97d6816d5f57c85f7213f7fb3e +Subproject commit 6e6d34905ac39bd2ed9548729041febadd42da2f diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index f790fe7..5436919 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -26,8 +26,8 @@ public class BuilderCloudCommand extends SWCommand { } @Register(description = "BUILDERCLOUD_USAGE") - public void genericCommand(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") Optional generator) { - new ServerStarter().builder(version, map, generator.orElse(null)).send(player).start(); + public void genericCommand(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { + new ServerStarter().builder(version, map, generator).send(player).start(); } @ClassMapper(value = ServerStarter.Version.class, local = true) @@ -79,24 +79,24 @@ public class BuilderCloudCommand extends SWCommand { @Cached(global = true) @Mapper(value = "generator", local = true) - private TypeMapper> generatorTypeMapper() { + private TypeMapper generatorTypeMapper() { - return new TypeMapper>() { + return new TypeMapper() { @Override - public Optional map(CommandSender commandSender, String[] previousArguments, String s) { + public File map(CommandSender commandSender, String[] previousArguments, String s) { if(s.equals("")) - return Optional.empty(); + return null; File folder = getWorldFolder(previousArguments, 2); if(folder == null) - return null; + throw new SecurityException(); File generator = new File(folder, s + ".dat"); if(!generator.exists() || !generator.isFile()) - return null; + throw new SecurityException(); - return Optional.of(generator); + return generator; } @Override diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 92fa0a7..143ae94 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -22,86 +22,103 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; import de.steamwar.bungeecore.sql.IgnoreSystem; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; +import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; +import java.util.Collection; import java.util.LinkedList; +import java.util.stream.Collectors; import static de.steamwar.bungeecore.Storage.challenges; -public class ChallengeCommand extends BasicCommand { +public class ChallengeCommand extends SWCommand { public ChallengeCommand() { - super("challenge", ""); + super("challenge"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(args.length < 1){ - Message.send("CHALLENGE_USAGE", sender); - return; - } - - if (!(sender instanceof ProxiedPlayer)) - return; - - if(ModLoaderBlocker.isFabric((ProxiedPlayer) sender)) { - Message.send("MODLOADER_DENIED", sender); - return; - } - - ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); - if(target == null){ - Message.send("CHALLENGE_OFFLINE", sender); - return; - }else if(target == sender){ - Message.send("CHALLENGE_SELF", sender); - return; - }else if (IgnoreSystem.isIgnored(target, (ProxiedPlayer) sender)) { - Message.send("CHALLENGE_IGNORED", sender); - return; - } - - Subserver subserver = Subserver.getSubserver(target); - if(subserver != null && subserver.getType() == Servertype.ARENA){ - Message.send("CHALLENGE_INARENA", sender); - return; - } - - FightCommand.createArena(sender, "/challenge " + target.getName() + " ", false, args, 1, false, (player, mode, map) -> { - if(challenges.containsKey(target) && challenges.get(target).contains(player)){ + @Register(description = "CHALLENGE_USAGE") + public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("target") ProxiedPlayer target, String... args) { + FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, args, 0, false, (p, mode, map) -> { + if(challenges.containsKey(target) && challenges.get(target).contains(p)){ challenges.remove(target); - challenges.remove(player); + challenges.remove(p); Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).redLeader(target).start(); Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName(), target.getName()); + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName(), target.getName()); }else{ - if(!challenges.containsKey(player)){ - challenges.put(player, new LinkedList<>()); + if(!challenges.containsKey(p)){ + challenges.put(p, new LinkedList<>()); } - challenges.get(player).add(target); + challenges.get(p).add(target); - Message.send("CHALLENGE_CHALLENGED", player, target.getName(), mode.getDisplayName()); - Message.send("CHALLENGE_CHALLENGED_TARGET", target, player.getName(), mode.getDisplayName(), mode.getMaps().size()!=1?Message.parse("CHALLENGE_CHALLENGED_MAP", target, map):""); + Message.send("CHALLENGE_CHALLENGED", p, target.getName(), mode.getDisplayName()); + Message.send("CHALLENGE_CHALLENGED_TARGET", target, p.getName(), mode.getDisplayName(), mode.getMaps().size()!=1?Message.parse("CHALLENGE_CHALLENGED_MAP", target, map):""); - Message.send("CHALLENGE_ACCEPT", target, Message.parse("CHALLENGE_ACCEPT_HOVER", target), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.getChatName() + " " + map)); + Message.send("CHALLENGE_ACCEPT", target, Message.parse("CHALLENGE_ACCEPT_HOVER", target), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + p.getName() + " " + mode.getChatName() + " " + map)); } }); } + @Validator("fabric") + public TypeValidator fabricChecker() { + return (sender, value, messageSender) -> { + if (ModLoaderBlocker.isFabric(value)) { + messageSender.send("MODLOADER_DENIED"); + return false; + } + return true; + }; + } + + @Mapper("target") + public TypeMapper targetMapper() { + return new TypeMapper() { + @Override + public ProxiedPlayer map(CommandSender commandSender, String[] previousArguments, String s) { + return BungeeCord.getInstance().getPlayer(s); + } + + @Override + public boolean validate(CommandSender sender, ProxiedPlayer value, MessageSender messageSender) { + if (value == null) { + messageSender.send("CHALLENGE_OFFLINE"); + return false; + } + if (sender == value) { + messageSender.send("CHALLENGE_SELF"); + return false; + } + if (IgnoreSystem.isIgnored(value, (ProxiedPlayer) sender)) { + messageSender.send("CHALLENGE_IGNORED"); + return false; + } + + Subserver subserver = Subserver.getSubserver(value); + if (subserver != null && subserver.getType() == Servertype.ARENA) { + messageSender.send("CHALLENGE_INARENA"); + return false; + } + return true; + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + return BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getDisplayName).collect(Collectors.toList()); + } + }; + } + public static void remove(ProxiedPlayer player){ challenges.remove(player); } - - @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length == 2) - return ArenaMode.getAllChatNames(false); - return new ArrayList<>(); - } }