From 106c555a0fa02351b547a85a4dddecd4716ab86e Mon Sep 17 00:00:00 2001 From: Moderocky Date: Fri, 17 May 2024 16:09:07 +0100 Subject: [PATCH 01/38] Create Script type. --- .../ch/njol/skript/classes/data/SkriptClasses.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java b/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java index 39dc6447fa5..1c1509af3d2 100644 --- a/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java @@ -64,6 +64,8 @@ import ch.njol.skript.util.visual.VisualEffect; import ch.njol.skript.util.visual.VisualEffects; import ch.njol.yggdrasil.Fields; +import org.jetbrains.annotations.NotNull; +import org.skriptlang.skript.lang.script.Script; import java.util.Arrays; @@ -690,6 +692,14 @@ public String toVariableNameString(VisualEffect e) { .since("2.5") .serializer(new YggdrasilSerializer()) ); + + Classes.registerClass(new ClassInfo<>(Script.class, "script") + .user("scripts?") + .name("Script") + .description("A script loaded by Skript.") + .usage("") + .examples("the current script") + .since("INSERT VERSION")); } } From fe9a1fb40c6aa896865d71415a295b4f3ead92c7 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Fri, 17 May 2024 16:46:05 +0100 Subject: [PATCH 02/38] Support script string/name conversion. --- .../skript/classes/data/SkriptClasses.java | 71 ++++++++++++------- .../ch/njol/skript/expressions/ExprName.java | 11 ++- 2 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java b/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java index 1c1509af3d2..80318294ace 100644 --- a/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java @@ -18,11 +18,14 @@ */ package ch.njol.skript.classes.data; +import java.io.File; import java.io.StreamCorruptedException; import java.util.Iterator; import java.util.Locale; import java.util.regex.Pattern; +import ch.njol.skript.ScriptLoader; +import ch.njol.skript.SkriptCommand; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @@ -75,7 +78,7 @@ @SuppressWarnings("rawtypes") public class SkriptClasses { public SkriptClasses() {} - + static { //noinspection unchecked Classes.registerClass(new ClassInfo<>(ClassInfo.class, "classinfo") @@ -98,17 +101,17 @@ public SkriptClasses() {} public ClassInfo parse(final String s, final ParseContext context) { return Classes.getClassInfoFromUserInput(Noun.stripIndefiniteArticle(s)); } - + @Override public String toString(final ClassInfo c, final int flags) { return c.toString(flags); } - + @Override public String toVariableNameString(final ClassInfo c) { return c.getCodeName(); } - + @Override public String getDebugMessage(final ClassInfo c) { return c.getCodeName(); @@ -122,17 +125,17 @@ public Fields serialize(final ClassInfo c) { f.putObject("codeName", c.getCodeName()); return f; } - + @Override public boolean canBeInstantiated() { return false; } - + @Override public void deserialize(final ClassInfo o, final Fields f) throws StreamCorruptedException { assert false; } - + @Override protected ClassInfo deserialize(final Fields fields) throws StreamCorruptedException { final String codeName = fields.getObject("codeName", String.class); @@ -143,20 +146,20 @@ protected ClassInfo deserialize(final Fields fields) throws StreamCorruptedExcep throw new StreamCorruptedException("Invalid ClassInfo " + codeName); return ci; } - + // return c.getCodeName(); @Override @Nullable public ClassInfo deserialize(final String s) { return Classes.getClassInfoNoError(s); } - + @Override public boolean mustSyncDeserialization() { return false; } })); - + Classes.registerClass(new ClassInfo<>(WeatherType.class, "weathertype") .user("weather ?types?", "weather conditions?", "weathers?") .name("Weather Type") @@ -173,12 +176,12 @@ public boolean mustSyncDeserialization() { public WeatherType parse(final String s, final ParseContext context) { return WeatherType.parse(s); } - + @Override public String toString(final WeatherType o, final int flags) { return o.toString(flags); } - + @Override public String toVariableNameString(final WeatherType o) { return "" + o.name().toLowerCase(Locale.ENGLISH); @@ -186,7 +189,7 @@ public String toVariableNameString(final WeatherType o) { }) .serializer(new EnumSerializer<>(WeatherType.class))); - + Classes.registerClass(new ClassInfo<>(ItemType.class, "itemtype") .user("item ?types?", "materials?") .name("Item Type") @@ -628,7 +631,7 @@ public String toVariableNameString(final EnchantmentType o) { .since("2.0") .parser(new Parser() { private final RegexMessage pattern = new RegexMessage("types.experience.pattern", Pattern.CASE_INSENSITIVE); - + @Override @Nullable public Experience parse(String s, final ParseContext context) { @@ -641,12 +644,12 @@ public Experience parse(String s, final ParseContext context) { return new Experience(xp); return null; } - + @Override public String toString(final Experience xp, final int flags) { return xp.toString(); } - + @Override public String toVariableNameString(final Experience xp) { return "" + xp.getXP(); @@ -682,7 +685,7 @@ public String toVariableNameString(VisualEffect e) { }) .serializer(new YggdrasilSerializer<>())); - + Classes.registerClass(new ClassInfo<>(GameruleValue.class, "gamerulevalue") .user("gamerule values?") .name("Gamerule Value") @@ -694,12 +697,32 @@ public String toVariableNameString(VisualEffect e) { ); Classes.registerClass(new ClassInfo<>(Script.class, "script") - .user("scripts?") - .name("Script") - .description("A script loaded by Skript.") - .usage("") - .examples("the current script") - .since("INSERT VERSION")); + .user("scripts?") + .name("Script") + .description("A script loaded by Skript.") + .usage("") + .examples("the current script") + .since("INSERT VERSION") + .parser(new Parser