diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoDisenchantEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoDisenchantEvent.java index d77d787cc1..2a1f54660b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoDisenchantEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoDisenchantEvent.java @@ -2,6 +2,8 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoDisenchanter; import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.bukkit.block.Block; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -18,6 +20,7 @@ public class AutoDisenchantEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); private final ItemStack item; + private Block block; private boolean cancelled; public AutoDisenchantEvent(@Nonnull ItemStack item) { @@ -26,6 +29,13 @@ public AutoDisenchantEvent(@Nonnull ItemStack item) { this.item = item; } + public AutoDisenchantEvent(@Nonnull ItemStack item, @Nullable Block block) { + super(true); + + this.item = item; + this.block = block; + } + /** * This returns the {@link ItemStack} that is being disenchanted. * @@ -36,6 +46,15 @@ public ItemStack getItem() { return item; } + /** + * This returns the {@link Block} that is disenchanting items + * + * @return The {@link Block} that is disenchanting items + */ + @Nullable public Block getBlock() { + return block; + } + @Override public boolean isCancelled() { return cancelled; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoEnchantEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoEnchantEvent.java index 0ce7b14299..3016cd212a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoEnchantEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoEnchantEvent.java @@ -2,6 +2,8 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoEnchanter; import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.bukkit.block.Block; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -20,6 +22,7 @@ public class AutoEnchantEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); private final ItemStack item; + private Block block; private boolean cancelled; public AutoEnchantEvent(@Nonnull ItemStack item) { @@ -28,6 +31,13 @@ public AutoEnchantEvent(@Nonnull ItemStack item) { this.item = item; } + public AutoEnchantEvent(@Nonnull ItemStack item, @Nullable Block block) { + super(true); + + this.item = item; + this.block = block; + } + /** * This returns the {@link ItemStack} that is being enchanted. * @@ -38,6 +48,15 @@ public ItemStack getItem() { return item; } + /** + * This returns the {@link Block} that is enchanting items + * + * @return The {@link Block} that is enchanting items + */ + @Nullable public Block getBlock() { + return block; + } + @Override public boolean isCancelled() { return cancelled; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java index 98e67991ac..8137e10b72 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java @@ -61,10 +61,14 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) { } // Call an event so other Plugins can modify it. - AutoDisenchantEvent event = new AutoDisenchantEvent(item); + AutoDisenchantEvent event = new AutoDisenchantEvent(item, menu.getBlock()); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { + if (InvUtils.fitAll(menu.toInventory(), new ItemStack[] {item}, getOutputSlots())) { + menu.replaceExistingItem(slot, null); + menu.pushItem(item, getOutputSlots()); + } return null; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java index a72166cc12..57919359c7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java @@ -54,7 +54,9 @@ public ItemStack getProgressBar() { @Override protected MachineRecipe findNextRecipe(BlockMenu menu) { for (int slot : getInputSlots()) { - ItemStack item = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]); + // Other item + int otherSlot = slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]; + ItemStack item = menu.getItemInSlot(otherSlot); // Check if the item is enchantable if (!isEnchantable(item)) { @@ -62,10 +64,14 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) { } // Call an event so other Plugins can modify it. - AutoEnchantEvent event = new AutoEnchantEvent(item); + AutoEnchantEvent event = new AutoEnchantEvent(item, menu.getBlock()); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { + if (InvUtils.fitAll(menu.toInventory(), new ItemStack[] {item}, getOutputSlots())) { + menu.replaceExistingItem(otherSlot, null); + menu.pushItem(item, getOutputSlots()); + } return null; }