Abilities issues fixed & deprecated methods replaced

This commit is contained in:
Roch Blonndiaux 2023-02-02 11:40:07 +01:00
parent 0db2980fda
commit 2ab70183ed
18 changed files with 36 additions and 45 deletions

View File

@ -170,7 +170,7 @@ public class DurabilityItem {
// Play sound when item breaks
if (isBroken()) {
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
PlayerData.get(player).getInventory().scheduleUpdate();
PlayerData.get(player).getInventory().update();
}
return this;

View File

@ -5,17 +5,15 @@ import net.Indyuce.mmoitems.api.player.PlayerData;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.jetbrains.annotations.ApiStatus;
import java.util.ArrayList;
import java.util.List;
@Deprecated
@ApiStatus.ScheduledForRemoval
/**
* TODO
* <p>
* It's one of the most urgent systems to update. Moving everything to a new
* class to mark everything that needs to be changed
*
* @author indyuce
* @deprecated Use {@link net.Indyuce.mmoitems.comp.inventory.PlayerInventoryHandler} instead
*/
public class InventoryUpdateHandler {
private final PlayerData player;
@ -38,7 +36,7 @@ public class InventoryUpdateHandler {
* - the player meets the item requirements (class, level etc)
*
* @return All equipped MMOItems in the player's inventory. Also includes
* items from custom inventory plugins like MMOInventory
* items from custom inventory plugins like MMOInventory
*/
public List<EquippedItem> getEquipped() {
return items;

View File

@ -311,9 +311,7 @@ public class PlayerInventoryHandler implements Runnable {
}
private void processNewItem(@NotNull PlayerInventoryImage newImage, @Nullable SlotEquippedItem item, @Nullable VolatileMMOItem newItem) {
if (newItem == null || item == null)
return;
if (!item.isPlacementLegal() || !this.data.getRPG().canUse(item.getNBT(), false, false))
if (newItem == null || item == null || !item.isPlacementLegal() || !this.data.getRPG().canUse(item.getNBT(), false, false))
return;
// Cache item and add it to the inventory
@ -330,7 +328,6 @@ public class PlayerInventoryHandler implements Runnable {
final ModifierSource source = item.getCached().getType().getModifierSource();
double value = item.getNBT().getStat(stat.getId());
// Apply hand weapon stat offset
if (source.isWeapon() && stat instanceof AttackWeaponStat)
value -= ((AttackWeaponStat) stat).getOffset(this.data);
@ -344,9 +341,9 @@ public class PlayerInventoryHandler implements Runnable {
List<UUID> uuids = new ArrayList<>();
for (AbilityData abilityData : ((AbilityListData) newItem.getData(ItemStats.ABILITIES)).getAbilities()) {
ModifierSource modSource = item.getCached().getType().getModifierSource();
PassiveSkill skill = this.data.getMMOPlayerData().getPassiveSkillMap().addModifier(new PassiveSkill("MMOItemsItem", abilityData, item.getSlot(), modSource));
if (skill != null)
uuids.add(skill.getUniqueId());
PassiveSkill skill = new PassiveSkill("MMOItemsItem", abilityData, item.getSlot(), modSource);
this.data.getMMOPlayerData().getPassiveSkillMap().addModifier(skill);
uuids.add(skill.getUniqueId());
}
newImage.itemAbilities().put(item.getSlotNumber(), uuids);
}

View File

@ -8,7 +8,6 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@ -66,7 +65,7 @@ public class PlayerMMOInventory {
}
public List<EquippedItem> equipped() {
return Collections.unmodifiableList(content);
return content;
}
public PlayerInventoryHandler getHandler() {

View File

@ -6,8 +6,8 @@ import io.lumine.mythic.lib.api.player.EquipmentSlot;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.inventory.EquippedItem;
import net.Indyuce.mmoitems.comp.inventory.model.SlotEquippedItem;
import net.Indyuce.mmoitems.comp.inventory.model.PlayerInventory;
import net.Indyuce.mmoitems.comp.inventory.model.SlotEquippedItem;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -54,7 +54,7 @@ public class OrnamentPlayerInventory implements PlayerInventory, Listener {
if (event.getEntityType() == EntityType.PLAYER) {
final NBTItem nbt = NBTItem.get(event.getItem().getItemStack());
if (nbt.hasType() && Type.get(nbt.getType()).getSupertype().equals(Type.ORNAMENT))
PlayerData.get((Player) event.getEntity()).getInventory().scheduleUpdate();
PlayerData.get((Player) event.getEntity()).getInventory().update();
}
}
@ -62,6 +62,6 @@ public class OrnamentPlayerInventory implements PlayerInventory, Listener {
public void updateOnItemDrop(PlayerDropItemEvent event) {
final NBTItem nbt = NBTItem.get(event.getItemDrop().getItemStack());
if (nbt.hasType() && Type.get(nbt.getType()).getSupertype().equals(Type.ORNAMENT))
PlayerData.get(event.getPlayer()).updateInventory();
PlayerData.get(event.getPlayer()).getInventory().update();
}
}

View File

@ -67,12 +67,12 @@ public class MMOCoreHook implements RPGHandler, Listener {
@EventHandler
public void updateInventoryOnLevelUp(PlayerLevelUpEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
@EventHandler
public void updateInventoryOnClassChange(PlayerChangeClassEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
/**
@ -86,7 +86,7 @@ public class MMOCoreHook implements RPGHandler, Listener {
@EventHandler
public void updateInventoryOnLoad(AsyncPlayerDataLoadEvent event) {
if (PlayerData.has(event.getPlayer()))
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
public static class MMOCoreRPGPlayer extends RPGPlayer {

View File

@ -47,7 +47,7 @@ public class AureliumSkillsHook implements RPGHandler, Listener {
public void a(SkillLevelUpEvent event) {
OfflinePlayer player = event.getPlayer();
if (player.isOnline())
PlayerData.get(player).getInventory().scheduleUpdate();
PlayerData.get(player).getInventory().update();
}
@Override

View File

@ -12,7 +12,7 @@ public class BattleLevelsHook implements RPGHandler, Listener {
@EventHandler
public void a(PlayerLevelUpEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
@Override

View File

@ -15,7 +15,7 @@ public class DefaultHook implements RPGHandler, Listener {
@EventHandler
public void a(PlayerLevelChangeEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
@Override

View File

@ -76,7 +76,7 @@ public class HeroesHook implements RPGHandler, Listener, AttackHandler {
*/
@EventHandler
public void a(HeroChangeLevelEvent event) {
PlayerData.get(event.getHero().getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getHero().getPlayer()).getInventory().update();
}
/**
@ -85,7 +85,7 @@ public class HeroesHook implements RPGHandler, Listener, AttackHandler {
*/
@EventHandler
public void b(ClassChangeEvent event) {
PlayerData.get(event.getHero().getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getHero().getPlayer()).getInventory().update();
}
public static class HeroesPlayer extends RPGPlayer {

View File

@ -1,19 +1,16 @@
package net.Indyuce.mmoitems.comp.rpg;
import net.Indyuce.mmoitems.MMOItems;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import com.gmail.nossr50.api.ExperienceAPI;
import com.gmail.nossr50.api.exceptions.McMMOPlayerNotFoundException;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelDownEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.stat.type.DisableStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class McMMOHook implements RPGHandler, Listener {
@ -28,12 +25,12 @@ public class McMMOHook implements RPGHandler, Listener {
@EventHandler(ignoreCancelled = true)
public void a(McMMOPlayerLevelUpEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
@EventHandler(ignoreCancelled = true)
public void b(McMMOPlayerLevelDownEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
@Override

View File

@ -12,7 +12,7 @@ public class McRPGHook implements RPGHandler, Listener {
@EventHandler
public void a(McRPGPlayerLevelChangeEvent event) {
PlayerData.get(event.getMcRPGPlayer().getOfflineMcRPGPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getMcRPGPlayer().getOfflineMcRPGPlayer()).getInventory().update();
}
@Override

View File

@ -58,7 +58,7 @@ public class ProSkillAPIHook implements RPGHandler, Listener, AttackHandler {
@EventHandler
public void b(PlayerLevelUpEvent event) {
net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).getInventory().scheduleUpdate();
net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).getInventory().update();
}
@Override

View File

@ -30,12 +30,12 @@ public class RacesAndClassesHook implements RPGHandler, Listener {
*/
@EventHandler
public void a(LevelUpEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
@EventHandler
public void b(LevelDownEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
public static class RacePlayer extends RPGPlayer {

View File

@ -58,7 +58,7 @@ public class SkillAPIHook implements RPGHandler, Listener, AttackHandler {
@EventHandler
public void b(PlayerLevelUpEvent event) {
net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).getInventory().scheduleUpdate();
net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).getInventory().update();
}
@Override

View File

@ -16,7 +16,7 @@ public class SkillsHook implements RPGHandler, Listener {
public void a(SkillLevelUpEvent event) {
OfflinePlayer player = event.getPlayer();
if (player.isOnline())
PlayerData.get(player).getInventory().scheduleUpdate();
PlayerData.get(player).getInventory().update();
}
@Override

View File

@ -16,7 +16,7 @@ public class SkillsProHook implements RPGHandler, Listener {
public void a(SkillLevelUpEvent event) {
OfflinePlayer player = event.getPlayer();
if (player.isOnline())
PlayerData.get(player).getInventory().scheduleUpdate();
PlayerData.get(player).getInventory().update();
}
@Override

View File

@ -166,7 +166,7 @@ public class PlayerListener implements Listener {
@Deprecated
@EventHandler
public void registerInventoryUpdates1(PlayerSwapHandItemsEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
/**
@ -180,7 +180,7 @@ public class PlayerListener implements Listener {
@Deprecated
@EventHandler
public void registerInventoryUpdates2(PlayerItemHeldEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
PlayerData.get(event.getPlayer()).getInventory().update();
}
/**