Archiviert
1
0

Merge pull request 'CommandArena' (#373) from CommandArena into master

Reviewed-on: SteamWar/BungeeCore#373
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-07-22 08:53:21 +02:00
Commit b562f1a24c

Datei anzeigen

@ -19,33 +19,55 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.Subserver;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class ArenaCommand extends BasicCommand { import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class ArenaCommand extends SWCommand {
public ArenaCommand() { public ArenaCommand() {
super("arena", null); super("arena");
}
@Register
public void arenaJoin(ProxiedPlayer player, Subserver server) {
TpCommand.teleport(player, server.getServer());
}
@ClassMapper(value = ServerInfo.class, local = true)
public TypeMapper<Subserver> serverInfoTypeMapper() {
return new TypeMapper<Subserver>() {
@Override
public Subserver map(CommandSender commandSender, String[] previousArguments, String s) {
return Subserver.getSubserver(ProxyServer.getInstance().getServerInfo(s));
} }
@Override @Override
public void execute(CommandSender sender, String[] args) { public boolean validate(CommandSender sender, Subserver value, MessageSender messageSender) {
if(!(sender instanceof ProxiedPlayer)) if (value == null || value.getType() != Servertype.ARENA) {
return; messageSender.send("ARENA_NOT_FOUND");
ProxiedPlayer player = (ProxiedPlayer) sender; return false;
}
ServerInfo server = ProxyServer.getInstance().getServerInfo(String.join(" ", args)); return true;
Subserver subserver = Subserver.getSubserver(server);
if(server == null || subserver == null || subserver.getType() != Servertype.ARENA) {
Message.send("ARENA_NOT_FOUND", player);
return;
} }
TpCommand.teleport(player, server); @Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
List<Subserver> subserverList = Subserver.getServerList();
synchronized (subserverList) {
return subserverList.stream().filter(subserver -> subserver.getType() == Servertype.ARENA).map(subserver -> subserver.getServer().getName()).collect(Collectors.toList());
}
}
};
} }
} }