-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nolist] Merge pull request #31 from ajgeiss0702/dev
2.6.0
- Loading branch information
Showing
54 changed files
with
1,137 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
api/src/main/java/us/ajg0702/queue/api/ServerTimeManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
api/src/main/java/us/ajg0702/queue/api/premium/PermissionHookRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
api/src/main/java/us/ajg0702/queue/api/queueholders/QueueHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
44 changes: 44 additions & 0 deletions
44
api/src/main/java/us/ajg0702/queue/api/queueholders/QueueHolderRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.