Guest Luiis Postado Maio 18, 2015 Denunciar Postado Maio 18, 2015 Olá, vim trazer para vocês uma api, ela consiste em pegar a uuid real do jogador, ex: "Quero pegar a uuid de um jogador offline, ó senhor, quem irá me defender?", kk brincadeiras a parte ela acessa a api da mojang e pega esta uuid, só não vai tentar usar isto em servidor pirata né filhão. public class UUIDUtils implements Callable<Map<String, UUID>> { private static final double PROFILES_PER_REQUEST = 100; private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; private final JSONParser jsonParser = new JSONParser(); private final List<String> names; private final boolean rateLimiting; public UUIDUtils(List<String> names, boolean rateLimiting) { this.names = ImmutableList.copyOf(names); this.rateLimiting = rateLimiting; } public UUIDUtils(List<String> names) { this(names, true); } public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<String, UUID>(); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body); JSONArray array = (JSONArray) jsonParser .parse(new InputStreamReader(connection.getInputStream())); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDUtils.getUUID(id); uuidMap.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } return uuidMap; } private static void writeBody(HttpURLConnection connection, String body) throws Exception { OutputStream stream = connection.getOutputStream(); stream.write(body.getBytes()); stream.flush(); stream.close(); } private static HttpURLConnection createConnection() throws Exception { URL url = new URL(PROFILE_URL); 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 UUID getUUID(String id) { return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32)); } public static byte[] toBytes(UUID uuid) { ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); byteBuffer.putLong(uuid.getMostSignificantBits()); byteBuffer.putLong(uuid.getLeastSignificantBits()); return byteBuffer.array(); } public static UUID fromBytes(byte[] array) { if (array.length != 16) { throw new IllegalArgumentException("Illegal byte array length: " + array.length); } ByteBuffer byteBuffer = ByteBuffer.wrap(array); long mostSignificant = byteBuffer.getLong(); long leastSignificant = byteBuffer.getLong(); return new UUID(mostSignificant, leastSignificant); } public static UUID getUUIDOf(String name) throws Exception { return new UUIDUtils(Arrays.asList(name)).call().get(name); } } Ou se quiser Clique Aqui Não vou ensinar a utilizar pois somente os que entendem um pouco mais vão conseguir utilizar, e aposto que já sabem pelo menos entender o código *Lembrando que não fui eu que criei o código, por mais que seja um código fácil envolvendo JSON não fui eu que criei. Aconselho também usa-lo em threads para que o servidor não fique esperando a resposta e possa assim causar algum lag.
Guest Luiis Postado Maio 18, 2015 Denunciar Postado Maio 18, 2015 Vou usar em servidor pirata iae x1? kkk
Guest Henrique Postado Maio 18, 2015 Denunciar Postado Maio 18, 2015 O Bukkit tem uma interface chamada OfflinePlayer e ela tem essas funções
Guest Luiis Postado Maio 18, 2015 Denunciar Postado Maio 18, 2015 O Bukkit tem uma interface chamada OfflinePlayer e ela tem essas funções Só que ela não retorna a uuid real do jogador, ela nunca vai retornar algo nulo, mas retorna uma uuid fake vamos assim dizer. Se quiser faça um teste pra ver
Ysko Postado Setembro 20, 2024 Denunciar Postado Setembro 20, 2024 ANÁLISE DE INATIVIDADE Este tópico foi automaticamente arquivado devido à inatividade. Para manter a organização e fluidez das discussões na comunidade, tópicos que permanecem sem novas interações por um período prolongado são fechados automaticamente. Se houver interesse em retomar o conteúdo, sinta-se à vontade para criar um novo tópico ou entre em contato com a equipe da comunidade para reabrir este tópico. Equipe de Moderação Gamer's Board
Posts Recomendados