1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Merge pull request #1244 from poma123/patch-1

AutoDisenchantEvent
This commit is contained in:
TheBusyBiscuit 2019-11-16 17:47:32 +01:00 committed by GitHub
commit 0a08690ae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,43 @@
package me.mrCookieSlime.Slimefun.Events;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
public class AutoDisenchantEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final ItemStack item;
private boolean cancelled;
public AutoDisenchantEvent(ItemStack item) {
super(true);
this.item = item;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public ItemStack getItem() {
return this.item;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}

View File

@ -5,9 +5,12 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import me.mrCookieSlime.Slimefun.Events.AutoDisenchantEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
@ -94,6 +97,12 @@ public class AutoDisenchanter extends AContainer {
return;
}
AutoDisenchantEvent event = new AutoDisenchantEvent(item);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// Disenchanting
if (item != null && target != null && target.getType() == Material.BOOK) {
int amount = 0;