Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev/feature' into dev/function…
Browse files Browse the repository at this point in the history
…-locate

# Conflicts:
#	src/main/java/ch/njol/skript/SkriptCommand.java
  • Loading branch information
TheAbsolutionism committed Dec 18, 2024
2 parents 37a6e08 + 349cb58 commit 103ff88
Show file tree
Hide file tree
Showing 91 changed files with 1,205 additions and 551 deletions.
10 changes: 10 additions & 0 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,16 @@ public void onEnable() {
classLoadError = e;
}

// Warn about pausing
if (Skript.methodExists(Server.class, "getPauseWhenEmptyTime")) {
int pauseThreshold = getServer().getPauseWhenEmptyTime();
if (pauseThreshold > -1) {
Skript.warning("Minecraft server pausing is enabled!");
Skript.warning("Scripts that interact with the world or entities may not work as intended when the server is paused and may crash your server.");
Skript.warning("Consider setting 'pause-when-empty-seconds' to -1 in server.properties to make sure you don't encounter any issues.");
}
}

// Config must be loaded after Java and Skript classes are parseable
// ... but also before platform check, because there is a config option to ignore some errors
SkriptConfig.load();
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/ch/njol/skript/SkriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
Expand All @@ -68,26 +69,27 @@ public class SkriptCommand implements CommandExecutor {
private static final String CONFIG_NODE = "skript command";
private static final ArgsMessage m_reloading = new ArgsMessage(CONFIG_NODE + ".reload.reloading");

// TODO /skript scripts show/list - lists all enabled and/or disabled scripts in the scripts folder and/or subfolders (maybe add a pattern [using * and **])
// TODO document this command on the website
private static final CommandHelp SKRIPT_COMMAND_HELP = new CommandHelp("<gray>/<gold>skript", SkriptColor.LIGHT_CYAN, CONFIG_NODE + ".help")
.add(new CommandHelp("reload", SkriptColor.DARK_CYAN)
.add(new CommandHelp("reload", SkriptColor.DARK_RED)
.add("all")
.add("config")
.add("aliases")
.add("scripts")
.add("<script>")
).add(new CommandHelp("enable", SkriptColor.DARK_CYAN)
).add(new CommandHelp("enable", SkriptColor.DARK_RED)
.add("all")
.add("<script>")
).add(new CommandHelp("disable", SkriptColor.DARK_CYAN)
).add(new CommandHelp("disable", SkriptColor.DARK_RED)
.add("all")
.add("<script>")
).add(new CommandHelp("update", SkriptColor.DARK_CYAN)
).add(new CommandHelp("update", SkriptColor.DARK_RED)
.add("check")
.add("changes")
.add("download")
).add("info")
)
.add("list")
.add("show")
.add("info")
.add("help")
.add("locate");

Expand Down Expand Up @@ -368,8 +370,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
updater.updateCheck(sender);
} else if (args[1].equalsIgnoreCase("changes")) {
updater.changesCheck(sender);
} else if (args[1].equalsIgnoreCase("download")) {
updater.updateCheck(sender);
}
} else if (args[0].equalsIgnoreCase("info")) {
info(sender, "info.aliases");
Expand Down Expand Up @@ -457,6 +457,22 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
})
);
} else if (args[0].equalsIgnoreCase("list") || args[0].equalsIgnoreCase("show")) {
info(sender, "list.enabled.header");
ScriptLoader.getLoadedScripts().stream()
.map(script -> script.getConfig().getFileName())
.forEach(name -> info(sender, "list.enabled.element", name));
info(sender, "list.disabled.header");
ScriptLoader.getDisabledScripts().stream()
.flatMap(file -> {
if (file.isDirectory()) {
return Arrays.stream(file.listFiles());
}
return Arrays.stream(new File[]{file});
})
.map(File::getPath)
.map(path -> path.substring(Skript.getInstance().getScriptsFolder().getPath().length() + 1))
.forEach(path -> info(sender, "list.disabled.element", path));
} else if (args[0].equalsIgnoreCase("help")) {
SKRIPT_COMMAND_HELP.showHelp(sender);
} else if (args[0].equalsIgnoreCase("locate")) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
if (args[0].equalsIgnoreCase("update") && args.length == 2) {
options.add("check");
options.add("changes");
options.add("download");
} else if (args[0].matches("(?i)(reload|disable|enable)") && args.length >= 2) {
File scripts = Skript.getInstance().getScriptsFolder();
String scriptsPathString = scripts.toPath().toString();
Expand Down Expand Up @@ -116,6 +115,8 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
options.add("enable");
options.add("disable");
options.add("update");
options.add("list");
options.add("show");
options.add("info");
options.add("locate");
if (Documentation.getDocsTemplateDirectory().exists())
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/ch/njol/skript/SkriptConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import co.aikar.timings.Timings;
import org.bukkit.event.EventPriority;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.util.event.EventRegistry;

import java.io.File;
import java.io.IOException;
Expand All @@ -46,6 +47,37 @@
@SuppressWarnings("unused")
public class SkriptConfig {

//<editor-fold desc="SkriptConfig events">
/**
* Used for listening to events involving Skript's configuration.
* @see #eventRegistry()
*/
public interface Event extends org.skriptlang.skript.util.event.Event { }

/**
* Called when Skript's configuration is successfully reloaded.
* This occurs when the reload process has finished, meaning the config is safe to reference.
*/
@FunctionalInterface
public interface ReloadEvent extends Event {

/**
* The method that is called when this event triggers.
*/
void onReload();

}

private static final EventRegistry<Event> eventRegistry = new EventRegistry<>();

/**
* @return An event registry for the configuration's events.
*/
public static EventRegistry<Event> eventRegistry() {
return eventRegistry;
}
//</editor-fold>

@Nullable
static Config mainConfig;
static Collection<Config> configs = new ArrayList<>();
Expand Down Expand Up @@ -436,6 +468,10 @@ static boolean load() {
Skript.exception(e, "An error occurred while loading the config");
return false;
}

// trigger reload event handlers
eventRegistry().events(ReloadEvent.class).forEach(ReloadEvent::onReload);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public interface SoundReceiver {

boolean ADVENTURE_API = Skript.classExists("net.kyori.adventure.sound.Sound$Builder");
boolean ADVENTURE_API = Skript.classExists("net.kyori.adventure.sound.Sound$Builder") && Skript.methodExists(SoundCategory.class, "soundSource");
boolean SPIGOT_SOUND_SEED = Skript.methodExists(Player.class, "playSound", Entity.class, Sound.class, SoundCategory.class, float.class, float.class, long.class);
boolean ENTITY_EMITTER_SOUND = Skript.methodExists(Player.class, "playSound", Entity.class, Sound.class, SoundCategory.class, float.class, float.class);
boolean ENTITY_EMITTER_STRING = Skript.methodExists(Player.class, "playSound", Entity.class, String.class, SoundCategory.class, float.class, float.class);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/ch/njol/skript/classes/Changer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ public interface Changer<T> {

enum ChangeMode {
ADD, SET, REMOVE, REMOVE_ALL, DELETE, RESET;

public boolean supportsKeyedChange() {
return this == SET;
// ADD could be supported in future
}

}

/**
* Tests whether this changer supports the given mode, and if yes what type(s) it expects the elements of <code>delta</code> to be.
* <p>
Expand Down
Loading

0 comments on commit 103ff88

Please sign in to comment.