|
|
|
@ -19,9 +19,18 @@ public class LinkedBeaconTeleporterManager {
|
|
|
|
|
HashMap<String, List<LinkedBeaconTeleporterBlock>> linkedBeaconTeleporterById = new HashMap();
|
|
|
|
|
HashMap<String, LinkedBeaconTeleporterBlock> linkedBeaconTeleporterByLoc = new HashMap();
|
|
|
|
|
|
|
|
|
|
// Regex to match item-name&lore and extract id (group 1)
|
|
|
|
|
String regex;
|
|
|
|
|
|
|
|
|
|
public LinkedBeaconTeleporterManager(){
|
|
|
|
|
Main.log.info("Loading LinkedBeaconTeleporter from config..");
|
|
|
|
|
|
|
|
|
|
// Construct search item-regex
|
|
|
|
|
regex = constructRegex(
|
|
|
|
|
Main.config.getString("item.name"),
|
|
|
|
|
Main.config.getStringList("item.lore")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Load teleporters
|
|
|
|
|
for(String teleporterId : Main.data.getKeys(false)){
|
|
|
|
|
ConfigurationSection teleportersData = Main.data.getConfigurationSection(teleporterId);
|
|
|
|
@ -66,4 +75,71 @@ public class LinkedBeaconTeleporterManager {
|
|
|
|
|
|
|
|
|
|
Main.log.info("All done!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Conversion-methods
|
|
|
|
|
public ItemStack getItemStackFromLbtItem(LinkedBeaconTeleporterItem lbtItem){
|
|
|
|
|
ItemStack item = new ItemStack(Material.BEACON);
|
|
|
|
|
ItemMeta itemMeta = item.getItemMeta();
|
|
|
|
|
|
|
|
|
|
// Get config-values
|
|
|
|
|
String name = Main.config.getString("item.name");
|
|
|
|
|
List<String> lore = Main.config.getStringList("item.lore");
|
|
|
|
|
|
|
|
|
|
// Replace parameters
|
|
|
|
|
name = name.replace("%id%", lbtItem.teleporterId);
|
|
|
|
|
for(int i=0; i<lore.size(); i++){
|
|
|
|
|
lore.set(i,
|
|
|
|
|
lore.get(i).replace("%id%", lbtItem.teleporterId)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set meta
|
|
|
|
|
itemMeta.setDisplayName(name);
|
|
|
|
|
itemMeta.setLore(lore);
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
public LinkedBeaconTeleporterItem getLbtItemFromItemStack(ItemStack itemStack){
|
|
|
|
|
// Serialize
|
|
|
|
|
String nameAndLore = serialiseBeaconItem(
|
|
|
|
|
itemStack.getI18NDisplayName(),
|
|
|
|
|
itemStack.getLore()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Regex match
|
|
|
|
|
Pattern pattern = Pattern.compile(regex);
|
|
|
|
|
Matcher matcher = pattern.matcher(nameAndLore);
|
|
|
|
|
if(!matcher.find())
|
|
|
|
|
// No data
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
LinkedBeaconTeleporterItem lbtItem = new LinkedBeaconTeleporterItem(
|
|
|
|
|
matcher.group(1),
|
|
|
|
|
itemStack
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return lbtItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String constructRegex(String name, List<String> lore){
|
|
|
|
|
// Serialize
|
|
|
|
|
String regex = serialiseBeaconItem(name, lore);
|
|
|
|
|
|
|
|
|
|
// Wrap in regex-quotes
|
|
|
|
|
regex = "\\Q"+ regex +"\\E";
|
|
|
|
|
// Exclude id from regex-quotes and create group
|
|
|
|
|
regex = regex.replace("%id%", "\\E(.*)\\Q");
|
|
|
|
|
|
|
|
|
|
return regex;
|
|
|
|
|
}
|
|
|
|
|
String serialiseBeaconItem(String name, List<String> lore){
|
|
|
|
|
// get name and remove control-chars
|
|
|
|
|
String str = name.replace("\\", "\\\\");
|
|
|
|
|
for (String loreLine : lore) {
|
|
|
|
|
// get lore-lines and remove control-chars
|
|
|
|
|
str += "\n"+ loreLine.replace("\\", "\\\\");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|