From 4ef0266d1d7447b9e358176925202eee1fe40dbf Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 11 Mar 2025 09:11:00 +0700 Subject: [PATCH] fix: custom name not showing on >= 1.21.4 place block core feat: check for invalid custom name JSON in the place block core --- build-number.txt | 2 +- .../chomens_bot/plugins/CorePlugin.java | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/build-number.txt b/build-number.txt index c59f88bd..1a85967c 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -1765 \ No newline at end of file +1768 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java index ced5a7ef..47dccf8c 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java @@ -1,5 +1,6 @@ package me.chayapak1.chomens_bot.plugins; +import com.google.gson.JsonSyntaxException; import me.chayapak1.chomens_bot.Bot; import me.chayapak1.chomens_bot.util.MathUtilities; import net.kyori.adventure.text.Component; @@ -241,13 +242,39 @@ public class CorePlugin extends PositionPlugin.Listener { blockEntityTagBuilder.putString("Command", command); blockEntityTagBuilder.putByte("auto", (byte) 1); blockEntityTagBuilder.putByte("TrackOutput", (byte) 1); - blockEntityTagBuilder.putString("CustomName", bot.config.core.customName); final NbtMap blockEntityTag = blockEntityTagBuilder.build(); final Map, DataComponent> map = new HashMap<>(); - map.put(DataComponentTypes.BLOCK_ENTITY_DATA, DataComponentTypes.BLOCK_ENTITY_DATA.getDataComponentFactory().create(DataComponentTypes.BLOCK_ENTITY_DATA, blockEntityTag)); + // is there a better way to put these data component types into the map? + + map.put( + DataComponentTypes.BLOCK_ENTITY_DATA, + DataComponentTypes.BLOCK_ENTITY_DATA + .getDataComponentFactory() + .create( + DataComponentTypes.BLOCK_ENTITY_DATA, + blockEntityTag + ) + ); + + try { + final Component customName = GsonComponentSerializer.gson().deserialize(bot.config.core.customName); + + map.put( + DataComponentTypes.CUSTOM_NAME, + DataComponentTypes.CUSTOM_NAME + .getDataComponentFactory() + .create( + DataComponentTypes.CUSTOM_NAME, + customName + ) + ); + } catch (JsonSyntaxException e) { + bot.logger.error("Error while parsing the core's custom name into Component! You might have an invalid syntax in the custom name."); + bot.logger.error(e); + } final DataComponents dataComponents = new DataComponents(map);