Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/dev/latvian/mods/kubejs/CommonProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/dev/latvian/mods/kubejs/command/KubeJSCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ public static void register(CommandDispatcher<CommandSourceStack> 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())))
Expand Down Expand Up @@ -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();
Expand Down