Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java
  • Loading branch information
ajgeiss0702 committed Jun 3, 2024
2 parents 2b0d6ce + 50f854f commit 6892c50
Show file tree
Hide file tree
Showing 54 changed files with 919 additions and 278 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ jobs:
# The desired behavior if no files are found using the provided path.
if-no-files-found: error
retention-days: 2
- name: Download changelogs
run: |
curl "https://ajg0702.us/pl/updater/changelogs.php?project=${{ github.repository }}" > changelogs.bb
curl "https://ajg0702.us/pl/updater/changelogs.php?project=${{ github.repository }}&format=html" > changelogs.html
- name: Deploy to Polymart/Modrinth
env:
POLYMART_TOKEN: ${{ secrets.POLYMART_TOKEN }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
export VERSION=`cat build.gradle.kts | grep "version " | awk -F'"' '{print $2}'`
curl --no-progress-meter -A "AJUPDATER/1.0" -H "Authorization: $MODRINTH_TOKEN" -F data="{\"project_id\": \"dzacATni\", \"version_number\": \"$VERSION\", \"name\": \"v$VERSION\", \"changelog\": \"$(cat changelogs.html)\", \"file_parts\": [\"file\"], \"version_type\": \"release\", \"loaders\": [\"bungeecord\", \"velocity\"], \"featured\": true, \"game_versions\": $(curl https://ajg0702.us/pl/updater/mc-versions.php), \"dependencies\": [], \"primary_file\": \"file\"}" -F "file=@free/build/libs/ajQueue-$VERSION.jar" "https://api.modrinth.com/v2/version"
curl -F "file=@free/build/libs/ajQueue-$VERSION.jar" -F api_key=$POLYMART_TOKEN -F resource_id="2535" -F version="$VERSION" -F title="v$VERSION" -F message="$(cat changelogs.bb)" "https://api.polymart.org/v1/postUpdate"
curl -F "file=@premium/build/libs/ajQueuePlus-$VERSION.jar" -F api_key=$POLYMART_TOKEN -F resource_id="2714" -F version="$VERSION" -F title="v$VERSION" -F message="$(cat changelogs.bb)" "https://api.polymart.org/v1/postUpdate"
curl -v --no-progress-meter -H "Content-Type: application/json" --request POST -d "{\"content\": \"<@&861713403080999003>\", \"embeds\": [{\"title\": \"${{ github.event.repository.name }} v$VERSION\", \"description\": \"Changelogs\n\n$(curl "https://ajg0702.us/pl/updater/changelogs.php?project=${{ github.repository }}&format=markdown")\n\n[Modrinth (free)](https://modrinth.com/plugin/ajQueue/version/$VERSION)\n[Polymart (free)](https://polymart.org/resource/2535/updates)\n[Polymart (plus)](https://polymart.org/resource/2714/updates)\", \"color\": 14845503, \"thumbnail\": {\"url\": \"https://ajg0702.us/pl/icons/${{ github.event.repository.name }}.png\"}}]}" "$DISCORD_WEBHOOK"
# - name: Download changelogs
# run: |
# curl "https://ajg0702.us/pl/updater/changelogs.php?project=${{ github.repository }}" > changelogs.bb
# curl "https://ajg0702.us/pl/updater/changelogs.php?project=${{ github.repository }}&format=html" > changelogs.html
# - name: Deploy to Polymart/Modrinth
# env:
# POLYMART_TOKEN: ${{ secrets.POLYMART_TOKEN }}
# MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
# DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
# run: |
# export VERSION=`cat build.gradle.kts | grep "version " | awk -F'"' '{print $2}'`
# curl --no-progress-meter -A "AJUPDATER/1.0" -H "Authorization: $MODRINTH_TOKEN" -F data="{\"project_id\": \"dzacATni\", \"version_number\": \"$VERSION\", \"name\": \"v$VERSION\", \"changelog\": \"$(cat changelogs.html)\", \"file_parts\": [\"file\"], \"version_type\": \"release\", \"loaders\": [\"bungeecord\", \"velocity\"], \"featured\": true, \"game_versions\": $(curl https://ajg0702.us/pl/updater/mc-versions.php), \"dependencies\": [], \"primary_file\": \"file\"}" -F "file=@free/build/libs/ajQueue-$VERSION.jar" "https://api.modrinth.com/v2/version"
# curl -F "file=@free/build/libs/ajQueue-$VERSION.jar" -F api_key=$POLYMART_TOKEN -F resource_id="2535" -F version="$VERSION" -F title="v$VERSION" -F message="$(cat changelogs.bb)" "https://api.polymart.org/v1/postUpdate"
# curl -F "file=@premium/build/libs/ajQueuePlus-$VERSION.jar" -F api_key=$POLYMART_TOKEN -F resource_id="2714" -F version="$VERSION" -F title="v$VERSION" -F message="$(cat changelogs.bb)" "https://api.polymart.org/v1/postUpdate"
# curl -v --no-progress-meter -H "Content-Type: application/json" --request POST -d "{\"content\": \"<@&861713403080999003>\", \"embeds\": [{\"title\": \"${{ github.event.repository.name }} v$VERSION\", \"description\": \"Changelogs\n\n$(curl "https://ajg0702.us/pl/updater/changelogs.php?project=${{ github.repository }}&format=markdown")\n\n[Modrinth (free)](https://modrinth.com/plugin/ajQueue/version/$VERSION)\n[Polymart (free)](https://polymart.org/resource/2535/updates)\n[Polymart (plus)](https://polymart.org/resource/2714/updates)\", \"color\": 14845503, \"thumbnail\": {\"url\": \"https://ajg0702.us/pl/icons/${{ github.event.repository.name }}.png\"}}]}" "$DISCORD_WEBHOOK"
6 changes: 3 additions & 3 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ java {
}

dependencies {
implementation("net.kyori:adventure-api:4.13.1")
implementation("net.kyori:adventure-text-serializer-plain:4.13.1")
implementation("net.kyori:adventure-api:4.15.0")
implementation("net.kyori:adventure-text-serializer-plain:4.15.0")
compileOnly("com.google.guava:guava:30.1.1-jre")

compileOnly("us.ajg0702:ajUtils:1.2.14")
compileOnly("us.ajg0702:ajUtils:1.2.25")
}

publishing {
Expand Down
4 changes: 4 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 @@ -10,6 +10,8 @@
import us.ajg0702.utils.common.Config;
import us.ajg0702.utils.common.Messages;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

public abstract class AjQueueAPI {
Expand Down Expand Up @@ -122,6 +124,8 @@ public static AjQueueSpigotAPI getSpigotInstance() {
*/
public abstract ProtocolNameManager getProtocolNameManager();

public abstract Map<String, List<String>> getQueueServers();

/**
* Tells ajQueue to shut down.
*/
Expand Down
7 changes: 5 additions & 2 deletions api/src/main/java/us/ajg0702/queue/api/EventHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package us.ajg0702.queue.api;

import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.server.AdaptedServer;

Expand All @@ -16,8 +17,10 @@ public interface EventHandler {
* Called when a player joins a server or switches between servers
* @param player the player
*/
void
onPlayerJoinServer(AdaptedPlayer player);
void onPlayerJoinServer(AdaptedPlayer player);

void onServerKick(AdaptedPlayer player, AdaptedServer from, Component reason, boolean moving);

@Nullable
AdaptedServer changeTargetServer(AdaptedPlayer player, AdaptedServer initialChoice);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

public interface ProtocolNameManager {
String getProtocolName(int protocol);
HashMap<Integer, String> getProtocolNames();
}
15 changes: 12 additions & 3 deletions api/src/main/java/us/ajg0702/queue/api/QueueManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,31 @@ public interface QueueManager {
* Adds a player to a queue
* @param player The player to be added
* @param server The server or group to add the player to
* @return True if adding was successfull, false if not.
* @return True if adding was successful, false if not.
*/
boolean addToQueue(AdaptedPlayer player, QueueServer server);

/**
* Adds a player to a queue
* @param player The player to be added
* @param serverName The name of the server or group to add the player too
* @return True if adding was successfull, false if not.
* @return True if adding was successful, false if not.
*/
@SuppressWarnings("UnusedReturnValue")
boolean addToQueue(AdaptedPlayer player, String serverName);

/**
* Checks if a player would be sent instantly if they were to join the queue right now
* @param player the player to check
* @param queueServer The QueueServer to check for
* @return if the player would be sent instantly if they join the queue now
*/
boolean canSendInstantly(AdaptedPlayer player, QueueServer queueServer);


/**
* Gets a list of QueueServers (servers and groups)
* @return A list of QueueServerss
* @return A list of QueueServers
*/
ImmutableList<QueueServer> getServers();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package us.ajg0702.queue.api.events;

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

/**
* Called before AjQueue auto-queues a player for a server. (on player kick)
* Use Case: View/Change the server that the player is auto-queued for.
* If canceled, the player will not be queued to any server.
* If you cancel this event, it is up to you to send a message telling the player why they were not auto-queued.
*/
@SuppressWarnings("unused")
public class AutoQueueOnKickEvent implements Event, Cancellable {
private final AdaptedPlayer player;
private String targetServer;

private boolean cancelled = false;

public AutoQueueOnKickEvent(AdaptedPlayer player, String targetServer) {
this.player = player;
this.targetServer = targetServer;
}

/**
* @return the player that is being re-queued
*/
public AdaptedPlayer getPlayer() {
return player;
}

/**
* @return The name of the server AjQueue will queue the player for.
*/
public String getTargetServer() {
return targetServer;
}

/**
* Set the name of the server AjQueue will queue the player for.
* @param targetServer The name of the server to queue the player for.
*/
public void setTargetServer(String targetServer) {
this.targetServer = targetServer;
}

public boolean isCancelled() {
return cancelled;
}

public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package us.ajg0702.queue.api.events;

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

import java.util.*;

/**
* Called before AjQueue attempts to re-compile its list of QueueServers
* Use Case: Add/Remove an AdaptedServer from being registered as a QueueServer.
*/
@SuppressWarnings("unused")
public class BuildServersEvent implements Event {
private final Map<String, AdaptedServer> servers = new HashMap<>();
private final Map<String, List<AdaptedServer>> groups = new HashMap<>();

public BuildServersEvent(List<? extends AdaptedServer> servers) {
// Compile a map of server names to servers
for(AdaptedServer server : servers) {
this.servers.put(server.getName(), server);
}
}

/**
* @see #addServer(AdaptedServer)
* @see #removeServer(AdaptedServer)
* @see #removeServer(String)
* @return an immutable view of the servers that will be registered as QueueServers.
*/
public List<AdaptedServer> getServers() {
return Collections.unmodifiableList(new ArrayList<>(servers.values()));
}

/**
* Add a server to be registered as a QueueServer.
* @param server The server to add
* @return The previous AdaptedServer with that name, or null if there was no previous server
*/
public @Nullable AdaptedServer addServer(AdaptedServer server) {
return servers.put(server.getName(), server);
}

/**
* Remove a server, preventing it from being registered as a QueueServer.
* @param server The AdaptedServer to remove
* @return true if the server was removed, false if it was not found
*/
public boolean removeServer(AdaptedServer server) {
return servers.remove(server.getName()) != null;
}

/**
* Remove a server, preventing it from being registered as a QueueServer.
* @param name The name of the server to remove
* @return true if the server was removed, false if it was not found
*/
public boolean removeServer(String name) {
return servers.remove(name) != null;
}


/**
* @see #addGroup(String, List)
* @see #removeGroup(String)
* @return an immutable list of the sets of servers that will be registered as group QueueServers.
*/
public List<List<AdaptedServer>> getGroups() {
return Collections.unmodifiableList(new ArrayList<>(groups.values()));
}

/**
* Used internally
*/
public Set<Map.Entry<String, List<AdaptedServer>>> groupEntrySet() {
return groups.entrySet();
}

/**
* Add a server-group to be registered by the Queue Manager.
* @param name The name of the server-group
* @param servers The servers to add to the group
* @return The previous server list with that name, or null if there was no previous data
*/
public @Nullable List<AdaptedServer> addGroup(String name, List<AdaptedServer> servers) {
return groups.put(name, servers);
}

/**
* Remove a server, preventing it from being registered as a QueueServer.
* @param name The name of the server to remove
* @return true if the server was removed, false if it was not found
*/
public boolean removeGroup(String name) {
return groups.remove(name) != null;
}

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

import org.jetbrains.annotations.NotNull;
import us.ajg0702.queue.api.players.QueuePlayer;
import us.ajg0702.queue.api.server.AdaptedServer;

/**
* Called before AjQueue attempts to connect a player to an AdaptedServer (via Bungee or Velocity)
* You can use setTargetServer to provide a custom AdaptedServer object for the player to connect to.
* If canceled, the player will not be connected to the target server.
* If you cancel this event, it is up to you to send a message telling the player why they were not connected.
*/
@SuppressWarnings("unused")
public class PreConnectEvent implements Event, Cancellable {
private @NotNull AdaptedServer targetServer;
private final @NotNull QueuePlayer queuePlayer;

private boolean cancelled = false;

public PreConnectEvent(@NotNull AdaptedServer targetServer, @NotNull QueuePlayer queuePlayer) {
this.targetServer = targetServer;
this.queuePlayer = queuePlayer;
}

/**
* Set the target server to connect the player to. (Override default behavior with a custom server)
*
* @param targetServer the target server (AdaptedServer)
*/
public void setTargetServer(@NotNull AdaptedServer targetServer) {
this.targetServer = targetServer;
}

/**
* @return The target server that the player is trying to connect to
*/
public @NotNull AdaptedServer getTargetServer() {
return targetServer;
}

/**
* @return The player that is being connected to the server
*/
public @NotNull QueuePlayer getPlayer() {
return queuePlayer;
}

public boolean isCancelled() {
return cancelled;
}

public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package us.ajg0702.queue.api.events;

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

/**
* Event that is called when priorities are calculated.
* You can provide dynamic priorities for your players based on your own criteria
* instead of just permissions<br>
* <br>
* Just listen to this event, and use the addPriority method to add a priority.
* If it is higher than a player's other priorities, it will be used.<br>
* <br>
* If running ajQueue (not ajQueuePlus), then any number bigger than 0 will count as priority
*/
public class PriorityCalculationEvent implements Event {
private final AdaptedPlayer player;
private int highestPriority;

public PriorityCalculationEvent(AdaptedPlayer player, int highestPriority) {
this.player = player;
this.highestPriority = highestPriority;
}

/**
* Gets the current highest priority
* @return The highest priority number
*/
public int getHighestPriority() {
return highestPriority;
}

/**
* Adds a priority. Does nothing if the priority is lower than the player already has
* @param priority the priority to add
*/
public void addPriority(int priority) {
if(priority < highestPriority) return; // do nothing if this isnt going to change the highest priority
highestPriority = priority;
}
}
Loading

0 comments on commit 6892c50

Please sign in to comment.