Skip to content

Commit

Permalink
[nolist] Merge pull request #31 from ajgeiss0702/dev
Browse files Browse the repository at this point in the history
2.6.0
  • Loading branch information
ajgeiss0702 authored Oct 21, 2023
2 parents c6976a3 + e67b790 commit 7af094d
Show file tree
Hide file tree
Showing 54 changed files with 1,137 additions and 369 deletions.
20 changes: 20 additions & 0 deletions api/src/main/java/us/ajg0702/queue/api/AjQueueAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import us.ajg0702.queue.api.events.utils.EventReceiver;
import us.ajg0702.queue.api.premium.Logic;
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.util.QueueLogger;
import us.ajg0702.utils.common.Config;
Expand All @@ -12,6 +14,10 @@

public abstract class AjQueueAPI {

public static QueueHolderRegistry queueHolderRegistry = new QueueHolderRegistry();

public static PermissionHookRegistry permissionHookRegistry = new PermissionHookRegistry();

public static AjQueueAPI INSTANCE;
public static AjQueueSpigotAPI SPIGOT_INSTANCE;

Expand Down Expand Up @@ -40,6 +46,12 @@ public static AjQueueSpigotAPI getSpigotInstance() {
*/
public abstract void setTimeBetweenPlayers();

/**
* Gets the server time manager instance, which tracks when players last changed servers
* @return The server time manager instance
*/
public abstract ServerTimeManager getServerTimeManager();

/**
* Gets the ajQueue config
* @return the ajQueue config
Expand Down Expand Up @@ -115,6 +127,14 @@ public static AjQueueSpigotAPI getSpigotInstance() {
*/
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 ExecutorService getServersUpdateExecutor();
Expand Down
6 changes: 0 additions & 6 deletions api/src/main/java/us/ajg0702/queue/api/QueueHolder.java

This file was deleted.

12 changes: 12 additions & 0 deletions api/src/main/java/us/ajg0702/queue/api/ServerTimeManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package us.ajg0702.queue.api;

import us.ajg0702.queue.api.players.AdaptedPlayer;

public interface ServerTimeManager {
/**
* Gets the time that the player specified was last seen switching servers
* @param player The player to check
* @return The time that they last switched servers, in milliseconds since midnight, January 1, 1970, UTC
*/
long getLastServerChange(AdaptedPlayer player);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package us.ajg0702.queue.api.players;

import us.ajg0702.queue.api.queues.QueueServer;
import us.ajg0702.queue.api.server.AdaptedServer;

import javax.annotation.Nullable;
import java.util.UUID;
Expand Down Expand Up @@ -68,4 +69,10 @@ public interface QueuePlayer {
* @return the max number of seconds this player can be offline before being removed from the queue
*/
int getMaxOfflineTime();

/**
* Gets the server that the player was in when they joined the queue
* @return the server that the player was in when they joined the queue
*/
AdaptedServer getInitialServer();
}
7 changes: 6 additions & 1 deletion api/src/main/java/us/ajg0702/queue/api/premium/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface Logic {
*/
PermissionGetter getPermissionGetter();

int getHighestPriority(QueueServer queueServer, AdaptedServer server, AdaptedPlayer player);

static int getUnJoinablePriorities(QueueServer queueServer, AdaptedServer server, AdaptedPlayer player) {
Config config = AjQueueAPI.getInstance().getConfig();
int highest = 0;
Expand All @@ -59,7 +61,10 @@ static int getUnJoinablePriorities(QueueServer queueServer, AdaptedServer server
}

if(fulljoinPriority > 0) {
if(server.isFull() && server.canJoinFull(player)) {
boolean hasMakeRoom = player.hasPermission("ajqueue.make-room") && AjQueueAPI.getInstance().getConfig().getBoolean("enable-make-room-permission");
if(
(server.isFull() && (server.canJoinFull(player) || hasMakeRoom)) ||
(queueServer.isManuallyFull() && (AdaptedServer.canJoinFull(player, queueServer.getName()) || hasMakeRoom))) {
highest = Math.max(highest, fulljoinPriority);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 1 deletion api/src/main/java/us/ajg0702/queue/api/queues/Balancer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package us.ajg0702.queue.api.queues;

import org.jetbrains.annotations.Nullable;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.server.AdaptedServer;

public interface Balancer {
AdaptedServer getIdealServer(AdaptedPlayer player);
AdaptedServer getIdealServer(@Nullable AdaptedPlayer player);
}
23 changes: 21 additions & 2 deletions api/src/main/java/us/ajg0702/queue/api/queues/QueueServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import com.google.common.collect.ImmutableList;
import us.ajg0702.queue.api.players.AdaptedPlayer;
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.AdaptedServerPing;

import java.util.HashMap;
import java.util.List;
import java.util.UUID;

Expand All @@ -19,7 +18,9 @@ public interface QueueServer {
/**
* Get 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();

/**
Expand Down Expand Up @@ -69,6 +70,18 @@ public interface QueueServer {
*/
boolean isJoinable(AdaptedPlayer p);

/**
* Gets the manually-set max player count for this server/group
* @return The manually-set max player count
*/
int getManualMaxPlayers();

/**
* Checks if the total number of players in this server/group is above the manually-set max player count
* @return If the server is at or above the manually-set player limit
*/
boolean isManuallyFull();

/**
* Pauses or unpauses a server
* @param paused true = paused, false = unpaused
Expand Down Expand Up @@ -209,6 +222,12 @@ default boolean isOnline() {
*/
Balancer getBalancer();

/**
* Gets the QueueHolder for this queue
* @return the QueueHolder that holds the queue
*/
QueueHolder getQueueHolder();


/**
* elliot is bad
Expand Down
22 changes: 19 additions & 3 deletions api/src/main/java/us/ajg0702/queue/api/server/AdaptedServer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package us.ajg0702.queue.api.server;

import us.ajg0702.queue.api.AjQueueAPI;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.util.Handle;
import us.ajg0702.queue.api.util.QueueLogger;
Expand Down Expand Up @@ -52,7 +53,20 @@ default CompletableFuture<AdaptedServerPing> ping() {
*/
int getOfflineTime();

boolean canJoinFull(AdaptedPlayer player);
default boolean canJoinFull(AdaptedPlayer player) {
return canJoinFull(player, getName());
}

static boolean canJoinFull(AdaptedPlayer player, String serverName) {
if(player == null) return true;
return
player.hasPermission("ajqueue.joinfull") ||
player.hasPermission("ajqueue.joinfullserver." + serverName) ||
player.hasPermission("ajqueue.joinfullandbypassserver." + serverName) ||
player.hasPermission("ajqueue.joinfullandbypass") ||
(AjQueueAPI.getInstance().isPremium() && AjQueueAPI.getInstance().getLogic().getPermissionGetter().hasUniqueFullBypass(player, serverName))
;
}

boolean justWentOnline();

Expand All @@ -75,14 +89,16 @@ default boolean isFull() {
}

/**
* Gets if the last ping was successfull
* Gets if the last ping was successful
* (which almost always means the server is online)
* @return If the server is determined to be online or not
*/
default boolean isOnline() {
return getLastPing().isPresent();
return getLastPing().isPresent() && !shouldWaitAfterOnline();
}

boolean shouldWaitAfterOnline();

/**
* Gets the number of players currently online
* @return The number of players online
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
}

allprojects {
version = "2.5.0"
version = "2.6.0"
group = "us.ajg0702"

plugins.apply("java")
Expand Down
Loading

0 comments on commit 7af094d

Please sign in to comment.