SteamWar/BungeeCore
Archiviert
13
2

Merge pull request 'Commands' (#427) from Commands into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #427
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-09-06 15:44:36 +02:00
Commit baef387fdb
7 geänderte Dateien mit 198 neuen und 106 gelöschten Zeilen

@ -1 +1 @@
Subproject commit 3701f6f5ff10fa97d6816d5f57c85f7213f7fb3e
Subproject commit 6e6d34905ac39bd2ed9548729041febadd42da2f

Datei anzeigen

@ -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<File> 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<Optional<File>> generatorTypeMapper() {
private TypeMapper<File> generatorTypeMapper() {
return new TypeMapper<Optional<File>>() {
return new TypeMapper<File>() {
@Override
public Optional<File> 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

Datei anzeigen

@ -22,86 +22,79 @@ 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("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);
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, m) : "");
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() + " " + m));
}
});
}
@Validator(value = "target", local = true)
public TypeValidator<ProxiedPlayer> targetValidator() {
return (sender, value, 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;
};
}
public static void remove(ProxiedPlayer player){
challenges.remove(player);
}
@Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) {
if(args.length == 2)
return ArenaMode.getAllChatNames(false);
return new ArrayList<>();
}
}

Datei anzeigen

@ -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;
@ -34,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:
*
@ -45,7 +44,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 +128,35 @@ 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(alreadyInArena(player))
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 +244,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
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(), player.getName());
, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName());
});
}
@Override
public Iterable<String> 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.
*/

Datei anzeigen

@ -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
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("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER",
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName());
});
}
@Override
public Iterable<String> 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<>();
}
}

Datei anzeigen

@ -0,0 +1,95 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
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;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@UtilityClass
public class TypeMappers {
public static void init() {
SWCommandUtils.addValidator("arenaPlayer", arenaPlayer());
SWCommandUtils.addMapper("nonHistoricArenaMode", arenaModeTypeMapper(false));
SWCommandUtils.addMapper("historicArenaMode", arenaModeTypeMapper(true));
SWCommandUtils.addMapper("arenaMap", arenaMapTypeMapper());
}
private static TypeValidator<ProxiedPlayer> arenaPlayer() {
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;
}
return true;
};
}
private static TypeMapper<ArenaMode> arenaModeTypeMapper(boolean historic) {
return new TypeMapper<ArenaMode>() {
@Override
public ArenaMode map(CommandSender commandSender, String[] previousArguments, String s) {
return ArenaMode.getByChat(s);
}
@Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
return ArenaMode.getAllChatNames(historic);
}
};
}
private static TypeMapper<String> arenaMapTypeMapper() {
return new TypeMapper<String>() {
@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<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
ArenaMode arenaMode = ArenaMode.getByChat(previousArguments[previousArguments.length - 1]);
List<String> stringList = new ArrayList<>(arenaMode.getMaps());
stringList.add("random");
return stringList;
}
};
}
}

Datei anzeigen

@ -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();
}
}