diff --git a/api/src/main/java/dev/aurelium/auraskills/api/user/SkillsUser.java b/api/src/main/java/dev/aurelium/auraskills/api/user/SkillsUser.java index 5548f906b..fd0a77e41 100644 --- a/api/src/main/java/dev/aurelium/auraskills/api/user/SkillsUser.java +++ b/api/src/main/java/dev/aurelium/auraskills/api/user/SkillsUser.java @@ -94,6 +94,15 @@ public interface SkillsUser { */ void setSkillLevel(Skill skill, int level); + /** + * Sets the level of a skill. + * + * @param skill the skill to set the level of + * @param level the level to set to + * @param refresh whether to refresh stats, permissions, rewards, and item modifiers to account for the change in skill level + */ + void setSkillLevel(Skill skill, int level, boolean refresh); + /** * Gets the user's average skill level of all enabled skills. * diff --git a/bukkit/build.gradle.kts b/bukkit/build.gradle.kts index 00159ab8b..34392366b 100644 --- a/bukkit/build.gradle.kts +++ b/bukkit/build.gradle.kts @@ -19,6 +19,7 @@ repositories { maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") maven("https://repo.codemc.io/repository/maven-public/") maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") + maven("https://repo.helpch.at/releases") maven("https://jitpack.io") maven("https://repo.dmulloy2.net/repository/public/") maven("https://repo.maven.apache.org/maven2/") @@ -37,7 +38,7 @@ dependencies { implementation("net.kyori:adventure-platform-bukkit:4.3.3") compileOnly("org.jetbrains:annotations:24.1.0") compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT") - compileOnly("me.clip:placeholderapi:2.11.2") + compileOnly("me.clip:placeholderapi:2.11.6") compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.5") { exclude("org.spigotmc", "spigot-api") } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/AuraSkills.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/AuraSkills.java index 2233fcd89..1778c21e9 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/AuraSkills.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/AuraSkills.java @@ -41,7 +41,7 @@ import dev.aurelium.auraskills.bukkit.message.BukkitMessageProvider; import dev.aurelium.auraskills.bukkit.modifier.ArmorModifierListener; import dev.aurelium.auraskills.bukkit.modifier.ItemListener; -import dev.aurelium.auraskills.bukkit.modifier.ModifierManager; +import dev.aurelium.auraskills.bukkit.modifier.BukkitModifierManager; import dev.aurelium.auraskills.bukkit.region.BukkitRegionManager; import dev.aurelium.auraskills.bukkit.region.BukkitWorldManager; import dev.aurelium.auraskills.bukkit.region.RegionBlockListener; @@ -149,7 +149,7 @@ public class AuraSkills extends JavaPlugin implements AuraSkillsPlugin { private BukkitRegionManager regionManager; private BukkitWorldManager worldManager; private LootTableManager lootTableManager; - private ModifierManager modifierManager; + private BukkitModifierManager modifierManager; private RequirementManager requirementManager; private BackupProvider backupProvider; private InventoryManager inventoryManager; @@ -222,7 +222,7 @@ public void onEnable() { xpRequirements = new XpRequirements(this); leaderboardManager = new LeaderboardManager(this); uiProvider = new BukkitUiProvider(this); - modifierManager = new ModifierManager(this); + modifierManager = new BukkitModifierManager(this); inventoryManager = new InventoryManager(this); inventoryManager.init(); rewardManager = new BukkitRewardManager(this); // Loaded later @@ -428,10 +428,6 @@ public LootTableManager getLootTableManager() { return lootTableManager; } - public ModifierManager getModifierManager() { - return modifierManager; - } - public RequirementManager getRequirementManager() { return requirementManager; } @@ -626,6 +622,11 @@ public ApiProvider getApiProvider() { return apiProvider; } + @Override + public BukkitModifierManager getModifierManager() { + return modifierManager; + } + public ItemManager getItemManager() { return itemManager; } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/modifier/ModifierManager.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/modifier/BukkitModifierManager.java similarity index 91% rename from bukkit/src/main/java/dev/aurelium/auraskills/bukkit/modifier/ModifierManager.java rename to bukkit/src/main/java/dev/aurelium/auraskills/bukkit/modifier/BukkitModifierManager.java index 008a211af..677dc781b 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/modifier/ModifierManager.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/modifier/BukkitModifierManager.java @@ -6,6 +6,8 @@ import dev.aurelium.auraskills.bukkit.AuraSkills; import dev.aurelium.auraskills.bukkit.item.SkillsItem; import dev.aurelium.auraskills.api.skill.Multiplier; +import dev.aurelium.auraskills.bukkit.user.BukkitUser; +import dev.aurelium.auraskills.common.modifier.ModifierManager; import dev.aurelium.auraskills.common.user.User; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -15,11 +17,11 @@ import java.util.HashSet; import java.util.Set; -public class ModifierManager { +public class BukkitModifierManager implements ModifierManager { private final AuraSkills plugin; - public ModifierManager(AuraSkills plugin) { + public BukkitModifierManager(AuraSkills plugin) { this.plugin = plugin; } @@ -102,4 +104,11 @@ public void reloadPlayer(Player player) { } } + @Override + public void reloadUser(User user) { + Player player = ((BukkitUser) user).getPlayer(); + if (player != null) { + reloadPlayer(player); + } + } } diff --git a/common/src/main/java/dev/aurelium/auraskills/common/AuraSkillsPlugin.java b/common/src/main/java/dev/aurelium/auraskills/common/AuraSkillsPlugin.java index deb3c074d..c54f5bbd3 100644 --- a/common/src/main/java/dev/aurelium/auraskills/common/AuraSkillsPlugin.java +++ b/common/src/main/java/dev/aurelium/auraskills/common/AuraSkillsPlugin.java @@ -19,6 +19,7 @@ import dev.aurelium.auraskills.common.message.MessageKey; import dev.aurelium.auraskills.common.message.MessageProvider; import dev.aurelium.auraskills.common.message.PlatformLogger; +import dev.aurelium.auraskills.common.modifier.ModifierManager; import dev.aurelium.auraskills.common.region.WorldManager; import dev.aurelium.auraskills.common.reward.RewardManager; import dev.aurelium.auraskills.common.scheduler.Scheduler; @@ -107,6 +108,8 @@ public interface AuraSkillsPlugin { ApiProvider getApiProvider(); + ModifierManager getModifierManager(); + // Message convenience methods /** diff --git a/common/src/main/java/dev/aurelium/auraskills/common/api/implementation/ApiSkillsUser.java b/common/src/main/java/dev/aurelium/auraskills/common/api/implementation/ApiSkillsUser.java index 4ba66da0e..501aab2b2 100644 --- a/common/src/main/java/dev/aurelium/auraskills/common/api/implementation/ApiSkillsUser.java +++ b/common/src/main/java/dev/aurelium/auraskills/common/api/implementation/ApiSkillsUser.java @@ -79,7 +79,22 @@ public int getSkillLevel(Skill skill) { @Override public void setSkillLevel(Skill skill, int level) { + setSkillLevel(skill, level, true); + } + + @Override + public void setSkillLevel(Skill skill, int level, boolean refresh) { + int oldLevel = user.getSkillLevel(skill); user.setSkillLevel(skill, level); + + if (refresh) { + plugin.getStatManager().updateStats(user); + plugin.getRewardManager().updatePermissions(user); + plugin.getRewardManager().applyRevertCommands(user, skill, oldLevel, level); + plugin.getRewardManager().applyLevelUpCommands(user, skill, oldLevel, level); + // Reload items and armor to check for newly met requirements + this.plugin.getModifierManager().reloadUser(user); + } } @Override diff --git a/common/src/main/java/dev/aurelium/auraskills/common/api/implementation/OfflineSkillsUser.java b/common/src/main/java/dev/aurelium/auraskills/common/api/implementation/OfflineSkillsUser.java index 9d5cbd957..0f442137a 100644 --- a/common/src/main/java/dev/aurelium/auraskills/common/api/implementation/OfflineSkillsUser.java +++ b/common/src/main/java/dev/aurelium/auraskills/common/api/implementation/OfflineSkillsUser.java @@ -70,6 +70,11 @@ public void setSkillLevel(Skill skill, int level) { } + @Override + public void setSkillLevel(Skill skill, int level, boolean refresh) { + + } + @Override public double getSkillAverage() { return 0; diff --git a/common/src/main/java/dev/aurelium/auraskills/common/modifier/ModifierManager.java b/common/src/main/java/dev/aurelium/auraskills/common/modifier/ModifierManager.java new file mode 100644 index 000000000..5e0c32c43 --- /dev/null +++ b/common/src/main/java/dev/aurelium/auraskills/common/modifier/ModifierManager.java @@ -0,0 +1,9 @@ +package dev.aurelium.auraskills.common.modifier; + +import dev.aurelium.auraskills.common.user.User; + +public interface ModifierManager { + + void reloadUser(User user); + +}