Skip to content

Commit 945780e

Browse files
committed
Finish inventory actions
1 parent 9c2b632 commit 945780e

File tree

5 files changed

+96
-2
lines changed

5 files changed

+96
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,11 @@ public String getVariableNamePattern() {
479479
}
480480
}).changer(DefaultChangers.inventoryChanger));
481481

482-
Classes.registerClass(new ClassInfo<InventoryAction>(InventoryAction.class, "inventory action")
482+
Classes.registerClass(new ClassInfo<InventoryAction>(InventoryAction.class, "inventoryaction")
483483
.user("inventory actions?")
484484
.name("Inventory Action")
485485
.description("There are multiple ways to perform clicks in inventories. Inventory actions represent them.")
486-
.user(InventoryActions.getAllNames())
486+
.usage(InventoryActions.getAllNames())
487487
.examples("")
488488
.since("2.2-dev16")
489489
.defaultExpression(new EventValueExpression<InventoryAction>(InventoryAction.class))

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.bukkit.event.hanging.HangingEvent;
6262
import org.bukkit.event.hanging.HangingPlaceEvent;
6363
import org.bukkit.event.inventory.CraftItemEvent;
64+
import org.bukkit.event.inventory.InventoryAction;
6465
import org.bukkit.event.inventory.InventoryClickEvent;
6566
import org.bukkit.event.inventory.PrepareItemCraftEvent;
6667
import org.bukkit.event.hanging.HangingEvent;
@@ -709,6 +710,13 @@ public ItemType get(final InventoryClickEvent e) {
709710
return new ItemType(e.getCurrentItem());
710711
}
711712
}, 0);
713+
EventValues.registerEventValue(InventoryClickEvent.class, InventoryAction.class, new Getter<InventoryAction, InventoryClickEvent>() {
714+
@Override
715+
@Nullable
716+
public InventoryAction get(final InventoryClickEvent e) {
717+
return e.getAction();
718+
}
719+
}, 0);
712720
// CraftItemEvent
713721
EventValues.registerEventValue(CraftItemEvent.class, ItemStack.class, new Getter<ItemStack, CraftItemEvent>() {
714722
@Override
@@ -719,6 +727,7 @@ public ItemStack get(final CraftItemEvent e) {
719727
}, 0);
720728
// PrepareItemCraftEvent
721729
EventValues.registerEventValue(PrepareItemCraftEvent.class, Slot.class, new Getter<Slot, PrepareItemCraftEvent>() {
730+
@SuppressWarnings("null")
722731
@Override
723732
@Nullable
724733
public Slot get(final PrepareItemCraftEvent e) {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This file is part of Skript.
3+
*
4+
* Skript is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Skript is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*
18+
* Copyright 2011-2016 Peter Güttinger and contributors
19+
*
20+
*/
21+
22+
package ch.njol.skript.expressions;
23+
24+
import org.bukkit.event.Event;
25+
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
26+
import org.bukkit.event.inventory.InventoryAction;
27+
import org.eclipse.jdt.annotation.Nullable;
28+
29+
import ch.njol.skript.Skript;
30+
import ch.njol.skript.doc.Description;
31+
import ch.njol.skript.doc.Examples;
32+
import ch.njol.skript.doc.Name;
33+
import ch.njol.skript.doc.Since;
34+
import ch.njol.skript.expressions.base.EventValueExpression;
35+
import ch.njol.skript.lang.ExpressionType;
36+
37+
@Name("Inventory Action")
38+
@Description("The <a href='../classes/#inventoryaction'>inventory action</a> of an inventory event. Please click on the link for more information.")
39+
@Examples("inventory action is pickup all")
40+
@Since("2.2-dev16")
41+
public class ExprInventoryAction extends EventValueExpression<InventoryAction> {
42+
43+
static {
44+
Skript.registerExpression(ExprInventoryAction.class, InventoryAction.class, ExpressionType.SIMPLE, "[the] inventory action");
45+
}
46+
47+
public ExprInventoryAction() {
48+
super(InventoryAction.class);
49+
}
50+
51+
@Override
52+
public String toString(final @Nullable Event e, final boolean debug) {
53+
return "the inventory action";
54+
}
55+
56+
}

src/main/java/ch/njol/skript/util/InventoryActions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@
2121

2222
package ch.njol.skript.util;
2323

24+
import java.util.ArrayList;
25+
import java.util.List;
26+
2427
import org.bukkit.block.Biome;
2528
import org.bukkit.event.inventory.InventoryAction;
2629
import org.eclipse.jdt.annotation.Nullable;
2730

31+
import ch.njol.skript.localization.Language;
32+
import ch.njol.skript.localization.LanguageChangeListener;
33+
import ch.njol.skript.localization.Noun;
34+
2835
/**
2936
* Inventory action utils...
3037
*/

src/main/resources/lang/english.lang

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,28 @@ visual effects:
960960
pattern: [sprinting] dust of [%itemtype%]
961961
area_expression: [with [offset of %number%, %number%(,| and) %number%][[and ]speed %number%]]
962962

963+
# -- Inventory Actions --
964+
inventory actions:
965+
nothing: nothing, do nothing
966+
pickup_all: pickup all, pickup all items
967+
pickup_some: pickup some, pickup some items
968+
pickup_half: pickup half, pickup half stack
969+
pickup_one: pickup one item, pickup single item, pickup single
970+
place_all: place all, place all items
971+
place_some: place some, place some items
972+
place_one: place one, place one item
973+
swap_with_cursor: swap with cursor, swap stack with cursor, swap cursor, swap cursor stack
974+
drop_all_cursor: drop all from cursor, drop stack from cursor, drop items from cursor, drop stack from cursor, drop cursor, drop cursor stack
975+
drop_one_cursor: drop one from cursor, drop one item from cursor, drop single item from cursor, drop cursor item
976+
drop_all_slot: drop all from slot, drop stack from slot, drop items from slot, drop stack from slot, drop slot, drop slot stack
977+
drop_one_slot: drop one from slot, drop one item from slot, drop single item from slot, drop slot item
978+
move_to_other_inventory: instant move, move to other inventory, shift move
979+
hotbar_move_and_readd: hotbar move and readd
980+
hotbar_swap: swap with hotbar, swap items with hotbar, hotbar swap, hotbar swap items
981+
clone_stack: clone stack
982+
collect_to_cursor: collect to cursor, collect items to cursor
983+
unknown: unknown, unsupported, custom
984+
963985
# -- Boolean --
964986
boolean:
965987
true:

0 commit comments

Comments
 (0)