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");
} }
@Override @Register
public void execute(CommandSender sender, String[] args) { public void arenaJoin(ProxiedPlayer player, Subserver server) {
if(!(sender instanceof ProxiedPlayer)) TpCommand.teleport(player, server.getServer());
return; }
ProxiedPlayer player = (ProxiedPlayer) sender;
ServerInfo server = ProxyServer.getInstance().getServerInfo(String.join(" ", args)); @ClassMapper(value = ServerInfo.class, local = true)
Subserver subserver = Subserver.getSubserver(server); public TypeMapper<Subserver> serverInfoTypeMapper() {
if(server == null || subserver == null || subserver.getType() != Servertype.ARENA) { return new TypeMapper<Subserver>() {
Message.send("ARENA_NOT_FOUND", player); @Override
return; public Subserver map(CommandSender commandSender, String[] previousArguments, String s) {
} return Subserver.getSubserver(ProxyServer.getInstance().getServerInfo(s));
}
TpCommand.teleport(player, server); @Override
public boolean validate(CommandSender sender, Subserver value, MessageSender messageSender) {
if (value == null || value.getType() != Servertype.ARENA) {
messageSender.send("ARENA_NOT_FOUND");
return false;
}
return true;
}
@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());
}
}
};
} }
} }