Fixed NPE's with unconventional weapons

This commit is contained in:
Indyuce 2020-08-18 20:45:31 +02:00
parent 85bce6b2a5
commit cdc7b32edb
4 changed files with 8 additions and 7 deletions

View File

@ -135,6 +135,10 @@ public enum TypeSet {
this.attackHandler = attackHandler; this.attackHandler = attackHandler;
} }
public boolean hasAttackEffect() {
return attackHandler != null;
}
public void applyAttackEffect(CachedStats playerStats, LivingEntity target, Weapon weapon, ItemAttackResult result) { public void applyAttackEffect(CachedStats playerStats, LivingEntity target, Weapon weapon, ItemAttackResult result) {
attackHandler.apply(playerStats, target, weapon, result); attackHandler.apply(playerStats, target, weapon, result);
} }

View File

@ -4,7 +4,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils; import net.Indyuce.mmoitems.MMOUtils;
@ -67,7 +66,7 @@ public class Weapon extends UseItem {
return true; return true;
} }
public ItemAttackResult targetedAttack(CachedStats stats, LivingEntity target, EquipmentSlot slot, ItemAttackResult result) { public ItemAttackResult targetedAttack(CachedStats stats, LivingEntity target, ItemAttackResult result) {
// cooldown // cooldown
double attackSpeed = getNBTItem().getStat(ItemStat.ATTACK_SPEED); double attackSpeed = getNBTItem().getStat(ItemStat.ATTACK_SPEED);
@ -75,7 +74,7 @@ public class Weapon extends UseItem {
if (!hasEnoughResources(attackSpeed, CooldownType.ATTACK, true)) if (!hasEnoughResources(attackSpeed, CooldownType.ATTACK, true))
return result.setSuccessful(false); return result.setSuccessful(false);
if (!getNBTItem().getBoolean("MMOITEMS_DISABLE_ATTACK_PASSIVE")) if (!getNBTItem().getBoolean("MMOITEMS_DISABLE_ATTACK_PASSIVE") && getMMOItem().getType().getItemSet().hasAttackEffect())
getMMOItem().getType().getItemSet().applyAttackEffect(stats, target, this, result); getMMOItem().getType().getItemSet().applyAttackEffect(stats, target, this, result);
return result; return result;

View File

@ -5,7 +5,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.inventory.EquipmentSlot;
import com.evill4mer.RealDualWield.Api.PlayerDamageEntityWithOffhandEvent; import com.evill4mer.RealDualWield.Api.PlayerDamageEntityWithOffhandEvent;
@ -59,7 +58,7 @@ public class RealDualWieldHook implements Listener {
return; return;
} }
weapon.targetedAttack(stats = playerData.getStats().newTemporary(), target, EquipmentSlot.HAND, result.setSuccessful(true)); weapon.targetedAttack(stats = playerData.getStats().newTemporary(), target, result);
if (!result.isSuccessful()) { if (!result.isSuccessful()) {
event.setCancelled(true); event.setCancelled(true);
return; return;

View File

@ -145,7 +145,7 @@ public class ItemUse implements Listener {
return; return;
} }
weapon.targetedAttack(stats = playerData.getStats().newTemporary(), target, EquipmentSlot.HAND, result.setSuccessful(true)); weapon.targetedAttack(stats = playerData.getStats().newTemporary(), target, result);
if (!result.isSuccessful()) { if (!result.isSuccessful()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -169,7 +169,6 @@ public class ItemUse implements Listener {
* cast on-hit abilities and add the extra damage to the damage event * cast on-hit abilities and add the extra damage to the damage event
*/ */
result.applyEffects(stats == null ? stats = playerData.getStats().newTemporary() : stats, item, target); result.applyEffects(stats == null ? stats = playerData.getStats().newTemporary() : stats, item, target);
event.setDamage(result.getDamage()); event.setDamage(result.getDamage());
} }