get current player from UUID
This commit is contained in:
parent
705150f7ad
commit
810ce8adb9
3 changed files with 18 additions and 34 deletions
24
build.gradle
24
build.gradle
|
@ -1,6 +1,5 @@
|
|||
plugins {
|
||||
id 'fabric-loom' version '0.7-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
@ -67,26 +66,3 @@ jar {
|
|||
rename { "${it}_${project.archivesBaseName}"}
|
||||
}
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
// add all the jars that should be included when publishing to maven
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
|
||||
repositories {
|
||||
// Add repositories to publish to here.
|
||||
// Notice: This block does NOT have the same function as the block in the top level.
|
||||
// The repositories here will be used for publishing your artifact, not for
|
||||
// retrieving dependencies.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class TagCommand extends EaaModCommand{
|
|||
Text text = null;
|
||||
try {
|
||||
String playerUUID = PlayerInfo.playerNameToUUID(player);
|
||||
String playerName = PlayerInfo.playerUUIDToName(playerUUID);
|
||||
String playerName = PlayerInfo.playerUUIDToCurrentName(playerUUID);
|
||||
|
||||
text = Text.of("You tagged player " + playerName + " : " + playerUUID);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.saltymc.eaa.util.mojangApi;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.apache.http.HttpResponse;
|
||||
|
@ -13,14 +13,13 @@ import org.apache.http.util.EntityUtils;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerInfo {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
|
||||
public static String playerNameToUUID(String playerName) throws MojangUtilException {
|
||||
|
||||
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||
|
@ -46,20 +45,29 @@ public class PlayerInfo {
|
|||
}
|
||||
}
|
||||
|
||||
public static String playerUUIDToName(String playerUUID) throws MojangUtilException{
|
||||
public static List<String> playerUUIDToNames(String playerUUID) throws MojangUtilException {
|
||||
try {
|
||||
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||
HttpGet request = new HttpGet("https://api.mojang.com/user/profiles/" + playerUUID.toString().replaceAll("-", "") + "/names");
|
||||
HttpResponse response = httpClient.execute(request);
|
||||
|
||||
List<String> ret = new ArrayList<>();
|
||||
|
||||
// take the response body as a json formatted string
|
||||
JsonObject responseJSON = new JsonParser().parse(EntityUtils.toString(response.getEntity())).getAsJsonArray().get(0).getAsJsonObject();
|
||||
for (JsonElement responseJSON : new JsonParser().parse(EntityUtils.toString(response.getEntity())).getAsJsonArray())
|
||||
ret.add(responseJSON.getAsJsonObject().get("name").getAsString());
|
||||
|
||||
return ret;
|
||||
|
||||
return responseJSON.get("name").getAsString();
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Could not parse UUID to username!", e);
|
||||
throw new MojangUtilException("Could not parse UUID to username!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String playerUUIDToCurrentName(String playerUUID) throws MojangUtilException {
|
||||
List<String> playernames = playerUUIDToNames(playerUUID);
|
||||
|
||||
return playernames.get(playernames.size() - 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue