Spawning EntityPlayer not working

Discussion in 'Plugin Development' started by Lickymoo, Sep 4, 2019.

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

    Lickymoo

    Hey guys, I have a system of spawning custom mobs, it works 100% fine for other entites, but for EntityPlayers it does not work.
    EntityTypes.spawnEntityEzmaroth() method
    Code:
        public static EntityEzmaroth spawnEntityEzmaroth(EntityEzmaroth entity, Location loc) {
            entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
            ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity);
            return entity;
        }
    registerEntity method, I have just a normal registerEntity class that takes Class<? extends EntityInsentient> but apparently EntityPlayer does not fall under that
    Code:
        public static void registerEntityPlayer(String name, int id, Class<? extends EntityPlayer> nmsClass, Class<? extends EntityPlayer> customClass){
            try{
                List<Map<?, ?>> dataMap = new ArrayList<Map<?, ?>>();
                for(Field f: EntityTypes.class.getDeclaredFields()){
                    if(f.getType().getSimpleName().equals(Map.class.getSimpleName())){
                        f.setAccessible(true);
                        dataMap.add((Map<?, ?>) f.get(null));
                    }
                }
                if(dataMap.size() > 3)
                if(dataMap.get(2).containsKey(id)){
                    dataMap.get(0).remove(name);
                    dataMap.get(2).remove(id);
                }
    
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    
    spawn function:
    Code:
     
        public void spawnEnemy(String enemy, Location loc, int amount, int level)
        {
         
            for(int i = 0; i < amount; i ++) {
                enemyObject en = new enemyObject(enemy, (int)enemyDatabaseManager.getEnemyType(enemy).healthOutput(level), level, (int)enemyDatabaseManager.getEnemyType(enemy).damageOutput(level));
                enemyDatabaseManager.getEnemyType(enemy).spawn(loc, en);
            }
    
        }
    
    actual class of custom mob
    Code:
    
    public class EntityEzmaroth extends EntityPlayer implements IenemyObject{
     
        public EntityEzmaroth(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile,
                PlayerInteractManager playerinteractmanager) {
            super(minecraftserver, worldserver, gameprofile, playerinteractmanager);
        }
    
        protected void initAttributes(){
            super.initAttributes();
            this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(0);
            this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(1);
        }
     
        public void apply(enemyObject en) {
            this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(en.damage);
            this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(en.maxHealth);
            this.setCustomNameVisible(true);
            this.setHealth((float)en.maxHealth);
            this.setCustomName(new ChatMessage("§8(§aLevel " + en.level + "§8) §7Ezmaroth §8(§a" + (int)en.maxHealth + "§8/§a" + (int) en.maxHealth + "§8)"));
        }
    }
    
    
    Code:
        public static EntityEzmaroth spawnEntityEzmaroth(EntityEzmaroth entity, Location loc) {
            entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
            ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity);
            return entity;
        }
    
    So i can spawn every other type of enemy fine but if i try to spawn this entityPlayer entity it does not work. Is there a special way i should be spawning it? the other classes are identical, aside from EntityZombie or whatever instead of EntityPlayer.

    --Edit within the spawn function of the enemyType class I ran a bukkit.broadCastMessage:
    Code:
            @Override
            public EntityEzmaroth spawn(Location loc, enemyObject en) { 
                enemyManager.registerEntityPlayer("Ezmaroth", 1, EntityPlayer.class, EntityEzmaroth.class);
                WorldServer Ws = ((CraftWorld) loc.getWorld()).getHandle();
                IenemyObject e = (IenemyObject) EntityTypes.spawnEntityEzmaroth(new EntityEzmaroth( ((MinecraftServer)((CraftServer) Bukkit.getServer()).getServer()), Ws, new GameProfile(Bukkit.getPlayer("Buby").getUniqueId(), "Buby"), new PlayerInteractManager(Ws)), loc);
                e.apply(en);
                Bukkit.broadcastMessage(e + "");
                return (EntityEzmaroth) e;
            }
    
    and it returns a proper mob with position etc meaning it has been spawned?
     
  2. Online

    timtower Administrator Administrator Moderator

    @Lickymoo Don't think that you can spawn players...
     
  3. Offline

    Lickymoo

    Isnt this how people make NPCS?
     
  4. Online

    timtower Administrator Administrator Moderator

    Why not use a library for it?
     
  5. Offline

    Lickymoo

    Trying to keep library use to a minimum since its a large plugin, but what are some suggestions? I've seen a few but most seem to be out of date. Couldnt find any others that are flexible enough aswell, so I thought that just making my own system would be better
     
  6. Online

    timtower Administrator Administrator Moderator

    https://github.com/CitizensDev/Citizens2
     
Thread Status:
Not open for further replies.

Share This Page