-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
Fix an issue with creating a non creatable inventory from ExprNamed and fix array store exception #5943
base: master
Are you sure you want to change the base?
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.
Looks ok, I'm not a fan of the try/catch but it could future-proof it.
bd134d0
to
3f08853
Compare
949b345
to
c51dc41
Compare
83ca24c
to
1b7b3a5
Compare
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.
did some quick manual tests, seems good.
"set tool of player to the player's tool named \"<gold>Wand\"", | ||
"set the name of the player's tool to \"<gold>Wand\"", | ||
"open hopper inventory named \"Magic Hopper\" to player" | ||
}) | ||
@Since("2.0, 2.2-dev34 (inventories)") | ||
public class ExprNamed extends PropertyExpression<Object, Object> { |
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.
IMO some tests would be good. You'd be fine to incorporate the tests from #6159
// Spigot forgot to label some InventoryType's as non creatable in some versions < 1.19.4 | ||
// So this throws NullPointerException aswell ontop of the IllegalArgumentException. | ||
// See https://hub.spigotmc.org/jira/browse/SPIGOT-7301 | ||
Skript.error("You can't create a '" + literal.toString() + "' inventory. It's not creatable!"); |
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.
Skript.error("You can't create a '" + literal.toString() + "' inventory. It's not creatable!"); | |
Skript.error(Utils.a(literal.toString) + "inventory cannot be created."); |
public static String a(final String s) { |
return get(source, obj -> obj); // No name provided, do nothing | ||
return get(source, object -> { | ||
if (object instanceof InventoryType) { | ||
try { |
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.
I think we should at least attempt to check if the inventory type is creatable here
@@ -97,15 +121,15 @@ public Object get(Object obj) { | |||
} | |||
}); | |||
} | |||
|
|||
@Override | |||
public Class<? extends Object> getReturnType() { | |||
return getExpr().getReturnType() == InventoryType.class ? Inventory.class : ItemType.class; |
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.
I don't believe this is safe for variables, or any other expression that would have Object.class as the return type. We might have an InventoryType type in a variable but would be returning ItemType as the return type here. Likely another issue we can fix while we're here :)
stack.setItemMeta(meta); | ||
public Object get(Object object) { | ||
if (object instanceof InventoryType) { | ||
try { |
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.
Same here, I think we'd be best off at least checking if it is creatable first. Since we have to do this in two places, and have the try (maybe could be replaced with checking incorrectly marked types? not sure), it might be worth moving to a private method
// See issue #1822 as to why this convert is required. | ||
if (exprs[0].getReturnType().equals(ItemStack.class)) { | ||
setExpr(exprs[0].getConvertedExpression(ItemType.class)); | ||
} else { | ||
setExpr(exprs[0]); | ||
} |
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.
I can't imagine an ItemStack would be passed here, and if one were to be, that is a separate issue to be fixed elsewhere. I don't think we should check this.
closing due to inactivity |
February requested changes is a crazy inactivity time |
Description
Fix an issue with creating a non creatable inventory from ExprNamed and fix array store exception.
Target Minecraft Versions: any
Requirements: none
Related Issues: #5495 and #5923