Use gson for decoding version command

This commit is contained in:
md_5 2019-03-23 20:22:06 +11:00
parent 0eaf10f193
commit 451bd74e46

View file

@ -15,6 +15,9 @@ import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.io.Resources; import com.google.common.io.Resources;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
@ -24,9 +27,6 @@ import java.util.Set;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class VersionCommand extends BukkitCommand { public class VersionCommand extends BukkitCommand {
public VersionCommand(@NotNull String name) { public VersionCommand(@NotNull String name) {
@ -241,9 +241,9 @@ public class VersionCommand extends BukkitCommand {
Charsets.UTF_8 Charsets.UTF_8
).openBufferedStream(); ).openBufferedStream();
try { try {
JSONObject obj = (JSONObject) new JSONParser().parse(reader); JsonObject obj = new Gson().fromJson(reader, JsonObject.class);
return ((Number) obj.get("totalCount")).intValue(); return obj.get("totalCount").getAsInt();
} catch (ParseException ex) { } catch (JsonSyntaxException ex) {
ex.printStackTrace(); ex.printStackTrace();
return -1; return -1;
} finally { } finally {