mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-19 14:59:20 +00:00
You can now fetch xuid by gamertag and gamertag by xuid
This commit is contained in:
@@ -27,6 +27,7 @@ package org.geysermc.floodgate.api;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import org.geysermc.cumulus.Form;
|
import org.geysermc.cumulus.Form;
|
||||||
import org.geysermc.cumulus.util.FormBuilder;
|
import org.geysermc.cumulus.util.FormBuilder;
|
||||||
import org.geysermc.floodgate.api.link.PlayerLink;
|
import org.geysermc.floodgate.api.link.PlayerLink;
|
||||||
@@ -94,6 +95,42 @@ public interface FloodgateApi {
|
|||||||
|
|
||||||
boolean sendForm(UUID uuid, FormBuilder<?, ?> formBuilder);
|
boolean sendForm(UUID uuid, FormBuilder<?, ?> formBuilder);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the xuid of the user that has the given gamertag.
|
||||||
|
*
|
||||||
|
* @param gamertag the gamertag of the player
|
||||||
|
* @return the xuid of the player with the given gamertag, or null when there is no player with
|
||||||
|
* the given gamertag
|
||||||
|
*/
|
||||||
|
CompletableFuture<Long> getXuidFor(String gamertag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the xuid of the player that has the given gamertag. It does the same thing as {@link
|
||||||
|
* #getXuidFor(String)} except that this method will return the xuid in Floodgate uuid format
|
||||||
|
* instead of just a long
|
||||||
|
*
|
||||||
|
* @param gamertag the gamertag of the player
|
||||||
|
* @return the xuid of the player with the given gamertag, or null when there is no player with
|
||||||
|
* the given gamertag
|
||||||
|
*/
|
||||||
|
default CompletableFuture<UUID> getUuidFor(String gamertag) {
|
||||||
|
return getXuidFor(gamertag).thenApply(xuid -> {
|
||||||
|
if (xuid == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return createJavaPlayerId(xuid);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the gamertag of the user that has the given xuid.
|
||||||
|
*
|
||||||
|
* @param xuid the gamertag of the player
|
||||||
|
* @return the gamertag of the player with the given xuid, or null when there is not player with
|
||||||
|
* the given xuid
|
||||||
|
*/
|
||||||
|
CompletableFuture<String> getGamertagFor(long xuid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the instance that manages all the linking.
|
* Returns the instance that manages all the linking.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -26,10 +26,12 @@
|
|||||||
package org.geysermc.floodgate.api;
|
package org.geysermc.floodgate.api;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.geysermc.cumulus.Form;
|
import org.geysermc.cumulus.Form;
|
||||||
@@ -39,6 +41,8 @@ import org.geysermc.floodgate.config.FloodgateConfigHolder;
|
|||||||
import org.geysermc.floodgate.player.FloodgatePlayerImpl;
|
import org.geysermc.floodgate.player.FloodgatePlayerImpl;
|
||||||
import org.geysermc.floodgate.pluginmessage.PluginMessageManager;
|
import org.geysermc.floodgate.pluginmessage.PluginMessageManager;
|
||||||
import org.geysermc.floodgate.pluginmessage.channel.FormChannel;
|
import org.geysermc.floodgate.pluginmessage.channel.FormChannel;
|
||||||
|
import org.geysermc.floodgate.util.Constants;
|
||||||
|
import org.geysermc.floodgate.util.HttpUtils;
|
||||||
import org.geysermc.floodgate.util.Utils;
|
import org.geysermc.floodgate.util.Utils;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -105,6 +109,50 @@ public class SimpleFloodgateApi implements FloodgateApi {
|
|||||||
return sendForm(uuid, formBuilder.build());
|
return sendForm(uuid, formBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Long> getXuidFor(String gamertag) {
|
||||||
|
if (gamertag == null || gamertag.isEmpty() || gamertag.length() > 16) {
|
||||||
|
return Utils.failedFuture(new IllegalStateException("Received an invalid gamertag"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return HttpUtils.asyncGet(Constants.GET_XUID_URL + gamertag)
|
||||||
|
.thenApply(result -> {
|
||||||
|
JsonObject response = result.getResponse();
|
||||||
|
boolean success = response.get("success").getAsBoolean();
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
throw new IllegalStateException(response.get("message").getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject data = response.getAsJsonObject("data");
|
||||||
|
if (data.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.get("xuid").getAsLong();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> getGamertagFor(long xuid) {
|
||||||
|
return HttpUtils.asyncGet(Constants.GET_GAMERTAG_URL + xuid)
|
||||||
|
.thenApply(result -> {
|
||||||
|
JsonObject response = result.getResponse();
|
||||||
|
boolean success = response.get("success").getAsBoolean();
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
throw new IllegalStateException(response.get("message").getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject data = response.getAsJsonObject("data");
|
||||||
|
if (data.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.get("gamertag").getAsString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public FloodgatePlayer addPlayer(UUID uuid, FloodgatePlayer player) {
|
public FloodgatePlayer addPlayer(UUID uuid, FloodgatePlayer player) {
|
||||||
return players.put(uuid, player);
|
return players.put(uuid, player);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public final class Constants {
|
|||||||
private static final String API_BASE_URL = "s://api.geysermc.org";
|
private static final String API_BASE_URL = "s://api.geysermc.org";
|
||||||
public static final String WEBSOCKET_URL = "ws" + API_BASE_URL + "/ws";
|
public static final String WEBSOCKET_URL = "ws" + API_BASE_URL + "/ws";
|
||||||
public static final String GET_XUID_URL = "http" + API_BASE_URL + "/v1/xbox/xuid/";
|
public static final String GET_XUID_URL = "http" + API_BASE_URL + "/v1/xbox/xuid/";
|
||||||
|
public static final String GET_GAMERTAG_URL = "http" + API_BASE_URL + "/v1/xbox/gamertag/";
|
||||||
|
|
||||||
public static final String LINK_INFO_URL = "https://link.geysermc.org/";
|
public static final String LINK_INFO_URL = "https://link.geysermc.org/";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user