Skip to content
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

Open
wants to merge 23 commits into
base: dev/feature
Choose a base branch
from
Open

Conversation

TheLimeGlass
Copy link
Contributor

@TheLimeGlass TheLimeGlass commented Mar 17, 2023

Description

  • Fixes EffOpenInventory to user error if a certain inventory type is used that cannot be created and opened.
  • Cleaned up the effect and added support for enchanting tables, loom, stonecutters, smithing tables, cartography tables and grindstones.
  • Made use of an enum class to allow for future implementation, includes version and method checking constructors.
  • Removed the deprecation of show/open to apply what it's been saying. Show = non interactable. Open = interactable. Example being a crafting table. If using the Spigot method openWorkbench, crafting recipes will be allowed, show will not include crafting recipes as it's just an inventory view. Due to this, this is a breaking change.
  • The past DROPPER, DISPENSER and ANVIL implementation did not actually solve the issues Anvil inventory doesn't let you do anything meaningful #41, Anvil Inventory support #3035 and Unusable Anvil GUI #4586

Target Minecraft Versions: 1.14+ for some inventory types.
Requirements: PaperSpigot for some inventory open actions.
Related Issues: #5495

@TheLimeGlass TheLimeGlass added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. enhancement Feature request, an issue about something that could be improved, or a PR improving something. labels Mar 17, 2023
@TheLimeGlass TheLimeGlass added the breaking changes Pull or feature requests that contain breaking changes (API, syntax, etc.) label Mar 17, 2023
Copy link
Member

@AyhamAl-Ali AyhamAl-Ali left a 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

src/main/java/ch/njol/skript/effects/EffOpenInventory.java Outdated Show resolved Hide resolved
Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com>
Copy link
Member

@APickledWalrus APickledWalrus left a 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.

@APickledWalrus APickledWalrus added the feature Pull request adding a new feature. label Mar 22, 2023
Copy link
Member

@APickledWalrus APickledWalrus left a 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>
@TheLimeGlass TheLimeGlass requested a review from Moderocky July 1, 2023 05:38
@Moderocky Moderocky force-pushed the master branch 2 times, most recently from bd134d0 to 3f08853 Compare September 16, 2023 16:59
@Moderocky Moderocky changed the base branch from master to dev/feature September 18, 2023 10:22
@sovdeeth sovdeeth added the 2.8 Targeting a 2.8.X version release label Dec 30, 2023
@sovdeeth sovdeeth removed the 2.8 Targeting a 2.8.X version release label Dec 31, 2023
@TheLimeGlass TheLimeGlass requested a review from sovdeeth January 1, 2024 01:40
@TheLimeGlass TheLimeGlass changed the base branch from dev/feature to dev/patch February 1, 2024 20:31
Base automatically changed from dev/patch to master June 1, 2024 19:38
@sovdeeth sovdeeth changed the base branch from master to dev/feature September 13, 2024 14:44
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
@TheLimeGlass TheLimeGlass requested a review from sovdeeth October 3, 2024 06:02
Object object = this.inventory.getSingle(event);
if (object == null)
return super.walk(event, false);
if (object instanceof Inventory) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (object instanceof InventoryType) {
} else if (object instanceof InventoryType inventoryType) {

} else if (object instanceof InventoryType) {
inventory = EffOpenInventory.createInventory((InventoryType) object);
} else {
assert false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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%",
Copy link
Member

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.

Comment on lines +136 to +137
@Nullable
private OpenableInventorySyntax syntax;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Nullable
private OpenableInventorySyntax syntax;
private @Nullable OpenableInventorySyntax syntax;


@Nullable
private OpenableInventorySyntax syntax;

@Nullable
Copy link
Member

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 {
Copy link
Member

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.

Comment on lines +59 to +61
static {
Skript.registerSection(SecOpenInventory.class, "[show|open|create] %inventory/inventorytype% [to %players%]");
}
Copy link
Member

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%]");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Skript.registerSection(SecOpenInventory.class, "[show|open|create] %inventory/inventorytype% [to %players%]");
Skript.registerSection(SecOpenInventory.class, "[show|open] %inventory/inventorytype% [(to|for) %players%]");

Comment on lines +103 to +111
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);
Copy link
Member

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?

Copy link
Member

@APickledWalrus APickledWalrus left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking changes Pull or feature requests that contain breaking changes (API, syntax, etc.) bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. enhancement Feature request, an issue about something that could be improved, or a PR improving something. feature Pull request adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants