Skip to content

Commit b2e9b78

Browse files
committed
Updated to not have Lua anymore...
1 parent 129ecba commit b2e9b78

File tree

3 files changed

+82
-95
lines changed

3 files changed

+82
-95
lines changed

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import org.mangorage.mangobotgradle.util.GitVersion
33
buildscript {
44
repositories {
55
mavenCentral()
6+
mavenLocal()
67
maven {
78
url = uri("https://plugins.gradle.org/m2/")
89
}
@@ -16,7 +17,7 @@ buildscript {
1617

1718
dependencies {
1819
classpath 'gradle.plugin.com.github.johnrengelman:shadow:7.1.2'
19-
classpath 'org.mangorage:MangoBotGradle:6.0.7'
20+
classpath 'org.mangorage:MangoBotGradle:6.0.8-beta.10'
2021
}
2122
}
2223

@@ -61,10 +62,11 @@ dependencies {
6162

6263
installer('org.mangorage:installer:4.0.13')
6364

64-
bot("org.mangorage:mangobotbootstrap:1.0.6")
65+
bot("org.mangorage:mangobotbootstrap:1.0.14-beta.10")
6566
plugin('org.mangorage:mangobot:12.0.44')
6667

67-
library('org.luaj:luaj-jse:3.0.1')
68+
// library('org.classdump.luna:luna-all-shaded:0.4.1')
69+
6870
library('dev.arbjerg:lavaplayer:2.2.3')
6971
library('dev.lavalink.youtube:common:1.12.0')
7072
}

src/main/java/module-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
requires net.dv8tion.jda;
55
requires com.google.gson;
6-
requires static luaj.jse;
76
requires jdk.unsupported;
87

98
requires net.minecraftforge.eventbus;

src/main/java/org/mangorage/mangobotplugin/commands/trick/TrickScriptable.java

Lines changed: 77 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,8 @@
2424

2525
import net.dv8tion.jda.api.entities.Message;
2626
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
27-
import org.luaj.vm2.Globals;
28-
import org.luaj.vm2.LoadState;
29-
import org.luaj.vm2.LuaTable;
30-
import org.luaj.vm2.LuaValue;
31-
import org.luaj.vm2.compiler.LuaC;
32-
import org.luaj.vm2.lib.PackageLib;
33-
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
34-
import org.luaj.vm2.lib.jse.JseBaseLib;
35-
import org.luaj.vm2.lib.jse.JseMathLib;
36-
import org.mangorage.mangobotplugin.entrypoint.MangoBot;
37-
import org.mangorage.mangobotplugin.commands.trick.lua.LuaJDA;
38-
import org.mangorage.mangobotplugin.commands.trick.lua.objects.LuaStringArray;
3927

40-
import java.util.concurrent.Executors;
41-
import java.util.concurrent.Future;
42-
import java.util.concurrent.ScheduledExecutorService;
43-
import java.util.concurrent.ScheduledFuture;
44-
import java.util.concurrent.TimeUnit;
45-
import java.util.concurrent.atomic.AtomicReference;
46-
import java.util.function.Consumer;
28+
import org.mangorage.mangobotplugin.entrypoint.MangoBot;
4729

4830
public class TrickScriptable {
4931
private final MangoBot plugin;
@@ -53,79 +35,83 @@ public TrickScriptable(MangoBot plugin) {
5335
}
5436

5537

56-
public Globals sandBoxedGlobals() {
57-
Globals server_globals = new Globals();
58-
59-
server_globals.load(new JseBaseLib());
60-
server_globals.load(new PackageLib());
61-
server_globals.load(new JseMathLib());
62-
63-
64-
LoadState.install(server_globals);
65-
LuaC.install(server_globals);
66-
67-
var array = new String[]{"os", "io", "luajava", "debug", "load", "loadfile"};
68-
69-
Consumer<String> NILLIFY = a -> {
70-
server_globals.set(a, LuaValue.NIL);
71-
};
72-
73-
for (String library : array)
74-
NILLIFY.accept(library);
75-
76-
return server_globals;
77-
}
38+
// public Globals sandBoxedGlobals() {
39+
// Globals server_globals = new Globals();
40+
//
41+
// server_globals.load(new JseBaseLib());
42+
// server_globals.load(new PackageLib());
43+
// server_globals.load(new JseMathLib());
44+
//
45+
//
46+
// LoadState.install(server_globals);
47+
// LuaC.install(server_globals);
48+
//
49+
// var array = new String[]{"os", "io", "luajava", "debug", "load", "loadfile"};
50+
//
51+
// Consumer<String> NILLIFY = a -> {
52+
// server_globals.set(a, LuaValue.NIL);
53+
// };
54+
//
55+
// for (String library : array)
56+
// NILLIFY.accept(library);
57+
//
58+
// return server_globals;
59+
// }
7860

7961
public void execute(Trick trick, String script, Message message, MessageChannel messageChannel, String[] args) {
80-
// Create a ScheduledExecutorService
81-
ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
82-
AtomicReference<ScheduledFuture<?>> TASK = new AtomicReference<>();
83-
84-
// Define the task you want to execute
85-
86-
Globals globals = sandBoxedGlobals();
87-
LuaValue code = globals.load(script);
88-
89-
Runnable task = () -> {
90-
try {
91-
code.call();
92-
93-
LuaValue method = globals.get("execute");
94-
LuaTable arr = new LuaTable();
95-
for (int i = 0; i < args.length; i++)
96-
arr.set(i + 1, LuaValue.valueOf(args[i]));
97-
98-
if (!method.isnil()) {
99-
method.call(
100-
CoerceJavaToLua.coerce(new LuaJDA(plugin, trick, message, messageChannel)),
101-
CoerceJavaToLua.coerce(new LuaStringArray(args))
102-
);
103-
}
104-
if (TASK.get() != null) {
105-
var a = TASK.get();
106-
if (a.isDone() || a.isCancelled()) return;
107-
a.cancel(true);
108-
}
109-
} catch (Exception e) {
110-
message.reply(e.getMessage()).mentionRepliedUser(false).queue();
111-
}
112-
};
113-
114-
// Submit the task to the executor
115-
Future<?> future = executor.submit(() -> {
116-
long time = System.currentTimeMillis();
117-
task.run();
118-
System.out.println("Script Took: %s ms".formatted(System.currentTimeMillis() - time));
119-
});
120-
121-
// Schedule a task to cancel the original task if it runs longer than the timeout
122-
TASK.set(executor.schedule(() -> {
123-
if (future.isDone() || future.isCancelled()) return;
124-
message.reply("Trick took to long to run. Stopping Trick...").mentionRepliedUser(false).queue();
125-
future.cancel(true);
126-
}, 1000, TimeUnit.MILLISECONDS));
127-
128-
// Shutdown the executor
129-
executor.shutdown();
62+
// // Create a ScheduledExecutorService
63+
// ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
64+
// AtomicReference<ScheduledFuture<?>> TASK = new AtomicReference<>();
65+
//
66+
// // Define the task you want to execute
67+
//
68+
// Globals globals = sandBoxedGlobals();
69+
// LuaValue code = globals.load(script);
70+
//
71+
// Runnable task = () -> {
72+
// try {
73+
// code.call();
74+
//
75+
// LuaValue method = globals.get("execute");
76+
// LuaTable arr = new LuaTable();
77+
// for (int i = 0; i < args.length; i++)
78+
// arr.set(i + 1, LuaValue.valueOf(args[i]));
79+
//
80+
// if (!method.isnil()) {
81+
// method.call(
82+
// CoerceJavaToLua.coerce(new LuaJDA(plugin, trick, message, messageChannel)),
83+
// CoerceJavaToLua.coerce(new LuaStringArray(args))
84+
// );
85+
// }
86+
// if (TASK.get() != null) {
87+
// var a = TASK.get();
88+
// if (a.isDone() || a.isCancelled()) return;
89+
// a.cancel(true);
90+
// }
91+
// } catch (Exception e) {
92+
// message.reply(e.getMessage()).mentionRepliedUser(false).queue();
93+
// }
94+
// };
95+
//
96+
// // Submit the task to the executor
97+
// Future<?> future = executor.submit(() -> {
98+
// long time = System.currentTimeMillis();
99+
// task.run();
100+
// System.out.println("Script Took: %s ms".formatted(System.currentTimeMillis() - time));
101+
// });
102+
//
103+
// // Schedule a task to cancel the original task if it runs longer than the timeout
104+
// TASK.set(executor.schedule(() -> {
105+
// if (future.isDone() || future.isCancelled()) return;
106+
// message.reply("Trick took to long to run. Stopping Trick...").mentionRepliedUser(false).queue();
107+
// future.cancel(true);
108+
// }, 1000, TimeUnit.MILLISECONDS));
109+
//
110+
// // Shutdown the executor
111+
// executor.shutdown();
112+
113+
if (message != null) {
114+
message.reply("Scripts Disabled").queue();
115+
}
130116
}
131117
}

0 commit comments

Comments
 (0)