Leashing an Entity to a fence (1.9)

Discussion in 'Plugin Development' started by Koningpeter, Jun 10, 2016.

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

    Koningpeter

    Hi all,

    I need help with a plugin that leash an entity to a fence.
    But when I use the command I get a NullPointerException on line 8.

    My current code:
    Code:
    if(label.equalsIgnoreCase("test")) {
                Player p = (Player) sender;
                Location l = p.getLocation();
                Location el = p.getLocation().add(5, 0, 0);
              
                l.getBlock().setType(Material.FENCE);
       
                LeashHitch leash = p.getWorld().spawn(l, LeashHitch.class);
       
                Cow cow = p.getWorld().spawn(el, Cow.class);
                cow.setLeashHolder(leash);
            }
    Does anyone know how to solve this?
    Thanks
     
  2. Offline

    Zombie_Striker

    Use cmd.getName() instead of label. Label is only there for backwards compatibility.

    Are you sure the location is not null? Are you sure the world is not null? Have you debugged?
     
  3. Offline

    Koningpeter

  4. Offline

    Zombie_Striker

    @Koningpeter
    Does that mean that the world is null? Have you tried using the .spawnEntity() method instead?
     
  5. Offline

    Koningpeter

    @Zombie_Striker
    Nope, the location isn't null. I've tried, but .spawnEntity() don't work...
     
Thread Status:
Not open for further replies.

Share This Page