Skip to content

Commit

Permalink
Merge branch '2.x' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
JRoy authored Jan 24, 2025
2 parents 3789848 + eb6e192 commit 1b44ec0
Show file tree
Hide file tree
Showing 49 changed files with 3,803 additions and 4,685 deletions.
6 changes: 3 additions & 3 deletions Essentials/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ dependencies {
implementation 'org.checkerframework:checker-qual:3.21.0'
implementation 'nu.studer:java-ordered-properties:1.0.4'

implementation 'net.kyori:adventure-api:4.17.0'
implementation 'net.kyori:adventure-text-minimessage:4.17.0'
implementation 'net.kyori:adventure-platform-bukkit:4.3.3'
implementation 'net.kyori:adventure-api:4.18.0'
implementation 'net.kyori:adventure-text-minimessage:4.18.0'
implementation 'net.kyori:adventure-platform-bukkit:4.3.4'

// Providers
api project(':providers:BaseProviders')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,14 @@ private void runDump(Server server, CommandSource sender, String commandLabel, S
final CompletableFuture<PasteUtil.PasteResult> future = PasteUtil.createPaste(files);
future.thenAccept(result -> {
if (result != null) {
final String dumpUrl = "https://essentialsx.net/dump.html?id=" + result.getPasteId();
final String dumpUrl = "https://essentialsx.net/dump.html?bytebin=" + result.getPasteId();
sender.sendTl("dumpUrl", dumpUrl);
sender.sendTl("dumpDeleteKey", result.getDeletionKey());
// pastes.dev doesn't support deletion keys
//sender.sendTl("dumpDeleteKey", result.getDeletionKey());
if (sender.isPlayer()) {
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpConsoleUrl", dumpUrl)));
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpDeleteKey", result.getDeletionKey())));
// pastes.dev doesn't support deletion keys
//ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpDeleteKey", result.getDeletionKey())));
}
}
files.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.flattener.ComponentFlattener;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.serializer.legacy.CharacterAndFormat;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.Reset;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public final class AdventureUtil {
private static final LegacyComponentSerializer LEGACY_SERIALIZER;
Expand All @@ -25,25 +18,8 @@ public final class AdventureUtil {
private static MiniMessage miniMessageInstance;

static {
final List<CharacterAndFormat> formats = new ArrayList<>();
formats.addAll(CharacterAndFormat.defaults());
formats.addAll(Arrays.asList(
CharacterAndFormat.characterAndFormat('A', NamedTextColor.GREEN),
CharacterAndFormat.characterAndFormat('B', NamedTextColor.AQUA),
CharacterAndFormat.characterAndFormat('C', NamedTextColor.RED),
CharacterAndFormat.characterAndFormat('D', NamedTextColor.LIGHT_PURPLE),
CharacterAndFormat.characterAndFormat('E', NamedTextColor.YELLOW),
CharacterAndFormat.characterAndFormat('F', NamedTextColor.WHITE),
CharacterAndFormat.characterAndFormat('K', TextDecoration.OBFUSCATED),
CharacterAndFormat.characterAndFormat('L', TextDecoration.BOLD),
CharacterAndFormat.characterAndFormat('M', TextDecoration.STRIKETHROUGH),
CharacterAndFormat.characterAndFormat('N', TextDecoration.UNDERLINED),
CharacterAndFormat.characterAndFormat('O', TextDecoration.ITALIC),
CharacterAndFormat.characterAndFormat('R', Reset.INSTANCE)
));
final LegacyComponentSerializer.Builder builder = LegacyComponentSerializer.builder()
.flattener(ComponentFlattener.basic())
.formats(formats)
.useUnusualXRepeatedCharacterHexFormat();
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_16_1_R01)) {
builder.hexColors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.common.io.CharStreams;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.checkerframework.checker.nullness.qual.Nullable;

Expand All @@ -17,10 +16,11 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.zip.GZIPOutputStream;

public final class PasteUtil {
private static final String PASTE_URL = "https://paste.gg/";
private static final String PASTE_UPLOAD_URL = "https://api.paste.gg/v1/pastes";
private static final String PASTE_URL = "https://pastes.dev/";
private static final String PASTE_UPLOAD_URL = "https://api.pastes.dev/post";
private static final ExecutorService PASTE_EXECUTOR_SERVICE = Executors.newSingleThreadExecutor();
private static final Gson GSON = new Gson();

Expand All @@ -42,7 +42,8 @@ public static CompletableFuture<PasteResult> createPaste(List<PasteFile> pages)
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("User-Agent", "EssentialsX plugin");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Content-Type", "text/json");
connection.setRequestProperty("Content-Encoding", "gzip");
final JsonObject body = new JsonObject();
final JsonArray files = new JsonArray();
for (final PasteFile page : pages) {
Expand All @@ -56,24 +57,22 @@ public static CompletableFuture<PasteResult> createPaste(List<PasteFile> pages)
}
body.add("files", files);

try (final OutputStream os = connection.getOutputStream()) {
try (final OutputStream os = new GZIPOutputStream(connection.getOutputStream())) {
os.write(body.toString().getBytes(Charsets.UTF_8));
}

if (connection.getResponseCode() >= 400) {
//noinspection UnstableApiUsage
future.completeExceptionally(new Error(CharStreams.toString(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8))));
return;
}

// Read URL
final JsonObject object = GSON.fromJson(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8), JsonObject.class);
final String pasteId = object.get("result").getAsJsonObject().get("id").getAsString();
final String pasteId = object.get("key").getAsString();
final String pasteUrl = PASTE_URL + pasteId;
final JsonElement deletionKey = object.get("result").getAsJsonObject().get("deletion_key");
connection.disconnect();

final PasteResult result = new PasteResult(pasteId, pasteUrl, deletionKey != null ? deletionKey.getAsString() : null);
final PasteResult result = new PasteResult(pasteId, pasteUrl, null);
future.complete(result);
} catch (Exception e) {
future.completeExceptionally(e);
Expand Down
Loading

0 comments on commit 1b44ec0

Please sign in to comment.