diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/EvalCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/EvalCommand.java index 4ead74d..eaccf63 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/EvalCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/EvalCommand.java @@ -3,6 +3,7 @@ package land.chipmunk.chipmunkmod.commands; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; +import land.chipmunk.chipmunkmod.util.Eval; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.MinecraftClient; import net.minecraft.text.Text; @@ -21,14 +22,22 @@ public class EvalCommand { public static void register (CommandDispatcher dispatcher) { dispatcher.register( literal("eval") - .then( - argument("code", greedyString()) - .executes(EvalCommand::eval) + .then(literal("java") + .then( + argument("code", greedyString()) + .executes(EvalCommand::evalJava) + ) + ) + .then(literal("lua") + .then( + argument("code", greedyString()) + .executes(EvalCommand::evalLua) + ) ) ); } - public static int eval (CommandContext context) { + public static int evalLua(CommandContext context) { final String code = getString(context, "code"); try { @@ -45,6 +54,13 @@ public class EvalCommand { context.getSource().sendError(Text.literal(e.toString())); } + return Command.SINGLE_SUCCESS; + } + public static int evalJava(CommandContext context) { + final String code = getString(context, "code"); + + Eval.shell(code); + return Command.SINGLE_SUCCESS; } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/TitleScreenMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/TitleScreenMixin.java index 5cf0770..b716a51 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/TitleScreenMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/TitleScreenMixin.java @@ -10,6 +10,7 @@ import org.slf4j.Logger; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -18,6 +19,7 @@ import java.io.IOException; @Mixin(TitleScreen.class) public class TitleScreenMixin { + @Shadow private SplashTextRenderer splashText; @Inject(method = "init", at = @At("HEAD")) @@ -28,6 +30,7 @@ public class TitleScreenMixin { Gui.addComponents(); Gui.gui = new Gui(); ModuleMemory.load(); + ChipmunkMod.LOGGER.info("Initialised gui!"); } } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/Eval.java b/src/main/java/land/chipmunk/chipmunkmod/util/Eval.java new file mode 100644 index 0000000..64cf2cc --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/util/Eval.java @@ -0,0 +1,17 @@ +package land.chipmunk.chipmunkmod.util; + +import jdk.jshell.JShell; + +public class Eval { + public static JShell shell = JShell.create(); + public static void shell(String code) { + shell.eval(code); + } + static { + shell.onSnippetEvent(event -> { + Chat.sendGold(event.value()); + }); + } + + +} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 8d854c8..d782698 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -28,10 +28,7 @@ "SharedConstantsMixin", "StringHelperMixin", "TextMixin", - "ClientConnectionInvoker", - "ClientConnectionAccessor", - "PlayerListEntryAccessor", - "SharedConstantsMixin" + "TitleScreenMixin" ], "injectors": { "defaultRequire": 1