Entity Wither Constructor Undefined

Discussion in 'Plugin Development' started by Johnyeric, Jul 22, 2020.

  1. Offline

    Johnyeric

    Code:
    package me.John.TextBanners;
    
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
    import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.util.Vector;
    
    import net.minecraft.server.v1_16_R1.EntityWither;
    import net.minecraft.server.v1_16_R1.PacketPlayOutEntityDestroy;
    import net.minecraft.server.v1_16_R1.PacketPlayOutSpawnEntityLiving;
    import net.minecraft.server.v1_16_R1.WorldServer;
    
    public class Bar {
        private Player p;
        private String message;
        private EntityWither w;
    
        public Bar(Player p, String message) {
            this.p = p;
            this.message = message;
            update();
        }
     
        public void update() {
            Vector d = p.getLocation().getDirection();
            Location loc = p.getLocation().add(d.multiply(20));
            removeWither();
            WorldServer world = ((CraftWorld)loc.getWorld()).getHandle();
            w = new EntityWither(EntityType.WITHER, world);
            w.setLocation(loc.getX(), p.getLocation().getY(), loc.getZ(), loc.getPitch(), loc.getYaw());
            ((Player) w).setDisplayName(message);
            w.setInvisible(true);
            PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(w);
            ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
        }
     
        private void removeWither() {
            if (w!=null) {
                PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(w.getId());
                ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
            }
        }
    }
    in w=new EntityWither(...); it says the constructor is undefined. I have tried defining it with only "world", but it says it needs an entityType as well, so I tried this and it does not work. Eclipse proposes null for that spot which makes me run into NullPointerException. I am not exactly sure what entityType it wants me to use here, or even if I should make a constructor overriding this one

    EDIT

    Code:
    package me.John.TextBanners;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    public class PlayerJoin implements Listener {
       
        private Main banner;
    
        public PlayerJoin(Main banner) {
            this.banner = banner;
        }
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            banner.set(e.getPlayer());
        }
    }
    
    Apparently another NullPointerExeption exists here in PlayerJoin, specifically in banner.set(e.getPlayer());
     
    Last edited: Jul 23, 2020

Share This Page