Skip to content

Commit

Permalink
Allow numbers in the changer for ExprHotbarSlot (#6139)
Browse files Browse the repository at this point in the history
* Allow numbers in the changer for ExprHotbarSlot

* Update ExprHotbarSlot.java

* Update ExprHotbarSlot.java

---------

Co-authored-by: Moderocky <[email protected]>
  • Loading branch information
TheLimeGlass and Moderocky authored Oct 22, 2023
1 parent db1dad7 commit d1fd453
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/main/java/ch/njol/skript/expressions/ExprHotbarSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,25 @@ public Slot get(Player player) {
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.SET)
return new Class[] {Slot.class};
return new Class[] {Slot.class, Number.class};
return null;
}

@Override
public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
assert delta != null;
Slot slot = (Slot) delta[0];
if (!(slot instanceof InventorySlot))
return; // Only inventory slots can be hotbar slots
Object object = delta[0];
Number number = null;
if (object instanceof InventorySlot) {
number = ((InventorySlot) object).getIndex();
} else if (object instanceof Number) {
number = (Number) object;
}

int index = ((InventorySlot) slot).getIndex();
if (index > 8) // Only slots in hotbar can be current hotbar slot
if (number == null)
return;
int index = number.intValue();
if (index > 8 || index < 0) // Only slots in hotbar can be current hotbar slot
return;

for (Player player : getExpr().getArray(event))
Expand Down

0 comments on commit d1fd453

Please sign in to comment.