Skip to content

Commit 1ac9515

Browse files
committed
Switch to using mixin for modification, no longer requiring players to re-enter the /kjs hand command
1 parent a9a5f8f commit 1ac9515

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

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

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

3-
import dev.latvian.mods.kubejs.CommonProperties;
43
import dev.latvian.mods.kubejs.ingredient.NamespaceIngredient;
54
import net.minecraft.ChatFormatting;
65
import net.minecraft.core.HolderSet;
@@ -28,15 +27,9 @@ private static Component copy(String s, ChatFormatting col, Component info) {
2827
}
2928

3029
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-
3730
return Component.literal("- ")
3831
.withStyle(ChatFormatting.GRAY)
39-
.withStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, textToCopy)))
32+
.withStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, c.getString())))
4033
.withStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, info.copy().append(" (Click to copy)"))))
4134
.append(c);
4235
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,13 @@ private static int toggleQuoteStyle(CommandSourceStack source) {
561561
CommonProperties.get().setUseDoubleQuotes(!current);
562562
String newStyle = CommonProperties.get().useDoubleQuotes ? "double" : "single";
563563
source.sendSuccess(() -> Component.literal("Quote style switched to: " + newStyle + " quotes"), true);
564-
source.sendSuccess(() -> Component.literal("Please use /kubejs hand again to apply the new quote style to chat messages.").withStyle(ChatFormatting.YELLOW), false);
565564
return 1;
566565
}
567566

568567
private static int setQuoteStyle(CommandSourceStack source, boolean useDoubleQuotes) {
569568
CommonProperties.get().setUseDoubleQuotes(useDoubleQuotes);
570569
String style = useDoubleQuotes ? "double" : "single";
571570
source.sendSuccess(() -> Component.literal("Quote style set to: " + style + " quotes"), true);
572-
source.sendSuccess(() -> Component.literal("Please use /kubejs hand again to apply the new quote style to chat messages.").withStyle(ChatFormatting.YELLOW), false);
573571
return 1;
574572
}
575573

src/main/java/dev/latvian/mods/kubejs/core/mixin/ClickEventMixin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
package dev.latvian.mods.kubejs.core.mixin;
22

33
import com.mojang.serialization.Codec;
4+
import dev.latvian.mods.kubejs.CommonProperties;
45
import dev.latvian.mods.kubejs.util.WithCodec;
56
import dev.latvian.mods.rhino.Context;
67
import net.minecraft.network.chat.ClickEvent;
78
import org.spongepowered.asm.mixin.Mixin;
89
import org.spongepowered.asm.mixin.Shadow;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
913

1014
@Mixin(ClickEvent.class)
1115
public abstract class ClickEventMixin implements WithCodec {
1216
@Shadow
1317
public abstract String getValue();
18+
19+
@Inject(method = "getValue", at = @At("RETURN"), cancellable = true)
20+
private void kubejs$getValueWithQuoteStyle(CallbackInfoReturnable<String> cir) {
21+
String value = cir.getReturnValue();
22+
23+
if (CommonProperties.get().useDoubleQuotes && value != null && value.startsWith("'") && value.endsWith("'")) {
24+
cir.setReturnValue("\"" + value.substring(1, value.length() - 1) + "\"");
25+
}
26+
}
1427

1528
@Override
1629
public Codec<?> getCodec(Context cx) {

0 commit comments

Comments
 (0)