diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java index f0c5efa8a..c6ae714e6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java @@ -98,6 +98,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.Cart import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.CauldronListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.CraftingTableListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.GrindstoneListener; +import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.HopperListener; import io.github.thebusybiscuit.slimefun4.implementation.resources.GEOResourcesSetup; import io.github.thebusybiscuit.slimefun4.implementation.setup.PostSetup; import io.github.thebusybiscuit.slimefun4.implementation.setup.ResearchSetup; @@ -475,6 +476,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { new CauldronListener(this); new GrindstoneListener(this); new CartographyTableListener(this); + new HopperListener(this); if (minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_15)) { new BeeListener(this); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java index 627fe50a9..c9f0d05da 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java @@ -5,6 +5,7 @@ import java.util.Map; import javax.annotation.Nonnull; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.VanillaContainer; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; @@ -26,7 +27,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; * @author Linox * */ -public class AutoBrewer extends AContainer { +public class AutoBrewer extends VanillaContainer { private static final Map potionRecipes = new EnumMap<>(Material.class); private static final Map fermentations = new EnumMap<>(PotionType.class); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java index 9273af6b4..188399887 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDrier.java @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machine import java.util.ArrayList; import java.util.List; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.VanillaContainer; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.inventory.ItemStack; @@ -22,7 +23,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; * @author Linox * */ -public class AutoDrier extends AContainer implements RecipeDisplayItem { +public class AutoDrier extends VanillaContainer implements RecipeDisplayItem { private List recipeList; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java index 8d70af663..0becc3e37 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricFurnace.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.VanillaContainer; import org.bukkit.Material; import org.bukkit.inventory.FurnaceRecipe; import org.bukkit.inventory.ItemStack; @@ -12,7 +13,7 @@ import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -public class ElectricFurnace extends AContainer { +public class ElectricFurnace extends VanillaContainer { public ElectricFurnace(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java index 1fe511565..d50e3fe7b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricIngotPulverizer.java @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machine import java.util.ArrayList; import java.util.List; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.VanillaContainer; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -23,7 +24,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; * @see ElectricIngotFactory * */ -public class ElectricIngotPulverizer extends AContainer implements RecipeDisplayItem { +public class ElectricIngotPulverizer extends VanillaContainer implements RecipeDisplayItem { public ElectricIngotPulverizer(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricOreGrinder.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricOreGrinder.java index 50187ea92..953795a2f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricOreGrinder.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricOreGrinder.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.VanillaContainer; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -9,7 +10,7 @@ import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -public class ElectricOreGrinder extends AContainer implements RecipeDisplayItem { +public class ElectricOreGrinder extends VanillaContainer implements RecipeDisplayItem { public ElectricOreGrinder(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricSmeltery.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricSmeltery.java index 4848b0514..a5f5eb43f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricSmeltery.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricSmeltery.java @@ -5,6 +5,7 @@ import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.VanillaContainer; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -35,7 +36,7 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; * @author TheBusyBiscuit * */ -public class ElectricSmeltery extends AContainer { +public class ElectricSmeltery extends VanillaContainer { private static final int[] border = { 4, 5, 6, 7, 8, 13, 31, 40, 41, 42, 43, 44 }; private static final int[] inputBorder = { 0, 1, 2, 3, 9, 12, 18, 21, 27, 30, 36, 37, 38, 39 }; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/HopperListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/HopperListener.java new file mode 100644 index 000000000..fd12aa234 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/HopperListener.java @@ -0,0 +1,36 @@ +package io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting; + +import javax.annotation.Nonnull; + +import org.bukkit.Location; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryMoveItemEvent; +import org.bukkit.event.inventory.InventoryType; + +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.VanillaContainer; +import me.mrCookieSlime.Slimefun.api.BlockStorage; + +/** + * This {@link Listener} prevents item from being transferred to a + * {@link VanillaContainer} using a hopper. + * + */ + +public class HopperListener implements SlimefunCraftingListener { + + public HopperListener(@Nonnull SlimefunPlugin plugin) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + public void fromHopper(InventoryMoveItemEvent e) { + Location loc = e.getDestination().getLocation(); + if (e.getSource().getType() == InventoryType.HOPPER && loc != null && BlockStorage.hasBlockInfo(loc)) { + if (BlockStorage.check(loc.getBlock()) instanceof VanillaContainer) { + e.setCancelled(true); + } + } + } +} diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/VanillaContainer.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/VanillaContainer.java new file mode 100644 index 000000000..aef1de788 --- /dev/null +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/VanillaContainer.java @@ -0,0 +1,17 @@ +package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems; + +import javax.annotation.ParametersAreNonnullByDefault; + +import org.bukkit.inventory.ItemStack; + +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; + +public abstract class VanillaContainer extends AContainer { + + @ParametersAreNonnullByDefault + public VanillaContainer(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + super(category, item, recipeType, recipe); + } +} \ No newline at end of file