Reload inventories on stats reload

This commit is contained in:
Roch Blonndiaux 2023-02-02 10:58:50 +01:00
parent bfd75e5c99
commit 0db2980fda
2 changed files with 18 additions and 0 deletions

View File

@ -3,8 +3,11 @@ package net.Indyuce.mmoitems.command.mmoitems;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.MMOItemReforger;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.comp.inventory.PlayerInventoryHandler;
import net.Indyuce.mmoitems.comp.inventory.model.PlayerMMOInventory;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -50,6 +53,8 @@ public class ReloadCommandTreeNode extends CommandTreeNode {
MythicLib.plugin.getSkills().initialize(true);
MMOItems.plugin.getSkills().initialize(true);
sender.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reloaded " + MMOItems.plugin.getSkills().getAll().size() + " skills.");
reloadPlayerInventories();
}
public void reloadMain(CommandSender sender) {
@ -100,4 +105,13 @@ public class ReloadCommandTreeNode extends CommandTreeNode {
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED
+ MMOItems.plugin.getCrafting().countRecipes() + ChatColor.GRAY + " Recipes");
}
public void reloadPlayerInventories() {
PlayerData.getLoaded()
.stream()
.map(PlayerData::getInventory)
.map(PlayerMMOInventory::getHandler)
.peek(PlayerInventoryHandler::reset)
.forEach(PlayerInventoryHandler::start);
}
}

View File

@ -68,4 +68,8 @@ public class PlayerMMOInventory {
public List<EquippedItem> equipped() {
return Collections.unmodifiableList(content);
}
public PlayerInventoryHandler getHandler() {
return handler;
}
}