List of usage examples for org.json.simple JSONArray toJSONString
public static String toJSONString(List list)
From source file:com.jadarstudios.rankcapes.bukkit.network.packet.S2PacketAvailableCapes.java
public void setCapes(List<String> capes) { this.capes = JSONArray.toJSONString(capes); }
From source file:de.Keyle.MyPet.util.player.UUIDFetcher.java
public static Map<String, UUID> call(List<String> names) { names = new ArrayList<String>(names); Iterator<String> iterator = names.iterator(); while (iterator.hasNext()) { String playerName = iterator.next(); if (fetchedUUIDs.containsKey(playerName)) { iterator.remove();//from w ww . ja v a2s.c om } } if (names.size() == 0) { return readonlyFetchedUUIDs; } int count = names.size(); DebugLogger.info("get UUIDs for " + names.size() + " player(s)"); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); try { 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())); count -= array.size(); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); fetchedUUIDs.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } } catch (InterruptedException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } if (count > 0) { MyPetLogger.write("Can not get UUIDs for " + count + " players. Pets of these player may be lost."); } return readonlyFetchedUUIDs; }
From source file:net.agentlv.namemanager.util.UUIDFetcher.java
public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<>(); 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);//w w w. j a v a2 s . c o m 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 = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }
From source file:com.codelanx.playtime.callable.UUIDFetcher.java
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);/* w w w . j a v a2s . c o m*/ 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 = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }
From source file:com.turt2live.hurtle.uuid.UUIDFetcher.java
public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<>(); 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);/* ww w . j av a2s . c o m*/ 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 = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }
From source file:com.mstiles92.plugins.stileslib.player.UUIDFetcher.java
public Map<String, UUID> execute() { Map<String, UUID> results = new HashMap<>(); try {/* ww w .j a va 2 s .co m*/ BasicHttpClient client = new BasicHttpClient(new URL("https://api.mojang.com/profiles/minecraft")); client.addHeader("Content-Type", "application/json"); int requests = (int) Math.ceil((double) usernames.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { int start = i * PROFILES_PER_REQUEST; int end = Math.min((i + 1) * PROFILES_PER_REQUEST, usernames.size()); client.setBody(JSONArray.toJSONString(usernames.subList(start, end))); String response = client.post(); JSONArray responseJson = (JSONArray) new JSONParser().parse(response); for (Object o : responseJson) { JSONObject profile = (JSONObject) o; String id = (String) profile.get("id"); String name = (String) profile.get("name"); results.put(name, getUUID(id)); } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return results; }
From source file:com.gmail.ferusgrim.util.UuidGrabber.java
public Map<String, UUID> call() throws Exception { JSONParser jsonParser = new JSONParser(); Map<String, UUID> responseMap = new HashMap<String, UUID>(); URL url = new URL("https://api.mojang.com/profiles/minecraft"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setUseCaches(false);//from w ww .ja v a 2 s.c o m connection.setDoInput(true); connection.setDoOutput(true); String body = JSONArray.toJSONString(this.namesToLookup); OutputStream stream = connection.getOutputStream(); stream.write(body.getBytes()); stream.flush(); stream.close(); 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 = Grab.uuidFromResult(id); responseMap.put(name, uuid); } return responseMap; }
From source file:com.publicuhc.pluginframework.util.UUIDFetcher.java
public Map<String, UUID> call() throws IOException, ParseException, InterruptedException { Map<String, UUID> playerMap = new HashMap<String, UUID>(); int requests = (int) Math.ceil(m_names.size() / QUERIES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = getConnection(); String query = JSONArray .toJSONString(m_names.subList(i * 100, Math.min((i + 1) * 100, m_names.size()))); writeQuery(connection, query);/*from ww w . j a va 2 s.co m*/ JSONArray parsedArray = (JSONArray) m_jsonParser .parse(new InputStreamReader(connection.getInputStream())); for (Object player : parsedArray) { JSONObject jsonPlayer = (JSONObject) player; String id = (String) jsonPlayer.get("id"); String name = (String) jsonPlayer.get("name"); UUID playerID = UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32)); playerMap.put(name, playerID); } if (i != requests - 1) { Thread.sleep(100L); } } return playerMap; }
From source file:com.kodyhusky.kodymc.UUIDFetcher.java
@Override @SuppressWarnings("SleepWhileInLoop") public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<>(); 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);//from w w w . ja va 2 s. c o m JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); for (Iterator it = array.iterator(); it.hasNext();) { Object profile = it.next(); JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }
From source file:com.cnaude.mutemanager.UUIDFetcher.java
@Override public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<>(); 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);/*w w w . j av a 2 s. c o m*/ 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 = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }