Use gson for decoding version command

By: md_5 <git@md-5.net>
This commit is contained in:
Bukkit/Spigot
2019-03-23 20:22:06 +11:00
parent 4526a9f21e
commit e86efb4b0b

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 {