This commit is contained in:
ajgeiss0702
2021-07-14 16:37:22 -07:00
parent 00a1d1fd39
commit cfdadd17ca
22 changed files with 569 additions and 14 deletions
@@ -3,14 +3,19 @@ package us.ajg0702.queue.platforms.velocity;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import net.kyori.adventure.text.Component;
import us.ajg0702.queue.api.PlatformMethods;
import us.ajg0702.queue.api.commands.IBaseCommand;
import us.ajg0702.queue.api.commands.ICommandSender;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.players.QueuePlayer;
import us.ajg0702.queue.api.queues.QueueServer;
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.logging.Logger;
@@ -18,10 +23,12 @@ public class PlatformMethodsImpl implements PlatformMethods {
final ProxyServer proxyServer;
final Logger logger;
final VelocityQueue plugin;
public PlatformMethodsImpl(ProxyServer proxyServer, Logger logger) {
public PlatformMethodsImpl(VelocityQueue plugin, ProxyServer proxyServer, Logger logger) {
this.proxyServer = proxyServer;
this.logger = logger;
this.plugin = plugin;
}
@Override
@@ -33,7 +40,8 @@ public class PlatformMethodsImpl implements PlatformMethods {
@Override
public void sendPluginMessage(AdaptedPlayer player, String channel, String... data) {
if(player == null) return;
Player velocityPlayer = ((VelocityPlayer) player).getHandle();
}
@Override
@@ -49,4 +57,50 @@ public class PlatformMethodsImpl implements PlatformMethods {
if(!version.isPresent()) return "?V";
return version.get();
}
@Override
public List<AdaptedPlayer> getOnlinePlayers() {
List<AdaptedPlayer> players = new ArrayList<>();
for(Player player : proxyServer.getAllPlayers()) {
players.add(new VelocityPlayer(player));
}
return players;
}
@Override
public List<String> getPlayerNames(boolean lowercase) {
List<String> players = new ArrayList<>();
for(Player player : proxyServer.getAllPlayers()) {
if(lowercase) {
players.add(player.getUsername().toLowerCase(Locale.ROOT));
} else {
players.add(player.getUsername());
}
}
return players;
}
@Override
public AdaptedPlayer getPlayer(String name) {
Optional<Player> player = proxyServer.getPlayer(name);
if(!player.isPresent()) {
System.out.println("Player "+name+" not found");
return null;
}
return new VelocityPlayer(player.get());
}
@Override
public List<String> getServerNames() {
List<String> names = new ArrayList<>();
for(RegisteredServer server : proxyServer.getAllServers()) {
names.add(server.getServerInfo().getName());
}
return names;
}
@Override
public List<IBaseCommand> getCommands() {
return plugin.commands;
}
}
@@ -2,11 +2,15 @@ package us.ajg0702.queue.platforms.velocity;
import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import us.ajg0702.queue.api.commands.IBaseCommand;
import us.ajg0702.queue.commands.BaseCommand;
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
import us.ajg0702.queue.commands.commands.listqueues.ListCommand;
@@ -14,6 +18,7 @@ import us.ajg0702.queue.commands.commands.manage.ManageCommand;
import us.ajg0702.queue.commands.commands.queue.QueueCommand;
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.queue.platforms.velocity.commands.VelocityCommand;
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
import us.ajg0702.queue.platforms.velocity.server.ServerBuilderImpl;
import java.io.File;
@@ -47,32 +52,48 @@ public class VelocityQueue {
this.dataFolder = dataFolder.toFile();
}
List<IBaseCommand> commands;
@Subscribe
public void onProxyInit(ProxyInitializeEvent e) {
main = new QueueMain(
logger,
new PlatformMethodsImpl(proxyServer, logger),
new PlatformMethodsImpl(this, proxyServer, logger),
dataFolder
);
main.setServerBuilder(new ServerBuilderImpl(main, proxyServer));
CommandManager commandManager = proxyServer.getCommandManager();
List<BaseCommand> commands = Arrays.asList(
commands = Arrays.asList(
new QueueCommand(main),
new LeaveCommand(main),
new ListCommand(main),
new ManageCommand(main)
);
for(BaseCommand command : commands) {
CommandManager commandManager = proxyServer.getCommandManager();
for(IBaseCommand command : commands) {
commandManager.register(
commandManager.metaBuilder(command.getName())
.aliases(command.getAliases().toArray(new String[]{}))
.build(),
new VelocityCommand(main, command)
new VelocityCommand(main, (BaseCommand) command)
);
}
}
@Subscribe
public void onPluginMessage(PluginMessageEvent e) {
if(e.getIdentifier().getId().equals("ajqueue:tospigot")) {
e.setResult(PluginMessageEvent.ForwardResult.handled());
return;
}
if(!e.getIdentifier().getId().equals("ajqueue:toproxy")) return;
e.setResult(PluginMessageEvent.ForwardResult.handled());
if(!(e.getTarget() instanceof Player)) return;
main.getEventHandler().handleMessage(new VelocityPlayer((Player) e.getTarget()), e.getData());
}
}
@@ -10,6 +10,8 @@ import java.util.List;
public class VelocityCommand implements RawCommand {
final QueueMain main;
final BaseCommand command;
@@ -65,6 +65,11 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
handle.createConnectionRequest((RegisteredServer) server.getHandle()).connect();
}
@Override
public String getName() {
return handle.getUsername();
}
@Override
public Player getHandle() {
return handle;
@@ -1,12 +1,17 @@
package us.ajg0702.queue.platforms.velocity.server;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerPing;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.server.AdaptedServer;
import us.ajg0702.queue.api.server.AdaptedServerInfo;
import us.ajg0702.queue.api.server.AdaptedServerPing;
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@@ -48,6 +53,15 @@ public class VelocityServer implements AdaptedServer {
return true;
}
@Override
public List<AdaptedPlayer> getPlayers() {
List<AdaptedPlayer> players = new ArrayList<>();
for(Player player : handle.getPlayersConnected()) {
players.add(new VelocityPlayer(player));
}
return players;
}
@Override
public RegisteredServer getHandle() {
return handle;