Skip to content

Commit 3d7e686

Browse files
committed
Release 1.4
2 parents ceb4fe5 + 87ec4b0 commit 3d7e686

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+713
-513
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "MockSkript"]
22
path = MockSkript
3-
url = https://github.com/SkEditorPlus/MockSkript
3+
url = https://github.com/SkEditorTeam/MockSkript

MockSkript

Submodule MockSkript updated 149 files

MockSkriptBridge/build.gradle.kts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
plugins {
2-
id("java")
32
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
43
}
54

6-
repositories {
7-
mavenCentral()
8-
maven("https://repo.papermc.io/repository/maven-public/")
9-
}
10-
115
dependencies {
126
compileOnly(project(":api"))
137
compileOnly(project(":MockSkript", "shadow")) {
148
exclude("*", "*")
159
}
16-
compileOnly("org.projectlombok:lombok:1.18.30")
17-
annotationProcessor("org.projectlombok:lombok:1.18.30")
18-
}
19-
20-
java {
21-
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
22-
}
23-
24-
tasks {
25-
compileJava {
26-
options.encoding = Charsets.UTF_8.name()
27-
options.release.set(17)
28-
dependsOn(clean)
29-
}
30-
31-
jar.get().archiveVersion = ""
10+
compileOnly("org.projectlombok:lombok:1.18.32")
11+
annotationProcessor("org.projectlombok:lombok:1.18.32")
3212
}
3313

3414
bukkit {

MockSkriptBridge/src/main/java/me/glicz/skanalyzer/bridge/AnalyzerCommandSender.java

Lines changed: 0 additions & 80 deletions
This file was deleted.

MockSkriptBridge/src/main/java/me/glicz/skanalyzer/bridge/MockSkriptBridgeImpl.java

Lines changed: 85 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22

33
import ch.njol.skript.ScriptLoader;
44
import ch.njol.skript.Skript;
5-
import ch.njol.skript.classes.ClassInfo;
65
import ch.njol.skript.command.ScriptCommand;
76
import ch.njol.skript.hooks.VaultHook;
87
import ch.njol.skript.hooks.regions.RegionsPlugin;
98
import ch.njol.skript.lang.SkriptEvent;
109
import ch.njol.skript.lang.SkriptEventInfo;
1110
import ch.njol.skript.lang.function.Signature;
12-
import ch.njol.skript.log.RedirectingLogHandler;
13-
import ch.njol.skript.structures.*;
11+
import ch.njol.skript.structures.StructCommand;
12+
import ch.njol.skript.structures.StructEvent;
13+
import ch.njol.skript.structures.StructFunction;
14+
import ch.njol.skript.structures.StructOptions;
1415
import me.glicz.skanalyzer.AnalyzerFlag;
15-
import me.glicz.skanalyzer.ScriptAnalyzeResult;
1616
import me.glicz.skanalyzer.SkAnalyzer;
17-
import me.glicz.skanalyzer.bridge.util.ReflectionUtil;
17+
import me.glicz.skanalyzer.bridge.log.CachingLogHandler;
18+
import me.glicz.skanalyzer.bridge.util.FilesUtil;
19+
import me.glicz.skanalyzer.result.ScriptAnalyzeResult;
20+
import me.glicz.skanalyzer.result.ScriptAnalyzeResults;
1821
import me.glicz.skanalyzer.structure.ScriptStructure;
1922
import me.glicz.skanalyzer.structure.data.CommandData;
2023
import me.glicz.skanalyzer.structure.data.EventData;
@@ -27,9 +30,13 @@
2730
import java.nio.file.InvalidPathException;
2831
import java.util.*;
2932
import java.util.concurrent.CompletableFuture;
33+
import java.util.concurrent.Executor;
34+
import java.util.function.Function;
3035
import java.util.stream.Collectors;
3136

3237
public class MockSkriptBridgeImpl extends MockSkriptBridge {
38+
private Executor mainThreadExecutor;
39+
3340
public MockSkriptBridgeImpl(SkAnalyzer skAnalyzer) {
3441
super(skAnalyzer);
3542
}
@@ -39,6 +46,11 @@ public void onLoad() {
3946
parseFlags();
4047
}
4148

49+
@Override
50+
public void onEnable() {
51+
mainThreadExecutor = getServer().getScheduler().getMainThreadExecutor(this);
52+
}
53+
4254
public void parseFlags() {
4355
if (skAnalyzer.getFlags().contains(AnalyzerFlag.FORCE_VAULT_HOOK)) {
4456
try {
@@ -63,23 +75,68 @@ public void parseFlags() {
6375
}
6476

6577
@Override
66-
public CompletableFuture<ScriptAnalyzeResult> parseScript(String path) {
78+
public CompletableFuture<ScriptAnalyzeResults> parseScript(String path, boolean load) {
6779
File file = new File(path);
68-
if (!file.exists() || !file.getName().endsWith(".sk")) {
80+
if (!file.exists() || (!file.getName().endsWith(".sk") && !(file.isDirectory() && load))) {
6981
skAnalyzer.getLogger().error("Invalid file path");
7082
return CompletableFuture.failedFuture(new InvalidPathException(path, "Provided file doesn't end with '.sk'"));
7183
}
72-
AnalyzerCommandSender sender = new AnalyzerCommandSender(skAnalyzer);
73-
RedirectingLogHandler logHandler = new RedirectingLogHandler(sender, null).start();
74-
return ScriptLoader.loadScripts(file, logHandler, false)
75-
.handle((info, throwable) -> {
76-
if (throwable != null) {
77-
skAnalyzer.getLogger().error("Something went wrong while trying to parse '%s'".formatted(path), throwable);
78-
return CompletableFuture.failedFuture(new RuntimeException(throwable));
79-
}
80-
return CompletableFuture.completedFuture(info);
81-
})
82-
.thenApply(info -> sender.finish(file, handleParsedScript(file)));
84+
85+
Set<File> files = FilesUtil.listScripts(file);
86+
return CompletableFuture.supplyAsync(
87+
() -> {
88+
CachingLogHandler logHandler = new CachingLogHandler().start();
89+
return ScriptLoader.loadScripts(files, logHandler)
90+
.handle((info, throwable) -> {
91+
if (throwable != null) {
92+
skAnalyzer.getLogger().error("Something went wrong while trying to parse '%s'".formatted(path), throwable);
93+
throw new RuntimeException(throwable);
94+
}
95+
return info;
96+
})
97+
.thenApply(info -> {
98+
ScriptAnalyzeResults results = new ScriptAnalyzeResults(buildAnalyzeResults(files, logHandler));
99+
if (!load) {
100+
unloadScript(path);
101+
}
102+
return results;
103+
})
104+
.join();
105+
},
106+
mainThreadExecutor
107+
);
108+
}
109+
110+
@Override
111+
public boolean unloadScript(String path) {
112+
File file = new File(path);
113+
if (!file.exists() || !file.getName().endsWith(".sk")) {
114+
skAnalyzer.getLogger().error("Invalid file path");
115+
return false;
116+
}
117+
118+
Script script = ScriptLoader.getScript(file);
119+
if (script != null) {
120+
ScriptLoader.unloadScript(script);
121+
return true;
122+
}
123+
return false;
124+
}
125+
126+
@Override
127+
public void unloadAllScripts() {
128+
ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts());
129+
}
130+
131+
private Map<File, ScriptAnalyzeResult> buildAnalyzeResults(Set<File> files, CachingLogHandler logHandler) {
132+
return files.stream().collect(Collectors.toMap(
133+
Function.identity(),
134+
file -> new ScriptAnalyzeResult(
135+
file,
136+
logHandler.scriptErrors(file),
137+
handleParsedScript(file)
138+
)
139+
));
83140
}
84141

85142
private ScriptStructure handleParsedScript(File file) {
@@ -92,15 +149,14 @@ private ScriptStructure handleParsedScript(File file) {
92149
if (script != null) {
93150
script.getStructures().forEach(structure -> {
94151
if (structure instanceof StructCommand command) {
95-
ScriptCommand scriptCommand = ReflectionUtil.getScriptCommand(command);
152+
ScriptCommand scriptCommand = command.scriptCommand;
96153
if (scriptCommand == null) return;
97154
commandDataList.add(handleCommand(command, scriptCommand));
98155
} else if (structure instanceof StructEvent event) {
99-
SkriptEventInfo<?> eventInfo = ReflectionUtil.getEventInfo(event.getSkriptEvent());
100-
if (eventInfo == null) return;
156+
SkriptEventInfo<?> eventInfo = event.getSkriptEvent().skriptEventInfo;
101157
eventDataList.add(handleEvent(event.getSkriptEvent(), eventInfo));
102158
} else if (structure instanceof StructFunction function) {
103-
Signature<?> signature = ReflectionUtil.getFunctionSignature(function);
159+
Signature<?> signature = function.signature;
104160
if (signature == null) return;
105161
functionDataList.add(handleFunction(function, signature));
106162
}
@@ -110,8 +166,6 @@ private ScriptStructure handleParsedScript(File file) {
110166
if (optionsData != null) {
111167
options.putAll(optionsData.getOptions());
112168
}
113-
114-
ScriptLoader.unloadScript(script);
115169
}
116170

117171
return new ScriptStructure(commandDataList, eventDataList, functionDataList, options);
@@ -122,35 +176,30 @@ private CommandData handleCommand(StructCommand command, ScriptCommand scriptCom
122176
command.getEntryContainer().getSource().getLine(),
123177
scriptCommand.getName(),
124178
scriptCommand.getAliases(),
125-
StringUtils.defaultIfEmpty(ReflectionUtil.getCommandPermission(scriptCommand), null),
126-
StringUtils.defaultIfEmpty(ReflectionUtil.getCommandDescription(scriptCommand), null),
179+
StringUtils.defaultIfEmpty(scriptCommand.permission, null),
180+
StringUtils.defaultIfEmpty(scriptCommand.description, null),
127181
scriptCommand.getPrefix(),
128-
StringUtils.defaultIfEmpty(ReflectionUtil.getCommandUsage(scriptCommand), null),
182+
StringUtils.defaultIfEmpty(scriptCommand.usage, null),
129183
scriptCommand.getArguments().stream()
130-
.map(argument -> {
131-
ClassInfo<?> argumentType = ReflectionUtil.getArgumentType(argument);
132-
if (argumentType != null)
133-
return argumentType.getCodeName();
134-
return null;
135-
})
136-
.filter(Objects::nonNull)
184+
.map(argument -> argument.type.getCodeName())
137185
.toList()
138186
);
139187
}
140188

141189
private EventData handleEvent(SkriptEvent event, SkriptEventInfo<?> eventInfo) {
142190
return new EventData(
143191
event.getEntryContainer().getSource().getLine(),
144-
ReflectionUtil.getEventExpression(event),
192+
event.expr,
145193
Objects.requireNonNullElse(eventInfo.getDocumentationID(), eventInfo.getId()),
146194
event.getEventPriority()
147195
);
148196
}
149197

150198
private FunctionData handleFunction(StructFunction function, Signature<?> signature) {
151199
String returnType = null;
152-
if (signature.getReturnType() != null)
200+
if (signature.getReturnType() != null) {
153201
returnType = signature.getReturnType().getCodeName();
202+
}
154203

155204
return new FunctionData(
156205
function.getEntryContainer().getSource().getLine(),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package me.glicz.skanalyzer.bridge.log;
2+
3+
import ch.njol.skript.log.LogEntry;
4+
import ch.njol.skript.log.LogHandler;
5+
import ch.njol.skript.log.SkriptLogger;
6+
import me.glicz.skanalyzer.error.ScriptError;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Unmodifiable;
9+
10+
import java.io.File;
11+
import java.util.ArrayList;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
public class CachingLogHandler extends LogHandler {
17+
private final Map<File, List<ScriptError>> scriptErrors = new HashMap<>();
18+
19+
public @Unmodifiable List<ScriptError> scriptErrors(File file) {
20+
if (scriptErrors.containsKey(file)) {
21+
return List.copyOf(scriptErrors.get(file));
22+
}
23+
return List.of();
24+
}
25+
26+
@Override
27+
public @NotNull LogResult log(@NotNull LogEntry entry) {
28+
if (entry.node != null) {
29+
this.scriptErrors.computeIfAbsent(entry.node.getConfig().getFile(), file -> new ArrayList<>())
30+
.add(new ScriptError(entry.node.getLine(), entry.message, entry.level));
31+
}
32+
33+
return LogResult.CACHED;
34+
}
35+
36+
@Override
37+
public @NotNull CachingLogHandler start() {
38+
return SkriptLogger.startLogHandler(this);
39+
}
40+
}

0 commit comments

Comments
 (0)