Add KitClaimEvent (#3197)

Adds an event fired when a kit is expanded for a user. Fixes #3196.
This commit is contained in:
kmecpp 2020-05-09 16:19:51 -04:00 committed by GitHub
parent a043de3e44
commit 96590a3389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 0 deletions

View File

@ -8,6 +8,8 @@ import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.utils.DateUtil;
import net.ess3.api.IEssentials;
import net.ess3.api.events.KitClaimEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -149,6 +151,12 @@ public class Kit {
IText input = new SimpleTextInput(items);
IText output = new KeywordReplacer(input, user.getSource(), ess, true, true);
KitClaimEvent event = new KitClaimEvent(user, this);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}
boolean spew = false;
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
final boolean currencyIsSuffix = ess.getSettings().isCurrencySymbolSuffixed();

View File

@ -0,0 +1,55 @@
package net.ess3.api.events;
import org.bukkit.Bukkit;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.earth2me.essentials.Kit;
import net.ess3.api.IUser;
/**
* Called when the player is given a kit
*/
public class KitClaimEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private Kit kit;
private IUser user;
private boolean cancelled;
public KitClaimEvent(IUser user, Kit kit) {
super(!Bukkit.getServer().isPrimaryThread());
this.user = user;
this.kit = kit;
}
public IUser getUser() {
return user;
}
public Kit getKit() {
return kit;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}