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

Expose displaced items in kit event #1036

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion core/src/main/java/tc/oc/pgm/kits/ApplyItemKitEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
public class ApplyItemKitEvent extends ApplyKitEvent {
private final Map<Slot, ItemStack> slotItems;
private final List<ItemStack> freeItems;
private final List<ItemStack> displacedItems;

public ApplyItemKitEvent(MatchPlayer player, ItemKit kit, boolean force) {
public ApplyItemKitEvent(
MatchPlayer player, ItemKit kit, boolean force, List<ItemStack> displacedItems) {
super(player, kit, force);

this.slotItems = new HashMap<>(kit.getSlotItems().size());
Expand All @@ -26,6 +28,7 @@ public ApplyItemKitEvent(MatchPlayer player, ItemKit kit, boolean force) {
for (ItemStack stack : kit.getFreeItems()) {
this.freeItems.add(stack.clone());
}
this.displacedItems = displacedItems;
}

/**
Expand All @@ -40,6 +43,10 @@ public List<ItemStack> getFreeItems() {
return freeItems;
}

public List<ItemStack> getDisplacedItems() {
return displacedItems;
}

/**
* Return all items that will be applied by the kit. Iterators from the returned iterable support
* {@link Iterator#remove} to prevent the item from being applied, without modifying the original
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/kits/ItemKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Iterable<ItemStack> getItems() {
*/
@Override
public void apply(MatchPlayer player, boolean force, List<ItemStack> displacedItems) {
ApplyItemKitEvent event = new ApplyItemKitEvent(player, this, force);
ApplyItemKitEvent event = new ApplyItemKitEvent(player, this, force, displacedItems);
player.getMatch().callEvent(event);
if (event.isCancelled()) {
return;
Expand Down