mirror of
https://github.com/ashhhleyyy/player-pronouns.git
synced 2024-11-01 07:07:38 +00:00
Update to PronounDB's v2 API.
This commit is contained in:
parent
a467a4d50d
commit
1cffd3895b
1 changed files with 22 additions and 23 deletions
|
@ -40,27 +40,15 @@ public class PlayerPronouns implements ModInitializer, PronounsApi.PronounReader
|
||||||
private static final String USER_AGENT = "player-pronouns/1.0 (+https://ashhhleyyy.dev/projects/2021/player-pronouns)";
|
private static final String USER_AGENT = "player-pronouns/1.0 (+https://ashhhleyyy.dev/projects/2021/player-pronouns)";
|
||||||
|
|
||||||
private static final Map<String, String> PRONOUNDB_ID_MAP = new HashMap<>() {{
|
private static final Map<String, String> PRONOUNDB_ID_MAP = new HashMap<>() {{
|
||||||
// short pronoun set identifier map from https://pronoundb.org/docs
|
// short pronoun set identifier map from https://pronoundb.org/wiki/api-docs
|
||||||
put("hh", "he/him");
|
put("he", "he/him");
|
||||||
put("hi", "he/it");
|
put("it", "it/its");
|
||||||
put("hs", "he/she");
|
put("she", "she/her");
|
||||||
put("ht", "he/they");
|
put("they", "they/them");
|
||||||
put("ih", "it/he");
|
|
||||||
put("ii", "it/its");
|
|
||||||
put("is", "it/she");
|
|
||||||
put("it", "it/they");
|
|
||||||
put("shh", "she/he");
|
|
||||||
put("sh", "she/her");
|
|
||||||
put("si", "she/it");
|
|
||||||
put("st", "she/they");
|
|
||||||
put("th", "they/he");
|
|
||||||
put("ti", "they/it");
|
|
||||||
put("ts", "they/she");
|
|
||||||
put("tt", "they/them");
|
|
||||||
put("any", "any");
|
put("any", "any");
|
||||||
put("other", "other");
|
|
||||||
put("ask", "ask");
|
put("ask", "ask");
|
||||||
put("avoid", "avoid");
|
put("avoid", "avoid");
|
||||||
|
put("other", "other");
|
||||||
}};
|
}};
|
||||||
|
|
||||||
private PronounDatabase pronounDatabase;
|
private PronounDatabase pronounDatabase;
|
||||||
|
@ -101,7 +89,7 @@ public class PlayerPronouns implements ModInitializer, PronounsApi.PronounReader
|
||||||
var currentPronouns = pronounDatabase.get(handler.getPlayer().getUuid());
|
var currentPronouns = pronounDatabase.get(handler.getPlayer().getUuid());
|
||||||
if (currentPronouns != null && !currentPronouns.remote()) return;
|
if (currentPronouns != null && !currentPronouns.remote()) return;
|
||||||
|
|
||||||
var pronounDbUrl = "https://pronoundb.org/api/v1/lookup?platform=minecraft&id=%s"
|
var pronounDbUrl = "https://pronoundb.org/api/v2/lookup?platform=minecraft&ids=%s"
|
||||||
.formatted(handler.getPlayer().getUuid());
|
.formatted(handler.getPlayer().getUuid());
|
||||||
try {
|
try {
|
||||||
var client = HttpClient.newBuilder()
|
var client = HttpClient.newBuilder()
|
||||||
|
@ -122,10 +110,21 @@ public class PlayerPronouns implements ModInitializer, PronounsApi.PronounReader
|
||||||
if (currentPronouns2 != null && !currentPronouns2.remote()) return;
|
if (currentPronouns2 != null && !currentPronouns2.remote()) return;
|
||||||
|
|
||||||
var json = JsonHelper.deserialize(body);
|
var json = JsonHelper.deserialize(body);
|
||||||
var pronounsResponse = json.get("pronouns").getAsString();
|
StringBuilder pronouns = new StringBuilder("unspecified");
|
||||||
if (!"unspecified".equals(pronounsResponse)) {
|
if (json.has(handler.getPlayer().getUuid().toString()) && json.getAsJsonObject(handler.getPlayer().getUuid().toString()).getAsJsonObject("sets").has("en")) {
|
||||||
var pronouns = PRONOUNDB_ID_MAP.getOrDefault(pronounsResponse, "ask");
|
var pronounsList = json.getAsJsonObject(handler.getPlayer().getUuid().toString()).getAsJsonObject("sets").getAsJsonArray("en");
|
||||||
setPronouns(handler.getPlayer(), new Pronouns(pronouns, PronounList.get().getCalculatedPronounStrings().get(pronouns), true));
|
if (pronounsList.size() == 1) {
|
||||||
|
pronouns = new StringBuilder(PRONOUNDB_ID_MAP.get(pronounsList.get(0).getAsString()));
|
||||||
|
} else {
|
||||||
|
pronouns = new StringBuilder();
|
||||||
|
for (var prounoun: pronounsList) {
|
||||||
|
pronouns.append(prounoun.getAsString()).append("/");
|
||||||
|
}
|
||||||
|
pronouns = new StringBuilder(pronouns.substring(0, pronouns.length() - 1)); // remove trailing slash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!"unspecified".contentEquals(pronouns)) {
|
||||||
|
setPronouns(handler.getPlayer(), new Pronouns(pronouns.toString(), PronounList.get().getCalculatedPronounStrings().get(pronouns.toString()), true));
|
||||||
}
|
}
|
||||||
}, server);
|
}, server);
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
|
|
Loading…
Reference in a new issue