diff --git a/src/main/java/dev/latvian/mods/kubejs/CommonProperties.java b/src/main/java/dev/latvian/mods/kubejs/CommonProperties.java index 6dc20b4a7..4c024bcfc 100644 --- a/src/main/java/dev/latvian/mods/kubejs/CommonProperties.java +++ b/src/main/java/dev/latvian/mods/kubejs/CommonProperties.java @@ -40,6 +40,7 @@ public static void reload() { public int defaultMaxStackSize; public JsonElement creativeModeTabIcon; public JsonElement creativeModeTabName; + public boolean useDoubleQuotes; private CommonProperties() { super(KubeJSPaths.COMMON_PROPERTIES, "KubeJS Common Properties"); @@ -59,6 +60,7 @@ protected void load() { startupErrorReportUrl = get("startup_error_report_url", ""); removeSlotLimit = get("remove_slot_limit", false); defaultMaxStackSize = Math.max(0, Math.min(1_000_000_000, get("default_max_stack_size", 0))); + useDoubleQuotes = get("use_double_quotes", false); creativeModeTabIcon = get("creative_mode_tab_icon", new JsonObject()); creativeModeTabName = get("creative_mode_tab_name", JsonNull.INSTANCE); @@ -70,6 +72,12 @@ public void setPackMode(String s) { set("packmode", new JsonPrimitive(s)); save(); } + + public void setUseDoubleQuotes(boolean value) { + useDoubleQuotes = value; + set("use_double_quotes", new JsonPrimitive(value)); + save(); + } public Component getCreativeModeTabName() { if (!creativeModeTabName.isJsonNull()) { diff --git a/src/main/java/dev/latvian/mods/kubejs/command/InformationCommands.java b/src/main/java/dev/latvian/mods/kubejs/command/InformationCommands.java index e8c2cccb7..5187695bb 100644 --- a/src/main/java/dev/latvian/mods/kubejs/command/InformationCommands.java +++ b/src/main/java/dev/latvian/mods/kubejs/command/InformationCommands.java @@ -1,5 +1,6 @@ package dev.latvian.mods.kubejs.command; +import dev.latvian.mods.kubejs.CommonProperties; import dev.latvian.mods.kubejs.ingredient.NamespaceIngredient; import net.minecraft.ChatFormatting; import net.minecraft.core.HolderSet; @@ -27,9 +28,15 @@ private static Component copy(String s, ChatFormatting col, Component info) { } private static Component copy(Component c, Component info) { + String textToCopy = c.getString(); + + if (textToCopy.startsWith("'") && textToCopy.endsWith("'") && CommonProperties.get().useDoubleQuotes) { + textToCopy = "\"" + textToCopy.substring(1, textToCopy.length() - 1) + "\""; + } + return Component.literal("- ") .withStyle(ChatFormatting.GRAY) - .withStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, c.getString()))) + .withStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, textToCopy))) .withStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, info.copy().append(" (Click to copy)")))) .append(c); } diff --git a/src/main/java/dev/latvian/mods/kubejs/command/KubeJSCommands.java b/src/main/java/dev/latvian/mods/kubejs/command/KubeJSCommands.java index 5141f2c98..bea0dde4b 100644 --- a/src/main/java/dev/latvian/mods/kubejs/command/KubeJSCommands.java +++ b/src/main/java/dev/latvian/mods/kubejs/command/KubeJSCommands.java @@ -198,6 +198,15 @@ public static void register(CommandDispatcher dispatcher) { .executes(context -> packmode(context.getSource(), StringArgumentType.getString(context, "name"))) ) ) + .then(Commands.literal("quote_style") + .executes(context -> toggleQuoteStyle(context.getSource())) + .then(Commands.literal("single") + .executes(context -> setQuoteStyle(context.getSource(), false)) + ) + .then(Commands.literal("double") + .executes(context -> setQuoteStyle(context.getSource(), true)) + ) + ) .then(Commands.literal("persistent-data") .requires(spOrOP) .then(PersistentDataCommands.addPersistentDataCommands(Commands.literal("server"), ctx -> Set.of(ctx.getSource().getServer()))) @@ -546,6 +555,23 @@ private static int packmode(CommandSourceStack source, String packmode) { return 1; } + + private static int toggleQuoteStyle(CommandSourceStack source) { + boolean current = CommonProperties.get().useDoubleQuotes; + CommonProperties.get().setUseDoubleQuotes(!current); + String newStyle = CommonProperties.get().useDoubleQuotes ? "double" : "single"; + source.sendSuccess(() -> Component.literal("Quote style switched to: " + newStyle + " quotes"), true); + source.sendSuccess(() -> Component.literal("Please use /kubejs hand again to apply the new quote style to chat messages.").withStyle(ChatFormatting.YELLOW), false); + return 1; + } + + private static int setQuoteStyle(CommandSourceStack source, boolean useDoubleQuotes) { + CommonProperties.get().setUseDoubleQuotes(useDoubleQuotes); + String style = useDoubleQuotes ? "double" : "single"; + source.sendSuccess(() -> Component.literal("Quote style set to: " + style + " quotes"), true); + source.sendSuccess(() -> Component.literal("Please use /kubejs hand again to apply the new quote style to chat messages.").withStyle(ChatFormatting.YELLOW), false); + return 1; + } private static int eval(CommandSourceStack source, String code) { var cx = (KubeJSContext) source.getServer().getServerResources().managers().kjs$getServerScriptManager().contextFactory.enter();