Fixed an issue with weapons taking away attributes

This commit is contained in:
Indyuce 2022-02-11 12:12:13 +01:00
parent c19f612928
commit cc7d4e8f20
12 changed files with 25 additions and 91 deletions

View File

@ -96,9 +96,9 @@ public class ItemStats {
UNBREAKABLE = new Unbreakable(),
TIER = new ItemTierStat(),
SET = new ItemSetStat(),
ARMOR = new Armor(),
ARMOR_TOUGHNESS = new ArmorToughness(),
MAX_HEALTH = new MaxHealth(),
ARMOR = new DoubleStat("ARMOR", VersionMaterial.GOLDEN_CHESTPLATE.toMaterial(), "Armor", new String[] { "The armor given to the holder." }),
ARMOR_TOUGHNESS = new DoubleStat("ARMOR_TOUGHNESS", Material.DIAMOND_CHESTPLATE, "Armor Toughness", new String[] { "Armor toughness reduces damage taken." }),
MAX_HEALTH = new DoubleStat("MAX_HEALTH", Material.GOLDEN_APPLE, "Max Health", new String[] { "The amount of health your", "item gives to the holder." }),
UNSTACKABLE = new Unstackable(),
MAX_MANA = new DoubleStat("MAX_MANA", VersionMaterial.LAPIS_LAZULI.toMaterial(), "Max Mana", new String[]{"Adds mana to your max mana bar."}),
KNOCKBACK_RESISTANCE = new KnockbackResistance(),

View File

@ -10,7 +10,7 @@ import io.lumine.mythic.lib.player.modifier.ModifierType;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.player.inventory.EquippedPlayerItem;
import net.Indyuce.mmoitems.stat.type.AttributeStat;
import net.Indyuce.mmoitems.stat.type.AttackWeaponStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
public class PlayerStats {
@ -75,8 +75,8 @@ public class PlayerStats {
ModifierSource source = type == null ? ModifierSource.OTHER : type.getItemSet().getModifierSource();
// Apply main hand weapon stat offset
if (item.getSlot() == EquipmentSlot.MAIN_HAND && stat instanceof AttributeStat)
value -= ((AttributeStat) stat).getOffset(playerData);
if (item.getSlot() == EquipmentSlot.MAIN_HAND && stat instanceof AttackWeaponStat)
value -= ((AttackWeaponStat) stat).getOffset(playerData);
packet.addModifier(new StatModifier("MMOItem-" + index++, stat.getId(), value, ModifierType.FLAT, item.getSlot(), source));
}

View File

@ -1,23 +1,15 @@
package net.Indyuce.mmoitems.manager;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.damage.DamageMetadata;
import io.lumine.mythic.lib.damage.DamageType;
import io.lumine.mythic.lib.player.PlayerMetadata;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ElementalAttack;
import net.Indyuce.mmoitems.api.ItemAttackMetadata;
import net.Indyuce.mmoitems.api.event.MMOItemsProjectileFireEvent;
import net.Indyuce.mmoitems.api.interaction.projectile.ArrowParticles;
import net.Indyuce.mmoitems.api.interaction.projectile.EntityData;
import net.Indyuce.mmoitems.api.interaction.projectile.ProjectileData;
import net.Indyuce.mmoitems.api.player.PlayerData;
import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -146,10 +138,8 @@ public class EntityManager implements Listener {
event.setDamage(damage);
// Remove projectile if it has no piercing anymore
if (projectile instanceof AbstractArrow) {
if (((AbstractArrow) projectile).getPierceLevel() > 1) { return; } }
unregisterCustomProjectile(projectile);
if (!(projectile instanceof AbstractArrow) && ((AbstractArrow) projectile).getPierceLevel() <= 1)
unregisterCustomProjectile(projectile);
}
// Unregister custom projectiles from the map

View File

@ -19,7 +19,6 @@ public class StatManager {
* individually to understand better
*/
private final Set<DoubleStat> numeric = new HashSet<>();
private final Set<AttributeStat> attributeBased = new HashSet<>();
private final Set<ItemRestriction> itemRestriction = new HashSet<>();
private final Set<ConsumableItemInteraction> consumableActions = new HashSet<>();
private final Set<PlayerConsumable> playerConsumables = new HashSet<>();
@ -42,14 +41,6 @@ public class StatManager {
return stats.values();
}
/**
* @return Collection of all stats which are based on vanilla player
* attributes like movement speed, attack damage, max health..
*/
public Set<AttributeStat> getAttributeStats() {
return attributeBased;
}
/**
* @return Collection of all numeric stats like atk damage, crit strike
* chance, max mana... which can be applied on a gem stone. This is
@ -122,9 +113,6 @@ public class StatManager {
if (stat instanceof DoubleStat && !(stat instanceof GemStoneStat) && stat.isCompatible(Type.GEM_STONE))
numeric.add((DoubleStat) stat);
if (stat instanceof AttributeStat)
attributeBased.add((AttributeStat) stat);
if (stat instanceof ItemRestriction)
itemRestriction.add((ItemRestriction) stat);

View File

@ -1,12 +0,0 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.type.AttributeStat;
import io.lumine.mythic.lib.version.VersionMaterial;
import org.bukkit.attribute.Attribute;
public class Armor extends AttributeStat {
public Armor() {
super("ARMOR", VersionMaterial.GOLDEN_CHESTPLATE.toMaterial(), "Armor", new String[] { "The armor given to the holder." },
Attribute.GENERIC_ARMOR);
}
}

View File

@ -1,12 +0,0 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.type.AttributeStat;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
public class ArmorToughness extends AttributeStat {
public ArmorToughness() {
super("ARMOR_TOUGHNESS", Material.DIAMOND_CHESTPLATE, "Armor Toughness",
new String[] { "Armor toughness reduces damage taken." }, Attribute.GENERIC_ARMOR_TOUGHNESS);
}
}

View File

@ -1,10 +1,10 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.type.AttributeStat;
import net.Indyuce.mmoitems.stat.type.AttackWeaponStat;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
public class AttackDamage extends AttributeStat {
public class AttackDamage extends AttackWeaponStat {
public AttackDamage() {
super("ATTACK_DAMAGE", Material.IRON_SWORD, "Attack Damage", new String[] { "The amount of damage", "your weapon deals." },
Attribute.GENERIC_ATTACK_DAMAGE);

View File

@ -1,10 +1,10 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.type.AttributeStat;
import net.Indyuce.mmoitems.stat.type.AttackWeaponStat;
import io.lumine.mythic.lib.version.VersionMaterial;
import org.bukkit.attribute.Attribute;
public class AttackSpeed extends AttributeStat {
public class AttackSpeed extends AttackWeaponStat {
public AttackSpeed() {
super("ATTACK_SPEED", VersionMaterial.LIGHT_GRAY_DYE.toMaterial(), "Attack Speed",
new String[] { "The speed at which your weapon strikes.", "In attacks/sec." }, Attribute.GENERIC_ATTACK_SPEED);

View File

@ -1,15 +1,12 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import net.Indyuce.mmoitems.stat.type.AttributeStat;
public class KnockbackResistance extends AttributeStat {
public class KnockbackResistance extends DoubleStat {
public KnockbackResistance() {
super("KNOCKBACK_RESISTANCE", Material.CHAINMAIL_CHESTPLATE, "Knockback Resistance", new String[] {
"The chance of your item to block the", "knockback from explosions, creepers...", "1.0 corresponds to 100%, 0.7 to 70%..." },
Attribute.GENERIC_KNOCKBACK_RESISTANCE);
"The chance of your item to block the", "knockback from explosions, creepers...", "1.0 corresponds to 100%, 0.7 to 70%..." });
}
@Override

View File

@ -1,13 +0,0 @@
package net.Indyuce.mmoitems.stat;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import net.Indyuce.mmoitems.stat.type.AttributeStat;
public class MaxHealth extends AttributeStat {
public MaxHealth() {
super("MAX_HEALTH", Material.GOLDEN_APPLE, "Max Health",
new String[] { "The amount of health your", "item gives to the holder." }, Attribute.GENERIC_MAX_HEALTH);
}
}

View File

@ -1,14 +1,11 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import net.Indyuce.mmoitems.stat.type.AttributeStat;
public class MovementSpeed extends AttributeStat {
public class MovementSpeed extends DoubleStat {
public MovementSpeed() {
super("MOVEMENT_SPEED", Material.LEATHER_BOOTS, "Movement Speed",
new String[] { "Movement Speed increase walk speed.", "Default MC walk speed: 0.1" }, Attribute.GENERIC_MOVEMENT_SPEED);
super("MOVEMENT_SPEED", Material.LEATHER_BOOTS, "Movement Speed", new String[] { "Movement Speed increase walk speed.", "Default MC walk speed: 0.1" });
}
@Override

View File

@ -5,16 +5,15 @@ import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
/**
* Attribute stats are also collected when registered in the StatManager because
* their corresponding player vanilla attributes must be updated when the player
* stat value changes.
* Since MMOItems 6.7 attribute stats are now fully handled by MythicLib.
*
* @author cympe
* @author jules
* @see {@link #getOffset(PlayerData)} for class use case
*/
public abstract class AttributeStat extends DoubleStat {
public abstract class AttackWeaponStat extends DoubleStat {
private final Attribute attribute;
public AttributeStat(String id, Material mat, String name, String[] lore, Attribute attribute) {
public AttackWeaponStat(String id, Material mat, String name, String[] lore, Attribute attribute) {
super(id, mat, name, lore, new String[]{"!consumable", "!block", "!miscellaneous", "all"});
this.attribute = attribute;
@ -40,7 +39,7 @@ public abstract class AttributeStat extends DoubleStat {
* This generated issues when MMOCore changed the player's base attribute
* value to non default values.
*
* @return Offset that need
* @return Offset that needs to be substract from the apparent stat value
*/
public double getOffset(PlayerData playerData) {
return playerData.getPlayer().getAttribute(attribute).getBaseValue();