Skip to content

Commit

Permalink
Fix SkillsUser#setSkillLevel not refreshing stats and rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed Sep 20, 2024
1 parent d2d8f08 commit 47eafda
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 2 additions & 1 deletion bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand All @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -428,10 +428,6 @@ public LootTableManager getLootTableManager() {
return lootTableManager;
}

public ModifierManager getModifierManager() {
return modifierManager;
}

public RequirementManager getRequirementManager() {
return requirementManager;
}
Expand Down Expand Up @@ -626,6 +622,11 @@ public ApiProvider getApiProvider() {
return apiProvider;
}

@Override
public BukkitModifierManager getModifierManager() {
return modifierManager;
}

public ItemManager getItemManager() {
return itemManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,6 +108,8 @@ public interface AuraSkillsPlugin {

ApiProvider getApiProvider();

ModifierManager getModifierManager();

// Message convenience methods

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.aurelium.auraskills.common.modifier;

import dev.aurelium.auraskills.common.user.User;

public interface ModifierManager {

void reloadUser(User user);

}

0 comments on commit 47eafda

Please sign in to comment.