-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
⚒️ Enhance and Fix ExprAge #4854
Conversation
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.
The changers should really support every ChangeMode as this is a number. I do this alot with Khoryl, so I have these on copy and paste. I have an implementation that makes this small and simpler, but this works for Skript conversion.
private void setAge(Object object, int age) {
if (object instanceof Block) {
Block block = ((Block) object);
Ageable ageable = (Ageable) block.getBlockData();
ageable.setAge(age);
block.setBlockData(ageable);
} else if (object instanceof org.bukkit.entity.Ageable) {
((org.bukkit.entity.Ageable) object).setAge(age);
}
}
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (isMax || mode == ChangeMode.REMOVE_ALL)
return null;
return CollectionUtils.array(Number.class);
}
@Override
public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
int value = 0;
switch (mode) {
case ADD:
if (delta == null || delta[0] == null)
return;
value = ((Number)delta[0]).intValue();
for (Object object : getExpr().getArray(event)) {
int existing = convert(object);
setAge(object, existing + value);
}
break;
case REMOVE:
if (delta == null || delta[0] == null)
return;
value = ((Number)delta[0]).intValue();
for (Object object : getExpr().getArray(event)) {
int existing = convert(object);
setAge(object, existing - value);
}
break;
case SET:
if (delta == null || delta[0] == null)
return;
value = ((Number)delta[0]).intValue();
// Fall through as the value will be 0 for others.
case DELETE:
case RESET:
for (Object object : getExpr().getArray(event))
setAge(object, value);
break;
default:
break;
}
}
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.
Ensure that you're returning the actual Number type like Integer as the generic instead of Number. The acceptChange is still fine with Number.
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.
When you make your commit messages, try to be more descriptive rather than just "RC" for requested changes.
Also if you want, we could add a test case to this as it's an object type expression and does runtime checking, but optional as we have many other tests similar to this.
Targeting 2.6.3 |
Merged master to fix actions from being hung |
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.
Just the one thing and then an idea for discussion
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.
Should be good
Description
In this PR (continue of #4594):
entities
multiple blocks
Target Minecraft Versions: 1.13+
Requirements: MC 1.13+
Related Issues:
%itemtype%
support is not needed and it doesn't have any kind if Ageable support, probably Snow thought of that due to how his code worked)