add servereval lmfao

This commit is contained in:
ChomeNS 2023-03-25 16:15:19 +07:00
parent 0438ebd641
commit 39196aef5b
3 changed files with 64 additions and 0 deletions

View file

@ -90,6 +90,12 @@
<artifactId>snakeyaml</artifactId>
<version>1.29</version>
</dependency>
<dependency>
<groupId>org.luaj</groupId>
<artifactId>luaj-jse</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>

View file

@ -0,0 +1,57 @@
package me.chayapak1.chomens_bot.commands;
import me.chayapak1.chomens_bot.command.Command;
import me.chayapak1.chomens_bot.command.CommandContext;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
import org.luaj.vm2.lib.jse.JsePlatform;
import java.util.ArrayList;
import java.util.List;
public class ServerEvalCommand implements Command {
public String name() { return "servereval"; }
public String description() {
return "Evaluate codes using LuaJ";
}
public List<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<{code}>");
return usages;
}
public List<String> alias() {
final List<String> aliases = new ArrayList<>();
aliases.add("");
return aliases;
}
public int trustLevel() {
return 2;
}
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
try {
Globals globals = JsePlatform.standardGlobals();
globals.set("bot", CoerceJavaToLua.coerce(context.bot()));
LuaValue chunk = globals.load(String.join(" ", args));
LuaValue output = chunk.call();
context.sendOutput(Component.text(output.toString()).color(NamedTextColor.GREEN));
} catch (Exception e) {
return Component.text(e.toString()).color(NamedTextColor.RED);
}
return Component.text("success");
}
}

View file

@ -37,6 +37,7 @@ public class CommandHandlerPlugin {
registerCommand(new UrbanCommand());
registerCommand(new ClearChatCommand());
registerCommand(new ListCommand());
registerCommand(new ServerEvalCommand());
}
public void registerCommand (Command command) {