Skip to content

Modernise enchantments#8668

Open
bluelhf wants to merge 27 commits into
SkriptLang:dev/featurefrom
bluelhf:feature/enchantments-module
Open

Modernise enchantments#8668
bluelhf wants to merge 27 commits into
SkriptLang:dev/featurefrom
bluelhf:feature/enchantments-module

Conversation

@bluelhf

@bluelhf bluelhf commented May 28, 2026

Copy link
Copy Markdown
Contributor

Problem

The current enchantment syntaxes are not yet migrated to the new module-based registration system, and their code is in many places out of date both in style and in logic.

Solution

This PR adds a new module for syntaxes related to enchantments, moves the existing syntaxes to the new module, improves their code style and flow and implements three new syntaxes:

  1. Minimum enchantment level: the minimum starting level for an enchantment in vanilla Minecraft. This is 1 for all currently existing enchantments (but I still made it use the Bukkit API instead of just returning 1!)
  2. Maximum enchantment level: the minimum's more useful sibling, e.g. 5 for Efficiency.
  3. Stored enchantments: the enchantments stored in an enchanted book (or anything else with the data component!)

Testing Completed

There is a new unit test for stored enchantments. I ran quickTest to ensure that my changes don't break any of the existing tests.

Supporting Information

I would appreciate if people with scripts that use these syntaxes extensively could test to make sure they still work identically to how they were before.


Completes: none
Related: none
AI assistance: Gemini 3.1 Pro was used to evaluate human-made changes

@bluelhf bluelhf requested a review from a team as a code owner May 28, 2026 20:43
@bluelhf bluelhf requested review from Pesekjak and TheMug06 and removed request for a team May 28, 2026 20:43
Comment thread src/main/java/org/skriptlang/skript/bukkit/enchantments/EnchantmentModule.java Outdated
Comment thread src/main/java/org/skriptlang/skript/bukkit/enchantments/EnchantmentModule.java Outdated
Comment thread src/main/java/org/skriptlang/skript/bukkit/enchantments/EnchantmentModule.java Outdated
bluelhf and others added 4 commits May 29, 2026 00:56
thanks @SirSmurfy2!

Co-authored-by: SirSmurfy2 <82696841+theabsolutionism@users.noreply.github.com>
…tments

Co-authored-by: SirSmurfy2 <82696841+Absolutionism@users.noreply.github.com>
…edEnchantments"

This reverts commit decd611, which was an incorrectly applied suggestion in GitHub UI.
@skriptlang-automation skriptlang-automation Bot added the needs reviews A PR that needs additional reviews label May 29, 2026
Comment thread src/main/java/org/skriptlang/skript/bukkit/enchantments/EnchantmentModule.java Outdated
@bluelhf bluelhf requested a review from Absolutionism June 2, 2026 21:07

@APickledWalrus APickledWalrus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work so far! Might be worth including https://jd.papermc.io/paper/26.1.2/org/bukkit/event/enchantment/EnchantItemEvent.html#getEnchantmentHint() which I don't think is covered yet.

registry.register(SyntaxRegistry.CONDITION, PropertyCondition
.infoBuilder(CondItemEnchantmentGlint.class, PropertyType.HAVE, "enchantment glint (override:overrid(den|e))", "itemtypes")
.addPatterns(getPatterns(PropertyType.BE, "forced to [:not] glint", "itemtypes"))
.supplier(CondItemEnchantmentGlint::new).build());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build calls should go on a new line 🙂

""")
@RequiredPlugins("Spigot 1.20.5+")
@Since("2.10")
public class CondItemEnchantmentGlint extends PropertyCondition<ItemType> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing override of getPropertyType

glint = !parseResult.hasTag("not");
return super.init(expressions, matchedPattern, isDelayed, parseResult);
if (!super.init(expressions, matchedPattern, isDelayed, parseResult)) return false;
override = parseResult.hasTag("override");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the parse tags is kind of confusing behavior. Since this is a single syntax info now, you should be able to just check that matchedPattern is 0 or 1

if (mode == ChangeMode.REMOVE || mode == ChangeMode.REMOVE_ALL || mode == ChangeMode.RESET)
return null;
return CollectionUtils.array(Number.class, Experience.class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the removal of Experience? Is this functionality preserved in a different way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, via the converter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a Comparator but not a Converter. Is it located outside of the module?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's at https://github.com/SkriptLang/Skript/blob/master/src%2Fmain%2Fjava%2Fch%2Fnjol%2Fskript%2Fclasses%2Fdata%2FDefaultConverters.java#L84

I saw some other classes still had their converters registered here rather than in the relevant module, should I move the registration to the module?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it isn't exclusively related to enchanting, you can keep it where it is for now.

set the level of sharpness of the player's tool to {_maximum}
""")
@Since("INSERT VERSION")
public class ExprMaximumEnchantmentLevel extends SimplePropertyExpression<Enchantment, Integer> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might combine this with ExprMinimumEnchantmentLevel

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but wasn't sure what to call it... ExprExtremumEnchantmentLevel? ExprMinMaxEnchantmentLevel? It feels like if I were looking for the class later for minimum or maximum enchantment level, two separate classes would be easier to find

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ExprMinMaxEnchantmentLevel is fine and fits with other cases. Can always use the docs to find the relevant implementation class too 😉

new TagModule(this),
new TextModule(this)
new TextModule(this),
new EnchantmentModule(this)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ordered alphabetically in the list

Comment thread src/test/skript/tests/bukkit/enchantments/ExprStoredEnchantments.sk
@skriptlang-automation skriptlang-automation Bot added needs reviews A PR that needs additional reviews and removed needs reviews A PR that needs additional reviews labels Jun 11, 2026
@bluelhf bluelhf requested a review from APickledWalrus June 12, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs reviews A PR that needs additional reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants