mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-03-01 15:51:06 +01:00
Global unlockScript, respawnScript & unlockCondition.
This commit is contained in:
parent
092ff0dd71
commit
b8b58a7686
@ -1,18 +1,30 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import io.lumine.mythic.lib.script.Script;
|
||||
import io.lumine.mythic.lib.script.condition.Condition;
|
||||
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.ConfigFile;
|
||||
import io.lumine.mythic.lib.util.configobject.ConfigSectionObject;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.spawnpoint.SpawnPoint;
|
||||
import net.Indyuce.mmocore.spawnpoint.def.DefaultSpawnOption;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import javax.swing.text.html.Option;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SpawnPointManager implements MMOCoreManager {
|
||||
|
||||
private Optional<Condition> globalUnlockCondition;
|
||||
private Optional<Skill> globalUnlockScript;
|
||||
private Optional<Skill> globalRespawnScript;
|
||||
|
||||
private final Map<String, SpawnPoint> spawnPoints = new HashMap<>();
|
||||
|
||||
private List<DefaultSpawnOption> defaultSpawnOptions = new ArrayList<>();
|
||||
@ -33,20 +45,60 @@ public class SpawnPointManager implements MMOCoreManager {
|
||||
@Override
|
||||
public void initialize(boolean clearBefore) {
|
||||
FileConfiguration config = new ConfigFile(MMOCore.plugin, "", "spawn-points").getConfig();
|
||||
Validate.isTrue(config.isConfigurationSection("spawn-points.default"), "You must specify a default spawn-point.");
|
||||
|
||||
if (config.isConfigurationSection("spawn-points"))
|
||||
for (String key : config.getConfigurationSection("spawn-points").getKeys(false)) {
|
||||
try{
|
||||
try {
|
||||
SpawnPoint spawnPoint = new SpawnPoint(config.getConfigurationSection("spawn-points." + key));
|
||||
spawnPoints.put(spawnPoint.getId(), spawnPoint);
|
||||
}catch (Exception e){
|
||||
MMOCore.log(Level.WARNING,"An error occured while loading spawnpoint " + key + ": " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
MMOCore.log(Level.WARNING, "An error occured while loading spawnpoint " + key + ": " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
for (String defaultSpawnOption : config.getStringList("default-spawn")) {
|
||||
defaultSpawnOptions.add(MMOCore.plugin.loadManager.loadDefaultSpawnOption(new MMOLineConfig(defaultSpawnOption)));
|
||||
}
|
||||
|
||||
|
||||
Skill globalUnlockScript = null;
|
||||
if (config.isConfigurationSection("global.unlock-script"))
|
||||
try {
|
||||
final Script script = MythicLib.plugin.getSkills().loadScript(config.getConfigurationSection("global.unlock-script"));
|
||||
globalUnlockScript = new SimpleSkill(TriggerType.CAST, new MythicLibSkillHandler(script));
|
||||
} catch (RuntimeException exception) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load unlock script: " + exception.getMessage());
|
||||
}
|
||||
this.globalUnlockScript = Optional.ofNullable(globalUnlockScript);
|
||||
|
||||
Skill globalRespawnScript = null;
|
||||
if (config.isConfigurationSection("global.respawn-script"))
|
||||
try {
|
||||
final Script script = MythicLib.plugin.getSkills().loadScript(config.getConfigurationSection("global.respawn-script"));
|
||||
globalRespawnScript = new SimpleSkill(TriggerType.CAST, new MythicLibSkillHandler(script));
|
||||
} catch (RuntimeException exception) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load respawn script: " + exception.getMessage());
|
||||
}
|
||||
this.globalRespawnScript = Optional.ofNullable(globalRespawnScript);
|
||||
|
||||
Condition globalUnlockCondition = null;
|
||||
if (config.isConfigurationSection("global.unlock-condition"))
|
||||
globalUnlockCondition = MythicLib.plugin.getSkills().loadCondition(new ConfigSectionObject(config.getConfigurationSection("global.unlock-condition")));
|
||||
this.globalUnlockCondition = Optional.ofNullable(globalUnlockCondition);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Optional<Condition> getUnlockCondition() {
|
||||
return globalUnlockCondition;
|
||||
}
|
||||
|
||||
public Optional<Skill> getUnlockScript() {
|
||||
return globalUnlockScript;
|
||||
}
|
||||
|
||||
public Optional<Skill> getRespawnScript() {
|
||||
return globalRespawnScript;
|
||||
}
|
||||
|
||||
public List<DefaultSpawnOption> getDefaultSpawnOptions() {
|
||||
|
@ -33,6 +33,8 @@ public class SpawnPoint implements Unlockable {
|
||||
private final Optional<Skill> unlockScript;
|
||||
private final Optional<Skill> respawnScript;
|
||||
|
||||
private final boolean overridesUnlockCondition, overridesRespawnScript, overridesUnlockScript;
|
||||
|
||||
public SpawnPoint(ConfigurationSection section) {
|
||||
id = section.getName();
|
||||
location = UtilityMethods.readLocation(new ConfigSectionObject(section.getConfigurationSection("location")));
|
||||
@ -41,22 +43,26 @@ public class SpawnPoint implements Unlockable {
|
||||
new ConfigSectionObject(section.getConfigurationSection("unlock-condition")));
|
||||
|
||||
strength = section.getDouble("strength", 1);
|
||||
overridesRespawnScript = section.getBoolean("override-respawn-script", false);
|
||||
overridesUnlockScript = section.getBoolean("override-unlock-script", false);
|
||||
overridesUnlockCondition = section.getBoolean("override-unlock-condition", false);
|
||||
Skill unlockScript = null;
|
||||
if (section.isConfigurationSection("unlock-script"))
|
||||
try {
|
||||
final Script script = MythicLib.plugin.getSkills().loadScript(section.getConfigurationSection("unlock-script"));
|
||||
unlockScript = new SimpleSkill(TriggerType.CAST, new MythicLibSkillHandler(script));
|
||||
} catch (RuntimeException exception) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load unlock script: " + exception.getMessage());
|
||||
MMOCore.log(Level.WARNING, "Could not load unlock script: " + exception.getMessage());
|
||||
}
|
||||
this.unlockScript = Optional.ofNullable(unlockScript);
|
||||
|
||||
Skill respawnScript = null;
|
||||
if (section.isConfigurationSection("respawn-script"))
|
||||
try {
|
||||
final Script script = MythicLib.plugin.getSkills().loadScript(section.getConfigurationSection("respawn-script"));
|
||||
respawnScript = new SimpleSkill(TriggerType.CAST, new MythicLibSkillHandler(script));
|
||||
} catch (RuntimeException exception) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load respawn script: " + exception.getMessage());
|
||||
MMOCore.log(Level.WARNING, "Could not load respawn script: " + exception.getMessage());
|
||||
}
|
||||
this.respawnScript = Optional.ofNullable(respawnScript);
|
||||
}
|
||||
@ -89,16 +95,24 @@ public class SpawnPoint implements Unlockable {
|
||||
|
||||
@Override
|
||||
public void whenUnlocked(PlayerData playerData) {
|
||||
PlayerMetadata caster = playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND);
|
||||
unlockScript.ifPresent(skill -> skill.cast(new TriggerMetadata(caster)));
|
||||
TriggerMetadata triggerMetadata = new TriggerMetadata(playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND));
|
||||
if (!overridesUnlockScript)
|
||||
MMOCore.plugin.spawnPointManager.getUnlockScript().ifPresent(skill -> skill.cast(triggerMetadata));
|
||||
unlockScript.ifPresent(skill -> skill.cast(triggerMetadata));
|
||||
}
|
||||
|
||||
public boolean matchesCondition(PlayerData playerData) {
|
||||
return unlockCondition.isMet(new SkillMetadata(null, playerData.getMMOPlayerData()));
|
||||
SkillMetadata metadata = new SkillMetadata(null, playerData.getMMOPlayerData());
|
||||
if (!overridesUnlockCondition && !MMOCore.plugin.spawnPointManager.getUnlockCondition()
|
||||
.map((condition) -> condition.isMet(metadata)).orElse(true))
|
||||
return false;
|
||||
return unlockCondition.isMet(metadata);
|
||||
}
|
||||
|
||||
public void whenRespawn(PlayerData playerData) {
|
||||
PlayerMetadata caster = playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND);
|
||||
respawnScript.ifPresent(skill -> skill.cast(new TriggerMetadata(caster)));
|
||||
TriggerMetadata triggerMetadata = new TriggerMetadata(playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND));
|
||||
if (!overridesRespawnScript)
|
||||
MMOCore.plugin.spawnPointManager.getRespawnScript().ifPresent(skill -> skill.cast(triggerMetadata));
|
||||
respawnScript.ifPresent(skill -> skill.cast(triggerMetadata));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user