This commit is contained in:
ajgeiss0702
2021-07-09 18:24:54 -07:00
parent 61e91587a6
commit 7a6d97229a
19 changed files with 351 additions and 15 deletions
+4
View File
@@ -7,11 +7,15 @@ group = "us.ajg0702.queue.api"
repositories { repositories {
mavenCentral() mavenCentral()
maven { url = uri("https://repo.ajg0702.us") }
} }
dependencies { dependencies {
implementation("net.kyori:adventure-api:4.8.1") implementation("net.kyori:adventure-api:4.8.1")
compileOnly("com.google.guava:guava:30.1.1-jre") compileOnly("com.google.guava:guava:30.1.1-jre")
compileOnly("us.ajg0702:ajUtils:1.1.6")
} }
publishing { publishing {
@@ -0,0 +1,8 @@
package us.ajg0702.queue.api;
import us.ajg0702.utils.common.Config;
public interface LogicGetter {
Logic constructLogic();
AliasManager constructAliasManager(Config config);
}
@@ -1,6 +1,9 @@
package us.ajg0702.queue.api; package us.ajg0702.queue.api;
import us.ajg0702.queue.api.players.AdaptedPlayer; 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.api.server.AdaptedServer;
public interface PlatformMethods { public interface PlatformMethods {
/** /**
@@ -10,7 +13,7 @@ public interface PlatformMethods {
* BungeeUtils.sendCustomData(p, "inqueue", "true"); * BungeeUtils.sendCustomData(p, "inqueue", "true");
* BungeeUtils.sendCustomData(p, "inqueueevent", "true"); * BungeeUtils.sendCustomData(p, "inqueueevent", "true");
*/ */
void sendJoinQueueChannelMessages(); void sendJoinQueueChannelMessages(QueueServer queueServer, QueuePlayer queuePlayer);
/** /**
* Sends a plugin message on the plugin messaging channel * Sends a plugin message on the plugin messaging channel
@@ -1,10 +1,11 @@
package us.ajg0702.queue.api.server; package us.ajg0702.queue.api.server;
import us.ajg0702.queue.api.players.AdaptedPlayer; import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.util.Handle;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public interface AdaptedServer { public interface AdaptedServer extends Handle {
/** /**
* Gets the ServerInfo for this server * Gets the ServerInfo for this server
@@ -1,6 +1,8 @@
package us.ajg0702.queue.api.server; package us.ajg0702.queue.api.server;
public interface AdaptedServerInfo { import us.ajg0702.queue.api.util.Handle;
public interface AdaptedServerInfo extends Handle {
/** /**
* Gets the name of the server * Gets the name of the server
@@ -1,8 +1,9 @@
package us.ajg0702.queue.api.server; package us.ajg0702.queue.api.server;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import us.ajg0702.queue.api.util.Handle;
public interface AdaptedServerPing { public interface AdaptedServerPing extends Handle {
/** /**
* Gets the component of the description (aka MOTD) * Gets the component of the description (aka MOTD)
* @return A compoent of the description * @return A compoent of the description
-2
View File
@@ -38,8 +38,6 @@ repositories {
dependencies { dependencies {
testImplementation("junit:junit:4.12") testImplementation("junit:junit:4.12")
implementation(project(":common"))
} }
+3 -1
View File
@@ -13,7 +13,9 @@ repositories {
dependencies { dependencies {
compileOnly("net.kyori:adventure-api:4.8.1") compileOnly("net.kyori:adventure-api:4.8.1")
compileOnly("com.google.guava:guava:30.1.1-jre") compileOnly("com.google.guava:guava:30.1.1-jre")
compileOnly("us.ajg0702:ajUtils:1.1.5") compileOnly("us.ajg0702:ajUtils:1.1.6")
compileOnly("org.spongepowered:configurate-yaml:4.0.0")
implementation(project(":api")) implementation(project(":api"))
} }
@@ -1,9 +1,12 @@
package us.ajg0702.queue.common; package us.ajg0702.queue.common;
import org.spongepowered.configurate.ConfigurateException;
import us.ajg0702.queue.api.*; import us.ajg0702.queue.api.*;
import us.ajg0702.utils.common.Config; import us.ajg0702.utils.common.Config;
import us.ajg0702.utils.common.Messages; import us.ajg0702.utils.common.Messages;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
public class QueueMain { public class QueueMain {
@@ -57,4 +60,91 @@ public class QueueMain {
public QueueManager getQueueManager() { public QueueManager getQueueManager() {
return queueManager; return queueManager;
} }
public QueueMain(Logger logger, ServerBuilder serverBuilder, PlatformMethods platformMethods, File dataFolder) {
this.logger = logger;
this.serverBuilder = serverBuilder;
this.platformMethods = platformMethods;
try {
config = new Config(dataFolder, logger);
} catch (ConfigurateException e) {
logger.warning("Unable to load config:");
e.printStackTrace();
return;
}
timeBetweenPlayers = config.getDouble("wait-time");
queueManager = new QueueManagerImpl(this);
LinkedHashMap<String, String> d = new LinkedHashMap<>();
d.put("status.offline.base", "&c{SERVER} is {STATUS}. &7You are in position &f{POS}&7 of &f{LEN}&7.");
d.put("status.offline.offline", "offline");
d.put("status.offline.restarting", "restarting");
d.put("status.offline.full", "full");
d.put("status.offline.restricted", "restricted");
d.put("status.offline.paused", "paused");
d.put("status.online.base", "&7You are in position &f{POS}&7 of &f{LEN}&7. Estimated time: {TIME}");
d.put("status.left-last-queue", "&aYou left the last queue you were in.");
d.put("status.now-in-queue", "&aYou are now queued for {SERVER}! &7You are in position &f{POS}&7 of &f{LEN}&7.\n&7Type &f/leavequeue&7 or &f<click:run_command:/leavequeue {SERVERNAME}>click here</click>&7 to leave the queue!");
d.put("status.now-in-empty-queue", "");
d.put("status.sending-now", "&aSending you to &f{SERVER} &anow..");
d.put("errors.server-not-exist", "&cThe server {SERVER} does not exist!");
d.put("errors.already-queued", "&cYou are already queued for that server!");
d.put("errors.player-only", "&cThis command can only be executed as a player!");
d.put("errors.already-connected", "&cYou are already connected to this server!");
d.put("errors.cant-join-paused", "&cYou cannot join the queue for {SERVER} because it is paused.");
d.put("errors.deny-joining-from-server", "&cYou are not allowed to join queues from this server!");
d.put("commands.leave-queue", "&aYou left the queue for {SERVER}!");
d.put("commands.reload", "&aConfig and messages reloaded successfully!");
d.put("commands.joinqueue.usage", "&cUsage: /joinqueue <server>");
d.put("noperm", "&cYou do not have permission to do this!");
d.put("format.time.mins", "{m}m {s}s");
d.put("format.time.secs", "{s} seconds");
d.put("list.format", "&b{SERVER} &7({COUNT}): {LIST}");
d.put("list.playerlist", "&9{NAME}&7, ");
d.put("list.total", "&7Total players in queues: &f{TOTAL}");
d.put("list.none", "&7None");
d.put("spigot.actionbar.online", "&7You are queued for &f{SERVER}&7. You are in position &f{POS}&7 of &f{LEN}&7. Estimated time: {TIME}");
d.put("spigot.actionbar.offline", "&7You are queued for &f{SERVER}&7. &7You are in position &f{POS}&7 of &f{LEN}&7.");
d.put("send", "&aAdded &f{PLAYER}&a to the queue for &f{SERVER}");
d.put("remove", "&aRemoved &f{PLAYER} from all queues they were in.");
d.put("placeholders.queued.none", "None");
d.put("placeholders.position.none", "None");
d.put("commands.leave.more-args", "&cPlease specify which queue you want to leave! &7You are in these queues: {QUEUES}");
d.put("commands.leave.queues-list-format", "&f{NAME}&7, ");
d.put("commands.leave.not-queued", "&cYou are not queued for that server! &7You are in these queues: {QUEUES}");
d.put("commands.leave.no-queues", "&cYou are not queued!");
d.put("commands.pause.more-args", "&cUsage: /ajqueue pause <server> [on/off]");
d.put("commands.pause.no-server", "&cThat server does not exist!");
d.put("commands.pause.success", "&aThe queue for &f{SERVER} &ais now {PAUSED}");
d.put("commands.pause.paused.true", "&epaused");
d.put("commands.pause.paused.false", "&aun-paused");
d.put("commands.send.player-not-found", "&cThat player could not be found. Make sure they are online!");
d.put("commands.listqueues.header", "&9Queues:");
d.put("commands.listqueues.format", "<hover:show_text:'&7Status: {STATUS}'>{COLOR}{NAME}&7: {COUNT} queued</hover>");
d.put("max-tries-reached", "&cUnable to connect to {SERVER}. Max retries reached.");
d.put("auto-queued", "&aYou've been auto-queued for {SERVER} because you were kicked.");
messages = new Messages(dataFolder, logger, d);
}
} }
@@ -115,7 +115,7 @@ public class QueueManagerImpl implements QueueManager {
)); ));
} }
main.getPlatformMethods().sendJoinQueueChannelMessages(); main.getPlatformMethods().sendJoinQueueChannelMessages(server, queuePlayer);
return true; return true;
} }
@@ -0,0 +1,21 @@
package us.ajg0702.queue.logic;
import us.ajg0702.queue.api.AliasManager;
import us.ajg0702.utils.common.Config;
public class FreeAliasManager implements AliasManager {
Config config;
public FreeAliasManager(Config config) {
this.config = config;
}
@Override
public String getAlias(String server) {
return server;
}
@Override
public String getServer(String alias) {
return alias;
}
}
@@ -0,0 +1,18 @@
package us.ajg0702.queue.logic;
import us.ajg0702.queue.api.Logic;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.players.QueuePlayer;
import us.ajg0702.queue.api.queues.QueueServer;
public class FreeLogic implements Logic {
@Override
public boolean isPremium() {
return false;
}
@Override
public QueuePlayer priorityLogic(QueueServer server, AdaptedPlayer player) {
return null;
}
}
@@ -0,0 +1,18 @@
package us.ajg0702.queue.logic;
import us.ajg0702.queue.api.AliasManager;
import us.ajg0702.queue.api.Logic;
import us.ajg0702.utils.common.Config;
public class LogicGetter implements us.ajg0702.queue.api.LogicGetter {
@Override
public Logic constructLogic() {
return new FreeLogic();
}
@Override
public AliasManager constructAliasManager(Config config) {
return new FreeAliasManager(config);
}
}
+2 -1
View File
@@ -14,12 +14,13 @@ repositories {
dependencies { dependencies {
compileOnly("net.kyori:adventure-api:4.8.1") compileOnly("net.kyori:adventure-api:4.8.1")
compileOnly("com.google.guava:guava:30.1.1-jre") compileOnly("com.google.guava:guava:30.1.1-jre")
compileOnly("us.ajg0702:ajUtils:1.1.5") compileOnly("us.ajg0702:ajUtils:1.1.6")
compileOnly("com.velocitypowered:velocity-api:3.0.0") compileOnly("com.velocitypowered:velocity-api:3.0.0")
annotationProcessor("com.velocitypowered:velocity-api:3.0.0") annotationProcessor("com.velocitypowered:velocity-api:3.0.0")
implementation(project(":common")) implementation(project(":common"))
implementation(project(":api"))
} }
@@ -0,0 +1,32 @@
package us.ajg0702.queue.platforms.velocity;
import com.velocitypowered.api.proxy.ProxyServer;
import us.ajg0702.queue.api.PlatformMethods;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.players.QueuePlayer;
import us.ajg0702.queue.api.queues.QueueServer;
import java.util.logging.Logger;
public class PlatformMethodImpl implements PlatformMethods {
ProxyServer proxyServer;
Logger logger;
public PlatformMethodImpl(ProxyServer proxyServer, Logger logger) {
this.proxyServer = proxyServer;
this.logger = logger;
}
@Override
public void sendJoinQueueChannelMessages(QueueServer queueServer, QueuePlayer queuePlayer) {
AdaptedPlayer player = queuePlayer.getPlayer();
if(player == null) return;
}
@Override
public void sendPluginMessage(AdaptedPlayer player, String channel, String... data) {
}
}
@@ -0,0 +1,34 @@
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;
}
}
@@ -1,8 +1,48 @@
package us.ajg0702.queue.platforms.velocity; package us.ajg0702.queue.platforms.velocity;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.ProxyServer;
import us.ajg0702.queue.common.QueueMain;
import java.io.File;
import java.nio.file.Path;
import java.util.logging.Logger;
@Plugin(
id = "ajqueue",
name = "ajQueue",
version = "@VERSION@",
url = "https://ajg0702.us",
description = "Queue for servers",
authors = {"ajgeiss0702"}
)
@Plugin(id = "ajqueue", name = "ajQueue", version = "@VERSION@")
public class VelocityQueue { public class VelocityQueue {
ProxyServer proxyServer;
Logger logger;
QueueMain main;
File dataFolder;
@Inject
public VelocityQueue(ProxyServer proxyServer, Logger logger, Path dataFolder) {
this.proxyServer = proxyServer;
this.logger = logger;
this.dataFolder = dataFolder.toFile();
}
@Subscribe
public void onProxyInit(ProxyInitializeEvent e) {
main = new QueueMain(
logger,
new ServerBuilderImpl(proxyServer),
new PlatformMethodImpl(proxyServer, logger),
dataFolder
);
}
} }
@@ -0,0 +1,68 @@
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.text.Component;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.server.AdaptedServer;
import java.util.Optional;
import java.util.UUID;
public class VelocityPlayer implements AdaptedPlayer {
Player handle;
public VelocityPlayer(Player player) {
handle = player;
}
@Override
public boolean isConnected() {
return handle.isActive();
}
@Override
public void sendMessage(Component message) {
handle.sendMessage(message);
}
@Override
public void sendActionBar(Component message) {
handle.sendActionBar(message);
}
@Override
public void sendMessage(String message) {
handle.sendMessage(Component.text().content(message));
}
@Override
public boolean hasPermission(String permission) {
return handle.hasPermission(permission);
}
@Override
public String getServerName() {
Optional<ServerConnection> serverConnection = handle.getCurrentServer();
if(!serverConnection.isPresent()) return "none";
ServerConnection connection = serverConnection.get();
return connection.getServerInfo().getName();
}
@Override
public UUID getUniqueId() {
return handle.getUniqueId();
}
@Override
public void connect(AdaptedServer server) {
handle.createConnectionRequest((RegisteredServer) server.getHandle()).connect();
}
@Override
public Player getHandle() {
return handle;
}
}
@@ -1,5 +0,0 @@
package us.ajg0702.queue.platforms.velocity;
public class test {
public static int i = 0;
}