Added Spigot-side API

This commit is contained in:
ajgeiss0702
2023-05-27 18:14:28 -07:00
parent 9f0881756d
commit c26e5835b7
38 changed files with 1454 additions and 206 deletions
@@ -2,6 +2,7 @@ package us.ajg0702.queue.api;
import us.ajg0702.queue.api.premium.Logic;
import us.ajg0702.queue.api.premium.LogicGetter;
import us.ajg0702.queue.api.spigot.AjQueueSpigotAPI;
import us.ajg0702.queue.api.util.QueueLogger;
import us.ajg0702.utils.common.Config;
import us.ajg0702.utils.common.Messages;
@@ -11,6 +12,7 @@ import java.util.concurrent.ExecutorService;
public abstract class AjQueueAPI {
public static AjQueueAPI INSTANCE;
public static AjQueueSpigotAPI SPIGOT_INSTANCE;
/**
* Gets the instance of the ajQueue API
@@ -21,6 +23,10 @@ public abstract class AjQueueAPI {
return INSTANCE;
}
public static AjQueueSpigotAPI getSpigotInstance() {
return SPIGOT_INSTANCE;
}
/**
* Gets the time that ajQueue will wait between sending players. In seconds
@@ -79,7 +85,6 @@ public abstract class AjQueueAPI {
/**
* Gets the event handler.
*
* This class will probably be replaced in the future with an actual event system
* @return the EventHandler
*/
@@ -0,0 +1,86 @@
package us.ajg0702.queue.api.communication;
import com.google.common.io.ByteArrayDataInput;
import java.util.UUID;
public class ComResponse {
private String from;
private String response;
private String identifier;
private String noneMessage;
private ComResponse(String from, String response) {
this.from = from;
this.response = response;
}
public static ComResponse from(String from) {
return new ComResponse(from, null);
}
public static ComResponse from(String from, ByteArrayDataInput in) {
String id = in.readUTF();
String response = in.readUTF();
String noneMessage = in.readUTF();
if(id.equalsIgnoreCase("null")) id = null;
if(response.equalsIgnoreCase("null")) response = null;
if(noneMessage.equalsIgnoreCase("null")) noneMessage = null;
return from(from)
.id(id)
.with(response)
.noneMessage(noneMessage);
}
public ComResponse id(String id) {
this.identifier = id;
return this;
}
public ComResponse id(UUID id) {
this.identifier = String.valueOf(id);
return this;
}
public ComResponse with(String response) {
this.response = response;
return this;
}
public ComResponse with(boolean response) {
this.response = String.valueOf(response);
return this;
}
public ComResponse with(Integer response) {
this.response = String.valueOf(response);
return this;
}
public ComResponse noneMessage(String message) {
this.noneMessage = message;
return this;
}
public String getIdentifier() {
return identifier;
}
public String getFrom() {
return from;
}
public String getNoneMessage() {
return noneMessage;
}
public String getResponse() {
return response;
}
@Override
public String toString() {
return "ComResponse{" +
"from='" + from + '\'' +
", response='" + response + '\'' +
", identifier='" + identifier + '\'' +
", noneMessage='" + noneMessage + '\'' +
'}';
}
}
@@ -0,0 +1,84 @@
package us.ajg0702.queue.api.spigot;
import java.util.UUID;
import java.util.concurrent.Future;
/**
* An API that is usable from the spigot-side
*/
public abstract class AjQueueSpigotAPI {
public static AjQueueSpigotAPI INSTANCE;
/**
* Gets the instance of the ajQueue spigot API
* @return the ajQueue API
*/
@SuppressWarnings("unused")
public static AjQueueSpigotAPI getInstance() {
return INSTANCE;
}
public abstract Future<Boolean> isInQueue(UUID player);
/**
* Adds a player to a queue
* @param player The player to be added
* @param queueName The server or group to add the player to
* @return True if adding was successful, false if not.
*/
public abstract Future<Boolean> addToQueue(UUID player, String queueName);
/**
* Gets the name of the queue that the player is in
* @param player the player
* @return the name of the queue that the player is in
*/
public abstract Future<MessagedResponse<String>> getQueueName(UUID player);
/**
* Gets the position of the player in their queue
* @param player The player
* @return The position of the player in their queue
*/
public abstract Future<MessagedResponse<Integer>> getPosition(UUID player);
/**
* Gets the total number of players who are in queue with the player
* @param player The player
* @return The number of player in the queue that the player is in.
*/
public abstract Future<MessagedResponse<Integer>> getTotalPositions(UUID player);
/**
* Gets the number of players in a specific queue
* @param queueName The name of the queue
* @return The number of players in that queue.
*/
public abstract Future<Integer> getPlayersInQueue(String queueName);
/**
* Gets the status string for the queue specified (e.g. full, restarting, etc)
* This is the display status, which is meant to be shown to players (and is pulled from the messages file)
* @param queueName the name of the queue
* @return The status string for the queue you specified.
*/
public abstract Future<String> getServerStatusString(String queueName);
/**
* Gets the status string for the queue specified (e.g. full, restarting, etc)
* This is the display status, which is meant to be shown to players (and is pulled from the messages file)
* @param queueName the name of the queue
* @param player the player to check with
* @return The status string for the queue you specified.
*/
public abstract Future<String> getServerStatusString(String queueName, UUID player);
/**
* Gets the estimated time until the player is sent to the server
* @param player The player to get
* @return The estimated time until the player is sent to the server
*/
public abstract Future<MessagedResponse<String>> getEstimatedTime(UUID player);
}
@@ -0,0 +1,36 @@
package us.ajg0702.queue.api.spigot;
public class MessagedResponse<T> {
private final T response;
private final String none;
public MessagedResponse(T response, String none) {
this.response = response;
this.none = none;
}
/**
* Gets the response from the method.
* @return The response. Null if there is a "none" message
*/
public T getResponse() {
return response;
}
/**
* Gets the "none" message
* @return The none message. null if there is a response.
*/
public String getNone() {
return none;
}
/**
* Gets either the response (as a string) or the none message, whichever is available
* @return A string
*/
public String getEither() {
if(response == null) return none;
return String.valueOf(response);
}
}