Mirror von
https://github.com/TheSilentPro/HeadDB.git
synchronisiert 2024-12-27 11:20:05 +01:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # pom.xml # src/main/java/tsp/headdb/event/DatabaseUpdateEvent.java
Dieser Commit ist enthalten in:
Commit
f5ddfdf167
@ -1,12 +1,12 @@
|
||||
package tsp.headdb.database;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import tsp.headdb.api.Head;
|
||||
import tsp.headdb.event.DatabaseUpdateEvent;
|
||||
import tsp.headdb.util.Log;
|
||||
@ -18,6 +18,7 @@ import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -157,21 +158,13 @@ public class HeadDatabase {
|
||||
long start = System.currentTimeMillis();
|
||||
List<Head> heads = new ArrayList<>();
|
||||
try {
|
||||
String line;
|
||||
StringBuilder response = new StringBuilder();
|
||||
|
||||
URLConnection connection = new URL("https://minecraft-heads.com/scripts/api.php?cat=" + category.getName() + "&tags=true").openConnection();
|
||||
connection.setConnectTimeout(timeout);
|
||||
connection.setRequestProperty("User-Agent", plugin.getName() + "-DatabaseUpdater");
|
||||
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
while ((line = in.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
}
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONArray array = (JSONArray) parser.parse(response.toString());
|
||||
for (Object o : array) {
|
||||
JSONObject obj = (JSONObject) o;
|
||||
|
||||
JsonArray array = JsonParser.parseReader(new BufferedReader(new InputStreamReader(connection.getInputStream()))).getAsJsonArray();
|
||||
for (JsonElement entry : array) {
|
||||
JsonObject obj = entry.getAsJsonObject();
|
||||
String rawUUID = obj.get("uuid").toString();
|
||||
|
||||
UUID uuid;
|
||||
@ -194,7 +187,7 @@ public class HeadDatabase {
|
||||
|
||||
long elapsed = (System.currentTimeMillis() - start);
|
||||
Log.debug(category.getName() + " -> Done! Time: " + elapsed + "ms (" + TimeUnit.MILLISECONDS.toSeconds(elapsed) + "s)");
|
||||
} catch (ParseException | IOException e) {
|
||||
} catch (IOException e) {
|
||||
Log.error("[" + plugin.getName() + "] Failed to fetch heads (no-cache) | Stack Trace:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -211,7 +204,7 @@ public class HeadDatabase {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, task -> getHeadsNoCacheAsync(heads -> {
|
||||
if (heads == null) {
|
||||
Log.error("[" + plugin.getName() + "] Failed to update database! Check above for any errors.");
|
||||
result.accept(null);
|
||||
result.accept(Collections.emptyMap());
|
||||
return;
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren