forked from public-mirrors/HuskSync
Overhaul API, add JitPack integration for developer API provision
parent
5dbea87ccb
commit
023082e749
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
JV=$(java -version 2>&1 >/dev/null | head -1)
|
||||||
|
echo "$JV" | sed -E 's/^.*version "([^".]*)\.[^"]*".*$/\1/'
|
||||||
|
|
||||||
|
if [ "$JV" != 16 ]; then
|
||||||
|
case "$1" in
|
||||||
|
install)
|
||||||
|
echo "installing sdkman..."
|
||||||
|
curl -s "https://get.sdkman.io" | bash
|
||||||
|
source ~/.sdkman/bin/sdkman-init.sh
|
||||||
|
sdk install java 16.0.1-open
|
||||||
|
;;
|
||||||
|
use)
|
||||||
|
echo "must source ~/.sdkman/bin/sdkman-init.sh"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
@ -0,0 +1,60 @@
|
|||||||
|
package me.william278.husksync.bukkit.api;
|
||||||
|
|
||||||
|
import me.william278.husksync.PlayerData;
|
||||||
|
import me.william278.husksync.Settings;
|
||||||
|
import me.william278.husksync.redis.RedisMessage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API method class for HuskSync. To access methods, use the {@link #getInstance()} entrypoint.
|
||||||
|
*/
|
||||||
|
public class HuskSyncAPI {
|
||||||
|
|
||||||
|
private HuskSyncAPI() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HuskSyncAPI instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API entry point. Returns an instance of the {@link HuskSyncAPI}
|
||||||
|
*
|
||||||
|
* @return instance of the {@link HuskSyncAPI}
|
||||||
|
*/
|
||||||
|
public static HuskSyncAPI getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new HuskSyncAPI();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (INTERNAL) Map of API requests that are processed by the bukkit plugin that implements the API.
|
||||||
|
*/
|
||||||
|
public static HashMap<UUID, CompletableFuture<PlayerData>> apiRequests = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a {@link CompletableFuture} that will fetch the {@link PlayerData} for a user given their {@link UUID}, which contains synchronised data that can then be deserialized into ItemStacks and other usable values using the {@link me.william278.husksync.bukkit.data.DataSerializer} class. If no data could be returned, such as if an invalid UUID is specified, the CompletableFuture will be cancelled. Note that this only returns the last cached data of the user; not necessarily the current state of their inventory if they are online.
|
||||||
|
*
|
||||||
|
* @param playerUUID The {@link UUID} of the player to get data for
|
||||||
|
* @return a {@link CompletableFuture} with the user's {@link PlayerData} accessible on completion
|
||||||
|
* @throws IOException If an exception occurs with serializing during processing of the request
|
||||||
|
*/
|
||||||
|
public CompletableFuture<PlayerData> getPlayerData(UUID playerUUID) throws IOException {
|
||||||
|
final UUID requestUUID = UUID.randomUUID();
|
||||||
|
CompletableFuture<PlayerData> playerDataCompletableFuture = new CompletableFuture<>();
|
||||||
|
playerDataCompletableFuture.whenComplete((playerData, throwable) -> apiRequests.remove(requestUUID));
|
||||||
|
|
||||||
|
// Request the data via the proxy
|
||||||
|
new RedisMessage(RedisMessage.MessageType.API_DATA_REQUEST,
|
||||||
|
new RedisMessage.MessageTarget(Settings.ServerType.PROXY, null, Settings.cluster),
|
||||||
|
playerUUID.toString(), requestUUID.toString()).send();
|
||||||
|
|
||||||
|
apiRequests.put(requestUUID, playerDataCompletableFuture);
|
||||||
|
return playerDataCompletableFuture;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
# This file ensures jitpack builds HuskSync correctly by setting the JDK to 16
|
||||||
|
jdk:
|
||||||
|
- 'openjdk16'
|
||||||
|
before_install:
|
||||||
|
- 'git clone https://github.com/WiIIiam278/HuskSync.git --recurse-submodules'
|
||||||
|
- 'chmod +x gradlew'
|
||||||
|
- 'chmod +x ./.jitpack/ensure-java-16'
|
||||||
|
- 'bash ./.jitpack/ensure-java-16 install'
|
||||||
|
install:
|
||||||
|
- 'if ! ./.jitpack/ensure-java-16 use; then source ~/.sdkman/bin/sdkman-init.sh; fi'
|
||||||
|
- 'java -version'
|
||||||
|
- './gradlew api:clean api:publishToMavenLocal'
|
Loading…
Reference in New Issue