Alias Posted January 9, 2021 Share Posted January 9, 2021 (edited) This is a simple class that can be used to convert String names into Item ID's or visa versa There are a few edge cases where there is more than one ID for the same item so that is a possibility if you're using this. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import com.google.gson.JsonObject; import com.google.gson.JsonParser; public class ItemConverter { private final static String URL = "https://rsbuddy.com/exchange/summary.json"; private final JsonObject json; public ItemConverter() { this.json = new JsonParser().parse(getJson()).getAsJsonObject(); } public int getID(final String item) { for (String key : json.keySet()) { final JsonObject obj = json.get(key).getAsJsonObject(); if (obj.get("name").getAsString().equals(item)) { return obj.get("id").getAsInt(); } } return -1; } public String getName(final int itemId) { for (String key : json.keySet()) { final JsonObject obj = json.get(key).getAsJsonObject(); if (obj.get("id").getAsInt() == itemId) { return obj.get("name").getAsString(); } } return ""; } private String getJson() { try { final URL url = new URL(URL); final BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String inputLine; String out = null; while ((inputLine = in.readLine()) != null) { out = inputLine; } in.close(); return out; } catch (IOException e) { e.printStackTrace(); } return null; } } Edited January 9, 2021 by Alias 2 1 Quote Link to comment Share on other sites More sharing options...
Sellout Posted January 9, 2021 Share Posted January 9, 2021 thx for sharing 🙂 Quote Link to comment Share on other sites More sharing options...
Proto Posted January 9, 2021 Share Posted January 9, 2021 16 hours ago, Alias said: This is a simple class that can be used to convert String names into Item ID's or visa versa There are a few edge cases where there is more than one ID for the same item so that is a possibility if you're using this. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import com.google.gson.JsonObject; import com.google.gson.JsonParser; public class ItemConverter { private final static String URL = "https://rsbuddy.com/exchange/summary.json"; private final JsonObject json; public ItemConverter() { this.json = new JsonParser().parse(getJson()).getAsJsonObject(); } public int getID(final String item) { for (String key : json.keySet()) { final JsonObject obj = json.get(key).getAsJsonObject(); if (obj.get("name").getAsString().equals(item)) { return obj.get("id").getAsInt(); } } return -1; } public String getName(final int itemId) { for (String key : json.keySet()) { final JsonObject obj = json.get(key).getAsJsonObject(); if (obj.get("id").getAsInt() == itemId) { return obj.get("name").getAsString(); } } return ""; } private String getJson() { try { final URL url = new URL(URL); final BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String inputLine; String out = null; while ((inputLine = in.readLine()) != null) { out = inputLine; } in.close(); return out; } catch (IOException e) { e.printStackTrace(); } return null; } } can this sort out this equation? x³+y³+z³=k Nice btw 😛 Quote Link to comment Share on other sites More sharing options...
Alias Posted January 9, 2021 Author Share Posted January 9, 2021 2 minutes ago, Proto said: x³+y³+z³=k where k=33, the answer is: (8,866,128,975,287,528)³ + (–8,778,405,442,862,239)³ + (–2,736,111,468,807,040)³ = 33. 1 Quote Link to comment Share on other sites More sharing options...
Proto Posted January 9, 2021 Share Posted January 9, 2021 Just now, Alias said: where k=33, the answer is: (8,866,128,975,287,528)³ + (–8,778,405,442,862,239)³ + (–2,736,111,468,807,040)³ = 33. Huge brain 💦 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.