mmocore 1.8.0 second release

This commit is contained in:
Indyuce 2021-08-26 12:53:21 +02:00
parent 8f99eedb1b
commit 87331e11ff
7 changed files with 91 additions and 56 deletions

View File

@ -1,43 +1,48 @@
package net.Indyuce.mmocore.api; package net.Indyuce.mmocore.api;
import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmocore.MMOCore;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.MMOCore;
import io.lumine.mythic.lib.MythicLib;
public class ConfigMessage { public class ConfigMessage {
private final List<String> messages; private final List<String> messages;
public ConfigMessage(String key) { public ConfigMessage(String key) {
messages = MMOCore.plugin.configManager.getMessage(key); messages = MMOCore.plugin.configManager.getMessage(key);
} }
public ConfigMessage addPlaceholders(String... placeholders) { public ConfigMessage addPlaceholders(String... placeholders) {
for (int n = 0; n < messages.size(); n++) { for (int n = 0; n < messages.size(); n++) {
String line = messages.get(n); String line = messages.get(n);
for (int j = 0; j < placeholders.length - 1; j += 2) { for (int j = 0; j < placeholders.length - 1; j += 2) {
String placeholder = placeholders[j]; String placeholder = placeholders[j];
if (line.contains("{" + placeholder + "}")) if (line.contains("{" + placeholder + "}"))
line = line.replace("{" + placeholder + "}", placeholders[j + 1]); line = line.replace("{" + placeholder + "}", placeholders[j + 1]);
} }
messages.set(n, line); messages.set(n, line);
} }
return this; return this;
} }
public void send(CommandSender sender) { public void send(CommandSender sender) {
messages.forEach(line -> sender.sendMessage(MythicLib.plugin.parseColors(line))); messages.forEach(line -> sender.sendMessage(format(sender, line)));
} }
public void send(Collection<? extends Player> players) { public void send(Collection<? extends Player> players) {
players.forEach(player -> messages.forEach(line -> player.sendMessage(MMOCore.plugin.placeholderParser.parse(player, line)))); players.forEach(player -> messages.forEach(line -> player.sendMessage(format(player, line))));
} }
public void sendAsJSon(Player player) { public void sendAsJSon(Player player) {
messages.forEach(line -> MythicLib.plugin.getVersion().getWrapper().sendJson(player, MythicLib.plugin.parseColors(line))); messages.forEach(line -> MythicLib.plugin.getVersion().getWrapper().sendJson(player, format(player, line)));
} }
private String format(CommandSender sender, String input) {
String str = MythicLib.plugin.parseColors(input);
return sender instanceof Player ? MMOCore.plugin.placeholderParser.parse((OfflinePlayer) sender, str) : str;
}
} }

View File

@ -1,6 +1,8 @@
package net.Indyuce.mmocore.api.player; package net.Indyuce.mmocore.api.player;
import io.lumine.mythic.lib.api.player.MMOPlayerData; import io.lumine.mythic.lib.api.player.MMOPlayerData;
import io.lumine.mythic.lib.player.CooldownInfo;
import io.lumine.mythic.lib.player.CooldownMap;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage; import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.Waypoint; import net.Indyuce.mmocore.api.Waypoint;
@ -24,7 +26,6 @@ import net.Indyuce.mmocore.experience.PlayerProfessions;
import net.Indyuce.mmocore.listener.SpellCast.SkillCasting; import net.Indyuce.mmocore.listener.SpellCast.SkillCasting;
import net.Indyuce.mmocore.manager.SoundManager; import net.Indyuce.mmocore.manager.SoundManager;
import net.Indyuce.mmocore.skill.CasterMetadata; import net.Indyuce.mmocore.skill.CasterMetadata;
import net.Indyuce.mmocore.skill.PlayerSkillData;
import net.Indyuce.mmocore.skill.Skill; import net.Indyuce.mmocore.skill.Skill;
import net.Indyuce.mmocore.skill.Skill.SkillInfo; import net.Indyuce.mmocore.skill.Skill.SkillInfo;
import net.Indyuce.mmocore.skill.metadata.SkillMetadata; import net.Indyuce.mmocore.skill.metadata.SkillMetadata;
@ -71,7 +72,6 @@ public class PlayerData extends OfflinePlayerData {
private final Map<String, Integer> skills = new HashMap<>(); private final Map<String, Integer> skills = new HashMap<>();
private final List<SkillInfo> boundSkills = new ArrayList<>(); private final List<SkillInfo> boundSkills = new ArrayList<>();
private final PlayerProfessions collectSkills = new PlayerProfessions(this); private final PlayerProfessions collectSkills = new PlayerProfessions(this);
private final PlayerSkillData skillData = new PlayerSkillData(this);
private final PlayerAttributes attributes = new PlayerAttributes(this); private final PlayerAttributes attributes = new PlayerAttributes(this);
private final Map<String, SavedClassInformation> classSlots = new HashMap<>(); private final Map<String, SavedClassInformation> classSlots = new HashMap<>();
@ -744,8 +744,8 @@ public class PlayerData extends OfflinePlayerData {
setAttributeReallocationPoints(attributeReallocationPoints + value); setAttributeReallocationPoints(attributeReallocationPoints + value);
} }
public PlayerSkillData getSkillData() { public CooldownMap getCooldownMap() {
return skillData; return mmoData.getCooldownMap();
} }
public void setClass(PlayerClass profess) { public void setClass(PlayerClass profess) {
@ -850,10 +850,12 @@ public class PlayerData extends OfflinePlayerData {
// Apply cooldown, mana and stamina costs // Apply cooldown, mana and stamina costs
if (!noCooldown) { if (!noCooldown) {
double flatCooldownReduction = Math.max(0, Math.min(1, getStats().getStat(StatType.COOLDOWN_REDUCTION) / 100));
flatCooldownReduction *= flatCooldownReduction > 0 ? skill.getModifier("cooldown", getSkillLevel(skill.getSkill())) * 1000 : 0;
skillData.setLastCast(cast.getSkill(), System.currentTimeMillis() - (long) flatCooldownReduction); // Cooldown
double flatCooldownReduction = Math.max(0, Math.min(1, getStats().getStat(StatType.COOLDOWN_REDUCTION) / 100));
CooldownInfo cooldownHandler = getCooldownMap().applyCooldown(cast.getSkill(), cast.getCooldown());
cooldownHandler.reduceInitialCooldown(flatCooldownReduction);
giveMana(-cast.getManaCost(), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST); giveMana(-cast.getManaCost(), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
giveStamina(-cast.getStaminaCost(), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST); giveStamina(-cast.getStaminaCost(), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
} }

View File

@ -4,7 +4,10 @@ import io.lumine.xikage.mythicmobs.MythicMobs;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicDropLoadEvent; import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicDropLoadEvent;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicReloadedEvent; import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicReloadedEvent;
import io.lumine.xikage.mythicmobs.skills.placeholders.Placeholder; import io.lumine.xikage.mythicmobs.skills.placeholders.Placeholder;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
import net.Indyuce.mmocore.comp.mythicmobs.load.CurrencyItemDrop; import net.Indyuce.mmocore.comp.mythicmobs.load.CurrencyItemDrop;
import net.Indyuce.mmocore.comp.mythicmobs.load.GoldPouchDrop; import net.Indyuce.mmocore.comp.mythicmobs.load.GoldPouchDrop;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -38,7 +41,24 @@ public class MythicHook implements Listener {
} }
private void registerPlaceholders() { private void registerPlaceholders() {
MythicMobs.inst().getPlaceholderManager().register("mana", Placeholder.meta((metadata, arg) -> String.valueOf((int) PlayerData.get(metadata.getCaster().getEntity().getUniqueId()).getMana())));
MythicMobs.inst().getPlaceholderManager().register("stamina", Placeholder.meta((metadata, arg) -> String.valueOf((int) PlayerData.get(metadata.getCaster().getEntity().getUniqueId()).getStamina()))); // Resource
MythicMobs.inst().getPlaceholderManager().register("mana", Placeholder.meta((metadata, arg) -> {
return String.valueOf((int) PlayerData.get(metadata.getCaster().getEntity().getUniqueId()).getMana());
}));
MythicMobs.inst().getPlaceholderManager().register("stamina", Placeholder.meta((metadata, arg) -> {
return String.valueOf((int) PlayerData.get(metadata.getCaster().getEntity().getUniqueId()).getStamina());
}));
MythicMobs.inst().getPlaceholderManager().register("stellium", Placeholder.meta((metadata, arg) -> {
return String.valueOf((int) PlayerData.get(metadata.getCaster().getEntity().getUniqueId()).getStellium());
}));
// Attributes
MythicMobs.inst().getPlaceholderManager().register("attribute", Placeholder.meta((metadata, arg) -> {
PlayerAttributes attributes = PlayerData.get(metadata.getCaster().getEntity().getUniqueId()).getAttributes();
PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(arg);
return String.valueOf(attributes.getAttribute(attribute));
}));
} }
} }

View File

@ -98,7 +98,7 @@ public class MythicSkill extends Skill {
MMOCore.plugin.antiCheatSupport.disableAntiCheat(caster.getPlayer(), antiCheat); MMOCore.plugin.antiCheatSupport.disableAntiCheat(caster.getPlayer(), antiCheat);
// Place cast skill info in a variable // Place cast skill info in a variable
skillMeta.getVariables().putObject("MMOCoreSkill", cast); skillMeta.getVariables().putObject("MMOSkill", cast);
skillMeta.getVariables().putObject("MMOStatMap", caster.getStats()); skillMeta.getVariables().putObject("MMOStatMap", caster.getStats());
// Yo is that me or the second argument is f***ing useless // Yo is that me or the second argument is f***ing useless

View File

@ -125,7 +125,7 @@ public class SpellCast implements Listener {
for (int j = 0; j < data.getBoundSkills().size(); j++) { for (int j = 0; j < data.getBoundSkills().size(); j++) {
SkillInfo skill = data.getBoundSkill(j); SkillInfo skill = data.getBoundSkill(j);
str.append((str.length() == 0) ? "" : split).append((onCooldown(data, skill) str.append((str.length() == 0) ? "" : split).append((onCooldown(data, skill)
? onCooldown.replace("{cooldown}", "" + data.getSkillData().getCooldown(skill) / 1000) ? onCooldown.replace("{cooldown}", String.valueOf(data.getCooldownMap().getInfo(skill.getSkill()).getRemaining() / 1000))
: noMana(data, skill) ? noMana : ready).replace("{index}", "" + (j + 1 + (data.getPlayer().getInventory().getHeldItemSlot() : noMana(data, skill) ? noMana : ready).replace("{index}", "" + (j + 1 + (data.getPlayer().getInventory().getHeldItemSlot()
<= j ? 1 : 0))).replace("{skill}", data.getBoundSkill(j).getSkill().getName())); <= j ? 1 : 0))).replace("{skill}", data.getBoundSkill(j).getSkill().getName()));
} }
@ -133,13 +133,13 @@ public class SpellCast implements Listener {
return str.toString(); return str.toString();
} }
/* /**
* no longer use index as arguments because data.getBoundSkill(int) has * We don't even need to check if the skill has the 'cooldown'
* n-complexity, it has to iterate through a list. using skillInfo * modifier. We just look for an entry in the cooldown map which
* argument uses only one iteration * won't be here if the skill has no cooldown.
*/ */
private boolean onCooldown(PlayerData data, SkillInfo skill) { private boolean onCooldown(PlayerData data, SkillInfo skill) {
return skill.getSkill().hasModifier("cooldown") && data.getSkillData().getCooldown(skill) > 0; return data.getCooldownMap().isOnCooldown(skill.getSkill());
} }
private boolean noMana(PlayerData data, SkillInfo skill) { private boolean noMana(PlayerData data, SkillInfo skill) {

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.skill; package net.Indyuce.mmocore.skill;
import io.lumine.mythic.lib.player.CooldownObject;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue; import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue;
@ -13,7 +14,7 @@ import org.bukkit.inventory.ItemStack;
import java.util.*; import java.util.*;
public abstract class Skill { public abstract class Skill implements CooldownObject {
private final String id; private final String id;
private String name; private String name;
@ -86,6 +87,11 @@ public abstract class Skill {
return icon.clone(); return icon.clone();
} }
@Override
public String getCooldownPath() {
return "mmocore_skill_" + id.toLowerCase();
}
/** /**
* Passive skills do not display any message when trying to cast them * Passive skills do not display any message when trying to cast them
* *

View File

@ -2,6 +2,7 @@ package net.Indyuce.mmocore.skill.metadata;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.comp.flags.CustomFlag; import io.lumine.mythic.lib.comp.flags.CustomFlag;
import io.lumine.mythic.lib.comp.mythicmobs.MythicSkillInfo;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.skill.CasterMetadata; import net.Indyuce.mmocore.skill.CasterMetadata;
import net.Indyuce.mmocore.skill.Skill; import net.Indyuce.mmocore.skill.Skill;
@ -9,7 +10,7 @@ import net.Indyuce.mmocore.skill.Skill.SkillInfo;
import java.util.Objects; import java.util.Objects;
public class SkillMetadata { public class SkillMetadata implements MythicSkillInfo {
private final SkillInfo skill; private final SkillInfo skill;
private final int level; private final int level;
private final double mana, cooldown, stamina; private final double mana, cooldown, stamina;
@ -22,11 +23,11 @@ public class SkillMetadata {
PlayerData data = caster.getPlayerData(); PlayerData data = caster.getPlayerData();
level = data.getSkillLevel(skill.getSkill()); level = data.getSkillLevel(skill.getSkill());
cooldown = (skill.getSkill().hasModifier("cooldown") ? data.getSkillData().getCooldown(skill) : 0); cooldown = skill.getSkill().hasModifier("cooldown") ? getModifier("cooldown") : 0;
mana = (skill.getSkill().hasModifier("mana") ? skill.getModifier("mana", level) : 0); mana = skill.getSkill().hasModifier("mana") ? getModifier("mana") : 0;
stamina = (skill.getSkill().hasModifier("stamina") ? skill.getModifier("stamina", level) : 0); stamina = skill.getSkill().hasModifier("stamina") ? getModifier("stamina") : 0;
cancelReason = !data.hasSkillUnlocked(skill) ? CancelReason.LOCKED cancelReason = !data.hasSkillUnlocked(skill) ? CancelReason.LOCKED
: cooldown > 0 ? CancelReason.COOLDOWN : data.getCooldownMap().isOnCooldown(getSkill()) ? CancelReason.COOLDOWN
: mana > data.getMana() ? CancelReason.MANA : mana > data.getMana() ? CancelReason.MANA
: stamina > data.getStamina() ? CancelReason.STAMINA : stamina > data.getStamina() ? CancelReason.STAMINA
: !data.isOnline() ? CancelReason.OTHER : !data.isOnline() ? CancelReason.OTHER
@ -39,9 +40,9 @@ public class SkillMetadata {
this.cancelReason = reason; this.cancelReason = reason;
level = data.getSkillLevel(skill.getSkill()); level = data.getSkillLevel(skill.getSkill());
cooldown = skill.getSkill().hasModifier("cooldown") ? data.getSkillData().getCooldown(skill) : 0; cooldown = skill.getSkill().hasModifier("cooldown") ? getModifier("cooldown") : 0;
mana = skill.getSkill().hasModifier("mana") ? skill.getModifier("mana", level) : 0; mana = skill.getSkill().hasModifier("mana") ? getModifier("mana") : 0;
stamina = (skill.getSkill().hasModifier("stamina") ? skill.getModifier("stamina", level) : 0); stamina = skill.getSkill().hasModifier("stamina") ? getModifier("stamina") : 0;
} }
public Skill getSkill() { public Skill getSkill() {
@ -84,6 +85,7 @@ public class SkillMetadata {
cancelReason = Objects.requireNonNull(reason, "Reason cannot be null"); cancelReason = Objects.requireNonNull(reason, "Reason cannot be null");
} }
@Override
public double getModifier(String modifier) { public double getModifier(String modifier) {
return skill.getModifier(modifier, level); return skill.getModifier(modifier, level);
} }