@@ -6,7 +6,9 @@ import me.scoretwo.fastscript.api.format.FormatHeader
6
6
import me.scoretwo.fastscript.api.script.Script
7
7
import me.scoretwo.fastscript.api.script.custom.CustomScript
8
8
import me.scoretwo.fastscript.utils.assist
9
+ import me.scoretwo.utils.sender.GlobalPlayer
9
10
import me.scoretwo.utils.sender.GlobalSender
11
+ import me.scoretwo.utils.server.globalServer
10
12
import org.apache.commons.lang.StringUtils
11
13
import javax.script.Invocable
12
14
import javax.script.ScriptEngine
@@ -26,11 +28,7 @@ abstract class TypeEngineExpansion: FastScriptExpansion() {
26
28
return this
27
29
}
28
30
29
- override fun eval (script : Script , sender : GlobalSender , args : Array <Any ?>, otherBindings : Map <String , Any ?>): Any? {
30
- val newEngine = engine.factory.scriptEngine
31
- if (! script.texts.keys.contains(sign))
32
- return null
33
-
31
+ fun addEntries (newEngine : ScriptEngine , script : Script ? , sender : GlobalSender , args : Array <Any ?>, otherBindings : Map <String , Any ?>) {
34
32
newEngine.put(" meta" , HashMap <String , Any ?>())
35
33
newEngine.put(" plugin" , plugin.toOriginalPlugin())
36
34
newEngine.put(" script" , script)
@@ -39,23 +37,34 @@ abstract class TypeEngineExpansion: FastScriptExpansion() {
39
37
newEngine.put(" scriptManager" , FastScript .instance.scriptManager)
40
38
newEngine.put(" expansionManager" , FastScript .instance.expansionManager)
41
39
42
- if (sender.isPlayer()) {
43
- sender.toPlayer().let {
44
- newEngine.put(" globalPlayer" , it)
45
- newEngine.put(" player" , plugin.toOriginalPlayer(it!! ))
46
- }
40
+ newEngine.put(" args" , args)
41
+ newEngine.put(" utils" , assist)
42
+ newEngine.put(" util" , assist)
43
+ otherBindings.forEach { newEngine.put(it.key, it.value) }
44
+ }
45
+
46
+ fun addSenders (newEngine : ScriptEngine , script : Script ? , sender : GlobalSender , args : Array <Any ?>, otherBindings : Map <String , Any ?>) {
47
+
48
+ if (globalServer.isOnlinePlayer(sender.name)) {
49
+ newEngine.put(" globalPlayer" , globalServer.getPlayer(sender.name).get())
50
+ newEngine.put(" player" , plugin.toOriginalPlayer(globalServer.getPlayer(sender.name).get()))
47
51
} else {
48
52
newEngine.put(" globalPlayer" , null )
49
53
newEngine.put(" player" , null )
50
54
}
51
55
newEngine.put(" globalSender" , sender)
52
56
newEngine.put(" sender" , plugin.toOriginalSender(sender))
53
- newEngine.put(" args" , args)
54
- newEngine.put(" utils" , assist)
55
- newEngine.put(" util" , assist)
56
- otherBindings.forEach { newEngine.put(it.key, it.value) }
57
+ }
57
58
59
+ override fun eval (script : Script , sender : GlobalSender , args : Array <Any ?>, otherBindings : Map <String , Any ?>): Any? {
60
+ val newEngine = engine.factory.scriptEngine
61
+ if (! script.texts.keys.contains(sign))
62
+ return null
63
+
64
+ addSenders(newEngine, script, sender, args, otherBindings)
65
+ addEntries(newEngine, script, sender, args, otherBindings)
58
66
engineScripts[script] = newEngine
67
+
59
68
return let {
60
69
try {
61
70
newEngine.eval(script.texts[sign]).also {
@@ -78,30 +87,8 @@ abstract class TypeEngineExpansion: FastScriptExpansion() {
78
87
if (text.isBlank())
79
88
return null
80
89
81
- newEngine.put(" meta" , HashMap <String , Any ?>())
82
- newEngine.put(" plugin" , plugin.toOriginalPlugin())
83
- newEngine.put(" server" , plugin.toOriginalServer())
84
- newEngine.put(" globalServer" , plugin.server)
85
- newEngine.put(" globalPlugin" , plugin)
86
- newEngine.put(" scriptManager" , FastScript .instance.scriptManager)
87
- newEngine.put(" expansionManager" , FastScript .instance.expansionManager)
88
-
89
- if (sender.isPlayer()) {
90
- sender.toPlayer().let {
91
- newEngine.put(" globalPlayer" , it)
92
- newEngine.put(" player" , plugin.toOriginalPlayer(it!! ))
93
- }
94
- } else {
95
- newEngine.put(" globalPlayer" , null )
96
- newEngine.put(" player" , null )
97
- }
98
- newEngine.put(" globalSender" , sender)
99
- newEngine.put(" sender" , plugin.toOriginalSender(sender))
100
- newEngine.put(" args" , args)
101
- newEngine.put(" utils" , assist)
102
- newEngine.put(" util" , assist)
103
- otherBindings.forEach { newEngine.put(it.key, it.value) }
104
-
90
+ addSenders(newEngine, null , sender, args, otherBindings)
91
+ addEntries(newEngine, null , sender, args, otherBindings)
105
92
engineTexts[text] = newEngine
106
93
return let {
107
94
try {
@@ -123,6 +110,8 @@ abstract class TypeEngineExpansion: FastScriptExpansion() {
123
110
return try {
124
111
if (engineScripts[script] !is Invocable )
125
112
eval(script, sender, arrayOf(), otherBindings)
113
+ else
114
+ addSenders(engineScripts[script]!! , script, sender, args, otherBindings)
126
115
127
116
val invocable = engineScripts[script] as Invocable
128
117
@@ -162,6 +151,8 @@ abstract class TypeEngineExpansion: FastScriptExpansion() {
162
151
return try {
163
152
if (engineTexts[text] !is Invocable )
164
153
eval(text, sender, arrayOf(), otherBindings)
154
+ else
155
+ addSenders(engineTexts[text]!! , null , sender, args, otherBindings)
165
156
166
157
val invocable = engineTexts[text] as Invocable
167
158
0 commit comments