From cb591fda59d8ba35e5919423d21bb5a65434d802 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Sep 2022 18:01:51 +0200 Subject: [PATCH 1/5] 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<>(); - } } From 7de6402a630d83bf6683f68367f94dba20233a83 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Sep 2022 18:24:56 +0200 Subject: [PATCH 2/5] Update ChallengeCommand --- .../bungeecore/commands/ChallengeCommand.java | 62 ++++--------- .../bungeecore/commands/TypeMappers.java | 88 +++++++++++++++++++ src/de/steamwar/command/TypeUtils.java | 3 + 3 files changed, 110 insertions(+), 43 deletions(-) create mode 100644 src/de/steamwar/bungeecore/commands/TypeMappers.java diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 143ae94..6f300f3 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -45,7 +45,7 @@ public class ChallengeCommand extends SWCommand { } @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("target") ProxiedPlayer target, String... args) { + public void challenge(@Validator("fabric") ProxiedPlayer player, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { 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); @@ -69,55 +69,31 @@ public class ChallengeCommand extends SWCommand { }); } - @Validator("fabric") - public TypeValidator fabricChecker() { + @Validator("target") + public TypeValidator targetValidator() { return (sender, value, messageSender) -> { - if (ModLoaderBlocker.isFabric(value)) { - messageSender.send("MODLOADER_DENIED"); + 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; }; } - @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); } diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java new file mode 100644 index 0000000..4f3d7bd --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -0,0 +1,88 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * 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.bungeecore.commands; + +import de.steamwar.bungeecore.ArenaMode; +import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; +import lombok.experimental.UtilityClass; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@UtilityClass +public class TypeMappers { + + public static void init() { + SWCommandUtils.addValidator("fabric", fabricChecker()); + SWCommandUtils.addMapper("nonHistoricArenaMode", arenaModeTypeMapper(false)); + SWCommandUtils.addMapper("historicArenaMode", arenaModeTypeMapper(true)); + SWCommandUtils.addMapper("arenaMap", arenaMapTypeMapper()); + } + + public static TypeValidator fabricChecker() { + return (sender, value, messageSender) -> { + if (ModLoaderBlocker.isFabric(value)) { + messageSender.send("MODLOADER_DENIED"); + return false; + } + return true; + }; + } + + public static TypeMapper arenaModeTypeMapper(boolean historic) { + return new TypeMapper() { + @Override + public ArenaMode map(CommandSender commandSender, String[] previousArguments, String s) { + return ArenaMode.getByChat(s); + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + return ArenaMode.getAllChatNames(historic); + } + }; + } + + public static TypeMapper arenaMapTypeMapper() { + return new TypeMapper() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + if (s.equalsIgnoreCase("random")) return "random"; + ArenaMode arenaMode = ArenaMode.getByChat(previousArguments[previousArguments.length - 1]); + if (arenaMode.getMaps().contains(s)) return s; + return null; + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + ArenaMode arenaMode = ArenaMode.getByChat(previousArguments[previousArguments.length - 1]); + List stringList = new ArrayList<>(arenaMode.getMaps()); + stringList.add("random"); + return stringList; + } + }; + } +} diff --git a/src/de/steamwar/command/TypeUtils.java b/src/de/steamwar/command/TypeUtils.java index df779d9..833cd4b 100644 --- a/src/de/steamwar/command/TypeUtils.java +++ b/src/de/steamwar/command/TypeUtils.java @@ -19,6 +19,7 @@ package de.steamwar.command; +import de.steamwar.bungeecore.commands.TypeMappers; import de.steamwar.bungeecore.sql.SteamwarUser; import lombok.experimental.UtilityClass; import net.md_5.bungee.BungeeCord; @@ -32,5 +33,7 @@ public class TypeUtils { static void init() { SWCommandUtils.addMapper(ProxiedPlayer.class, SWCommandUtils.createMapper(BungeeCord.getInstance()::getPlayer, (s) -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); + + TypeMappers.init(); } } From 669375e7519b5c59b61457c48283de8105c55115 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Sep 2022 18:39:08 +0200 Subject: [PATCH 3/5] Update ChallengeCommand Update FightCommand Update HistoricCommand --- .../bungeecore/commands/ChallengeCommand.java | 6 +- .../bungeecore/commands/FightCommand.java | 63 +++++++++++++------ .../bungeecore/commands/HistoricCommand.java | 32 +++------- 3 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 6f300f3..e69eaaf 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -46,7 +46,7 @@ public class ChallengeCommand extends SWCommand { @Register(description = "CHALLENGE_USAGE") public void challenge(@Validator("fabric") ProxiedPlayer player, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, args, 0, false, (p, mode, map) -> { + FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, arenaMode, map, false, (p, mode, m) -> { if(challenges.containsKey(target) && challenges.get(target).contains(p)){ challenges.remove(target); challenges.remove(p); @@ -62,9 +62,9 @@ public class ChallengeCommand extends SWCommand { challenges.get(p).add(target); 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_CHALLENGED_TARGET", target, p.getName(), mode.getDisplayName(), mode.getMaps().size() != 1 ? Message.parse("CHALLENGE_CHALLENGED_MAP", target, m) : ""); - Message.send("CHALLENGE_ACCEPT", target, Message.parse("CHALLENGE_ACCEPT_HOVER", target), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + p.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() + " " + m)); } }); } diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 3273016..c1fcd89 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; import de.steamwar.bungeecore.sql.Punishment; +import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; @@ -45,7 +46,7 @@ import java.util.LinkedList; * Sollte die Map fehlen, kann sie mit getMap() bestimmt werden. */ -public class FightCommand extends BasicCommand { +public class FightCommand extends SWCommand { public FightCommand() { super("fight", "", "f"); @@ -129,6 +130,43 @@ public class FightCommand extends BasicCommand { return false; } + static void createArena(ProxiedPlayer player, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) { + ChatSender sender = ChatSender.of(player); + if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) { + return; + } + + if(alreadyInArena(player)) + return; + + if(ModLoaderBlocker.isFabric(player) && !precommand.equals("/bau testarena ")) { + sender.system("MODLOADER_DENIED"); + return; + } + + if (arenaMode == null) { + getModes(sender, precommand, historic); + return; + } + + if (map == null) { + if (arenaMode.getMaps().size() == 1) { + map = arenaMode.getRandomMap(); + } else { + getMaps(sender, precommand, arenaMode); + return; + } + } else if (map.equalsIgnoreCase("random")) { + map = arenaMode.getRandomMap(); + } + + if (!allowMerging) { + callback.run(player, arenaMode, map); + } else { + suggestMerging(player, arenaMode, map, callback); + } + } + static void createArena(CommandSender s, String precommand, boolean allowMerging, String[] args, int startArg, boolean historic, FightCallback callback){ if(!(s instanceof ProxiedPlayer)) return; @@ -216,28 +254,15 @@ public class FightCommand extends BasicCommand { inventory.open(); } - @Override - public void execute(CommandSender sender, String[] args) { - createArena(sender, "/fight ", true, args, 0, false, (player, mode, map) -> { - Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).start(); + @Register(description = "CHALLENGE_USAGE") + public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + createArena(player, "/fight", true, arenaMode, map, false, (p, mode, m) -> { + Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER" - , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName()); + , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); }); } - @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length == 1){ - return ArenaMode.getAllChatNames(false); - }else if(args.length == 2){ - ArenaMode mode = ArenaMode.getByChat(args[1]); - if(mode == null) - return new LinkedList<>(); - return mode.getMaps(); - } - return new LinkedList<>(); - } - /** * Is called when arena parameters are clear. */ diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index b056c91..e1fa176 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -23,35 +23,21 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.ServerStarter; import de.steamwar.bungeecore.Subserver; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.command.SWCommand; import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.LinkedList; - -public class HistoricCommand extends BasicCommand { +public class HistoricCommand extends SWCommand { public HistoricCommand() { super("historic", null); } - @Override - public void execute(CommandSender sender, String[] args) { - FightCommand.createArena(sender, "/historic ", true, args, 0, true, (player, mode, map) -> { - Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).start(); - Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER" - , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName()); + @Register(description = "CHALLENGE_USAGE") + public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + FightCommand.createArena(player, "/historic", true, arenaMode, map, true, (p, mode, m) -> { + Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); + Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); }); } - - @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length == 1){ - return ArenaMode.getAllChatNames(true); - }else if(args.length == 2){ - ArenaMode mode = ArenaMode.getByChat(args[1]); - if(mode == null) - return new LinkedList<>(); - return mode.getMaps(); - } - return new LinkedList<>(); - } } From 2325190cf1ec0b51d1e7678467947d39a60e104c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 3 Sep 2022 14:33:00 +0200 Subject: [PATCH 4/5] Fix stuff --- .../bungeecore/commands/ChallengeCommand.java | 4 ++-- .../bungeecore/commands/FightCommand.java | 16 +++------------- .../bungeecore/commands/HistoricCommand.java | 8 ++++---- .../bungeecore/commands/TypeMappers.java | 15 +++++++++++---- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index e69eaaf..9ec135e 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -45,7 +45,7 @@ public class ChallengeCommand extends SWCommand { } @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("fabric") ProxiedPlayer player, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void challenge(@Validator("arenaPlayer") ProxiedPlayer player, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, arenaMode, map, false, (p, mode, m) -> { if(challenges.containsKey(target) && challenges.get(target).contains(p)){ challenges.remove(target); @@ -69,7 +69,7 @@ public class ChallengeCommand extends SWCommand { }); } - @Validator("target") + @Validator(value = "target", local = true) public TypeValidator targetValidator() { return (sender, value, messageSender) -> { if (value == null) { diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index c1fcd89..d041815 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -35,8 +35,6 @@ import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.hover.content.Text; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.LinkedList; - /** * Jeder Fightcommand (auch bau testarena und challenge) haben folgende Optionskette: * @@ -132,18 +130,10 @@ public class FightCommand extends SWCommand { static void createArena(ProxiedPlayer player, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) { ChatSender sender = ChatSender.of(player); - if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) { - return; - } if(alreadyInArena(player)) return; - if(ModLoaderBlocker.isFabric(player) && !precommand.equals("/bau testarena ")) { - sender.system("MODLOADER_DENIED"); - return; - } - if (arenaMode == null) { getModes(sender, precommand, historic); return; @@ -254,9 +244,9 @@ public class FightCommand extends SWCommand { inventory.open(); } - @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - createArena(player, "/fight", true, arenaMode, map, false, (p, mode, m) -> { + @Register + public void challenge(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + createArena(player, "/fight ", true, arenaMode, map, false, (p, mode, m) -> { Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER" , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index e1fa176..6c77fab 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -32,11 +32,11 @@ public class HistoricCommand extends SWCommand { super("historic", null); } - @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(player, "/historic", true, arenaMode, map, true, (p, mode, m) -> { + @Register + public void challenge(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> { Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); - Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", + Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); }); } diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java index 4f3d7bd..b503748 100644 --- a/src/de/steamwar/bungeecore/commands/TypeMappers.java +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -21,9 +21,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; +import de.steamwar.messages.ChatSender; import lombok.experimental.UtilityClass; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -36,14 +38,19 @@ import java.util.List; public class TypeMappers { public static void init() { - SWCommandUtils.addValidator("fabric", fabricChecker()); + SWCommandUtils.addValidator("arenaPlayer", fabricChecker()); SWCommandUtils.addMapper("nonHistoricArenaMode", arenaModeTypeMapper(false)); SWCommandUtils.addMapper("historicArenaMode", arenaModeTypeMapper(true)); SWCommandUtils.addMapper("arenaMap", arenaMapTypeMapper()); } - public static TypeValidator fabricChecker() { + private static TypeValidator fabricChecker() { return (sender, value, messageSender) -> { + ChatSender player = ChatSender.of(value); + if (player.user().isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) { + return false; + } + if (ModLoaderBlocker.isFabric(value)) { messageSender.send("MODLOADER_DENIED"); return false; @@ -52,7 +59,7 @@ public class TypeMappers { }; } - public static TypeMapper arenaModeTypeMapper(boolean historic) { + private static TypeMapper arenaModeTypeMapper(boolean historic) { return new TypeMapper() { @Override public ArenaMode map(CommandSender commandSender, String[] previousArguments, String s) { @@ -66,7 +73,7 @@ public class TypeMappers { }; } - public static TypeMapper arenaMapTypeMapper() { + private static TypeMapper arenaMapTypeMapper() { return new TypeMapper() { @Override public String map(CommandSender commandSender, String[] previousArguments, String s) { From 16c3f9374155e4389f141086012f37da8dc2c154 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 6 Sep 2022 15:36:27 +0200 Subject: [PATCH 5/5] Fix stuff --- src/de/steamwar/bungeecore/commands/TypeMappers.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java index b503748..6310171 100644 --- a/src/de/steamwar/bungeecore/commands/TypeMappers.java +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -38,13 +38,13 @@ import java.util.List; public class TypeMappers { public static void init() { - SWCommandUtils.addValidator("arenaPlayer", fabricChecker()); + SWCommandUtils.addValidator("arenaPlayer", arenaPlayer()); SWCommandUtils.addMapper("nonHistoricArenaMode", arenaModeTypeMapper(false)); SWCommandUtils.addMapper("historicArenaMode", arenaModeTypeMapper(true)); SWCommandUtils.addMapper("arenaMap", arenaMapTypeMapper()); } - private static TypeValidator fabricChecker() { + private static TypeValidator arenaPlayer() { return (sender, value, messageSender) -> { ChatSender player = ChatSender.of(value); if (player.user().isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) {