Archiviert
1
0

Update ChallengeCommand

Dieser Commit ist enthalten in:
yoyosource 2022-09-01 18:24:56 +02:00
Ursprung cb591fda59
Commit 7de6402a63
3 geänderte Dateien mit 110 neuen und 43 gelöschten Zeilen

Datei anzeigen

@ -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<ProxiedPlayer> fabricChecker() {
@Validator("target")
public TypeValidator<ProxiedPlayer> 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<ProxiedPlayer> targetMapper() {
return new TypeMapper<ProxiedPlayer>() {
@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<String> 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);
}

Datei anzeigen

@ -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 <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.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<ProxiedPlayer> fabricChecker() {
return (sender, value, messageSender) -> {
if (ModLoaderBlocker.isFabric(value)) {
messageSender.send("MODLOADER_DENIED");
return false;
}
return true;
};
}
public 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);
}
};
}
public 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();
}
}