mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-30 14:03:23 +01:00
Remove unused imports in SongodaAuth and apply code formatting
This commit is contained in:
parent
d9586cfe86
commit
6145021ecb
@ -1,44 +1,31 @@
|
|||||||
package com.songoda.core.utils;
|
package com.songoda.core.utils;
|
||||||
|
|
||||||
import com.songoda.core.commands.AbstractCommand;
|
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SongodaAuth {
|
public class SongodaAuth {
|
||||||
|
|
||||||
public static boolean isAuthorized(boolean allowOffline) {
|
public static boolean isAuthorized(boolean allowOffline) {
|
||||||
String productId = "%%__PLUGIN__%%";
|
String productId = "%%__PLUGIN__%%";
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(productId);
|
Integer.parseInt(productId);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
//Self compiled, return true
|
// Self compiled
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = getUUID();
|
UUID uuid = getUUID();
|
||||||
try {
|
try {
|
||||||
URL url = new URL("https://marketplace.songoda.com/api/v2/products/license/validate");
|
URL url = new URL("https://marketplace.songoda.com/api/v2/products/license/validate");
|
||||||
@ -55,10 +42,11 @@ public class SongodaAuth {
|
|||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) {
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) {
|
||||||
StringBuilder response = new StringBuilder();
|
StringBuilder response = new StringBuilder();
|
||||||
String responseLine = null;
|
String responseLine;
|
||||||
while ((responseLine = br.readLine()) != null) {
|
while ((responseLine = br.readLine()) != null) {
|
||||||
response.append(responseLine.trim());
|
response.append(responseLine.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString());
|
JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString());
|
||||||
if (jsonObject.get("error") != null) {
|
if (jsonObject.get("error") != null) {
|
||||||
//Got an error, return false and print error
|
//Got an error, return false and print error
|
||||||
@ -99,14 +87,15 @@ public class SongodaAuth {
|
|||||||
con.setRequestMethod("GET");
|
con.setRequestMethod("GET");
|
||||||
con.setRequestProperty("Accept", "application/json");
|
con.setRequestProperty("Accept", "application/json");
|
||||||
con.setDoOutput(true);
|
con.setDoOutput(true);
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) {
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) {
|
||||||
StringBuilder response = new StringBuilder();
|
StringBuilder response = new StringBuilder();
|
||||||
String responseLine = null;
|
String responseLine;
|
||||||
while ((responseLine = br.readLine()) != null) {
|
while ((responseLine = br.readLine()) != null) {
|
||||||
response.append(responseLine.trim());
|
response.append(responseLine.trim());
|
||||||
}
|
}
|
||||||
JSONParser parser = new JSONParser();
|
|
||||||
JSONObject jsonObject = (JSONObject) parser.parse(response.toString());
|
JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString());
|
||||||
return jsonObject.get("ip").toString();
|
return jsonObject.get("ip").toString();
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user