-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from JakeGBLP/dev/feature
Dev/feature -> main
- Loading branch information
Showing
6 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,5 +89,5 @@ jobs: | |
uses: SkriptLang/[email protected] | ||
with: | ||
test_script_directory: src/test/scripts | ||
skript_repo_ref: dev/patch | ||
skript_repo_ref: dev/feature | ||
extra_plugins_directory: extra-plugins/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...java/it/jakegblp/lusk/elements/minecraft/namespacedkey/types/NamespacedKeyClassInfos.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
})); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters