almost done :)
This commit is contained in:
@@ -13,6 +13,7 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("net.kyori:adventure-api:4.8.1")
|
implementation("net.kyori:adventure-api:4.8.1")
|
||||||
|
implementation("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT")
|
||||||
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")
|
compileOnly("us.ajg0702:ajUtils:1.1.6")
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package us.ajg0702.queue.api;
|
package us.ajg0702.queue.api;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
|
|
||||||
public interface EventHandler {
|
public interface EventHandler {
|
||||||
|
|
||||||
@@ -9,4 +11,13 @@ public interface EventHandler {
|
|||||||
void onPlayerJoin(AdaptedPlayer player);
|
void onPlayerJoin(AdaptedPlayer player);
|
||||||
|
|
||||||
void onPlayerLeave(AdaptedPlayer player);
|
void onPlayerLeave(AdaptedPlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player joins a server or switches between servers
|
||||||
|
* @param player the player
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
onPlayerJoinServer(AdaptedPlayer player);
|
||||||
|
|
||||||
|
void onServerKick(AdaptedPlayer player, AdaptedServer from, Component reason, boolean moving);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,4 +116,6 @@ public interface QueueManager {
|
|||||||
* @return A list of QueueServers that this player is queued for
|
* @return A list of QueueServers that this player is queued for
|
||||||
*/
|
*/
|
||||||
ImmutableList<QueueServer> getPlayerQueues(AdaptedPlayer p);
|
ImmutableList<QueueServer> getPlayerQueues(AdaptedPlayer p);
|
||||||
|
|
||||||
|
void clear(AdaptedPlayer player);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,4 @@ public interface ServerBuilder {
|
|||||||
List<QueueServer> buildServers();
|
List<QueueServer> buildServers();
|
||||||
|
|
||||||
AdaptedServer getServer(String name);
|
AdaptedServer getServer(String name);
|
||||||
|
|
||||||
QueueServer buildGroup(String name, List<AdaptedServer> servers);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class ListCommand extends BaseCommand {
|
|||||||
public void execute(ICommandSender sender, String[] args) {
|
public void execute(ICommandSender sender, String[] args) {
|
||||||
if(!checkPermission(sender)) return;
|
if(!checkPermission(sender)) return;
|
||||||
|
|
||||||
|
|
||||||
AdaptedPlayer spp = null;
|
AdaptedPlayer spp = null;
|
||||||
if(sender.isPlayer()) {
|
if(sender.isPlayer()) {
|
||||||
spp = main.getPlatformMethods().senderToPlayer(sender);
|
spp = main.getPlatformMethods().senderToPlayer(sender);
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
package us.ajg0702.queue.common;
|
package us.ajg0702.queue.common;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
import us.ajg0702.queue.api.EventHandler;
|
import us.ajg0702.queue.api.EventHandler;
|
||||||
import us.ajg0702.queue.api.commands.IBaseCommand;
|
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||||
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.players.QueuePlayer;
|
||||||
import us.ajg0702.queue.api.queues.QueueServer;
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
import us.ajg0702.queue.commands.commands.PlayerSender;
|
import us.ajg0702.queue.commands.commands.PlayerSender;
|
||||||
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class EventHandlerImpl implements EventHandler {
|
public class EventHandlerImpl implements EventHandler {
|
||||||
|
|
||||||
@@ -91,7 +96,6 @@ public class EventHandlerImpl implements EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerJoin(AdaptedPlayer player) {
|
public void onPlayerJoin(AdaptedPlayer player) {
|
||||||
ImmutableList<QueuePlayer> queues = main.getQueueManager().findPlayerInQueues(player);
|
ImmutableList<QueuePlayer> queues = main.getQueueManager().findPlayerInQueues(player);
|
||||||
@@ -109,5 +113,84 @@ public class EventHandlerImpl implements EventHandler {
|
|||||||
for(QueuePlayer queuePlayer : queues) {
|
for(QueuePlayer queuePlayer : queues) {
|
||||||
((QueuePlayerImpl) queuePlayer).setLeaveTime(System.currentTimeMillis());
|
((QueuePlayerImpl) queuePlayer).setLeaveTime(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
main.getQueueManager().clear(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerJoinServer(AdaptedPlayer player) {
|
||||||
|
ImmutableList<QueuePlayer> alreadyqueued = main.getQueueManager().findPlayerInQueues(player);
|
||||||
|
for(QueuePlayer queuePlayer : alreadyqueued) {
|
||||||
|
QueueServer server = queuePlayer.getQueueServer();
|
||||||
|
int pos = queuePlayer.getPosition();
|
||||||
|
if((pos <= 1 && server.getServerNames().contains(player.getServerName())) || main.getConfig().getBoolean("remove-player-on-server-switch")) {
|
||||||
|
server.removePlayer(player);
|
||||||
|
server.setLastSentTime(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String serverName = player.getServerName();
|
||||||
|
List<String> svs = main.getConfig().getStringList("queue-servers");
|
||||||
|
for(String s : svs) {
|
||||||
|
if(!s.contains(":")) continue;
|
||||||
|
String[] parts = s.split(":");
|
||||||
|
String from = parts[0];
|
||||||
|
String to = parts[1];
|
||||||
|
if(from.equalsIgnoreCase(serverName)) {
|
||||||
|
main.getQueueManager().addToQueue(player, to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServerKick(AdaptedPlayer player, AdaptedServer from, Component reason, boolean moving) {
|
||||||
|
|
||||||
|
if(!player.isConnected()) return;
|
||||||
|
|
||||||
|
String plainReason = PlainTextComponentSerializer.plainText().serialize(reason);
|
||||||
|
|
||||||
|
if(!moving && main.getConfig().getBoolean("send-fail-debug")) {
|
||||||
|
main.getLogger().warning("Failed to send "+player.getName()+" to "+from.getName()+". Kicked with reason: "+plainReason);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImmutableList<QueueServer> queuedServers = main.getQueueManager().getPlayerQueues(player);
|
||||||
|
if(!queuedServers.contains(main.getQueueManager().findServer(from.getName())) && main.getConfig().getBoolean("auto-add-to-queue-on-kick")) {
|
||||||
|
|
||||||
|
List<String> reasons = main.getConfig().getStringList("auto-add-kick-reasons");
|
||||||
|
boolean shouldqueue = false;
|
||||||
|
for(String kickReason : reasons) {
|
||||||
|
if(plainReason.toLowerCase().contains(kickReason.toLowerCase())) {
|
||||||
|
shouldqueue = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shouldqueue || reasons.isEmpty()) {
|
||||||
|
main.getTaskManager().runLater(() -> {
|
||||||
|
if(!player.isConnected()) return;
|
||||||
|
|
||||||
|
String toName = from.getName();
|
||||||
|
player.sendMessage(main.getMessages().getComponent("auto-queued", "SERVER:"+toName));
|
||||||
|
main.getQueueManager().addToQueue(player, toName);
|
||||||
|
}, (long) (main.getConfig().getDouble("auto-add-to-queue-on-kick-delay")*1000), TimeUnit.MILLISECONDS);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(QueueServer server : queuedServers) {
|
||||||
|
if(!(server.getServerNames().contains(from.getName()))) continue;
|
||||||
|
QueuePlayer queuePlayer = server.findPlayer(player);
|
||||||
|
if(queuePlayer.getPosition() != 1) continue;
|
||||||
|
List<String> kickReasons = main.getConfig().getStringList("kick-reasons");
|
||||||
|
|
||||||
|
for(String kickReason : kickReasons) {
|
||||||
|
if(plainReason.toLowerCase().contains(kickReason.toLowerCase())) {
|
||||||
|
server.removePlayer(queuePlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import us.ajg0702.utils.common.TimeUtils;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class QueueManagerImpl implements QueueManager {
|
public class QueueManagerImpl implements QueueManager {
|
||||||
|
|
||||||
@@ -27,47 +28,12 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
this.main = main;
|
this.main = main;
|
||||||
this.msgs = main.getMessages();
|
this.msgs = main.getMessages();
|
||||||
|
|
||||||
|
int delay = main.getConfig().getBoolean("wait-to-load-servers") ? main.getConfig().getInt("wait-to-load-servers-delay") : 0;
|
||||||
|
|
||||||
|
main.getTaskManager().runLater(() -> {
|
||||||
CompletableFuture<ServerBuilder> serverBuilderFuture = main.getFutureServerBuilder();
|
CompletableFuture<ServerBuilder> serverBuilderFuture = main.getFutureServerBuilder();
|
||||||
serverBuilderFuture.thenRunAsync(() -> {
|
serverBuilderFuture.thenRunAsync(this::reloadServers);
|
||||||
try {
|
}, delay, TimeUnit.MILLISECONDS);
|
||||||
servers = serverBuilderFuture.get().buildServers();
|
|
||||||
List<String> groupsRaw = main.getConfig().getStringList("server-groups");
|
|
||||||
for(String groupRaw : groupsRaw) {
|
|
||||||
if(groupRaw.isEmpty()) {
|
|
||||||
main.getLogger().warning("Empty group string! If you dont want server groups, set server-groups like this: server-groups: []");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String groupName = groupRaw.split(":")[0];
|
|
||||||
String[] serversRaw = groupRaw.split(":")[1].split(",");
|
|
||||||
|
|
||||||
if(main.getServerBuilder().getServer(groupName) != null) {
|
|
||||||
main.getLogger().warning("The name of a group ('"+groupName+"') cannot be the same as the name of a server!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AdaptedServer> groupServers = new ArrayList<>();
|
|
||||||
|
|
||||||
for(String serverRaw : serversRaw) {
|
|
||||||
AdaptedServer si = main.getServerBuilder().getServer(serverRaw);
|
|
||||||
if(si == null) {
|
|
||||||
main.getLogger().warning("Could not find server named '"+serverRaw+"' in servergroup '"+groupName+"'!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
groupServers.add(si);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(groupServers.size() == 0) {
|
|
||||||
main.getLogger().warning("Server group '"+groupName+"' has no servers! Ignoring it.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
servers.add(new QueueServerImpl(groupName, main, groupServers));
|
|
||||||
}
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -261,7 +227,7 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.servers.add(main.getServerBuilder().buildGroup(groupName, groupServers));
|
this.servers.add(new QueueServerImpl(groupName, main, groupServers));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,4 +481,9 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
}
|
}
|
||||||
return ImmutableList.copyOf(srs);
|
return ImmutableList.copyOf(srs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear(AdaptedPlayer player) {
|
||||||
|
sendingNowAntiSpam.remove(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ public class TaskManager {
|
|||||||
return scheduleAtFixedRate(executor, command, 0, period, unit);
|
return scheduleAtFixedRate(executor, command, 0, period, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ScheduledFuture<?> runLater(Runnable runnable, long delay, TimeUnit unit) {
|
||||||
|
return executor.schedule(runnable, delay, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private ScheduledFuture<?> scheduleAtFixedRate(ScheduledExecutorService executor, Runnable command, long initialDelay, long period, TimeUnit unit) {
|
private ScheduledFuture<?> scheduleAtFixedRate(ScheduledExecutorService executor, Runnable command, long initialDelay, long period, TimeUnit unit) {
|
||||||
return executor.scheduleAtFixedRate(() -> {
|
return executor.scheduleAtFixedRate(() -> {
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ dependencies {
|
|||||||
|
|
||||||
implementation("us.ajg0702:ajUtils:1.1.6")
|
implementation("us.ajg0702:ajUtils:1.1.6")
|
||||||
|
|
||||||
//implementation("net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT")
|
|
||||||
|
|
||||||
implementation(project(":platforms:velocity"))
|
implementation(project(":platforms:velocity"))
|
||||||
|
implementation(project(":platforms:bungeecord"))
|
||||||
|
|
||||||
implementation(project(":spigot"))
|
implementation(project(":spigot"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +32,8 @@ tasks.shadowJar {
|
|||||||
relocate("io.leangen.geantyref", "us.ajg0702.queue.libs.geantyref")
|
relocate("io.leangen.geantyref", "us.ajg0702.queue.libs.geantyref")
|
||||||
relocate("org.spongepowered", "us.ajg0702.queue.libs.sponge")
|
relocate("org.spongepowered", "us.ajg0702.queue.libs.sponge")
|
||||||
relocate("org.yaml", "us.ajg0702.queue.libs.yaml")
|
relocate("org.yaml", "us.ajg0702.queue.libs.yaml")
|
||||||
archiveFileName.set("${baseName}-${version}.${extension}")
|
archiveBaseName.set("ajQueue")
|
||||||
|
archiveClassifier.set("")
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
plugins {
|
||||||
|
`java-library`
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "us.ajg0702.queue.platforms.bungeecord"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven { url = uri("https://repo.ajg0702.us") }
|
||||||
|
maven { url = uri("https://nexus.velocitypowered.com/repository/maven-public/") }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly("net.kyori:adventure-api:4.8.1")
|
||||||
|
compileOnly("com.google.guava:guava:30.1.1-jre")
|
||||||
|
compileOnly("us.ajg0702:ajUtils:1.1.6")
|
||||||
|
|
||||||
|
compileOnly("net.md-5:bungeecord-api:1.14-SNAPSHOT")
|
||||||
|
|
||||||
|
compileOnly("net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT")
|
||||||
|
|
||||||
|
implementation("net.kyori:adventure-platform-bungeecord:4.0.0-SNAPSHOT")
|
||||||
|
compileOnly("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT")
|
||||||
|
|
||||||
|
implementation(project(":common"))
|
||||||
|
implementation(project(":api"))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tasks.withType<ProcessResources> {
|
||||||
|
from(sourceSets.main.get().java.srcDirs)
|
||||||
|
filter<org.apache.tools.ant.filters.ReplaceTokens>(
|
||||||
|
"tokens" to mapOf(
|
||||||
|
"VERSION" to project.version.toString()
|
||||||
|
)
|
||||||
|
).into("$buildDir/src")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.jar {
|
||||||
|
exclude("**/*.java")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
create<MavenPublication>("mavenJava") {
|
||||||
|
artifact(tasks["jar"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
|
||||||
|
val mavenUrl = "https://repo.ajg0702.us/releases"
|
||||||
|
|
||||||
|
if(!System.getenv("REPO_TOKEN").isNullOrEmpty()) {
|
||||||
|
maven {
|
||||||
|
url = uri(mavenUrl)
|
||||||
|
name = "ajRepo"
|
||||||
|
|
||||||
|
credentials {
|
||||||
|
username = "plugins"
|
||||||
|
password = System.getenv("REPO_TOKEN")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package us.ajg0702.queue.platforms.bungeecord;
|
||||||
|
|
||||||
|
import us.ajg0702.queue.api.util.QueueLogger;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class BungeeLogger implements QueueLogger {
|
||||||
|
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
|
protected BungeeLogger(Logger logger) {
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(String message) {
|
||||||
|
logger.warning(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warning(String message) {
|
||||||
|
logger.warning(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String message) {
|
||||||
|
logger.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String message) {
|
||||||
|
logger.severe(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void severe(String message) {
|
||||||
|
logger.severe(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
+103
@@ -0,0 +1,103 @@
|
|||||||
|
package us.ajg0702.queue.platforms.bungeecord;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
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.util.QueueLogger;
|
||||||
|
import us.ajg0702.queue.commands.commands.PlayerSender;
|
||||||
|
import us.ajg0702.queue.platforms.bungeecord.players.BungeePlayer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class BungeeMethods implements PlatformMethods {
|
||||||
|
|
||||||
|
final ProxyServer proxyServer;
|
||||||
|
final QueueLogger logger;
|
||||||
|
final BungeeQueue plugin;
|
||||||
|
|
||||||
|
public BungeeMethods(BungeeQueue plugin, ProxyServer proxyServer, QueueLogger logger) {
|
||||||
|
this.proxyServer = proxyServer;
|
||||||
|
this.logger = logger;
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
|
@Override
|
||||||
|
public void sendPluginMessage(AdaptedPlayer player, String channel, String... data) {
|
||||||
|
Collection<ProxiedPlayer> networkPlayers = ProxyServer.getInstance().getPlayers();
|
||||||
|
if (networkPlayers != null && !networkPlayers.isEmpty()) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF(channel);
|
||||||
|
out.writeUTF(player.getName());
|
||||||
|
int length = data.length;
|
||||||
|
|
||||||
|
for (String s : data) {
|
||||||
|
out.writeUTF(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
((BungeePlayer) player).getHandle().getServer().sendData("ajqueue:tospigot", out.toByteArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AdaptedPlayer senderToPlayer(ICommandSender sender) {
|
||||||
|
if(sender instanceof PlayerSender) {
|
||||||
|
return ((PlayerSender) sender).getHandle();
|
||||||
|
}
|
||||||
|
return new BungeePlayer((ProxiedPlayer) sender.getHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPluginVersion() {
|
||||||
|
return plugin.getDescription().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AdaptedPlayer> getOnlinePlayers() {
|
||||||
|
List<AdaptedPlayer> players = new ArrayList<>();
|
||||||
|
proxyServer.getPlayers().forEach(pp -> players.add(new BungeePlayer(pp)));
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getPlayerNames(boolean lowercase) {
|
||||||
|
List<String> names = new ArrayList<>();
|
||||||
|
proxyServer.getPlayers().forEach(player -> names.add(lowercase ? player.getName().toLowerCase(Locale.ROOT) : player.getName()));
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AdaptedPlayer getPlayer(String name) {
|
||||||
|
ProxiedPlayer player = proxyServer.getPlayer(name);
|
||||||
|
if(player == null) return null;
|
||||||
|
return new BungeePlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getServerNames() {
|
||||||
|
return new ArrayList<>(proxyServer.getServers().keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getImplementationName() {
|
||||||
|
return "BungeeCord";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IBaseCommand> getCommands() {
|
||||||
|
return plugin.commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPlugin(String pluginName) {
|
||||||
|
return proxyServer.getPluginManager().getPlugin(pluginName) != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+132
@@ -0,0 +1,132 @@
|
|||||||
|
package us.ajg0702.queue.platforms.bungeecord;
|
||||||
|
|
||||||
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.event.*;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||||
|
import us.ajg0702.queue.api.util.QueueLogger;
|
||||||
|
import us.ajg0702.queue.commands.BaseCommand;
|
||||||
|
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
|
||||||
|
import us.ajg0702.queue.commands.commands.listqueues.ListCommand;
|
||||||
|
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.bungeecord.commands.BungeeCommand;
|
||||||
|
import us.ajg0702.queue.platforms.bungeecord.players.BungeePlayer;
|
||||||
|
import us.ajg0702.queue.platforms.bungeecord.server.BungeeServer;
|
||||||
|
import us.ajg0702.queue.platforms.bungeecord.server.BungeeServerBuilder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BungeeQueue extends Plugin implements Listener {
|
||||||
|
|
||||||
|
private QueueLogger logger;
|
||||||
|
|
||||||
|
private QueueMain main;
|
||||||
|
|
||||||
|
private File dataFolder;
|
||||||
|
|
||||||
|
List<IBaseCommand> commands;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
logger = new BungeeLogger(getLogger());
|
||||||
|
dataFolder = getDataFolder();
|
||||||
|
|
||||||
|
main = new QueueMain(
|
||||||
|
logger,
|
||||||
|
new BungeeMethods(this, getProxy(), logger),
|
||||||
|
dataFolder
|
||||||
|
);
|
||||||
|
main.setServerBuilder(new BungeeServerBuilder(main, getProxy()));
|
||||||
|
|
||||||
|
getProxy().registerChannel("ajqueue:tospigot");
|
||||||
|
getProxy().registerChannel("ajqueue:tobungee");
|
||||||
|
|
||||||
|
commands = Arrays.asList(
|
||||||
|
new QueueCommand(main),
|
||||||
|
new LeaveCommand(main),
|
||||||
|
new ListCommand(main),
|
||||||
|
new ManageCommand(main)
|
||||||
|
);
|
||||||
|
|
||||||
|
for(IBaseCommand command : commands) {
|
||||||
|
getProxy().getPluginManager()
|
||||||
|
.registerCommand(this, new BungeeCommand(main, (BaseCommand) command));
|
||||||
|
}
|
||||||
|
|
||||||
|
getProxy().getPluginManager().registerListener(this, this);
|
||||||
|
|
||||||
|
adventure = BungeeAudiences.create(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BungeeAudiences adventure;
|
||||||
|
|
||||||
|
public static @NonNull BungeeAudiences adventure() {
|
||||||
|
if(adventure == null) {
|
||||||
|
throw new IllegalStateException("Cannot retrieve audience provider while plugin is not enabled");
|
||||||
|
}
|
||||||
|
return adventure;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
main.shutdown();
|
||||||
|
if(adventure != null) {
|
||||||
|
adventure.close();
|
||||||
|
adventure = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPluginMessage(PluginMessageEvent e) {
|
||||||
|
|
||||||
|
if(e.getTag().equals("ajqueue:tospigot")) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!e.getTag().equals("ajqueue:toproxy")) return;
|
||||||
|
e.setCancelled(true);
|
||||||
|
|
||||||
|
if(!(e.getReceiver() instanceof ProxiedPlayer)) return;
|
||||||
|
|
||||||
|
main.getEventHandler().handleMessage(new BungeePlayer((ProxiedPlayer) e.getReceiver()), e.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PostLoginEvent e) {
|
||||||
|
main.getEventHandler().onPlayerJoin(new BungeePlayer(e.getPlayer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onServerSwitch(ServerSwitchEvent e) {
|
||||||
|
main.getEventHandler().onPlayerJoinServer(new BungeePlayer(e.getPlayer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onLeave(PlayerDisconnectEvent e) {
|
||||||
|
main.getEventHandler().onPlayerLeave(new BungeePlayer(e.getPlayer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onKick(ServerKickEvent e) {
|
||||||
|
if(!e.getPlayer().isConnected()) return;
|
||||||
|
if(e.getPlayer().getServer() == null) return; // if the player is kicked on initial join, we dont care
|
||||||
|
Component reason = BungeeComponentSerializer.get().deserialize(e.getKickReasonComponent());
|
||||||
|
main.getEventHandler().onServerKick(
|
||||||
|
new BungeePlayer(e.getPlayer()),
|
||||||
|
new BungeeServer(e.getCancelServer()),
|
||||||
|
reason,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package us.ajg0702.queue.platforms.bungeecord.commands;
|
||||||
|
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||||
|
import us.ajg0702.queue.commands.BaseCommand;
|
||||||
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
|
|
||||||
|
public class BungeeCommand extends Command implements TabExecutor {
|
||||||
|
QueueMain main;
|
||||||
|
BaseCommand command;
|
||||||
|
public BungeeCommand(QueueMain main, BaseCommand command) {
|
||||||
|
super(command.getName(), command.getPermission(), command.getAliases().toArray(new String[0]));
|
||||||
|
this.main = main;
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
command.execute(new BungeeSender(sender), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
|
return command.autoComplete(new BungeeSender(sender), args);
|
||||||
|
}
|
||||||
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
package us.ajg0702.queue.platforms.bungeecord.commands;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
|
import us.ajg0702.queue.platforms.bungeecord.BungeeQueue;
|
||||||
|
|
||||||
|
public class BungeeSender implements ICommandSender {
|
||||||
|
|
||||||
|
final CommandSender handle;
|
||||||
|
|
||||||
|
public BungeeSender(CommandSender handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(String permission) {
|
||||||
|
return handle.hasPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPlayer() {
|
||||||
|
return handle instanceof ProxiedPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(@NotNull Component message) {
|
||||||
|
BungeeQueue.adventure().sender(handle).sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandSender getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
package us.ajg0702.queue.platforms.bungeecord.players;
|
||||||
|
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.chat.BaseComponentSerializer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
|
import us.ajg0702.queue.platforms.bungeecord.BungeeQueue;
|
||||||
|
import us.ajg0702.queue.platforms.bungeecord.server.BungeeServer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class BungeePlayer implements AdaptedPlayer, Audience {
|
||||||
|
|
||||||
|
final ProxiedPlayer handle;
|
||||||
|
|
||||||
|
public BungeePlayer(ProxiedPlayer player) {
|
||||||
|
handle = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConnected() {
|
||||||
|
return handle.isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(@NotNull Component message) {
|
||||||
|
if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return;
|
||||||
|
BungeeQueue.adventure().player(handle).sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendActionBar(@NotNull Component message) {
|
||||||
|
if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return;
|
||||||
|
BungeeQueue.adventure().player(handle).sendActionBar(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(String message) {
|
||||||
|
if(message.isEmpty()) return;
|
||||||
|
BungeeQueue.adventure().player(handle).sendMessage(Component.text(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(String permission) {
|
||||||
|
return handle.hasPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getServerName() {
|
||||||
|
return handle.getServer().getInfo().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUniqueId() {
|
||||||
|
return handle.getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connect(AdaptedServer server) {
|
||||||
|
handle.connect(((BungeeServer) server).getHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return handle.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getPermissions() {
|
||||||
|
return new ArrayList<>(handle.getPermissions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProxiedPlayer getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
+63
@@ -0,0 +1,63 @@
|
|||||||
|
package us.ajg0702.queue.platforms.bungeecord.server;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
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.bungeecord.players.BungeePlayer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class BungeeServer implements AdaptedServer {
|
||||||
|
|
||||||
|
final ServerInfo handle;
|
||||||
|
final BungeeServerInfo serverInfo;
|
||||||
|
|
||||||
|
public BungeeServer(ServerInfo handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
serverInfo = new BungeeServerInfo(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AdaptedServerInfo getServerInfo() {
|
||||||
|
return serverInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return serverInfo.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<AdaptedServerPing> ping() {
|
||||||
|
CompletableFuture<AdaptedServerPing> future = new CompletableFuture<>();
|
||||||
|
handle.ping((pp, error) -> {
|
||||||
|
if(error != null) {
|
||||||
|
future.complete(null);
|
||||||
|
}
|
||||||
|
future.complete(new BungeeServerPing(pp));
|
||||||
|
});
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canAccess(AdaptedPlayer player) {
|
||||||
|
return handle.canAccess((ProxiedPlayer) player.getHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AdaptedPlayer> getPlayers() {
|
||||||
|
List<AdaptedPlayer> players = new ArrayList<>();
|
||||||
|
handle.getPlayers().forEach(pp -> players.add(new BungeePlayer(pp)));
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerInfo getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package us.ajg0702.queue.platforms.bungeecord.server;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
|
import us.ajg0702.queue.api.server.ServerBuilder;
|
||||||
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
|
import us.ajg0702.queue.common.queues.QueueServerImpl;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class BungeeServerBuilder implements ServerBuilder {
|
||||||
|
|
||||||
|
private final ProxyServer proxyServer;
|
||||||
|
private final QueueMain main;
|
||||||
|
public BungeeServerBuilder(QueueMain main, ProxyServer proxyServer) {
|
||||||
|
this.proxyServer = proxyServer;
|
||||||
|
this.main = main;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<QueueServer> buildServers() {
|
||||||
|
List<QueueServer> result = new ArrayList<>();
|
||||||
|
Map<String, ServerInfo> servers = proxyServer.getServers();
|
||||||
|
|
||||||
|
for(String serverName : servers.keySet()) {
|
||||||
|
ServerInfo serverInfo = servers.get(serverName);
|
||||||
|
AdaptedServer adaptedServer = new BungeeServer(serverInfo);
|
||||||
|
result.add(new QueueServerImpl(adaptedServer.getName(), main, adaptedServer));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AdaptedServer getServer(String name) {
|
||||||
|
ServerInfo server = proxyServer.getServerInfo(name);
|
||||||
|
if(server == null) return null;
|
||||||
|
return new BungeeServer(server);
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package us.ajg0702.queue.platforms.bungeecord.server;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import us.ajg0702.queue.api.server.AdaptedServerInfo;
|
||||||
|
|
||||||
|
public class BungeeServerInfo implements AdaptedServerInfo {
|
||||||
|
|
||||||
|
final ServerInfo handle;
|
||||||
|
public BungeeServerInfo(ServerInfo handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return handle.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerInfo getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
package us.ajg0702.queue.platforms.bungeecord.server;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||||
|
import net.md_5.bungee.api.ServerPing;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import us.ajg0702.queue.api.server.AdaptedServerPing;
|
||||||
|
|
||||||
|
public class BungeeServerPing implements AdaptedServerPing {
|
||||||
|
|
||||||
|
final ServerPing handle;
|
||||||
|
|
||||||
|
public BungeeServerPing(ServerPing handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getDescriptionComponent() {
|
||||||
|
BaseComponent[] baseComponents = new BaseComponent[1];
|
||||||
|
baseComponents[0] = handle.getDescriptionComponent();
|
||||||
|
return BungeeComponentSerializer.get().deserialize(baseComponents);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPlainDescription() {
|
||||||
|
return handle.getDescriptionComponent().toPlainText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPlayerCount() {
|
||||||
|
return handle.getPlayers().getOnline();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxPlayers() {
|
||||||
|
return handle.getPlayers().getMax();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerPing getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
name: ajQueue
|
||||||
|
version: "@VERSION@"
|
||||||
|
main: us.ajg0702.queue.platforms.bungeecord.BungeeQueue
|
||||||
|
author: ajgeiss0702
|
||||||
+1
-2
@@ -64,8 +64,7 @@ public class VelocityMethods implements PlatformMethods {
|
|||||||
Optional<PluginContainer> plugin = proxyServer.getPluginManager().getPlugin("ajqueue");
|
Optional<PluginContainer> plugin = proxyServer.getPluginManager().getPlugin("ajqueue");
|
||||||
if(!plugin.isPresent()) return "?E";
|
if(!plugin.isPresent()) return "?E";
|
||||||
Optional<String> version = plugin.get().getDescription().getVersion();
|
Optional<String> version = plugin.get().getDescription().getVersion();
|
||||||
if(!version.isPresent()) return "?V";
|
return version.orElse("?V");
|
||||||
return version.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+23
-4
@@ -5,6 +5,7 @@ import com.velocitypowered.api.command.CommandManager;
|
|||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.event.player.KickedFromServerEvent;
|
||||||
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||||
@@ -13,6 +14,7 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import us.ajg0702.queue.api.commands.IBaseCommand;
|
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||||
import us.ajg0702.queue.commands.BaseCommand;
|
import us.ajg0702.queue.commands.BaseCommand;
|
||||||
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
|
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
|
||||||
@@ -22,14 +24,16 @@ import us.ajg0702.queue.commands.commands.queue.QueueCommand;
|
|||||||
import us.ajg0702.queue.common.QueueMain;
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
import us.ajg0702.queue.platforms.velocity.commands.VelocityCommand;
|
import us.ajg0702.queue.platforms.velocity.commands.VelocityCommand;
|
||||||
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
|
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
|
||||||
import us.ajg0702.queue.platforms.velocity.server.ServerBuilderImpl;
|
import us.ajg0702.queue.platforms.velocity.server.VelocityServerBuilder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
import us.ajg0702.queue.platforms.velocity.server.VelocityServer;
|
||||||
|
|
||||||
@Plugin(
|
@Plugin(
|
||||||
id = "ajqueue",
|
id = "ajqueue",
|
||||||
@@ -65,7 +69,7 @@ public class VelocityQueue {
|
|||||||
new VelocityMethods(this, proxyServer, logger),
|
new VelocityMethods(this, proxyServer, logger),
|
||||||
dataFolder
|
dataFolder
|
||||||
);
|
);
|
||||||
main.setServerBuilder(new ServerBuilderImpl(main, proxyServer));
|
main.setServerBuilder(new VelocityServerBuilder(main, proxyServer));
|
||||||
|
|
||||||
commands = Arrays.asList(
|
commands = Arrays.asList(
|
||||||
new QueueCommand(main),
|
new QueueCommand(main),
|
||||||
@@ -101,7 +105,6 @@ public class VelocityQueue {
|
|||||||
|
|
||||||
if(e.getIdentifier().getId().equals("ajqueue:tospigot")) {
|
if(e.getIdentifier().getId().equals("ajqueue:tospigot")) {
|
||||||
e.setResult(PluginMessageEvent.ForwardResult.handled());
|
e.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||||
System.out.println("Skipping message: "+e.getIdentifier().getId());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!e.getIdentifier().getId().equals("ajqueue:toproxy")) return;
|
if(!e.getIdentifier().getId().equals("ajqueue:toproxy")) return;
|
||||||
@@ -115,12 +118,28 @@ public class VelocityQueue {
|
|||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onJoin(ServerPostConnectEvent e) {
|
public void onJoin(ServerPostConnectEvent e) {
|
||||||
if(e.getPreviousServer() != null) return; // only run if the player just joined
|
if(e.getPreviousServer() != null) { // only run if the player just joined
|
||||||
main.getEventHandler().onPlayerJoin(new VelocityPlayer(e.getPlayer()));
|
main.getEventHandler().onPlayerJoin(new VelocityPlayer(e.getPlayer()));
|
||||||
}
|
}
|
||||||
|
main.getEventHandler().onPlayerJoinServer(new VelocityPlayer(e.getPlayer()));
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onLeave(DisconnectEvent e) {
|
public void onLeave(DisconnectEvent e) {
|
||||||
main.getEventHandler().onPlayerLeave(new VelocityPlayer(e.getPlayer()));
|
main.getEventHandler().onPlayerLeave(new VelocityPlayer(e.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onKick(KickedFromServerEvent e) {
|
||||||
|
if(!e.getPlayer().getCurrentServer().isPresent()) return; // if the player is kicked on initial join, we dont care
|
||||||
|
Optional<Component> reasonOptional = e.getServerKickReason();
|
||||||
|
main.getEventHandler().onServerKick(
|
||||||
|
new VelocityPlayer(e.getPlayer()),
|
||||||
|
new VelocityServer(e.getServer()),
|
||||||
|
reasonOptional.orElseGet(() -> Component.text("Proxy lost connection")),
|
||||||
|
// According to Tux on discord, velocity doesnt give a reason when the proxy loses connection to the connected server
|
||||||
|
e.kickedDuringServerConnect()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-2
@@ -10,8 +10,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public class VelocityCommand implements RawCommand {
|
public class VelocityCommand implements RawCommand {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final QueueMain main;
|
final QueueMain main;
|
||||||
final BaseCommand command;
|
final BaseCommand command;
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -9,6 +9,7 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -63,7 +64,18 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(AdaptedServer server) {
|
public void connect(AdaptedServer server) {
|
||||||
handle.createConnectionRequest((RegisteredServer) server.getHandle()).connect();
|
handle.createConnectionRequest((RegisteredServer) server.getHandle()).connect().thenAcceptAsync(
|
||||||
|
result -> {
|
||||||
|
if(!result.isSuccessful()) {
|
||||||
|
QueueMain.getInstance().getEventHandler().onServerKick(
|
||||||
|
this,
|
||||||
|
server,
|
||||||
|
result.getReasonComponent().orElseGet(() -> Component.text("Connection failed")),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
-7
@@ -13,11 +13,11 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ServerBuilderImpl implements ServerBuilder {
|
public class VelocityServerBuilder implements ServerBuilder {
|
||||||
|
|
||||||
private final ProxyServer proxyServer;
|
private final ProxyServer proxyServer;
|
||||||
private final QueueMain main;
|
private final QueueMain main;
|
||||||
public ServerBuilderImpl(QueueMain main, ProxyServer proxyServer) {
|
public VelocityServerBuilder(QueueMain main, ProxyServer proxyServer) {
|
||||||
this.proxyServer = proxyServer;
|
this.proxyServer = proxyServer;
|
||||||
this.main = main;
|
this.main = main;
|
||||||
}
|
}
|
||||||
@@ -35,15 +35,11 @@ public class ServerBuilderImpl implements ServerBuilder {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("OptionalIsPresent")
|
||||||
@Override
|
@Override
|
||||||
public AdaptedServer getServer(String name) {
|
public AdaptedServer getServer(String name) {
|
||||||
Optional<RegisteredServer> serverOptional = proxyServer.getServer(name);
|
Optional<RegisteredServer> serverOptional = proxyServer.getServer(name);
|
||||||
if(!serverOptional.isPresent()) return null;
|
if(!serverOptional.isPresent()) return null;
|
||||||
return new VelocityServer(serverOptional.get());
|
return new VelocityServer(serverOptional.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public QueueServer buildGroup(String name, List<AdaptedServer> servers) {
|
|
||||||
return new QueueServerImpl(name, main, servers);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,13 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.shadowJar {
|
tasks.shadowJar {
|
||||||
archiveFileName.set("${baseName}-${version}.${extension}")
|
relocate("us.ajg0702.utils", "us.ajg0702.queue.libs.utils")
|
||||||
|
relocate("org.bstats", "us.ajg0702.queue.libs.bstats")
|
||||||
|
relocate("io.leangen.geantyref", "us.ajg0702.queue.libs.geantyref")
|
||||||
|
relocate("org.spongepowered", "us.ajg0702.queue.libs.sponge")
|
||||||
|
relocate("org.yaml", "us.ajg0702.queue.libs.yaml")
|
||||||
|
archiveBaseName.set("ajQueuePlus")
|
||||||
|
archiveClassifier.set("")
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ include(":common")
|
|||||||
include(":spigot")
|
include(":spigot")
|
||||||
|
|
||||||
include(":platforms:velocity")
|
include(":platforms:velocity")
|
||||||
|
include(":platforms:bungeecord")
|
||||||
|
|
||||||
include(":free")
|
include(":free")
|
||||||
include(":premium")
|
include(":premium")
|
||||||
Reference in New Issue
Block a user