Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. package pl.ahcode.namemc.api;
  2.  
  3. import org.apache.commons.io.IOUtils;
  4. import org.bukkit.command.CommandSender;
  5. import org.bukkit.entity.Player;
  6. import org.json.simple.JSONObject;
  7. import org.json.simple.JSONValue;
  8.  
  9. import pl.ahcode.namemc.database.Config;
  10. import pl.ahcode.namemc.util.ChatUtil;
  11.  
  12. import java.io.BufferedReader;
  13. import java.io.IOException;
  14. import java.io.InputStreamReader;
  15. import java.net.URL;
  16. import java.net.URLConnection;
  17. import java.text.ParseException;
  18.  
  19. public class ConnectionAPI {
  20. public static boolean verifyNamemc(final String uuid) {
  21. try {
  22. final URL url = new URL("https://api.namemc.com/server/"+ Config.SERVER+"/likes?profile=" + uuid);
  23. final URLConnection connection = url.openConnection();
  24. connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
  25. final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  26. String line = null;
  27. boolean ret = false;
  28. while ((line = bufferedReader.readLine()) != null) {
  29. line = line.toLowerCase();
  30. if (line.contains("true")) {
  31. ret = true;
  32. break;
  33. }
  34. }
  35. bufferedReader.close();
  36. return ret;
  37. } catch (Exception ex) {
  38. System.out.println(ex.getMessage());
  39. return false;
  40. }
  41. }
  42. public static String getNameMC_UUID(Player p) {
  43. String url = "https://api.mojang.com/users/profiles/minecraft/"+p.getName();
  44. try {
  45. @SuppressWarnings("deprecation")
  46. String UUIDJson = IOUtils.toString(new URL(url));
  47. if(UUIDJson.isEmpty()) return "invalid name";
  48. JSONObject UUIDObject = (JSONObject) JSONValue.parseWithException(UUIDJson);
  49. return UUIDObject.get("id").toString();
  50. } catch (IOException | org.json.simple.parser.ParseException | IllegalArgumentException e) {
  51. ChatUtil.sendMessage(p, "&8>> &cKomenda tylko dla graczy premium!");
  52. }
  53. return "error";
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement