new scripting items

This commit is contained in:
Indyuce 2022-07-09 13:58:56 +02:00
parent add8b00609
commit 7efdf5b017
6 changed files with 87 additions and 3 deletions

View File

@ -48,6 +48,10 @@ import net.Indyuce.mmocore.party.PartyModule;
import net.Indyuce.mmocore.party.PartyModuleType; import net.Indyuce.mmocore.party.PartyModuleType;
import net.Indyuce.mmocore.party.provided.MMOCorePartyModule; import net.Indyuce.mmocore.party.provided.MMOCorePartyModule;
import net.Indyuce.mmocore.skill.cast.SkillCastingMode; import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
import net.Indyuce.mmocore.skill.custom.mechanic.ExperienceMechanic;
import net.Indyuce.mmocore.skill.custom.mechanic.ManaMechanic;
import net.Indyuce.mmocore.skill.custom.mechanic.StaminaMechanic;
import net.Indyuce.mmocore.skill.custom.mechanic.StelliumMechanic;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -117,6 +121,12 @@ public class MMOCore extends LuminePlugin {
MythicLib.plugin.getEntities().registerRestriction(new MMOCoreTargetRestriction()); MythicLib.plugin.getEntities().registerRestriction(new MMOCoreTargetRestriction());
MythicLib.plugin.getModifiers().registerModifierType("attribute", configObject -> new AttributeModifier(configObject)); MythicLib.plugin.getModifiers().registerModifierType("attribute", configObject -> new AttributeModifier(configObject));
// Skill creation
MythicLib.plugin.getSkills().registerMechanic("mana", config -> new ManaMechanic(config));
MythicLib.plugin.getSkills().registerMechanic("stamina", config -> new StaminaMechanic(config));
MythicLib.plugin.getSkills().registerMechanic("stellium", config -> new StelliumMechanic(config));
MythicLib.plugin.getSkills().registerMechanic("experience", config -> new ExperienceMechanic(config));
// Register extra objective, drop items... // Register extra objective, drop items...
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null)
loadManager.registerLoader(new WorldGuardMMOLoader()); loadManager.registerLoader(new WorldGuardMMOLoader());

View File

@ -0,0 +1,46 @@
package net.Indyuce.mmocore.skill.custom.mechanic;
import io.lumine.mythic.lib.skill.SkillMetadata;
import io.lumine.mythic.lib.skill.custom.mechanic.type.TargetMechanic;
import io.lumine.mythic.lib.util.DoubleFormula;
import io.lumine.mythic.lib.util.configobject.ConfigObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.SimpleExperienceObject;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import org.apache.commons.lang.Validate;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ExperienceMechanic extends TargetMechanic {
@NotNull
private final DoubleFormula amount;
@NotNull
private final EXPSource source;
@NotNull
private final ExperienceDispenser dispenser;
public ExperienceMechanic(ConfigObject config) {
super(config);
config.validateKeys("amount");
amount = config.getDoubleFormula("amount");
if (config.contains("profession")) {
String id = config.getString("profession").toLowerCase().replace("_", "-");
Validate.isTrue(MMOCore.plugin.professionManager.has(id), "Could not find profession");
dispenser = MMOCore.plugin.professionManager.get(id);
} else
dispenser = new SimpleExperienceObject();
source = config.contains("source") ? EXPSource.valueOf(config.getString("source").toUpperCase()) : EXPSource.QUEST;
}
@Override
public void cast(SkillMetadata meta, Entity target) {
Validate.isTrue(target instanceof Player, "Target is not a player");
PlayerData targetData = PlayerData.get(target.getUniqueId());
dispenser.giveExperience(targetData, amount.evaluate(meta), null, source);
}
}

View File

@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
public class ManaMechanic extends TargetMechanic { public class ManaMechanic extends TargetMechanic {
private final DoubleFormula amount; private final DoubleFormula amount;
private final Operation operation;
private final PlayerResourceUpdateEvent.UpdateReason reason; private final PlayerResourceUpdateEvent.UpdateReason reason;
public ManaMechanic(ConfigObject config) { public ManaMechanic(ConfigObject config) {
@ -22,12 +23,18 @@ public class ManaMechanic extends TargetMechanic {
amount = new DoubleFormula(config.getString("amount")); amount = new DoubleFormula(config.getString("amount"));
reason = PlayerResourceUpdateEvent.UpdateReason.valueOf(UtilityMethods.enumName(config.getString("reason", "CUSTOM"))); reason = PlayerResourceUpdateEvent.UpdateReason.valueOf(UtilityMethods.enumName(config.getString("reason", "CUSTOM")));
operation = config.contains("operation") ? Operation.valueOf(config.getString("operation").toUpperCase()) : Operation.GIVE;
} }
@Override @Override
public void cast(SkillMetadata meta, Entity target) { public void cast(SkillMetadata meta, Entity target) {
Validate.isTrue(target instanceof Player, "Target is not a player"); Validate.isTrue(target instanceof Player, "Target is not a player");
PlayerData targetData = PlayerData.get(target.getUniqueId()); PlayerData targetData = PlayerData.get(target.getUniqueId());
targetData.giveMana(amount.evaluate(meta), reason); if (operation == Operation.GIVE)
targetData.giveMana(amount.evaluate(meta), reason);
else if (operation == Operation.SET)
targetData.setMana(amount.evaluate(meta));
else if (operation == Operation.TAKE)
targetData.giveMana(-amount.evaluate(meta), reason);
} }
} }

View File

@ -0,0 +1,7 @@
package net.Indyuce.mmocore.skill.custom.mechanic;
public enum Operation {
GIVE,
SET,
TAKE
}

View File

@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
public class StaminaMechanic extends TargetMechanic { public class StaminaMechanic extends TargetMechanic {
private final DoubleFormula amount; private final DoubleFormula amount;
private final Operation operation;
private final PlayerResourceUpdateEvent.UpdateReason reason; private final PlayerResourceUpdateEvent.UpdateReason reason;
public StaminaMechanic(ConfigObject config) { public StaminaMechanic(ConfigObject config) {
@ -22,12 +23,18 @@ public class StaminaMechanic extends TargetMechanic {
amount = new DoubleFormula(config.getString("amount")); amount = new DoubleFormula(config.getString("amount"));
reason = PlayerResourceUpdateEvent.UpdateReason.valueOf(UtilityMethods.enumName(config.getString("reason", "CUSTOM"))); reason = PlayerResourceUpdateEvent.UpdateReason.valueOf(UtilityMethods.enumName(config.getString("reason", "CUSTOM")));
operation = config.contains("operation") ? Operation.valueOf(config.getString("operation").toUpperCase()) : Operation.GIVE;
} }
@Override @Override
public void cast(SkillMetadata meta, Entity target) { public void cast(SkillMetadata meta, Entity target) {
Validate.isTrue(target instanceof Player, "Target is not a player"); Validate.isTrue(target instanceof Player, "Target is not a player");
PlayerData targetData = PlayerData.get(target.getUniqueId()); PlayerData targetData = PlayerData.get(target.getUniqueId());
targetData.giveStamina(amount.evaluate(meta), reason); if (operation == Operation.GIVE)
targetData.giveStamina(amount.evaluate(meta), reason);
else if (operation == Operation.SET)
targetData.setStamina(amount.evaluate(meta));
else if (operation == Operation.TAKE)
targetData.giveStamina(-amount.evaluate(meta), reason);
} }
} }

View File

@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
public class StelliumMechanic extends TargetMechanic { public class StelliumMechanic extends TargetMechanic {
private final DoubleFormula amount; private final DoubleFormula amount;
private final Operation operation;
private final PlayerResourceUpdateEvent.UpdateReason reason; private final PlayerResourceUpdateEvent.UpdateReason reason;
public StelliumMechanic(ConfigObject config) { public StelliumMechanic(ConfigObject config) {
@ -22,12 +23,18 @@ public class StelliumMechanic extends TargetMechanic {
amount = new DoubleFormula(config.getString("amount")); amount = new DoubleFormula(config.getString("amount"));
reason = PlayerResourceUpdateEvent.UpdateReason.valueOf(UtilityMethods.enumName(config.getString("reason", "CUSTOM"))); reason = PlayerResourceUpdateEvent.UpdateReason.valueOf(UtilityMethods.enumName(config.getString("reason", "CUSTOM")));
operation = config.contains("operation") ? Operation.valueOf(config.getString("operation").toUpperCase()) : Operation.GIVE;
} }
@Override @Override
public void cast(SkillMetadata meta, Entity target) { public void cast(SkillMetadata meta, Entity target) {
Validate.isTrue(target instanceof Player, "Target is not a player"); Validate.isTrue(target instanceof Player, "Target is not a player");
PlayerData targetData = PlayerData.get(target.getUniqueId()); PlayerData targetData = PlayerData.get(target.getUniqueId());
targetData.giveStellium(amount.evaluate(meta), reason); if (operation == Operation.GIVE)
targetData.giveStellium(amount.evaluate(meta), reason);
else if (operation == Operation.SET)
targetData.setStellium(amount.evaluate(meta));
else if (operation == Operation.TAKE)
targetData.giveStellium(-amount.evaluate(meta), reason);
} }
} }