Changed data.yml format and added save-method
This commit is contained in:
parent
b54af93d4b
commit
6c2e06afaf
@ -47,6 +47,8 @@ public class Main extends JavaPlugin {
|
|||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|
||||||
|
LinkedBeaconTeleporterManager.saveData();
|
||||||
|
|
||||||
log.info("Plugin deactivated");
|
log.info("Plugin deactivated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,4 +70,15 @@ public class Main extends JavaPlugin {
|
|||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void saveData() {
|
||||||
|
// data.yml
|
||||||
|
try{
|
||||||
|
File dataFile = new File("plugins/"+ plugin.getName() +"/data.yml");
|
||||||
|
data.save(dataFile);
|
||||||
|
}catch (Exception ex){
|
||||||
|
log.severe("Could not save data.yml!");
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.ShapelessRecipe;
|
import org.bukkit.inventory.ShapelessRecipe;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
@ -39,18 +39,17 @@ public class LinkedBeaconTeleporterManager {
|
|||||||
|
|
||||||
// Load teleporters
|
// Load teleporters
|
||||||
for(String teleporterId : Main.data.getKeys(false)){
|
for(String teleporterId : Main.data.getKeys(false)){
|
||||||
ConfigurationSection teleportersData = Main.data.getConfigurationSection(teleporterId);
|
List<String> serialisedLocs = Main.data.getStringList(teleporterId);
|
||||||
|
|
||||||
// New list for this id
|
// New list for this id
|
||||||
List<LinkedBeaconTeleporter> linkedBeaconTeleporters = new ArrayList();
|
List<LinkedBeaconTeleporter> linkedBeaconTeleporters = new ArrayList();
|
||||||
|
|
||||||
for(String serializedLoc : teleportersData.getKeys(false)) {
|
for(String serializedLoc : serialisedLocs) {
|
||||||
ConfigurationSection teleporterData = teleportersData.getConfigurationSection(serializedLoc);
|
|
||||||
|
|
||||||
// Load location
|
// Load location
|
||||||
Location loc;
|
Location loc;
|
||||||
try {
|
try {
|
||||||
loc = Function.deserializeBlockLocation(teleporterData.getString("loc"));
|
loc = Function.deserializeBlockLocation(serializedLoc);
|
||||||
} catch (InvalidPropertiesFormatException e) {
|
} catch (InvalidPropertiesFormatException e) {
|
||||||
Main.log.severe("Could not load location='"+ serializedLoc +"' from "+ teleporterId);
|
Main.log.severe("Could not load location='"+ serializedLoc +"' from "+ teleporterId);
|
||||||
continue;
|
continue;
|
||||||
@ -80,6 +79,31 @@ public class LinkedBeaconTeleporterManager {
|
|||||||
Main.log.info("All done!");
|
Main.log.info("All done!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void saveData(){
|
||||||
|
Main.log.info("Saving data..");
|
||||||
|
|
||||||
|
Main.data = new YamlConfiguration();
|
||||||
|
for(String teleporterId : placedLBTsById.keySet()){
|
||||||
|
List<LinkedBeaconTeleporter> LBTs = placedLBTsById.get(teleporterId);
|
||||||
|
|
||||||
|
// Generate clean array with data we want
|
||||||
|
List<String> dataList = new ArrayList<>();
|
||||||
|
for(LinkedBeaconTeleporter lbt : LBTs){
|
||||||
|
dataList.add(
|
||||||
|
Function.serialiseBlockLocation(
|
||||||
|
((LinkedBeaconTeleporterBlock)lbt).block().getLocation()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Main.data.set(teleporterId, dataList);
|
||||||
|
}
|
||||||
|
|
||||||
|
Main.saveData();
|
||||||
|
|
||||||
|
Main.log.info("done");
|
||||||
|
}
|
||||||
|
|
||||||
static void constructAndAddRecipes(){
|
static void constructAndAddRecipes(){
|
||||||
// Create result-item
|
// Create result-item
|
||||||
ItemStack item = getItemStackFromData("-");
|
ItemStack item = getItemStackFromData("-");
|
||||||
@ -160,7 +184,7 @@ public class LinkedBeaconTeleporterManager {
|
|||||||
return placedLBTsById.get(teleportId);
|
return placedLBTsById.get(teleportId);
|
||||||
}
|
}
|
||||||
|
|
||||||
String constructRegex(String name, List<String> lore){
|
static String constructRegex(String name, List<String> lore){
|
||||||
// Serialize
|
// Serialize
|
||||||
String regex = serialiseBeaconItem(name, lore);
|
String regex = serialiseBeaconItem(name, lore);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user