Skip to content

Commit 8274f7c

Browse files
committed
Merge remote-tracking branch 'upstream/dev/feature' into dev/Recipes
# Conflicts: # src/main/java/ch/njol/skript/Skript.java
2 parents baa600e + a0dc7b4 commit 8274f7c

File tree

290 files changed

+8197
-4247
lines changed

Some content is hidden

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

290 files changed

+8197
-4247
lines changed

src/main/java/ch/njol/skript/ScriptLoader.java

Lines changed: 49 additions & 253 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import ch.njol.skript.log.*;
1616
import ch.njol.skript.sections.SecLoop;
1717
import ch.njol.skript.structures.StructOptions.OptionsData;
18+
import ch.njol.skript.test.runner.TestMode;
1819
import ch.njol.skript.util.ExceptionUtils;
1920
import ch.njol.skript.util.SkriptColor;
2021
import ch.njol.skript.util.Task;
@@ -26,11 +27,12 @@
2627
import ch.njol.util.StringUtils;
2728
import org.bukkit.Bukkit;
2829
import org.bukkit.event.Event;
30+
import org.jetbrains.annotations.ApiStatus;
2931
import org.jetbrains.annotations.Nullable;
30-
import org.skriptlang.skript.util.event.EventRegistry;
3132
import org.skriptlang.skript.lang.script.Script;
3233
import org.skriptlang.skript.lang.script.ScriptWarning;
3334
import org.skriptlang.skript.lang.structure.Structure;
35+
import org.skriptlang.skript.util.event.EventRegistry;
3436

3537
import java.io.File;
3638
import java.io.FileFilter;
@@ -457,6 +459,7 @@ public static CompletableFuture<ScriptInfo> loadScripts(Set<File> files, OpenClo
457459
* and closed after the {@link Structure#postLoad()} stage.
458460
* @return Info on the loaded scripts.
459461
*/
462+
@SuppressWarnings("removal")
460463
private static CompletableFuture<ScriptInfo> loadScripts(List<Config> configs, OpenCloseable openCloseable) {
461464
if (configs.isEmpty()) // Nothing to load
462465
return CompletableFuture.completedFuture(new ScriptInfo());
@@ -696,7 +699,6 @@ private static LoadingScriptInfo loadScript(Config config) {
696699

697700
ScriptLoader.eventRegistry().events(ScriptInitEvent.class)
698701
.forEach(event -> event.onInit(script));
699-
700702
return null;
701703
};
702704
if (isAsync()) { // Need to delegate to main thread
@@ -868,6 +870,7 @@ public static ScriptInfo unloadScripts(Set<Script> scripts) {
868870
parser.setInactive();
869871

870872
script.clearData();
873+
script.invalidate();
871874
loadedScripts.remove(script); // We just unloaded it, so...
872875
File scriptFile = script.getConfig().getFile();
873876
assert scriptFile != null;
@@ -1049,6 +1052,20 @@ public static ArrayList<TriggerItem> loadItems(SectionNode node) {
10491052
return items;
10501053
}
10511054

1055+
/**
1056+
* Creates a Script object for a file (or resource) that may (or may not) exist.
1057+
* This is used for providing handles for disabled scripts.
1058+
* <br/>
1059+
* This does <em>not</em> load (or parse or open or do anything to) the given file.
1060+
*
1061+
* @return An unlinked, empty script object with an empty backing config
1062+
*/
1063+
@ApiStatus.Internal
1064+
public static Script createDummyScript(String name, @Nullable File file) {
1065+
Config config = new Config(name, file);
1066+
return new Script(config, Collections.emptyList());
1067+
}
1068+
10521069
/*
10531070
* Other Utility Methods
10541071
*/
@@ -1173,263 +1190,42 @@ public static EventRegistry<LoaderEvent> eventRegistry() {
11731190
return eventRegistry;
11741191
}
11751192

1176-
/*
1177-
* Deprecated stuff
1178-
*
1179-
* These fields / methods are from the old version of ScriptLoader,
1180-
* and are merely here for backwards compatibility.
1181-
*
1182-
* Some methods have been replaced by ParserInstance, some
1183-
* by new methods in this class.
1184-
*/
1185-
1186-
/**
1187-
* Unloads the provided script.
1188-
* @param scriptFile The file representing the script to unload.
1189-
* @return Statistics for the unloaded script.
1190-
* @deprecated Use {@link #unloadScript(Script)}.
1191-
*/
1192-
@Deprecated
1193-
public static ScriptInfo unloadScript(File scriptFile) {
1194-
Script script = getScript(scriptFile);
1195-
if (script != null)
1196-
return unloadScript(script);
1197-
return new ScriptInfo();
1198-
}
1199-
1200-
/**
1201-
* Unloads all scripts present in the provided folder.
1202-
* @param folder The folder containing scripts to unload.
1203-
* @return Combined statistics for the unloaded scripts.
1204-
* This data is calculated by using {@link ScriptInfo#add(ScriptInfo)}.
1205-
* @deprecated Use {@link #unloadScripts(Set)}.
1206-
*/
1207-
@Deprecated
1208-
private static ScriptInfo unloadScripts(File folder) {
1209-
return unloadScripts(getScripts(folder));
1210-
}
1211-
1212-
/**
1213-
* Reloads a single script.
1214-
* @param scriptFile The file representing the script to reload.
1215-
* @return Future of statistics of the newly loaded script.
1216-
* @deprecated Use {@link #reloadScript(Script, OpenCloseable)}.
1217-
*/
1218-
@Deprecated
1219-
public static CompletableFuture<ScriptInfo> reloadScript(File scriptFile, OpenCloseable openCloseable) {
1220-
unloadScript(scriptFile);
1221-
return loadScripts(scriptFile, openCloseable);
1222-
}
1223-
1224-
/**
1225-
* Reloads all scripts in the given folder and its subfolders.
1226-
* @param folder A folder.
1227-
* @return Future of statistics of newly loaded scripts.
1228-
* @deprecated Use {@link #reloadScripts}.
1229-
*/
1230-
@Deprecated
1231-
public static CompletableFuture<ScriptInfo> reloadScripts(File folder, OpenCloseable openCloseable) {
1232-
unloadScripts(folder);
1233-
return loadScripts(folder, openCloseable);
1234-
}
1235-
12361193
/**
1237-
* @deprecated Use <b>{@link #getLoadedScripts()}.size()</b>.
1194+
* Gets a script's file from its name, if one exists.
1195+
* @param script The script name/path
1196+
* @return The script file, if one is found
12381197
*/
1239-
@Deprecated
1240-
public static int loadedScripts() {
1241-
return getLoadedScripts().size();
1242-
}
1243-
1244-
/**
1245-
* @deprecated Use <b>{@link #getLoadedScripts()}</b> and <b>{@link Script#getStructures()}.size()</b>.
1246-
* Please note that a Structure may have multiple triggers, and this is only an estimate.
1247-
*/
1248-
@Deprecated
1249-
public static int loadedTriggers() {
1250-
int loaded = 0;
1251-
for (Script script : getLoadedScripts())
1252-
loaded += script.getStructures().size();
1253-
return loaded;
1254-
}
1255-
1256-
/**
1257-
* @deprecated Use {@link #loadScripts(File, OpenCloseable)}
1258-
*/
1259-
@Deprecated
1260-
static void loadScripts() {
1261-
unloadScripts(getLoadedScripts());
1262-
loadScripts(Skript.getInstance().getScriptsFolder(), OpenCloseable.EMPTY).join();
1263-
}
1198+
@Nullable
1199+
public static File getScriptFromName(String script) {
1200+
if (script.endsWith("/") || script.endsWith("\\")) { // Always allow '/' and '\' regardless of OS
1201+
script = script.replace('/', File.separatorChar).replace('\\', File.separatorChar);
1202+
} else if (!StringUtils.endsWithIgnoreCase(script, ".sk")) {
1203+
int dot = script.lastIndexOf('.');
1204+
if (dot > 0 && !script.substring(dot + 1).equals(""))
1205+
return null;
1206+
script = script + ".sk";
1207+
}
12641208

1265-
/**
1266-
* @deprecated Callers should not be using configs. Use {@link #loadScripts(Set, OpenCloseable)}.
1267-
*/
1268-
@Deprecated
1269-
public static ScriptInfo loadScripts(List<Config> configs) {
1270-
return loadScripts(configs, OpenCloseable.EMPTY).join();
1271-
}
1209+
if (script.startsWith(ScriptLoader.DISABLED_SCRIPT_PREFIX))
1210+
script = script.substring(ScriptLoader.DISABLED_SCRIPT_PREFIX_LENGTH);
12721211

1273-
/**
1274-
* @deprecated Callers should not be using configs. Use {@link #loadScripts(Set, OpenCloseable)}.
1275-
* @see RetainingLogHandler
1276-
*/
1277-
@Deprecated
1278-
public static ScriptInfo loadScripts(List<Config> configs, List<LogEntry> logOut) {
1279-
RetainingLogHandler logHandler = new RetainingLogHandler();
1212+
File scriptsFolder = Skript.getInstance().getScriptsFolder();
1213+
File scriptFile = new File(scriptsFolder, script);
1214+
if (!scriptFile.exists()) {
1215+
scriptFile = new File(scriptFile.getParentFile(), ScriptLoader.DISABLED_SCRIPT_PREFIX + scriptFile.getName());
1216+
if (!scriptFile.exists()) {
1217+
return null;
1218+
}
1219+
}
12801220
try {
1281-
return loadScripts(configs, logHandler).join();
1282-
} finally {
1283-
logOut.addAll(logHandler.getLog());
1221+
// Unless it's a test, check if the user is asking for a script in the scripts folder
1222+
// and not something outside Skript's domain.
1223+
if (TestMode.ENABLED || scriptFile.getCanonicalPath().startsWith(scriptsFolder.getCanonicalPath() + File.separator))
1224+
return scriptFile.getCanonicalFile();
1225+
return null;
1226+
} catch (IOException e) {
1227+
throw Skript.exception(e, "An exception occurred while trying to get the script file from the string '" + script + "'");
12841228
}
12851229
}
12861230

1287-
/**
1288-
* @deprecated Callers should not be using configs. Use {@link #loadScripts(Set, OpenCloseable)}.
1289-
*/
1290-
@Deprecated
1291-
public static ScriptInfo loadScripts(Config... configs) {
1292-
return loadScripts(Arrays.asList(configs), OpenCloseable.EMPTY).join();
1293-
}
1294-
1295-
/**
1296-
* @deprecated Use {@link #reloadScript(Script, OpenCloseable)}.
1297-
*/
1298-
@Deprecated
1299-
public static ScriptInfo reloadScript(File script) {
1300-
return reloadScript(script, OpenCloseable.EMPTY).join();
1301-
}
1302-
1303-
/**
1304-
* @deprecated Use {@link #reloadScripts(Set, OpenCloseable)}.
1305-
*/
1306-
@Deprecated
1307-
public static ScriptInfo reloadScripts(File folder) {
1308-
return reloadScripts(folder, OpenCloseable.EMPTY).join();
1309-
}
1310-
1311-
/**
1312-
* @deprecated Use {@link ParserInstance#getHasDelayBefore()}.
1313-
*/
1314-
@Deprecated
1315-
public static Kleenean getHasDelayBefore() {
1316-
return getParser().getHasDelayBefore();
1317-
}
1318-
1319-
/**
1320-
* @deprecated Use {@link ParserInstance#setHasDelayBefore(Kleenean)}.
1321-
*/
1322-
@Deprecated
1323-
public static void setHasDelayBefore(Kleenean hasDelayBefore) {
1324-
getParser().setHasDelayBefore(hasDelayBefore);
1325-
}
1326-
1327-
/**
1328-
* @deprecated Use {@link ParserInstance#getCurrentScript()}.
1329-
*/
1330-
@Nullable
1331-
@Deprecated
1332-
public static Config getCurrentScript() {
1333-
ParserInstance parser = getParser();
1334-
return parser.isActive() ? parser.getCurrentScript().getConfig() : null;
1335-
}
1336-
1337-
/**
1338-
* @deprecated Addons should no longer be modifying this.
1339-
*/
1340-
@Deprecated
1341-
public static void setCurrentScript(@Nullable Config currentScript) {
1342-
getParser().setCurrentScript(currentScript);
1343-
}
1344-
1345-
/**
1346-
* @deprecated Use {@link ParserInstance#getCurrentSections()}.
1347-
*/
1348-
@Deprecated
1349-
public static List<TriggerSection> getCurrentSections() {
1350-
return getParser().getCurrentSections();
1351-
}
1352-
1353-
/**
1354-
* @deprecated Use {@link ParserInstance#setCurrentSections(List)}.
1355-
*/
1356-
@Deprecated
1357-
public static void setCurrentSections(List<TriggerSection> currentSections) {
1358-
getParser().setCurrentSections(currentSections);
1359-
}
1360-
1361-
/**
1362-
* @deprecated Use {@link ParserInstance#getCurrentSections(Class)}.
1363-
*/
1364-
@Deprecated
1365-
public static List<SecLoop> getCurrentLoops() {
1366-
return getParser().getCurrentSections(SecLoop.class);
1367-
}
1368-
1369-
/**
1370-
* @deprecated Never use this method, it has no effect.
1371-
*/
1372-
@Deprecated
1373-
public static void setCurrentLoops(List<SecLoop> currentLoops) { }
1374-
1375-
/**
1376-
* @deprecated Use {@link ParserInstance#getCurrentEventName()}.
1377-
*/
1378-
@Nullable
1379-
@Deprecated
1380-
public static String getCurrentEventName() {
1381-
return getParser().getCurrentEventName();
1382-
}
1383-
1384-
/**
1385-
* @deprecated Use {@link ParserInstance#setCurrentEvent(String, Class[])}.
1386-
*/
1387-
@SafeVarargs
1388-
@Deprecated
1389-
public static void setCurrentEvent(String name, @Nullable Class<? extends Event>... events) {
1390-
getParser().setCurrentEvent(name, events);
1391-
}
1392-
1393-
/**
1394-
* @deprecated Use {@link ParserInstance#deleteCurrentEvent()}.
1395-
*/
1396-
@Deprecated
1397-
public static void deleteCurrentEvent() {
1398-
getParser().deleteCurrentEvent();
1399-
}
1400-
1401-
/**
1402-
* @deprecated Use {@link ParserInstance#isCurrentEvent(Class)}
1403-
*/
1404-
@Deprecated
1405-
public static boolean isCurrentEvent(@Nullable Class<? extends Event> event) {
1406-
return getParser().isCurrentEvent(event);
1407-
}
1408-
1409-
/**
1410-
* @deprecated Use {@link ParserInstance#isCurrentEvent(Class[])}.
1411-
*/
1412-
@SafeVarargs
1413-
@Deprecated
1414-
public static boolean isCurrentEvent(Class<? extends Event>... events) {
1415-
return getParser().isCurrentEvent(events);
1416-
}
1417-
1418-
/**
1419-
* @deprecated Use {@link ParserInstance#getCurrentEvents()}.
1420-
*/
1421-
@Nullable
1422-
@Deprecated
1423-
public static Class<? extends Event>[] getCurrentEvents() {
1424-
return getParser().getCurrentEvents();
1425-
}
1426-
1427-
/**
1428-
* @deprecated This method has no functionality, it just returns its input.
1429-
*/
1430-
@Deprecated
1431-
public static Config loadStructure(Config config) {
1432-
return config;
1433-
}
1434-
14351231
}

0 commit comments

Comments
 (0)