Skip to content

Commit

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

# Conflicts:
#	src/main/java/ch/njol/skript/events/SimpleEvents.java
  • Loading branch information
TheAbsolutionism committed Dec 20, 2024
2 parents 87823d8 + b9fbbfa commit 116bb6a
Show file tree
Hide file tree
Showing 85 changed files with 3,879 additions and 797 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
shadow group: 'org.bstats', name: 'bstats-bukkit', version: '3.0.2'
shadow group: 'net.kyori', name: 'adventure-text-serializer-bungeecord', version: '4.3.2'

implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.21.3-R0.1-SNAPSHOT'
implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.21.4-R0.1-SNAPSHOT'
implementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.1'

// bundled with Minecraft 1.19.4+ for display entity transforms
Expand Down Expand Up @@ -244,7 +244,7 @@ void createTestTask(String name, String desc, String environments, int javaVersi
def java21 = 21
def java17 = 17

def latestEnv = 'java21/paper-1.21.3.json'
def latestEnv = 'java21/paper-1.21.4.json'
def latestJava = java21
def oldestJava = java17

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import org.skriptlang.skript.bukkit.SkriptMetrics;
import org.skriptlang.skript.bukkit.breeding.BreedingModule;
import org.skriptlang.skript.bukkit.displays.DisplayModule;
import org.skriptlang.skript.bukkit.fishing.FishingModule;
import org.skriptlang.skript.bukkit.input.InputModule;
import org.skriptlang.skript.lang.comparator.Comparator;
import org.skriptlang.skript.lang.comparator.Comparators;
Expand Down Expand Up @@ -544,6 +545,7 @@ public void onEnable() {
"conditions", "effects", "events", "expressions", "entity", "sections", "structures");
getAddonInstance().loadClasses("org.skriptlang.skript.bukkit", "misc");
// todo: become proper module once registry api is merged
FishingModule.load();
BreedingModule.load();
DisplayModule.load();
InputModule.load();
Expand Down
58 changes: 37 additions & 21 deletions src/main/java/ch/njol/skript/SkriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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 @@ -64,27 +65,28 @@ 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("all")
.add("config")
.add("aliases")
.add("scripts")
.add("<script>")
).add(new CommandHelp("enable", SkriptColor.DARK_CYAN)
.add("all")
.add("<script>")
).add(new CommandHelp("disable", SkriptColor.DARK_CYAN)
.add("all")
.add("<script>")
).add(new CommandHelp("update", SkriptColor.DARK_CYAN)
.add("check")
.add("changes")
.add("download")
).add("info"
).add("help");
.add(new CommandHelp("reload", SkriptColor.DARK_RED)
.add("all")
.add("config")
.add("aliases")
.add("scripts")
.add("<script>")
).add(new CommandHelp("enable", SkriptColor.DARK_RED)
.add("all")
.add("<script>")
).add(new CommandHelp("disable", SkriptColor.DARK_RED)
.add("all")
.add("<script>")
).add(new CommandHelp("update", SkriptColor.DARK_RED)
.add("check")
.add("changes")
)
.add("list")
.add("show")
.add("info")
.add("help");

static {
// Add command to generate documentation
Expand Down Expand Up @@ -360,8 +362,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 @@ -449,6 +449,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);
}
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");
if (Documentation.getDocsTemplateDirectory().exists())
options.add("gen-docs");
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
27 changes: 26 additions & 1 deletion src/main/java/ch/njol/skript/classes/EnumClassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import ch.njol.util.coll.iterator.ArrayIterator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.comparator.Comparators;
import org.skriptlang.skript.lang.comparator.Relation;

/**
* This class can be used for an easier writing of ClassInfos that are enums,
Expand All @@ -23,7 +25,17 @@ public class EnumClassInfo<T extends Enum<T>> extends ClassInfo<T> {
* @param languageNode The language node of the type
*/
public EnumClassInfo(Class<T> enumClass, String codeName, String languageNode) {
this(enumClass, codeName, languageNode, new EventValueExpression<>(enumClass));
this(enumClass, codeName, languageNode, new EventValueExpression<>(enumClass), true);
}

/**
* @param enumClass The class
* @param codeName The name used in patterns
* @param languageNode The language node of the type
* @param registerComparator Whether a default comparator should be registered for this enum's classinfo
*/
public EnumClassInfo(Class<T> enumClass, String codeName, String languageNode, boolean registerComparator) {
this(enumClass, codeName, languageNode, new EventValueExpression<>(enumClass), registerComparator);
}

/**
Expand All @@ -33,6 +45,17 @@ public EnumClassInfo(Class<T> enumClass, String codeName, String languageNode) {
* @param defaultExpression The default expression of the type
*/
public EnumClassInfo(Class<T> enumClass, String codeName, String languageNode, DefaultExpression<T> defaultExpression) {
this(enumClass, codeName, languageNode, defaultExpression, true);
}

/**
* @param enumClass The class
* @param codeName The name used in patterns
* @param languageNode The language node of the type
* @param defaultExpression The default expression of the type
* @param registerComparator Whether a default comparator should be registered for this enum's classinfo
*/
public EnumClassInfo(Class<T> enumClass, String codeName, String languageNode, DefaultExpression<T> defaultExpression, boolean registerComparator) {
super(enumClass, codeName);
EnumUtils<T> enumUtils = new EnumUtils<>(enumClass, languageNode);
usage(enumUtils.getAllNames())
Expand All @@ -55,6 +78,8 @@ public EnumClassInfo(Class<T> enumClass, String codeName, String languageNode, D
return enumUtils.toString(constant, StringMode.VARIABLE_NAME);
}
});
if (registerComparator)
Comparators.registerComparator(enumClass, enumClass, (o1, o2) -> Relation.get(o1.ordinal() - o2.ordinal()));
}

}
Loading

0 comments on commit 116bb6a

Please sign in to comment.