Skip to content

EntityData Overhaul #7985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e63d99b
Initial Commit
Absolutionism Jun 26, 2025
389dc5a
Additional Cleanup
Absolutionism Jun 26, 2025
7145797
Update default.lang
Absolutionism Jun 26, 2025
7439f0e
Initial Commit
Absolutionism Jun 26, 2025
b4e91d5
Merge branch 'dev/EntityDataParseTags' into dev/EntityDataMultiLinedP…
Absolutionism Jun 26, 2025
5a43b48
Follow Up Commit
Absolutionism Jun 27, 2025
ad87cc1
Language Map Update
Absolutionism Jun 28, 2025
123bf4d
EntityDataInfo and EnitityData Update
Absolutionism Jun 30, 2025
001746f
Merge remote-tracking branch 'upstream/dev/feature' into dev/EntityDa…
Absolutionism Jun 30, 2025
9be006a
Merge remote-tracking branch 'upstream/dev/feature' into dev/EntityDa…
Absolutionism Jun 30, 2025
4a256d9
Overhaul
Absolutionism Jul 1, 2025
3e9879e
Enum->Interface Fixes
Absolutionism Jul 1, 2025
40e1d0c
Added states and test
Absolutionism Jul 3, 2025
5af956a
Merge remote-tracking branch 'upstream/dev/feature' into dev/EntityDa…
Absolutionism Jul 3, 2025
68f0144
Update EntityData.java
Absolutionism Jul 3, 2025
dc262e9
Update EntityData.sk
Absolutionism Jul 3, 2025
8c2566d
Fix test
Absolutionism Jul 3, 2025
0a947fc
Kleenean Changes
Absolutionism Jul 3, 2025
3d4279e
Update EntityData.sk
Absolutionism Jul 4, 2025
c4a045a
Efy's Requested Changes
Absolutionism Jul 4, 2025
d6526c4
Efy's Requested Changes -2
Absolutionism Jul 4, 2025
45721aa
Sovdes Requested Changes
Absolutionism Jul 7, 2025
22e7165
FieldHandler
Absolutionism Jul 8, 2025
0ea837c
Massive Fixes/Changes
Absolutionism Jul 8, 2025
57e503d
Update EntityData.sk
Absolutionism Jul 8, 2025
313c005
Merge remote-tracking branch 'upstream/dev/feature' into dev/EntityDa…
Absolutionism Jul 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@

# Functions
/src/main/java/ch/njol/skript/lang/function @Efnilite @skriptlang/core-developers

# EntityData
/src/main/java/ch/njol/skript/entity @Absolutionism @skriptlang/core-developers
16 changes: 16 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,22 @@ public String toVariableNameString(WorldBorder border) {
.since("2.12")
);

ClassInfo<?> frogVariantClassInfo = getRegistryClassInfo(
"org.bukkit.entity.Frog$Variant",
"FROG_VARIANT",
"frogvariant",
"frog variants"
);
assert frogVariantClassInfo != null;
Classes.registerClass(frogVariantClassInfo
.user("frog ?variants?")
.name("Frog Variant")
.description("Represents the variant of a frog entity.",
"NOTE: Minecraft namespaces are supported, ex: 'minecraft:warm'.")
.since("INSERT VERSION")
.documentationId("FrogVariant")
);

}

/**
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsSpawnable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.SyntaxStringBuilder;
import ch.njol.util.Kleenean;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Is Spawnable")
@Description("""
Whether an entity type can be spawned in a world. If no world is provided, will default to the first world.
Any general types such as 'monster, mob, entity, living entity' etc. will never be spawnable.
""")
@Example("""
if a pig is spawnable: # true
if a monster can be spawned: # false
""")
@Since("INSERT VERSION")
public class CondIsSpawnable extends Condition {

static {
Skript.registerCondition(CondIsSpawnable.class, ConditionType.COMBINED,
"%entitydatas% is spawnable [in [the [world]] %-world%]",
"%entitydatas% can be spawned [in [the [world]] %-world%]",
"%entitydatas% (isn't|is not) spawnable [in [the [world]] %-world%]",
"%entitydatas% (can't|can not) be spawned [in [the [world]] %-world%]");
}

private Expression<EntityData<?>> datas;
private @Nullable Expression<World> world = null;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
//noinspection unchecked
datas = (Expression<EntityData<?>>) exprs[0];
if (exprs[1] != null) {
//noinspection unchecked
world = (Expression<World>) exprs[1];
}
setNegated(matchedPattern >= 2);
return true;
}

@Override
public boolean check(Event event) {
World world = null;
if (this.world != null) {
world = this.world.getSingle(event);
}
if (world == null)
world = Bukkit.getWorlds().get(0);

World finalWorld = world;
return datas.check(event, entityData -> entityData.canSpawn(finalWorld), isNegated());
}

@Override
public String toString(@Nullable Event event, boolean debug) {
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
builder.append(datas, "is");
if (isNegated())
builder.append("not");
builder.append("spawnable");
if (world != null)
builder.append("in", world);
return builder.toString();
}

}
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/skript/doc/Documentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private static void insertSyntaxElement(final PrintWriter pw, final SyntaxElemen
Skript.warning("" + elementClass.getSimpleName() + "'s description or 'since' is invalid");
return;
}
final String patterns = cleanPatterns(StringUtils.join(info.patterns, "\n", 0, elementClass == CondCompare.class ? 8 : info.patterns.length));
String patterns = cleanPatterns(StringUtils.join(info.patterns, "\n", 0, elementClass == CondCompare.class ? 8 : info.getPatterns().length));
insertOnDuplicateKeyUpdate(pw, "syntax_elements",
"id, name, type, patterns, description, examples, since",
"patterns = TRIM(LEADING '\n' FROM CONCAT(patterns, '\n', '" + escapeSQL(patterns) + "'))",
Expand Down Expand Up @@ -341,7 +341,7 @@ private static void insertEvent(final PrintWriter pw, final SkriptEventInfo<?> i
Skript.warning("description or 'since' of " + info.getName() + " (" + info.getElementClass().getSimpleName() + ") is invalid");
return;
}
final String patterns = cleanPatterns(info.getName().startsWith("On ") ? "[on] " + StringUtils.join(info.patterns, "\n[on] ") : StringUtils.join(info.patterns, "\n"));
String patterns = cleanPatterns(info.getName().startsWith("On ") ? "[on] " + StringUtils.join(info.getPatterns(), "\n[on] ") : StringUtils.join(info.patterns, "\n"));
insertOnDuplicateKeyUpdate(pw, "syntax_elements",
"id, name, type, patterns, description, examples, since",
"patterns = '" + escapeSQL(patterns) + "'",
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/skript/doc/HTMLGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo<?> info, @Nu
String[] split = data.split(" ");
String pattern = readFile(new File(templateDir + "/templates/" + split[1]));
StringBuilder patterns = new StringBuilder();
for (String line : getDefaultIfNullOrEmpty(info.patterns, "Missing patterns.")) {
for (String line : getDefaultIfNullOrEmpty(info.getPatterns(), "Missing patterns.")) {
assert line != null;
line = cleanPatterns(line);
String parsed = pattern.replace("${element.pattern}", line);
Expand Down Expand Up @@ -693,7 +693,7 @@ private String generateEvent(String descTemp, SkriptEventInfo<?> info, @Nullable
String[] split = data.split(" ");
String pattern = readFile(new File(templateDir + "/templates/" + split[1]));
StringBuilder patterns = new StringBuilder();
for (String line : getDefaultIfNullOrEmpty(info.patterns, "Missing patterns.")) {
for (String line : getDefaultIfNullOrEmpty(info.getPatterns(), "Missing patterns.")) {
assert line != null;
line = "[on] " + cleanPatterns(line);
String parsed = pattern.replace("${element.pattern}", line);
Expand Down
70 changes: 43 additions & 27 deletions src/main/java/ch/njol/skript/entity/AxolotlData.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,71 @@
package ch.njol.skript.entity;

import ch.njol.skript.Skript;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Patterns;
import ch.njol.skript.variables.Variables;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.entity.Axolotl;
import org.bukkit.entity.Axolotl.Variant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class AxolotlData extends EntityData<Axolotl> {

private static final Patterns<Variant> PATTERNS = new Patterns<>(new Object[][]{
{"axolotl", null},
{"lucy axolotl", Variant.LUCY},
{"wild axolotl", Variant.WILD},
{"gold axolotl", Variant.GOLD},
{"cyan axolotl", Variant.CYAN},
{"blue axolotl", Variant.BLUE}
});
private static final Variant[] VARIANTS = Variant.values();

static {
if (Skript.classExists("org.bukkit.entity.Axolotl")) {
EntityData.register(AxolotlData.class, "axolotl", Axolotl.class, 0,
"axolotl", "lucy axolotl", "wild axolotl", "gold axolotl", "cyan axolotl", "blue axolotl");
}
EntityData.register(AxolotlData.class, "axolotl", Axolotl.class, 0, PATTERNS.getPatterns());

Variables.yggdrasil.registerSingleClass(Variant.class, "Axolotl.Variant");
}

@Nullable
private Variant variant = null;
private @Nullable Variant variant = null;

public AxolotlData() {}

public AxolotlData(@Nullable Variant variant) {
this.variant = variant;
matchedPattern = variant != null ? variant.ordinal() + 1 : 0;
super.codeNameIndex = PATTERNS.getMatchedPattern(variant, 0).orElse(0);
}

@Override
protected boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {
if (matchedPattern > 0)
variant = Variant.values()[matchedPattern - 1];
protected boolean init(Literal<?>[] exprs, int matchedCodeName, int matchedPattern, ParseResult parseResult) {
variant = PATTERNS.getInfo(matchedCodeName);
return true;
}

@Override
protected boolean init(@Nullable Class<? extends Axolotl> c, @Nullable Axolotl axolotl) {
if (axolotl != null)
protected boolean init(@Nullable Class<? extends Axolotl> entityClass, @Nullable Axolotl axolotl) {
if (axolotl != null) {
variant = axolotl.getVariant();
super.codeNameIndex = PATTERNS.getMatchedPattern(variant, 0).orElse(0);
}
return true;
}

@Override
public void set(Axolotl entity) {
if (variant != null)
entity.setVariant(variant);
public void set(Axolotl axolotl) {
Variant variant = this.variant;
if (variant == null)
variant = CollectionUtils.getRandom(VARIANTS);
assert variant != null;
axolotl.setVariant(variant);
}

@Override
protected boolean match(Axolotl entity) {
return variant == null || variant == entity.getVariant();
protected boolean match(Axolotl axolotl) {
return dataMatch(variant, axolotl.getVariant());
}

@Override
Expand All @@ -58,27 +74,27 @@ public Class<? extends Axolotl> getType() {
}

@Override
public @NotNull EntityData getSuperType() {
return new AxolotlData(variant);
public @NotNull EntityData<?> getSuperType() {
return new AxolotlData();
}

@Override
protected int hashCode_i() {
return variant != null ? variant.hashCode() : 0;
return variant == null ? 0 : Objects.hashCode(variant);
}

@Override
protected boolean equals_i(EntityData<?> data) {
if (!(data instanceof AxolotlData))
protected boolean equals_i(EntityData<?> entityData) {
if (!(entityData instanceof AxolotlData other))
return false;
return variant == ((AxolotlData) data).variant;
return variant == other.variant;
}

@Override
public boolean isSupertypeOf(EntityData<?> data) {
if (!(data instanceof AxolotlData))
public boolean isSupertypeOf(EntityData<?> entityData) {
if (!(entityData instanceof AxolotlData other))
return false;
return variant == null || variant == ((AxolotlData) data).variant;
return dataMatch(variant, other.variant);
}

}
Loading