geforkt von SteamWar/BungeeCore
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:
Commit
b562f1a24c
@ -19,33 +19,55 @@
|
||||
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.Servertype;
|
||||
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.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
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() {
|
||||
super("arena", null);
|
||||
super("arena");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!(sender instanceof ProxiedPlayer))
|
||||
return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
@Register
|
||||
public void arenaJoin(ProxiedPlayer player, Subserver server) {
|
||||
TpCommand.teleport(player, server.getServer());
|
||||
}
|
||||
|
||||
ServerInfo server = ProxyServer.getInstance().getServerInfo(String.join(" ", args));
|
||||
Subserver subserver = Subserver.getSubserver(server);
|
||||
if(server == null || subserver == null || subserver.getType() != Servertype.ARENA) {
|
||||
Message.send("ARENA_NOT_FOUND", player);
|
||||
return;
|
||||
}
|
||||
@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));
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren