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 ea08190..50eaf24 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,28 @@ public class LinkedBeaconTeleporterManager { Main.log.info("All done!"); } + public LinkedBeaconTeleporterBlock placeLbtItem(LinkedBeaconTeleporterItem lbtItem, Block block){ + // Check if id already exists + List lbtBlocks = linkedBeaconTeleporterById.get(lbtItem.teleporterId()); + if(lbtBlocks == null){ + // Create empty if not found + lbtBlocks = new ArrayList<>(); + } + + // Block from item + LinkedBeaconTeleporterBlock lbtBlock = new LinkedBeaconTeleporterBlock(lbtItem.teleporterId(), block); + + // Add to list + lbtBlocks.add(lbtBlock); + // Add to location + linkedBeaconTeleporterByLoc.put( + Function.serialiseBlockLocation(block.getLocation()), + lbtBlock + ); + + return lbtBlock; + } + public LinkedBeaconTeleporterItem breakLbtBlock(LinkedBeaconTeleporterBlock lbtBlock){ // Get list by id List lbtBlocks = linkedBeaconTeleporterById.get(lbtBlock.teleporterId()); diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnBlockPlace.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnBlockPlace.java index 57d9e89..e474b01 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnBlockPlace.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnBlockPlace.java @@ -1,11 +1,16 @@ 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 org.bukkit.block.Block; import org.bukkit.event.block.BlockPlaceEvent; public class OnBlockPlace { public static void onBlockPlaceEvent(BlockPlaceEvent e, LinkedBeaconTeleporterItem lbtItem){ + Block block = e.getBlock(); + LinkedBeaconTeleporterBlock lbtBlock = Main.lbtManager.placeLbtItem(lbtItem, block); } }