diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java index 0b1ba63..831b72d 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java @@ -24,6 +24,11 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter { this.item = item; } + public LinkedBeaconTeleporterItem(String teleporterId){ + this(teleporterId, + new ItemStack(Material.BEACON) + ); + } public ItemStack item(){ return item; diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java index a45b944..ea08190 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java @@ -76,6 +76,23 @@ public class LinkedBeaconTeleporterManager { Main.log.info("All done!"); } + public LinkedBeaconTeleporterItem breakLbtBlock(LinkedBeaconTeleporterBlock lbtBlock){ + // Get list by id + List lbtBlocks = linkedBeaconTeleporterById.get(lbtBlock.teleporterId()); + + // Remove from list + lbtBlocks.remove(lbtBlock); + // Remove from location + linkedBeaconTeleporterByLoc.remove( + Function.serialiseBlockLocation(lbtBlock.block().getLocation()) + ); + + // Item from block + LinkedBeaconTeleporterItem lbtItem = new LinkedBeaconTeleporterItem(lbtBlock.teleporterId()); + + return lbtItem; + } + // Conversion-methods public ItemStack getItemStackFromLbtItem(LinkedBeaconTeleporterItem lbtItem){ ItemStack item = new ItemStack(Material.BEACON); diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnBlockBreak.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnBlockBreak.java index dca66c9..97d9e7b 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnBlockBreak.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnBlockBreak.java @@ -1,11 +1,24 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener; +import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main; import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock; +import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem; +import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterManager; import org.bukkit.event.block.BlockBreakEvent; public class OnBlockBreak { public static void onBlockBreakEvent(BlockBreakEvent e, LinkedBeaconTeleporterBlock lbtBlock){ + LinkedBeaconTeleporterItem lbtItem = Main.lbtManager.breakLbtBlock(lbtBlock); + // Dont drop anything + e.setDropItems(false); + e.setExpToDrop(0); + + // Drop custom-item + lbtBlock.block().getLocation().getWorld().dropItemNaturally( + lbtBlock.block().getLocation(), + lbtItem.item() + ); } }