Compare commits
61 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7af094d1f1 | |||
| e67b790875 | |||
| 2b9e2a9043 | |||
| bfe336f9e5 | |||
| 7eb1a75a35 | |||
| d61ce73cde | |||
| e8ca809cb0 | |||
| b0892dd0d2 | |||
| d769e4a6d7 | |||
| 688641735c | |||
| 8355c7619c | |||
| b3480b6ac2 | |||
| e51ff8dca5 | |||
| cda97662d3 | |||
| c5fd5fb32f | |||
| 52938eeb4d | |||
| c0b736b781 | |||
| de4ff2ba26 | |||
| d95f892cfe | |||
| 1f875fa622 | |||
| 6592925c6d | |||
| 8d7d56a8c6 | |||
| 71c471c407 | |||
| 4fc7ca38ca | |||
| d92d8796fd | |||
| d935ae3370 | |||
| 3a33b7b512 | |||
| 391080483b | |||
| 8fe8713aaf | |||
| a0e8411cc6 | |||
| 567f97f440 | |||
| 89a11c176b | |||
| 46fedd2276 | |||
| 412d173d82 | |||
| fab9cd8d34 | |||
| 06ed22e65f | |||
| 12031cf8dd | |||
| 3e25fd7e2d | |||
| ca36bdfc1f | |||
| 06a4c47072 | |||
| e0c8c29204 | |||
| bc3aa1ffe1 | |||
| 609f1e4b81 | |||
| fa9f594830 | |||
| 49a3812867 | |||
| e5d9df9aa8 | |||
| 0899bf88ed | |||
| 2414c698ed | |||
| 80289de371 | |||
| a99bd73614 | |||
| 429eb354b0 | |||
| 67aece11f0 | |||
| 17c6963889 | |||
| c26e5835b7 | |||
| 9f0881756d | |||
| a91d271932 | |||
| f1c9749c59 | |||
| e9bfeb22b9 | |||
| 786a302a2a | |||
| 1c9a41316c | |||
| 4fd393c4fe |
@@ -3,6 +3,8 @@ package us.ajg0702.queue.api;
|
|||||||
import us.ajg0702.queue.api.events.utils.EventReceiver;
|
import us.ajg0702.queue.api.events.utils.EventReceiver;
|
||||||
import us.ajg0702.queue.api.premium.Logic;
|
import us.ajg0702.queue.api.premium.Logic;
|
||||||
import us.ajg0702.queue.api.premium.LogicGetter;
|
import us.ajg0702.queue.api.premium.LogicGetter;
|
||||||
|
import us.ajg0702.queue.api.premium.PermissionHookRegistry;
|
||||||
|
import us.ajg0702.queue.api.queueholders.QueueHolderRegistry;
|
||||||
import us.ajg0702.queue.api.spigot.AjQueueSpigotAPI;
|
import us.ajg0702.queue.api.spigot.AjQueueSpigotAPI;
|
||||||
import us.ajg0702.queue.api.util.QueueLogger;
|
import us.ajg0702.queue.api.util.QueueLogger;
|
||||||
import us.ajg0702.utils.common.Config;
|
import us.ajg0702.utils.common.Config;
|
||||||
@@ -12,6 +14,10 @@ import java.util.concurrent.ExecutorService;
|
|||||||
|
|
||||||
public abstract class AjQueueAPI {
|
public abstract class AjQueueAPI {
|
||||||
|
|
||||||
|
public static QueueHolderRegistry queueHolderRegistry = new QueueHolderRegistry();
|
||||||
|
|
||||||
|
public static PermissionHookRegistry permissionHookRegistry = new PermissionHookRegistry();
|
||||||
|
|
||||||
public static AjQueueAPI INSTANCE;
|
public static AjQueueAPI INSTANCE;
|
||||||
public static AjQueueSpigotAPI SPIGOT_INSTANCE;
|
public static AjQueueSpigotAPI SPIGOT_INSTANCE;
|
||||||
|
|
||||||
@@ -121,6 +127,14 @@ public abstract class AjQueueAPI {
|
|||||||
*/
|
*/
|
||||||
public abstract void shutdown();
|
public abstract void shutdown();
|
||||||
|
|
||||||
|
public static QueueHolderRegistry getQueueHolderRegistry() {
|
||||||
|
return queueHolderRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PermissionHookRegistry getPermissionHookRegistry() {
|
||||||
|
return permissionHookRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract <E> void listen(Class<E> event, EventReceiver<E> handler);
|
public abstract <E> void listen(Class<E> event, EventReceiver<E> handler);
|
||||||
|
|
||||||
public abstract ExecutorService getServersUpdateExecutor();
|
public abstract ExecutorService getServersUpdateExecutor();
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package us.ajg0702.queue.api;
|
|
||||||
|
|
||||||
public interface QueueHolder {
|
|
||||||
boolean isAvailable();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ public interface ServerTimeManager {
|
|||||||
/**
|
/**
|
||||||
* Gets the time that the player specified was last seen switching servers
|
* Gets the time that the player specified was last seen switching servers
|
||||||
* @param player The player to check
|
* @param player The player to check
|
||||||
* @return The time that they last switched servers, in miliseconds since midnight, January 1, 1970, UTC
|
* @return The time that they last switched servers, in milliseconds since midnight, January 1, 1970, UTC
|
||||||
*/
|
*/
|
||||||
long getLastServerChange(AdaptedPlayer player);
|
long getLastServerChange(AdaptedPlayer player);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package us.ajg0702.queue.api.premium;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PermissionHookRegistry {
|
||||||
|
private final Map<String, PermissionHook> hooks = new HashMap<>();
|
||||||
|
|
||||||
|
public void register(PermissionHook... permissionHooks) {
|
||||||
|
for (PermissionHook hook : permissionHooks) {
|
||||||
|
if(hooks.containsKey(hook.getName())) {
|
||||||
|
throw new IllegalArgumentException("Hook " + hook.getName() + " is already registered!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (PermissionHook hook : permissionHooks) {
|
||||||
|
hooks.put(hook.getName(), hook);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<PermissionHook> getRegisteredHooks() {
|
||||||
|
return hooks.values();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package us.ajg0702.queue.api.queueholders;
|
||||||
|
|
||||||
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
|
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||||
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class QueueHolder {
|
||||||
|
|
||||||
|
private final QueueServer queueServer;
|
||||||
|
|
||||||
|
public QueueHolder(QueueServer queueServer) {
|
||||||
|
this.queueServer = queueServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the identifier of this QueueHolder
|
||||||
|
* Used by the server owner in order to tell ajQueue to use this QueueHolder
|
||||||
|
* @return a string that is very unlikely to be re-used by another QueueHolder
|
||||||
|
*/
|
||||||
|
public abstract String getIdentifier();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a player to the end of the queue
|
||||||
|
* NOTE: Do not manually call this! Use the QueueManager to add players to queues
|
||||||
|
* @param player The QueuePlayer to add
|
||||||
|
*/
|
||||||
|
public abstract void addPlayer(QueuePlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a player to the specified position in the queue
|
||||||
|
* NOTE: Do not manually call this! Use the QueueManager to add players to queues
|
||||||
|
* @param player The QueuePlayer to add
|
||||||
|
* @param position The position to add them to
|
||||||
|
*/
|
||||||
|
public abstract void addPlayer(QueuePlayer player, int position);
|
||||||
|
|
||||||
|
public void removePlayer(AdaptedPlayer player) {
|
||||||
|
removePlayer(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePlayer(UUID uuid) {
|
||||||
|
QueuePlayer player = findPlayer(uuid);
|
||||||
|
if(player == null) return;
|
||||||
|
removePlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a player from the queue
|
||||||
|
* @param player The player to remove
|
||||||
|
*/
|
||||||
|
public abstract void removePlayer(QueuePlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the player with this uuid in this queue and returns the representative QueuePlayer
|
||||||
|
* @return The QueuePlayer representing the player, null if not found
|
||||||
|
*/
|
||||||
|
public abstract QueuePlayer findPlayer(UUID uuid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the player with this username in this queue and returns the representative QueuePlayer
|
||||||
|
* @return The QueuePlayer representing the player, null if not found
|
||||||
|
*/
|
||||||
|
public abstract QueuePlayer findPlayer(String name);
|
||||||
|
|
||||||
|
public QueuePlayer findPlayer(AdaptedPlayer player) {
|
||||||
|
return findPlayer(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the size of the queue
|
||||||
|
* @return The number of players in the queue
|
||||||
|
*/
|
||||||
|
public abstract int getQueueSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all players that are in the queue
|
||||||
|
* @return a list of players in the queue
|
||||||
|
*/
|
||||||
|
public abstract List<QueuePlayer> getAllPlayers();
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package us.ajg0702.queue.api.queueholders;
|
||||||
|
|
||||||
|
import us.ajg0702.queue.api.AjQueueAPI;
|
||||||
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class QueueHolderRegistry {
|
||||||
|
|
||||||
|
private Map<String, Class<? extends QueueHolder>> holders = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a QueueHolder that can be used
|
||||||
|
* @param holder The QueueHolder to register
|
||||||
|
*/
|
||||||
|
public void register(String identifier, Class<? extends QueueHolder> holder) {
|
||||||
|
holders.put(identifier, holder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueueHolder getQueueHolder(QueueServer queueServer) {
|
||||||
|
String queueHolderName = AjQueueAPI.getInstance().getConfig().getString("queue-holder");
|
||||||
|
QueueHolder queueHolder = getQueueHolder(queueHolderName, queueServer);
|
||||||
|
if(queueHolder == null) {
|
||||||
|
AjQueueAPI.getInstance().getLogger().warn("Invalid queue-holder '" + queueHolderName + "'! Using the default one");
|
||||||
|
return getQueueHolder("default", queueServer);
|
||||||
|
}
|
||||||
|
return queueHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueueHolder getQueueHolder(String identifier, QueueServer queueServer) {
|
||||||
|
Class<? extends QueueHolder> holder = holders.get(identifier);
|
||||||
|
if(holder == null) return null;
|
||||||
|
try {
|
||||||
|
return holder.getConstructor(QueueServer.class).newInstance(queueServer);
|
||||||
|
} catch(NoSuchMethodException e) {
|
||||||
|
throw new IllegalArgumentException("QueueHolder " + identifier + " is missing the required constructor!");
|
||||||
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package us.ajg0702.queue.api.queues;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||||
|
import us.ajg0702.queue.api.queueholders.QueueHolder;
|
||||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -17,7 +18,9 @@ public interface QueueServer {
|
|||||||
/**
|
/**
|
||||||
* Get the players who are queued.
|
* Get the players who are queued.
|
||||||
* @return The players who are queued
|
* @return The players who are queued
|
||||||
|
* @deprecated It is recommended to not use this method unless you absolutely have to. If you have to, use getQueueHolder().getAllPlayers()
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
ImmutableList<QueuePlayer> getQueue();
|
ImmutableList<QueuePlayer> getQueue();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -219,6 +222,12 @@ public interface QueueServer {
|
|||||||
*/
|
*/
|
||||||
Balancer getBalancer();
|
Balancer getBalancer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the QueueHolder for this queue
|
||||||
|
* @return the QueueHolder that holds the queue
|
||||||
|
*/
|
||||||
|
QueueHolder getQueueHolder();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* elliot is bad
|
* elliot is bad
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
version = "2.5.0"
|
version = "2.6.0"
|
||||||
group = "us.ajg0702"
|
group = "us.ajg0702"
|
||||||
|
|
||||||
plugins.apply("java")
|
plugins.apply("java")
|
||||||
|
|||||||
+8
-4
@@ -1,6 +1,7 @@
|
|||||||
package us.ajg0702.queue.commands.commands.SlashServer;
|
package us.ajg0702.queue.commands.commands.SlashServer;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
import us.ajg0702.queue.commands.BaseCommand;
|
import us.ajg0702.queue.commands.BaseCommand;
|
||||||
import us.ajg0702.queue.common.QueueMain;
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
@@ -14,6 +15,10 @@ public class SlashServerCommand extends BaseCommand {
|
|||||||
final QueueMain main;
|
final QueueMain main;
|
||||||
final String server;
|
final String server;
|
||||||
final String command;
|
final String command;
|
||||||
|
|
||||||
|
private IBaseCommand moveCommand;
|
||||||
|
|
||||||
|
|
||||||
public SlashServerCommand(QueueMain main, String server) {
|
public SlashServerCommand(QueueMain main, String server) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
@@ -51,11 +56,10 @@ public class SlashServerCommand extends BaseCommand {
|
|||||||
sender.sendMessage(getMessages().getComponent("errors.player-only"));
|
sender.sendMessage(getMessages().getComponent("errors.player-only"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(main.getConfig().getBoolean("require-permission") && !sender.hasPermission("ajqueue.queue."+server)) {
|
if(moveCommand == null) {
|
||||||
sender.sendMessage(getMessages().getComponent("noperm"));
|
moveCommand = main.getPlatformMethods().getCommands().get(0);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
main.getQueueManager().addToQueue(main.getPlatformMethods().senderToPlayer(sender), server);
|
moveCommand.execute(sender, new String[]{server});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package us.ajg0702.queue.common;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||||
|
import us.ajg0702.queue.api.queueholders.QueueHolder;
|
||||||
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
public class DefaultQueueHolder extends QueueHolder {
|
||||||
|
|
||||||
|
List<QueuePlayer> queue = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
public DefaultQueueHolder(QueueServer queueServer) {
|
||||||
|
super(queueServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return "default";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addPlayer(QueuePlayer player) {
|
||||||
|
queue.add(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addPlayer(QueuePlayer player, int position) {
|
||||||
|
queue.add(position, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removePlayer(QueuePlayer player) {
|
||||||
|
queue.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueuePlayer findPlayer(UUID uuid) {
|
||||||
|
for(QueuePlayer queuePlayer : queue) {
|
||||||
|
if(queuePlayer.getUniqueId().toString().equals(uuid.toString())) {
|
||||||
|
return queuePlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueuePlayer findPlayer(String name) {
|
||||||
|
for(QueuePlayer queuePlayer : queue) {
|
||||||
|
if(queuePlayer.getName().equalsIgnoreCase(name)) {
|
||||||
|
return queuePlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getQueueSize() {
|
||||||
|
return queue.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<QueuePlayer> getAllPlayers() {
|
||||||
|
return ImmutableList.copyOf(queue);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -118,7 +118,19 @@ public class EventHandlerImpl implements EventHandler {
|
|||||||
player.hasPermission("ajqueue.queueserver." + to.getName())
|
player.hasPermission("ajqueue.queueserver." + to.getName())
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
main.getQueueManager().addToQueue(player, to);
|
int delay = Math.min(main.getConfig().getInt("queue-server-delay"), 3000);
|
||||||
|
Runnable task = () -> {
|
||||||
|
if(to.getServers().contains(player.getCurrentServer())) return;
|
||||||
|
main.getQueueManager().addToQueue(player, to);
|
||||||
|
};
|
||||||
|
|
||||||
|
Debug.info("Delaying queue-server by " + delay);
|
||||||
|
|
||||||
|
if(delay > 0) {
|
||||||
|
main.getTaskManager().executor.schedule(task, delay, TimeUnit.MILLISECONDS);
|
||||||
|
} else {
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,6 +200,8 @@ public class QueueMain extends AjQueueAPI {
|
|||||||
|
|
||||||
constructMessages();
|
constructMessages();
|
||||||
|
|
||||||
|
getQueueHolderRegistry().register("default", DefaultQueueHolder.class);
|
||||||
|
|
||||||
logic = logicGetter.constructLogic();
|
logic = logicGetter.constructLogic();
|
||||||
aliasManager = logicGetter.constructAliasManager(config);
|
aliasManager = logicGetter.constructAliasManager(config);
|
||||||
|
|
||||||
@@ -339,6 +341,10 @@ public class QueueMain extends AjQueueAPI {
|
|||||||
List<String> oldProtocolNames = config.getStringList("protocol-names");
|
List<String> oldProtocolNames = config.getStringList("protocol-names");
|
||||||
for (String oldProtocolName : oldProtocolNames) {
|
for (String oldProtocolName : oldProtocolNames) {
|
||||||
String[] parts = oldProtocolName.split(":");
|
String[] parts = oldProtocolName.split(":");
|
||||||
|
if(parts.length != 2) {
|
||||||
|
logger.warn("Invalid old (in the config) protocol name '" + oldProtocolName + "'. Skipping.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
String protocol = parts[0];
|
String protocol = parts[0];
|
||||||
String name = parts[1];
|
String name = parts[1];
|
||||||
|
|
||||||
|
|||||||
@@ -470,6 +470,11 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
long lastSwitch = main.getServerTimeManager().getLastServerChange(player);
|
||||||
|
int delay = Math.min(Math.max(main.getConfig().getInt("queue-server-delay"), 0), 3000);
|
||||||
|
if(System.currentTimeMillis() - lastSwitch < delay + 1000 || !player.getCurrentServer().equals(from)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(
|
if(
|
||||||
!getPlayerQueues(player).contains(to) &&
|
!getPlayerQueues(player).contains(to) &&
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package us.ajg0702.queue.common.queues;
|
package us.ajg0702.queue.common.queues;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import us.ajg0702.queue.api.AjQueueAPI;
|
||||||
import us.ajg0702.queue.api.events.PositionChangeEvent;
|
import us.ajg0702.queue.api.events.PositionChangeEvent;
|
||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||||
|
import us.ajg0702.queue.api.queueholders.QueueHolder;
|
||||||
import us.ajg0702.queue.api.queues.Balancer;
|
import us.ajg0702.queue.api.queues.Balancer;
|
||||||
import us.ajg0702.queue.api.queues.QueueServer;
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
@@ -17,7 +19,6 @@ import us.ajg0702.queue.common.utils.Debug;
|
|||||||
import us.ajg0702.utils.common.Messages;
|
import us.ajg0702.utils.common.Messages;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
|
||||||
|
|
||||||
public class QueueServerImpl implements QueueServer {
|
public class QueueServerImpl implements QueueServer {
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
|
|
||||||
private final List<AdaptedServer> servers;
|
private final List<AdaptedServer> servers;
|
||||||
|
|
||||||
private final List<QueuePlayer> queue = new CopyOnWriteArrayList<>();
|
private final QueueHolder queueHolder = AjQueueAPI.getQueueHolderRegistry().getQueueHolder(this);
|
||||||
|
|
||||||
private List<Integer> supportedProtocols = new ArrayList<>();
|
private List<Integer> supportedProtocols = new ArrayList<>();
|
||||||
|
|
||||||
@@ -123,7 +124,7 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableList<QueuePlayer> getQueue() {
|
public ImmutableList<QueuePlayer> getQueue() {
|
||||||
return ImmutableList.copyOf(queue);
|
return ImmutableList.copyOf(queueHolder.getAllPlayers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -248,7 +249,7 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
@Override
|
@Override
|
||||||
public void removePlayer(QueuePlayer player) {
|
public void removePlayer(QueuePlayer player) {
|
||||||
main.getQueueManager().getSendingAttempts().remove(player);
|
main.getQueueManager().getSendingAttempts().remove(player);
|
||||||
queue.remove(player);
|
queueHolder.removePlayer(player);
|
||||||
positionChange();
|
positionChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,12 +267,12 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPlayer(QueuePlayer player, int position) {
|
public void addPlayer(QueuePlayer player, int position) {
|
||||||
if(!player.getQueueServer().equals(this) || queue.contains(player)) return;
|
if(!player.getQueueServer().equals(this) || queueHolder.findPlayer(player.getUniqueId()) != null) return;
|
||||||
|
|
||||||
if(position >= 0) {
|
if(position >= 0) {
|
||||||
queue.add(position, player);
|
queueHolder.addPlayer(player, position);
|
||||||
} else {
|
} else {
|
||||||
queue.add(player);
|
queueHolder.addPlayer(player);
|
||||||
}
|
}
|
||||||
positionChange();
|
positionChange();
|
||||||
}
|
}
|
||||||
@@ -328,12 +329,7 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueuePlayer findPlayer(String player) {
|
public QueuePlayer findPlayer(String player) {
|
||||||
for(QueuePlayer queuePlayer : queue) {
|
return queueHolder.findPlayer(player);
|
||||||
if(queuePlayer.getName().equalsIgnoreCase(player)) {
|
|
||||||
return queuePlayer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public QueuePlayer findPlayer(AdaptedPlayer player) {
|
public QueuePlayer findPlayer(AdaptedPlayer player) {
|
||||||
@@ -341,12 +337,7 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public QueuePlayer findPlayer(UUID uuid) {
|
public QueuePlayer findPlayer(UUID uuid) {
|
||||||
for(QueuePlayer queuePlayer : queue) {
|
return queueHolder.findPlayer(uuid);
|
||||||
if(queuePlayer.getUniqueId().toString().equals(uuid.toString())) {
|
|
||||||
return queuePlayer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -369,9 +360,14 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
return balancer;
|
return balancer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueueHolder getQueueHolder() {
|
||||||
|
return queueHolder;
|
||||||
|
}
|
||||||
|
|
||||||
private void positionChange() {
|
private void positionChange() {
|
||||||
main.getTaskManager().runNow(
|
main.getTaskManager().runNow(
|
||||||
() -> queue.forEach(queuePlayer -> {
|
() -> queueHolder.getAllPlayers().forEach(queuePlayer -> {
|
||||||
if(((QueuePlayerImpl) queuePlayer).lastPosition != queuePlayer.getPosition()) {
|
if(((QueuePlayerImpl) queuePlayer).lastPosition != queuePlayer.getPosition()) {
|
||||||
main.call(new PositionChangeEvent(queuePlayer));
|
main.call(new PositionChangeEvent(queuePlayer));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ auto-add-kick-reasons:
|
|||||||
queue-servers:
|
queue-servers:
|
||||||
- 'limbo:lobbys'
|
- 'limbo:lobbys'
|
||||||
|
|
||||||
|
# How much should we delay queueing players in queue servers?
|
||||||
|
# You should only use this if you have issues with the instant sending.
|
||||||
|
# Set to 0 or any negative number to disable
|
||||||
|
# In milliseconds. Maximum value is 3000 (3 seconds)
|
||||||
|
# Default: 0
|
||||||
|
queue-server-delay: 0
|
||||||
|
|
||||||
# Should we completely kick the user from the server if they are in a queue-server
|
# Should we completely kick the user from the server if they are in a queue-server
|
||||||
# and are kicked from the server with one of the above reasons?
|
# and are kicked from the server with one of the above reasons?
|
||||||
# Note this will do nothing on servers that aren't queue-servers
|
# Note this will do nothing on servers that aren't queue-servers
|
||||||
@@ -290,6 +297,11 @@ require-queueserver-permission: false
|
|||||||
# Default: 10
|
# Default: 10
|
||||||
max-tries: 10
|
max-tries: 10
|
||||||
|
|
||||||
|
# What QueueHolder should we use?
|
||||||
|
# By default, the only QueueHolder available is 'default'
|
||||||
|
# But more may be available via addons (registered via the API)
|
||||||
|
queue-holder: default
|
||||||
|
|
||||||
|
|
||||||
# Should we enable the ajqueue.make-room permission?
|
# Should we enable the ajqueue.make-room permission?
|
||||||
# The make-room permission will force there to be room in a server.
|
# The make-room permission will force there to be room in a server.
|
||||||
@@ -377,7 +389,7 @@ debug: false
|
|||||||
|
|
||||||
|
|
||||||
# Don't touch this number please
|
# Don't touch this number please
|
||||||
config-version: 42
|
config-version: 44
|
||||||
|
|
||||||
|
|
||||||
# This is ONLY here so that they can be moved to messages.yml. Please edit these in messages.yml!
|
# This is ONLY here so that they can be moved to messages.yml. Please edit these in messages.yml!
|
||||||
|
|||||||
+10
-10
@@ -1,9 +1,11 @@
|
|||||||
package us.ajg0702.queue.logic.permissions;
|
package us.ajg0702.queue.logic.permissions;
|
||||||
|
|
||||||
|
import us.ajg0702.queue.api.AjQueueAPI;
|
||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
import us.ajg0702.queue.api.premium.PermissionGetter;
|
import us.ajg0702.queue.api.premium.PermissionGetter;
|
||||||
import us.ajg0702.queue.api.premium.PermissionHook;
|
import us.ajg0702.queue.api.premium.PermissionHook;
|
||||||
import us.ajg0702.queue.common.QueueMain;
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
|
import us.ajg0702.queue.common.utils.Debug;
|
||||||
import us.ajg0702.queue.logic.permissions.hooks.AquaCoreHook;
|
import us.ajg0702.queue.logic.permissions.hooks.AquaCoreHook;
|
||||||
import us.ajg0702.queue.logic.permissions.hooks.BuiltInHook;
|
import us.ajg0702.queue.logic.permissions.hooks.BuiltInHook;
|
||||||
import us.ajg0702.queue.logic.permissions.hooks.LuckPermsHook;
|
import us.ajg0702.queue.logic.permissions.hooks.LuckPermsHook;
|
||||||
@@ -13,16 +15,15 @@ import java.util.*;
|
|||||||
|
|
||||||
public class PermissionGetterImpl implements PermissionGetter {
|
public class PermissionGetterImpl implements PermissionGetter {
|
||||||
|
|
||||||
private final List<PermissionHook> hooks;
|
|
||||||
|
|
||||||
private final QueueMain main;
|
private final QueueMain main;
|
||||||
|
private PermissionHook builtInHook;
|
||||||
public PermissionGetterImpl(QueueMain main) {
|
public PermissionGetterImpl(QueueMain main) {
|
||||||
hooks = Arrays.asList(
|
AjQueueAPI.getPermissionHookRegistry().register(
|
||||||
new BuiltInHook(main),
|
|
||||||
new LuckPermsHook(main),
|
new LuckPermsHook(main),
|
||||||
new UltraPermissionsHook(main),
|
new UltraPermissionsHook(main),
|
||||||
new AquaCoreHook(main)
|
new AquaCoreHook(main)
|
||||||
);
|
);
|
||||||
|
builtInHook = new BuiltInHook(main);
|
||||||
this.main = main;
|
this.main = main;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,16 +31,15 @@ public class PermissionGetterImpl implements PermissionGetter {
|
|||||||
@Override
|
@Override
|
||||||
public PermissionHook getSelected() {
|
public PermissionHook getSelected() {
|
||||||
if(selected != null) return selected;
|
if(selected != null) return selected;
|
||||||
if(hooks == null) {
|
for(PermissionHook hook : AjQueueAPI.getPermissionHookRegistry().getRegisteredHooks()) {
|
||||||
throw new IllegalStateException("Hooks are not initialized yet!");
|
boolean canUse = hook.canUse();
|
||||||
}
|
Debug.info(hook.getName() + " "+ canUse);
|
||||||
for(PermissionHook hook : hooks) {
|
if(canUse) {
|
||||||
if(hook.canUse()) {
|
|
||||||
selected = hook;
|
selected = hook;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(selected == null) {
|
if(selected == null) {
|
||||||
throw new IllegalStateException("All hooks are unusable!");
|
selected = builtInHook;
|
||||||
}
|
}
|
||||||
main.getLogger().info("Using "+selected.getName()+" for permissions.");
|
main.getLogger().info("Using "+selected.getName()+" for permissions.");
|
||||||
return selected;
|
return selected;
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ public class EstimatedTime extends Placeholder {
|
|||||||
cache.put(p.getUniqueId(), response.getEither());
|
cache.put(p.getUniqueId(), response.getEither());
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (TimeoutException ignored) {}
|
} catch (TimeoutException | IllegalArgumentException ignored) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
return cache.getOrDefault(p.getUniqueId(), "...");
|
return cache.getOrDefault(p.getUniqueId(), "...");
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class InQueue extends Placeholder {
|
|||||||
cache.put(p.getUniqueId(), response + "");
|
cache.put(p.getUniqueId(), response + "");
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (TimeoutException ignored) {}
|
} catch (TimeoutException | IllegalArgumentException ignored) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
return cache.getOrDefault(p.getUniqueId(), "...");
|
return cache.getOrDefault(p.getUniqueId(), "...");
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ public class Position extends Placeholder {
|
|||||||
cache.put(p.getUniqueId(), response.getEither());
|
cache.put(p.getUniqueId(), response.getEither());
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (TimeoutException ignored) {}
|
} catch (TimeoutException | IllegalArgumentException ignored) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
return cache.getOrDefault(p.getUniqueId(), "...");
|
return cache.getOrDefault(p.getUniqueId(), "...");
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ public class PositionOf extends Placeholder {
|
|||||||
cache.put(p.getUniqueId(), response.getEither());
|
cache.put(p.getUniqueId(), response.getEither());
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (TimeoutException ignored) {}
|
} catch (TimeoutException | IllegalArgumentException ignored) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
return cache.getOrDefault(p.getUniqueId(), "...");
|
return cache.getOrDefault(p.getUniqueId(), "...");
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class Queued extends Placeholder {
|
|||||||
cache.put(p.getUniqueId(), response.getEither());
|
cache.put(p.getUniqueId(), response.getEither());
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (TimeoutException ignored) {}
|
} catch (TimeoutException | IllegalArgumentException ignored) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
return cache.getOrDefault(p.getUniqueId(), "...");
|
return cache.getOrDefault(p.getUniqueId(), "...");
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class Status extends Placeholder {
|
|||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} catch (TimeoutException ignored) {}
|
} catch (TimeoutException | IllegalArgumentException ignored) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
return cached;
|
return cached;
|
||||||
|
|||||||
+1
-1
@@ -47,7 +47,7 @@ public class StatusPlayer extends Placeholder {
|
|||||||
cache.put(key, response);
|
cache.put(key, response);
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (TimeoutException ignored) {}
|
} catch (TimeoutException | IllegalArgumentException ignored) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
return cache.getOrDefault(key, "...");
|
return cache.getOrDefault(key, "...");
|
||||||
|
|||||||
Reference in New Issue
Block a user