Adding non-player skins to npc with citizens.

Discussion in 'Plugin Development' started by guitargun, Aug 3, 2015.

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

    guitargun

    so I tried asking fullwall for this yet I still don't get any results with it.
    he said that I can add the texture with the texture property to the gameprofile something which I already discovered. the problem I still have is getting the gameprofile from the npc.

    my npc spawn method:
    Code:
        public void spawnNpc(Location location, String name, int uniqueid,
                String skin) {
            NPCRegistry registry = CitizensAPI.getNPCRegistry();
            NPC npc = registry.createNPC(EntityType.PLAYER, name);
           
            //        npc.data().set(NPC.PLAYER_SKIN_UUID_METADATA,
    //                NPCSkin.getNonPlayerProfile(skin).getName());
           
            //this is the main problem getting the profile
             npc.spawn(location);
             CitizensNPC cnpc = (CitizensNPC) npc;
             EntityHumanNPC.PlayerNPC np = (EntityHumanNPC.PlayerNPC)  cnpc.getEntity();
             GameProfile pro  =np.getProfile();
            
             //yet setting the skin seems easy
             String n = npcskin.SetUrlBasedSkin(np.getProfile(), "guitargun");
             npc.data().set(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA, n);
             UUID npcuuid = npc.getUniqueId();
    
            spawnlocation.put(npcuuid, location);
            npclocation.put(npcuuid, location);
            if (uniqueid != -1) {
                uniquenpcid.put(uniqueid, npcuuid);
            } else {
                int id = 0;
                while (uniquenpcid.containsKey(id)) {
                    id++;
                }
                uniquenpcid.put(id, npcuuid);
            }
    
            npchear(npcuuid);
    
        }
    my skin set method:
    Code:
        private  String returnUrl(String name){
            switch(name){
            case "dawn_nl":
                return "https://i.imgur.com/wQg8efk.png";
            case "guitargun":
                return "https://i.imgur.com/dTmFuhw.png";
            default:
                return null;
            }
        }
       
        public  String  SetUrlBasedSkin(GameProfile prof, String name){
            String url = returnUrl(name);
            PropertyMap pm = prof.getProperties();
           
            if(pm == null){
                throw new IllegalArgumentException("Profile doesn't contain a property map");
            }
            byte[] encoded =  Base64Coder.encodeString("{textures:{SKIN:{url:\"" + url + "\"}}}").getBytes();
            pm.put("textures", new Property("textures", new String(encoded)));
            return url;
        }
    and yes I tested if the url from the string is not null
     
  2. Offline

    Tecno_Wizard

    @guitargun, sorry. Citizens clearly states in their wiki that is impossible to change the skin of a player because the skin is not handled by Bukkit, it is handled by the client and the client alone.
     
    Last edited: Aug 3, 2015
  3. Offline

    mine-care

    Also please fix your project to follow the naming conventions
     
  4. Offline

    guitargun

    @Tecno_Wizard yet you can make a npc which skin differs from the name you put in.
     
  5. Offline

    Totom3

    @guitargun The skin and the name of a player and NPC can be changed and do not need to match, but the skin must be an actual player's skin.
     
  6. Offline

    ComeFme

    Hey, do u know how to change the skin, casue I have no idea how to do it. I tried /npc skin, but it saids that the command doesn't exsit
     
Thread Status:
Not open for further replies.

Share This Page