lot of progress
This commit is contained in:
@@ -18,6 +18,7 @@ dependencies {
|
||||
|
||||
compileOnly("com.velocitypowered:velocity-api:3.0.0")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.0.0")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT")
|
||||
|
||||
implementation(project(":common"))
|
||||
implementation(project(":api"))
|
||||
|
||||
+8
@@ -1,10 +1,13 @@
|
||||
package us.ajg0702.queue.platforms.velocity;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import us.ajg0702.queue.api.PlatformMethods;
|
||||
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.logging.Logger;
|
||||
|
||||
@@ -29,4 +32,9 @@ public class PlatformMethodImpl implements PlatformMethods {
|
||||
public void sendPluginMessage(AdaptedPlayer player, String channel, String... data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdaptedPlayer senderToPlayer(ICommandSender sender) {
|
||||
return new VelocityPlayer((Player) sender.getHandle());
|
||||
}
|
||||
}
|
||||
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package us.ajg0702.queue.platforms.velocity;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import us.ajg0702.queue.api.ServerBuilder;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ServerBuilderImpl implements ServerBuilder {
|
||||
|
||||
private final ProxyServer proxyServer;
|
||||
public ServerBuilderImpl(ProxyServer proxyServer) {
|
||||
this.proxyServer = proxyServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QueueServer> getServers() {
|
||||
List<QueueServer> result = new ArrayList<>();
|
||||
Collection<RegisteredServer> servers = proxyServer.getAllServers();
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueueServer buildGroup(String name, List<AdaptedServer> servers) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+24
-2
@@ -1,14 +1,22 @@
|
||||
package us.ajg0702.queue.platforms.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
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.ProxyServer;
|
||||
import us.ajg0702.queue.commands.BaseCommand;
|
||||
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.server.ServerBuilderImpl;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Plugin(
|
||||
@@ -29,7 +37,7 @@ public class VelocityQueue {
|
||||
File dataFolder;
|
||||
|
||||
@Inject
|
||||
public VelocityQueue(ProxyServer proxyServer, Logger logger, Path dataFolder) {
|
||||
public VelocityQueue(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataFolder) {
|
||||
this.proxyServer = proxyServer;
|
||||
this.logger = logger;
|
||||
|
||||
@@ -40,9 +48,23 @@ public class VelocityQueue {
|
||||
public void onProxyInit(ProxyInitializeEvent e) {
|
||||
main = new QueueMain(
|
||||
logger,
|
||||
new ServerBuilderImpl(proxyServer),
|
||||
new PlatformMethodImpl(proxyServer, logger),
|
||||
dataFolder
|
||||
);
|
||||
main.setServerBuilder(new ServerBuilderImpl(main, proxyServer));
|
||||
|
||||
CommandManager commandManager = proxyServer.getCommandManager();
|
||||
|
||||
|
||||
List<BaseCommand> commands = Arrays.asList(new QueueCommand(main));
|
||||
|
||||
for(BaseCommand command : commands) {
|
||||
commandManager.register(
|
||||
commandManager.metaBuilder(command.getName())
|
||||
.aliases(command.getAliases().toArray(new String[]{}))
|
||||
.build(),
|
||||
new VelocityCommand(main, command)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package us.ajg0702.queue.platforms.velocity.commands;
|
||||
|
||||
import com.velocitypowered.api.command.RawCommand;
|
||||
import us.ajg0702.queue.commands.BaseCommand;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VelocityCommand implements RawCommand {
|
||||
|
||||
QueueMain main;
|
||||
BaseCommand command;
|
||||
|
||||
public VelocityCommand(QueueMain main, BaseCommand command) {
|
||||
this.main = main;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
command.execute(new VelocitySender(invocation.source()), invocation.arguments().split(" "));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(final Invocation invocation) {
|
||||
return command.autoComplete(new VelocitySender(invocation.source()), invocation.arguments().split(" "));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final Invocation invocation) {
|
||||
return command.checkPermission(new VelocitySender(invocation.source()));
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package us.ajg0702.queue.platforms.velocity.commands;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||
|
||||
public class VelocitySender implements ICommandSender {
|
||||
|
||||
CommandSource handle;
|
||||
|
||||
public VelocitySender(CommandSource handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return handle.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return !(handle instanceof ConsoleCommandSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSource getHandle() {
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -3,6 +3,7 @@ package us.ajg0702.queue.platforms.velocity.players;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
@@ -10,7 +11,7 @@ import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocityPlayer implements AdaptedPlayer {
|
||||
public class VelocityPlayer implements AdaptedPlayer, Audience {
|
||||
|
||||
Player handle;
|
||||
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package us.ajg0702.queue.platforms.velocity.server;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import us.ajg0702.queue.api.server.ServerBuilder;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.common.queues.QueueServerImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ServerBuilderImpl implements ServerBuilder {
|
||||
|
||||
private final ProxyServer proxyServer;
|
||||
private final QueueMain main;
|
||||
public ServerBuilderImpl(QueueMain main, ProxyServer proxyServer) {
|
||||
this.proxyServer = proxyServer;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QueueServer> buildServers() {
|
||||
List<QueueServer> result = new ArrayList<>();
|
||||
Collection<RegisteredServer> servers = proxyServer.getAllServers();
|
||||
|
||||
for(RegisteredServer server : servers) {
|
||||
AdaptedServer adaptedServer = new VelocityServer(server);
|
||||
result.add(new QueueServerImpl(adaptedServer.getName(), main, adaptedServer));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdaptedServer getServer(String name) {
|
||||
Optional<RegisteredServer> serverOptional = proxyServer.getServer(name);
|
||||
if(serverOptional.isEmpty()) return null;
|
||||
return new VelocityServer(serverOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueueServer buildGroup(String name, List<AdaptedServer> servers) {
|
||||
return new QueueServerImpl(name, main, servers);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package us.ajg0702.queue.platforms.velocity.server;
|
||||
|
||||
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 java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class VelocityServer implements AdaptedServer {
|
||||
|
||||
private final RegisteredServer handle;
|
||||
public VelocityServer(RegisteredServer handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdaptedServerInfo getServerInfo() {
|
||||
return new VelocityServerInfo(handle.getServerInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getServerInfo().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<AdaptedServerPing> ping() {
|
||||
CompletableFuture<AdaptedServerPing> future = new CompletableFuture<>();
|
||||
CompletableFuture<ServerPing> serverPing = handle.ping();
|
||||
serverPing.thenRunAsync(() -> {
|
||||
AdaptedServerPing aPing = null;
|
||||
try {
|
||||
aPing = new VelocityServerPing(serverPing.get());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
future.complete(aPing);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccess(AdaptedPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegisteredServer getHandle() {
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package us.ajg0702.queue.platforms.velocity.server;
|
||||
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import us.ajg0702.queue.api.server.AdaptedServerInfo;
|
||||
|
||||
public class VelocityServerInfo implements AdaptedServerInfo {
|
||||
|
||||
private final ServerInfo handle;
|
||||
|
||||
public VelocityServerInfo(ServerInfo handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerInfo getHandle() {
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package us.ajg0702.queue.platforms.velocity.server;
|
||||
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServerPing;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class VelocityServerPing implements AdaptedServerPing {
|
||||
|
||||
private final ServerPing handle;
|
||||
public VelocityServerPing(ServerPing handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getDescriptionComponent() {
|
||||
return handle.getDescriptionComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlainDescription() {
|
||||
return PlainTextComponentSerializer.plainText().serialize(handle.getDescriptionComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerCount() {
|
||||
Optional<ServerPing.Players> players = handle.getPlayers();
|
||||
if(players.isEmpty()) return 0;
|
||||
return players.get().getOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxPlayers() {
|
||||
Optional<ServerPing.Players> players = handle.getPlayers();
|
||||
if(players.isEmpty()) return 0;
|
||||
return players.get().getMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerPing getHandle() {
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user