Implemented partner-list saved on LinkedBeaconTeleporter

master
Ruakij 4 years ago
parent f03a80cf99
commit 3d602c526d

@ -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<LinkedBeaconTeleporter> 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<LinkedBeaconTeleporter> linkedBeaconTeleporters(){
return linkedBeaconTeleporters;
}
}

@ -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<String, List<LinkedBeaconTeleporterBlock>> linkedBeaconTeleporterById = new HashMap();
HashMap<String, List<LinkedBeaconTeleporter>> linkedBeaconTeleporterById = new HashMap();
HashMap<String, LinkedBeaconTeleporterBlock> 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<LinkedBeaconTeleporterBlock> lbtBlocks = new ArrayList();
List<LinkedBeaconTeleporter> 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<LinkedBeaconTeleporterBlock> lbtBlocks = linkedBeaconTeleporterById.get(lbtItem.teleporterId());
List<LinkedBeaconTeleporter> 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<LinkedBeaconTeleporterBlock> lbtBlocks = linkedBeaconTeleporterById.get(lbtBlock.teleporterId());
List<LinkedBeaconTeleporter> lbtBlocks = linkedBeaconTeleporterById.get(lbtBlock.teleporterId());
// Remove from list
lbtBlocks.remove(lbtBlock);
@ -198,7 +197,7 @@ public class LinkedBeaconTeleporterManager {
return linkedBeaconTeleporterByLoc.get(serializedLoc);
}
public List<LinkedBeaconTeleporterBlock> getLbtBlocksFromTeleportId(String teleportId){
public List<LinkedBeaconTeleporter> getLbtBlocksFromTeleportId(String teleportId){
return linkedBeaconTeleporterById.get(teleportId);
}

@ -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<LinkedBeaconTeleporterBlock> 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)
);
}
}

Loading…
Cancel
Save