Supports AuraSkills 2+, thanks @ErikSzabo

This commit is contained in:
Jules 2024-04-10 07:24:27 -07:00
parent ca0dfe1588
commit e801e9d786
7 changed files with 212 additions and 20 deletions

View File

@ -64,18 +64,8 @@
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>inventive-repo</id>
<url>https://repo.inventivetalent.org/content/groups/public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
<id>sonatype</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<!-- Repository used to fetch all Spigot builds -->
@ -90,6 +80,21 @@
<url>https://repo.codemc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>inventive-repo</id>
<url>https://repo.inventivetalent.org/content/groups/public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<!--
@ -137,6 +142,13 @@
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- Aura Skills -->
<dependency>
<groupId>dev.aurelium</groupId>
<artifactId>auraskills-api-bukkit</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- PhatLoots -->
<dependency>
<groupId>com.github.RednedEpic</groupId>

View File

@ -0,0 +1,177 @@
package net.Indyuce.mmoitems.comp.rpg;
import dev.aurelium.auraskills.api.AuraSkillsApi;
import dev.aurelium.auraskills.api.event.skill.SkillLevelUpEvent;
import dev.aurelium.auraskills.api.event.user.UserLoadEvent;
import dev.aurelium.auraskills.api.skill.Skill;
import dev.aurelium.auraskills.api.stat.StatModifier;
import dev.aurelium.auraskills.api.stat.Stats;
import dev.aurelium.auraskills.api.skill.Skills;
import dev.aurelium.auraskills.api.trait.TraitModifier;
import dev.aurelium.auraskills.api.trait.Traits;
import dev.aurelium.auraskills.api.user.SkillsUser;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.EmptyRPGPlayer;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.RequiredLevelStat;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class AuraSkillsHook implements RPGHandler, Listener {
private AuraSkillsApi aSkills;
private final Map<Stats, ItemStat> statExtra = new HashMap<>();
public AuraSkillsHook() {
aSkills = AuraSkillsApi.get();
for (Stats stat : Stats.values()) {
final String statName = UtilityMethods.caseOnWords(stat.name().toLowerCase());
final ItemStat miStat = new DoubleStat("ADDITIONAL_" + stat.name(), Material.BOOK,
"Additional " + statName,
new String[]{"Additional " + statName + " (AuraSkills)"},
new String[]{"!miscellaneous", "!block", "all"});
statExtra.put(stat, miStat);
MMOItems.plugin.getStats().register(miStat);
}
// Register stat for required professions
for (Skills skill : Skills.values())
MMOItems.plugin.getStats().register(new RequiredProfessionStat(skill));
}
@EventHandler
public void a(SkillLevelUpEvent event) {
OfflinePlayer player = event.getPlayer();
if (player.isOnline())
PlayerData.get(player).getInventory().scheduleUpdate();
}
/**
* AuraSkills stores modifiers using ONE hash map for every stat
* unlike MythicLib which has several stat instances. Therefore, a
* valid key for a stat modifier is "mmoitems_<stat_name>".
* <p>
* Be careful, ASkills permanently stores modifiers unlike ML
*/
private static final String MODIFIER_KEY_PREFIX = "mmoitems_";
@Override
public void refreshStats(PlayerData data) {
SkillsUser user = aSkills.getUser(data.getPlayer().getUniqueId());
user.addTraitModifier(
new TraitModifier(MODIFIER_KEY_PREFIX + "max_mana", Traits.MAX_MANA, data.getStats().getStat(ItemStats.MAX_MANA)));
double currentMaxMana = user.getMaxMana();
if(user.getMana() > currentMaxMana) {
user.setMana(currentMaxMana);
}
statExtra.forEach((stat, miStat) -> aSkills.getUser(data.getPlayer().getUniqueId()).addStatModifier(new StatModifier(MODIFIER_KEY_PREFIX + stat.name(), stat, data.getStats().getStat(miStat))));
}
@Override
public RPGPlayer getInfo(PlayerData data) {
/**
* AuraSkills does not load player data directly on startup, instead we have to
* listen to the PlayerDataLoadEvent before caching the rpg player data instance.
*
* See PlayerDataLoadEvent event handler below.
*/
return new EmptyRPGPlayer(data);
}
@EventHandler
public void a(UserLoadEvent event) {
Player player = event.getPlayer();
PlayerData playerData = PlayerData.get(player);
playerData.setRPGPlayer(new AuraSkillsPlayer(playerData, event.getUser()));
}
public static class AuraSkillsPlayer extends RPGPlayer {
private final SkillsUser info;
public AuraSkillsPlayer(PlayerData playerData, SkillsUser rpgPlayerData) {
super(playerData);
info = rpgPlayerData;
}
@Override
public int getLevel() {
return info.getPowerLevel();
}
@Override
public String getClassName() {
return "";
}
@Override
public double getMana() {
return info.getMana();
}
@Override
public double getStamina() {
return getPlayer().getFoodLevel();
}
@Override
public void setMana(double value) {
info.setMana(value);
}
@Override
public void setStamina(double value) {
getPlayer().setFoodLevel((int) value);
}
}
public class RequiredProfessionStat extends RequiredLevelStat {
private final Skill skill;
public RequiredProfessionStat(Skills skill) {
super(skill.name(), VersionMaterial.EXPERIENCE_BOTTLE.toMaterial(), skill.getDisplayName(Locale.getDefault()),
new String[]{"Amount of " + skill.getDisplayName(Locale.getDefault()) + " levels the", "player needs to use the item.", "(AuraSkills)"});
this.skill = aSkills.getGlobalRegistry().getSkill(skill.getId());
}
@Override
public boolean canUse(RPGPlayer player, NBTItem item, boolean message) {
final int skillLevel = aSkills.getUser(player.getPlayer().getUniqueId()).getSkillLevel(skill);
final int required = item.getInteger("MMOITEMS_REQUIRED_" + skill.name());
if (skillLevel < required && !player.getPlayer().hasPermission("mmoitems.bypass.level")) {
if (message) {
Message.NOT_ENOUGH_PROFESSION.format(ChatColor.RED, "#profession#", skill.getDisplayName(Locale.getDefault())).send(player.getPlayer());
player.getPlayer().playSound(player.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1.5f);
}
return false;
}
return true;
}
}
}

View File

@ -27,6 +27,10 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* @deprecated Old version of {@link AuraSkillsHook}
*/
@Deprecated
public class AureliumSkillsHook implements RPGHandler, Listener {
private final AureliumSkills aSkills;

View File

@ -38,8 +38,9 @@ public interface RPGHandler {
BATTLELEVELS("BattleLevels", BattleLevelsHook.class),
MCMMO("mcMMO", McMMOHook.class),
MCRPG("McRPG", McRPGHook.class),
SKILLS("Skills", SkillsHook.class),
AURELIUM_SKILLS("AureliumSkills", AureliumSkillsHook.class),
AURA_SKILLS("AuraSkills", AuraSkillsHook.class),
SKILLS("Skills", SkillsHook.class),
SKILLSPRO("SkillsPro", SkillsProHook.class);
private final Class<? extends RPGHandler> pluginClass;

View File

@ -2,15 +2,12 @@ package net.Indyuce.mmoitems.stat.type;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.RequiredLevelData;
import net.Indyuce.mmoitems.stat.data.random.RandomRequiredLevelData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
@ -19,8 +16,8 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
/**
* Used by {@link net.Indyuce.mmoitems.comp.rpg.AureliumSkillsHook} to handle
* required skill levels.
* Used by {@link net.Indyuce.mmoitems.comp.rpg.AuraSkillsHook}
* to handle required skill levels.
*/
public abstract class RequiredLevelStat extends DoubleStat implements ItemRestriction, GemStoneStat {
// private final String idKey;

View File

@ -29,7 +29,8 @@ locked-skins: true
# - MCMMO (power level)
# - MCRPG (power level)
# - SKILLS or SKILLSPRO (class, level, mana)
# - AURELIUM_SKILLS (power level, mana)
# - AURELIUM_SKILLS (version 1.X: power level, mana)
# - AURA_SKILLS (version 2+: power level, mana)
preferred-rpg-provider: MMOCORE
# By default, all player inventories will be updated every

View File

@ -4,7 +4,7 @@ main: net.Indyuce.mmoitems.MMOItems
author: Indyuce
description: ${project.description}
depend: [MythicLib]
softdepend: [WorldGuard,Residence,BossShopPro,SkillAPI,SkillsPro,MMOCore,MMOProfiles,MythicMobs,MMOInventory,PlaceholderAPI,Vault,Denizen,AureliumSkills]
softdepend: [WorldGuard,Residence,BossShopPro,SkillAPI,SkillsPro,MMOCore,MMOProfiles,MythicMobs,MMOInventory,PlaceholderAPI,Vault,Denizen,AureliumSkills,AuraSkills]
api-version: 1.13
commands:
mmoitems: