Add API events system
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package us.ajg0702.queue.api;
|
||||
|
||||
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.spigot.AjQueueSpigotAPI;
|
||||
@@ -114,5 +115,7 @@ public abstract class AjQueueAPI {
|
||||
*/
|
||||
public abstract void shutdown();
|
||||
|
||||
public abstract <E> void listen(Class<E> event, EventReceiver<E> handler);
|
||||
|
||||
public abstract ExecutorService getServersUpdateExecutor();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package us.ajg0702.queue.api.events;
|
||||
|
||||
public interface Cancellable {
|
||||
/**
|
||||
* Whether this event is canceled.
|
||||
* @return True if canceled. False if not.
|
||||
*/
|
||||
boolean isCancelled();
|
||||
|
||||
/**
|
||||
* Allows you to cancel or un-cancel this event
|
||||
* @param cancelled True to cancel the event, false to un-cancel
|
||||
*/
|
||||
void setCancelled(boolean cancelled);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package us.ajg0702.queue.api.events;
|
||||
|
||||
public interface Event {
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package us.ajg0702.queue.api.events;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
|
||||
/**
|
||||
* Called when someone is added or removed from a queue that the player is in, causing the player's position to change
|
||||
*/
|
||||
public class PositionChangeEvent implements Event {
|
||||
private final QueuePlayer player;
|
||||
private final int position;
|
||||
|
||||
public PositionChangeEvent(QueuePlayer player) {
|
||||
this.player = player;
|
||||
position = player.getPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the QueuePlayer object that represents this player
|
||||
* @return the QueuePlayer object
|
||||
*/
|
||||
public QueuePlayer getQueuePlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AdaptedPlayer that this event is about. May return null!
|
||||
* @return The AdaptedPlayer that this event is about. Returns null if the player is offline.
|
||||
*/
|
||||
public @Nullable AdaptedPlayer getPlayer() {
|
||||
return player.getPlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player's new position in the queue
|
||||
* @return The player's new position. 1 being 1st, 2 being 2nd, etc
|
||||
*/
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the queue that this event is from
|
||||
* @return The QueueServer that the player is in that their position changed
|
||||
*/
|
||||
public QueueServer getQueue() {
|
||||
return player.getQueueServer();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package us.ajg0702.queue.api.events;
|
||||
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
|
||||
/**
|
||||
* Called after all checks are made, right before a player is actually added to the queue.
|
||||
* If canceled, the player will not be added to the queue.
|
||||
* If you cancel this event, it is up to you to send a message telling the player why they were not added to the queue.
|
||||
*/
|
||||
public class PreQueueEvent implements Event, Cancellable {
|
||||
private final AdaptedPlayer player;
|
||||
private final QueueServer target;
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public PreQueueEvent(AdaptedPlayer player, QueueServer target) {
|
||||
this.player = player;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that is joining the queue
|
||||
* @return
|
||||
*/
|
||||
public AdaptedPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the target QueueServer that the player is trying to queue for
|
||||
* @return The QueueServer that the player is trying to queue for
|
||||
*/
|
||||
public QueueServer getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package us.ajg0702.queue.api.events;
|
||||
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
|
||||
/**
|
||||
* Called after a player is successfully sent to a server.
|
||||
*/
|
||||
public class SuccessfulSendEvent implements Event {
|
||||
private final QueuePlayer player;
|
||||
private final AdaptedServer server;
|
||||
|
||||
public SuccessfulSendEvent(QueuePlayer player, AdaptedServer server) {
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that was sent
|
||||
* @return the player that was sent
|
||||
*/
|
||||
public AdaptedPlayer getPlayer() {
|
||||
return player.getPlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server that the player was sent to
|
||||
* @return The server that the player was sent to
|
||||
*/
|
||||
public AdaptedServer getServer() {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package us.ajg0702.queue.api.events.utils;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EventReceiver<E> {
|
||||
void execute(E event);
|
||||
}
|
||||
@@ -55,6 +55,12 @@ public interface AdaptedPlayer extends Handle, Audience {
|
||||
*/
|
||||
String getServerName();
|
||||
|
||||
/**
|
||||
* Gets the server that the player is currently connected to
|
||||
* @return The server that the player is currently connected to.
|
||||
*/
|
||||
AdaptedServer getCurrentServer();
|
||||
|
||||
/**
|
||||
* Gets the player's unique id (UUID)
|
||||
* @return The player's uuid
|
||||
|
||||
Reference in New Issue
Block a user