-
-
Notifications
You must be signed in to change notification settings - Fork 376
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 and enhance EffOpenInventory #5531
base: dev/feature
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.
Well done 🚀 Amazing and clean changes
Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com>
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.
Good stuff. Just a few things.
…ript into fix/open-inventory
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.
Looking really good so far :)
Inventory section is a nice addition
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
bd134d0
to
3f08853
Compare
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Object object = this.inventory.getSingle(event); | ||
if (object == null) | ||
return super.walk(event, false); | ||
if (object instanceof Inventory) { |
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.
if (object instanceof Inventory) { | |
if (object instanceof Inventory inventory) { |
return super.walk(event, false); | ||
if (object instanceof Inventory) { | ||
inventory = (Inventory) object; | ||
} else if (object instanceof InventoryType) { |
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.
} else if (object instanceof InventoryType) { | |
} else if (object instanceof InventoryType inventoryType) { |
} else if (object instanceof InventoryType) { | ||
inventory = EffOpenInventory.createInventory((InventoryType) object); | ||
} else { | ||
assert false; |
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.
assert false; | |
assert false; | |
return super.walk(event, false); |
if (inventory instanceof Literal) { | ||
Literal<?> literal = (Literal<?>) inventory; | ||
Object object = literal.getSingle(); | ||
if (object instanceof InventoryType && !((InventoryType) object).isCreatable()) { |
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.
if (object instanceof InventoryType && !((InventoryType) object).isCreatable()) { | |
if (object instanceof InventoryType inventoryType && !(inventoryType.isCreatable()) { |
|
||
inventory = exprs[0]; | ||
players = (Expression<Player>) exprs[1]; | ||
if (inventory instanceof Literal) { |
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.
if (inventory instanceof Literal) { | |
if (inventory instanceof Literal literal) { |
@Name("Open/Close Inventory Section") | ||
@Description({ | ||
"Opens an inventory to a player.", | ||
"The section then allows to modify the event-inventory." |
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 section then allows to modify the event-inventory." | |
"This section allows easy modification of the opened inventory." |
"(open|show) ((0¦(crafting [table]|workbench)|1¦chest|2¦anvil|3¦hopper|4¦dropper|5¦dispenser) (view|window|inventory|)|%-inventory/inventorytype%) (to|for) %players%", | ||
"close [the] inventory [view] (to|of|for) %players%", "close %players%'[s] inventory [view]"); | ||
"show %inventory/inventorytype% (to|for) %players%", | ||
"open [a[n]] " + OpenableInventorySyntax.construct() + " [view|window|inventory] (to|for) %players%", |
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.
This means you cannot open chests, barrels, hoppers, droppers, dispensers, or a myriad of other inventories to players, only show
them.
@Nullable | ||
private OpenableInventorySyntax syntax; |
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.
@Nullable | |
private OpenableInventorySyntax syntax; | |
private @Nullable OpenableInventorySyntax syntax; |
|
||
@Nullable | ||
private OpenableInventorySyntax syntax; | ||
|
||
@Nullable |
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.
needs inlining
"\topen event-inventory to all players" | ||
}) | ||
@Since("INSERT VERSION") | ||
public class SecOpenInventory extends Section { |
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.
wouldn't it be easier to have this be an EffectSection, then EffOpenInventory can become just closing inventories and all the inventory logic is concentrated in this class? The this could support anvils and such as well.
static { | ||
Skript.registerSection(SecOpenInventory.class, "[show|open|create] %inventory/inventorytype% [to %players%]"); | ||
} |
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.
Needs a event-inventory to be registered. Event-player could also be nice.
} | ||
|
||
static { | ||
Skript.registerSection(SecOpenInventory.class, "[show|open|create] %inventory/inventorytype% [to %players%]"); |
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.registerSection(SecOpenInventory.class, "[show|open|create] %inventory/inventorytype% [to %players%]"); | |
Skript.registerSection(SecOpenInventory.class, "[show|open] %inventory/inventorytype% [(to|for) %players%]"); |
InventorySectionEvent inventoryEvent = new InventorySectionEvent(inventory); | ||
Object localVars = Variables.copyLocalVariables(event); | ||
Variables.setLocalVariables(inventoryEvent, localVars); | ||
TriggerItem.walk(trigger, inventoryEvent); | ||
Variables.setLocalVariables(event, Variables.copyLocalVariables(inventoryEvent)); | ||
Variables.removeLocals(inventoryEvent); | ||
if (players != null) | ||
for (Player player : players.getArray(event)) | ||
player.openInventory(inventory); |
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.
What do you think about not running the section at all if players.getArray is empty?
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.
Feel free to re-request me once the requested changes by other contributors have been addressed.
Description
Target Minecraft Versions: 1.14+ for some inventory types.
Requirements: PaperSpigot for some inventory open actions.
Related Issues: #5495