-
-
Notifications
You must be signed in to change notification settings - Fork 407
Spawners #8193
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
Burbulinis
wants to merge
6
commits into
SkriptLang:dev/feature
Choose a base branch
from
Burbulinis:feature/spawner
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Spawners #8193
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
746475a
Init commit
Burbulinis 28db3c5
Register AnyWeighted classinfo
Burbulinis 55b7699
Add setExpr()
Burbulinis 5b1744d
Fix ExprSpawnerData and SecModifySpawnerData grabbing the regular dat…
Burbulinis f43cd2e
Remove the old ExprSpawnerType
Burbulinis f2a0612
Add newline at the end
Burbulinis 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
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
118 changes: 0 additions & 118 deletions
118
src/main/java/ch/njol/skript/expressions/ExprSpawnerType.java
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package ch.njol.skript.expressions; | ||
|
||
import ch.njol.skript.classes.Changer.ChangeMode; | ||
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.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; | ||
|
||
@Name("Weight") | ||
@Description(""" | ||
Returns the weight of a weighted object. If supported, this weight can be modified. | ||
""") | ||
@Example(""" | ||
broadcast weight of {_spawner entry} | ||
set weight of {_spawner entry} to 5 | ||
add 5 to weight of {_spawner entry} | ||
remove 2 from weight of {_spawner entry} | ||
""") | ||
@Since("INSERT VERSION") | ||
public class ExprWeight extends SimplePropertyExpression<AnyWeighted, Number> { | ||
|
||
static { | ||
register(ExprWeight.class, Number.class, "weight[s]", "weighteds"); | ||
} | ||
|
||
@Override | ||
public @Nullable Number convert(AnyWeighted weighted) { | ||
return weighted.weight(); | ||
} | ||
|
||
@Override | ||
public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||
return switch (mode) { | ||
case SET, ADD, REMOVE -> CollectionUtils.array(Number.class); | ||
default -> null; | ||
}; | ||
} | ||
|
||
@Override | ||
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||
assert delta != null; | ||
|
||
Number deltaValue = (Number) delta[0]; | ||
for (AnyWeighted weighted : getExpr().getArray(event)) { | ||
if (!weighted.supportsWeightChange()) | ||
error("This object does not support weight modification."); | ||
|
||
Number newValue = switch (mode) { | ||
case SET -> deltaValue; | ||
case ADD -> weighted.weight().doubleValue() + deltaValue.doubleValue(); | ||
case REMOVE -> weighted.weight().doubleValue() - deltaValue.doubleValue(); | ||
default -> 0; | ||
}; | ||
|
||
weighted.setWeight(newValue); | ||
} | ||
} | ||
|
||
@Override | ||
public Class<? extends Number> getReturnType() { | ||
return Number.class; | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return "weight"; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/ch/njol/skript/lang/util/common/AnyWeighted.java
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 |
---|---|---|
@@ -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 Number weight(); | ||
|
||
/** | ||
* This is called before {@link #setWeight(Number)}. | ||
* 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(Number weight) throws UnsupportedOperationException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
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.