Skip to content

Commit 671c094

Browse files
committed
Add a command kubejs /kjs quote_style double/single
Used to choose between double quotes or single quotes when copying Items Id or Tag
1 parent a4f0250 commit 671c094

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/main/java/dev/latvian/mods/kubejs/CommonProperties.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static void reload() {
4040
public int defaultMaxStackSize;
4141
public JsonElement creativeModeTabIcon;
4242
public JsonElement creativeModeTabName;
43+
public boolean useDoubleQuotes;
4344

4445
private CommonProperties() {
4546
super(KubeJSPaths.COMMON_PROPERTIES, "KubeJS Common Properties");
@@ -59,6 +60,7 @@ protected void load() {
5960
startupErrorReportUrl = get("startup_error_report_url", "");
6061
removeSlotLimit = get("remove_slot_limit", false);
6162
defaultMaxStackSize = Math.max(0, Math.min(1_000_000_000, get("default_max_stack_size", 0)));
63+
useDoubleQuotes = get("use_double_quotes", false);
6264

6365
creativeModeTabIcon = get("creative_mode_tab_icon", new JsonObject());
6466
creativeModeTabName = get("creative_mode_tab_name", JsonNull.INSTANCE);
@@ -70,6 +72,12 @@ public void setPackMode(String s) {
7072
set("packmode", new JsonPrimitive(s));
7173
save();
7274
}
75+
76+
public void setUseDoubleQuotes(boolean value) {
77+
useDoubleQuotes = value;
78+
set("use_double_quotes", new JsonPrimitive(value));
79+
save();
80+
}
7381

7482
public Component getCreativeModeTabName() {
7583
if (!creativeModeTabName.isJsonNull()) {

src/main/java/dev/latvian/mods/kubejs/command/InformationCommands.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.latvian.mods.kubejs.command;
22

3+
import dev.latvian.mods.kubejs.CommonProperties;
34
import dev.latvian.mods.kubejs.ingredient.NamespaceIngredient;
45
import net.minecraft.ChatFormatting;
56
import net.minecraft.core.HolderSet;
@@ -27,9 +28,15 @@ private static Component copy(String s, ChatFormatting col, Component info) {
2728
}
2829

2930
private static Component copy(Component c, Component info) {
31+
String textToCopy = c.getString();
32+
33+
if (textToCopy.startsWith("'") && textToCopy.endsWith("'") && CommonProperties.get().useDoubleQuotes) {
34+
textToCopy = "\"" + textToCopy.substring(1, textToCopy.length() - 1) + "\"";
35+
}
36+
3037
return Component.literal("- ")
3138
.withStyle(ChatFormatting.GRAY)
32-
.withStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, c.getString())))
39+
.withStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, textToCopy)))
3340
.withStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, info.copy().append(" (Click to copy)"))))
3441
.append(c);
3542
}

src/main/java/dev/latvian/mods/kubejs/command/KubeJSCommands.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
198198
.executes(context -> packmode(context.getSource(), StringArgumentType.getString(context, "name")))
199199
)
200200
)
201+
.then(Commands.literal("quote_style")
202+
.executes(context -> toggleQuoteStyle(context.getSource()))
203+
.then(Commands.literal("single")
204+
.executes(context -> setQuoteStyle(context.getSource(), false))
205+
)
206+
.then(Commands.literal("double")
207+
.executes(context -> setQuoteStyle(context.getSource(), true))
208+
)
209+
)
201210
.then(Commands.literal("persistent-data")
202211
.requires(spOrOP)
203212
.then(PersistentDataCommands.addPersistentDataCommands(Commands.literal("server"), ctx -> Set.of(ctx.getSource().getServer())))
@@ -546,6 +555,21 @@ private static int packmode(CommandSourceStack source, String packmode) {
546555

547556
return 1;
548557
}
558+
559+
private static int toggleQuoteStyle(CommandSourceStack source) {
560+
boolean current = CommonProperties.get().useDoubleQuotes;
561+
CommonProperties.get().setUseDoubleQuotes(!current);
562+
String newStyle = CommonProperties.get().useDoubleQuotes ? "double" : "single";
563+
source.sendSuccess(() -> Component.literal("Quote style switched to: " + newStyle + " quotes"), true);
564+
return 1;
565+
}
566+
567+
private static int setQuoteStyle(CommandSourceStack source, boolean useDoubleQuotes) {
568+
CommonProperties.get().setUseDoubleQuotes(useDoubleQuotes);
569+
String style = useDoubleQuotes ? "double" : "single";
570+
source.sendSuccess(() -> Component.literal("Quote style set to: " + style + " quotes"), true);
571+
return 1;
572+
}
549573

550574
private static int eval(CommandSourceStack source, String code) {
551575
var cx = (KubeJSContext) source.getServer().getServerResources().managers().kjs$getServerScriptManager().contextFactory.enter();

0 commit comments

Comments
 (0)