revert yaml and move servereval to plugins
This commit is contained in:
@@ -43,6 +43,7 @@ public class Bot {
|
||||
@Getter private final HashingPlugin hashing;
|
||||
@Getter private final MusicPlayerPlugin music;
|
||||
@Getter private final TPSPlugin tps;
|
||||
@Getter private final EvalRunnerPlugin eval;
|
||||
|
||||
public Bot (String host, int port, String _username, boolean kaboom, List<Bot> allBots, Configuration config) {
|
||||
this.host = host;
|
||||
@@ -63,6 +64,7 @@ public class Bot {
|
||||
this.hashing = new HashingPlugin(this);
|
||||
this.music = new MusicPlayerPlugin(this);
|
||||
this.tps = new TPSPlugin(this);
|
||||
this.eval = new EvalRunnerPlugin(this);
|
||||
|
||||
reconnect();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.chayapak1.chomens_bot;
|
||||
|
||||
import me.chayapak1.chomens_bot.plugins.ConsolePlugin;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
|
||||
|
||||
@@ -4,10 +4,7 @@ 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;
|
||||
@@ -39,13 +36,7 @@ public class ServerEvalCommand implements Command {
|
||||
|
||||
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();
|
||||
final LuaValue output = context.bot().eval().run(String.join(" ", args));
|
||||
|
||||
context.sendOutput(Component.text(output.toString()).color(NamedTextColor.GREEN));
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.chayapak1.chomens_bot.plugins;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
|
||||
import org.luaj.vm2.lib.jse.JsePlatform;
|
||||
|
||||
public class EvalRunnerPlugin {
|
||||
@Getter private final Globals globals = JsePlatform.standardGlobals();
|
||||
|
||||
public EvalRunnerPlugin (Bot bot) {
|
||||
globals.set("bot", CoerceJavaToLua.coerce(bot));
|
||||
}
|
||||
|
||||
public LuaValue run (String code) {
|
||||
LuaValue chunk = globals.load(code);
|
||||
|
||||
return chunk.call();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user