Errors in Console

Discussion in 'Plugin Help/Development/Requests' started by shotgun528, Apr 9, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    I develope now a Villager Inventory ...

    If i click on my developed Villager i dont get Errors! but if i click on Villagers that have Custom Names or other normal Villagers i get This Error:

    [13:07:39 ERROR]: Could not pass event PlayerInteractEntityEvent to GreenlandCore v0.4
    at$1.execute( ~[spigot.jar:git-Spigot-8a983f9-e81edfc]
    at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot.jar:git-Spigot-8a983f9-e81edfc]
    at org.bukkit.plugin.SimplePluginManager.fireEvent( [spigot.jar:git-Spigot-8a983f9-e81edfc]
    at org.bukkit.plugin.SimplePluginManager.callEvent( [spigot.jar:git-Spigot-8a983f9-e81edfc]
    at net.minecraft.server.v1_8_R1.PlayerConnection.a( [spigot.jar:git-Spigot-8a983f9-e81edfc]
    at net.minecraft.server.v1_8_R1.PacketPlayInUseEntity.a(SourceFile:52) [spigot.jar:git-Spigot-8a983f9-e81edfc]
    at net.minecraft.server.v1_8_R1.PacketPlayInUseEntity.a(SourceFile:11) [spigot.jar:git-Spigot-8a983f9-e81edfc]
    at [spigot.jar:git-Spigot-8a983f9-e81edfc]
    at java.util.concurrent.Executors$ [?:1.8.0_40]
    at [?:1.8.0_40]
    at net.minecraft.server.v1_8_R1.MinecraftServer.z( [spigot.jar:git-Spigot-8a983f9-e81edfc]
    at net.minecraft.server.v1_8_R1.DedicatedServer.z( [spigot.jar:git-Spigot-8a983f9-e81edfc]
    at net.minecraft.server.v1_8_R1.MinecraftServer.y( [spigot.jar:git-Spigot-8a983f9-e81edfc]
    at [spigot.jar:git-Spigot-8a983f9-e81edfc]
    at [?:1.8.0_40]
    Caused by: java.lang.NullPointerException
    at Listener.VillagerClass.onInteract( ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.8.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.8.0_40]
    at java.lang.reflect.Method.invoke( ~[?:1.8.0_40]
    at$1.execute( ~[spigot.jar:git-Spigot-8a983f9-e81edfc]
    ... 14 more

    and The code is:

    package Listener;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Villager;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import Main.Main;
    public class VillagerClass implements Listener{
    private Main plugin;
        public VillagerClass(Main plugin) {
            this.plugin = plugin;
        public void onInteract(PlayerInteractEntityEvent e){
            Villager v = (Villager) e.getRightClicked();
            if(v.getCustomName().equalsIgnoreCase("§c§lShop assistant")){
                Inventory inv = Bukkit.createInventory(null, 9, "Shop");
                inv.setItem(0, new ItemStack(Material.DIAMOND));
                inv.setItem(1, new ItemStack(Material.DIRT, 100));
  2. @shotgun528 If the villager does not have a custom name, it will return null. (Check if the custom name is null first)
    CrystallFTW likes this.
  3. According to what @DJSkepter said, you can use this nice trick, to prevent that.
    If the string (custom name) is null, none of the methods (for example .equalsIgnoreCase) will work. But if you use the method for a valid string ("§c§lShop assistant") it will work :D
    Here is an example:
    1. if ("§c§lShop assistant".equalsIgnoreCase(v.getCustomName()) {
  4. Offline


    Also make sure e.getRightClicked is an instance of Villager and not a Zombie or so.
    But for this code you don't even have to cast it to Villager.

    @shotgun528 @shotgun528
Thread Status:
Not open for further replies.

Share This Page