Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.ahcode.namemc.api;
- import org.apache.commons.io.IOUtils;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.json.simple.JSONObject;
- import org.json.simple.JSONValue;
- import pl.ahcode.namemc.database.Config;
- import pl.ahcode.namemc.util.ChatUtil;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import java.text.ParseException;
- public class ConnectionAPI {
- public static boolean verifyNamemc(final String uuid) {
- try {
- final URL url = new URL("https://api.namemc.com/server/"+ Config.SERVER+"/likes?profile=" + uuid);
- final URLConnection connection = url.openConnection();
- 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");
- final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String line = null;
- boolean ret = false;
- while ((line = bufferedReader.readLine()) != null) {
- line = line.toLowerCase();
- if (line.contains("true")) {
- ret = true;
- break;
- }
- }
- bufferedReader.close();
- return ret;
- } catch (Exception ex) {
- System.out.println(ex.getMessage());
- return false;
- }
- }
- public static String getNameMC_UUID(Player p) {
- String url = "https://api.mojang.com/users/profiles/minecraft/"+p.getName();
- try {
- @SuppressWarnings("deprecation")
- String UUIDJson = IOUtils.toString(new URL(url));
- if(UUIDJson.isEmpty()) return "invalid name";
- JSONObject UUIDObject = (JSONObject) JSONValue.parseWithException(UUIDJson);
- return UUIDObject.get("id").toString();
- } catch (IOException | org.json.simple.parser.ParseException | IllegalArgumentException e) {
- ChatUtil.sendMessage(p, "&8>> &cKomenda tylko dla graczy premium!");
- }
- return "error";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement