Skip to content

Commit

Permalink
Update to 2.5-alpha4
Browse files Browse the repository at this point in the history
  • Loading branch information
Matocolotoe committed Jun 29, 2020
1 parent e8d26b8 commit e6659e0
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 48 deletions.
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ allprojects {
url 'http://ci.emc.gs/nexus/content/groups/aikar/'
}

maven {
url 'http://nexus.hc.to/content/repositories/pub_releases'
}

maven {
url 'https://jitpack.io'
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
groupid=ch.njol
name=skript
version=2.5-alpha3
version=2.5-alpha4
101 changes: 71 additions & 30 deletions src/main/java/ch/njol/skript/ScriptLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -107,27 +108,27 @@ final public class ScriptLoader {
private ScriptLoader() {}

private final static Message m_no_errors = new Message("skript.no errors"),
m_no_scripts = new Message("skript.no scripts");
m_no_scripts = new Message("skript.no scripts");
private final static PluralizingArgsMessage m_scripts_loaded = new PluralizingArgsMessage("skript.scripts loaded");

@Nullable
public static Config currentScript = null;

/**
* If true, a {@link PreScriptLoadEvent} will be called
* right before a script starts parsing, but after
* {@link ScriptLoader#currentScript} has been set
* to a non-null {@link Config}.
*/
private static boolean callPreLoadEvent;

/**
* A set of all the SkriptAddons that have called
* {@link ScriptLoader#setCallPreloadEvent(boolean, SkriptAddon)}
* with true.
*/
private static Set<SkriptAddon> preloadListeners = new HashSet<>();

/**
* Sets {@link ScriptLoader#callPreLoadEvent} to the provided boolean,
* and adds/removes the provided SkriptAddon from {@link ScriptLoader#preloadListeners}
Expand All @@ -143,11 +144,11 @@ public static void setCallPreloadEvent(boolean state, SkriptAddon addon) {
else
preloadListeners.remove(addon);
}

public static boolean getCallPreloadEvent() {
return callPreLoadEvent;
}

/**
* Returns an unmodifiable list of all the addons
* that have called {@link ScriptLoader#setCallPreloadEvent(boolean, SkriptAddon)}
Expand All @@ -157,7 +158,7 @@ public static boolean getCallPreloadEvent() {
public static Set<SkriptAddon> getPreloadListeners() {
return Collections.unmodifiableSet(preloadListeners);
}

/**
* use {@link #setCurrentEvent(String, Class...)}
*/
Expand All @@ -177,7 +178,7 @@ public static String getCurrentEventName() {

/**
* Call {@link #deleteCurrentEvent()} after parsing
*
*
* @param name
* @param events
*/
Expand Down Expand Up @@ -238,7 +239,7 @@ public ScriptInfo(ScriptInfo o) {
functions = o.functions;
commandNames = new HashSet<>(o.commandNames);
}

public void add(final ScriptInfo other) {
files += other.files;
triggers += other.triggers;
Expand All @@ -264,7 +265,7 @@ public String toString() {
* to be re-sent to clients on MC 1.13+.
*/
private static final Map<String, Set<String>> commandNames = new HashMap<>();

// private final static class SerializedScript {
// public SerializedScript() {}
//
Expand Down Expand Up @@ -306,6 +307,39 @@ public static Collection<File> getLoadedFiles() {
return Collections.unmodifiableCollection(loadedFiles);
}

/**
* All disabled script files.
*/
@SuppressWarnings("null")
static final Set<File> disabledFiles = Collections.synchronizedSet(new HashSet<>());

@SuppressWarnings("null")
public static Collection<File> getDisabledFiles() {
return Collections.unmodifiableCollection(disabledFiles);
}

/**
* Filter for disabled scripts & folders.
*/
private final static FileFilter disabledFilter = new FileFilter() {
@Override
public boolean accept(final @Nullable File f) {
return f != null && (f.isDirectory() || StringUtils.endsWithIgnoreCase("" + f.getName(), ".sk")) && f.getName().startsWith("-");
}
};

private static void updateDisabledScripts(Path path) {
disabledFiles.clear();
try {
Files.walk(path)
.map(Path::toFile)
.filter(disabledFilter::accept)
.forEach(disabledFiles::add);
} catch (IOException e) {
e.printStackTrace();
}
}

// Initialize and start load thread
static {
loaderThread = new AsyncLoaderThread();
Expand All @@ -315,7 +349,7 @@ public static Collection<File> getLoadedFiles() {
private static class AsyncLoaderThread extends Thread {

public AsyncLoaderThread() { }

@Override
public void run() {
while (true) {
Expand All @@ -335,6 +369,8 @@ static void loadScripts() {

final Date start = new Date();

updateDisabledScripts(scriptsFolder.toPath());

Runnable task = () -> {
final Set<File> oldLoadedFiles = new HashSet<>(loadedFiles);

Expand All @@ -361,7 +397,7 @@ static void loadScripts() {
// Use internal unload method which does not call validateFunctions()
unloadScript_(script);
String name = Skript.getInstance().getDataFolder().toPath().toAbsolutePath()
.resolve(Skript.SCRIPTSFOLDER).relativize(script.toPath()).toString();
.resolve(Skript.SCRIPTSFOLDER).relativize(script.toPath()).toString();
assert name != null;
Functions.clearFunctions(name);
}
Expand Down Expand Up @@ -393,7 +429,7 @@ public boolean accept(final @Nullable File f) {

/**
* Loads the specified scripts.
*
*
* @param configs Configs for scripts, loaded by {@link #loadStructures(File[])}
* @return Info on the loaded scripts.
*/
Expand Down Expand Up @@ -432,7 +468,7 @@ public static ScriptInfo loadScripts(final List<Config> configs) {
if (syncCommands.get()) {
Server server = Bukkit.getServer();
assert server != null;
if (CommandReloader.syncCommands(server))
if (CommandReloader.syncCommands(server))
Skript.debug("Commands synced to clients");
else
Skript.debug("Commands changed but not synced to clients (normal on 1.12 and older)");
Expand All @@ -447,7 +483,7 @@ public static ScriptInfo loadScripts(final List<Config> configs) {

/**
* Loads specified scripts and places log to given list.
*
*
* @param configs Configs for scripts, loaded by {@link #loadStructures(File[])}
* @param logOut List where to place log.
* @return Info on the loaded scripts.
Expand All @@ -465,7 +501,7 @@ public static ScriptInfo loadScripts(final List<Config> configs, final List<LogE

/**
* Loads the specified scripts.
*
*
* @param configs Configs for scripts, loaded by {@link #loadStructure(File)}
* @return Info on the loaded scripts
*/
Expand All @@ -475,7 +511,7 @@ public static ScriptInfo loadScripts(final Config... configs) {

/**
* Load specified scripts.
*
*
* @param files Script files.
* @return Info on the loaded scripts.
* @deprecated Use the methods that take configs as parameters.
Expand Down Expand Up @@ -530,7 +566,7 @@ private static ScriptInfo loadScript(final @Nullable Config config) {

currentOptions.clear();
currentScript = config;

/*
* If editing this class, please remember to call this event
* after currentScript has already been set to the provided Config,
Expand Down Expand Up @@ -719,10 +755,10 @@ public String run(final Matcher m) {

// In always sync task, enable stuff
Callable<Void> callable = new Callable<Void>() {

@SuppressWarnings("synthetic-access")
@SuppressWarnings({"synthetic-access", "null"})
@Override
public @Nullable Void call() throws Exception {
public @Nullable Void call() throws Exception {
// Unload script IF we're doing async stuff
// (else it happened already)
File file = config.getFile();
Expand Down Expand Up @@ -759,6 +795,10 @@ public String run(final Matcher m) {
deleteCurrentEvent();
}

// Remove the script from the disabled scripts list
File disabledFile = new File(file.getParentFile(), "-" + file.getName());
disabledFiles.remove(disabledFile);

// Add to loaded files to use for future reloads
loadedFiles.add(file);

Expand All @@ -780,7 +820,7 @@ public String run(final Matcher m) {

/**
* Loads structures of specified scripts.
*
*
* @param files
*/
public static List<Config> loadStructures(final File[] files) {
Expand Down Expand Up @@ -834,7 +874,7 @@ public static List<Config> loadStructures(File directory) {

try {
String name = Skript.getInstance().getDataFolder().toPath().toAbsolutePath()
.resolve(Skript.SCRIPTSFOLDER).relativize(f.toPath().toAbsolutePath()).toString();
.resolve(Skript.SCRIPTSFOLDER).relativize(f.toPath().toAbsolutePath()).toString();
assert name != null;
return loadStructure(new FileInputStream(f), name);
} catch (final IOException e) {
Expand All @@ -853,7 +893,7 @@ public static List<Config> loadStructures(File directory) {
public static @Nullable Config loadStructure(final InputStream source, final String name) {
try {
final Config config = new Config(source, name,
Skript.getInstance().getDataFolder().toPath().resolve(Skript.SCRIPTSFOLDER).resolve(name).toFile(), true, false, ":");
Skript.getInstance().getDataFolder().toPath().resolve(Skript.SCRIPTSFOLDER).resolve(name).toFile(), true, false, ":");
return loadStructure(config);
} catch (final IOException e) {
Skript.error("Could not load " + name + ": " + ExceptionUtils.toString(e));
Expand Down Expand Up @@ -915,7 +955,7 @@ public static List<Config> loadStructures(File directory) {

/**
* Unloads enabled scripts from the specified directory and its subdirectories.
*
*
* @param folder
* @return Info on the unloaded scripts
*/
Expand All @@ -940,7 +980,7 @@ private static ScriptInfo unloadScripts_(final File folder) {

/**
* Unloads the specified script.
*
*
* @param script
* @return Info on the unloaded script
*/
Expand All @@ -958,12 +998,13 @@ private static ScriptInfo unloadScript_(final File script) {
}

loadedFiles.remove(script); // We just unloaded it, so...
disabledFiles.add(new File(script.getParentFile(), "-" + script.getName()));

// Clear functions, DO NOT validate them yet
// If unloading, our caller will do this immediately after we return
// However, if reloading, new version of this script is first loaded
String name = Skript.getInstance().getDataFolder().toPath().toAbsolutePath()
.resolve(Skript.SCRIPTSFOLDER).relativize(script.toPath().toAbsolutePath()).toString();
.resolve(Skript.SCRIPTSFOLDER).relativize(script.toPath().toAbsolutePath()).toString();
assert name != null;
Functions.clearFunctions(name);

Expand Down Expand Up @@ -1000,7 +1041,7 @@ public static ScriptInfo reloadScripts(File folder) {
Functions.validateFunctions();
return loadScripts(configs);
}

/**
* Replaces options in a string.
*/
Expand Down Expand Up @@ -1147,7 +1188,7 @@ public static ArrayList<TriggerItem> loadItems(final SectionNode node) {

/**
* For unit testing
*
*
* @param node
* @return The loaded Trigger
*/
Expand Down Expand Up @@ -1216,4 +1257,4 @@ public static Class<? extends Event>[] getCurrentEvents() {
return currentEvents;
}

}
}
9 changes: 9 additions & 0 deletions src/main/java/ch/njol/skript/SkriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginDescriptionFile;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.ScriptLoader.ScriptInfo;
Expand Down Expand Up @@ -332,6 +333,14 @@ public boolean onCommand(final @Nullable CommandSender sender, final @Nullable C
} else if (args[0].equalsIgnoreCase("info")) {
info(sender, "info.aliases");
info(sender, "info.documentation");
info(sender, "info.server", Bukkit.getVersion());
info(sender, "info.version", Skript.getVersion());
info(sender, "info.addons");
for (SkriptAddon addon : Skript.getAddons()) {
PluginDescriptionFile desc = addon.plugin.getDescription();
String web = desc.getWebsite();
Skript.info(sender, " - " + desc.getFullName() + (web != null ? " (" + web + ")" : ""));
}
} else if (args[0].equalsIgnoreCase("help")) {
skriptCommandHelp.showHelp(sender);
} else if (args[0].equalsIgnoreCase("gen-docs")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void setBlock(Block block, Material type, @Nullable BlockValues values, i
// Generic block placement
if (!placed) {
block.setType(type);
if (ourValues != null)
if (ourValues != null && !ourValues.isDefault())
block.setBlockData(ourValues.data, applyPhysics);
}
}
Expand Down
Loading

0 comments on commit e6659e0

Please # to comment.