From c64946173b09c04bc10d007c32d90e1879f3b6d3 Mon Sep 17 00:00:00 2001 From: darbyjack Date: Fri, 25 Sep 2020 19:08:56 -0500 Subject: [PATCH] Implemented working version for 1.8.8 - 1.16.3 --- .../commands/impl/local/CommandDump.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java index d3c3637..48ab55e 100644 --- a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandDump.java @@ -21,7 +21,17 @@ package me.clip.placeholderapi.commands.impl.local; import com.google.common.io.CharStreams; -import com.google.gson.JsonParser; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -41,20 +51,15 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.logging.Level; import java.util.stream.Collectors; -import me.clip.placeholderapi.PlaceholderAPIPlugin; -import me.clip.placeholderapi.commands.PlaceholderCommand; -import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import me.clip.placeholderapi.util.Msg; -import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Unmodifiable; public final class CommandDump extends PlaceholderCommand { @NotNull private static final String URL = "https://paste.helpch.at/"; + @NotNull + private static final Gson gson = new Gson(); + @NotNull private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter .ofLocalizedDateTime(FormatStyle.LONG) @@ -102,9 +107,8 @@ public final class CommandDump extends PlaceholderCommand { try (final InputStream stream = connection.getInputStream()) { //noinspection UnstableApiUsage - final String json = CharStreams - .toString(new InputStreamReader(stream, StandardCharsets.UTF_8)); - return JsonParser.parseString(json).getAsJsonObject().get("key").getAsString(); + final String json = CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8)); + return gson.fromJson(json, JsonObject.class).get("key").getAsString(); } } catch (final IOException ex) { throw new CompletionException(ex);