From 7408899816364ab1dcc0bf7e0e215940e0df1d0b Mon Sep 17 00:00:00 2001 From: Jules Date: Tue, 20 Feb 2024 00:19:12 +0100 Subject: [PATCH] Fixed potential confusions w/ stat methods --- .../mmoitems/api/player/PlayerData.java | 30 ++++++++----------- .../mmoitems/api/player/PlayerStats.java | 14 +++++---- .../net/Indyuce/mmoitems/stat/Amphibian.java | 2 +- .../net/Indyuce/mmoitems/MMOItemsBukkit.java | 2 +- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java index 78c20940..f02a967b 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java @@ -40,9 +40,6 @@ import org.jetbrains.annotations.Nullable; import java.util.*; public class PlayerData extends SynchronizedDataHolder implements Closeable { - @NotNull - private final MMOPlayerData mmoData; - // Reloaded everytime the player reconnects in case of major change. private RPGPlayer rpgPlayer; @@ -62,7 +59,6 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { public PlayerData(@NotNull MMOPlayerData mmoData) { super(mmoData); - this.mmoData = mmoData; rpgPlayer = MMOItems.plugin.getMainRPG().getInfo(this); stats = new PlayerStats(this); } @@ -73,7 +69,7 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { } public boolean isOnline() { - return mmoData.isOnline(); + return getMMOPlayerData().isOnline(); } public RPGPlayer getRPG() { @@ -93,7 +89,7 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { /** * @return If the player hands are full i.e if the player is holding - * two items in their hands, one being two handed + * two items in their hands, one being two handed */ public boolean isEncumbered() { @@ -122,10 +118,8 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { this.rpgPlayer = rpgPlayer; } - @SuppressWarnings("deprecation") public void updateInventory() { - if (!mmoData.isOnline()) - return; + if (!isOnline()) return; /* * Very important, clear particle data AFTER canceling the runnable @@ -134,7 +128,7 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { inventory.getEquipped().clear(); permanentEffects.clear(); cancelRunnables(); - mmoData.getPassiveSkillMap().removeModifiers("MMOItemsItem"); + getMMOPlayerData().getPassiveSkillMap().removeModifiers("MMOItemsItem"); itemParticles.clear(); overridingItemParticles = null; if (MMOItems.plugin.hasPermissions()) { @@ -180,7 +174,7 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { if (item.hasData(ItemStats.ABILITIES)) for (AbilityData abilityData : ((AbilityListData) item.getData(ItemStats.ABILITIES)).getAbilities()) { ModifierSource modSource = equipped.getCached().getType().getModifierSource(); - mmoData.getPassiveSkillMap().addModifier(new PassiveSkill("MMOItemsItem", abilityData, equipped.getSlot(), modSource)); + getMMOPlayerData().getPassiveSkillMap().addModifier(new PassiveSkill("MMOItemsItem", abilityData, equipped.getSlot(), modSource)); } // Modifier application rules @@ -254,7 +248,7 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { perms.playerAdd(getPlayer(), perm); } for (AbilityData ability : setBonuses.getAbilities()) - mmoData.getPassiveSkillMap().addModifier(new PassiveSkill("MMOItemsItem", ability, EquipmentSlot.OTHER, ModifierSource.OTHER)); + getMMOPlayerData().getPassiveSkillMap().addModifier(new PassiveSkill("MMOItemsItem", ability, EquipmentSlot.OTHER, ModifierSource.OTHER)); for (ParticleData particle : setBonuses.getParticles()) itemParticles.add(particle.start(this)); for (PotionEffect effect : setBonuses.getPotionEffects()) @@ -277,7 +271,7 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { inventory.offhand = getPlayer().getInventory().getItemInOffHand(); } - public void updateStats() { + public void timedRunnable() { // Permanent effects permanentEffects.values().forEach(effect -> getPlayer().addPotionEffect(effect)); @@ -335,11 +329,11 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { } public boolean isOnCooldown(CooldownType type) { - return mmoData.getCooldownMap().isOnCooldown(type.name()); + return getMMOPlayerData().getCooldownMap().isOnCooldown(type.name()); } public void applyCooldown(CooldownType type, double value) { - mmoData.getCooldownMap().applyCooldown(type.name(), value); + getMMOPlayerData().getCooldownMap().applyCooldown(type.name(), value); } /** @@ -347,7 +341,7 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { */ @Deprecated public boolean isOnCooldown(ItemReference ref) { - return mmoData.getCooldownMap().isOnCooldown(ref); + return getMMOPlayerData().getCooldownMap().isOnCooldown(ref); } /** @@ -355,7 +349,7 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { */ @Deprecated public void applyItemCooldown(ItemReference ref, double value) { - mmoData.getCooldownMap().applyCooldown(ref, value); + getMMOPlayerData().getCooldownMap().applyCooldown(ref, value); } /** @@ -363,7 +357,7 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable { */ @Deprecated public double getItemCooldown(ItemReference ref) { - return mmoData.getCooldownMap().getInfo(ref).getRemaining() / 1000d; + return getMMOPlayerData().getCooldownMap().getInfo(ref).getRemaining() / 1000d; } @NotNull diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerStats.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerStats.java index 9ba0c830..ecb50d73 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerStats.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerStats.java @@ -11,6 +11,7 @@ import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; import net.Indyuce.mmoitems.stat.type.AttackWeaponStat; import net.Indyuce.mmoitems.stat.type.ItemStat; +import org.jetbrains.annotations.NotNull; public class PlayerStats { private final PlayerData playerData; @@ -23,15 +24,17 @@ public class PlayerStats { return playerData; } + @NotNull public StatMap getMap() { return playerData.getMMOPlayerData().getStatMap(); } - public double getStat(ItemStat stat) { - return getMap().getInstance(stat.getId()).getTotal(); + public double getStat(@NotNull ItemStat stat) { + return getMap().getStat(stat.getId()); } - public StatInstance getInstance(ItemStat stat) { + @NotNull + public StatInstance getInstance(@NotNull ItemStat stat) { return getMap().getInstance(stat.getId()); } @@ -44,7 +47,8 @@ public class PlayerStats { * source will NOT be taken into account for stat calculation * @return */ - public PlayerMetadata newTemporary(EquipmentSlot castSlot) { + @NotNull + public PlayerMetadata newTemporary(@NotNull EquipmentSlot castSlot) { return playerData.getMMOPlayerData().getStatMap().cache(castSlot); } @@ -79,7 +83,7 @@ public class PlayerStats { } // Finally run a stat update after all modifiers have been gathered in the packet - packet.runUpdate(); + packet.update(); } } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Amphibian.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Amphibian.java index d5fc653a..494eb7d2 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Amphibian.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Amphibian.java @@ -186,7 +186,7 @@ public class Amphibian extends ChooseStat implements ItemRestriction, GemStoneSt } } - //BKK//MMOItems. Log("Total: \u00a7e" + ret.size() + "\u00a77 blocks."); + //BKK//MMOItems. Log("Tot: \u00a7e" + ret.size() + "\u00a77 blocks."); return ret; } } diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java index 77cc334d..df955431 100644 --- a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java @@ -37,6 +37,6 @@ public class MMOItemsBukkit { if (MythicLib.plugin.hasProfiles()) Bukkit.getPluginManager().registerEvents(new ProfileSupportListener(), plugin); - Bukkit.getScheduler().runTaskTimer(plugin, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).updateStats()), 100, 20); + Bukkit.getScheduler().runTaskTimer(plugin, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).timedRunnable()), 100, 20); } }