Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds InventoryMoveItemEvent #5462

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
Expand Down Expand Up @@ -1562,5 +1563,19 @@ public Location get(LootGenerateEvent event) {
}
}, EventValues.TIME_NOW);
}

// InventoryItemMoveEvent - does not extend InventoryEvent
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
EventValues.registerEventValue(InventoryMoveItemEvent.class, Inventory.class, new Getter<Inventory, InventoryMoveItemEvent>() {
@Override
public Inventory get(InventoryMoveItemEvent event) {
return event.getSource();
}
}, EventValues.TIME_NOW);
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
EventValues.registerEventValue(InventoryMoveItemEvent.class, Inventory.class, new Getter<Inventory, InventoryMoveItemEvent>() {
@Override
public Inventory get(InventoryMoveItemEvent event) {
return event.getDestination();
}
}, EventValues.TIME_FUTURE);
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
}
}
19 changes: 17 additions & 2 deletions src/main/java/ch/njol/skript/events/EvtItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package ch.njol.skript.events;

import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.sections.EffSecSpawn;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockDispenseEvent;
Expand All @@ -28,6 +29,7 @@
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
Expand Down Expand Up @@ -127,6 +129,17 @@ public class EvtItem extends SkriptEvent {
.examples("on item merge of gold blocks:",
" cancel event")
.since("2.2-dev35");
Skript.registerEvent("Inventory Item Move", SimpleEvent.class, InventoryMoveItemEvent.class, "inventory item (move|transport)")
.description(
"Called when an entity or block (e.g. hopper) tries to move items directly from one inventory to another.",
"When this event is called, the initiator may already have removed the item from the source inventory and is ready to move it into the destination inventory.",
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
"If this event is cancelled, the items will be returned to the source inventory."
)
.examples(
"on inventory item move:",
"\tsend \"%holder of event-inventory% is transporting %event-item% to %holder of future event-inventory%!\""
)
.since("INSERT VERSION");
}

@Nullable
Expand Down Expand Up @@ -184,6 +197,8 @@ public boolean check(final Event event) {
is = ((ItemDespawnEvent) event).getEntity().getItemStack();
} else if (event instanceof ItemMergeEvent) {
is = ((ItemMergeEvent) event).getTarget().getItemStack();
} else if (event instanceof InventoryMoveItemEvent) {
is = ((InventoryMoveItemEvent) event).getItem();
} else {
assert false;
return false;
Expand All @@ -201,8 +216,8 @@ public boolean check(final ItemType t) {
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return "dispense/spawn/drop/craft/pickup/consume/break/despawn/merge" + (types == null ? "" : " of " + types);
public String toString(@Nullable Event event, boolean debug) {
return "dispense/spawn/drop/craft/pickup/consume/break/despawn/merge/move item" + (types == null ? "" : " of " + types);
NotSoDelayed marked this conversation as resolved.
Show resolved Hide resolved
}

}