Removed use of deprecated API

This commit is contained in:
Jules 2024-05-24 20:02:56 -07:00
parent b150817964
commit 5c2bd9b637
13 changed files with 208 additions and 179 deletions

View File

@ -4,7 +4,6 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import io.lumine.mythic.lib.player.modifier.ModifierSource;
import io.lumine.mythic.lib.player.skill.PassiveSkill;
import io.lumine.mythic.lib.script.Script;
@ -12,6 +11,8 @@ import io.lumine.mythic.lib.skill.SimpleSkill;
import io.lumine.mythic.lib.skill.Skill;
import io.lumine.mythic.lib.skill.handler.MythicLibSkillHandler;
import io.lumine.mythic.lib.skill.trigger.TriggerType;
import io.lumine.mythic.lib.util.PostLoadAction;
import io.lumine.mythic.lib.util.PreloadedObject;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -37,7 +38,6 @@ import net.md_5.bungee.api.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -48,7 +48,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.logging.Level;
public class PlayerClass extends PostLoadObject implements ExperienceObject {
public class PlayerClass implements ExperienceObject, PreloadedObject {
private final String name, id, actionBarFormat;
private final List<String> description = new ArrayList<>(), attrDescription = new ArrayList<>();
private final ItemStack icon;
@ -81,8 +81,22 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
@Deprecated
private final Map<String, EventTrigger> eventTriggers = new HashMap<>();
private final PostLoadAction postLoadAction = new PostLoadAction(config -> {
if (config.contains("subclasses"))
for (String key : config.getConfigurationSection("subclasses").getKeys(false))
try {
subclasses.add(new Subclass(
MMOCore.plugin.classManager
.getOrThrow(key.toUpperCase().replace("-", "_").replace(" ", "_")),
config.getInt("subclasses." + key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load subclass '" + key + "' from class '"
+ getId() + "': " + exception.getMessage());
}
});
public PlayerClass(String id, FileConfiguration config) {
super(config);
postLoadAction.cacheConfig(config);
this.id = id.toUpperCase().replace("-", "_").replace(" ", "_");
@ -245,8 +259,6 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
* option was not provided.
*/
public PlayerClass(String id, String name, Material material) {
super(null);
this.id = id;
this.name = name;
manaDisplay = ManaDisplayOptions.DEFAULT;
@ -264,21 +276,6 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
resourceHandlers.put(resource, new ResourceRegeneration(resource));
}
@Override
protected void whenPostLoaded(ConfigurationSection config) {
if (config.contains("subclasses"))
for (String key : config.getConfigurationSection("subclasses").getKeys(false))
try {
subclasses.add(new Subclass(
MMOCore.plugin.classManager
.getOrThrow(key.toUpperCase().replace("-", "_").replace(" ", "_")),
config.getInt("subclasses." + key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load subclass '" + key + "' from class '"
+ getId() + "': " + exception.getMessage());
}
}
public String getId() {
return id;
}
@ -310,6 +307,12 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
return displayOrder;
}
@NotNull
@Override
public PostLoadAction getPostLoadAction() {
return postLoadAction;
}
@Override
public ExpCurve getExpCurve() {
return expCurve;

View File

@ -1,12 +1,8 @@
package net.Indyuce.mmocore.api.quest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.util.PostLoadAction;
import io.lumine.mythic.lib.util.PreloadedObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.objective.Objective;
@ -14,26 +10,32 @@ import net.Indyuce.mmocore.experience.Profession;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import java.util.*;
import java.util.logging.Level;
public class Quest extends PostLoadObject {
private final String id;
private final String name;
public class Quest implements PreloadedObject {
private final String id, name;
private final List<Quest> parents = new ArrayList<>();
private final List<Objective> objectives = new ArrayList<>();
private final List<String> lore;
private final int mainLevelRestriction;
private final Map<Profession, Integer> levelRestrictions = new HashMap<>();
// cooldown in millis
// Cooldown in millis
private final long cooldown;
private final PostLoadAction postLoadAction = new PostLoadAction(config -> {
// Load parent quests
if (config.contains("parent"))
for (String parent : config.getStringList("parent"))
parents.add(MMOCore.plugin.questManager.getOrThrow(parent.toLowerCase().replace(" ", "-").replace("_", "-")));
});
public Quest(String id, FileConfiguration config) {
super(config);
postLoadAction.cacheConfig(config);
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
cooldown = (long) (config.contains("delay") ? config.getDouble("delay") * 60 * 60 * 1000 : -1);
@ -69,11 +71,10 @@ public class Quest extends PostLoadObject {
}
}
@NotNull
@Override
protected void whenPostLoaded(ConfigurationSection config) {
if (config.contains("parent"))
for (String parent : config.getStringList("parent"))
parents.add(MMOCore.plugin.questManager.getOrThrow(parent.toLowerCase().replace(" ", "-").replace("_", "-")));
public PostLoadAction getPostLoadAction() {
return postLoadAction;
}
public String getId() {

View File

@ -1,14 +1,14 @@
package net.Indyuce.mmocore.experience;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import io.lumine.mythic.lib.util.PostLoadAction;
import io.lumine.mythic.lib.util.PreloadedObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -18,7 +18,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
public class Profession extends PostLoadObject implements ExperienceObject {
public class Profession implements ExperienceObject, PreloadedObject {
private final String id, name;
private final int maxLevel;
private final Map<ProfessionOption, Boolean> options = new HashMap<>();
@ -31,8 +31,14 @@ public class Profession extends PostLoadObject implements ExperienceObject {
*/
private final LinearValue experience;
private final PostLoadAction postLoadAction = new PostLoadAction(config -> {
// Link profession to hardcoded profession manager
MMOCore.plugin.professionManager.loadProfessionConfigurations(this, config);
});
public Profession(String id, FileConfiguration config) {
super(config);
postLoadAction.cacheConfig(config);
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.name = config.getString("name");
@ -74,9 +80,10 @@ public class Profession extends PostLoadObject implements ExperienceObject {
}
}
@NotNull
@Override
protected void whenPostLoaded(ConfigurationSection configurationSection) {
MMOCore.plugin.professionManager.loadProfessionConfigurations(this, configurationSection);
public PostLoadAction getPostLoadAction() {
return postLoadAction;
}
public boolean getOption(ProfessionOption option) {

View File

@ -1,99 +1,104 @@
package net.Indyuce.mmocore.loot.droptable;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.util.PostLoadAction;
import io.lumine.mythic.lib.util.PreloadedObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.loot.LootBuilder;
import net.Indyuce.mmocore.loot.chest.condition.Condition;
import net.Indyuce.mmocore.loot.chest.condition.ConditionInstance;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.loot.chest.condition.Condition;
import net.Indyuce.mmocore.loot.chest.condition.ConditionInstance;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.ArmorStand;
import org.bukkit.inventory.ItemStack;
public class DropTable implements PreloadedObject {
private final String id;
private final Set<DropItem> drops = new LinkedHashSet<>();
private final Set<Condition> conditions = new LinkedHashSet<>();
import net.Indyuce.mmocore.loot.LootBuilder;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.util.PostLoadObject;
private final PostLoadAction postLoadAction;
public class DropTable extends PostLoadObject {
private final String id;
private final Set<DropItem> drops = new LinkedHashSet<>();
private final Set<Condition> conditions = new LinkedHashSet<>();
public DropTable(ConfigurationSection config) {
this.postLoadAction = generatePostLoadAction();
this.postLoadAction.cacheConfig(config);
public DropTable(ConfigurationSection config) {
super(config);
this.id = config.getName();
}
id = config.getName();
}
public DropTable(String id) {
this.postLoadAction = generatePostLoadAction();
this.id = id;
}
public DropTable(String id) {
super(null);
ArmorStand armorStand;
this.id = id;
}
private PostLoadAction generatePostLoadAction() {
return new PostLoadAction(config -> {
List<String> itemsList = config.getStringList("items");
List<String> conditionsList = config.getStringList("conditions");
Validate.notNull(itemsList, "Could not find drop item list");
/*
* must be loaded after since drop tables must be initialized first
* otherwise no reference for drop table drop items.
*/
@Override
protected void whenPostLoaded(ConfigurationSection config) {
List<String> itemsList = config.getStringList("items");
List<String> conditionsList = config.getStringList("conditions");
Validate.notNull(itemsList, "Could not find drop item list");
for (String key : itemsList)
try {
drops.add(MMOCore.plugin.loadManager.loadDropItem(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load drop item '" + key + "' from table '" + id + "': " + exception.getMessage());
}
for (String key : conditionsList)
try {
conditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load condition '" + key + "' from table '" + id + "': " + exception.getMessage());
}
});
}
for (String key : itemsList)
try {
drops.add(MMOCore.plugin.loadManager.loadDropItem(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load drop item '" + key + "' from table '" + id + "': " + exception.getMessage());
}
for (String key : conditionsList)
try {
conditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load condition '" + key + "' from table '" + id + "': " + exception.getMessage());
}
}
@NotNull
@Override
public PostLoadAction getPostLoadAction() {
return postLoadAction;
}
public String getId() {
return id;
}
public String getId() {
return id;
}
public void registerDropItem(DropItem item) {
Validate.notNull(item);
public void registerDropItem(DropItem item) {
Validate.notNull(item);
drops.add(item);
}
drops.add(item);
}
public Set<DropItem> getDrops() {
return drops;
}
public Set<DropItem> getDrops() {
return drops;
}
public List<ItemStack> collect(LootBuilder builder) {
public List<ItemStack> collect(LootBuilder builder) {
for (DropItem item : drops)
if (item.rollChance(builder.getEntity()) && builder.getCapacity() >= item.getWeight()) {
item.collect(builder);
builder.reduceCapacity(item.getWeight());
}
for (DropItem item : drops)
if (item.rollChance(builder.getEntity()) && builder.getCapacity() >= item.getWeight()) {
item.collect(builder);
builder.reduceCapacity(item.getWeight());
}
return builder.getLoot();
}
return builder.getLoot();
}
public Set<Condition> getConditions() {
return conditions;
}
public Set<Condition> getConditions() {
return conditions;
}
public boolean areConditionsMet(ConditionInstance entity) {
for (Condition condition : conditions)
if (!condition.isMet(entity))
return false;
return true;
}
public boolean areConditionsMet(ConditionInstance entity) {
for (Condition condition : conditions)
if (!condition.isMet(entity))
return false;
return true;
}
}

View File

@ -93,7 +93,7 @@ public class ClassManager implements MMOCoreManager {
for (PlayerClass profess : map.values())
try {
profess.postLoad();
profess.getPostLoadAction().performAction();
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not post-load class '" + profess.getId() + "': " + exception.getMessage());
}

View File

@ -1,5 +1,12 @@
package net.Indyuce.mmocore.manager;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.loot.droptable.DropTable;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
@ -7,15 +14,6 @@ import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import net.Indyuce.mmocore.MMOCore;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import net.Indyuce.mmocore.loot.droptable.DropTable;
public class DropTableManager implements MMOCoreManager {
private final Map<String, DropTable> map = new HashMap<>();
@ -51,7 +49,7 @@ public class DropTableManager implements MMOCoreManager {
if (obj instanceof ConfigurationSection) {
DropTable table = new DropTable((ConfigurationSection) obj);
Bukkit.getScheduler().runTask(MMOCore.plugin, table::postLoad);
Bukkit.getScheduler().runTask(MMOCore.plugin, table.getPostLoadAction()::performAction);
return table;
}
@ -78,6 +76,6 @@ public class DropTableManager implements MMOCoreManager {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load drop table file '" + file.getName() + "': " + exception.getMessage());
}
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> map.values().forEach(PostLoadObject::postLoad));
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> map.values().forEach(table -> table.getPostLoadAction().performAction()));
}
}

View File

@ -51,7 +51,7 @@ public class QuestManager implements MMOCoreManager {
load(new File(MMOCore.plugin.getDataFolder() + "/quests"));
for (Quest quest : quests.values())
try {
quest.postLoad();
quest.getPostLoadAction().performAction();
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not post-load quest '" + quest.getId() + "': " + exception.getMessage());
}

View File

@ -3,14 +3,16 @@ package net.Indyuce.mmocore.manager;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.itemtype.ItemType;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import io.lumine.mythic.lib.util.PostLoadAction;
import io.lumine.mythic.lib.util.PreloadedObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.block.BlockType;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.block.BlockType;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@ -49,7 +51,7 @@ public class RestrictionManager implements MMOCoreManager {
for (ToolPermissions perms : map.values())
try {
perms.postLoad();
perms.getPostLoadAction().performAction();
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "Could not post-load perm set '" + perms.getTool().display() + "': " + exception.getMessage());
}
@ -88,7 +90,7 @@ public class RestrictionManager implements MMOCoreManager {
return perms != null && perms.canMine(block);
}
public class ToolPermissions extends PostLoadObject {
public class ToolPermissions implements PreloadedObject {
/**
* Now saving string keys using {@link BlockType#generateKey()} instead
@ -102,15 +104,8 @@ public class RestrictionManager implements MMOCoreManager {
private ToolPermissions parent;
public ToolPermissions(ConfigurationSection config) {
super(config);
private final PostLoadAction postLoadAction = new PostLoadAction(config -> {
tool = ItemType.fromString(config.getName());
defaultSet = config.getBoolean("default");
}
@Override
protected void whenPostLoaded(ConfigurationSection config) {
if (config.contains("parent")) {
String parentFormat = formatId(config.getString("parent"));
parent = Objects.requireNonNull(map.get(parentFormat), "Could not find parent with ID '" + parentFormat + "'");
@ -118,6 +113,19 @@ public class RestrictionManager implements MMOCoreManager {
if (config.contains("can-mine"))
for (String key : config.getStringList("can-mine"))
mineable.add(MMOCore.plugin.loadManager.loadBlockType(new MMOLineConfig(key)).generateKey());
});
public ToolPermissions(ConfigurationSection config) {
postLoadAction.cacheConfig(config);
tool = ItemType.fromString(config.getName());
defaultSet = config.getBoolean("default");
}
@NotNull
@Override
public PostLoadAction getPostLoadAction() {
return postLoadAction;
}
/**

View File

@ -59,7 +59,7 @@ public class WaypointManager implements MMOCoreManager {
for (Waypoint waypoint : waypoints.values())
try {
waypoint.postLoad();
waypoint.getPostLoadAction().performAction();
} catch (RuntimeException exception) {
MMOCore.log(Level.WARNING, "Could not post-load waypoint '" + waypoint.getId() + "': " + exception.getMessage());
}

View File

@ -81,7 +81,7 @@ public class ProfessionManager implements MMOCoreManager {
// Load profession-specific configurations
for (Profession profession : professions.values())
try {
profession.postLoad();
profession.getPostLoadAction().performAction();
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not postload profession " + profession.getId() + ": " + exception.getMessage());
}

View File

@ -1,21 +1,14 @@
package net.Indyuce.mmocore.skilltree.tree;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.util.PostLoadAction;
import net.Indyuce.mmocore.skilltree.ParentType;
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
public class CustomSkillTree extends SkillTree {
public CustomSkillTree(ConfigurationSection config) {
super(config);
// Setup the coordinate map because coordinates are given in the yml for linked skill tree
super.coordinatesSetup();
}
@Override
protected void whenPostLoaded(@NotNull ConfigurationSection config) {
private final PostLoadAction postLoadAction = new PostLoadAction(config -> {
// Setup the children and parents for each node.
for (SkillTreeNode node : nodes.values()) {
@ -31,6 +24,15 @@ public class CustomSkillTree extends SkillTree {
}
}
setupRoots();
});
public CustomSkillTree(ConfigurationSection config) {
super(config);
postLoadAction.cacheConfig(config);
// Setup the coordinate map because coordinates are given in the yml for linked skill tree
super.coordinatesSetup();
}
private void setupRoots() {
@ -44,4 +46,10 @@ public class CustomSkillTree extends SkillTree {
}
}
}
@NotNull
@Override
public PostLoadAction getPostLoadAction() {
return postLoadAction;
}
}

View File

@ -2,7 +2,6 @@ package net.Indyuce.mmocore.skilltree.tree;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import io.lumine.mythic.lib.util.PreloadedObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -33,7 +32,7 @@ import java.util.*;
* @author Ka0rX
* @see {@link SkillTreeNode}
*/
public abstract class SkillTree extends PostLoadObject implements RegisteredObject, PreloadedObject {
public abstract class SkillTree implements RegisteredObject, PreloadedObject {
private final String id, name;
private final List<String> lore = new ArrayList<>();
private final Material item;
@ -58,10 +57,7 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
protected final Map<DisplayInfo, Icon> icons = new HashMap<>();
public SkillTree(ConfigurationSection config) {
super(config);
this.id = Objects.requireNonNull(config.getString("id"), "Could not find skill tree id");
this.name = MythicLib.plugin.parseColors(Objects.requireNonNull(config.getString("name"), "Could not find skill tree name"));
Objects.requireNonNull(config.getStringList("lore"), "Could not find skill tree lore").forEach(str -> lore.add(MythicLib.plugin.parseColors(str)));
@ -124,9 +120,6 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
}
}
@Override
protected abstract void whenPostLoaded(@NotNull ConfigurationSection configurationSection);
public List<String> getLore() {
return lore;
}
@ -144,7 +137,7 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
try {
skillTree = new CustomSkillTree(config);
skillTree.postLoad();
skillTree.getPostLoadAction().performAction();
} catch (Exception e) {
MMOCore.log("Couldn't load skill tree " + config.getString("id") + ": " + e.getMessage());
}

View File

@ -1,12 +1,13 @@
package net.Indyuce.mmocore.waypoint;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import io.lumine.mythic.lib.util.PostLoadAction;
import io.lumine.mythic.lib.util.PreloadedObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.player.Unlockable;
import net.Indyuce.mmocore.loot.chest.condition.Condition;
import net.Indyuce.mmocore.loot.chest.condition.ConditionInstance;
import net.Indyuce.mmocore.player.Unlockable;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -19,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.logging.Level;
public class Waypoint extends PostLoadObject implements Unlockable {
public class Waypoint implements Unlockable, PreloadedObject {
private final String id, name;
private final Location loc;
private final List<String> lore;
@ -41,8 +42,18 @@ public class Waypoint extends PostLoadObject implements Unlockable {
private final double dynamicCost, setSpawnCost, normalCost;
private final List<Condition> dynamicUseConditions = new ArrayList<>();
private final PostLoadAction postLoadAction = new PostLoadAction(config -> {
// Load waypoint network
if (config.contains("linked")) {
ConfigurationSection section = config.getConfigurationSection("linked");
for (String key : section.getKeys(false))
destinations.put(MMOCore.plugin.waypointManager.get(key), section.getDouble(key));
}
});
public Waypoint(ConfigurationSection config) {
super(config);
postLoadAction.cacheConfig(config);
id = Objects.requireNonNull(config, "Could not load config section").getName();
name = Objects.requireNonNull(config.getString("name"), "Could not load waypoint name");
@ -70,15 +81,10 @@ public class Waypoint extends PostLoadObject implements Unlockable {
}
}
@NotNull
@Override
protected void whenPostLoaded(@NotNull ConfigurationSection config) {
// Load waypoint network
if (config.contains("linked")) {
ConfigurationSection section = config.getConfigurationSection("linked");
for (String key : section.getKeys(false))
destinations.put(MMOCore.plugin.waypointManager.get(key), section.getDouble(key));
}
public PostLoadAction getPostLoadAction() {
return postLoadAction;
}
public String getId() {