-
-
Notifications
You must be signed in to change notification settings - Fork 424
Inline Durability/Damaged Item #7438
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
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cc6bdc3
Reverse Durability
NagasonicDev f648738
Update Description
NagasonicDev 56345fe
Update Description
NagasonicDev 1f494dc
Look Nicer
NagasonicDev 2ab41b5
Look Nicer
NagasonicDev 063e35c
Look Nicer
NagasonicDev 2341aef
Look Nicer
NagasonicDev 9df590f
Look Nicer?
NagasonicDev 840dd10
Look Nicer
NagasonicDev 2321cde
Update src/main/java/ch/njol/skript/expressions/ExprDamagedItem.java
NagasonicDev 08d7a5b
Fix Issues
NagasonicDev 36f67df
e -> event
NagasonicDev 8f36484
Added plurals
NagasonicDev 7b28dc6
Update src/main/java/ch/njol/skript/expressions/ExprDamagedItem.java
NagasonicDev ad582bd
Update src/main/java/ch/njol/skript/expressions/ExprDamagedItem.java
NagasonicDev 059f750
Update src/main/java/ch/njol/skript/expressions/ExprDamagedItem.java
NagasonicDev 98d4b63
Update src/main/java/ch/njol/skript/expressions/ExprDamagedItem.java
NagasonicDev 3a4efdd
Update ExprDamagedItem.java
NagasonicDev 85185ff
Merge branch 'dev/feature' into patch-2
NagasonicDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| package ch.njol.skript.expressions; | ||
|
|
||
| import ch.njol.skript.bukkitutil.ItemUtils; | ||
| import ch.njol.skript.lang.SkriptParser; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
|
|
@@ -12,54 +14,73 @@ | |
| 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; | ||
| import ch.njol.util.Kleenean; | ||
|
|
||
| @Name("Damaged Item") | ||
| @Description("Directly damages an item. In MC versions 1.12.2 and lower, this can be used to apply data values to items/blocks") | ||
| @Description({ | ||
| "Changes the durability of an item.", | ||
| "Damage is used to remove the specified number from the base durability of an item, e.g. 400 - damage. " | ||
| + "Durability is used to modify the total durability." | ||
| }) | ||
| @Examples({"give player diamond sword with damage value 100", "set player's tool to diamond hoe damaged by 250", | ||
| "give player diamond sword with damage 700 named \"BROKEN SWORD\"", | ||
| "set {_item} to diamond hoe with damage value 50 named \"SAD HOE\"", | ||
| "set target block of player to wool with data value 1", "set target block of player to potato plant with data value 7"}) | ||
| @Since("2.4") | ||
| "give player diamond sword with damage 700 named \"BROKEN SWORD\"", | ||
| "set {_item} to diamond hoe with damage value 50 named \"SAD HOE\"", | ||
| "set target block of player to wool with data value 1", "set target block of player to potato plant with data value 7", | ||
| "give player wooden sword with 1 durability named \"VERY BROKEN SWORD\"", | ||
| "set player's tool to diamond hoe with durability 500"}) | ||
| @Since("2.4, INSERT VERSION (with durability)") | ||
| public class ExprDamagedItem extends PropertyExpression<ItemType, ItemType> { | ||
|
|
||
| static { | ||
| Skript.registerExpression(ExprDamagedItem.class, ItemType.class, ExpressionType.COMBINED, | ||
| "%itemtype% with (damage|data) [value] %number%", | ||
| "%itemtype% damaged by %number%"); | ||
| "%itemtypes% with (damage|data) [value] %number%", | ||
| "%itemtypes% damaged by %number%", | ||
| "%itemtypes% with durability %number%", | ||
| "%itemtypes% with %number% durability"); | ||
| } | ||
|
|
||
| @SuppressWarnings("null") | ||
| private Expression<Number> damage; | ||
|
|
||
| @SuppressWarnings({"unchecked", "null"}) | ||
| private boolean hasDurability; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
| @SuppressWarnings({"unchecked", "null"}) | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| setExpr((Expression<ItemType>) exprs[0]); | ||
| damage = (Expression<Number>) exprs[1]; | ||
| hasDurability = matchedPattern > 1 ? true : false; | ||
| if (matchedPattern == 0) { | ||
| Skript.warning("Data value is deprecated and is only used in older Minecraft versions that do not support this Skript version."); | ||
| } | ||
|
Comment on lines
+52
to
+54
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to check they actually used 'data' and didn't just use |
||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected ItemType[] get(Event e, ItemType[] source) { | ||
| Number damage = this.damage.getSingle(e); | ||
| protected ItemType[] get(Event event, ItemType[] source) { | ||
| Number damage = this.damage.getSingle(event); | ||
| if (damage == null) | ||
| return source; | ||
| return get(source.clone(), item -> { | ||
| item.iterator().forEachRemaining(i -> i.setDurability(damage.intValue())); | ||
| if (hasDurability == true) { | ||
| ItemUtils.setDamage(item, ItemUtils.getMaxDamage(item) - damage.intValue()); | ||
| } else { | ||
| item.iterator().forEachRemaining(i -> i.setDurability(damage.intValue())); | ||
| } | ||
| return item; | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends ItemType> getReturnType() { | ||
| return ItemType.class; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(final @Nullable Event e, boolean debug) { | ||
| return getExpr().toString(e, debug) + " with damage value " + damage.toString(e, debug); | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| if (hasDurability == true) | ||
| return getExpr().toString(event, debug) + " with durability " + damage.toString(event, debug); | ||
|
|
||
| return getExpr().toString(event, debug) + " with damage value " + damage.toString(event, debug); | ||
| } | ||
NagasonicDev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.