the basics are working on velocity now
This commit is contained in:
@@ -79,6 +79,11 @@ public interface QueueManager {
|
|||||||
*/
|
*/
|
||||||
void sendMessage(QueuePlayer queuePlayer);
|
void sendMessage(QueuePlayer queuePlayer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates info about the servers
|
||||||
|
*/
|
||||||
|
void updateServers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a server by its name
|
* Find a server by its name
|
||||||
* @param name The name to look for
|
* @param name The name to look for
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package us.ajg0702.queue.commands.commands.listqueues;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
|
import us.ajg0702.queue.api.commands.ISubCommand;
|
||||||
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
|
import us.ajg0702.queue.commands.BaseCommand;
|
||||||
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
|
import us.ajg0702.utils.common.Messages;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ListCommand extends BaseCommand {
|
||||||
|
|
||||||
|
private final QueueMain main;
|
||||||
|
|
||||||
|
public ListCommand(QueueMain main) {
|
||||||
|
this.main = main;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "listqueues";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImmutableList<String> getAliases() {
|
||||||
|
return ImmutableList.of("listq");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImmutableList<ISubCommand> getSubCommands() {
|
||||||
|
return ImmutableList.<ISubCommand>builder().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "ajqueue.listqueues";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Messages getMessages() {
|
||||||
|
return main.getMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addSubCommand(ISubCommand subCommand) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(ICommandSender sender, String[] args) {
|
||||||
|
if(!checkPermission(sender)) return;
|
||||||
|
|
||||||
|
AdaptedPlayer spp = null;
|
||||||
|
if(sender.isPlayer()) {
|
||||||
|
spp = main.getPlatformMethods().senderToPlayer(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Component m = main.getMessages().getComponent("commands.listqueues.header");
|
||||||
|
boolean none = true;
|
||||||
|
for(QueueServer s : main.getQueueManager().getServers()) {
|
||||||
|
none = false;
|
||||||
|
String color = "&a";
|
||||||
|
if(!s.isOnline()) {
|
||||||
|
color = "&c";
|
||||||
|
} else if(!s.isJoinable(spp)) {
|
||||||
|
color = "&e";
|
||||||
|
}
|
||||||
|
|
||||||
|
m = m.append(Component.text("\n"));
|
||||||
|
m = m.append(main.getMessages().getComponent("commands.listqueues.format",
|
||||||
|
"COLOR:" + main.getMessages().color(color),
|
||||||
|
"NAME:" + s.getName(),
|
||||||
|
"COUNT:" + s.getQueue().size(),
|
||||||
|
"STATUS:" + s.getStatusString(spp)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
sender.sendMessage(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> autoComplete(ICommandSender sender, String[] args) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package us.ajg0702.queue.commands.commands.manage;
|
package us.ajg0702.queue.commands.commands.manage;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
import us.ajg0702.queue.api.commands.ISubCommand;
|
import us.ajg0702.queue.api.commands.ISubCommand;
|
||||||
import us.ajg0702.queue.commands.BaseCommand;
|
import us.ajg0702.queue.commands.BaseCommand;
|
||||||
@@ -9,7 +10,9 @@ import us.ajg0702.queue.common.QueueMain;
|
|||||||
import us.ajg0702.utils.common.Messages;
|
import us.ajg0702.utils.common.Messages;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class ManageCommand extends BaseCommand {
|
public class ManageCommand extends BaseCommand {
|
||||||
|
|
||||||
@@ -18,7 +21,8 @@ public class ManageCommand extends BaseCommand {
|
|||||||
public ManageCommand(QueueMain main) {
|
public ManageCommand(QueueMain main) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
|
|
||||||
|
addSubCommand(new Reload(main));
|
||||||
|
addSubCommand(new Tasks(main));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -56,11 +60,31 @@ public class ManageCommand extends BaseCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(ICommandSender sender, String[] args) {
|
public void execute(ICommandSender sender, String[] args) {
|
||||||
|
if(args.length > 0) {
|
||||||
|
for(ISubCommand subCommand : subCommands) {
|
||||||
|
if(args[0].equalsIgnoreCase(subCommand.getName()) || subCommand.getAliases().contains(args[0].toLowerCase(Locale.ROOT))) {
|
||||||
|
subCommand.execute(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.sendMessage(Component.text("/ajQueue <reload|list|send|pause>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> autoComplete(ICommandSender sender, String[] args) {
|
public List<String> autoComplete(ICommandSender sender, String[] args) {
|
||||||
return null;
|
if(args.length > 0) {
|
||||||
|
for(ISubCommand subCommand : subCommands) {
|
||||||
|
if(args[0].equalsIgnoreCase(subCommand.getName()) || subCommand.getAliases().contains(args[0].toLowerCase(Locale.ROOT))) {
|
||||||
|
return subCommand.autoComplete(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<String> commands = new ArrayList<>();
|
||||||
|
for(ISubCommand subCommand : subCommands) {
|
||||||
|
commands.add(subCommand.getName());
|
||||||
|
commands.addAll(subCommand.getAliases());
|
||||||
|
}
|
||||||
|
return commands;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package us.ajg0702.queue.commands.commands.manage;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
|
import us.ajg0702.queue.api.commands.ISubCommand;
|
||||||
|
import us.ajg0702.queue.commands.SubCommand;
|
||||||
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
|
import us.ajg0702.utils.common.Messages;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Reload extends SubCommand {
|
||||||
|
|
||||||
|
QueueMain main;
|
||||||
|
public Reload(QueueMain main) {
|
||||||
|
this.main = main;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "reload";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImmutableList<String> getAliases() {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "ajqueue.reload";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Messages getMessages() {
|
||||||
|
return main.getMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addSubCommand(ISubCommand subCommand) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(ICommandSender sender, String[] args) {
|
||||||
|
if(!checkPermission(sender)) return;
|
||||||
|
main.getMessages().reload();
|
||||||
|
try {
|
||||||
|
main.getConfig().reload();
|
||||||
|
} catch (ConfigurateException e) {
|
||||||
|
sender.sendMessage(Component.text("An error occurred while reloading. Check the console").color(NamedTextColor.RED));
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
main.setTimeBetweenPlayers();
|
||||||
|
main.getTaskManager().rescheduleTasks();
|
||||||
|
main.getQueueManager().reloadServers();
|
||||||
|
|
||||||
|
sender.sendMessage(getMessages().getComponent("commands.reload"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> autoComplete(ICommandSender sender, String[] args) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package us.ajg0702.queue.commands.commands.manage;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
|
import us.ajg0702.queue.api.commands.ISubCommand;
|
||||||
|
import us.ajg0702.queue.commands.SubCommand;
|
||||||
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
|
import us.ajg0702.utils.common.Messages;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Tasks extends SubCommand {
|
||||||
|
|
||||||
|
QueueMain main;
|
||||||
|
public Tasks(QueueMain main) {
|
||||||
|
this.main = main;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "tasks";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImmutableList<String> getAliases() {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "ajqueue.tasks";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Messages getMessages() {
|
||||||
|
return main.getMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addSubCommand(ISubCommand subCommand) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(ICommandSender sender, String[] args) {
|
||||||
|
if(!checkPermission(sender)) return;
|
||||||
|
sender.sendMessage(Component.text(main.getTaskManager().taskStatus()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> autoComplete(ICommandSender sender, String[] args) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import us.ajg0702.queue.common.QueueMain;
|
|||||||
import us.ajg0702.utils.common.Messages;
|
import us.ajg0702.utils.common.Messages;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class QueueCommand extends BaseCommand {
|
public class QueueCommand extends BaseCommand {
|
||||||
@@ -26,7 +27,11 @@ public class QueueCommand extends BaseCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableList<String> getAliases() {
|
public ImmutableList<String> getAliases() {
|
||||||
return ImmutableList.of("move", "server", "joinqueue", "joinq");
|
List<String> aliases = new ArrayList<>(Arrays.asList("move", "joinqueue", "joinq"));
|
||||||
|
if(main.getConfig().getBoolean("enable-server-command")) {
|
||||||
|
aliases.add("server");
|
||||||
|
}
|
||||||
|
return ImmutableList.copyOf(aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.io.File;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.*;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class QueueMain {
|
public class QueueMain {
|
||||||
@@ -24,6 +24,9 @@ public class QueueMain {
|
|||||||
public double getTimeBetweenPlayers() {
|
public double getTimeBetweenPlayers() {
|
||||||
return timeBetweenPlayers;
|
return timeBetweenPlayers;
|
||||||
}
|
}
|
||||||
|
public void setTimeBetweenPlayers() {
|
||||||
|
this.timeBetweenPlayers = config.getDouble("wait-time");
|
||||||
|
}
|
||||||
|
|
||||||
private Config config;
|
private Config config;
|
||||||
public Config getConfig() {
|
public Config getConfig() {
|
||||||
@@ -59,6 +62,11 @@ public class QueueMain {
|
|||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final TaskManager taskManager = new TaskManager(this);
|
||||||
|
public TaskManager getTaskManager() {
|
||||||
|
return taskManager;
|
||||||
|
}
|
||||||
|
|
||||||
private List<CompletableFuture<ServerBuilder>> serverCompletableFutures = new ArrayList<>();
|
private List<CompletableFuture<ServerBuilder>> serverCompletableFutures = new ArrayList<>();
|
||||||
private ServerBuilder serverBuilder;
|
private ServerBuilder serverBuilder;
|
||||||
public ServerBuilder getServerBuilder() {
|
public ServerBuilder getServerBuilder() {
|
||||||
@@ -104,14 +112,14 @@ public class QueueMain {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
timeBetweenPlayers = config.getDouble("wait-time");
|
setTimeBetweenPlayers();
|
||||||
|
|
||||||
queueManager = new QueueManagerImpl(this);
|
queueManager = new QueueManagerImpl(this);
|
||||||
|
|
||||||
logic = new LogicGetter().constructLogic();
|
logic = new LogicGetter().constructLogic();
|
||||||
aliasManager = new LogicGetter().constructAliasManager(config);
|
aliasManager = new LogicGetter().constructAliasManager(config);
|
||||||
|
|
||||||
|
taskManager.rescheduleTasks();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
|
|
||||||
public class QueueManagerImpl implements QueueManager {
|
public class QueueManagerImpl implements QueueManager {
|
||||||
|
|
||||||
private List<QueueServer> servers;
|
private List<QueueServer> servers = new ArrayList<>();
|
||||||
|
|
||||||
private final QueueMain main;
|
private final QueueMain main;
|
||||||
private final Messages msgs;
|
private final Messages msgs;
|
||||||
@@ -130,6 +130,9 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!server.isJoinable(player)) {
|
||||||
|
sendMessage(queuePlayer);
|
||||||
|
}
|
||||||
main.getPlatformMethods().sendJoinQueueChannelMessages(server, queuePlayer);
|
main.getPlatformMethods().sendJoinQueueChannelMessages(server, queuePlayer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -272,11 +275,16 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessages() {
|
public void sendMessages() {
|
||||||
|
if(servers == null) return;
|
||||||
|
try {
|
||||||
for(QueueServer server : servers) {
|
for(QueueServer server : servers) {
|
||||||
for(QueuePlayer queuePlayer : server.getQueue()) {
|
for(QueuePlayer queuePlayer : server.getQueue()) {
|
||||||
sendMessage(queuePlayer);
|
sendMessage(queuePlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -289,7 +297,7 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
int pos = queuePlayer.getPosition();
|
int pos = queuePlayer.getPosition();
|
||||||
int len = server.getQueue().size();
|
int len = server.getQueue().size();
|
||||||
|
|
||||||
if(server.isJoinable(player)) {
|
if(!server.isJoinable(player)) {
|
||||||
String status = server.getStatusString(player);
|
String status = server.getStatusString(player);
|
||||||
|
|
||||||
if(msgs.getString("status.offline.base").isEmpty()) return;
|
if(msgs.getString("status.offline.base").isEmpty()) return;
|
||||||
@@ -312,6 +320,17 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateServers() {
|
||||||
|
try {
|
||||||
|
for(QueueServer server : servers) {
|
||||||
|
server.updatePing();
|
||||||
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueueServer findServer(String name) {
|
public QueueServer findServer(String name) {
|
||||||
for(QueueServer server : servers) {
|
for(QueueServer server : servers) {
|
||||||
@@ -360,22 +379,30 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
player.sendMessage(msgs.getComponent("status.sending-now", "SERVER:"+server.getAlias()));
|
player.sendMessage(msgs.getComponent("status.sending-now", "SERVER:"+server.getAlias()));
|
||||||
player.connect(selected);
|
player.connect(selected);
|
||||||
}
|
}
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueuePlayer nextQueuePlayer = server.getQueue().get(0);
|
QueuePlayer nextQueuePlayer = server.getQueue().get(0);
|
||||||
AdaptedPlayer nextPlayer = nextQueuePlayer.getPlayer();
|
AdaptedPlayer nextPlayer = nextQueuePlayer.getPlayer();
|
||||||
|
|
||||||
|
|
||||||
// If the first person int the queue is offline or already in the server, find the next online player in the queue
|
// If the first person int the queue is offline or already in the server, find the next online player in the queue
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while((nextPlayer == null || server.getServerNames().contains(nextPlayer.getServerName())) && i < server.getQueue().size()) {
|
while((nextPlayer == null || server.getServerNames().contains(nextPlayer.getServerName())) && i < server.getQueue().size()) {
|
||||||
if(nextPlayer != null) { // Remove them if they are already in the server
|
if(nextPlayer != null) { // Remove them if they are already in the server
|
||||||
server.removePlayer(nextQueuePlayer);
|
server.removePlayer(nextQueuePlayer);
|
||||||
} else {
|
if(server.getQueue().size() > i) {
|
||||||
i++;
|
|
||||||
}
|
|
||||||
nextQueuePlayer = server.getQueue().get(i);
|
nextQueuePlayer = server.getQueue().get(i);
|
||||||
nextPlayer = nextQueuePlayer.getPlayer();
|
nextPlayer = nextQueuePlayer.getPlayer();
|
||||||
|
} else {
|
||||||
|
nextPlayer = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
nextQueuePlayer = server.getQueue().get(i);
|
||||||
|
nextPlayer = nextQueuePlayer.getPlayer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nextPlayer == null) continue; // None of the players in the queue are online
|
if(nextPlayer == null) continue; // None of the players in the queue are online
|
||||||
@@ -388,7 +415,6 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
if(server.isPaused() && !nextPlayer.hasPermission("ajqueue.bypasspaused")) continue;
|
if(server.isPaused() && !nextPlayer.hasPermission("ajqueue.bypasspaused")) continue;
|
||||||
} else if(server.isPaused()) { continue; }
|
} else if(server.isPaused()) { continue; }
|
||||||
|
|
||||||
|
|
||||||
int tries = sendingAttempts.get(nextQueuePlayer) == null ? 0 : sendingAttempts.get(nextQueuePlayer);
|
int tries = sendingAttempts.get(nextQueuePlayer) == null ? 0 : sendingAttempts.get(nextQueuePlayer);
|
||||||
int maxTries = main.getConfig().getInt("max-tries");
|
int maxTries = main.getConfig().getInt("max-tries");
|
||||||
if(tries >= maxTries && maxTries > 0) {
|
if(tries >= maxTries && maxTries > 0) {
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package us.ajg0702.queue.common;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class TaskManager {
|
||||||
|
|
||||||
|
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||||
|
ScheduledExecutorService updateExecutor = Executors.newScheduledThreadPool(1);
|
||||||
|
|
||||||
|
QueueMain main;
|
||||||
|
public TaskManager(QueueMain main) {
|
||||||
|
this.main = main;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String taskStatus() {
|
||||||
|
List<ScheduledFuture<?>> tasks = Arrays.asList(sendTask, updateTask, messageTask, actionBarTask, queueEventTask, reloadServerTask);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for(ScheduledFuture<?> task : tasks) {
|
||||||
|
sb.append(task == null ? "null" : task.isDone() ? "canceled/done" : "running");
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
ScheduledFuture<?> sendTask;
|
||||||
|
ScheduledFuture<?> updateTask;
|
||||||
|
ScheduledFuture<?> messageTask;
|
||||||
|
ScheduledFuture<?> actionBarTask;
|
||||||
|
ScheduledFuture<?> queueEventTask;
|
||||||
|
ScheduledFuture<?> reloadServerTask;
|
||||||
|
public void rescheduleTasks() {
|
||||||
|
cancelTasks();
|
||||||
|
|
||||||
|
sendTask = scheduleAtFixedRate(
|
||||||
|
main.getQueueManager()::sendPlayers,
|
||||||
|
0L,
|
||||||
|
(long) (main.getConfig().getDouble("wait-time")*1000L),
|
||||||
|
TimeUnit.MILLISECONDS
|
||||||
|
);
|
||||||
|
|
||||||
|
updateTask = scheduleAtFixedRate(updateExecutor,
|
||||||
|
main.getQueueManager()::updateServers,
|
||||||
|
0L,
|
||||||
|
(long) (Math.max(main.getTimeBetweenPlayers(), 2)*1000L),
|
||||||
|
TimeUnit.MILLISECONDS
|
||||||
|
);
|
||||||
|
|
||||||
|
messageTask = scheduleAtFixedRate(
|
||||||
|
main.getQueueManager()::sendMessages,
|
||||||
|
0L,
|
||||||
|
main.getConfig().getInt("message-time"),
|
||||||
|
TimeUnit.SECONDS
|
||||||
|
);
|
||||||
|
|
||||||
|
actionBarTask = scheduleAtFixedRate(
|
||||||
|
main.getQueueManager()::sendActionBars,
|
||||||
|
0L,
|
||||||
|
2L,
|
||||||
|
TimeUnit.SECONDS
|
||||||
|
);
|
||||||
|
|
||||||
|
queueEventTask = scheduleAtFixedRate(
|
||||||
|
main.getQueueManager()::sendQueueEvents,
|
||||||
|
0L,
|
||||||
|
2L,
|
||||||
|
TimeUnit.SECONDS
|
||||||
|
);
|
||||||
|
|
||||||
|
if(main.getConfig().getInt("reload-servers-interval") > 0) {
|
||||||
|
reloadServerTask = scheduleAtFixedRate(
|
||||||
|
main.getQueueManager()::reloadServers,
|
||||||
|
0L,
|
||||||
|
main.getConfig().getInt("reload-servers-interval"),
|
||||||
|
TimeUnit.SECONDS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelTasks() {
|
||||||
|
if(sendTask != null && !sendTask.isCancelled()) {
|
||||||
|
sendTask.cancel(false);
|
||||||
|
}
|
||||||
|
if(updateTask != null && !updateTask.isCancelled()) {
|
||||||
|
updateTask.cancel(false);
|
||||||
|
}
|
||||||
|
if(messageTask != null && !messageTask.isCancelled()) {
|
||||||
|
messageTask.cancel(false);
|
||||||
|
}
|
||||||
|
if(actionBarTask != null && !actionBarTask.isCancelled()) {
|
||||||
|
actionBarTask.cancel(false);
|
||||||
|
}
|
||||||
|
if(queueEventTask != null && !queueEventTask.isCancelled()) {
|
||||||
|
queueEventTask.cancel(false);
|
||||||
|
}
|
||||||
|
if(reloadServerTask != null && !reloadServerTask.isCancelled()) {
|
||||||
|
reloadServerTask.cancel(false);
|
||||||
|
reloadServerTask = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
|
||||||
|
return scheduleAtFixedRate(executor, command, initialDelay, period, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ScheduledFuture<?> scheduleAtFixedRate(ScheduledExecutorService executor, Runnable command, long initialDelay, long period, TimeUnit unit) {
|
||||||
|
return executor.scheduleAtFixedRate(() -> {
|
||||||
|
try {
|
||||||
|
command.run();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("An error ocurred while running an ajQueue task");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}, initialDelay, period, unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ public class QueuePlayerImpl implements QueuePlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUniqueId() {
|
public UUID getUniqueId() {
|
||||||
|
if(uuid == null) throw new IllegalStateException("Why is my UUID null??");
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,9 +117,13 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
ping = futurePing.get(5, TimeUnit.SECONDS);
|
ping = futurePing.get(5, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||||
if(main.getConfig().getBoolean("pinger-debug")) {
|
if(main.getConfig().getBoolean("pinger-debug")) {
|
||||||
main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] sending ping");
|
main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] offline:");
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(ping != null && main.getConfig().getBoolean("pinger-debug")) {
|
||||||
|
main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] online. motd: "+ping.getPlainDescription()+" players: "+ping.getPlayerCount()+"/"+ping.getMaxPlayers());
|
||||||
|
}
|
||||||
|
|
||||||
pings.put(server, ping);
|
pings.put(server, ping);
|
||||||
i++;
|
i++;
|
||||||
@@ -297,11 +301,18 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueuePlayer findPlayer(AdaptedPlayer player) {
|
public synchronized QueuePlayer findPlayer(AdaptedPlayer player) {
|
||||||
for(QueuePlayer queuePlayer : queue) {
|
for(QueuePlayer queuePlayer : queue) {
|
||||||
AdaptedPlayer queuedPlayer = queuePlayer.getPlayer();
|
AdaptedPlayer queuedPlayer = queuePlayer.getPlayer();
|
||||||
if(queuedPlayer == null) continue;
|
if(queuedPlayer == null) continue;
|
||||||
if(queuedPlayer.getUniqueId().equals(player.getUniqueId())) {
|
if(
|
||||||
|
queuedPlayer
|
||||||
|
.getUniqueId()
|
||||||
|
.equals(
|
||||||
|
player
|
||||||
|
.getUniqueId()
|
||||||
|
)
|
||||||
|
) {
|
||||||
return queuePlayer;
|
return queuePlayer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Dont touch this number please
|
# Dont touch this number please
|
||||||
config-version: 21
|
config-version: 22
|
||||||
|
|
||||||
# The time the server will wait between sending people in the queue
|
# The time the server will wait between sending people in the queue
|
||||||
# Default: 5
|
# Default: 5
|
||||||
@@ -172,3 +172,8 @@ auto-add-to-queue-on-kick-delay: 1
|
|||||||
auto-add-kick-reasons:
|
auto-add-kick-reasons:
|
||||||
- "restarting"
|
- "restarting"
|
||||||
- "closed"
|
- "closed"
|
||||||
|
|
||||||
|
# Should we enable the server command being a queue command?
|
||||||
|
# This may require extra setup on bungeecord. See the wiki:
|
||||||
|
# https://wiki.ajg0702.us/ajqueue/setup/replacing-server-command
|
||||||
|
enable-server-command: false
|
||||||
+5
-1
@@ -9,6 +9,8 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
|||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import us.ajg0702.queue.commands.BaseCommand;
|
import us.ajg0702.queue.commands.BaseCommand;
|
||||||
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
|
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
|
||||||
|
import us.ajg0702.queue.commands.commands.listqueues.ListCommand;
|
||||||
|
import us.ajg0702.queue.commands.commands.manage.ManageCommand;
|
||||||
import us.ajg0702.queue.commands.commands.queue.QueueCommand;
|
import us.ajg0702.queue.commands.commands.queue.QueueCommand;
|
||||||
import us.ajg0702.queue.common.QueueMain;
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
import us.ajg0702.queue.platforms.velocity.commands.VelocityCommand;
|
import us.ajg0702.queue.platforms.velocity.commands.VelocityCommand;
|
||||||
@@ -59,7 +61,9 @@ public class VelocityQueue {
|
|||||||
|
|
||||||
List<BaseCommand> commands = Arrays.asList(
|
List<BaseCommand> commands = Arrays.asList(
|
||||||
new QueueCommand(main),
|
new QueueCommand(main),
|
||||||
new LeaveCommand(main)
|
new LeaveCommand(main),
|
||||||
|
new ListCommand(main),
|
||||||
|
new ManageCommand(main)
|
||||||
);
|
);
|
||||||
|
|
||||||
for(BaseCommand command : commands) {
|
for(BaseCommand command : commands) {
|
||||||
|
|||||||
+2
-1
@@ -1,11 +1,11 @@
|
|||||||
package us.ajg0702.queue.platforms.velocity.players;
|
package us.ajg0702.queue.platforms.velocity.players;
|
||||||
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
|
|
||||||
@@ -27,6 +27,7 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(Component message) {
|
public void sendMessage(Component message) {
|
||||||
|
if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return;
|
||||||
handle.sendMessage(message);
|
handle.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -27,14 +27,14 @@ public class VelocityServerPing implements AdaptedServerPing {
|
|||||||
@Override
|
@Override
|
||||||
public int getPlayerCount() {
|
public int getPlayerCount() {
|
||||||
Optional<ServerPing.Players> players = handle.getPlayers();
|
Optional<ServerPing.Players> players = handle.getPlayers();
|
||||||
if(players.isPresent()) return 0;
|
if(!players.isPresent()) return 0;
|
||||||
return players.get().getOnline();
|
return players.get().getOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxPlayers() {
|
public int getMaxPlayers() {
|
||||||
Optional<ServerPing.Players> players = handle.getPlayers();
|
Optional<ServerPing.Players> players = handle.getPlayers();
|
||||||
if(players.isPresent()) return 0;
|
if(!players.isPresent()) return 0;
|
||||||
return players.get().getMax();
|
return players.get().getMax();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user