Skip to content

Commit 9c2b632

Browse files
committed
Inventory actions WIP
1 parent 526e6fe commit 9c2b632

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import ch.njol.skript.util.BiomeUtils;
7777
import ch.njol.skript.util.DamageCauseUtils;
7878
import ch.njol.skript.util.EnchantmentType;
79+
import ch.njol.skript.util.InventoryActions;
7980
import ch.njol.skript.util.PotionEffectUtils;
8081
import ch.njol.skript.util.StringMode;
8182
import ch.njol.util.StringUtils;
@@ -482,7 +483,7 @@ public String getVariableNamePattern() {
482483
.user("inventory actions?")
483484
.name("Inventory Action")
484485
.description("There are multiple ways to perform clicks in inventories. Inventory actions represent them.")
485-
.user(Language.getList("inventory actions"))
486+
.user(InventoryActions.getAllNames())
486487
.examples("")
487488
.since("2.2-dev16")
488489
.defaultExpression(new EventValueExpression<InventoryAction>(InventoryAction.class))
@@ -491,22 +492,23 @@ public String getVariableNamePattern() {
491492
@Override
492493
@Nullable
493494
public InventoryAction parse(String s, ParseContext context) {
494-
return null; // TODO Do this, while supporting language changes... How?
495+
return InventoryActions.parse(s);
495496
}
496497

497498
@Override
498499
public String toString(InventoryAction o, int flags) {
499-
return Language.get("inventory actions." + o.toString().toLowerCase());
500+
return InventoryActions.toString(o, flags);
500501
}
501502

503+
@SuppressWarnings("null")
502504
@Override
503505
public String toVariableNameString(InventoryAction o) {
504-
return Language.get("inventory actions." + o.toString().toLowerCase());
506+
return o.name();
505507
}
506508

507509
@Override
508510
public String getVariableNamePattern() {
509-
return "[a-z]+";
511+
return "\\S+";
510512
}
511513

512514
}));

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ public Class<? extends Object>[] acceptChange(final ChangeMode mode) {
196196
return CollectionUtils.array(ItemType[].class, Inventory[].class);
197197
}
198198

199-
@SuppressWarnings("null")
200199
@Override
201200
public void change(final Inventory[] invis, final @Nullable Object[] delta, final ChangeMode mode) {
202201
for (final Inventory invi : invis) {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.util;
23+
24+
import org.bukkit.block.Biome;
25+
import org.bukkit.event.inventory.InventoryAction;
26+
import org.eclipse.jdt.annotation.Nullable;
27+
28+
/**
29+
* Inventory action utils...
30+
*/
31+
public class InventoryActions {
32+
33+
private final static EnumUtils<InventoryAction> util = new EnumUtils<InventoryAction>(InventoryAction.class, "inventory actions");
34+
35+
public static @Nullable InventoryAction parse(String s) {
36+
return util.parse(s);
37+
}
38+
39+
public static String getAllNames() {
40+
return util.getAllNames();
41+
}
42+
43+
public static String toString(final InventoryAction action, final int flags) {
44+
return util.toString(action, flags);
45+
}
46+
}

0 commit comments

Comments
 (0)