Added Manager for storing Data related to id and location
parent
16a46a6a35
commit
48f961fc9c
@ -0,0 +1,69 @@
|
||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter;
|
||||
|
||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Function;
|
||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
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, LinkedBeaconTeleporterBlock> linkedBeaconTeleporterByLoc = new HashMap();
|
||||
|
||||
public LinkedBeaconTeleporterManager(){
|
||||
Main.log.info("Loading LinkedBeaconTeleporter from config..");
|
||||
|
||||
// Load teleporters
|
||||
for(String teleporterId : Main.data.getKeys(false)){
|
||||
ConfigurationSection teleportersData = Main.data.getConfigurationSection(teleporterId);
|
||||
|
||||
// New list for this id
|
||||
ArrayList<LinkedBeaconTeleporterBlock> lbtBlocks = new ArrayList();
|
||||
|
||||
for(String blockId : teleportersData.getKeys(false)) {
|
||||
ConfigurationSection teleporterData = teleportersData.getConfigurationSection(blockId);
|
||||
|
||||
// Load location
|
||||
String serializedLoc = teleporterData.getString("loc");
|
||||
Location loc;
|
||||
try {
|
||||
loc = Function.deserializeBlockLocation(teleporterData.getString("loc"));
|
||||
} catch (InvalidPropertiesFormatException e) {
|
||||
Main.log.severe("Could not load location='"+ serializedLoc +"' from "+ teleporterId +" > "+ blockId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if block is of type Beacon (in case the world was changed without the plugin running)
|
||||
Block block = loc.getBlock();
|
||||
if(block.getType() != Material.BEACON){
|
||||
// Data out of sync! Skipping
|
||||
Main.log.warning(teleporterId +" > "+ blockId +" at location "+ serializedLoc +" changed and is no longer LinkedBlockTeleporter! (Changed without the plugin running?)");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Construct block
|
||||
LinkedBeaconTeleporterBlock lbtBlock = new LinkedBeaconTeleporterBlock(teleporterId, block);
|
||||
|
||||
// Add block to id-list
|
||||
lbtBlocks.add(lbtBlock);
|
||||
|
||||
// Save to loc-list
|
||||
linkedBeaconTeleporterByLoc.put(serializedLoc, lbtBlock);
|
||||
}
|
||||
|
||||
// Save list to id-list
|
||||
linkedBeaconTeleporterById.put(teleporterId, lbtBlocks);
|
||||
}
|
||||
|
||||
Main.log.info("All done!");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue