-
-
Notifications
You must be signed in to change notification settings - Fork 415
Spawners Incoming #7477
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
Spawners Incoming #7477
Changes from all commits
518223d
7fe97ee
4a46169
a0873c8
8fce16c
f5cbfaa
c3ff81f
96f0fa7
9e0e7cc
7a1a809
82a8b97
035c55b
aab1c96
7cae29f
55c97a2
f798cca
947416c
45be4ac
3239e51
3eef5df
d0d23df
852135a
6779927
f56df91
366e2c4
2582f60
33496a7
d56ff41
d6e193d
ac136f6
59bcb92
87410dc
233a923
bd034bd
3687530
7cabe46
49aaec2
e01f70e
3ac935d
c6e7dff
789687f
21d3433
631c56f
a699071
aaaaacc
ee74ca3
6fdf55a
d90dd25
a54d7f0
36920d2
e7b273e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||
| package ch.njol.skript.expressions; | ||||||
|
|
||||||
| import ch.njol.skript.classes.Changer.ChangeMode; | ||||||
| import ch.njol.skript.expressions.base.SimplePropertyExpression; | ||||||
| import ch.njol.skript.lang.util.common.AnyWeighted; | ||||||
| import ch.njol.util.coll.CollectionUtils; | ||||||
| import org.bukkit.event.Event; | ||||||
| import org.jetbrains.annotations.Nullable; | ||||||
|
|
||||||
| public class ExprWeight extends SimplePropertyExpression<Object, Integer> { | ||||||
|
|
||||||
| static { | ||||||
| registerDefault(ExprWeight.class, Integer.class, "weight", "weighteds"); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public @Nullable Integer convert(Object object) { | ||||||
| if (object instanceof AnyWeighted weighted) | ||||||
| return weighted.weight(); | ||||||
| assert false; | ||||||
Efnilite marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||||||
| return switch (mode) { | ||||||
| case SET, ADD, REMOVE -> CollectionUtils.array(Integer.class); | ||||||
| default -> null; | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||||||
| assert delta != null; | ||||||
| int weight = (int) delta[0]; | ||||||
|
|
||||||
| for (Object object : getExpr().getArray(event)) { | ||||||
| if (!(object instanceof AnyWeighted weighted)) | ||||||
| continue; | ||||||
|
|
||||||
| if (!weighted.supportsWeightChange()) { | ||||||
| error("The weight of this object cannot be changed."); | ||||||
|
Contributor
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. Only problem I have with this, is that it doesn't say what object that was provided cannot be changed.
Member
Author
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. It provides the line and file, but sure that is fair |
||||||
| continue; | ||||||
| } | ||||||
|
|
||||||
| switch (mode) { | ||||||
| case SET -> weighted.setWeight(weight); | ||||||
| case ADD -> weighted.setWeight(weighted.weight() + weight); | ||||||
| case REMOVE -> weighted.setWeight(weighted.weight() - weight); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public Class<? extends Integer> getReturnType() { | ||||||
| return Integer.class; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| protected String getPropertyName() { | ||||||
| return "the weight"; | ||||||
|
Contributor
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.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package ch.njol.skript.lang.util.common; | ||
|
|
||
| import org.jetbrains.annotations.UnknownNullability; | ||
|
|
||
| /** | ||
| * A provider for anything with a weight. | ||
| * Anything implementing this (or convertible to this) can be used by the {@link ch.njol.skript.expressions.ExprWeight} | ||
| * property expression. | ||
| * | ||
| * @see AnyProvider | ||
| */ | ||
| @FunctionalInterface | ||
| public interface AnyWeighted extends AnyProvider { | ||
|
|
||
| /** | ||
| * @return This thing's weight | ||
| */ | ||
| @UnknownNullability Integer weight(); | ||
|
|
||
| /** | ||
| * This is called before {@link #setWeight(Integer)}. | ||
| * If the result is false, setting the weight will never be attempted. | ||
| * | ||
| * @return Whether this supports being set | ||
| */ | ||
| default boolean supportsWeightChange() { | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * The behaviour for changing this thing's weight, if possible. | ||
| * If not possible, then {@link #supportsWeightChange()} should return false and this | ||
| * may throw an error. | ||
| * | ||
| * @param weight The weight to change | ||
| * @throws UnsupportedOperationException If this is impossible | ||
| */ | ||
| default void setWeight(Integer weight) throws UnsupportedOperationException { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs