progress
This commit is contained in:
@@ -62,4 +62,10 @@ public interface QueuePlayer {
|
|||||||
* @return The number of miliseconds since this player was online
|
* @return The number of miliseconds since this player was online
|
||||||
*/
|
*/
|
||||||
long getTimeSinceOnline();
|
long getTimeSinceOnline();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the max number of seconds this player is allowed to be offline before getting removed from the queue.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getMaxOfflineTime();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package us.ajg0702.queue.api.util;
|
||||||
|
|
||||||
|
public interface QueueLogger {
|
||||||
|
void warn(String message);
|
||||||
|
void warning(String message);
|
||||||
|
void info(String message);
|
||||||
|
void error(String message);
|
||||||
|
void severe(String message);
|
||||||
|
}
|
||||||
+1
-23
@@ -22,36 +22,14 @@ allprojects {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
mavenLocal()
|
|
||||||
|
|
||||||
maven { url = uri("https://jitpack.io") }
|
|
||||||
maven { url = uri("https://gitlab.com/api/v4/projects/19978391/packages/maven") }
|
|
||||||
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") }
|
|
||||||
maven { url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/") }
|
|
||||||
maven { url = uri("https://repo.codemc.org/repository/maven-public") }
|
|
||||||
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
|
|
||||||
maven { url = uri("https://repo.codemc.io/repository/nms/") }
|
|
||||||
maven { url = uri("https://repo.ajg0702.us") }
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation("junit:junit:4.12")
|
testImplementation("junit:junit:4.12")
|
||||||
|
|
||||||
|
implementation(project(":free"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tasks.shadowJar {
|
|
||||||
relocate("us.ajg0702.utils", "us.ajg0702.queue.utils")
|
|
||||||
relocate("org.bstats", "us.ajg0702.bstats")
|
|
||||||
relocate("net.kyori", "us.ajg0702.queue.kyori")
|
|
||||||
relocate("org.spongepowered.configurate", "us.ajg0702.queue.configurate")
|
|
||||||
archiveFileName.set("${archiveBaseName.get()}-${archiveVersion.get()}.${archiveExtension.get()}")
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
create<MavenPublication>("mavenJava") {
|
create<MavenPublication>("mavenJava") {
|
||||||
|
|||||||
@@ -12,10 +12,12 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("net.kyori:adventure-api:4.8.1")
|
compileOnly("net.kyori:adventure-api:4.8.1")
|
||||||
|
compileOnly("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")
|
||||||
|
|
||||||
compileOnly("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT")
|
compileOnly("org.slf4j:slf4j-log4j12:1.7.29")
|
||||||
|
|
||||||
compileOnly("org.spongepowered:configurate-yaml:4.0.0")
|
compileOnly("org.spongepowered:configurate-yaml:4.0.0")
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package us.ajg0702.queue.common;
|
|||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import us.ajg0702.queue.api.*;
|
import us.ajg0702.queue.api.*;
|
||||||
import us.ajg0702.queue.api.server.ServerBuilder;
|
import us.ajg0702.queue.api.server.ServerBuilder;
|
||||||
import us.ajg0702.queue.logic.LogicGetter;
|
import us.ajg0702.queue.api.util.QueueLogger;
|
||||||
|
import us.ajg0702.queue.common.utils.LogConverter;
|
||||||
|
import us.ajg0702.queue.logic.LogicGetterImpl;
|
||||||
import us.ajg0702.utils.common.Config;
|
import us.ajg0702.utils.common.Config;
|
||||||
import us.ajg0702.utils.common.Messages;
|
import us.ajg0702.utils.common.Messages;
|
||||||
|
|
||||||
@@ -12,10 +14,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class QueueMain {
|
public class QueueMain {
|
||||||
|
|
||||||
|
private static QueueMain instance;
|
||||||
|
public static QueueMain getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
private double timeBetweenPlayers;
|
private double timeBetweenPlayers;
|
||||||
public double getTimeBetweenPlayers() {
|
public double getTimeBetweenPlayers() {
|
||||||
@@ -54,8 +59,8 @@ public class QueueMain {
|
|||||||
return platformMethods;
|
return platformMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Logger logger;
|
private final QueueLogger logger;
|
||||||
public Logger getLogger() {
|
public QueueLogger getLogger() {
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +109,18 @@ public class QueueMain {
|
|||||||
private final File dataFolder;
|
private final File dataFolder;
|
||||||
|
|
||||||
|
|
||||||
public QueueMain(Logger logger, PlatformMethods platformMethods, File dataFolder) {
|
public QueueMain(QueueLogger logger, PlatformMethods platformMethods, File dataFolder) {
|
||||||
|
|
||||||
|
if(instance != null) {
|
||||||
|
try {
|
||||||
|
throw new Exception("ajQueue QueueMain is being initialized when there is already one! Still initializing it, but this can cause issues.");
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.platformMethods = platformMethods;
|
this.platformMethods = platformMethods;
|
||||||
this.dataFolder = dataFolder;
|
this.dataFolder = dataFolder;
|
||||||
@@ -112,7 +128,7 @@ public class QueueMain {
|
|||||||
constructMessages();
|
constructMessages();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = new Config(dataFolder, logger);
|
config = new Config(dataFolder, new LogConverter(logger));
|
||||||
} catch (ConfigurateException e) {
|
} catch (ConfigurateException e) {
|
||||||
logger.warning("Unable to load config:");
|
logger.warning("Unable to load config:");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -123,8 +139,8 @@ public class QueueMain {
|
|||||||
|
|
||||||
queueManager = new QueueManagerImpl(this);
|
queueManager = new QueueManagerImpl(this);
|
||||||
|
|
||||||
logic = new LogicGetter().constructLogic();
|
logic = new LogicGetterImpl().constructLogic();
|
||||||
aliasManager = new LogicGetter().constructAliasManager(config);
|
aliasManager = new LogicGetterImpl().constructAliasManager(config);
|
||||||
|
|
||||||
taskManager.rescheduleTasks();
|
taskManager.rescheduleTasks();
|
||||||
|
|
||||||
@@ -196,6 +212,6 @@ public class QueueMain {
|
|||||||
d.put("max-tries-reached", "&cUnable to connect to {SERVER}. Max retries reached.");
|
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.");
|
d.put("auto-queued", "&aYou've been auto-queued for {SERVER} because you were kicked.");
|
||||||
|
|
||||||
messages = new Messages(dataFolder, logger, d);
|
messages = new Messages(dataFolder, new LogConverter(logger), d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import us.ajg0702.queue.api.queues.QueueServer;
|
|||||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
import us.ajg0702.queue.api.server.ServerBuilder;
|
import us.ajg0702.queue.api.server.ServerBuilder;
|
||||||
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
||||||
|
import us.ajg0702.queue.common.queues.QueueServerImpl;
|
||||||
import us.ajg0702.utils.bungee.BungeeUtils;
|
import us.ajg0702.utils.bungee.BungeeUtils;
|
||||||
import us.ajg0702.utils.common.Messages;
|
import us.ajg0702.utils.common.Messages;
|
||||||
import us.ajg0702.utils.common.TimeUtils;
|
import us.ajg0702.utils.common.TimeUtils;
|
||||||
@@ -31,7 +32,39 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
serverBuilderFuture.thenRunAsync(() -> {
|
serverBuilderFuture.thenRunAsync(() -> {
|
||||||
try {
|
try {
|
||||||
servers = serverBuilderFuture.get().buildServers();
|
servers = serverBuilderFuture.get().buildServers();
|
||||||
// TODO: groups
|
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) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -81,7 +114,8 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
} else {
|
} else {
|
||||||
int priority = player.hasPermission("ajqueue.priority") ||
|
int priority = player.hasPermission("ajqueue.priority") ||
|
||||||
player.hasPermission("ajqueue.serverpriority."+server.getName()) ? 1 : 0;
|
player.hasPermission("ajqueue.serverpriority."+server.getName()) ? 1 : 0;
|
||||||
queuePlayer = new QueuePlayerImpl(player, server, priority);
|
int maxOfflineTime = player.hasPermission("ajqueue.stayqueued") ? 60 : 0;
|
||||||
|
queuePlayer = new QueuePlayerImpl(player, server, priority, maxOfflineTime);
|
||||||
if(
|
if(
|
||||||
priority == 1 &&
|
priority == 1 &&
|
||||||
server.getQueue().size() > 0
|
server.getQueue().size() > 0
|
||||||
@@ -180,7 +214,9 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getQueuedName(AdaptedPlayer player) {
|
public String getQueuedName(AdaptedPlayer player) {
|
||||||
return getSingleServer(player).getName();
|
QueueServer server = getSingleServer(player);
|
||||||
|
if(server == null) return main.getMessages().getString("placeholders.queued.none");
|
||||||
|
return server.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -367,6 +403,12 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(QueueServer server : sendingServers) {
|
for(QueueServer server : sendingServers) {
|
||||||
|
for(QueuePlayer queuePlayer : server.getQueue()) {
|
||||||
|
if(queuePlayer.getPlayer() != null) continue;
|
||||||
|
if(main.getLogic().playerDisconnectedTooLong(queuePlayer)) {
|
||||||
|
server.removePlayer(queuePlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(!server.isOnline()) continue;
|
if(!server.isOnline()) continue;
|
||||||
if(server.getQueue().size() == 0) continue;
|
if(server.getQueue().size() == 0) continue;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ public class QueuePlayerImpl implements QueuePlayer {
|
|||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public QueuePlayerImpl(AdaptedPlayer player, QueueServer server, int highestPriority) {
|
private final int maxOfflineTime;
|
||||||
|
|
||||||
|
public QueuePlayerImpl(AdaptedPlayer player, QueueServer server, int highestPriority, int maxOfflineTime) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
|
||||||
@@ -26,6 +28,8 @@ public class QueuePlayerImpl implements QueuePlayer {
|
|||||||
|
|
||||||
uuid = player.getUniqueId();
|
uuid = player.getUniqueId();
|
||||||
name = player.getName();
|
name = player.getName();
|
||||||
|
|
||||||
|
this.maxOfflineTime = maxOfflineTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,6 +88,11 @@ public class QueuePlayerImpl implements QueuePlayer {
|
|||||||
return System.currentTimeMillis()-leaveTime;
|
return System.currentTimeMillis()-leaveTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxOfflineTime() {
|
||||||
|
return maxOfflineTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private long leaveTime = 0;
|
private long leaveTime = 0;
|
||||||
public void setLeaveTime(long leaveTime) {
|
public void setLeaveTime(long leaveTime) {
|
||||||
|
|||||||
@@ -244,12 +244,12 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void addPlayer(QueuePlayer player) {
|
public void addPlayer(QueuePlayer player) {
|
||||||
addPlayer(player, -1);
|
addPlayer(player, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPlayer(QueuePlayer player, int position) {
|
public synchronized void addPlayer(QueuePlayer player, int position) {
|
||||||
if(!player.getQueueServer().equals(this) || queue.contains(player)) return;
|
if(!player.getQueueServer().equals(this) || queue.contains(player)) return;
|
||||||
if(position > 0) {
|
if(position > 0) {
|
||||||
queue.add(position, player);
|
queue.add(position, player);
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package us.ajg0702.queue.common.utils;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import us.ajg0702.queue.api.util.QueueLogger;
|
||||||
|
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class LogConverter extends Logger {
|
||||||
|
private final QueueLogger logger;
|
||||||
|
public LogConverter(QueueLogger logger) {
|
||||||
|
super("ajqueue-convert", null);
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(@NotNull LogRecord logRecord) {
|
||||||
|
String message = logRecord.getMessage();
|
||||||
|
switch(logRecord.getLevel().getName()) {
|
||||||
|
case "OFF":
|
||||||
|
break;
|
||||||
|
case "SEVERE":
|
||||||
|
logger.error(message);
|
||||||
|
case "WARNING":
|
||||||
|
logger.warn(message);
|
||||||
|
case "INFO":
|
||||||
|
logger.info(message);
|
||||||
|
default:
|
||||||
|
logger.info(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,6 @@ public class FreeLogic implements Logic {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerDisconnectedTooLong(QueuePlayer player) {
|
public boolean playerDisconnectedTooLong(QueuePlayer player) {
|
||||||
return true;
|
return 60000L < player.getTimeSinceOnline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ import us.ajg0702.queue.api.AliasManager;
|
|||||||
import us.ajg0702.queue.api.Logic;
|
import us.ajg0702.queue.api.Logic;
|
||||||
import us.ajg0702.utils.common.Config;
|
import us.ajg0702.utils.common.Config;
|
||||||
|
|
||||||
public class LogicGetter implements us.ajg0702.queue.api.LogicGetter {
|
public class LogicGetterImpl implements us.ajg0702.queue.api.LogicGetter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Logic constructLogic() {
|
public Logic constructLogic() {
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package us.ajg0702.queue.platforms.velocity;
|
||||||
|
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import us.ajg0702.queue.api.util.QueueLogger;
|
||||||
|
|
||||||
|
public class VelocityLogger implements QueueLogger {
|
||||||
|
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
|
protected VelocityLogger(Logger logger) {
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(String message) {
|
||||||
|
logger.warn(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warning(String message) {
|
||||||
|
logger.warn(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String message) {
|
||||||
|
logger.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String message) {
|
||||||
|
logger.error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void severe(String message) {
|
||||||
|
logger.error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
-9
@@ -5,16 +5,15 @@ import com.google.common.io.ByteStreams;
|
|||||||
import com.velocitypowered.api.plugin.PluginContainer;
|
import com.velocitypowered.api.plugin.PluginContainer;
|
||||||
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.ChannelIdentifier;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import us.ajg0702.queue.api.PlatformMethods;
|
import us.ajg0702.queue.api.PlatformMethods;
|
||||||
import us.ajg0702.queue.api.commands.IBaseCommand;
|
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
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.util.QueueLogger;
|
||||||
import us.ajg0702.queue.api.queues.QueueServer;
|
|
||||||
import us.ajg0702.queue.commands.commands.PlayerSender;
|
import us.ajg0702.queue.commands.commands.PlayerSender;
|
||||||
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
|
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
|
||||||
|
|
||||||
@@ -22,15 +21,14 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class VelocityMethods implements PlatformMethods {
|
public class VelocityMethods implements PlatformMethods {
|
||||||
|
|
||||||
final ProxyServer proxyServer;
|
final ProxyServer proxyServer;
|
||||||
final Logger logger;
|
final QueueLogger logger;
|
||||||
final VelocityQueue plugin;
|
final VelocityQueue plugin;
|
||||||
|
|
||||||
public VelocityMethods(VelocityQueue plugin, ProxyServer proxyServer, Logger logger) {
|
public VelocityMethods(VelocityQueue plugin, ProxyServer proxyServer, QueueLogger logger) {
|
||||||
this.proxyServer = proxyServer;
|
this.proxyServer = proxyServer;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@@ -46,8 +44,11 @@ public class VelocityMethods implements PlatformMethods {
|
|||||||
for(String s : data) {
|
for(String s : data) {
|
||||||
out.writeUTF( s );
|
out.writeUTF( s );
|
||||||
}
|
}
|
||||||
|
Optional<ServerConnection> server = velocityPlayer.getCurrentServer();
|
||||||
velocityPlayer.sendPluginMessage(MinecraftChannelIdentifier.from("ajqueue:tospigot"), out.toByteArray());
|
if(!server.isPresent()) {
|
||||||
|
throw new IllegalStateException("No server to send data to");
|
||||||
|
}
|
||||||
|
server.get().sendPluginMessage(MinecraftChannelIdentifier.from("ajqueue:tospigot"), out.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+5
-10
@@ -13,7 +13,6 @@ 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;
|
||||||
@@ -29,7 +28,8 @@ 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.logging.Logger;
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
@Plugin(
|
@Plugin(
|
||||||
id = "ajqueue",
|
id = "ajqueue",
|
||||||
@@ -42,7 +42,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
public class VelocityQueue {
|
public class VelocityQueue {
|
||||||
final ProxyServer proxyServer;
|
final ProxyServer proxyServer;
|
||||||
final Logger logger;
|
final VelocityLogger logger;
|
||||||
|
|
||||||
QueueMain main;
|
QueueMain main;
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class VelocityQueue {
|
|||||||
@Inject
|
@Inject
|
||||||
public VelocityQueue(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataFolder) {
|
public VelocityQueue(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataFolder) {
|
||||||
this.proxyServer = proxyServer;
|
this.proxyServer = proxyServer;
|
||||||
this.logger = logger;
|
this.logger = new VelocityLogger(logger);
|
||||||
|
|
||||||
this.dataFolder = dataFolder.toFile();
|
this.dataFolder = dataFolder.toFile();
|
||||||
}
|
}
|
||||||
@@ -104,14 +104,9 @@ public class VelocityQueue {
|
|||||||
System.out.println("Skipping message: "+e.getIdentifier().getId());
|
System.out.println("Skipping message: "+e.getIdentifier().getId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!e.getIdentifier().getId().equals("ajqueue:toproxy")) {
|
if(!e.getIdentifier().getId().equals("ajqueue:toproxy")) return;
|
||||||
System.out.println("Skipping message: "+e.getIdentifier().getId());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
e.setResult(PluginMessageEvent.ForwardResult.handled());
|
e.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||||
|
|
||||||
System.out.println("Processing message: "+e.getIdentifier().getId());
|
|
||||||
|
|
||||||
if(!(e.getTarget() instanceof Player)) return;
|
if(!(e.getTarget() instanceof Player)) return;
|
||||||
|
|
||||||
main.getEventHandler().handleMessage(new VelocityPlayer((Player) e.getTarget()), e.getData());
|
main.getEventHandler().handleMessage(new VelocityPlayer((Player) e.getTarget()), e.getData());
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
plugins {
|
||||||
|
`java-library`
|
||||||
|
id("com.github.johnrengelman.shadow")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "us.ajg0702.queue"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven { url = uri("https://repo.ajg0702.us") }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":free"))
|
||||||
|
|
||||||
|
compileOnly(project(":api"))
|
||||||
|
compileOnly(project(":common"))
|
||||||
|
|
||||||
|
compileOnly("com.google.guava:guava:30.1.1-jre")
|
||||||
|
|
||||||
|
compileOnly("us.ajg0702:ajUtils:1.1.6")
|
||||||
|
|
||||||
|
compileOnly("net.kyori:adventure-api:4.8.1")
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package us.ajg0702.queue.logic;
|
||||||
|
|
||||||
|
import us.ajg0702.queue.api.AliasManager;
|
||||||
|
import us.ajg0702.queue.api.Logic;
|
||||||
|
import us.ajg0702.queue.api.LogicGetter;
|
||||||
|
import us.ajg0702.utils.common.Config;
|
||||||
|
|
||||||
|
public class LogicGetterImpl implements LogicGetter {
|
||||||
|
@Override
|
||||||
|
public Logic constructLogic() {
|
||||||
|
return new PremiumLogic();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AliasManager constructAliasManager(Config config) {
|
||||||
|
return new PremiumAliasManager(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package us.ajg0702.queue.logic;
|
||||||
|
|
||||||
|
import us.ajg0702.queue.api.AliasManager;
|
||||||
|
import us.ajg0702.utils.common.Config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PremiumAliasManager implements AliasManager {
|
||||||
|
|
||||||
|
private final Config config;
|
||||||
|
|
||||||
|
protected PremiumAliasManager(Config config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAlias(String server) {
|
||||||
|
List<String> aliasesraw = config.getStringList("server-aliases");
|
||||||
|
for(String aliasraw : aliasesraw) {
|
||||||
|
String realname = aliasraw.split(":")[0];
|
||||||
|
if(!realname.equalsIgnoreCase(server)) continue;
|
||||||
|
return aliasraw.split(":")[1];
|
||||||
|
}
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getServer(String alias) {
|
||||||
|
List<String> aliasesraw = config.getStringList("server-aliases");
|
||||||
|
for(String aliasraw : aliasesraw) {
|
||||||
|
String salias = aliasraw.split(":")[1];
|
||||||
|
if(!alias.equalsIgnoreCase(salias)) continue;
|
||||||
|
return aliasraw.split(":")[0];
|
||||||
|
}
|
||||||
|
return alias;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package us.ajg0702.queue.logic;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
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;
|
||||||
|
import us.ajg0702.queue.api.util.QueueLogger;
|
||||||
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
|
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
||||||
|
import us.ajg0702.queue.logic.permissions.PermissionGetter;
|
||||||
|
|
||||||
|
public class PremiumLogic implements Logic {
|
||||||
|
@Override
|
||||||
|
public boolean isPremium() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueuePlayer priorityLogic(QueueServer server, AdaptedPlayer player) {
|
||||||
|
int maxOfflineTime = PermissionGetter.getMaxOfflineTime(player);
|
||||||
|
|
||||||
|
QueueMain main = QueueMain.getInstance();
|
||||||
|
|
||||||
|
if(player.hasPermission("ajqueue.bypass") || player.hasPermission("ajqueue.serverbypass."+server.getName())) {
|
||||||
|
QueuePlayer queuePlayer = new QueuePlayerImpl(player, server, Integer.MAX_VALUE, maxOfflineTime);
|
||||||
|
server.addPlayer(queuePlayer, 0);
|
||||||
|
main.getQueueManager().sendPlayers(server);
|
||||||
|
return queuePlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
int priority = PermissionGetter.getPriority(player);
|
||||||
|
int serverPriority = PermissionGetter.getServerPriotity(server.getName(), player);
|
||||||
|
|
||||||
|
int highestPriority = Math.max(priority, serverPriority);
|
||||||
|
|
||||||
|
QueuePlayer queuePlayer = new QueuePlayerImpl(player, server, highestPriority, maxOfflineTime);
|
||||||
|
|
||||||
|
QueueLogger logger = main.getLogger();
|
||||||
|
boolean debug = main.getConfig().getBoolean("priority-queue-debug");
|
||||||
|
|
||||||
|
if(debug) {
|
||||||
|
logger.info("[priority] "+player.getName()+" highestPriority: "+highestPriority);
|
||||||
|
logger.info("[priority] "+player.getName()+" priority: "+priority);
|
||||||
|
logger.info("[priority] "+player.getName()+" serverPriority: "+serverPriority);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(highestPriority <= 0) {
|
||||||
|
if(debug) {
|
||||||
|
logger.info("[priority] "+player.getName()+" No priority" );
|
||||||
|
}
|
||||||
|
server.addPlayer(queuePlayer);
|
||||||
|
return queuePlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImmutableList<QueuePlayer> list = server.getQueue();
|
||||||
|
|
||||||
|
for(int i = 0; i < list.size(); i++) {
|
||||||
|
QueuePlayer pl = list.get(i);
|
||||||
|
if(pl.getPriority() < highestPriority) {
|
||||||
|
if(debug) {
|
||||||
|
logger.info("[priority] "+player.getName()+" Adding to: "+i);
|
||||||
|
}
|
||||||
|
server.addPlayer(queuePlayer, i);
|
||||||
|
return queuePlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(debug) {
|
||||||
|
logger.info("[priority] "+player.getName()+" Cant go infront of anyone" );
|
||||||
|
}
|
||||||
|
server.addPlayer(queuePlayer);
|
||||||
|
return queuePlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean playerDisconnectedTooLong(QueuePlayer player) {
|
||||||
|
return player.getTimeSinceOnline() > player.getMaxOfflineTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package us.ajg0702.queue.logic.permissions;
|
||||||
|
|
||||||
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
|
|
||||||
|
public class PermissionGetter {
|
||||||
|
|
||||||
|
//TODO: all of this
|
||||||
|
|
||||||
|
public static int getMaxOfflineTime(AdaptedPlayer player) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getPriority(AdaptedPlayer player) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getServerPriotity(String server, AdaptedPlayer player) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,3 +8,4 @@ include(":spigot")
|
|||||||
include(":platforms:velocity")
|
include(":platforms:velocity")
|
||||||
|
|
||||||
include(":free")
|
include(":free")
|
||||||
|
include(":premium")
|
||||||
@@ -9,8 +9,8 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
public class Commands implements CommandExecutor {
|
||||||
|
|
||||||
Main pl;
|
SpigotMain pl;
|
||||||
public Commands(Main pl) {
|
public Commands(SpigotMain pl) {
|
||||||
this.pl = pl;
|
this.pl = pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.util.Iterator;
|
|||||||
*/
|
*/
|
||||||
public class Placeholders extends PlaceholderExpansion {
|
public class Placeholders extends PlaceholderExpansion {
|
||||||
|
|
||||||
private Main plugin;
|
private SpigotMain plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Since we register the expansion inside our own plugin, we
|
* Since we register the expansion inside our own plugin, we
|
||||||
@@ -24,7 +24,7 @@ public class Placeholders extends PlaceholderExpansion {
|
|||||||
* @param plugin
|
* @param plugin
|
||||||
* The instance of our plugin.
|
* The instance of our plugin.
|
||||||
*/
|
*/
|
||||||
public Placeholders(Main plugin){
|
public Placeholders(SpigotMain plugin){
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-21
@@ -15,7 +15,7 @@ import us.ajg0702.queue.spigot.utils.VersionSupport;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Main extends JavaPlugin implements PluginMessageListener,Listener {
|
public class SpigotMain extends JavaPlugin implements PluginMessageListener,Listener {
|
||||||
|
|
||||||
boolean papi = false;
|
boolean papi = false;
|
||||||
Placeholders placeholders;
|
Placeholders placeholders;
|
||||||
@@ -64,30 +64,12 @@ public class Main extends JavaPlugin implements PluginMessageListener,Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
|
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
|
||||||
if (!channel.equals("ajqueue:tospigot")) {
|
if (!channel.equals("ajqueue:tospigot")) return;
|
||||||
getLogger().info("Skipping message: "+channel);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getLogger().info("Processing message: "+channel);
|
|
||||||
|
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
||||||
|
|
||||||
String subchannel = in.readUTF();
|
String subchannel = in.readUTF();
|
||||||
|
|
||||||
if(subchannel.equals("actionbar")) {
|
|
||||||
String playername = in.readUTF();
|
|
||||||
Player p = Bukkit.getPlayer(playername);
|
|
||||||
if(p == null) return;
|
|
||||||
|
|
||||||
String data = in.readUTF();
|
|
||||||
final String text = data.split(";time=")[0];
|
|
||||||
//getLogger().info("recieved actionbar for "+player.getName()+": "+text);
|
|
||||||
VersionSupport.sendActionBar(p, text);
|
|
||||||
|
|
||||||
/*QueueActionbarUpdateEvent e = new QueueActionbarUpdateEvent(p);
|
|
||||||
Bukkit.getPluginManager().callEvent(e);*/
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(subchannel.equals("inqueueevent")) {
|
if(subchannel.equals("inqueueevent")) {
|
||||||
String playername = in.readUTF();
|
String playername = in.readUTF();
|
||||||
Player p = Bukkit.getPlayer(playername);
|
Player p = Bukkit.getPlayer(playername);
|
||||||
@@ -161,7 +143,6 @@ public class Main extends JavaPlugin implements PluginMessageListener,Listener {
|
|||||||
|
|
||||||
|
|
||||||
public void sendMessage(Player player, String subchannel, String data) {
|
public void sendMessage(Player player, String subchannel, String data) {
|
||||||
//getLogger().info("Sending message. "+subchannel+" "+data);
|
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF(subchannel);
|
out.writeUTF(subchannel);
|
||||||
out.writeUTF(data);
|
out.writeUTF(data);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
main: us.ajg0702.queue.spigot.Main
|
main: us.ajg0702.queue.spigot.SpigotMain
|
||||||
version: "@VERSION@"
|
version: "@VERSION@"
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
author: ajgeiss0702
|
author: ajgeiss0702
|
||||||
|
|||||||
Reference in New Issue
Block a user