Skip to content

Commit

Permalink
Add InventoryType support to EffOpenInventory (#3765)
Browse files Browse the repository at this point in the history
* Update DefaultConverters.java

* Update DefaultConverters.java

* Update EffOpenInventory.java
  • Loading branch information
TPGamesNL authored Mar 19, 2021
1 parent 61a8b3d commit b6354f3
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main/java/ch/njol/skript/effects/EffOpenInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public class EffOpenInventory extends Effect {

static {
Skript.registerEffect(EffOpenInventory.class,
"(open|show) ((0¦(crafting [table]|workbench)|1¦chest|2¦anvil|3¦hopper|4¦dropper|5¦dispenser) (view|window|inventory|)|%-inventory%) (to|for) %players%",
"(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]");
}

@Nullable
private Expression<Inventory> invi;
private Expression<?> invi;

boolean open;
private int invType;
Expand Down Expand Up @@ -89,7 +89,7 @@ public boolean init(final Expression<?>[] exprs, final int matchedPattern, final
}

open = matchedPattern == 0;
invi = open ? (Expression<Inventory>) exprs[0] : null;
invi = open ? exprs[0] : null;
players = (Expression<Player>) exprs[exprs.length - 1];
if (openFlag == 1 && invi != null) {
Skript.warning("Using 'show' inventory instead of 'open' is not recommended as it will eventually show an unmodifiable view of the inventory in the future.");
Expand All @@ -100,7 +100,18 @@ public boolean init(final Expression<?>[] exprs, final int matchedPattern, final
@Override
protected void execute(final Event e) {
if (invi != null) {
final Inventory i = invi.getSingle(e);
Inventory i;

assert invi != null;
Object o = invi.getSingle(e);
if (o instanceof Inventory) {
i = (Inventory) o;
} else if (o instanceof InventoryType) {
i = Bukkit.createInventory(null, (InventoryType) o);
} else {
return;
}

if (i == null)
return;
for (final Player p : players.getArray(e)) {
Expand Down

0 comments on commit b6354f3

Please sign in to comment.