Remove the UUID fetcher code. Its useless now
This commit is contained in:
parent
8ac42f97c1
commit
4e381f9d60
@ -4,7 +4,6 @@ import java.lang.reflect.Field;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -41,7 +40,6 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
|||||||
public class DisguiseUtilities {
|
public class DisguiseUtilities {
|
||||||
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<Integer, HashSet<TargetedDisguise>>();
|
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<Integer, HashSet<TargetedDisguise>>();
|
||||||
private static LibsDisguises libsDisguises;
|
private static LibsDisguises libsDisguises;
|
||||||
private static HashMap<String, String> namesUuids = new HashMap<String, String>();
|
|
||||||
// A internal storage of fake entity ID's I can use.
|
// A internal storage of fake entity ID's I can use.
|
||||||
// Realistically I could probably use a ID like "4" for everyone, seeing as no one shares the ID
|
// Realistically I could probably use a ID like "4" for everyone, seeing as no one shares the ID
|
||||||
private static HashMap<UUID, Integer> selfDisguisesIds = new HashMap<UUID, Integer>();
|
private static HashMap<UUID, Integer> selfDisguisesIds = new HashMap<UUID, Integer>();
|
||||||
@ -312,45 +310,6 @@ public class DisguiseUtilities {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*else if (disguise != null) {
|
|
||||||
if (namesUuids.containsKey(playerName)) {
|
|
||||||
if (namesUuids.get(playerName) != null) {
|
|
||||||
return UUID.fromString(namesUuids.get(playerName));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Add null so that if this is called again. I already know I'm doing something about it
|
|
||||||
namesUuids.put(playerName, null);
|
|
||||||
Bukkit.getScheduler().scheduleAsyncDelayedTask(libsDisguises, new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(playerName));
|
|
||||||
try {
|
|
||||||
final HashMap<String, UUID> map = fetcher.call();
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if (map.containsKey(playerName)) {
|
|
||||||
if (namesUuids.containsKey(playerName) && namesUuids.get(playerName) == null) {
|
|
||||||
namesUuids.put(playerName, map.get(playerName).toString());
|
|
||||||
}
|
|
||||||
if (DisguiseUtilities.isDisguiseInUse(disguise)) {
|
|
||||||
DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise);
|
|
||||||
if (disguise.getEntity() instanceof Player && disguise.isSelfDisguiseVisible()) {
|
|
||||||
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (namesUuids.containsKey(playerName) && namesUuids.get(playerName) == null) {
|
|
||||||
namesUuids.remove(playerName);
|
|
||||||
}
|
|
||||||
System.out.print("[LibsDisguises] Error when fetching " + playerName + "'s uuid from mojang: "
|
|
||||||
+ e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.JSONValue;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
public class UUIDFetcher implements Callable<HashMap<String, UUID>> {
|
|
||||||
private static final String AGENT = "minecraft";
|
|
||||||
private static final int MAX_SEARCH = 100;
|
|
||||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/page/";
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static String buildBody(List<String> names) {
|
|
||||||
List<JSONObject> lookups = new ArrayList<JSONObject>();
|
|
||||||
for (String name : names) {
|
|
||||||
JSONObject obj = new JSONObject();
|
|
||||||
obj.put("name", name);
|
|
||||||
obj.put("agent", AGENT);
|
|
||||||
lookups.add(obj);
|
|
||||||
}
|
|
||||||
return JSONValue.toJSONString(lookups);
|
|
||||||
}
|
|
||||||
private static HttpURLConnection createConnection(int page) throws Exception {
|
|
||||||
URL url = new URL(PROFILE_URL + page);
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
|
||||||
connection.setUseCaches(false);
|
|
||||||
connection.setDoInput(true);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void writeBody(HttpURLConnection connection, String body) throws Exception {
|
|
||||||
DataOutputStream writer = new DataOutputStream(connection.getOutputStream());
|
|
||||||
writer.write(body.getBytes());
|
|
||||||
writer.flush();
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final JSONParser jsonParser = new JSONParser();
|
|
||||||
|
|
||||||
private final List<String> names;
|
|
||||||
|
|
||||||
public UUIDFetcher(List<String> names) {
|
|
||||||
this.names = ImmutableList.copyOf(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, UUID> call() throws Exception {
|
|
||||||
HashMap<String, UUID> uuidMap = new HashMap<String, UUID>();
|
|
||||||
String body = buildBody(names);
|
|
||||||
for (int i = 1; i < MAX_SEARCH; i++) {
|
|
||||||
HttpURLConnection connection = createConnection(i);
|
|
||||||
writeBody(connection, body);
|
|
||||||
JSONObject jsonObject = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
|
||||||
JSONArray array = (JSONArray) jsonObject.get("profiles");
|
|
||||||
Number count = (Number) jsonObject.get("size");
|
|
||||||
if (count.intValue() == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (Object profile : array) {
|
|
||||||
JSONObject jsonProfile = (JSONObject) profile;
|
|
||||||
String id = (String) jsonProfile.get("id");
|
|
||||||
String name = (String) jsonProfile.get("name");
|
|
||||||
UUID uuid = UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-"
|
|
||||||
+ id.substring(16, 20) + "-" + id.substring(20, 32));
|
|
||||||
uuidMap.put(name, uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uuidMap;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user