Skip to content

Commit be3bb5b

Browse files
committed
Anvil inventory support...
1 parent 6a3e78f commit be3bb5b

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,7 @@ public Block get(final PlayerInteractEvent e) {
573573
@Override
574574
@Nullable
575575
public ItemStack get(final PlayerInteractEvent e) {
576-
if (offHandSupport) {
577-
EquipmentSlot hand = e.getHand();
578-
if (hand == EquipmentSlot.HAND) return e.getPlayer().getInventory().getItemInMainHand();
579-
else if (hand == EquipmentSlot.OFF_HAND) return e.getPlayer().getInventory().getItemInOffHand();
580-
else return null;
581-
} else {
582-
return e.getPlayer().getItemInHand();
583-
}
576+
return e.getItem();
584577
}
585578
}, 0);
586579
// PlayerShearEntityEvent

src/main/java/ch/njol/skript/effects/EffOpenInventory.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222
package ch.njol.skript.effects;
2323

24+
import org.bukkit.Bukkit;
2425
import org.bukkit.entity.Player;
2526
import org.bukkit.event.Event;
27+
import org.bukkit.event.inventory.InventoryType;
2628
import org.bukkit.inventory.Inventory;
2729
import org.eclipse.jdt.annotation.Nullable;
2830

@@ -44,29 +46,47 @@
4446
"Please note that currently 'show' and 'open' have the same effect, but 'show' will eventually show an unmodifiable view of the inventory in the future."})
4547
@Examples({"show the victim's inventory to the player",
4648
"open the player's inventory for the player"})
47-
@Since("2.0, 2.1.1 (closing)")
49+
@Since("2.0, 2.1.1 (closing), 2.2-Fixes-V10 (anvil)")
4850
public class EffOpenInventory extends Effect {
51+
52+
private final static int WORKBENCH = 0, CHEST = 1, ANVIL = 2;
53+
4954
static {
5055
Skript.registerEffect(EffOpenInventory.class,
51-
"(0¦open|1¦show) ((crafting [table]|workbench) (view|window|inventory|)|%-inventory%) (to|for) %players%",
56+
"(0¦open|1¦show) ((20¦(crafting [table]|workbench)|40¦chest|60¦anvil) (view|window|inventory|)|%-inventory%) (to|for) %players%",
5257
"close [the] inventory [view] (to|of|for) %players%", "close %players%'[s] inventory [view]");
5358
}
5459

5560
@Nullable
5661
private Expression<Inventory> invi;
5762

5863
boolean open;
64+
private int invType;
5965

6066
@SuppressWarnings("null")
6167
private Expression<Player> players;
6268

6369
@SuppressWarnings({"unchecked", "null"})
6470
@Override
6571
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
72+
int openFlag = 0;
73+
if (parseResult.mark >= 60) {
74+
openFlag = parseResult.mark ^ 60;
75+
invType = ANVIL;
76+
} else if (parseResult.mark >= 40) {
77+
openFlag = parseResult.mark ^ 40;
78+
invType = CHEST;
79+
} else if (parseResult.mark >= 20) {
80+
invType = WORKBENCH;
81+
openFlag = parseResult.mark ^ 20;
82+
} else {
83+
openFlag = parseResult.mark;
84+
}
85+
6686
open = matchedPattern == 0;
6787
invi = open ? (Expression<Inventory>) exprs[0] : null;
6888
players = (Expression<Player>) exprs[exprs.length - 1];
69-
if (parseResult.mark == 1 && invi != null) {
89+
if (openFlag == 1 && invi != null) {
7090
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.");
7191
}
7292
return true;
@@ -83,9 +103,18 @@ protected void execute(final Event e) {
83103
}
84104
} else {
85105
for (final Player p : players.getArray(e)) {
86-
if (open)
87-
p.openWorkbench(null, true);
88-
else
106+
if (open) {
107+
switch (invType) {
108+
case WORKBENCH:
109+
p.openWorkbench(null, true);
110+
break;
111+
case CHEST:
112+
p.openInventory(Bukkit.createInventory(p, InventoryType.CHEST));
113+
break;
114+
case ANVIL:
115+
p.openInventory(Bukkit.createInventory(p, InventoryType.ANVIL));
116+
}
117+
} else
89118
p.closeInventory();
90119
}
91120
}

0 commit comments

Comments
 (0)