diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporter.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporter.java index 65e89c6..1a9ad03 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporter.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporter.java @@ -3,6 +3,9 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter; import eu.ruekov.ruakij.LinkedBeaconTeleporters.Function; import org.bukkit.Location; +import java.util.ArrayList; +import java.util.List; + /** * Describes a placed-beacon-teleporter in the world */ @@ -11,6 +14,9 @@ public abstract class LinkedBeaconTeleporter { // Persistent id for linked-beacons public String teleporterId; + // List of all linkedBeaconTeleporters with same teleporterId (real Type is usually ..Block, because linked Items are temporary constructs are useless) + protected List linkedBeaconTeleporters = new ArrayList<>(); + LinkedBeaconTeleporter(){ this.teleporterId = Function.randomString("abcdefghijklmnopqrstuvwxyz0123456789", 10); } @@ -21,4 +27,8 @@ public abstract class LinkedBeaconTeleporter { public String teleporterId(){ return teleporterId; } + + public List linkedBeaconTeleporters(){ + return linkedBeaconTeleporters; + } } 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 16dd218..583e8c3 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java @@ -19,7 +19,7 @@ import java.util.regex.Pattern; public class LinkedBeaconTeleporterManager { // Stores all placed Beacon-Teleporters for fast access // TODO: Evaluate necessity of 2 HashMaps with main reason of performance - HashMap> linkedBeaconTeleporterById = new HashMap(); + HashMap> linkedBeaconTeleporterById = new HashMap(); HashMap linkedBeaconTeleporterByLoc = new HashMap(); // Regex to match item-name&lore and extract id (group 1) @@ -42,7 +42,7 @@ public class LinkedBeaconTeleporterManager { ConfigurationSection teleportersData = Main.data.getConfigurationSection(teleporterId); // New list for this id - ArrayList lbtBlocks = new ArrayList(); + List linkedBeaconTeleporters = new ArrayList(); for(String blockId : teleportersData.getKeys(false)) { ConfigurationSection teleporterData = teleportersData.getConfigurationSection(blockId); @@ -67,16 +67,15 @@ public class LinkedBeaconTeleporterManager { // Construct block LinkedBeaconTeleporterBlock lbtBlock = new LinkedBeaconTeleporterBlock(teleporterId, block); - - // Add block to id-list - lbtBlocks.add(lbtBlock); + // Write reference of list + lbtBlock.linkedBeaconTeleporters = linkedBeaconTeleporters; // Save to loc-list linkedBeaconTeleporterByLoc.put(serializedLoc, lbtBlock); } // Save list to id-list - linkedBeaconTeleporterById.put(teleporterId, lbtBlocks); + linkedBeaconTeleporterById.put(teleporterId, linkedBeaconTeleporters); } Main.log.info("All done!"); @@ -84,7 +83,7 @@ public class LinkedBeaconTeleporterManager { public LinkedBeaconTeleporterBlock placeLbtItem(LinkedBeaconTeleporterItem lbtItem, Block block){ // Check if id already exists - List lbtBlocks = linkedBeaconTeleporterById.get(lbtItem.teleporterId()); + List lbtBlocks = linkedBeaconTeleporterById.get(lbtItem.teleporterId()); if(lbtBlocks == null){ // Create empty if not found lbtBlocks = new ArrayList<>(); @@ -107,7 +106,7 @@ public class LinkedBeaconTeleporterManager { public LinkedBeaconTeleporterItem breakLbtBlock(LinkedBeaconTeleporterBlock lbtBlock){ // Get list by id - List lbtBlocks = linkedBeaconTeleporterById.get(lbtBlock.teleporterId()); + List lbtBlocks = linkedBeaconTeleporterById.get(lbtBlock.teleporterId()); // Remove from list lbtBlocks.remove(lbtBlock); @@ -198,7 +197,7 @@ public class LinkedBeaconTeleporterManager { return linkedBeaconTeleporterByLoc.get(serializedLoc); } - public List getLbtBlocksFromTeleportId(String teleportId){ + public List getLbtBlocksFromTeleportId(String teleportId){ return linkedBeaconTeleporterById.get(teleportId); } diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCustomPlayerMove.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCustomPlayerMove.java index c732d7d..ae78e27 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCustomPlayerMove.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCustomPlayerMove.java @@ -4,6 +4,7 @@ import eu.ruekov.ruakij.LinkedBeaconTeleporters.Function; import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main; import eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent.CustomPlayerMoveEvent; import eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent.CustomPlayerMoveEventListener; +import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporter; import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock; import org.bukkit.Material; import org.bukkit.block.Block; @@ -52,17 +53,15 @@ public class OnCustomPlayerMove implements CustomPlayerMoveEventListener { if(lbtBlock == null) return; // Check if player should be ignored on this LinkedBeaconTeleporter + // FIXME: Will remove player from list, even though he should be ignored :/ if(playerBeaconLocation.get(uuid) != null && playerBeaconLocation.get(uuid) == lbtBlock) return; - // Find partnering Beacon - List lbtBlocks = Main.lbtManager.getLbtBlocksFromTeleportId(lbtBlock.teleporterId()); - if(lbtBlocks == null) return; - // Get first partner thats not our current-block LinkedBeaconTeleporterBlock lbtBlockPartner = null; - for(LinkedBeaconTeleporterBlock lbtBlockTmp: lbtBlocks){ - if(lbtBlockTmp != lbtBlocks){ - lbtBlockPartner = lbtBlockTmp; + for(LinkedBeaconTeleporter lbtBlockTmp: lbtBlock.linkedBeaconTeleporters()){ + // Upcast as linked-Teleporters are only blocks anyways + if((LinkedBeaconTeleporterBlock)lbtBlockTmp != lbtBlock){ + lbtBlockPartner = (LinkedBeaconTeleporterBlock)lbtBlockTmp; break; } } @@ -75,7 +74,7 @@ public class OnCustomPlayerMove implements CustomPlayerMoveEventListener { // Teleport e.player().teleport( - lbtBlockPartner.block().getLocation().add(0, 1, 0) + lbtBlockPartner.block().getLocation().add(0.5, 1, 0.5) ); } }