revert yaml and move servereval to plugins

This commit is contained in:
ChomeNS 2023-03-25 17:11:35 +07:00
parent c94d8bc4b7
commit d06ca203ae
5 changed files with 27 additions and 11 deletions

View file

@ -88,7 +88,7 @@
<dependency> <dependency>
<groupId>org.yaml</groupId> <groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId> <artifactId>snakeyaml</artifactId>
<version>2.0</version> <version>1.29</version>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -43,6 +43,7 @@ public class Bot {
@Getter private final HashingPlugin hashing; @Getter private final HashingPlugin hashing;
@Getter private final MusicPlayerPlugin music; @Getter private final MusicPlayerPlugin music;
@Getter private final TPSPlugin tps; @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) { public Bot (String host, int port, String _username, boolean kaboom, List<Bot> allBots, Configuration config) {
this.host = host; this.host = host;
@ -63,6 +64,7 @@ public class Bot {
this.hashing = new HashingPlugin(this); this.hashing = new HashingPlugin(this);
this.music = new MusicPlayerPlugin(this); this.music = new MusicPlayerPlugin(this);
this.tps = new TPSPlugin(this); this.tps = new TPSPlugin(this);
this.eval = new EvalRunnerPlugin(this);
reconnect(); reconnect();
} }

View file

@ -1,6 +1,7 @@
package me.chayapak1.chomens_bot; package me.chayapak1.chomens_bot;
import me.chayapak1.chomens_bot.plugins.ConsolePlugin; import me.chayapak1.chomens_bot.plugins.ConsolePlugin;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.constructor.Constructor;

View file

@ -4,10 +4,7 @@ import me.chayapak1.chomens_bot.command.Command;
import me.chayapak1.chomens_bot.command.CommandContext; import me.chayapak1.chomens_bot.command.CommandContext;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue; 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.ArrayList;
import java.util.List; import java.util.List;
@ -39,13 +36,7 @@ public class ServerEvalCommand implements Command {
public Component execute(CommandContext context, String[] args, String[] fullArgs) { public Component execute(CommandContext context, String[] args, String[] fullArgs) {
try { try {
Globals globals = JsePlatform.standardGlobals(); final LuaValue output = context.bot().eval().run(String.join(" ", args));
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)); context.sendOutput(Component.text(output.toString()).color(NamedTextColor.GREEN));
} catch (Exception e) { } catch (Exception e) {

View file

@ -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();
}
}