Max stamina stat for Heroes

This commit is contained in:
Indyuce 2022-07-07 00:12:59 +02:00
parent 611c901e8f
commit 0885263210
3 changed files with 24 additions and 12 deletions

View File

@ -66,6 +66,11 @@
<url>https://mvn.lumine.io/repository/maven-public/</url> <url>https://mvn.lumine.io/repository/maven-public/</url>
</repository> </repository>
<repository>
<id>lumine</id>
<url>https://mvn.lumine.io/repository/maven-private/</url>
</repository>
<repository> <repository>
<id>jitpack.io</id> <id>jitpack.io</id>
<url>https://jitpack.io</url> <url>https://jitpack.io</url>
@ -244,8 +249,8 @@
<dependency> <dependency>
<groupId>com.herocraftonline</groupId> <groupId>com.herocraftonline</groupId>
<artifactId>heroes</artifactId> <artifactId>Heroes</artifactId>
<version>1.9.3</version> <version>1.9.22</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -35,6 +35,7 @@ import net.Indyuce.mmoitems.comp.parse.placeholders.DefaultPlaceholderParser;
import net.Indyuce.mmoitems.comp.parse.placeholders.PlaceholderAPIParser; import net.Indyuce.mmoitems.comp.parse.placeholders.PlaceholderAPIParser;
import net.Indyuce.mmoitems.comp.parse.placeholders.PlaceholderParser; import net.Indyuce.mmoitems.comp.parse.placeholders.PlaceholderParser;
import net.Indyuce.mmoitems.comp.rpg.DefaultHook; import net.Indyuce.mmoitems.comp.rpg.DefaultHook;
import net.Indyuce.mmoitems.comp.rpg.HeroesHook;
import net.Indyuce.mmoitems.comp.rpg.McMMOHook; import net.Indyuce.mmoitems.comp.rpg.McMMOHook;
import net.Indyuce.mmoitems.comp.rpg.RPGHandler; import net.Indyuce.mmoitems.comp.rpg.RPGHandler;
import net.Indyuce.mmoitems.gui.PluginInventory; import net.Indyuce.mmoitems.gui.PluginInventory;
@ -139,6 +140,9 @@ public class MMOItems extends LuminePlugin {
} }
if (Bukkit.getPluginManager().getPlugin("MythicEnchants") != null) enchantPlugins.add(new MythicEnchantsSupport()); if (Bukkit.getPluginManager().getPlugin("MythicEnchants") != null) enchantPlugins.add(new MythicEnchantsSupport());
if (Bukkit.getPluginManager().getPlugin("Heroes") != null)
statManager.register(HeroesHook.MAX_STAMINA);
} }
@Override @Override

View File

@ -16,6 +16,9 @@ import io.lumine.mythic.lib.damage.DamageType;
import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -24,12 +27,12 @@ import org.jetbrains.annotations.Nullable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public class HeroesHook implements RPGHandler, Listener, AttackHandler { public class HeroesHook implements RPGHandler, Listener, AttackHandler {
private final Map<SkillType, DamageType> damages = new HashMap<>(); private final Map<SkillType, DamageType> damages = new HashMap<>();
public static final ItemStat MAX_STAMINA = new DoubleStat("MAX_STAMINA", Material.EMERALD, "Max Stamina", new String[]{"Adds stamina to your max stamina bar"});
public HeroesHook() { public HeroesHook() {
MythicLib.plugin.getDamage().registerHandler(this); MythicLib.plugin.getDamage().registerHandler(this);
@ -46,8 +49,7 @@ public class HeroesHook implements RPGHandler, Listener, AttackHandler {
return null; return null;
Player player = (Player) info.getCharacter().getEntity(); Player player = (Player) info.getCharacter().getEntity();
Set<DamageType> types = info.getSkill().getTypes().stream().filter(damages::containsKey).map(damages::get).collect(Collectors.toSet()); DamageMetadata damageMeta = new DamageMetadata(0, info.getSkill().getTypes().stream().filter(damages::containsKey).map(damages::get).distinct().toArray(DamageType[]::new));
DamageMetadata damageMeta = new DamageMetadata(0, types.toArray(new DamageType[0]));
return new AttackMetadata(damageMeta, MMOPlayerData.get(player).getStatMap().cache(EquipmentSlot.MAIN_HAND)); return new AttackMetadata(damageMeta, MMOPlayerData.get(player).getStatMap().cache(EquipmentSlot.MAIN_HAND));
} }
@ -56,6 +58,10 @@ public class HeroesHook implements RPGHandler, Listener, AttackHandler {
Hero hero = Heroes.getInstance().getCharacterManager().getHero(data.getPlayer()); Hero hero = Heroes.getInstance().getCharacterManager().getHero(data.getPlayer());
hero.removeMaxMana("MMOItems"); hero.removeMaxMana("MMOItems");
hero.addMaxMana("MMOItems", (int) data.getStats().getStat(ItemStats.MAX_MANA)); hero.addMaxMana("MMOItems", (int) data.getStats().getStat(ItemStats.MAX_MANA));
hero.removeMaxStamina("MMOItems");
hero.addMaxStamina("MMOItems", (int) data.getStats().getStat(MAX_STAMINA));
hero.removeMaxHealth("MMOItems");
hero.addMaxHealth("MMOItems", data.getStats().getStat(ItemStats.MAX_HEALTH));
} }
@Override @Override
@ -82,43 +88,40 @@ public class HeroesHook implements RPGHandler, Listener, AttackHandler {
} }
public static class HeroesPlayer extends RPGPlayer { public static class HeroesPlayer extends RPGPlayer {
private final Hero hero;
public HeroesPlayer(PlayerData playerData) { public HeroesPlayer(PlayerData playerData) {
super(playerData); super(playerData);
hero = Heroes.getInstance().getCharacterManager().getHero(getPlayer());
} }
@Override @Override
public int getLevel() { public int getLevel() {
Hero hero = Heroes.getInstance().getCharacterManager().getHero(getPlayer());
return hero.getHeroLevel(); return hero.getHeroLevel();
} }
@Override @Override
public String getClassName() { public String getClassName() {
Hero hero = Heroes.getInstance().getCharacterManager().getHero(getPlayer());
return hero.getHeroClass().getName(); return hero.getHeroClass().getName();
} }
@Override @Override
public double getMana() { public double getMana() {
Hero hero = Heroes.getInstance().getCharacterManager().getHero(getPlayer());
return hero.getMana(); return hero.getMana();
} }
@Override @Override
public double getStamina() { public double getStamina() {
Hero hero = Heroes.getInstance().getCharacterManager().getHero(getPlayer());
return hero.getStamina(); return hero.getStamina();
} }
@Override @Override
public void setMana(double value) { public void setMana(double value) {
Hero hero = Heroes.getInstance().getCharacterManager().getHero(getPlayer());
hero.setMana((int) value); hero.setMana((int) value);
} }
@Override @Override
public void setStamina(double value) { public void setStamina(double value) {
Hero hero = Heroes.getInstance().getCharacterManager().getHero(getPlayer());
hero.setStamina((int) value); hero.setStamina((int) value);
} }
} }