wip
This commit is contained in:
+1
-1
@@ -6,4 +6,4 @@ dependency-reduced-pom.xml
|
|||||||
.gradle
|
.gradle
|
||||||
build
|
build
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.nosync
|
.nosync
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
plugins {
|
||||||
|
`java-library`
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "us.ajg0702.queue.api"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly("net.kyori:adventure-api:4.8.1")
|
||||||
|
compileOnly("com.google.guava:guava:30.1.1-jre")
|
||||||
|
}
|
||||||
|
|
||||||
|
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,16 @@
|
|||||||
|
package us.ajg0702.queue.api;
|
||||||
|
|
||||||
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
|
|
||||||
|
public interface QueueManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a player to a queue
|
||||||
|
* @param player The player to be added
|
||||||
|
* @param server The server or group to add the player to
|
||||||
|
* @return True if adding was successfull, false if not.
|
||||||
|
*/
|
||||||
|
public boolean addToQueue(AdaptedPlayer player, QueueServer server);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package us.ajg0702.queue.api.players;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import us.ajg0702.queue.api.util.Handle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a cross-platform player
|
||||||
|
*/
|
||||||
|
public interface AdaptedPlayer extends Handle {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a player a message from a Component
|
||||||
|
* @param message The message to send
|
||||||
|
*/
|
||||||
|
void sendMessage(Component message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a player a message from a string
|
||||||
|
* Converted to Component internally
|
||||||
|
* @param message The message to send
|
||||||
|
*/
|
||||||
|
void sendMessage(String message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package us.ajg0702.queue.api.players;
|
||||||
|
|
||||||
|
public interface QueuePlayer {
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package us.ajg0702.queue.api.queues;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
|
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a server or a group that can be queued for
|
||||||
|
*/
|
||||||
|
public interface QueueServer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the players who are queued.
|
||||||
|
* @return The players who are queued
|
||||||
|
*/
|
||||||
|
ImmutableList<QueuePlayer> getQueue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the status of the server as a string
|
||||||
|
* @param p The player that you are checking for. Used for checking restricted servers
|
||||||
|
* @return The status of the server as a string
|
||||||
|
*/
|
||||||
|
String getStatusString(AdaptedPlayer p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the status of the server as a string.
|
||||||
|
* Does not check if the player has access using restricted mode. May show online if it is restricted
|
||||||
|
* @return The status of the server as a string
|
||||||
|
*/
|
||||||
|
String getStatusString();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a server ping and uses the response to update online status, player count status, and whitelist status
|
||||||
|
*/
|
||||||
|
void updatePing();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the time the server has been offline, in miliseconds
|
||||||
|
* @return The number of miliseconds the server has been offline for
|
||||||
|
*/
|
||||||
|
int getOfflineTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets how long since the last person was sent
|
||||||
|
* @return The number of miliseconds since the last person was sent
|
||||||
|
*/
|
||||||
|
int getLastSentTime();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if the server is whitelisted or not
|
||||||
|
* @return True if whitelisted, false if not
|
||||||
|
*/
|
||||||
|
boolean isWhitelisted();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets if the server is whitelisted or not
|
||||||
|
*/
|
||||||
|
void setWhitelisted(boolean whitelisted);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the list of players who are whitelisted
|
||||||
|
* @return The list of player UUIDs who are whitelisted
|
||||||
|
*/
|
||||||
|
ImmutableList<UUID> getWhitelistedPlayers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the list of UUIDs that are whitelisted
|
||||||
|
*/
|
||||||
|
void setWhitelistedPlayers(List<UUID> whitelistedPlayers);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the server is joinable by a player
|
||||||
|
* @param p The player to see if they can join
|
||||||
|
* @return If the server is joinable
|
||||||
|
*/
|
||||||
|
boolean isJoinable(AdaptedPlayer p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pauses or unpauses a server
|
||||||
|
* @param paused true = paused, false = unpaused
|
||||||
|
*/
|
||||||
|
void setPaused(boolean paused);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the server is paused
|
||||||
|
* @return True if the server is paused, false if its not
|
||||||
|
*/
|
||||||
|
boolean isPaused();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the server is online
|
||||||
|
* @return True if the server is online, false if not
|
||||||
|
*/
|
||||||
|
boolean isOnline();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the server went online within the time set in the config
|
||||||
|
* @return If the sevrer just came online
|
||||||
|
*/
|
||||||
|
boolean justWentOnline();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the server is full
|
||||||
|
* @return If the server is full
|
||||||
|
*/
|
||||||
|
boolean isFull();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* elliot is bad
|
||||||
|
* @return true because elliot is bad
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
default boolean elliot_is_bad() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package us.ajg0702.queue.api.util;
|
||||||
|
|
||||||
|
public interface Handle {
|
||||||
|
Object getHandle();
|
||||||
|
}
|
||||||
+16
-9
@@ -4,8 +4,21 @@ plugins {
|
|||||||
`maven-publish`
|
`maven-publish`
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "us.ajg0702"
|
allprojects {
|
||||||
version = "1.9.8"
|
version = "2.0.0"
|
||||||
|
group = "us.ajg0702"
|
||||||
|
|
||||||
|
tasks.withType<Test>().configureEach {
|
||||||
|
useJUnitPlatform()
|
||||||
|
|
||||||
|
ignoreFailures = false
|
||||||
|
failFast = true
|
||||||
|
maxParallelForks = (Runtime.getRuntime().availableProcessors() - 1).takeIf { it > 0 } ?: 1
|
||||||
|
|
||||||
|
reports.html.isEnabled = false
|
||||||
|
reports.junitXml.isEnabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -23,17 +36,11 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation("junit:junit:4.12")
|
testImplementation("junit:junit:4.12")
|
||||||
testImplementation("net.kyori:adventure-text-serializer-bungeecord:4.0.0-SNAPSHOT")
|
|
||||||
testImplementation("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT")
|
|
||||||
|
|
||||||
compileOnly("com.github.MyzelYam:PremiumVanishAPI:2.0.3")
|
|
||||||
compileOnly("net.md-5:bungeecord-api:1.14-SNAPSHOT")
|
|
||||||
compileOnly(group = "org.spigotmc", name = "spigot", version = "1.16.5-R0.1-SNAPSHOT")
|
|
||||||
compileOnly("me.clip:placeholderapi:2.10.4")
|
compileOnly("me.clip:placeholderapi:2.10.4")
|
||||||
compileOnly("net.kyori:adventure-text-serializer-bungeecord:4.0.0-SNAPSHOT")
|
compileOnly("net.kyori:adventure-text-serializer-bungeecord:4.0.0-SNAPSHOT")
|
||||||
|
|
||||||
implementation("us.ajg0702:ajUtils:1.0.4")
|
implementation("us.ajg0702:ajUtils:1.0.4")
|
||||||
implementation("org.bstats:bstats-bungeecord:2.2.1")
|
|
||||||
implementation("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT")
|
implementation("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +58,7 @@ tasks.shadowJar {
|
|||||||
relocate("us.ajg0702.utils", "us.ajg0702.queue.utils")
|
relocate("us.ajg0702.utils", "us.ajg0702.queue.utils")
|
||||||
relocate("org.bstats", "us.ajg0702.bstats")
|
relocate("org.bstats", "us.ajg0702.bstats")
|
||||||
relocate("net.kyori", "us.ajg0702.queue.kyori")
|
relocate("net.kyori", "us.ajg0702.queue.kyori")
|
||||||
archiveFileName.set("${baseName}-${version}.${extension}")
|
archiveFileName.set("${archiveBaseName.get()}-${archiveVersion.get()}.${archiveExtension.get()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
plugins {
|
||||||
|
`java-library`
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "us.ajg0702.queue.api"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-1
@@ -1 +1,4 @@
|
|||||||
rootProject.name = "ajQueue"
|
rootProject.name = "ajQueue"
|
||||||
|
|
||||||
|
include(":api")
|
||||||
|
include(":common")
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package us.ajg0702.queue;
|
|
||||||
|
|
||||||
public class AliasManager {
|
|
||||||
public AliasManager(Main pl) {}
|
|
||||||
public String getAlias(String server) {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
public String getServer(String alias) {
|
|
||||||
return alias;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package us.ajg0702.queue;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
public class Logic {
|
|
||||||
|
|
||||||
static boolean isp = false;
|
|
||||||
|
|
||||||
public static void priorityLogic(List<ProxiedPlayer> list, String s, ProxiedPlayer p) {}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,355 +0,0 @@
|
|||||||
package us.ajg0702.queue;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.api.event.ServerKickEvent;
|
|
||||||
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import us.ajg0702.queue.commands.LeaveCommand;
|
|
||||||
import us.ajg0702.queue.commands.ListCommand;
|
|
||||||
import us.ajg0702.queue.commands.ManageCommand;
|
|
||||||
import us.ajg0702.queue.commands.MoveCommand;
|
|
||||||
import us.ajg0702.utils.bungee.*;
|
|
||||||
|
|
||||||
public class Main extends Plugin implements Listener {
|
|
||||||
|
|
||||||
static Main plugin = null;
|
|
||||||
|
|
||||||
public double timeBetweenPlayers = 5.0;
|
|
||||||
|
|
||||||
BungeeStats metrics;
|
|
||||||
|
|
||||||
BungeeMessages msgs;
|
|
||||||
|
|
||||||
BungeeConfig config;
|
|
||||||
|
|
||||||
Manager man;
|
|
||||||
|
|
||||||
boolean isp;
|
|
||||||
|
|
||||||
MoveCommand moveCommand;
|
|
||||||
|
|
||||||
public AliasManager aliases;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
plugin = this;
|
|
||||||
|
|
||||||
config = new BungeeConfig(this);
|
|
||||||
checkConfig();
|
|
||||||
|
|
||||||
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.");
|
|
||||||
|
|
||||||
msgs = BungeeMessages.getInstance(this, d);
|
|
||||||
|
|
||||||
aliases = new AliasManager(this);
|
|
||||||
|
|
||||||
moveCommand = new MoveCommand(this);
|
|
||||||
this.getProxy().getPluginManager().registerCommand(this, moveCommand);
|
|
||||||
this.getProxy().getPluginManager().registerCommand(this, new ManageCommand(this));
|
|
||||||
this.getProxy().getPluginManager().registerCommand(this, new LeaveCommand(this));
|
|
||||||
this.getProxy().getPluginManager().registerCommand(this, new ListCommand(this));
|
|
||||||
|
|
||||||
this.getProxy().getPluginManager().registerListener(this, this);
|
|
||||||
|
|
||||||
getProxy().registerChannel("ajqueue:tospigot");
|
|
||||||
getProxy().registerChannel("ajqueue:tobungee");
|
|
||||||
|
|
||||||
timeBetweenPlayers = config.getDouble("wait-time");
|
|
||||||
|
|
||||||
isp = Logic.isp;
|
|
||||||
|
|
||||||
man = Manager.getInstance(this);
|
|
||||||
|
|
||||||
|
|
||||||
metrics = new BungeeStats(this, 7404);
|
|
||||||
metrics.addCustomChart(new BungeeStats.SimplePie("premium", () -> isp+""));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isp() {
|
|
||||||
return isp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void checkConfig() {
|
|
||||||
if(config == null) {
|
|
||||||
getLogger().warning("Config is null!");
|
|
||||||
}
|
|
||||||
List<String> svs = getConfig().getStringList("queue-servers");
|
|
||||||
for(String s : svs) {
|
|
||||||
if(!s.contains(":")) {
|
|
||||||
getLogger().warning("The queue-servers section in the config has been set up incorrectly! Please read the comment above the setting and make sure you have a queue server and a destination server separated by a colon (:)");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BungeeConfig getConfig() {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BaseComponent[] formatMessage(String text) {
|
|
||||||
return TextComponent.fromLegacyText(net.md_5.bungee.api.ChatColor.translateAlternateColorCodes('&', text));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void moveServer(ServerSwitchEvent e) {
|
|
||||||
ProxiedPlayer p = e.getPlayer();
|
|
||||||
List<QueueServer> alreadyqueued = man.findPlayerInQueue(p);
|
|
||||||
for(QueueServer ser : alreadyqueued) {
|
|
||||||
List<ProxiedPlayer> queue = ser.getQueue();
|
|
||||||
int pos = queue.indexOf(p);
|
|
||||||
if((pos == 0 && ser.getInfos().contains(p.getServer().getInfo())) || config.getBoolean("remove-player-on-server-switch")) {
|
|
||||||
queue.remove(p);
|
|
||||||
ser.setLastSentTime(System.currentTimeMillis());
|
|
||||||
Manager.getInstance().sendingAttempts.remove(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String servername = e.getPlayer().getServer().getInfo().getName();
|
|
||||||
List<String> svs = config.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)) {
|
|
||||||
man.addToQueue(p, to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onLeave(PlayerDisconnectEvent e) {
|
|
||||||
ProxiedPlayer p = e.getPlayer();
|
|
||||||
//if(p.hasPermission("ajqueue.stay-queued-on-leave")) return;
|
|
||||||
List<QueueServer> servers = man.findPlayerInQueue(p);
|
|
||||||
for(QueueServer server : servers) {
|
|
||||||
server.getQueue().remove(p);
|
|
||||||
}
|
|
||||||
man.sendingNowAntiSpam.remove(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onFailedMove(ServerKickEvent e) {
|
|
||||||
final ProxiedPlayer p = e.getPlayer();
|
|
||||||
List<QueueServer> queuedServers = man.findPlayerInQueue(p);
|
|
||||||
|
|
||||||
|
|
||||||
if(!queuedServers.contains(man.getServer(e.getKickedFrom().getName())) && config.getBoolean("auto-add-to-queue-on-kick")) {
|
|
||||||
|
|
||||||
StringBuilder plainReason = new StringBuilder();
|
|
||||||
for(BaseComponent b : e.getKickReasonComponent()) {
|
|
||||||
plainReason.append(b.toPlainText());
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> reasons = config.getStringList("auto-add-kick-reasons");
|
|
||||||
boolean shouldqueue = false;
|
|
||||||
for(String reason : reasons) {
|
|
||||||
if(plainReason.toString().toLowerCase().contains(reason.toLowerCase())) {
|
|
||||||
shouldqueue = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(shouldqueue || reasons.isEmpty()) {
|
|
||||||
plugin.getProxy().getScheduler().schedule(this, () -> {
|
|
||||||
if(!p.isConnected()) return;
|
|
||||||
|
|
||||||
String toName = e.getKickedFrom().getName();
|
|
||||||
p.sendMessage(msgs.getBC("auto-queued", "SERVER:"+toName));
|
|
||||||
man.addToQueue(p, toName);
|
|
||||||
}, (long) (config.getDouble("auto-add-to-queue-on-kick-delay")*1000), TimeUnit.MILLISECONDS);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for(QueueServer server : queuedServers) {
|
|
||||||
if(!(server.getInfos().contains(e.getKickedFrom()))) continue;
|
|
||||||
if(server.getQueue().indexOf(p) != 0) continue;
|
|
||||||
List<String> kickreasons = config.getStringList("kick-reasons");
|
|
||||||
//getLogger().info(e.getKickReasonComponent());
|
|
||||||
StringBuilder plainReason = new StringBuilder();
|
|
||||||
for(BaseComponent b : e.getKickReasonComponent()) {
|
|
||||||
plainReason.append(b.toPlainText());
|
|
||||||
}
|
|
||||||
for(String reason : kickreasons) {
|
|
||||||
if(plainReason.toString().toLowerCase().contains(reason.toLowerCase())) {
|
|
||||||
server.getQueue().remove(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(config.getBoolean("send-fail-debug")) {
|
|
||||||
StringBuilder r = new StringBuilder();
|
|
||||||
for(BaseComponent b : e.getKickReasonComponent()) {
|
|
||||||
r.append(b.toPlainText());
|
|
||||||
}
|
|
||||||
getLogger().warning("Failed to send "+p.getName()+" to "+e.getKickedFrom().getName()+" because "+r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onMessage(PluginMessageEvent e) {
|
|
||||||
//getLogger().info("Recieved message of "+e.getTag());
|
|
||||||
if(e.getTag().equals("ajqueue:tospigot")) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!e.getTag().equals("ajqueue:tobungee")) return;
|
|
||||||
if(!(e.getReceiver() instanceof ProxiedPlayer)) return;
|
|
||||||
e.setCancelled(true);
|
|
||||||
DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()));
|
|
||||||
try {
|
|
||||||
String subchannel = in.readUTF();
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) e.getReceiver();
|
|
||||||
|
|
||||||
|
|
||||||
if(subchannel.equals("queue")) {
|
|
||||||
String data = in.readUTF();
|
|
||||||
String[] args = new String[1];
|
|
||||||
args[0] = data;
|
|
||||||
moveCommand.execute(player, args);
|
|
||||||
//man.addToQueue(player, data);
|
|
||||||
|
|
||||||
}
|
|
||||||
if(subchannel.equals("massqueue")) {
|
|
||||||
String data = in.readUTF();
|
|
||||||
String[] parts = data.split(",");
|
|
||||||
for(String part : parts) {
|
|
||||||
String[] pparts = part.split(":");
|
|
||||||
if(pparts.length < 2) continue;
|
|
||||||
String pname = pparts[0];
|
|
||||||
String pserver = pparts[1];
|
|
||||||
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(pname);
|
|
||||||
String[] args = new String[1];
|
|
||||||
args[0] = pserver;
|
|
||||||
moveCommand.execute(p, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(subchannel.equals("queuename")) {
|
|
||||||
BungeeUtils.sendCustomData(player, "queuename", aliases.getAlias(man.getQueuedName(player)));
|
|
||||||
}
|
|
||||||
if(subchannel.equals("position")) {
|
|
||||||
QueueServer server = man.getSingleServer(player);
|
|
||||||
String pos = msgs.getString("placeholders.position.none");
|
|
||||||
if(server != null) {
|
|
||||||
pos = server.getQueue().indexOf(player)+1+"";
|
|
||||||
}
|
|
||||||
BungeeUtils.sendCustomData(player, "position", pos);
|
|
||||||
}
|
|
||||||
if(subchannel.equals("positionof")) {
|
|
||||||
QueueServer server = man.getSingleServer(player);
|
|
||||||
String pos = msgs.getString("placeholders.position.none");
|
|
||||||
if(server != null) {
|
|
||||||
pos = server.getQueue().size()+"";
|
|
||||||
}
|
|
||||||
BungeeUtils.sendCustomData(player, "positionof", pos);
|
|
||||||
}
|
|
||||||
if(subchannel.equals("inqueue")) {
|
|
||||||
QueueServer server = man.getSingleServer(player);
|
|
||||||
BungeeUtils.sendCustomData(player, "inqueue", (server != null)+"");
|
|
||||||
}
|
|
||||||
if(subchannel.equals("queuedfor")) {
|
|
||||||
String srv = in.readUTF();
|
|
||||||
QueueServer server = man.findServer(srv);
|
|
||||||
if(server == null) return;
|
|
||||||
BungeeUtils.sendCustomData(player, "queuedfor", srv, server.getQueue().size()+"");
|
|
||||||
}
|
|
||||||
if(subchannel.equals("leavequeue")) {
|
|
||||||
String arg = "";
|
|
||||||
try {
|
|
||||||
arg = in.readUTF();
|
|
||||||
} catch(Exception ignored) {}
|
|
||||||
getProxy().getPluginManager().dispatchCommand(player, "leavequeue"+arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e1) {
|
|
||||||
getLogger().warning("An error occured while reading data from spigot side:");
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,648 +0,0 @@
|
|||||||
package us.ajg0702.queue;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.ServerPing;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import us.ajg0702.utils.GenUtils;
|
|
||||||
import us.ajg0702.utils.bungee.BungeeMessages;
|
|
||||||
import us.ajg0702.utils.bungee.BungeeUtils;
|
|
||||||
|
|
||||||
public class Manager {
|
|
||||||
|
|
||||||
static Manager INSTANCE = null;
|
|
||||||
public static Manager getInstance(Main pl) {
|
|
||||||
if(INSTANCE == null) {
|
|
||||||
INSTANCE = new Manager(pl);
|
|
||||||
}
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
public static Manager getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BungeeMessages msgs;
|
|
||||||
|
|
||||||
|
|
||||||
Main pl;
|
|
||||||
private Manager(Main pl) {
|
|
||||||
this.pl = pl;
|
|
||||||
msgs = BungeeMessages.getInstance();
|
|
||||||
reloadIntervals();
|
|
||||||
if(!pl.config.getBoolean("wait-to-load-servers")) {
|
|
||||||
pl.getProxy().getScheduler().schedule(pl, this::reloadServers, 0, TimeUnit.MILLISECONDS);
|
|
||||||
} else {
|
|
||||||
pl.getProxy().getScheduler().schedule(pl, this::reloadServers, pl.config.getInt("wait-to-load-servers-delay"), TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns all servers
|
|
||||||
*/
|
|
||||||
public List<QueueServer> getServers() {
|
|
||||||
return servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name of all servers and groups
|
|
||||||
* @return The names of all servers and groups
|
|
||||||
*/
|
|
||||||
public List<String> getServerNames() {
|
|
||||||
List<String> names = new ArrayList<>();
|
|
||||||
for(QueueServer s : servers) {
|
|
||||||
names.add(s.getName());
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int sendId = -1;
|
|
||||||
int updateId = -1;
|
|
||||||
int messagerId = -1;
|
|
||||||
int actionbarId = -1;
|
|
||||||
int srvRefId = -1;
|
|
||||||
int queueEventId = -1;
|
|
||||||
/**
|
|
||||||
* Clears all intervals and re-makes them
|
|
||||||
*/
|
|
||||||
public void reloadIntervals() {
|
|
||||||
if(sendId != -1) {
|
|
||||||
try {
|
|
||||||
pl.getProxy().getScheduler().cancel(sendId);
|
|
||||||
} catch(IllegalArgumentException ignored) {}
|
|
||||||
sendId = -1;
|
|
||||||
}
|
|
||||||
if(updateId != -1) {
|
|
||||||
try {
|
|
||||||
pl.getProxy().getScheduler().cancel(updateId);
|
|
||||||
} catch(IllegalArgumentException ignored) {}
|
|
||||||
updateId = -1;
|
|
||||||
}
|
|
||||||
if(messagerId != -1) {
|
|
||||||
try {
|
|
||||||
pl.getProxy().getScheduler().cancel(messagerId);
|
|
||||||
} catch(IllegalArgumentException ignored) {}
|
|
||||||
messagerId = -1;
|
|
||||||
}
|
|
||||||
if(actionbarId != -1) {
|
|
||||||
try {
|
|
||||||
pl.getProxy().getScheduler().cancel(actionbarId);
|
|
||||||
} catch(IllegalArgumentException ignored) {}
|
|
||||||
actionbarId = -1;
|
|
||||||
}
|
|
||||||
if(srvRefId != -1) {
|
|
||||||
try {
|
|
||||||
pl.getProxy().getScheduler().cancel(srvRefId);
|
|
||||||
} catch(IllegalArgumentException ignored) {}
|
|
||||||
srvRefId = -1;
|
|
||||||
}
|
|
||||||
if(queueEventId != -1) {
|
|
||||||
try {
|
|
||||||
pl.getProxy().getScheduler().cancel(queueEventId);
|
|
||||||
} catch(IllegalArgumentException ignored) {}
|
|
||||||
queueEventId = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
queueEventId = pl.getProxy().getScheduler().schedule(pl, this::sendQueueEvents, 2, 2, TimeUnit.SECONDS).getId();
|
|
||||||
|
|
||||||
sendId = pl.getProxy().getScheduler().schedule(pl, this::sendPlayers, 2, Math.round(pl.timeBetweenPlayers*1000), TimeUnit.MILLISECONDS).getId();
|
|
||||||
|
|
||||||
updateId = pl.getProxy().getScheduler().schedule(pl, this::updateServers, 0, Math.max(Math.round(pl.timeBetweenPlayers), 2), TimeUnit.SECONDS).getId();
|
|
||||||
//pl.getLogger().info("Time: "+pl.timeBetweenPlayers);
|
|
||||||
|
|
||||||
messagerId = pl.getProxy().getScheduler().schedule(pl, this::sendMessages, 0, pl.getConfig().getInt("message-time"), TimeUnit.SECONDS).getId();
|
|
||||||
actionbarId = pl.getProxy().getScheduler().schedule(pl, this::sendActionBars, 0, 2, TimeUnit.SECONDS).getId();
|
|
||||||
|
|
||||||
if(pl.config.getInt("reload-servers-interval") > 0) {
|
|
||||||
srvRefId = pl.getProxy().getScheduler().schedule(pl, this::updateServers, pl.config.getInt("reload-servers-interval"), pl.config.getInt("reload-servers-interval"), TimeUnit.SECONDS).getId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the name of the server the player is queued for.
|
|
||||||
* If multiple servers are queued for, it will use the multi-server-queue-pick option in the config
|
|
||||||
* @param p The player
|
|
||||||
* @return The name of the server, the placeholder none message if not queued
|
|
||||||
*/
|
|
||||||
public String getQueuedName(ProxiedPlayer p) {
|
|
||||||
List<QueueServer> queued = findPlayerInQueue(p);
|
|
||||||
if(queued.size() <= 0) {
|
|
||||||
return msgs.getString("placeholders.queued.none");
|
|
||||||
}
|
|
||||||
QueueServer selected = queued.get(0);
|
|
||||||
|
|
||||||
if(pl.config.getString("multi-server-queue-pick").equalsIgnoreCase("last")) {
|
|
||||||
selected = queued.get(queued.size()-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return selected.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a single server the player is queued for. Depends on the multi-server-queue-pick option in the config
|
|
||||||
* @param p The player
|
|
||||||
* @return The server that was chosen that the player is queued for.
|
|
||||||
*/
|
|
||||||
public QueueServer getSingleServer(ProxiedPlayer p) {
|
|
||||||
List<QueueServer> queued = findPlayerInQueue(p);
|
|
||||||
if(queued.size() <= 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
QueueServer selected = queued.get(0);
|
|
||||||
|
|
||||||
if(pl.config.getString("multi-server-queue-pick").equalsIgnoreCase("last")) {
|
|
||||||
selected = queued.get(queued.size()-1);
|
|
||||||
}
|
|
||||||
return selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<QueueServer> servers = new ArrayList<>();
|
|
||||||
/**
|
|
||||||
* Checks servers that are in bungeecord and adds any it doesnt
|
|
||||||
* know about.
|
|
||||||
*
|
|
||||||
* Also creates/edits server groups
|
|
||||||
*/
|
|
||||||
public synchronized void reloadServers() {
|
|
||||||
if(pl.config == null) {
|
|
||||||
pl.getLogger().warning("[MAN] Config is null");
|
|
||||||
}
|
|
||||||
Map<String, ServerInfo> svs = ProxyServer.getInstance().getServers();
|
|
||||||
for(String name : svs.keySet()) {
|
|
||||||
if(findServer(name) != null) continue;
|
|
||||||
ServerInfo info = svs.get(name);
|
|
||||||
//pl.getLogger().info("Adding server "+name);
|
|
||||||
servers.add(new QueueServer(name, info));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> groupsraw = pl.config.getStringList("server-groups");
|
|
||||||
for(String groupraw : groupsraw) {
|
|
||||||
if(groupraw.isEmpty()) {
|
|
||||||
pl.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(getServer(groupname) != null) {
|
|
||||||
pl.getLogger().warning("The name of a group ('"+groupname+"') cannot be the same as the name of a server!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ServerInfo> servers = new ArrayList<>();
|
|
||||||
|
|
||||||
for(String serverraw : serversraw) {
|
|
||||||
ServerInfo si = svs.get(serverraw);
|
|
||||||
if(si == null) {
|
|
||||||
pl.getLogger().warning("Could not find server named '"+serverraw+"' in servergroup '"+groupname+"'!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
servers.add(si);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(servers.size() == 0) {
|
|
||||||
pl.getLogger().warning("Server group '"+groupname+"' has no servers! Ignoring it.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.servers.add(new QueueServer(groupname, servers));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends actionbar updates to all players in all queues with their
|
|
||||||
* position in the queue and time remaining
|
|
||||||
*/
|
|
||||||
public synchronized void sendActionBars() {
|
|
||||||
if(!pl.getConfig().getBoolean("send-actionbar")) return;
|
|
||||||
|
|
||||||
for(ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
|
|
||||||
QueueServer s = this.getSingleServer(p);
|
|
||||||
|
|
||||||
if(s == null) continue;
|
|
||||||
List<ProxiedPlayer> plys = s.getQueue();
|
|
||||||
int pos = plys.indexOf(p)+1;
|
|
||||||
if(pos == 0) {
|
|
||||||
plys.remove(p);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int len = plys.size();
|
|
||||||
if(!s.isJoinable(p)) {
|
|
||||||
|
|
||||||
String status = s.getStatusString(p);
|
|
||||||
|
|
||||||
|
|
||||||
p.sendMessage(ChatMessageType.ACTION_BAR, msgs.getBC("spigot.actionbar.offline",
|
|
||||||
"POS:"+pos,
|
|
||||||
"LEN:"+len,
|
|
||||||
"SERVER:"+pl.aliases.getAlias(s.getName()),
|
|
||||||
"STATUS:"+status));
|
|
||||||
} else {
|
|
||||||
int time = (int) Math.round(pos*pl.timeBetweenPlayers);
|
|
||||||
int min = (int) Math.floor((time) / (60.0));
|
|
||||||
int sec = (int) Math.floor((time % (60.0)));
|
|
||||||
String timeStr;
|
|
||||||
if(min <= 0) {
|
|
||||||
timeStr = msgs.getString("format.time.secs")
|
|
||||||
.replaceAll("\\{m}", "0")
|
|
||||||
.replaceAll("\\{s}", sec+"");
|
|
||||||
} else {
|
|
||||||
timeStr = msgs.getString("format.time.mins")
|
|
||||||
.replaceAll("\\{m}", min+"")
|
|
||||||
.replaceAll("\\{s}", sec+"");
|
|
||||||
}
|
|
||||||
p.sendMessage(ChatMessageType.ACTION_BAR, msgs.getBC("spigot.actionbar.online",
|
|
||||||
"POS:"+pos,
|
|
||||||
"LEN:"+len,
|
|
||||||
"SERVER:"+pl.aliases.getAlias(s.getName()),
|
|
||||||
"TIME:"+timeStr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public synchronized void sendQueueEvents() {
|
|
||||||
for (QueueServer s : servers) {
|
|
||||||
for (ProxiedPlayer player : s.getQueue()) {
|
|
||||||
if (player == null) continue;
|
|
||||||
if (!player.isConnected()) continue;
|
|
||||||
BungeeUtils.sendCustomData(player, "inqueueevent", "true");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the message to the player updating them on their position in the queue
|
|
||||||
* along with their time remaining
|
|
||||||
*/
|
|
||||||
public synchronized void sendMessages() {
|
|
||||||
for(QueueServer s : servers) {
|
|
||||||
List<ProxiedPlayer> plys = s.getQueue();
|
|
||||||
Iterator<ProxiedPlayer> it = plys.iterator();
|
|
||||||
while(it.hasNext()) {
|
|
||||||
ProxiedPlayer ply = it.next();
|
|
||||||
int pos = plys.indexOf(ply)+1;
|
|
||||||
if(pos == 0) {
|
|
||||||
it.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
sendMessage(ply, s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Sends a status message to a player
|
|
||||||
* @param ply The player to send the message to
|
|
||||||
* @param s The QueueServer the message should be about
|
|
||||||
*/
|
|
||||||
public synchronized void sendMessage(ProxiedPlayer ply, QueueServer s) {
|
|
||||||
List<ProxiedPlayer> plys = s.getQueue();
|
|
||||||
int pos = plys.indexOf(ply)+1;
|
|
||||||
if(pos == 0) return;
|
|
||||||
int len = plys.size();
|
|
||||||
if(!s.isJoinable(ply)) {
|
|
||||||
|
|
||||||
String status = s.getStatusString(ply);
|
|
||||||
|
|
||||||
if(status.isEmpty()) return;
|
|
||||||
|
|
||||||
ply.sendMessage(msgs.getBC("status.offline.base",
|
|
||||||
"STATUS:"+status,
|
|
||||||
"POS:"+pos,
|
|
||||||
"LEN:"+len,
|
|
||||||
"SERVER:"+pl.aliases.getAlias(s.getName())
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
if(msgs.getString("spigot.actionbar.offline").isEmpty()) return;
|
|
||||||
int time = (int) Math.round(pos*pl.timeBetweenPlayers);
|
|
||||||
int min = (int) Math.floor((time) / (60.0));
|
|
||||||
int sec = (int) Math.floor((time % (60.0)));
|
|
||||||
String timeStr;
|
|
||||||
if(min <= 0) {
|
|
||||||
timeStr = msgs.getString("format.time.secs")
|
|
||||||
.replaceAll("\\{m}", "0")
|
|
||||||
.replaceAll("\\{s}", sec+"");
|
|
||||||
} else {
|
|
||||||
timeStr = msgs.getString("format.time.mins")
|
|
||||||
.replaceAll("\\{m}", min+"")
|
|
||||||
.replaceAll("\\{s}", sec+"");
|
|
||||||
}
|
|
||||||
ply.sendMessage(msgs.getBC("status.online.base",
|
|
||||||
"TIME:"+timeStr,
|
|
||||||
"POS:"+pos,
|
|
||||||
"LEN:"+len,
|
|
||||||
"SERVER:"+pl.aliases.getAlias(s.getName())
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find a server by name
|
|
||||||
* @param name Name of the server
|
|
||||||
* @return The server if it exists (otherwise null)
|
|
||||||
*/
|
|
||||||
public QueueServer findServer(String name) {
|
|
||||||
for(QueueServer server : servers) {
|
|
||||||
if(server == null) continue;
|
|
||||||
if(server.getName().equalsIgnoreCase(name)) {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates info about servers.
|
|
||||||
*/
|
|
||||||
public synchronized void updateServers() {
|
|
||||||
for (QueueServer server : servers) {
|
|
||||||
server.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the ideal server in a server group.
|
|
||||||
* @param s The group to check
|
|
||||||
* @param p The player to check
|
|
||||||
* @return the ideal server
|
|
||||||
*/
|
|
||||||
public ServerInfo getIdealServer(QueueServer s, ProxiedPlayer p) {
|
|
||||||
HashMap<ServerInfo, ServerPing> serverInfos = s.getLastPings();
|
|
||||||
ServerInfo selected = null;
|
|
||||||
int selectednum = 0;
|
|
||||||
if(serverInfos.keySet().size() == 1) {
|
|
||||||
selected = serverInfos.keySet().iterator().next();
|
|
||||||
} else {
|
|
||||||
for(ServerInfo si : serverInfos.keySet()) {
|
|
||||||
ServerPing sp = serverInfos.get(si);
|
|
||||||
if(sp == null) continue;
|
|
||||||
if(sp.getPlayers() == null) continue;
|
|
||||||
int online = sp.getPlayers().getOnline();
|
|
||||||
if(selected == null) {
|
|
||||||
selected = si;
|
|
||||||
selectednum = online;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(selectednum > online && findServer(si.getName()).isJoinable(p)) {
|
|
||||||
selected = si;
|
|
||||||
selectednum = online;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(selected == null && serverInfos.size() > 0) {
|
|
||||||
selected = serverInfos.keySet().iterator().next();
|
|
||||||
}
|
|
||||||
if(selected == null) {
|
|
||||||
pl.getLogger().warning("Unable to find ideal server, using random server from group.");
|
|
||||||
int r = GenUtils.randomInt(0, s.getInfos().size()-1);
|
|
||||||
selected = s.getInfos().get(r);
|
|
||||||
}
|
|
||||||
return selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to send the first player in all queues
|
|
||||||
*/
|
|
||||||
public void sendPlayers() {
|
|
||||||
sendPlayers(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<ProxiedPlayer, Long> sendingNowAntiSpam = new HashMap<>();
|
|
||||||
HashMap<ProxiedPlayer, Integer> sendingAttempts = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to send the first player in this queue
|
|
||||||
* @param server The server to send the first player in the queue. null for all servers.
|
|
||||||
*/
|
|
||||||
public void sendPlayers(String server) {
|
|
||||||
for(QueueServer s : servers) {
|
|
||||||
String name = s.getName();
|
|
||||||
if(server != null && !server.equals(name)) continue;
|
|
||||||
if(!s.isOnline()) continue;
|
|
||||||
if(s.getQueue().size() <= 0) continue;
|
|
||||||
|
|
||||||
if(pl.config.getBoolean("send-all-when-back-online") && s.justWentOnline() && s.isOnline()) {
|
|
||||||
|
|
||||||
|
|
||||||
for(ProxiedPlayer p : s.getQueue()) {
|
|
||||||
|
|
||||||
if(s.isFull() && !p.hasPermission("ajqueue.joinfull")) continue;
|
|
||||||
|
|
||||||
ServerInfo selected = getIdealServer(s, p);
|
|
||||||
if(selected == null) {
|
|
||||||
pl.getLogger().severe("Could not find ideal server for server/group '"+s.getName()+"'!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.sendMessage(msgs.getBC("status.sending-now", "SERVER:"+pl.aliases.getAlias(name)));
|
|
||||||
p.connect(selected);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProxiedPlayer nextplayer = s.getQueue().get(0);
|
|
||||||
if(nextplayer == null) {
|
|
||||||
if(s.getQueue().size() > 0) {
|
|
||||||
s.getQueue().remove(0);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!s.canAccess(nextplayer)) continue;
|
|
||||||
|
|
||||||
|
|
||||||
if(s.getQueue().size() <= 0) continue;
|
|
||||||
while(!nextplayer.isConnected()) {
|
|
||||||
s.getQueue().remove(nextplayer);
|
|
||||||
if(s.getQueue().size() <= 0) break;
|
|
||||||
nextplayer = s.getQueue().get(0);
|
|
||||||
}
|
|
||||||
while(nextplayer.getServer().getInfo().getName().equals(s.getName())) {
|
|
||||||
s.getQueue().remove(nextplayer);
|
|
||||||
if(s.getQueue().size() <= 0) break;
|
|
||||||
nextplayer = s.getQueue().get(0);
|
|
||||||
}
|
|
||||||
if(s.getQueue().size() <= 0) continue;
|
|
||||||
if(s.isFull() && !nextplayer.hasPermission("ajqueue.joinfull")) continue;
|
|
||||||
|
|
||||||
if(pl.config.getBoolean("enable-bypasspaused-permission")) {
|
|
||||||
if(s.isPaused() && !nextplayer.hasPermission("ajqueue.bypasspaused")) continue;
|
|
||||||
} else if(s.isPaused()) { continue; }
|
|
||||||
|
|
||||||
|
|
||||||
int tries = sendingAttempts.get(nextplayer) == null ? 0 : sendingAttempts.get(nextplayer);
|
|
||||||
int maxTries = pl.config.getInt("max-tries");
|
|
||||||
if(tries >= maxTries && maxTries > 0) {
|
|
||||||
s.getQueue().remove(nextplayer);
|
|
||||||
sendingAttempts.remove(nextplayer);
|
|
||||||
nextplayer.sendMessage(msgs.getBC("max-tries-reached", "SERVER:"+pl.aliases.getAlias(s.getName())));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
tries++;
|
|
||||||
sendingAttempts.put(nextplayer, tries);
|
|
||||||
|
|
||||||
if(!sendingNowAntiSpam.containsKey(nextplayer)) {
|
|
||||||
sendingNowAntiSpam.put(nextplayer, (long) 0);
|
|
||||||
}
|
|
||||||
if(System.currentTimeMillis() - sendingNowAntiSpam.get(nextplayer) >= 5000) {
|
|
||||||
nextplayer.sendMessage(msgs.getBC("status.sending-now", "SERVER:"+pl.aliases.getAlias(s.getName())));
|
|
||||||
sendingNowAntiSpam.put(nextplayer, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ServerInfo selected = getIdealServer(s, nextplayer);
|
|
||||||
if(selected == null) {
|
|
||||||
pl.getLogger().severe("Could not find ideal server for server/group '"+s.getName()+"'!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
nextplayer.connect(selected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a player to the queue for a server
|
|
||||||
* @param p The player
|
|
||||||
* @param s The name of the server
|
|
||||||
*/
|
|
||||||
public synchronized void addToQueue(ProxiedPlayer p, String s) {
|
|
||||||
if(p == null || s == null) return;
|
|
||||||
QueueServer server = findServer(s);
|
|
||||||
if(server == null) {
|
|
||||||
p.sendMessage(msgs.getBC("errors.server-not-exist"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!p.isConnected()) return;
|
|
||||||
|
|
||||||
if(pl.config.getBoolean("joinfrom-server-permission") && !p.hasPermission("ajqueue.joinfrom."+p.getServer().getInfo().getName())) {
|
|
||||||
p.sendMessage(msgs.getBC("errors.deny-joining-from-server"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(server.isPaused() && pl.config.getBoolean("prevent-joining-paused")) {
|
|
||||||
p.sendMessage(msgs.getBC("errors.cant-join-paused", "SERVER:"+pl.aliases.getAlias(server.getName())));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(p.getServer().getInfo().getName().equals(s)) {
|
|
||||||
p.sendMessage(msgs.getBC("errors.already-connected", "SERVER:"+pl.aliases.getAlias(server.getName())));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<QueueServer> beforeQueues = findPlayerInQueue(p);
|
|
||||||
if(beforeQueues.size() > 0) {
|
|
||||||
if(beforeQueues.contains(server)) {
|
|
||||||
p.sendMessage(msgs.getBC("errors.already-queued"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!pl.config.getBoolean("allow-multiple-queues")) {
|
|
||||||
p.sendMessage(msgs.getBC("status.left-last-queue", "SERVER:"+pl.aliases.getAlias(server.getName())));
|
|
||||||
for(QueueServer ser : beforeQueues) {
|
|
||||||
ser.getQueue().remove(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ProxiedPlayer> list = server.getQueue();
|
|
||||||
if(list.contains(p)) {
|
|
||||||
int pos = list.indexOf(p)+1;
|
|
||||||
int len = list.size();
|
|
||||||
p.sendMessage(msgs.getBC("errors.already-queued",
|
|
||||||
"POS:"+pos,
|
|
||||||
"LEN:"+len
|
|
||||||
));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(pl.isp) {
|
|
||||||
Logic.priorityLogic(server.getQueue(), s, p);
|
|
||||||
} else {
|
|
||||||
if((p.hasPermission("ajqueue.priority") || p.hasPermission("ajqueue.serverpriority."+s)) && list.size() > 0) {
|
|
||||||
//p.sendMessage(Main.formatMessage("in priority"));
|
|
||||||
int i = 0;
|
|
||||||
for(ProxiedPlayer ply : list) {
|
|
||||||
if(!(ply.hasPermission("ajqueue.priority") || ply.hasPermission("ajqueue.serverpriority."+s))) {
|
|
||||||
//p.sendMessage(Main.formatMessage("Adding beind: "+i));
|
|
||||||
list.add(i, p);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
//p.sendMessage(Main.formatMessage("after loop"));
|
|
||||||
if(list.size() == 0) {
|
|
||||||
list.add(p);
|
|
||||||
} else if(!list.contains(p)) {
|
|
||||||
list.add(p);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//p.sendMessage(Main.formatMessage("normal add"));
|
|
||||||
list.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int pos = list.indexOf(p)+1;
|
|
||||||
int len = list.size();
|
|
||||||
|
|
||||||
|
|
||||||
boolean sendInstant = pl.config.getStringList("send-instantly").contains(server.getName()) || server.isJoinable(p);
|
|
||||||
boolean sendInstantp = list.size() <= 1 && server.canAccess(p);
|
|
||||||
boolean timeGood = !pl.config.getBoolean("check-last-player-sent-time") || System.currentTimeMillis() - server.getLastSentTime() > Math.floor(pl.getConfig().getDouble("wait-time") * 1000);
|
|
||||||
|
|
||||||
if((sendInstant && (sendInstantp && timeGood))) {
|
|
||||||
sendPlayers(s);
|
|
||||||
//p.sendMessage(Main.formatMessage("sending instant"));
|
|
||||||
BaseComponent[] m = msgs.getBC("status.now-in-empty-queue", "POS:"+pos, "LEN:"+len, "SERVER:"+pl.aliases.getAlias(s));
|
|
||||||
if(TextComponent.toPlainText(m).length() > 0) {
|
|
||||||
p.sendMessage(m);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
p.sendMessage(msgs.getBC("status.now-in-queue",
|
|
||||||
"POS:"+pos,
|
|
||||||
"LEN:"+len,
|
|
||||||
"SERVER:"+pl.aliases.getAlias(server.getName()),
|
|
||||||
"SERVERNAME:"+server.getName()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
//p.sendMessage(Main.formatMessage(sendInstant+" && ("+sendInstantp+" && " + timeGood+")"));
|
|
||||||
|
|
||||||
BungeeUtils.sendCustomData(p, "position", pos+"");
|
|
||||||
BungeeUtils.sendCustomData(p, "positionof", len+"");
|
|
||||||
BungeeUtils.sendCustomData(p, "queuename", pl.aliases.getAlias(s));
|
|
||||||
BungeeUtils.sendCustomData(p, "inqueue", "true");
|
|
||||||
BungeeUtils.sendCustomData(p, "inqueueevent", "true");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds which servers the player is queued for
|
|
||||||
* @param p The player to search for
|
|
||||||
* @return The servers the player is queued for.
|
|
||||||
*/
|
|
||||||
public List<QueueServer> findPlayerInQueue(ProxiedPlayer p) {
|
|
||||||
List<QueueServer> srs = new ArrayList<>();
|
|
||||||
for(QueueServer s : servers) {
|
|
||||||
if(s.getQueue().contains(p)) {
|
|
||||||
srs.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return srs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public QueueServer getServer(String name) {
|
|
||||||
return findServer(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,248 +0,0 @@
|
|||||||
package us.ajg0702.queue;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.Callback;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.ServerPing;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import us.ajg0702.utils.bungee.BungeeConfig;
|
|
||||||
import us.ajg0702.utils.bungee.BungeeMessages;
|
|
||||||
|
|
||||||
public class QueueServer {
|
|
||||||
|
|
||||||
String name;
|
|
||||||
List<ServerInfo> servers;
|
|
||||||
|
|
||||||
public QueueServer(String name, ServerInfo info) {
|
|
||||||
init(name, Collections.singletonList(info));
|
|
||||||
}
|
|
||||||
public QueueServer(String name, List<ServerInfo> infos) {
|
|
||||||
init(name, infos);
|
|
||||||
}
|
|
||||||
private void init(String name, List<ServerInfo> infos) {
|
|
||||||
if(Manager.getInstance() == null || Main.plugin.getConfig() == null) {
|
|
||||||
ProxyServer.getInstance().getLogger()
|
|
||||||
.warning("[ajQueue] Something is loading a QueueServer too early! The plugin hasnt fully loaded yet!");
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
this.servers = infos;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInfos(List<ServerInfo> infos) {
|
|
||||||
servers = infos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
public List<ServerInfo> getInfos() {
|
|
||||||
return servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
int offlineTime = 0;
|
|
||||||
boolean online = false;
|
|
||||||
int playercount = 0;
|
|
||||||
int maxplayers = 0;
|
|
||||||
long lastUpdate = -1;
|
|
||||||
HashMap<ServerInfo, ServerPing> pings = new HashMap<>();
|
|
||||||
public void update() {
|
|
||||||
pings = new HashMap<>();
|
|
||||||
for(final ServerInfo info : getInfos()) {
|
|
||||||
if(Main.plugin.getConfig().getBoolean("pinger-debug")) {
|
|
||||||
Main.plugin.getLogger().info("[pinger] ["+info.getName()+"] sending ping");
|
|
||||||
}
|
|
||||||
info.ping((result, error) -> {
|
|
||||||
if(Manager.getInstance() == null || Main.plugin.getConfig() == null) {
|
|
||||||
ProxyServer.getInstance().getLogger()
|
|
||||||
.warning("[ajQueue] Something used update() too early! The plugin hasnt fully loaded yet!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
boolean online = error == null;
|
|
||||||
BungeeConfig config = Main.plugin.getConfig();
|
|
||||||
|
|
||||||
if(config.getBoolean("pinger-debug")) {
|
|
||||||
if(error != null) {
|
|
||||||
ProxyServer.getInstance().getLogger().info("[ajQueue] [pinger] ["+name+"] Status: offline. Error: ");
|
|
||||||
error.printStackTrace();
|
|
||||||
} else {
|
|
||||||
ProxyServer.getInstance().getLogger().info("[ajQueue] [pinger] ["+name+"] Status: online. motd: "
|
|
||||||
+result.getDescriptionComponent()+" players:"+result.getPlayers());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pings.put(info, online ? result : null);
|
|
||||||
if(pings.size() == servers.size()) allDonePing();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatusString(ProxiedPlayer p) {
|
|
||||||
BungeeMessages msgs = Main.plugin.msgs;
|
|
||||||
|
|
||||||
if(getOfflineTime() > Main.plugin.getConfig().getInt("offline-time")) {
|
|
||||||
return msgs.getString("status.offline.offline");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isOnline()) {
|
|
||||||
return msgs.getString("status.offline.restarting");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isPaused()) {
|
|
||||||
return msgs.getString("status.offline.paused");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isFull()) {
|
|
||||||
return msgs.getString("status.offline.full");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(p != null && !canAccess(p)) {
|
|
||||||
return msgs.getString("status.offline.restricted");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return "Online";
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<ServerInfo, ServerPing> getLastPings() {
|
|
||||||
return pings;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void allDonePing() {
|
|
||||||
int onlineCount = 0;
|
|
||||||
playercount = 0;
|
|
||||||
maxplayers = 0;
|
|
||||||
for(ServerInfo info : pings.keySet()) {
|
|
||||||
ServerPing ping = pings.get(info);
|
|
||||||
if(ping == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
onlineCount++;
|
|
||||||
playercount += ping.getPlayers().getOnline();
|
|
||||||
maxplayers += ping.getPlayers().getMax();
|
|
||||||
}
|
|
||||||
online = onlineCount > 0;
|
|
||||||
|
|
||||||
if(lastUpdate == -1) {
|
|
||||||
lastUpdate = System.currentTimeMillis();
|
|
||||||
offlineTime = 0;
|
|
||||||
} else {
|
|
||||||
int timesincelast = (int) Math.round((System.currentTimeMillis() - lastUpdate*1.0)/1000);
|
|
||||||
lastUpdate = System.currentTimeMillis();
|
|
||||||
if(!online) {
|
|
||||||
offlineTime += timesincelast;
|
|
||||||
} else {
|
|
||||||
offlineTime = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOfflineTime() {
|
|
||||||
return offlineTime;
|
|
||||||
}
|
|
||||||
long lastOffline = 0;
|
|
||||||
public boolean isOnline() {
|
|
||||||
BungeeConfig config = Main.plugin.getConfig();
|
|
||||||
if(System.currentTimeMillis()-lastOffline <= (config.getInt("wait-after-online")*1000) && online) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(!online) {
|
|
||||||
lastOffline = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
return online;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean justWentOnline() {
|
|
||||||
BungeeConfig config = Main.plugin.getConfig();
|
|
||||||
return System.currentTimeMillis()-lastOffline <= (config.getDouble("wait-time")) && online;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFull() {
|
|
||||||
return playercount >= maxplayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
List<ProxiedPlayer> queue = new ArrayList<>();
|
|
||||||
public synchronized List<ProxiedPlayer> getQueue() {
|
|
||||||
return queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the player can access the server. (Bungeecord's restricted servers)
|
|
||||||
* @param ply The player
|
|
||||||
* @return if the player can join based on bungeecord's restricted servers system
|
|
||||||
*/
|
|
||||||
public boolean canAccess(ProxiedPlayer ply) {
|
|
||||||
if(ply == null) return true;
|
|
||||||
boolean ca = false;
|
|
||||||
for(ServerInfo si : servers) {
|
|
||||||
if(si.canAccess(ply)) {
|
|
||||||
ca = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ca;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
long lastSent = 0;
|
|
||||||
public long getLastSentTime() {
|
|
||||||
return lastSent;
|
|
||||||
}
|
|
||||||
public void setLastSentTime(long newLastSent) {
|
|
||||||
lastSent = newLastSent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
boolean whitelisted = false;
|
|
||||||
List<String> whitelistedplayers = new ArrayList<>();
|
|
||||||
public void setWhitelisted(boolean b) {
|
|
||||||
whitelisted = b;
|
|
||||||
}
|
|
||||||
public void setWhitelistedPlayers(List<String> plys) {
|
|
||||||
whitelistedplayers = plys;
|
|
||||||
}
|
|
||||||
public boolean getWhitelisted() {
|
|
||||||
return whitelisted;
|
|
||||||
}
|
|
||||||
public boolean isWhitelisted() {
|
|
||||||
return whitelisted;
|
|
||||||
}
|
|
||||||
public List<String> getWhitelistedPlayers() {
|
|
||||||
return whitelistedplayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the server is joinable as a player
|
|
||||||
* @param p The player
|
|
||||||
* @return If the player can join the server
|
|
||||||
*/
|
|
||||||
public boolean isJoinable(ProxiedPlayer p) {
|
|
||||||
return (!whitelisted || whitelistedplayers.contains(p.getName())) &&
|
|
||||||
this.isOnline() &&
|
|
||||||
this.canAccess(p) &&
|
|
||||||
!this.isFull() &&
|
|
||||||
!this.isPaused();
|
|
||||||
|
|
||||||
}
|
|
||||||
public String getJoinableDebug(ProxiedPlayer p) {
|
|
||||||
return "whitelist: "+(!whitelisted || whitelistedplayers.contains(p.getName())) + "\n" +
|
|
||||||
"online: "+this.isOnline() +"\n"+
|
|
||||||
"canaccess: "+this.canAccess(p) +"\n"+
|
|
||||||
"full: "+ !this.isFull() +"\n"+
|
|
||||||
"paused: "+!this.isPaused()+"\n"+
|
|
||||||
"- joinable: "+isJoinable(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
boolean paused = false;
|
|
||||||
public boolean isPaused() {
|
|
||||||
return paused;
|
|
||||||
}
|
|
||||||
public void setPaused(boolean to) {
|
|
||||||
paused = to;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
package us.ajg0702.queue.commands;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
import us.ajg0702.queue.Main;
|
|
||||||
import us.ajg0702.queue.Manager;
|
|
||||||
import us.ajg0702.queue.QueueServer;
|
|
||||||
import us.ajg0702.utils.bungee.BungeeMessages;
|
|
||||||
|
|
||||||
public class LeaveCommand extends Command {
|
|
||||||
Main plugin;
|
|
||||||
BungeeMessages msgs;
|
|
||||||
public LeaveCommand(Main pl) {
|
|
||||||
super("leavequeue", null, "leaveq");
|
|
||||||
this.plugin = pl;
|
|
||||||
msgs = BungeeMessages.getInstance();
|
|
||||||
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
|
||||||
if(!(sender instanceof ProxiedPlayer)) {
|
|
||||||
sender.sendMessage(msgs.getBC("errors.player-only"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Manager man = Manager.getInstance();
|
|
||||||
ProxiedPlayer p = (ProxiedPlayer) sender;
|
|
||||||
List<QueueServer> servers = man.findPlayerInQueue(p);
|
|
||||||
|
|
||||||
if(servers.size() == 0) {
|
|
||||||
p.sendMessage(msgs.getBC("commands.leave.no-queues"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(servers.size() == 1) {
|
|
||||||
servers.get(0).getQueue().remove(p);
|
|
||||||
p.sendMessage(msgs.getBC("commands.leave-queue", "SERVER:"+plugin.aliases.getAlias(servers.get(0).getName())));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(args.length <= 0) {
|
|
||||||
p.sendMessage(msgs.getBC("commands.leave.more-args", "QUEUES:"+getQueueList(servers)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String leaving = args[0];
|
|
||||||
QueueServer leavingsrv = man.getServer(leaving);
|
|
||||||
if(leavingsrv == null) {
|
|
||||||
p.sendMessage(msgs.getBC("commands.leave.not-queued", "QUEUES:"+getQueueList(servers)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(leavingsrv.getQueue().indexOf(p) == -1) {
|
|
||||||
p.sendMessage(msgs.getBC("commands.leave.not-queued", "QUEUES:"+getQueueList(servers)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
leavingsrv.getQueue().remove(p);
|
|
||||||
p.sendMessage(msgs.getBC("commands.leave-queue", "SERVER:"+plugin.aliases.getAlias(leavingsrv.getName())));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getQueueList(List<QueueServer> servers) {
|
|
||||||
StringBuilder queueList = new StringBuilder();
|
|
||||||
for(QueueServer server : servers) {
|
|
||||||
queueList.append(msgs.getString("commands.leave.queues-list-format").replaceAll("\\{NAME\\}", server.getName()));
|
|
||||||
}
|
|
||||||
if(queueList.length() > 2) {
|
|
||||||
queueList = new StringBuilder(queueList.substring(0, queueList.length() - 2));
|
|
||||||
}
|
|
||||||
return queueList.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
package us.ajg0702.queue.commands;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
import us.ajg0702.queue.Main;
|
|
||||||
import us.ajg0702.queue.Manager;
|
|
||||||
import us.ajg0702.queue.QueueServer;
|
|
||||||
import us.ajg0702.utils.bungee.BungeeMessages;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class ListCommand extends Command {
|
|
||||||
Main pl;
|
|
||||||
BungeeMessages msgs;
|
|
||||||
|
|
||||||
public ListCommand(Main pl) {
|
|
||||||
super("listqueues", null, "listq");
|
|
||||||
this.pl = pl;
|
|
||||||
msgs = BungeeMessages.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
|
||||||
if(!sender.hasPermission("ajqueue.listqueues")) {
|
|
||||||
sender.sendMessage(msgs.getBC("noperm"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProxiedPlayer spp = null;
|
|
||||||
if(sender instanceof ProxiedPlayer) {
|
|
||||||
spp = (ProxiedPlayer) sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<BaseComponent> m = new ArrayList<>(Arrays.asList(msgs.getBC("commands.listqueues.header")));
|
|
||||||
for(QueueServer s : Manager.getInstance().getServers()) {
|
|
||||||
String color = "&a";
|
|
||||||
if(!s.isOnline()) {
|
|
||||||
color = "&c";
|
|
||||||
} else if(!s.isJoinable(spp)) {
|
|
||||||
color = "&e";
|
|
||||||
}
|
|
||||||
|
|
||||||
m.addAll(Arrays.asList(TextComponent.fromLegacyText("\n")));
|
|
||||||
m.addAll(Arrays.asList(msgs.getBC("commands.listqueues.format",
|
|
||||||
"COLOR:" + msgs.color(color),
|
|
||||||
"NAME:" + s.getName(),
|
|
||||||
"COUNT:" + s.getQueue().size(),
|
|
||||||
"STATUS:" + s.getStatusString(spp)
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(m.toArray(new BaseComponent[m.size()-1]));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,267 +0,0 @@
|
|||||||
package us.ajg0702.queue.commands;
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.PatternReplacementResult;
|
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
|
||||||
import us.ajg0702.queue.Main;
|
|
||||||
import us.ajg0702.queue.Manager;
|
|
||||||
import us.ajg0702.queue.QueueServer;
|
|
||||||
import us.ajg0702.utils.bungee.BungeeMessages;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class ManageCommand extends Command implements TabExecutor {
|
|
||||||
|
|
||||||
Main pl;
|
|
||||||
BungeeMessages msgs;
|
|
||||||
|
|
||||||
public ManageCommand(Main pl) {
|
|
||||||
super("ajqueue", null, "ajq");
|
|
||||||
this.pl = pl;
|
|
||||||
msgs = BungeeMessages.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
|
||||||
if(args.length == 1) {
|
|
||||||
if(args[0].equalsIgnoreCase("reload")) {
|
|
||||||
if(!sender.hasPermission("ajqueue.reload")) {
|
|
||||||
sender.sendMessage(msgs.getBC("noperm"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
msgs.reload();
|
|
||||||
pl.getConfig().reload();
|
|
||||||
pl.timeBetweenPlayers = pl.getConfig().getDouble("wait-time");
|
|
||||||
Manager.getInstance().reloadIntervals();
|
|
||||||
Manager.getInstance().reloadServers();
|
|
||||||
pl.checkConfig();
|
|
||||||
sender.sendMessage(msgs.getBC("commands.reload"));
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
if(args[0].equalsIgnoreCase("list")) {
|
|
||||||
if(!sender.hasPermission("ajqueue.list")) {
|
|
||||||
sender.sendMessage(msgs.getBC("noperm"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int total = 0;
|
|
||||||
for(QueueServer server : Manager.getInstance().getServers()) {
|
|
||||||
|
|
||||||
Component msg = msgs.getComponent("list.format",
|
|
||||||
"SERVER:"+server.getName()
|
|
||||||
);
|
|
||||||
Component playerList = Component.empty();
|
|
||||||
List<ProxiedPlayer> players = server.getQueue();
|
|
||||||
boolean none = true;
|
|
||||||
for(ProxiedPlayer p : players) {
|
|
||||||
playerList = playerList.append(msgs.getComponent("list.playerlist",
|
|
||||||
"NAME:" + p.getDisplayName()
|
|
||||||
));
|
|
||||||
none = false;
|
|
||||||
}
|
|
||||||
if(none) {
|
|
||||||
playerList = playerList.append(msgs.getComponent("list.none"));
|
|
||||||
playerList = playerList.append(Component.text(", "));
|
|
||||||
}
|
|
||||||
Component finalPlayerList = playerList;
|
|
||||||
msg = msg.replaceText(b -> b.match(Pattern.compile("\\{LIST}")).replacement(finalPlayerList));
|
|
||||||
char[] commaCountString = PlainTextComponentSerializer.plainText().serialize(msg).toCharArray();
|
|
||||||
int commas = 0;
|
|
||||||
for(Character fChar : commaCountString) {
|
|
||||||
if(fChar == ',') commas++;
|
|
||||||
}
|
|
||||||
|
|
||||||
int finalCommas = commas;
|
|
||||||
msg = msg.replaceText(b -> b.match(",(?!.*,)").replacement("").condition((r, c, re) -> {
|
|
||||||
if(c == finalCommas) {
|
|
||||||
return PatternReplacementResult.REPLACE;
|
|
||||||
}
|
|
||||||
return PatternReplacementResult.CONTINUE;
|
|
||||||
}));
|
|
||||||
total += players.size();
|
|
||||||
msg = msg.replaceText(b -> b.match(Pattern.compile("\\{COUNT}")).replacement(players.size()+""));
|
|
||||||
sender.sendMessage(msgs.getBC(msg));
|
|
||||||
}
|
|
||||||
sender.sendMessage(msgs.getBC("list.total", "TOTAL:"+total));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(args[0].equalsIgnoreCase("p")) {
|
|
||||||
sender.sendMessage(Main.formatMessage(pl.isp()+""));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(args[0].equalsIgnoreCase("statusdebug")) {
|
|
||||||
QueueServer s = Manager.getInstance().getSingleServer((ProxiedPlayer) sender);
|
|
||||||
if(s == null) return;
|
|
||||||
sender.sendMessage(Main.formatMessage(s.getJoinableDebug((ProxiedPlayer) sender)));
|
|
||||||
}
|
|
||||||
if(args[0].equalsIgnoreCase("send")) {
|
|
||||||
if(!sender.hasPermission("ajqueue.send")) {
|
|
||||||
sender.sendMessage(msgs.getBC("noperm"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sender.sendMessage(Main.formatMessage("/ajQueue send <player> <server>"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(args[0].equalsIgnoreCase("version")) {
|
|
||||||
sender.sendMessage(Main.formatMessage(pl.getDescription().getVersion()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(args[0].equalsIgnoreCase("pause")) {
|
|
||||||
if(!sender.hasPermission("ajqueue.pause")) {
|
|
||||||
sender.sendMessage(msgs.getBC("noperm"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sender.sendMessage(msgs.getBC("commands.pause.more-args"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(args.length == 2) {
|
|
||||||
if(args[0].equalsIgnoreCase("pause")) {
|
|
||||||
if(!sender.hasPermission("ajqueue.pause")) {
|
|
||||||
sender.sendMessage(msgs.getBC("noperm"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!Manager.getInstance().getServerNames().contains(args[1])) {
|
|
||||||
sender.sendMessage(msgs.getBC("errors.server-not-exist", "SERVER:"+args[1]));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QueueServer srv = Manager.getInstance().findServer(args[1]);
|
|
||||||
if(srv == null) {
|
|
||||||
sender.sendMessage(msgs.getBC("commands.pause.no-server", "SERVER:"+args[1]));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
srv.setPaused(!srv.isPaused());
|
|
||||||
sender.sendMessage(msgs.getBC("commands.pause.success",
|
|
||||||
"SERVER:"+srv.getName(),
|
|
||||||
"PAUSED:"+msgs.getString("commands.pause.paused."+srv.isPaused())
|
|
||||||
));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(args[0].equalsIgnoreCase("send")) {
|
|
||||||
if(!sender.hasPermission("ajqueue.send")) {
|
|
||||||
sender.sendMessage(msgs.getBC("noperm"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sender.sendMessage(Main.formatMessage("/ajQueue send <player> <server>"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(args.length == 3) {
|
|
||||||
if(args[0].equalsIgnoreCase("pause")) {
|
|
||||||
if(!sender.hasPermission("ajqueue.pause")) {
|
|
||||||
sender.sendMessage(msgs.getBC("noperm"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!Manager.getInstance().getServerNames().contains(args[1])) {
|
|
||||||
sender.sendMessage(msgs.getBC("commands.pause.no-server", "SERVER:"+args[1]));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QueueServer srv = Manager.getInstance().findServer(args[1]);
|
|
||||||
if(srv == null) {
|
|
||||||
sender.sendMessage(msgs.getBC("commands.pause.no-server", "SERVER:"+args[1]));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
srv.setPaused(args[2].equalsIgnoreCase("on") || args[2].equalsIgnoreCase("true"));
|
|
||||||
sender.sendMessage(msgs.getBC("commands.pause.success",
|
|
||||||
"SERVER:"+srv.getName(),
|
|
||||||
"PAUSED:"+msgs.getString("commands.pause.paused."+srv.isPaused())
|
|
||||||
));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(args[0].equalsIgnoreCase("send")) {
|
|
||||||
if(!sender.hasPermission("ajqueue.send")) {
|
|
||||||
sender.sendMessage(msgs.getBC("noperm"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Manager.getInstance().getServer(args[2]) == null) {
|
|
||||||
sender.sendMessage(msgs.getBC("errors.server-not-exist", "SERVER:"+args[2]));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> playerNames = getNameList(true);
|
|
||||||
if(playerNames.contains(args[1].toLowerCase())) {
|
|
||||||
|
|
||||||
ProxiedPlayer ply = pl.getProxy().getPlayer(args[1]);
|
|
||||||
Manager.getInstance().addToQueue(ply, args[2]);
|
|
||||||
sender.sendMessage(msgs.getBC("send",
|
|
||||||
"PLAYER:"+ply.getDisplayName(),
|
|
||||||
"SERVER:"+args[2])
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
} else if(pl.getProxy().getServers().containsKey(args[1])) {
|
|
||||||
|
|
||||||
ServerInfo from = pl.getProxy().getServerInfo(args[1]);
|
|
||||||
if(from == null) {
|
|
||||||
sender.sendMessage(msgs.getBC("errors.server-not-exist", "SERVER:"+args[1]));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<ProxiedPlayer> players = new ArrayList<>(from.getPlayers());
|
|
||||||
for(ProxiedPlayer ply : players) {
|
|
||||||
Manager.getInstance().addToQueue(ply, args[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(msgs.getBC("send", "PLAYER:"+args[1], "SERVER:"+args[2]));
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(msgs.getBC("commands.send.player-not-found"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(Main.formatMessage("/ajqueue <reload|list|send|pause>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getNameList(boolean lowercase) {
|
|
||||||
List<String> playerNames = new ArrayList<>();
|
|
||||||
for(ProxiedPlayer ply : pl.getProxy().getPlayers()) {
|
|
||||||
if(ply == null || !ply.isConnected()) continue;
|
|
||||||
if(lowercase) {
|
|
||||||
playerNames.add(ply.getName().toLowerCase());
|
|
||||||
} else {
|
|
||||||
playerNames.add(ply.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return playerNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
|
||||||
if(args.length == 1) {
|
|
||||||
return Arrays.asList("reload", "list", "send", "pause");
|
|
||||||
}
|
|
||||||
if(args.length == 2) {
|
|
||||||
if(args[0].equalsIgnoreCase("send")) {
|
|
||||||
List<String> options = new ArrayList<>(pl.getProxy().getServers().keySet());
|
|
||||||
options.addAll(getNameList(false));
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
if(args[0].equalsIgnoreCase("pause")) {
|
|
||||||
return Manager.getInstance().getServerNames();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(args.length == 3) {
|
|
||||||
if(args[0].equalsIgnoreCase("send")) {
|
|
||||||
return Manager.getInstance().getServerNames();
|
|
||||||
}
|
|
||||||
if(args[0].equalsIgnoreCase("pause")) {
|
|
||||||
return Arrays.asList("on", "off", "true", "false");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package us.ajg0702.queue.commands;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
|
||||||
import us.ajg0702.queue.Main;
|
|
||||||
import us.ajg0702.queue.Manager;
|
|
||||||
import us.ajg0702.utils.bungee.BungeeMessages;
|
|
||||||
|
|
||||||
public class MoveCommand extends Command implements TabExecutor {
|
|
||||||
Main plugin;
|
|
||||||
BungeeMessages msgs;
|
|
||||||
public MoveCommand(Main pl) {
|
|
||||||
super("move", null, "queue", "server", "joinqueue", "joinq");
|
|
||||||
this.plugin = pl;
|
|
||||||
msgs = BungeeMessages.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
|
||||||
if(!(sender instanceof ProxiedPlayer)) {
|
|
||||||
sender.sendMessage(msgs.getBC("errors.player-only"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ProxiedPlayer p = (ProxiedPlayer) sender;
|
|
||||||
|
|
||||||
if(args.length > 0) {
|
|
||||||
if(plugin.getConfig().getBoolean("require-permission") && !p.hasPermission("ajqueue.queue."+args[0])) {
|
|
||||||
sender.sendMessage(msgs.getBC("noperm"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Manager.getInstance().addToQueue(p, args[0]);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(msgs.getBC("commands.joinqueue.usage"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
|
||||||
if(!plugin.getConfig().getBoolean("tab-complete-queues")) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
if(args.length == 1) {
|
|
||||||
return Manager.getInstance().getServerNames();
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package us.ajg0702.queue.spigot;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
|
|
||||||
Main pl;
|
|
||||||
public Commands(Main pl) {
|
|
||||||
this.pl = pl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
Player player = null;
|
|
||||||
if(sender instanceof Player) {
|
|
||||||
player = (Player) sender;
|
|
||||||
}
|
|
||||||
if(command.getName().equals("leavequeue")) {
|
|
||||||
if(player == null) return true;
|
|
||||||
StringBuilder arg = new StringBuilder();
|
|
||||||
for(String a : args) {
|
|
||||||
arg.append(" ");
|
|
||||||
arg.append(a);
|
|
||||||
}
|
|
||||||
pl.sendMessage(player, "leavequeue", arg.toString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(args.length < 1) return false;
|
|
||||||
|
|
||||||
String srvname = args[0];
|
|
||||||
|
|
||||||
if(args.length > 1) {
|
|
||||||
pl.getLogger().info("Sending "+args[0]+" to queue");
|
|
||||||
if(!sender.hasPermission("ajqueue.send")) {
|
|
||||||
sender.sendMessage(color("&cYou do not have permission to do this!"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Player tply = Bukkit.getPlayer(args[0]);
|
|
||||||
if(tply == null) {
|
|
||||||
sender.sendMessage(color("&cCannot find that player!"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
player = tply;
|
|
||||||
srvname = args[1];
|
|
||||||
}
|
|
||||||
if(pl.config.getBoolean("send-queue-commands-in-batches")) {
|
|
||||||
pl.queuebatch.put(player, srvname);
|
|
||||||
} else {
|
|
||||||
pl.sendMessage(player, "queue", srvname);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String color(String txt) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', txt);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
package us.ajg0702.queue.spigot;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
public class Config {
|
|
||||||
File f;
|
|
||||||
YamlConfiguration yml;
|
|
||||||
|
|
||||||
JavaPlugin pl;
|
|
||||||
|
|
||||||
|
|
||||||
public boolean getBoolean(String key) {
|
|
||||||
return yml.getBoolean(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Config(JavaPlugin pl) {
|
|
||||||
this.pl = pl;
|
|
||||||
f = new File(pl.getDataFolder(), "config.yml");
|
|
||||||
if(!f.exists()) {
|
|
||||||
if(!Files.exists(pl.getDataFolder().toPath())) {
|
|
||||||
try {
|
|
||||||
Files.createDirectory(pl.getDataFolder().toPath());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
PrintWriter writer = new PrintWriter(pl.getDataFolder()+File.separator+"config.yml", "UTF-8");
|
|
||||||
String[] lines = getDefaultConfig().split("\n");
|
|
||||||
for(String line : lines) {
|
|
||||||
writer.println(line);
|
|
||||||
|
|
||||||
}
|
|
||||||
writer.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
yml = YamlConfiguration.loadConfiguration(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDefaultConfig() {
|
|
||||||
return "# This is the config for the spigot side.\n"
|
|
||||||
+ "# You can find more settings in the config of bungee.\n"
|
|
||||||
+ "\n\n"
|
|
||||||
+ "# Should we send queue requests from commands in batches?\n"
|
|
||||||
+ "# Enable this if you have issues with players sometimes not executing commands correctly\n"
|
|
||||||
+ "# Note though that it could delay queue commands by up to 1 second!\n"
|
|
||||||
+ "send-queue-commands-in-batches: false";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,183 +0,0 @@
|
|||||||
package us.ajg0702.queue.spigot;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
|
|
||||||
import us.ajg0702.queue.spigot.utils.VersionSupport;
|
|
||||||
|
|
||||||
public class Main extends JavaPlugin implements PluginMessageListener,Listener {
|
|
||||||
|
|
||||||
boolean papi = false;
|
|
||||||
Placeholders placeholders;
|
|
||||||
|
|
||||||
Config config;
|
|
||||||
|
|
||||||
public void onEnable() {
|
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, "ajqueue:tospigot", this);
|
|
||||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "ajqueue:tobungee");
|
|
||||||
|
|
||||||
this.getCommand("move").setExecutor(new Commands(this));
|
|
||||||
this.getCommand("leavequeue").setExecutor(new Commands(this));
|
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(this, this);
|
|
||||||
|
|
||||||
papi = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
|
||||||
|
|
||||||
if(papi) {
|
|
||||||
placeholders = new Placeholders(this);
|
|
||||||
placeholders.register();
|
|
||||||
getLogger().info("Registered PlaceholderAPI placeholders");
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if(Bukkit.getOnlinePlayers().size() <= 0 || queuebatch.size() <= 0) return;
|
|
||||||
String msg = "";
|
|
||||||
for(Player p : queuebatch.keySet()) {
|
|
||||||
if(p == null || !p.isOnline()) continue;
|
|
||||||
msg += p.getName()+":"+queuebatch.get(p)+",";
|
|
||||||
}
|
|
||||||
if(msg.length() > 1) {
|
|
||||||
msg = msg.substring(0, msg.length()-1);
|
|
||||||
}
|
|
||||||
queuebatch.clear();
|
|
||||||
sendMessage("massqueue", msg);
|
|
||||||
}
|
|
||||||
}, 2*20, 20);
|
|
||||||
|
|
||||||
config = new Config(this);
|
|
||||||
|
|
||||||
getLogger().info("Spigot side enabled! v"+getDescription().getVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<Player, String> queuebatch = new HashMap<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
|
||||||
if (!channel.equals("ajqueue:tospigot")) return;
|
|
||||||
|
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
|
||||||
|
|
||||||
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")) {
|
|
||||||
String playername = in.readUTF();
|
|
||||||
Player p = Bukkit.getPlayer(playername);
|
|
||||||
if(p == null) return;
|
|
||||||
QueueScoreboardActivator e = new QueueScoreboardActivator(p);
|
|
||||||
Bukkit.getPluginManager().callEvent(e);
|
|
||||||
}
|
|
||||||
if(subchannel.equals("queuename") && papi) {
|
|
||||||
String playername = in.readUTF();
|
|
||||||
Player p = Bukkit.getPlayer(playername);
|
|
||||||
if(p == null) return;
|
|
||||||
if(!p.isOnline()) return;
|
|
||||||
|
|
||||||
String data = in.readUTF();
|
|
||||||
HashMap<String, String> phs = placeholders.responseCache.get(p);
|
|
||||||
if(phs == null) phs = new HashMap<>();
|
|
||||||
phs.put("queued", data);
|
|
||||||
placeholders.responseCache.put(p, phs);
|
|
||||||
}
|
|
||||||
if(subchannel.equals("position") && papi) {
|
|
||||||
String playername = in.readUTF();
|
|
||||||
Player p = Bukkit.getPlayer(playername);
|
|
||||||
if(p == null) return;
|
|
||||||
if(!p.isOnline()) return;
|
|
||||||
|
|
||||||
String data = in.readUTF();
|
|
||||||
HashMap<String, String> phs = placeholders.responseCache.get(p);
|
|
||||||
if(phs == null) phs = new HashMap<>();
|
|
||||||
phs.put("position", data);
|
|
||||||
placeholders.responseCache.put(p, phs);
|
|
||||||
}
|
|
||||||
if(subchannel.equals("positionof") && papi) {
|
|
||||||
String playername = in.readUTF();
|
|
||||||
Player p = Bukkit.getPlayer(playername);
|
|
||||||
if(p == null) return;
|
|
||||||
if(!p.isOnline()) return;
|
|
||||||
|
|
||||||
String data = in.readUTF();
|
|
||||||
HashMap<String, String> phs = placeholders.responseCache.get(p);
|
|
||||||
if(phs == null) phs = new HashMap<>();
|
|
||||||
phs.put("of", data);
|
|
||||||
placeholders.responseCache.put(p, phs);
|
|
||||||
}
|
|
||||||
if(subchannel.equals("inqueue") && papi) {
|
|
||||||
String playername = in.readUTF();
|
|
||||||
Player p = Bukkit.getPlayer(playername);
|
|
||||||
if(p == null) return;
|
|
||||||
if(!p.isOnline()) return;
|
|
||||||
|
|
||||||
String data = in.readUTF();
|
|
||||||
HashMap<String, String> phs = placeholders.responseCache.get(p);
|
|
||||||
if(phs == null) phs = new HashMap<>();
|
|
||||||
phs.put("inqueue", data);
|
|
||||||
placeholders.responseCache.put(p, phs);
|
|
||||||
}
|
|
||||||
if(subchannel.equals("queuedfor")) {
|
|
||||||
String playername = in.readUTF();
|
|
||||||
String queuename = in.readUTF();
|
|
||||||
|
|
||||||
Player p = Bukkit.getPlayer(playername);
|
|
||||||
if(p == null) return;
|
|
||||||
if(!p.isOnline()) return;
|
|
||||||
|
|
||||||
int number = Integer.valueOf(in.readUTF());
|
|
||||||
HashMap<String, String> phs = placeholders.responseCache.get(p);
|
|
||||||
if(phs == null) phs = new HashMap<>();
|
|
||||||
phs.put("queuedfor_"+queuename, number+"");
|
|
||||||
placeholders.responseCache.put(p, phs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void sendMessage(Player player, String subchannel, String data) {
|
|
||||||
//getLogger().info("Sending message. "+subchannel+" "+data);
|
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
out.writeUTF(subchannel);
|
|
||||||
out.writeUTF(data);
|
|
||||||
|
|
||||||
player.sendPluginMessage(this, "ajqueue:tobungee", out.toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(String subchannel, String data) {
|
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
out.writeUTF(subchannel);
|
|
||||||
out.writeUTF(data);
|
|
||||||
|
|
||||||
Bukkit.getOnlinePlayers().iterator().next()
|
|
||||||
.sendPluginMessage(this, "ajqueue:tobungee", out.toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onLeave(PlayerQuitEvent e) {
|
|
||||||
if(!papi) return;
|
|
||||||
placeholders.cleanCache();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,214 +0,0 @@
|
|||||||
package us.ajg0702.queue.spigot;
|
|
||||||
|
|
||||||
import java.util.ConcurrentModificationException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class will be registered through the register-method in the
|
|
||||||
* plugins onEnable-method.
|
|
||||||
*/
|
|
||||||
public class Placeholders extends PlaceholderExpansion {
|
|
||||||
|
|
||||||
private Main plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Since we register the expansion inside our own plugin, we
|
|
||||||
* can simply use this method here to get an instance of our
|
|
||||||
* plugin.
|
|
||||||
*
|
|
||||||
* @param plugin
|
|
||||||
* The instance of our plugin.
|
|
||||||
*/
|
|
||||||
public Placeholders(Main plugin){
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Because this is an internal class,
|
|
||||||
* you must override this method to let PlaceholderAPI know to not unregister your expansion class when
|
|
||||||
* PlaceholderAPI is reloaded
|
|
||||||
*
|
|
||||||
* @return true to persist through reloads
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean persist(){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Because this is a internal class, this check is not needed
|
|
||||||
* and we can simply return {@code true}
|
|
||||||
*
|
|
||||||
* @return Always true since it's an internal class.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean canRegister(){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the person who created this expansion should go here.
|
|
||||||
* <br>For convienience do we return the author from the plugin.yml
|
|
||||||
*
|
|
||||||
* @return The name of the author as a String.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getAuthor(){
|
|
||||||
return plugin.getDescription().getAuthors().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The placeholder identifier should go here.
|
|
||||||
* <br>This is what tells PlaceholderAPI to call our onRequest
|
|
||||||
* method to obtain a value if a placeholder starts with our
|
|
||||||
* identifier.
|
|
||||||
* <br>This must be unique and can not contain % or _
|
|
||||||
*
|
|
||||||
* @return The identifier in {@code %<identifier>_<value>%} as String.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getIdentifier(){
|
|
||||||
return "ajqueue";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the version of the expansion.
|
|
||||||
* <br>You don't have to use numbers, since it is set as a String.
|
|
||||||
*
|
|
||||||
* For convienience do we return the version from the plugin.yml
|
|
||||||
*
|
|
||||||
* @return The version as a String.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getVersion(){
|
|
||||||
return plugin.getDescription().getVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<Player, HashMap<String, String>> responseCache = new HashMap<>();
|
|
||||||
|
|
||||||
public void cleanCache() {
|
|
||||||
Iterator<Player> it = responseCache.keySet().iterator();
|
|
||||||
while(it.hasNext()) {
|
|
||||||
Player p = it.next();
|
|
||||||
if(p == null) {
|
|
||||||
it.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(!p.isOnline()) {
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the method called when a placeholder with our identifier
|
|
||||||
* is found and needs a value.
|
|
||||||
* <br>We specify the value identifier in this method.
|
|
||||||
* <br>Since version 2.9.1 can you use OfflinePlayers in your requests.
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* A org.bukkit.PkPlayer Player.
|
|
||||||
* @param identifier
|
|
||||||
* A String containing the identifier/value.
|
|
||||||
*
|
|
||||||
* @return possibly-null String of the requested identifier.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String onPlaceholderRequest(Player player, final String identifier){
|
|
||||||
//Bukkit.getLogger().info("itentifier: "+identifier);
|
|
||||||
|
|
||||||
|
|
||||||
if(player == null) return "No player";
|
|
||||||
|
|
||||||
|
|
||||||
String noc = "_nocache";
|
|
||||||
if(identifier.length() > noc.length()) {
|
|
||||||
int olen = identifier.length()-noc.length();
|
|
||||||
if(identifier.indexOf(noc) == olen) {
|
|
||||||
String idfr = identifier.substring(0, olen);
|
|
||||||
return this.parsePlaceholder(player, idfr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
HashMap<String, String> playerCache;
|
|
||||||
if(responseCache.containsKey(player)) {
|
|
||||||
playerCache = responseCache.get(player);
|
|
||||||
} else {
|
|
||||||
playerCache = new HashMap<String, String>();
|
|
||||||
}
|
|
||||||
if(playerCache.size() > 75) {
|
|
||||||
try {
|
|
||||||
playerCache.remove(playerCache.keySet().toArray()[0]);
|
|
||||||
} catch(ConcurrentModificationException e) {
|
|
||||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
playerCache.remove(playerCache.keySet().toArray()[0]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String resp = parsePlaceholder(player, identifier);
|
|
||||||
if(resp == null) return;
|
|
||||||
playerCache.put(identifier, resp);
|
|
||||||
responseCache.put(player, playerCache);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
if(responseCache.containsKey(player)) {
|
|
||||||
HashMap<String, String> playerCache = responseCache.get(player);
|
|
||||||
if(playerCache.containsKey(identifier)) {
|
|
||||||
return playerCache.get(identifier);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(identifier.equalsIgnoreCase("queued")) {
|
|
||||||
return "None";
|
|
||||||
}
|
|
||||||
if(identifier.equalsIgnoreCase("position") || identifier.equalsIgnoreCase("of")) {
|
|
||||||
return "None";
|
|
||||||
}
|
|
||||||
if(identifier.equalsIgnoreCase("inqueue")) {
|
|
||||||
return "false";
|
|
||||||
}
|
|
||||||
if(identifier.matches("queuedfor_*.*")) {
|
|
||||||
return "0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String parsePlaceholder(Player player, String identifier) {
|
|
||||||
if(identifier.equalsIgnoreCase("queued")) {
|
|
||||||
plugin.sendMessage(player, "queuename", "");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(identifier.equalsIgnoreCase("position")) {
|
|
||||||
plugin.sendMessage(player, "position", "");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(identifier.equalsIgnoreCase("of")) {
|
|
||||||
plugin.sendMessage(player, "positionof", "");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(identifier.equalsIgnoreCase("inqueue")) {
|
|
||||||
plugin.sendMessage(player, "inqueue", "");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(identifier.matches("queuedfor_*.*")) {
|
|
||||||
plugin.sendMessage(player, "queuedfor", identifier.split("_")[1]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package us.ajg0702.queue.spigot;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
public class QueueScoreboardActivator extends Event {
|
|
||||||
private static final HandlerList HANDLERS = new HandlerList();
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return HANDLERS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return HANDLERS;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player ply;
|
|
||||||
|
|
||||||
public QueueScoreboardActivator(Player p) {
|
|
||||||
this.ply = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
return ply.getPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
package us.ajg0702.queue.spigot.utils;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A cross-version actionbar class
|
|
||||||
* @author Based on ActionBarAPI from https://github.com/ConnorLinfoot
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ActionBar {
|
|
||||||
|
|
||||||
private static String version;
|
|
||||||
private static boolean old;
|
|
||||||
|
|
||||||
public static void send(Player player, String message) {
|
|
||||||
if(player == null) return;
|
|
||||||
if(!player.isOnline()) return;
|
|
||||||
|
|
||||||
version = Bukkit.getServer().getClass().getPackage().getName();
|
|
||||||
version = version.substring(version.lastIndexOf(".") + 1);
|
|
||||||
|
|
||||||
old = version.equalsIgnoreCase("v1_8_R1") || version.startsWith("v1_7_");
|
|
||||||
|
|
||||||
try {
|
|
||||||
Class<?> craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftPlayer");
|
|
||||||
Object craftPlayer = craftPlayerClass.cast(player);
|
|
||||||
Object packet;
|
|
||||||
Class<?> packetPlayOutChatClass = Class.forName("net.minecraft.server." + version + ".PacketPlayOutChat");
|
|
||||||
Class<?> packetClass = Class.forName("net.minecraft.server." + version + ".Packet");
|
|
||||||
if (old) {
|
|
||||||
Class<?> chatSerializerClass = Class.forName("net.minecraft.server." + version + ".ChatSerializer");
|
|
||||||
Class<?> iChatBaseComponentClass = Class.forName("net.minecraft.server." + version + ".IChatBaseComponent");
|
|
||||||
Method m3 = chatSerializerClass.getDeclaredMethod("a", String.class);
|
|
||||||
Object cbc = iChatBaseComponentClass.cast(m3.invoke(chatSerializerClass, "{\"text\": \"" + message + "\"}"));
|
|
||||||
packet = packetPlayOutChatClass.getConstructor(new Class<?>[]{iChatBaseComponentClass, byte.class}).newInstance(cbc, (byte) 2);
|
|
||||||
} else {
|
|
||||||
Class<?> chatComponentTextClass = Class.forName("net.minecraft.server." + version + ".ChatComponentText");
|
|
||||||
Class<?> iChatBaseComponentClass = Class.forName("net.minecraft.server." + version + ".IChatBaseComponent");
|
|
||||||
try {
|
|
||||||
Class<?> chatMessageTypeClass = Class.forName("net.minecraft.server." + version + ".ChatMessageType");
|
|
||||||
Object[] chatMessageTypes = chatMessageTypeClass.getEnumConstants();
|
|
||||||
Object chatMessageType = null;
|
|
||||||
for (Object o : chatMessageTypes) {
|
|
||||||
if (o.toString().equals("GAME_INFO")) {
|
|
||||||
chatMessageType = o;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Object chatCompontentText = chatComponentTextClass.getConstructor(new Class<?>[]{String.class}).newInstance(message);
|
|
||||||
packet = packetPlayOutChatClass.getConstructor(new Class<?>[]{iChatBaseComponentClass, chatMessageTypeClass}).newInstance(chatCompontentText, chatMessageType);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
Object chatCompontentText = chatComponentTextClass.getConstructor(new Class<?>[]{String.class}).newInstance(message);
|
|
||||||
packet = packetPlayOutChatClass.getConstructor(new Class<?>[]{iChatBaseComponentClass, byte.class}).newInstance(chatCompontentText, (byte) 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Method craftPlayerHandleMethod = craftPlayerClass.getDeclaredMethod("getHandle");
|
|
||||||
Object craftPlayerHandle = craftPlayerHandleMethod.invoke(craftPlayer);
|
|
||||||
Field playerConnectionField = craftPlayerHandle.getClass().getDeclaredField("playerConnection");
|
|
||||||
Object playerConnection = playerConnectionField.get(craftPlayerHandle);
|
|
||||||
Method sendPacketMethod = playerConnection.getClass().getDeclaredMethod("sendPacket", packetClass);
|
|
||||||
sendPacketMethod.invoke(playerConnection, packet);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package us.ajg0702.queue.spigot.utils;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
|
|
||||||
public class VersionSupport {
|
|
||||||
|
|
||||||
public static String getVersion() {
|
|
||||||
return Bukkit.getVersion().split("\\(MC: ")[1].split("\\)")[0];
|
|
||||||
}
|
|
||||||
public static int getMinorVersion() {
|
|
||||||
return Integer.parseInt(getVersion().split("\\.")[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send the player an actionbar message
|
|
||||||
* @param ply The {@link org.bukkit.entity.Player Player} to send the actionbar to
|
|
||||||
* @param message The message to send in the actionbar.
|
|
||||||
*/
|
|
||||||
public static void sendActionBar(Player ply, String message) {
|
|
||||||
// Use spigot version if available, otherwise use packets.
|
|
||||||
if(getMinorVersion() >= 11) {
|
|
||||||
ply.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
|
|
||||||
} else if(getMinorVersion() >= 8) {
|
|
||||||
ActionBar.send(ply, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
name: ajQueue
|
|
||||||
version: "@VERSION@"
|
|
||||||
main: us.ajg0702.queue.Main
|
|
||||||
author: ajgeiss0702
|
|
||||||
@@ -1,174 +0,0 @@
|
|||||||
# Dont touch this number please
|
|
||||||
config-version: 21
|
|
||||||
|
|
||||||
# The time the server will wait between sending people in the queue
|
|
||||||
# Default: 5
|
|
||||||
wait-time: 5
|
|
||||||
|
|
||||||
# The time that a server has to be offline to be marked as offline instead of restarting
|
|
||||||
# Default: 120
|
|
||||||
offline-time: 120
|
|
||||||
|
|
||||||
# The time the server will wait between sending players update messages on what position they are in the queue.
|
|
||||||
# Default: 10
|
|
||||||
message-time: 10
|
|
||||||
|
|
||||||
# If a player is in a server, you can have the plugin make them automatically join a queue for another server
|
|
||||||
# Example with the default values: Player joins survivalqueue server, they will auto-join the queue for survival
|
|
||||||
queue-servers:
|
|
||||||
- 'survivalqueue:survival'
|
|
||||||
|
|
||||||
# Should the plugin send an actionbar to the player?
|
|
||||||
# The actionbar contains some info such as which server they are queued for, what position they are in, estimated time remaining, etc.
|
|
||||||
send-actionbar: true
|
|
||||||
|
|
||||||
# What kick reasons should cause the player to be removed from the queue?
|
|
||||||
# For example, if one of the below kick reasons is 'banned' and the player gets kicked when trying to connect to
|
|
||||||
# a server in a queue with a message saying "You are banned from this server!" then it will kick them from the queue too.
|
|
||||||
kick-reasons:
|
|
||||||
- 'banned'
|
|
||||||
- 'blacklisted'
|
|
||||||
|
|
||||||
|
|
||||||
# Should we remove a player from the queue if they move servers?
|
|
||||||
# If they join another queue, they will be removed from the previous one no matter what
|
|
||||||
# This is more meant for if you have multiple lobbies if you want to let the player switch
|
|
||||||
# between them without losing their queue position
|
|
||||||
# Default: false
|
|
||||||
remove-player-on-server-switch: false
|
|
||||||
|
|
||||||
|
|
||||||
# Should we wait until the server is done loading to load the servers?
|
|
||||||
# Enable this if you have a plugin that adds servers to the server list during startup.
|
|
||||||
# Default: false
|
|
||||||
wait-to-load-servers: false
|
|
||||||
|
|
||||||
# How long should we wait after the server finishes loading to load the server list?
|
|
||||||
# Only works if the above is enabled.
|
|
||||||
# This is in miliseconds so 1000 = 1 second
|
|
||||||
# Default: 500
|
|
||||||
wait-to-load-servers-delay: 500
|
|
||||||
|
|
||||||
|
|
||||||
# How often (in seconds) we should check for new servers to add queues for.
|
|
||||||
# If you dynamicly add servers, set this to something other than 0.
|
|
||||||
# To disable, set to 0
|
|
||||||
reload-servers-interval: 0
|
|
||||||
|
|
||||||
|
|
||||||
# Should we require permissions for players to be able to join queues?
|
|
||||||
# If enabled, players will be required to have the permission ajqueue.queue.<server>
|
|
||||||
# Default: false
|
|
||||||
require-permission: false
|
|
||||||
|
|
||||||
|
|
||||||
# Should we let players join more than one queue?
|
|
||||||
# If enabled, players will be able to be in multiple queues at once.
|
|
||||||
# Default: true
|
|
||||||
allow-multiple-queues: true
|
|
||||||
|
|
||||||
# If the player is queued for multiple servers, which server should we pick to use in things like placeholders and actionbars
|
|
||||||
# Options are first and last
|
|
||||||
# Default: last
|
|
||||||
multi-server-queue-pick: last
|
|
||||||
|
|
||||||
|
|
||||||
# THIS FEATURE IS ONLY AVAILABLE ON ajQueuePlus (https://www.spigotmc.org/resources/ajqueueplus.79123/)
|
|
||||||
# This will show players a different name than the actual bungeecord server name
|
|
||||||
# for example, instead of showing players "event-a", this option can make it appear as "Event A"
|
|
||||||
# With this example, you would use this: - "event-a:Event A"
|
|
||||||
# Note that currently players still have to use the normal names in queue commands and leave commands
|
|
||||||
# Format: "realname:Alias"
|
|
||||||
server-aliases:
|
|
||||||
- "event-a:Event A"
|
|
||||||
|
|
||||||
|
|
||||||
# How long should we wait after a server is online before sending players?
|
|
||||||
# The server will still show up as offline or restarting until this amount of time after its up
|
|
||||||
# Meant to let your server 'cool down' after lag from starting up
|
|
||||||
# In seconds
|
|
||||||
# Default: 1
|
|
||||||
wait-after-online: 1
|
|
||||||
|
|
||||||
|
|
||||||
# This is for helping with finding issues with the server pinged
|
|
||||||
# This will spam the console when enabled
|
|
||||||
# When this enabled, if servers are offline then it will spam errors. You can ignore them.
|
|
||||||
# Default: false
|
|
||||||
pinger-debug: false
|
|
||||||
|
|
||||||
|
|
||||||
# When a queue is paused, should we prevent players from joining it?
|
|
||||||
# Default: false
|
|
||||||
prevent-joining-paused: false
|
|
||||||
|
|
||||||
# When a server goes back online, should we send all players in the queue instantly?
|
|
||||||
# Default: false
|
|
||||||
send-all-when-back-online: false
|
|
||||||
|
|
||||||
# Require a permission for players to be able to join a queue from a server
|
|
||||||
# If enabled, players will need the permission ajqueue.joinfrom.<server> to join queues.
|
|
||||||
# Replace <server> with the name of the server
|
|
||||||
# Default: false
|
|
||||||
joinfrom-server-permission: false
|
|
||||||
|
|
||||||
# Server groups are a group of servers that you can queue for. It will send you to the server that is the least full.
|
|
||||||
# If all servers in the group are full, it will act the same as it would when a single server is full.
|
|
||||||
# Same if all servers are offline. It will only send players to servers that are online.
|
|
||||||
# Format: "groupname:server1,server2,etc"
|
|
||||||
server-groups:
|
|
||||||
- "lobbys:lobby-1,lobby-2,lobby-3"
|
|
||||||
|
|
||||||
|
|
||||||
# Should we allow tab-completing in the /queue command?
|
|
||||||
# Default: true
|
|
||||||
tab-complete-queues: true
|
|
||||||
|
|
||||||
# Should we have no wait time for these servers?
|
|
||||||
# If the server is joinable, the plugin will attempt to send players who join these queues as soon as they join.
|
|
||||||
# If the server is not immidiatly joinable, they will have to wait for the normal wait-time
|
|
||||||
# This also works with group
|
|
||||||
# NOTE: Server names are caps sensitive
|
|
||||||
send-instantly:
|
|
||||||
- "lobbys"
|
|
||||||
|
|
||||||
# Should we log to the bungeecord console when a player fails to get sent to a server from the queue?
|
|
||||||
# Enable this if you are having an issue with one player stopping the queue
|
|
||||||
# Default: false
|
|
||||||
send-fail-debug: false
|
|
||||||
|
|
||||||
# After how many (unsuccessfull) attempts of sending the player should we remove them from the queue?
|
|
||||||
# Set to -1 to disable
|
|
||||||
# Default: 10
|
|
||||||
max-tries: 10
|
|
||||||
|
|
||||||
# Should we enable the ajqueue.bypasspaused permission?
|
|
||||||
# If enabled, anyone with the permission ajqueue.bypasspaused will be able to join paused servers
|
|
||||||
# Default: false
|
|
||||||
enable-bypasspaused-permission: false
|
|
||||||
|
|
||||||
# Should we check to make sure that people dont get sent quicker than wait-time?
|
|
||||||
# Default: true
|
|
||||||
check-last-player-sent-time: true
|
|
||||||
|
|
||||||
# Should we send debug info to the console when priority queue is used?
|
|
||||||
# This will print several lines to the console when a player joins a queue,
|
|
||||||
# so you should probably only use this for debugging purposes
|
|
||||||
# Default: false
|
|
||||||
priority-queue-debug: false
|
|
||||||
|
|
||||||
# When a player is kicked from a server, should we automatically add that player to the queue?
|
|
||||||
# You will still need to use another plugin to make sure the player doesnt get kicked from bungee completly.
|
|
||||||
# Default: false
|
|
||||||
auto-add-to-queue-on-kick: false
|
|
||||||
# The delay for the above option.
|
|
||||||
# In seconds, decimals supported.
|
|
||||||
auto-add-to-queue-on-kick-delay: 1
|
|
||||||
|
|
||||||
# With what kick reasons should we auto-add the player to the queue
|
|
||||||
# This wont work if auto-add-to-queue-on-kick is disabled.
|
|
||||||
# If you set it to [], then all kick messages will cause the player to be added to the queue
|
|
||||||
# This works on contains, so you dont have to include the whole kick message, just a few words.
|
|
||||||
auto-add-kick-reasons:
|
|
||||||
- "restarting"
|
|
||||||
- "closed"
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
main: us.ajg0702.queue.spigot.Main
|
|
||||||
version: "@VERSION@"
|
|
||||||
api-version: 1.13
|
|
||||||
author: ajgeiss0702
|
|
||||||
name: ajQueue
|
|
||||||
softdepend: [PlaceholderAPI]
|
|
||||||
commands:
|
|
||||||
move:
|
|
||||||
aliases: [server, queue, joinq, joinqueue]
|
|
||||||
description: Queue for a server
|
|
||||||
leavequeue:
|
|
||||||
aliases: [leaveq]
|
|
||||||
description: Leaves a queue
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.PatternReplacementResult;
|
|
||||||
import net.kyori.adventure.text.TextReplacementConfig;
|
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class RegexTest {
|
|
||||||
@Test
|
|
||||||
public void regex() throws Exception {
|
|
||||||
Component msg = Component.text("&b{SERVER} &7({COUNT}): {LIST}");
|
|
||||||
Component playerList = Component.empty();
|
|
||||||
List<String> players = Arrays.asList("bot01", "bot02", "bot03", "bot04", "bot05", "bot06");
|
|
||||||
for(String p : players) {
|
|
||||||
playerList = playerList.append(Component.text("&9"+p+"&7, "));
|
|
||||||
}
|
|
||||||
Component finalPlayerList = playerList;
|
|
||||||
msg = msg.replaceText(b -> b.match(Pattern.compile("\\{LIST}")).replacement(finalPlayerList));
|
|
||||||
char[] commaCountString = PlainTextComponentSerializer.plainText().serialize(msg).toCharArray();
|
|
||||||
int commas = 0;
|
|
||||||
for(Character fChar : commaCountString) {
|
|
||||||
if(fChar == ',') commas++;
|
|
||||||
}
|
|
||||||
|
|
||||||
int finalCommas = commas;
|
|
||||||
msg = msg.replaceText(b -> b.match(",(?!.*,)").replacement("").condition((r, c, re) -> {
|
|
||||||
if(c == finalCommas) {
|
|
||||||
return PatternReplacementResult.REPLACE;
|
|
||||||
}
|
|
||||||
return PatternReplacementResult.CONTINUE;
|
|
||||||
}));
|
|
||||||
msg = msg.replaceText(b -> b.match(Pattern.compile("\\{COUNT}")).replacement(players.size()+""));
|
|
||||||
|
|
||||||
|
|
||||||
String f = PlainTextComponentSerializer.plainText().serialize(msg);
|
|
||||||
System.out.println(f);
|
|
||||||
int c = 0;
|
|
||||||
for(Character fChar : f.toCharArray()) {
|
|
||||||
if(fChar == ',') c++;
|
|
||||||
}
|
|
||||||
if(c != 5) {
|
|
||||||
throw new Exception("Wrong comma count! Had "+c+" when expected 5");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user