From fcaed268d7f336ceb14a6b5aef0a660972074a51 Mon Sep 17 00:00:00 2001 From: zbx1425 Date: Mon, 18 Sep 2023 13:30:08 +0800 Subject: [PATCH] Change anonymous comments to be not too anonymous --- .../main/java/cn/zbx1425/worldcomment/data/CommentEntry.java | 3 +-- .../cn/zbx1425/worldcomment/data/network/UplinkRequest.java | 2 +- .../java/cn/zbx1425/worldcomment/gui/WidgetCommentEntry.java | 5 ++++- .../zbx1425/worldcomment/network/PacketEntryCreateC2S.java | 3 +-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/cn/zbx1425/worldcomment/data/CommentEntry.java b/common/src/main/java/cn/zbx1425/worldcomment/data/CommentEntry.java index acff848..5c3fde5 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/data/CommentEntry.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/data/CommentEntry.java @@ -44,11 +44,10 @@ public CommentEntry(Player initiator, boolean isAnonymous, int messageType, Stri id = ServerWorldData.SNOWFLAKE.nextId(); timestamp = System.currentTimeMillis(); level = initiator.level().dimension().location(); + this.initiator = initiator.getGameProfile().getId(); if (isAnonymous) { - this.initiator = Util.NIL_UUID; initiatorName = ""; } else { - this.initiator = initiator.getGameProfile().getId(); initiatorName = initiator.getGameProfile().getName(); } this.messageType = messageType; diff --git a/common/src/main/java/cn/zbx1425/worldcomment/data/network/UplinkRequest.java b/common/src/main/java/cn/zbx1425/worldcomment/data/network/UplinkRequest.java index f81927a..954ba90 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/data/network/UplinkRequest.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/data/network/UplinkRequest.java @@ -38,7 +38,7 @@ public class UplinkRequest { public final Consumer callback; public UplinkRequest(String url, JsonObject payload) { - this(url, "GET", payload, null); + this(url, "POST", payload, null); } public UplinkRequest(String url, String method, JsonObject payload, Consumer callback) { diff --git a/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetCommentEntry.java b/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetCommentEntry.java index d62a863..013e470 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetCommentEntry.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetCommentEntry.java @@ -99,6 +99,9 @@ guiGraphics, getX(), getY(), getWidth(), getHeight(), Component nameComponent = comment.initiatorName.isEmpty() ? Component.translatable("gui.worldcomment.anonymous") : Component.literal(comment.initiatorName); + String uuidToDisplay = comment.initiatorName.isEmpty() + ? (Minecraft.getInstance().player.hasPermissions(3) ? comment.initiator.toString() : "") + : "..." + comment.initiator.toString().substring(24); guiGraphics.drawString(font, nameComponent, getX() + 34, getY() + 8, 0xFFFFFFFF, true); @@ -120,7 +123,7 @@ guiGraphics, getX(), getY(), getWidth(), getHeight(), .append(Component.literal(" (" + comment.location.toShortString() + ")").setStyle(Style.EMPTY.withBold(false).withColor(ChatFormatting.WHITE))), Component.literal(" " + Instant.ofEpochMilli(comment.timestamp).atZone(ZoneId.systemDefault()) .toLocalDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)).withStyle(Style.EMPTY.withColor(ChatFormatting.GRAY)), - Component.literal(" " + nameComponent.getString() + " ..." + comment.initiator.toString().substring(24)).withStyle(Style.EMPTY.withColor(ChatFormatting.GRAY)) + Component.literal(" " + nameComponent.getString() + " " + uuidToDisplay).withStyle(Style.EMPTY.withColor(ChatFormatting.GRAY)) ), Optional.empty(), mouseX, mouseY); } } diff --git a/common/src/main/java/cn/zbx1425/worldcomment/network/PacketEntryCreateC2S.java b/common/src/main/java/cn/zbx1425/worldcomment/network/PacketEntryCreateC2S.java index 6295901..8d15e1a 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/network/PacketEntryCreateC2S.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/network/PacketEntryCreateC2S.java @@ -29,8 +29,7 @@ public static void send(CommentEntry comment) { public static void handle(MinecraftServer server, ServerPlayer initiator, FriendlyByteBuf buffer) { ResourceLocation level = buffer.readResourceLocation(); CommentEntry comment = new CommentEntry(level, buffer, false); - if (!comment.initiator.equals(Util.NIL_UUID) - && !comment.initiator.equals(initiator.getGameProfile().getId())) { + if (!comment.initiator.equals(initiator.getGameProfile().getId())) { return; } try {