Add KitPreExpandItemsEvent (#5407)

Co-authored-by: YanisBft <yanis.briffaut@gmail.com>
Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com>
This commit is contained in:
Josh Roy 2023-07-01 17:51:58 -04:00 committed by GitHub
parent d57094c0bc
commit 1022f7a3ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.NumberUtil;
import net.ess3.api.IEssentials;
import net.ess3.api.events.KitClaimEvent;
import net.essentialsx.api.v2.events.KitPreExpandItemsEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -219,7 +220,11 @@ public class Kit {
final int maxStackSize = user.isAuthorized("essentials.oversizedstacks") ? ess.getSettings().getOversizedStackSize() : 0;
final boolean isDropItemsIfFull = ess.getSettings().isDropItemsIfFull();
final KitPreExpandItemsEvent itemsEvent = new KitPreExpandItemsEvent(user, kitName, itemList);
Bukkit.getPluginManager().callEvent(itemsEvent);
final ItemStack[] itemArray = itemList.toArray(new ItemStack[0]);
if (!isDropItemsIfFull && !Inventories.hasSpace(user.getBase(), maxStackSize, autoEquip, itemArray)) {
user.sendMessage(tl("kitInvFullNoDrop"));
return false;

View File

@ -0,0 +1,62 @@
package net.essentialsx.api.v2.events;
import net.ess3.api.IUser;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
* Called when items from a kit are about to be given to a {@link IUser user}.
* <p>
* This event is not cancellable and is called right before items are about to be received by the {@link #getUser() user}.
* If you want to prevent kits from being claimed to begin with, use the {@link net.ess3.api.events.KitClaimEvent}
* @see net.ess3.api.events.KitClaimEvent
*/
public class KitPreExpandItemsEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private final IUser user;
private final String kitName;
private final List<ItemStack> itemStacks;
public KitPreExpandItemsEvent(IUser user, String kitName, List<ItemStack> itemStacks) {
this.user = user;
this.kitName = kitName;
this.itemStacks = itemStacks;
}
/**
* Gets the {@link IUser user} who is receiving the kit.
* @return the user.
*/
public IUser getUser() {
return user;
}
/**
* Gets the name of the kit the {@link IUser user} is receiving.
* @return the name of the kit.
*/
public String getKitName() {
return kitName;
}
/**
* Returns a mutable list with items to be received by the {@link IUser user}.
* @return the list of items.
*/
public List<ItemStack> getItemStacks() {
return itemStacks;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}