mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-25 19:55:22 +01:00
Updated data loading system to work with the new core update.
This commit is contained in:
parent
d2c79eefa5
commit
e818b99970
@ -121,7 +121,6 @@ public class UltimateKits extends SongodaPlugin {
|
||||
crateFile.load();
|
||||
checkKeyDefaults();
|
||||
checkCrateDefaults();
|
||||
loadKits();
|
||||
keyFile.saveChanges();
|
||||
crateFile.saveChanges();
|
||||
|
||||
@ -185,6 +184,118 @@ public class UltimateKits extends SongodaPlugin {
|
||||
particleHandler.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataLoad() {
|
||||
//Empty categories from manager.
|
||||
categoryManager.clearCategories();
|
||||
|
||||
/*
|
||||
* Register categories into CategoryManager from Configuration.
|
||||
*/
|
||||
if (categoryConfig.getConfigurationSection("Categories") != null)
|
||||
for (String key : categoryConfig.getConfigurationSection("Categories").getKeys(false)) {
|
||||
ConfigurationSection section = categoryConfig.getConfigurationSection("Categories." + key);
|
||||
if (section == null) continue;
|
||||
|
||||
Category category = categoryManager.addCategory(key, section.getString("name"));
|
||||
if (section.contains("material"))
|
||||
category.setMaterial(CompatibleMaterial.getMaterial(section.getString("material")).getMaterial());
|
||||
}
|
||||
|
||||
//Empty kits from manager.
|
||||
kitManager.clearKits();
|
||||
|
||||
/*
|
||||
* Register kits into KitManager from Configuration.
|
||||
*/
|
||||
if (kitConfig.getConfigurationSection("Kits") != null)
|
||||
for (String kitName : kitConfig.getConfigurationSection("Kits").getKeys(false)) {
|
||||
ConfigurationSection section = kitConfig.getConfigurationSection("Kits." + kitName);
|
||||
if (section == null) continue;
|
||||
|
||||
kitManager.addKit(new Kit(kitName)
|
||||
.setTitle(section.getString("title"))
|
||||
.setDelay(section.getLong("delay"))
|
||||
.setLink(section.getString("link"))
|
||||
.setDisplayItem(section.contains("displayItem")
|
||||
? CompatibleMaterial.getMaterial(section.getString("displayItem"), CompatibleMaterial.DIAMOND_HELMET)
|
||||
: null)
|
||||
.setCategory(categoryManager.getCategory(section.getString("category")))
|
||||
.setHidden(section.getBoolean("hidden"))
|
||||
.setPrice(section.getDouble("price"))
|
||||
.setContents(section.getStringList("items").stream().map(KitItem::new).collect(Collectors.toList()))
|
||||
.setKitAnimation(KitAnimation.valueOf(section.getString("animation", KitAnimation.NONE.name())))
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Register legacy kit locations into KitManager from Configuration.
|
||||
*/
|
||||
if (dataFile.contains("BlockData")) {
|
||||
for (String key : dataFile.getConfigurationSection("BlockData").getKeys(false)) {
|
||||
Location location = Methods.unserializeLocation(key);
|
||||
Kit kit = kitManager.getKit(dataFile.getString("BlockData." + key + ".kit"));
|
||||
KitType type = KitType.valueOf(dataFile.getString("BlockData." + key + ".type", "PREVIEW"));
|
||||
boolean holograms = dataFile.getBoolean("BlockData." + key + ".holograms");
|
||||
boolean displayItems = dataFile.getBoolean("BlockData." + key + ".displayItems");
|
||||
boolean particles = dataFile.getBoolean("BlockData." + key + ".particles");
|
||||
boolean itemOverride = dataFile.getBoolean("BlockData." + key + ".itemOverride");
|
||||
|
||||
if (kit == null) dataFile.set("BlockData." + key, null);
|
||||
else {
|
||||
updateHologram(kitManager.addKitToLocation(kit, location, type, holograms, particles, displayItems, itemOverride));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Register kit locations into KitManager from Configuration.
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskLater(this, () ->
|
||||
this.dataManager.getBlockData((blockData) -> {
|
||||
this.kitManager.setKitLocations(blockData);
|
||||
if (HologramManager.isEnabled()) {
|
||||
loadHolograms();
|
||||
}
|
||||
}), 20L);
|
||||
|
||||
//Apply default keys.
|
||||
checkKeyDefaults();
|
||||
checkCrateDefaults();
|
||||
|
||||
//Empty keys from manager.
|
||||
keyManager.clear();
|
||||
crateManager.clear();
|
||||
|
||||
/*
|
||||
* Register keys into KitManager from Configuration.
|
||||
*/
|
||||
if (keyFile.contains("Keys")) {
|
||||
for (String keyName : keyFile.getConfigurationSection("Keys").getKeys(false)) {
|
||||
int amt = keyFile.getInt("Keys." + keyName + ".Item Amount");
|
||||
int kitAmount = keyFile.getInt("Keys." + keyName + ".Amount of kit received");
|
||||
boolean enchanted = keyFile.getBoolean("Keys." + keyName + ".Enchanted");
|
||||
|
||||
Key key = new Key(keyName, amt, kitAmount, enchanted);
|
||||
keyManager.addKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Register Crates
|
||||
* */
|
||||
if (crateFile.contains("Crates")) {
|
||||
for (String crateName : crateFile.getConfigurationSection("Crates").getKeys(false)) {
|
||||
int amt = crateFile.getInt("Crates." + crateName + ".Item Amount");
|
||||
int kitAmount = crateFile.getInt("Crates." + crateName + ".Amount of kit received");
|
||||
|
||||
Crate crate = new Crate(crateName, amt, kitAmount);
|
||||
crateManager.addCrate(crate);
|
||||
}
|
||||
}
|
||||
this.loaded = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
saveKits(false);
|
||||
@ -208,122 +319,7 @@ public class UltimateKits extends SongodaPlugin {
|
||||
categoryConfig.load();
|
||||
keyFile.load();
|
||||
crateFile.load();
|
||||
loadKits();
|
||||
}
|
||||
|
||||
void loadKits() {
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||
|
||||
//Empty categories from manager.
|
||||
categoryManager.clearCategories();
|
||||
|
||||
/*
|
||||
* Register categories into CategoryManager from Configuration.
|
||||
*/
|
||||
if (categoryConfig.getConfigurationSection("Categories") != null)
|
||||
for (String key : categoryConfig.getConfigurationSection("Categories").getKeys(false)) {
|
||||
ConfigurationSection section = categoryConfig.getConfigurationSection("Categories." + key);
|
||||
if (section == null) continue;
|
||||
|
||||
Category category = categoryManager.addCategory(key, section.getString("name"));
|
||||
if (section.contains("material"))
|
||||
category.setMaterial(CompatibleMaterial.getMaterial(section.getString("material")).getMaterial());
|
||||
}
|
||||
|
||||
//Empty kits from manager.
|
||||
kitManager.clearKits();
|
||||
|
||||
/*
|
||||
* Register kits into KitManager from Configuration.
|
||||
*/
|
||||
if (kitConfig.getConfigurationSection("Kits") != null)
|
||||
for (String kitName : kitConfig.getConfigurationSection("Kits").getKeys(false)) {
|
||||
ConfigurationSection section = kitConfig.getConfigurationSection("Kits." + kitName);
|
||||
if (section == null) continue;
|
||||
|
||||
kitManager.addKit(new Kit(kitName)
|
||||
.setTitle(section.getString("title"))
|
||||
.setDelay(section.getLong("delay"))
|
||||
.setLink(section.getString("link"))
|
||||
.setDisplayItem(section.contains("displayItem")
|
||||
? CompatibleMaterial.getMaterial(section.getString("displayItem"), CompatibleMaterial.DIAMOND_HELMET)
|
||||
: null)
|
||||
.setCategory(categoryManager.getCategory(section.getString("category")))
|
||||
.setHidden(section.getBoolean("hidden"))
|
||||
.setPrice(section.getDouble("price"))
|
||||
.setContents(section.getStringList("items").stream().map(KitItem::new).collect(Collectors.toList()))
|
||||
.setKitAnimation(KitAnimation.valueOf(section.getString("animation", KitAnimation.NONE.name())))
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Register legacy kit locations into KitManager from Configuration.
|
||||
*/
|
||||
if (dataFile.contains("BlockData")) {
|
||||
for (String key : dataFile.getConfigurationSection("BlockData").getKeys(false)) {
|
||||
Location location = Methods.unserializeLocation(key);
|
||||
Kit kit = kitManager.getKit(dataFile.getString("BlockData." + key + ".kit"));
|
||||
KitType type = KitType.valueOf(dataFile.getString("BlockData." + key + ".type", "PREVIEW"));
|
||||
boolean holograms = dataFile.getBoolean("BlockData." + key + ".holograms");
|
||||
boolean displayItems = dataFile.getBoolean("BlockData." + key + ".displayItems");
|
||||
boolean particles = dataFile.getBoolean("BlockData." + key + ".particles");
|
||||
boolean itemOverride = dataFile.getBoolean("BlockData." + key + ".itemOverride");
|
||||
|
||||
if (kit == null) dataFile.set("BlockData." + key, null);
|
||||
else {
|
||||
updateHologram(kitManager.addKitToLocation(kit, location, type, holograms, particles, displayItems, itemOverride));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Register kit locations into KitManager from Configuration.
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskLater(this, () ->
|
||||
this.dataManager.getBlockData((blockData) -> {
|
||||
this.kitManager.setKitLocations(blockData);
|
||||
if (HologramManager.isEnabled()) {
|
||||
loadHolograms();
|
||||
}
|
||||
}), 20L);
|
||||
|
||||
//Apply default keys.
|
||||
checkKeyDefaults();
|
||||
checkCrateDefaults();
|
||||
|
||||
//Empty keys from manager.
|
||||
keyManager.clear();
|
||||
crateManager.clear();
|
||||
|
||||
/*
|
||||
* Register keys into KitManager from Configuration.
|
||||
*/
|
||||
if (keyFile.contains("Keys")) {
|
||||
for (String keyName : keyFile.getConfigurationSection("Keys").getKeys(false)) {
|
||||
int amt = keyFile.getInt("Keys." + keyName + ".Item Amount");
|
||||
int kitAmount = keyFile.getInt("Keys." + keyName + ".Amount of kit received");
|
||||
boolean enchanted = keyFile.getBoolean("Keys." + keyName + ".Enchanted");
|
||||
|
||||
Key key = new Key(keyName, amt, kitAmount, enchanted);
|
||||
keyManager.addKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Register Crates
|
||||
* */
|
||||
if (crateFile.contains("Crates")) {
|
||||
for (String crateName : crateFile.getConfigurationSection("Crates").getKeys(false)) {
|
||||
int amt = crateFile.getInt("Crates." + crateName + ".Item Amount");
|
||||
int kitAmount = crateFile.getInt("Crates." + crateName + ".Amount of kit received");
|
||||
|
||||
Crate crate = new Crate(crateName, amt, kitAmount);
|
||||
crateManager.addCrate(crate);
|
||||
}
|
||||
}
|
||||
this.loaded = true;
|
||||
|
||||
}, 10);
|
||||
onDataLoad();
|
||||
}
|
||||
|
||||
public void removeHologram(KitBlockData data) {
|
||||
|
Loading…
Reference in New Issue
Block a user