NEWS: Welcome to my new homepage! <3

Added AutoBreakerModule, AutoPlacerModule, HopperSorterModule and fixed bug - poppy - A feature-rich Minecraft plugin which enhances gaming experience

poppy

A feature-rich Minecraft plugin which enhances gaming experience
git clone git://192.168.2.2/poppy
Log | Files | Refs | README

commit 06e6bbe78513f4b31c4f6c9f02b9c95741e049df
parent 9f8579ccd74178430ea77ffba3ace8dc7ae1b756
Author: chunksize <reisingerluca@gmail.com>
Date:   Fri, 17 Feb 2023 14:03:34 +0100

Added AutoBreakerModule, AutoPlacerModule, HopperSorterModule and fixed bug

Diffstat:
Msrc/poppy/Config.java | 116++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/poppy/Main.java | 15+++++++++++++++
Msrc/poppy/Utils.java | 6++++++
Asrc/poppy/modules/AutoBreakerModule.java | 230+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/poppy/modules/AutoPlacerModule.java | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/poppy/modules/CommonModule.java | 2+-
Asrc/poppy/modules/HopperSorterModule.java | 335+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/poppy/modules/SpawnerModule.java | 36++++++++++++++++++++++--------------
8 files changed, 755 insertions(+), 73 deletions(-)

diff --git a/src/poppy/Config.java b/src/poppy/Config.java @@ -12,73 +12,73 @@ import org.bukkit.Location; public class Config { - private File file; - private FileConfiguration configuration; + private File file; + private FileConfiguration configuration; - public Config(final String path) - { - this.file = new File(path); - this.configuration = YamlConfiguration.loadConfiguration(this.file); - } + public Config(final String path) + { + this.file = new File(path); + this.configuration = YamlConfiguration.loadConfiguration(this.file); + } - public void setHome(final Player player) throws IOException - { - final String path = "home." + player.getDisplayName(); - final Location location = Utils.calcBlockCenter(player.getLocation()); - - this.configuration.set(path, location); - this.configuration.save(this.file); - } + public void setHome(final Player player) throws IOException + { + final String path = "home." + player.getDisplayName(); + final Location location = Utils.calcBlockCenter(player.getLocation()); + + this.configuration.set(path, location); + this.configuration.save(this.file); + } - public Location getHome(final Player player) - { - final String path = "home." + player.getDisplayName(); - - return this.configuration.getLocation(path); - } + public Location getHome(final Player player) + { + final String path = "home." + player.getDisplayName(); + + return this.configuration.getLocation(path); + } - public boolean setWarp(final String name, final Location location) throws IOException - { - final String path = "warp." + name; + public boolean setWarp(final String name, final Location location) throws IOException + { + final String path = "warp." + name; - if(this.configuration.getLocation(path) != null) - { - return false; - } - - this.configuration.set(path, Utils.calcBlockCenter(location)); - this.configuration.save(this.file); + if(this.configuration.getLocation(path) != null) + { + return false; + } + + this.configuration.set(path, Utils.calcBlockCenter(location)); + this.configuration.save(this.file); - return true; - } + return true; + } - public Location getWarp(final String name) - { - final String path = "warp." + name; - - return this.configuration.getLocation(path); - } + public Location getWarp(final String name) + { + final String path = "warp." + name; + + return this.configuration.getLocation(path); + } - public List<String> getInfoPages() - { - final String path = "info"; - List<String> pages = null; + public List<String> getInfoPages() + { + final String path = "info"; + List<String> pages = null; - try - { - this.configuration.load(this.file); - pages = this.configuration.getStringList(path); - } - catch(Exception ex) - { - // ignore - } + try + { + this.configuration.load(this.file); + pages = this.configuration.getStringList(path); + } + catch(Exception ex) + { + // ignore + } - if(pages == null) - { - pages = new ArrayList<>(); - } + if(pages == null) + { + pages = new ArrayList<>(); + } - return pages; - } + return pages; + } } diff --git a/src/poppy/Main.java b/src/poppy/Main.java @@ -15,10 +15,13 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import poppy.modules.AutoBreakerModule; +import poppy.modules.AutoPlacerModule; import poppy.modules.AutoWorkbenchModule; import poppy.modules.CauldronModule; import poppy.modules.ChairModule; import poppy.modules.DoubleDoorModule; +import poppy.modules.HopperSorterModule; import poppy.modules.CommonModule; import poppy.modules.LeavesDecayModule; import poppy.modules.SpawnerModule; @@ -37,6 +40,9 @@ public class Main extends JavaPlugin private LeavesDecayModule leavesDecayModule; private CauldronModule cauldronModule; private SpawnerModule spawnerModule; + private HopperSorterModule hopperSorterModule; + private AutoPlacerModule autoPlacerModule; + private AutoBreakerModule autoBreakerModule; @Override public void onEnable() @@ -66,6 +72,15 @@ public class Main extends JavaPlugin spawnerModule = new SpawnerModule(); pluginManager.registerEvents(spawnerModule, this); + + hopperSorterModule = new HopperSorterModule(); + pluginManager.registerEvents(hopperSorterModule, this); + + autoPlacerModule = new AutoPlacerModule(this); + pluginManager.registerEvents(autoPlacerModule, this); + + autoBreakerModule = new AutoBreakerModule(this); + pluginManager.registerEvents(autoBreakerModule, this); } @Override diff --git a/src/poppy/Utils.java b/src/poppy/Utils.java @@ -247,4 +247,10 @@ public class Utils { return from.getWorld().getName().equals(to.getWorld().getName()); } + + public static boolean randomlyReduceDurability(final int level) + { + final float chance = 100.0f / (level + 1); + return Math.random() * 100 <= chance; + } } diff --git a/src/poppy/modules/AutoBreakerModule.java b/src/poppy/modules/AutoBreakerModule.java @@ -0,0 +1,230 @@ +package poppy.modules; + +import java.util.HashSet; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Tag; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.Chest; +import org.bukkit.block.Dispenser; +import org.bukkit.block.data.Directional; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockDispenseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.Plugin; + +import poppy.Utils; + +public class AutoBreakerModule implements Listener +{ + private Plugin plugin; + + public AutoBreakerModule(Plugin plugin) + { + this.plugin = plugin; + } + + @EventHandler + public void onBlockDispenseEvent(BlockDispenseEvent event) + { + final Block block = event.getBlock(); + final BlockState blockState = block.getState(); + final ItemStack item = event.getItem(); + + if(blockState instanceof Dispenser) + { + final Dispenser dispenser = (Dispenser) blockState; + + if(dispenser.getCustomName().toLowerCase().equals("breaker")) + { + event.setCancelled(true); + + if(block.getBlockData() instanceof Directional) + { + final Directional direction = (Directional) dispenser.getBlockData(); + final Block faceBlock = dispenser.getBlock().getRelative(direction.getFacing()); + + final HashSet<ItemStack> drops = new HashSet<ItemStack>(faceBlock.getDrops(item)); + + if(item.getType().toString().endsWith("_PICKAXE")) + { + if(Tag.MINEABLE_PICKAXE.isTagged(faceBlock.getType())) + { + if(!addItemToChest(direction, dispenser, drops)) + { + setDamage(item, dispenser); + faceBlock.breakNaturally(item); + } + else + { + setDamage(item, dispenser); + faceBlock.setType(Material.AIR); + } + } + } + + if(item.getType().toString().endsWith("_AXE")) + { + if(Tag.MINEABLE_AXE.isTagged(faceBlock.getType())) + { + if(!addItemToChest(direction, dispenser, drops)) + { + setDamage(item, dispenser); + faceBlock.breakNaturally(item); + } + else + { + setDamage(item, dispenser); + faceBlock.setType(Material.AIR); + } + } + } + + if(item.getType().toString().endsWith("_SHOVEL")) + { + if(Tag.MINEABLE_SHOVEL.isTagged(faceBlock.getType())) + { + if(!addItemToChest(direction, dispenser, drops)) + { + setDamage(item, dispenser); + faceBlock.breakNaturally(item); + } + else + { + setDamage(item, dispenser); + faceBlock.setType(Material.AIR); + } + } + } + + if(item.getType().toString().endsWith("_HOE")) + { + if(Tag.MINEABLE_HOE.isTagged(faceBlock.getType())) + { + if(!addItemToChest(direction, dispenser, drops)) + { + setDamage(item, dispenser); + faceBlock.breakNaturally(item); + } + else + { + setDamage(item, dispenser); + faceBlock.setType(Material.AIR); + } + } + } + + if(item.getType().toString().endsWith("_PICKAXE") && !Utils.isAir(faceBlock.getType()) + && !Tag.MINEABLE_PICKAXE.isTagged(faceBlock.getType()) + && !Tag.MINEABLE_HOE.isTagged(faceBlock.getType()) + && !Tag.MINEABLE_AXE.isTagged(faceBlock.getType()) + && !Tag.MINEABLE_SHOVEL.isTagged(faceBlock.getType())) + { + setDamage(item, dispenser); + faceBlock.breakNaturally(item); + } + } + } + } + } + + public static boolean isInventoryFullList(Inventory inventory, HashSet<ItemStack> items) + { + final HashSet<ItemStack> itemsCopy = new HashSet<ItemStack>(items); + + for(ItemStack item : itemsCopy) + { + if(!Utils.isInventoryFull(inventory, item)) + { + itemsCopy.remove(item); + } + } + return itemsCopy.size() != 0; + } + + public static boolean addItemToChest(Directional direction, Dispenser dispenser, HashSet<ItemStack> items) + { + Chest chest = null; + boolean succeeded = false; + + for(BlockFace face : faces) + { + if(!face.equals(direction.getFacing()) && chest == null) + { + final Block blockAtFacing = dispenser.getBlock().getRelative(face); + final BlockState blockStateAtFacing = blockAtFacing.getState(); + + if(blockAtFacing.getType().equals(Material.CHEST) && blockStateAtFacing instanceof Chest) + { + final Chest chestBlock = (Chest) blockStateAtFacing; + + if(!isInventoryFullList(chestBlock.getInventory(), items)) + { + for(ItemStack item : items) + { + chestBlock.getInventory().addItem(item); + } + succeeded = true; + break; + } + chest = chestBlock; + } + } + } + return succeeded; + } + + public void setDamage(ItemStack item, Dispenser dispenser) + { + Bukkit.getScheduler().runTaskLater(plugin, () -> { + if(Utils.randomlyReduceDurability(item.getEnchantmentLevel(Enchantment.DURABILITY))) + { + final ItemMeta itemMeta = item.getItemMeta(); + final int slot = dispenser.getInventory().first(item); + + if(itemMeta instanceof Damageable && slot != -1) + { + final ItemStack itemstack = dispenser.getInventory().getItem(slot); + final Damageable itemDamage = (Damageable) itemstack.getItemMeta(); + + if(itemDamage.getDamage() == 0) + { + itemDamage.setDamage(1); + } + else if(itemDamage.getDamage() != 0) + { + final int addedDamage = itemDamage.getDamage() + 1; + + if(addedDamage < itemstack.getType().getMaxDurability()) + { + itemDamage.setDamage(addedDamage); + } + else + { + itemstack.setType(Material.AIR); + } + } + itemstack.setItemMeta(itemDamage); + dispenser.getInventory().setItem(slot, itemstack); + } + } + }, 1); + } + + private static final BlockFace[] faces = { + BlockFace.DOWN, + BlockFace.UP, + BlockFace.NORTH, + BlockFace.EAST, + BlockFace.SOUTH, + BlockFace.WEST + }; +} diff --git a/src/poppy/modules/AutoPlacerModule.java b/src/poppy/modules/AutoPlacerModule.java @@ -0,0 +1,88 @@ +package poppy.modules; + +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Tag; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Dispenser; +import org.bukkit.block.data.Directional; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockDispenseEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BlockStateMeta; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.Plugin; + +import poppy.Utils; + +public class AutoPlacerModule implements Listener +{ + private Plugin plugin; + + public AutoPlacerModule(Plugin plugin) + { + this.plugin = plugin; + } + + @EventHandler + public void onBlockDispenseEvent(BlockDispenseEvent event) + { + final Block block = event.getBlock(); + final BlockState blockState = block.getState(); + final ItemStack item = event.getItem(); + + if(blockState instanceof Dispenser) + { + Dispenser dispenser = (Dispenser) blockState; + + if(dispenser.getCustomName().toLowerCase().equals("placer")) + { + event.setCancelled(true); + + if(block.getBlockData() instanceof Directional) + { + final Directional direction = (Directional) dispenser.getBlockData(); + final Block faceBlock = dispenser.getBlock().getRelative(direction.getFacing()); + + if(item.getType().isBlock() && Utils.isAir(faceBlock.getType()) && !isShulkerboxContend(item)) + { + faceBlock.setType(item.getType()); + removeSnapshotItem(dispenser, item.getType(), 1); + } + } + + if(isShulkerboxContend(item)) + { + event.setCancelled(false); + } + } + } + } + + public boolean isShulkerboxContend(ItemStack itemStack) + { + final ItemMeta itemMeta = itemStack.getItemMeta(); + final Set<Material> shulkerboxes = Tag.SHULKER_BOXES.getValues(); + + for(Material material : shulkerboxes) + { + if(itemStack.getType().equals(material) && itemMeta instanceof BlockStateMeta) + { + return true; + } + } + return false; + } + + public void removeSnapshotItem(Dispenser dispenser, Material material, int amount) + { + Bukkit.getScheduler().runTaskLater(plugin, () -> { + dispenser.getSnapshotInventory().addItem(new ItemStack(material, -amount)); + dispenser.update(); + }, 1); + } +} diff --git a/src/poppy/modules/CommonModule.java b/src/poppy/modules/CommonModule.java @@ -164,7 +164,7 @@ public class CommonModule implements Listener { Player clickedPlayer = (Player) event.getRightClicked(); - if(clickedPlayer.getInventory().getHelmet().getType().equals(Material.SADDLE)) + if(clickedPlayer.getInventory().getHelmet().getType().equals(Material.SADDLE) && player.getPassengers().size() < 0) { clickedPlayer.addPassenger(player); } diff --git a/src/poppy/modules/HopperSorterModule.java b/src/poppy/modules/HopperSorterModule.java @@ -0,0 +1,335 @@ +package poppy.modules; + +import java.util.HashSet; +import java.util.ListIterator; +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Tag; +import org.bukkit.block.Block; +import org.bukkit.block.ShulkerBox; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.ItemFrame; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryMoveItemEvent; +import org.bukkit.event.inventory.InventoryPickupItemEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BlockStateMeta; +import org.bukkit.inventory.meta.ItemMeta; + +import poppy.Utils; + +public class HopperSorterModule implements Listener +{ + @EventHandler + public void onInventoryMoveItem(InventoryMoveItemEvent event) + { + final Location targetHopperLocation = event.getDestination().getLocation().clone(); + final Block targetHopper = targetHopperLocation.getBlock(); + + if(targetHopper.getType() != Material.HOPPER) + { + return; + } + + ItemFrame[] itemFrames = getBlockItemFrames(targetHopper); + + if(itemFrames.length == 0) + { + return; + } + + event.setCancelled(true); + + final HashSet<ItemStack> allowedItems = new HashSet <ItemStack>(); + final HashSet<ItemStack> allowedItemExact = new HashSet <ItemStack>(); + + saveItemsInLists(itemFrames, allowedItems, allowedItemExact); + addInventoryItems(allowedItems, allowedItemExact, event.getSource(), event.getDestination()); + + for(ItemStack item : allowedItems) + { + if(event.getItem().getType().equals(item.getType())) + { + event.setCancelled(false); + } + } + + for(ItemStack item : allowedItemExact) + { + if(event.getItem().equals(item) && event.getItem().getItemMeta().equals(item.getItemMeta())) + { + event.setCancelled(false); + } + } + } + + @EventHandler + public void onInventoryPickupItem(InventoryPickupItemEvent event) + { + final Location targetHopperLocation = event.getInventory().getLocation().clone(); + final Block targetHopper = targetHopperLocation.getBlock(); + + if(!event.getInventory().getType().equals(InventoryType.HOPPER)) + { + return; + } + + ItemFrame[] itemFrames = getBlockItemFrames(targetHopper); + + if(itemFrames.length == 0) + { + return; + } + + event.setCancelled(true); + + final HashSet<ItemStack> allowedItems = new HashSet <ItemStack>(); + final HashSet<ItemStack> allowedItemExact = new HashSet <ItemStack>(); + + saveItemsInLists(itemFrames, allowedItems, allowedItemExact); + + for(ItemStack item : allowedItems) + { + if(event.getItem().getItemStack().getType().equals(item.getType())) + { + event.setCancelled(false); + } + } + + for(ItemStack item : allowedItemExact) + { + if(event.getItem().getItemStack().getType().equals(item.getType()) && event.getItem().getItemStack().getItemMeta().equals(item.getItemMeta())) + { + event.setCancelled(false); + } + } + } + + public void addInventoryItems(HashSet<ItemStack> allowedItems, HashSet<ItemStack> allowedItemsExact, Inventory inventory, Inventory destinationInv) + { + ItemStack dummyItem = null; + final ListIterator<ItemStack> iterator = inventory.iterator(); + + while(iterator.hasNext()) + { + final ItemStack item = iterator.next(); + + for(ItemStack allowedItemExact : allowedItemsExact) + { + if(Utils.isEmpty(item)) + { + continue; + } + + if(item.getType().equals(allowedItemExact.getType()) && item.getItemMeta().equals(allowedItemExact.getItemMeta()) && dummyItem == null) + { + final HashSet<ItemStack> nullItems = new HashSet <ItemStack>(); + final int slot = inventory.first(item); + + if(slot > 0) + { + for (int i = slot -1 ; i >= 0; i--) + { + Boolean filterdItem = false; + final ItemStack nullItem = inventory.getItem(i); + + if(nullItem != null) + { + for(ItemStack allowedItem1 : allowedItems) + { + if(allowedItem1.getType().equals(nullItem.getType())) + { + filterdItem = true; + } + } + + for(ItemStack allowedItemExact1 : allowedItemsExact) + { + if(allowedItemExact1.getType().equals(nullItem.getType()) && allowedItemExact1.getItemMeta().equals(nullItem.getItemMeta())) + { + filterdItem = true; + } + } + + if(!filterdItem) + { + nullItems.add(inventory.getItem(i)); + } + } + } + } + + if(nullItems.size() != 0) + { + if(!Utils.isInventoryFull(destinationInv, item)) + { + final ItemStack clonedItem = item.clone(); + clonedItem.setAmount(1); + + destinationInv.addItem(clonedItem); + item.setAmount(item.getAmount() - 1); + dummyItem = item; + break; + } + } + } + } + + for(ItemStack allowedItem : allowedItems) + { + if(Utils.isEmpty(item)) + { + continue; + } + + if(item.getType() == allowedItem.getType() && dummyItem == null) + { + final HashSet<ItemStack> nullItems = new HashSet <ItemStack>(); + final int slot = inventory.first(item); + + if(slot > 0) + { + for (int i = slot - 1 ; i >= 0; i--) + { + Boolean filterdItem = false; + final ItemStack nullItem = inventory.getItem(i); + + if(nullItem != null) + { + for(ItemStack allowedItem1 : allowedItems) + { + if(allowedItem1.getType().equals(nullItem.getType())) + { + filterdItem = true; + } + } + + for(ItemStack allowedItemExact1 : allowedItemsExact) + { + if(allowedItemExact1.getType().equals(nullItem.getType()) && allowedItemExact1.getItemMeta().equals(nullItem.getItemMeta())) + { + filterdItem = true; + } + } + + if(!filterdItem) + { + nullItems.add(inventory.getItem(i)); + } + } + } + } + + if(nullItems.size() != 0) + { + if(!Utils.isInventoryFull(destinationInv, item)) + { + final ItemStack clonedItem = item.clone(); + clonedItem.setAmount(1); + + destinationInv.addItem(clonedItem); + item.setAmount(item.getAmount() - 1); + dummyItem = item; + break; + } + } + } + } + } + } + + public void saveItemsInLists(ItemFrame[] itemFrames, HashSet<ItemStack> allowedItems, HashSet<ItemStack> allowedItemExact) + { + for(ItemFrame itemFrame : itemFrames) + { + if(itemFrame.getType() == EntityType.GLOW_ITEM_FRAME) + { + allowedItemExact.add(itemFrame.getItem()); + + for(ItemStack items : getShulkerboxContent(itemFrame.getItem())) + { + allowedItemExact.add(items); + } + } + else if(itemFrame.getType() == EntityType.ITEM_FRAME) + { + allowedItems.add(itemFrame.getItem()); + + for(ItemStack items : getShulkerboxContent(itemFrame.getItem())) + { + allowedItems.add(items); + } + } + } + } + + public static ItemFrame[] getBlockItemFrames(Block block) + { + final HashSet<ItemFrame> itemframes = new HashSet <ItemFrame>(); + + for(Entity entity : getNearbyEntities(block.getLocation().add(.5, .5, .5), 1)) + { + if(entity instanceof ItemFrame) + { + final ItemFrame itemFrame = (ItemFrame) entity; + itemframes.add(itemFrame); + } + } + return itemframes.toArray(new ItemFrame[itemframes.size()]); + } + + public static ItemStack[] getShulkerboxContent(ItemStack itemStack) + { + final HashSet<ItemStack> itemList = new HashSet<ItemStack>(); + + if(itemStack.getType().equals(Material.AIR)) + { + return itemList.toArray(new ItemStack[itemList.size()]); + } + + final ItemMeta itemMeta = itemStack.getItemMeta(); + final Set<Material> shulkerboxes = Tag.SHULKER_BOXES.getValues(); + + for(Material material : shulkerboxes) + { + if(itemStack.getType().equals(material) && itemMeta instanceof BlockStateMeta) + { + final BlockStateMeta blockMeta = (BlockStateMeta) itemMeta; + final ShulkerBox shulkerBox = (ShulkerBox) blockMeta.getBlockState(); + + for(ItemStack item : shulkerBox.getInventory().getContents().clone()) + { + if(item != null) + { + item.setAmount(1); + itemList.add(item); + } + } + } + } + return itemList.toArray(new ItemStack[itemList.size()]); + } + + public static Entity[] getNearbyEntities(Location l, int radius) + { + int chunkRadius = radius < 16 ? 1 : (radius - (radius % 16)) / 16; + HashSet <Entity> radiusEntities = new HashSet < Entity > (); + + for (int chX = 0 - chunkRadius; chX <= chunkRadius; chX++) { + for (int chZ = 0 - chunkRadius; chZ <= chunkRadius; chZ++) { + int x = (int) l.getX(), y = (int) l.getY(), z = (int) l.getZ(); + for (Entity e: new Location(l.getWorld(), x + (chX * 16), y, z + (chZ * 16)).getChunk().getEntities()) { + if (e.getLocation().distance(l) <= radius && e.getLocation().getBlock() != l.getBlock()) + radiusEntities.add(e); + } + } + } + return radiusEntities.toArray(new Entity[radiusEntities.size()]); + } +} diff --git a/src/poppy/modules/SpawnerModule.java b/src/poppy/modules/SpawnerModule.java @@ -25,23 +25,31 @@ public class SpawnerModule implements Listener final Block block = event.getBlock(); final Player player = event.getPlayer(); final ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); + final Location blockLocation = block.getLocation(); - if(block.getType() == Material.SPAWNER && itemInMainHand.containsEnchantment(Enchantment.SILK_TOUCH)) + if(itemInMainHand.containsEnchantment(Enchantment.SILK_TOUCH)) { - final CreatureSpawner creatureSpawner = (CreatureSpawner) block.getState(); - final ItemStack spawner = new ItemStack(Material.SPAWNER); - final ItemMeta spawnerItemMeta = spawner.getItemMeta(); - final ArrayList<String> spawneritemLore = new ArrayList<String>(); - final Location blockLocation = block.getLocation(); - final BlockStateMeta spawnerblockMeta = (BlockStateMeta) spawner.getItemMeta(); + if(block.getType() == Material.SPAWNER) + { + final CreatureSpawner creatureSpawner = (CreatureSpawner) block.getState(); + final ItemStack spawner = new ItemStack(Material.SPAWNER); + final ItemMeta spawnerItemMeta = spawner.getItemMeta(); + final ArrayList<String> spawneritemLore = new ArrayList<String>(); + final BlockStateMeta spawnerblockMeta = (BlockStateMeta) spawner.getItemMeta(); - spawneritemLore.add(creatureSpawner.getSpawnedType().toString()); - spawnerItemMeta.setLore(spawneritemLore); - spawner.setItemMeta(spawnerItemMeta); - spawnerblockMeta.setBlockState(creatureSpawner); - blockLocation.getWorld().dropItemNaturally(blockLocation, spawner); - block.setType(Material.AIR); - event.setExpToDrop(0); + spawneritemLore.add(creatureSpawner.getSpawnedType().toString()); + spawnerItemMeta.setLore(spawneritemLore); + spawner.setItemMeta(spawnerItemMeta); + spawnerblockMeta.setBlockState(creatureSpawner); + blockLocation.getWorld().dropItemNaturally(blockLocation, spawner); + block.setType(Material.AIR); + event.setExpToDrop(0); + } + + if(block.getType() == Material.BUDDING_AMETHYST) + { + blockLocation.getWorld().dropItemNaturally(blockLocation, new ItemStack(Material.BUDDING_AMETHYST)); + } } }