Skip to content
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

Adds Enchantment Glint Syntaxes #6638

Open
wants to merge 31 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3d9a79d
Add enchantment glint override
NotSoDelayed May 3, 2024
1e4d32c
Add Skript docs and fix annotations
NotSoDelayed May 3, 2024
b0319a7
Add expr item with glint
NotSoDelayed May 4, 2024
c97d40c
Add condition item has enchantment glint
NotSoDelayed May 4, 2024
cb1cdc5
Add version check
NotSoDelayed May 4, 2024
cc60891
Add tests
NotSoDelayed May 4, 2024
49cce6f
Correction to syntax patterns
NotSoDelayed May 4, 2024
c0740c7
License says hi
NotSoDelayed May 4, 2024
d75af9d
Expression said bye
NotSoDelayed May 4, 2024
49f79d6
Fix setExpr
NotSoDelayed May 4, 2024
4405b6c
Finally
NotSoDelayed May 4, 2024
9540e42
Fix tests
NotSoDelayed May 4, 2024
7036781
Bulk requested changes
NotSoDelayed May 5, 2024
6ed6051
Merge branch 'dev/feature' into feature/expr-enchantment-glint
Moderocky May 8, 2024
ec0a561
Merge branch 'dev/feature' into feature/expr-enchantment-glint
NotSoDelayed May 10, 2024
1477e1f
Merge branch 'dev/feature' into feature/expr-enchantment-glint
Moderocky Jun 19, 2024
b0c2278
Merge branch 'dev/feature' into feature/expr-enchantment-glint
Moderocky Jun 26, 2024
48ef71d
Implementation overhaul
NotSoDelayed Jun 30, 2024
f65f7c7
Implementation overhaul
NotSoDelayed Jun 30, 2024
70c07d2
Implementation overhaul
NotSoDelayed Jun 30, 2024
2588bd9
Fix test
NotSoDelayed Jun 30, 2024
c8658fc
Fix test
NotSoDelayed Jul 1, 2024
36ef45a
Fix test
NotSoDelayed Jul 1, 2024
7795ea5
Fix test
NotSoDelayed Jul 1, 2024
3cc306a
Fix test
NotSoDelayed Jul 1, 2024
9d3d7f7
Merge branch 'dev/feature' into feature/expr-enchantment-glint
NotSoDelayed Jul 1, 2024
5091294
Remove license header (#6684)
NotSoDelayed Jul 19, 2024
e17c558
Merge branch 'dev/feature' into feature/expr-enchantment-glint
NotSoDelayed Jul 20, 2024
cad832e
Merge branch 'dev/feature' into feature/expr-enchantment-glint
Moderocky Aug 15, 2024
1c9d1f0
Requested changes and optimise imports
NotSoDelayed Aug 24, 2024
1c0408f
Merge remote-tracking branch 'origin/feature/expr-enchantment-glint' …
NotSoDelayed Aug 24, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;

@Name("Has Enchantment Glint Override")
@Description("Checks whether an item has enchantment glint override set.")
@Examples({
"if {_item} has enchantment glint override:",
"\tsend \"%{_item}% has enchantment glint override\" to player"
})
@RequiredPlugins("Spigot 1.20.5+")
@Since("INSERT VERSION")
public class CondItemHasEnchantmentGlint extends PropertyCondition<ItemType> {

static {
if (Skript.isRunningMinecraft(1, 20, 5))
register(CondItemHasEnchantmentGlint.class, PropertyType.HAVE, "enchant[ment] glint overrid(e|den)", "itemtypes");
}

@Override
public boolean check(ItemType itemType) {
return itemType.getItemMeta().hasEnchantmentGlintOverride();
}

@Override
protected String getPropertyName() {
return "enchantment glint override";
}

}
79 changes: 79 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffForceEnchantmentGlint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Nullable;

@Name("Force Enchantment Glint")
@Description("Forces the items to glint or not.")
@Examples({
"force {_items::*} to glint",
"force the player's tool to stop glinting"
})
@RequiredPlugins("Spigot 1.20.5+")
@Since("INSERT VERSION")
public class EffForceEnchantmentGlint extends Effect {

static {
if (Skript.isRunningMinecraft(1, 20, 5))
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
Skript.registerEffect(EffForceEnchantmentGlint.class,
"(force|make) %itemtypes% [to] [start] glint[ing]",
"(force|make) %itemtypes% [to] (not|stop) glint[ing]");
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
}

@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<ItemType> itemtypes;
private boolean glint;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
itemtypes = (Expression<ItemType>) expressions[0];
glint = matchedPattern == 0;
return true;
}

@Override
protected void execute(Event event) {
for (ItemType itemType : this.itemtypes.getArray(event)) {
ItemMeta meta = itemType.getItemMeta();
meta.setEnchantmentGlintOverride(glint);
itemType.setItemMeta(meta);
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "force the " + itemtypes.toString(event, debug) + " to " + (glint ? "start" : "stop") + " glinting";
}

}
107 changes: 107 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprEnchantmentGlint.java
Copy link
Member

Choose a reason for hiding this comment

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

I still think we should look into how the conditions can be modified so that we do not need to include a boolean expression

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.expressions;

import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Nullable;

@Name("Enchantment Glint")
@Description({
"Sets the 'enchantment_glint_override' on items.",
"If true, the item will glint, even without enchantments.",
"if false, the item will not glint, even with enchantments.",
"If cleared, the glint enforcement will be cleared."
})
@Examples({
"set the enchantment glint of player's tool to true",
"set the enchantment glint of {_items::*} to false",
"clear the enchantment glint of player's tool"
})
@RequiredPlugins("Spigot 1.20.5+")
@Since("INSERT VERSION")
public class ExprEnchantmentGlint extends SimplePropertyExpression<ItemType, Boolean> {

static {
register(ExprEnchantmentGlint.class, Boolean.class, "enchantment glint", "itemtypes");
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
@Nullable
public Boolean convert(ItemType item) {
ItemMeta meta = item.getItemMeta();
if (!meta.hasEnchantmentGlintOverride())
return null;
// Spigot claims this does not return null, hence we return null ourselves
return meta.getEnchantmentGlintOverride();
}

@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
switch (mode) {
case SET:
case DELETE:
return CollectionUtils.array(Boolean.class);
default:
return null;
}
}

@Override
public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
switch (mode) {
case SET:
if (!(delta[0] instanceof Boolean))
return;
for (ItemType itemType : getExpr().getArray(event)) {
ItemMeta meta = itemType.getItemMeta();
meta.setEnchantmentGlintOverride((Boolean) delta[0]);
itemType.setItemMeta(meta);
}
break;
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
case DELETE:
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
for (ItemType itemType : getExpr().getArray(event)) {
ItemMeta meta = itemType.getItemMeta();
meta.setEnchantmentGlintOverride(null);
itemType.setItemMeta(meta);
}
}
}

@Override
public Class<? extends Boolean> getReturnType() {
return Boolean.class;
}

@Override
protected String getPropertyName() {
return "enchantment glint";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.expressions;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.PropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Nullable;

@Name("Item with Enchantment Glint")
@Description("Get an item with or without enchantment glint. Items with enchantment glint")
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
@Examples({
"set {_item with glint} to diamond with enchantment glint",
"set {_item without glint} to diamond without enchantment glint"
})
@RequiredPlugins("Spigot 1.20.5+")
@Since("INSERT VERSION")
public class ExprItemWithEnchantmentGlint extends PropertyExpression<ItemType, ItemType> {

static {
if (Skript.isRunningMinecraft(1, 20, 5))
Skript.registerExpression(ExprItemWithEnchantmentGlint.class, ItemType.class, ExpressionType.PROPERTY, "%itemtypes% with[:out] [enchant[ment]] glint");
}
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved

private boolean glint;

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setExpr((Expression<ItemType>) expressions[0]);
glint = !parseResult.hasTag("out");
return true;
}

@Override
protected ItemType[] get(Event event, ItemType[] source) {
return get(source.clone(), itemType -> {
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
ItemMeta meta = itemType.getItemMeta();
meta.setEnchantmentGlintOverride(glint);
itemType.setItemMeta(meta);
return itemType;
});
}

@Override
public Class<? extends ItemType> getReturnType() {
return ItemType.class;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return getExpr().toString(event, debug) + (glint ? " with" : " without") + " enchantment glint";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
test "item with enchantment glint" when running minecraft "1.20.5":

Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts about adding some test using the parse section testing most if not all patterns?

# Expression %itemtype% with enchantment glint
set {_glint1} to diamond with enchantment glint
assert {_glint1} has enchantment glint override with "{_glint1} expected to have enchantment glint override set"
assert enchantment glint of {_glint1} is true with "{_glint1} expected to have enchantment glint override set to true"
set {_glint1} to {_glint1} without enchantment glint
assert {_glint1} has enchantment glint override with "{_glint1} expected to have enchantment glint override set"
assert enchantment glint of {_glint1} is false with "{_glint1} expected to have enchantment glint override set to false"

# Expression %itemtype%'s enchantment glint
set {_glint2} to diamond
set enchantment glint of {_glint2} to true
assert {_glint2} has enchantment glint override with "{_glint2} expected to have enchantment glint override set"
assert enchantment glint of {_glint2} is true with "{_glint2} expected to have enchantment glint override set to true"
set enchantment glint of {_glint2} to false
assert {_glint2} has enchantment glint override with "{_glint2} expected to have enchantment glint override set"
assert enchantment glint of {_glint2} is false with "{_glint2} expected to have enchantment glint override set to false"
clear enchantment glint of {_glint2}
assert {_glint2} does not have enchantment glint override with "{_glint2} expected to not have enchantment glint override set"
assert enchantment glint of {_glint2} is not set with "{_glint2} expected to have enchantment glint override cleared"