From 2a1c7b7758da24d79b0c97fe6927340caecf399a Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 15 Jan 2025 10:09:05 +0100 Subject: [PATCH 1/6] 1.4 version bump --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e5304de0..4af8758a 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ compileJava { options.encoding = "UTF-8" } -version = "1.3.3" +version = "1.4" def latestJava = 21 def oldestJava = 16 From 65590515bc4ba0f4e34ac26ac70132043a0a1ad8 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 15 Jan 2025 10:27:59 +0100 Subject: [PATCH 2/6] Added basic namespaced key support. --- .../types/NamespacedKeyClassInfos.java | 80 +++++++++++++++++++ .../it/jakegblp/lusk/utils/Constants.java | 2 + .../it/jakegblp/lusk/utils/LuskUtils.java | 17 ++++ src/main/resources/lang/default.lang | 1 + 4 files changed, 100 insertions(+) create mode 100644 src/main/java/it/jakegblp/lusk/elements/minecraft/namespacedkey/types/NamespacedKeyClassInfos.java diff --git a/src/main/java/it/jakegblp/lusk/elements/minecraft/namespacedkey/types/NamespacedKeyClassInfos.java b/src/main/java/it/jakegblp/lusk/elements/minecraft/namespacedkey/types/NamespacedKeyClassInfos.java new file mode 100644 index 00000000..2ac447c3 --- /dev/null +++ b/src/main/java/it/jakegblp/lusk/elements/minecraft/namespacedkey/types/NamespacedKeyClassInfos.java @@ -0,0 +1,80 @@ +package it.jakegblp.lusk.elements.minecraft.namespacedkey.types; + +import ch.njol.skript.classes.ClassInfo; +import ch.njol.skript.classes.Parser; +import ch.njol.skript.classes.Serializer; +import ch.njol.skript.lang.ParseContext; +import ch.njol.skript.registrations.Classes; +import ch.njol.yggdrasil.Fields; +import it.jakegblp.lusk.utils.LuskUtils; +import org.bukkit.NamespacedKey; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.StreamCorruptedException; + +public class NamespacedKeyClassInfos { + static { + if (Classes.getExactClassInfo(NamespacedKey.class) == null) { + Classes.registerClass(new ClassInfo<>(NamespacedKey.class, "namespacedkey") + .user("namespaced ?keys?") + .name("Namespaced Key") + .description(""" + A String based key which consists of a namespace and a key; used to declare and specify game objects in Minecraft without without potential ambiguity or conflicts. + + Namespaces may only contain lowercase alphanumeric characters, periods, underscores, and hyphens. + Keys may only contain lowercase alphanumeric characters, periods, underscores, hyphens, and forward slashes. + + More Info: [**Resource Location**](https://minecraft.wiki/w/Resource_location) + """) + .since("1.4") + .parser(new Parser<>() { + @Override + public @Nullable NamespacedKey parse(String s, ParseContext context) { + return LuskUtils.getNamespacedKey(s); + } + + @Override + public String toString(NamespacedKey o, int flags) { + return o.toString(); + } + + @Override + public String toVariableNameString(NamespacedKey o) { + return o.toString(); + } + }) + .serializer(new Serializer<>() { + @Override + public @NotNull Fields serialize(NamespacedKey namespacedKey) { + Fields fields = new Fields(); + fields.putObject("key", namespacedKey.toString()); + return fields; + } + + @Override + public void deserialize(NamespacedKey o, Fields f) { + } + + @Override + protected NamespacedKey deserialize(Fields fields) throws StreamCorruptedException { + String key = fields.getObject("key", String.class); + if (key == null) { + throw new StreamCorruptedException("NamespacedKey string is null"); + } + return NamespacedKey.fromString(key); + } + + @Override + public boolean mustSyncDeserialization() { + return true; + } + + @Override + protected boolean canBeInstantiated() { + return false; + } + })); + } + } +} \ No newline at end of file diff --git a/src/main/java/it/jakegblp/lusk/utils/Constants.java b/src/main/java/it/jakegblp/lusk/utils/Constants.java index 0f41d9bb..acab87e8 100644 --- a/src/main/java/it/jakegblp/lusk/utils/Constants.java +++ b/src/main/java/it/jakegblp/lusk/utils/Constants.java @@ -33,6 +33,8 @@ public class Constants { public static final double EPSILON = 1e-7; + public static final short MAX_NAMESPACED_KEY_LENGTH = isPaper() ? Short.MAX_VALUE : 255; + public static final String[] LUSK_COLORS = new String[]{"&7", "&9"}; public static final Semver diff --git a/src/main/java/it/jakegblp/lusk/utils/LuskUtils.java b/src/main/java/it/jakegblp/lusk/utils/LuskUtils.java index d545bffe..ed67ca58 100644 --- a/src/main/java/it/jakegblp/lusk/utils/LuskUtils.java +++ b/src/main/java/it/jakegblp/lusk/utils/LuskUtils.java @@ -7,14 +7,17 @@ import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; import org.bukkit.Color; +import org.bukkit.NamespacedKey; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.text.MessageFormat; import java.util.List; import java.util.stream.IntStream; import static it.jakegblp.lusk.utils.Constants.*; +import static it.jakegblp.lusk.utils.Constants.MAX_NAMESPACED_KEY_LENGTH; public class LuskUtils { @@ -113,4 +116,18 @@ public static ColorRGB getColorAsRGB(@NotNull Color color) { return new ColorRGB(color.getRed(), color.getGreen(), color.getBlue()); } + + @Nullable + public static NamespacedKey getNamespacedKey(@NotNull String key) { + if (key.isEmpty()) return null; + if (!key.contains(":")) key = "minecraft:" + key; + if (key.length() > MAX_NAMESPACED_KEY_LENGTH) { + warning("Namespacedkey {0} with length {1} exceeds the max length of {2}!", key, key.length(), MAX_NAMESPACED_KEY_LENGTH); + return null; + } + key = key.toLowerCase(); + if (key.contains(" ")) key = key.replace(" ", "_"); + return NamespacedKey.fromString(key); + } + } diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang index b258f319..078a63c4 100644 --- a/src/main/resources/lang/default.lang +++ b/src/main/resources/lang/default.lang @@ -36,6 +36,7 @@ types: timespanperiod: time span period¦s @a ignitecause: ignition cause¦s @an entitysnapshot: entity snapshot¦s @an + namespacedkey: namespaced key¦s @a # -- Rotations -- rotations: From 615a9d379a56bced4dfbd11d2a2a91e706e4902b Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 16 Jan 2025 03:20:57 +0100 Subject: [PATCH 3/6] skript-test-action 1.2 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ff00ba4..337335f7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,7 @@ jobs: path: extra-plugins/ merge-multiple: true - name: Run tests - uses: SkriptLang/skript-test-action@v1.1 + uses: SkriptLang/skript-test-action@v1.2 with: test_script_directory: src/test/scripts skript_repo_ref: dev/patch From 99f05d3e754f6b8ea144cd222b0e6bf9e491ef61 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 16 Jan 2025 03:33:24 +0100 Subject: [PATCH 4/6] skript-test-action dev/patch -> dev/feature --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 337335f7..c7ac1cdf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,5 +45,5 @@ jobs: uses: SkriptLang/skript-test-action@v1.2 with: test_script_directory: src/test/scripts - skript_repo_ref: dev/patch + skript_repo_ref: dev/feature extra_plugins_directory: extra-plugins/ From ff7927e711e54dda4798bb248d744ca1b7ab2d5e Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 16 Jan 2025 03:48:57 +0100 Subject: [PATCH 5/6] Updated skript dependency from 2.9.5 to 2.10 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4af8758a..98257425 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ repositories { dependencies { implementation('org.jetbrains:annotations:20.1.0') compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT") - compileOnly('com.github.SkriptLang:Skript:2.9.5') + compileOnly('com.github.SkriptLang:Skript:2.10') implementation('org.bstats:bstats-bukkit:3.0.2') implementation('com.vdurmont:semver4j:3.1.0') implementation('net.wesjd:anvilgui:1.10.3-SNAPSHOT') From e33bd42fba01c954eb9cc4d88b1f73c1f246f9fb Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 16 Jan 2025 03:52:30 +0100 Subject: [PATCH 6/6] added missing patch version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 98257425..fdff7fd5 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ repositories { dependencies { implementation('org.jetbrains:annotations:20.1.0') compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT") - compileOnly('com.github.SkriptLang:Skript:2.10') + compileOnly('com.github.SkriptLang:Skript:2.10.0') implementation('org.bstats:bstats-bukkit:3.0.2') implementation('com.vdurmont:semver4j:3.1.0') implementation('net.wesjd:anvilgui:1.10.3-SNAPSHOT')