#Console spam

1 messages · Page 1 of 1 (latest)

deft raptor
#

Console is spammed whenever a player clicks an item within their inventory. My code checks for whether the player has a full armour of a specific set "divnium armour" or whether they have a specific helmet. And im assuming the spam is from it constantly checking whether the helmet or the full armour is being used is their anyway to fix this

compact onyxBOT
deft raptor
#

import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.meta.ItemMeta;

public class CheckHelm implements Listener {

    public static boolean checkHelm(Player p, String s) {

        if(p.getInventory().getHelmet() == null ) {
            return false;
        }
        if(p.getInventory().getHelmet().getItemMeta() == null ) {
            return false;
        }

        ItemMeta helmMeta = p.getInventory().getHelmet().getItemMeta();


        if (helmMeta.getLore().contains(s)) {
            return true;

        }
        return false;
    }

}
#

^ my code

#
05.07 02:03:31 [Server] [INFO] java.lang.NullPointerException: Cannot invoke "java.util.List.contains(Object)" because the return value of "org.bukkit.inventory.meta.ItemMeta.getLore()" is null
05.07 02:03:31 [Server] [INFO] at me.oxid.myfirstplugin.CheckHelm.checkHelm(CheckHelm.java:21) ~[MyFirstPlugin (1).jar:?]
05.07 02:03:31 [Server] [INFO] at me.oxid.myfirstplugin.events.FishingHelmetBonus.fishinghelmetbonus(FishingHelmetBonus.java:17) ~[MyFirstPlugin (1).jar:?]```
#

It works just spams the console tho

sullen forge
#

your item's lore is null

#

check if helpMeta.hasLore() or helpMeta.getLore() != null

deft raptor
#

import me.oxid.myfirstplugin.CheckSet;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class DiviniumBonus implements Listener {
    @EventHandler
    public void diviniumbonus (InventoryClickEvent e) {
        Player p = (Player) e.getWhoClicked();
        if (p instanceof Player) {
            if (CheckSet.checkSet(p,"§7§7Equip full set for damage resistance")) {
                p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1, false, false));
            } else if (!CheckSet.checkSet(p,"§7§7Equip full set for damage resistance")) {
                p.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
            }
        }
    }

}```
#

the lore is there '!CheckSet.checkSet(p,"§7§7Equip full set for damage resistance") "

sullen forge
#

add a null check just in case ¯_(ツ)_/¯

#

could prevent issues if a player clicks on a helmet with no lore

deft raptor
#

oh yes i forgot to update

#

because vanilla items don’t have lite

#

the game would produce and error as vanilla items don’t have more zbd therefore spamming the console