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
24 changes: 24 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,21 @@ 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);
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);
return 1;
}

private static int eval(CommandSourceStack source, String code) {
var cx = (KubeJSContext) source.getServer().getServerResources().managers().kjs$getServerScriptManager().contextFactory.enter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package dev.latvian.mods.kubejs.core.mixin;

import com.mojang.serialization.Codec;
import dev.latvian.mods.kubejs.CommonProperties;
import dev.latvian.mods.kubejs.util.WithCodec;
import dev.latvian.mods.rhino.Context;
import net.minecraft.network.chat.ClickEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ClickEvent.class)
public abstract class ClickEventMixin implements WithCodec {
@Shadow
public abstract String getValue();

@Inject(method = "getValue", at = @At("RETURN"), cancellable = true)
private void kubejs$getValueWithQuoteStyle(CallbackInfoReturnable<String> cir) {
String value = cir.getReturnValue();

if (CommonProperties.get().useDoubleQuotes && value != null && value.startsWith("'") && value.endsWith("'")) {
cir.setReturnValue("\"" + value.substring(1, value.length() - 1) + "\"");
}
}

@Override
public Codec<?> getCodec(Context cx) {
Expand Down