Skip to content

Commit

Permalink
Fix "add X to inventory" and partially region events
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Mar 11, 2016
1 parent 13f80ca commit 334555c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/main/java/ch/njol/skript/aliases/ItemType.java
Expand Up @@ -879,8 +879,7 @@ public boolean addTo(final Inventory invi) {
}
}

final boolean b = addTo(buf);
Skript.info("Adding items to " + Arrays.asList(buf).toString());
final boolean b = addTo(buf);
invi.setContents(buf);
return b;
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/ch/njol/skript/classes/data/DefaultChangers.java
Expand Up @@ -21,6 +21,8 @@

package ch.njol.skript.classes.data;

import java.util.Arrays;

import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
Expand All @@ -35,6 +37,7 @@
import org.bukkit.potion.PotionEffectType;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.PlayerUtils;
import ch.njol.skript.classes.Changer;
Expand Down Expand Up @@ -193,6 +196,7 @@ public Class<? extends Object>[] acceptChange(final ChangeMode mode) {
return CollectionUtils.array(ItemType[].class, Inventory[].class);
}

@SuppressWarnings("null")
@Override
public void change(final Inventory[] invis, final @Nullable Object[] delta, final ChangeMode mode) {
for (final Inventory invi : invis) {
Expand All @@ -216,7 +220,8 @@ public void change(final Inventory[] invis, final @Nullable Object[] delta, fina
//$FALL-THROUGH$
case ADD:
assert delta != null;
if(delta instanceof ItemStack[]) {

if(delta instanceof ItemStack[]) { // Old behavior - legacy code
ItemStack[] items = (ItemStack[]) delta;
if(items.length > 36) {
return;
Expand All @@ -231,6 +236,10 @@ public void change(final Inventory[] invis, final @Nullable Object[] delta, fina
((ItemType) d).addTo(invi);
}
}
} else if (delta instanceof ItemType[]) {
for (final Object d : delta) {
((ItemType) d).addTo(invi);
}
}
break;
case REMOVE:
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.bukkit.inventory.InventoryHolder;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
Expand Down
Expand Up @@ -154,7 +154,7 @@ public void execute(final @Nullable Listener listener, final Event event) throws
last = event;
final PlayerMoveEvent e = (PlayerMoveEvent) event;
final Location to = e.getTo(), from = e.getFrom();
if (to.equals(from))
if (to.equals(from) || to.distanceSquared(from) < 2)
return;
final Set<? extends Region> oldRs = RegionsPlugin.getRegionsAt(from), newRs = RegionsPlugin.getRegionsAt(to);
for (final Region r : oldRs) {
Expand Down

0 comments on commit 334555c

Please sign in to comment.