Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The NPCs are invisible #124

Open
andrei923 opened this issue Oct 6, 2020 · 38 comments
Open

The NPCs are invisible #124

andrei923 opened this issue Oct 6, 2020 · 38 comments
Labels
bug Something isn't working

Comments

@andrei923
Copy link

andrei923 commented Oct 6, 2020

Describe the bug
The NPCs are invisible, only the hologram is shown.

Server version
Spigot-21fe707-e1ebe52 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
& spigot 1.16.3

To Reproduce

  • Create an NPC (The player must be offline when you create it! otherwise will work as expected.)
  • Join the server
  • Show the NPC to the player.

tested with npclib-plugin-2.10-SNAPSHOT.

@andrei923 andrei923 added the bug Something isn't working label Oct 6, 2020
@iSatnin9
Copy link

The exact same thing happens to me in version 1.16 I hope they fix it soon, it becomes impossible to use having this problem.

@ByteExceptionDE
Copy link

same here
tested with 2.9 and 2.10

@Mooselk
Copy link
Contributor

Mooselk commented Nov 17, 2020

Are you setting a skin when creating the npc? Or just a blank npc?

@andrei923
Copy link
Author

Yes, I'm setting skin for it.

npc.setLocation(loc)
npc.setSkin(skin)				
npc.create()

@iNezuko
Copy link

iNezuko commented Nov 19, 2020

Same for me, the name appears but the skin doesn't. It's invisible.

@Mooselk
Copy link
Contributor

Mooselk commented Nov 19, 2020

I'll look into it when I get the chance.

@Mooselk
Copy link
Contributor

Mooselk commented Nov 20, 2020

I can’t seem to replicate it, are you spawning in a bunch of npcs at a time? I.e. looping through a set of locations and creating an npc for each?

@andrei923 @iNezuko would you mind sharing your code?

@andrei923
Copy link
Author

andrei923 commented Nov 20, 2020

looping through a set of locations and creating an NPC for each?

yes, also make sure you(the player) are not online when creating them.

@iNezuko
Copy link

iNezuko commented Nov 20, 2020

I can’t seem to replicate it, are you spawning in a bunch of npcs at a time? I.e. looping through a set of locations and creating an npc for each?

@andrei923 @iNezuko would you mind sharing your code?

I'm using 1.16.4 (from the updated version someone shared on the issues). I'm using single NPC. Edit: oh it was you

https://pastebin.com/dYuXMJti

https://pastebin.com/nFSTyz70

My gamemode relies on NPCs made from packets. This lib seems to have saved my time, but yeah. If it's an issue of the version then I can downgrade to 1.16.2

I also tried changing the skin int and replacing it with Skin skin

@Mooselk
Copy link
Contributor

Mooselk commented Nov 20, 2020

looping through a set of locations and creating an NPC for each?

yes, also make sure you(the player) are not online when creating them.

I had this issue in the past, I believe it was a limitation of the mineskin api. I fixed the issue by serializing and saving the skin object in a config and retrieving it later so I only have to make the api call once.

Here’s my serializable skin class https://github.com/Mooselk/All-In-One-Lobby/blob/master/src/main/java/me/kate/lobby/npcs/api/skin/Skin.java

@Mooselk
Copy link
Contributor

Mooselk commented Nov 20, 2020

I can’t seem to replicate it, are you spawning in a bunch of npcs at a time? I.e. looping through a set of locations and creating an npc for each?
@andrei923 @iNezuko would you mind sharing your code?

I'm using 1.16.4 (from the updated version someone shared on the issues). I'm using single NPC. Edit: oh it was you

https://pastebin.com/dYuXMJti

https://pastebin.com/nFSTyz70

My gamemode relies on NPCs made from packets. This lib seems to have saved my time, but yeah. If it's an issue of the version then I can downgrade to 1.16.2

I also tried changing the skin int and replacing it with Skin skin

That’s very strange, do you have the same issue if you create the skin object manually? You can do this by copy pasting the signature and value from mineskin and creating the skin object Skin(value, signature)

@iNezuko
Copy link

iNezuko commented Nov 21, 2020

That’s very strange, do you have the same issue if you create the skin object manually? You can do this by copy pasting the signature and value from mineskin and creating the skin object Skin(value, signature)

Yes I did it with Skin skin =
I'll try the one from your code in a second.

@iNezuko
Copy link

iNezuko commented Nov 21, 2020

That’s very strange, do you have the same issue if you create the skin object manually? You can do this by copy pasting the signature and value from mineskin and creating the skin object Skin(value, signature)

Loaded class net.jitse.npclib.api.skin.Skin from NPCLibPlugin v2.9.1-SNAPSHOT which is not a depend, softdepend or loadbefore of this plugin.

I have added Depend on npclib and put it inside plugins folder (also before shaded it in maven but I undid it)

My code looks like this: https://pastebin.com/mtvZes5q

Still invisible.

Edit: I have changed from Depend to depend. The error vanished, but the skin still doesnt show up

Edit: It seems to not even create the NPC as it's not showing a Hitbox, or maybe because it's packets. I don't know how it works yet. https://gyazo.com/3a1a37619fcd8fa3a3963ec1cdfad0cc

Edit: I removed the setskin code and the NPC still wont show.

Edit: I downgraded the versions to 1.16.2 and used supporting version. Still throws error. Has to be something wtih code.

Edit!: I tried checking if npc is created and shown. It returns true for "created" and false for shown. Then I tried showing it against and got Task #2571 for SWSettlements v1.0-SNAPSHOT generated an exception
java.lang.IllegalArgumentException: NPC is already shown to player

@iNezuko
Copy link

iNezuko commented Nov 21, 2020

That’s very strange, do you have the same issue if you create the skin object manually? You can do this by copy pasting the signature and value from mineskin and creating the skin object Skin(value, signature)

My code now I took from "examples" the author of this lib did. It works and spawned the NPC.

https://pastebin.com/pS1s26Ks

@Mooselk
Copy link
Contributor

Mooselk commented Nov 22, 2020

My code now I took from "examples" the author of this lib did. It works and spawned the NPC.

https://pastebin.com/pS1s26Ks

Good to here that it’s working now, still confused as to why it wasn’t before.

@Mooselk
Copy link
Contributor

Mooselk commented Nov 22, 2020

@andrei923 looks like it was an issue with rate limiting, especially if your loading the npcs again and again. Each request for a given skin has a 60 second cool down.

I’d recommend serializing and saving your skins so you only need to make the api call once.

@iNezuko
Copy link

iNezuko commented Nov 22, 2020

Good to here that it’s working now, still confused as to why it wasn’t before.

I'm p sure the NPC has to be created when the player is on the server. Or like couple minutes after start.

@andrei923
Copy link
Author

is not related to the skin, tried without setting the skin, the same result, the bug was added in 2.8

@andrei923
Copy link
Author

Good to here that it’s working now, still confused as to why it wasn’t before.

I'm p sure the NPC has to be created when the player is on the server.

that's the bug, meaning that you have to create an NPC every time a player joins.

@iNezuko
Copy link

iNezuko commented Nov 22, 2020

that's the bug, meaning that you have to create an NPC every time a player joins.

Works for me as I'd make them spawn like this anyways. Hope you can figure it out soon

I’d recommend serializing and saving your skins so you only need to make the api call once.

Would it work with saving the data of the skin. Value and signature? How it would look like in the code?

@Mooselk
Copy link
Contributor

Mooselk commented Nov 22, 2020

Would it work with saving the data of the skin. Value and signature? How it would look like in the code?

You’d just need to save the value and signature under the id so you can grab it later.

Here’s my skin class https://github.com/Mooselk/All-In-One-Lobby/blob/master/src/main/java/me/kate/lobby/npcs/api/skin/Skin.java

And fetching methods https://github.com/Mooselk/All-In-One-Lobby/blob/master/src/main/java/me/kate/lobby/cache/SkinCache.java

@Mooselk
Copy link
Contributor

Mooselk commented Nov 22, 2020

is not related to the skin, tried without setting the skin, the same result, the bug was added in 2.8

I need to see how you’re showing the npc, I’m still unable to replicate your issue.

Have you tried hiding and unhiding the npc? I’m trying to narrow this down as much as possible before I go digging.

@andrei923
Copy link
Author

is not related to the skin, tried without setting the skin, the same result, the bug was added in 2.8

I need to see how you’re showing the npc, I’m still unable to replicate your issue.

Have you tried hiding and unhiding the npc? I’m trying to narrow this down as much as possible before I go digging.

yes, the NPC is still hidden, it throws the "NPC is already shown to player" error, the hologram works.

@sam302rk
Copy link
Contributor

Creating a new NPC Object for every player and using the code from #130 worked for me. It seems, like it's a issue with the NPCs getting created before the skin finished downloading... 🤔

@andrei923
Copy link
Author

Creating a new NPC Object for every player and using the code from #130 worked for me. It seems like it's an issue with the NPCs getting created before the skin finished downloading... 🤔

it's not related to the skin, you don't need to set the skin to reproduce it.
2020-12-16_14 52 47

@sam302rk
Copy link
Contributor

sam302rk commented Dec 16, 2020 via email

@andrei923
Copy link
Author

andrei923 commented Dec 22, 2020

Creating a new NPC Object for every player and using the code from #130 worked for me.

this.

@sam302rk
Copy link
Contributor

Creating a new NPC Object for every player and using the code from #130 worked for me.

this.

what do you mean?

@JitseB
Copy link
Owner

JitseB commented Dec 27, 2020

Please note that showing the NPCs to the players async results in strange behavior like this. Always make sure that player related mechanics act on the main server thread!

@andrei923
Copy link
Author

Version 2.7.2 works as it should, In 2.8 it doesn't.

@vytskalt
Copy link

vytskalt commented Mar 9, 2021

Still an issue in the latest version.

@RiverThrough
Copy link

Can confirm, brand new user here running Paper Version 495 1.16.5-R0.1-Snapshot and NPCLibPlugin 2.11.1-Snapshot when I spawn a npc on server start it will appear invisible even if spawned with no skin. Weird thing is if I reload the plugin (Using PlugMan) the npc will become visible so I thought maybe spawning the npc right as the server started was causing this somehow and tried using a delayed task but no luck there, I ended up trying what someone recommended here which is to spawn an npc for each individual player when they join and that works fine, its messy and I assume not very efficient but for now it is a temporary fix I hope.

@Mooselk
Copy link
Contributor

Mooselk commented Mar 18, 2021

for (NPC npc : NPCManager.getAllNPCs())
{
	if (!npc.isCreated())
		npc.create();
			
	npc.show(event.getPlayer());
}

I solved this issue in 1.16.5 by running the following code on player join.

@andrei923
Copy link
Author

for (NPC npc : NPCManager.getAllNPCs())
{
	if (!npc.isCreated())
		npc.create();
			
	npc.show(event.getPlayer());
}

I solved this issue in 1.16.5 by running the following code on player join.

the player must be offline to reproduce it.

  • create npc
  • join server
  • show npc

@Mooselk
Copy link
Contributor

Mooselk commented Mar 19, 2021

I'm giving people a solution. I created the NPC object while the server is starting, and ran npc#create and npc#show on join. I can't find a way to fix it properly, I don't know if there is.

I think the issue lies somewhere between sending the packets and there being no players to receive them.

@RiverThrough
Copy link

RiverThrough commented Mar 19, 2021

I'm giving people a solution. I created the NPC object while the server is starting, and ran npc#create and npc#show on join. I can't find a way to fix it properly, I don't know if there is.

Yeah your fix is much better than creating individual npcs for every player which was the solution I went with before, I will note that I ran into an null error with isCreated() but it has to do with how I define the npc variable, I define the npc in the class with like:
public NPC examplenpc;
so instead of doing
if(!examplenpc.isCreated())

I switched it to

if(examplenpc != null)

I'm assuming the difference is how we are initially defining our npc variable, here is my final improvised example from your solution which works great in case anyone finds it useful:

public NPC woodcuttingnpc;
@EventHandler
public void OnJoin(PlayerJoinEvent event){
    if(woodcuttingnpc != null){
        woodcuttingnpc.show(event.getPlayer());
    }else{
        Skin skin = new Skin("ewogICJ0aW1lc3RhbXAiIDogMTYxNjExNTcwNj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PIZC9lyFivoMZ+SFxpD9xD3+gVRnzjjxQm0VLnDm2GEt6fj7MOLCmY6dvY=");
        int skinID = 962200259;
        Location loc = new Location(Bukkit.getWorld("world"), -500.443, 65, -149.591, -179, 4);
        //NPC dmv = null;
        woodcuttingnpc = plugin.getNPCLib().createNPC(Arrays.asList("§e§lRobin", "§7Right Click to Interact"));
        woodcuttingnpc.setSkin(skin);
        woodcuttingnpc.setLocation(loc);
        woodcuttingnpc.create();
        woodcuttingnpc.show(event.getPlayer());
    }
}

@Mooselk
Copy link
Contributor

Mooselk commented Mar 22, 2021

I'm giving people a solution. I created the NPC object while the server is starting, and ran npc#create and npc#show on join. I can't find a way to fix it properly, I don't know if there is.

Yeah your fix is much better than creating individual npcs for every player which was the solution I went with before, I will note that I ran into an null error with isCreated() but it has to do with how I define the npc variable, I define the npc in the class with like:
public NPC examplenpc;
so instead of doing
if(!examplenpc.isCreated())

I switched it to

if(examplenpc != null)

I'm assuming the difference is how we are initially defining our npc variable, here is my final improvised example from your solution which works great in case anyone finds it useful:

public NPC woodcuttingnpc;
@EventHandler
public void OnJoin(PlayerJoinEvent event){
    if(woodcuttingnpc != null){
        woodcuttingnpc.show(event.getPlayer());
    }else{
        Skin skin = new Skin("ewogICJ0aW1lc3RhbXAiIDogMTYxNjExNTcwNjE5OSwKICAicHJvZmlsZUlkIiA6ICJjNjc3MGJjZWMzZjE0ODA3ODc4MTU0NWRhMGFmMDI1NCIsCiAgInByb2ZpbGVOYW1lIiA6ICJDVUNGTDE2IiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2Q1ZWQ4MDk3ZTM0YThmMGJkNDZlNzY2MTkwYzNhOWY2ODNiYThkODBjM2FiM2RiZTYwMWI1ZDU4ZWQ3MjEwMGUiLAogICAgICAibWV0YWRhdGEiIDogewogICAgICAgICJtb2RlbCIgOiAic2xpbSIKICAgICAgfQogICAgfQogIH0KfQ==", "HCPbYqjTkLRgm2VpvkCj9OMIibZCZIpJ7qd/yb5TtZdriX4T5YFYB1pUwnP/wSPHXU9eDwqYHP32G5kiXLV7W4GrTqRT55t1dtDE0l4nHzLNMFVZZDuZ9/DGCTPGdWZ2ACfijiQ+KRE3n5mrWNIG88m0GAQuwIp5WmoIPRcdEyBZieruU8Mqb6Rnk/xusJwHdj4YLZFT0HMpm2dJGnUhVNA5ZD59MMFb4bByMeQX7NHChqYxGkPyg5WIrTRDE4lfRleOOm7ZYKDsDiNGof9xytmQhGVk+BeOTqnSq2Yo2NDc/2Ag6QVYrdpFmSnSjvb2hpxAF2H0SMb0rGZDNqD8ASY0MI2LgZo95acTO9yWV5ep32ykbmUCEDuJmPbbbKiJqifiZzkPbZOihifwoVhEvFrFLBYcWdJmsCmaBeNQHbnGR5flbhR+8mY7+L7EHQndUEAc7juAGVFjWSc8DG4Wsy16eozuDSrc3YcY7ymszN2ol/VqdAt1hdhwOzcaGFBkrXJQ/t+1Dlpb4+n6Wk3Fezi+Hq7Ln74x/PahyV2SoQriEERYlikV6xj1V+4W4wTwFihqs+uH8UxAkJYq6W5wjBlF6zDwK3+bip52a+RuCYTENdrfOPIZC9lyFivoMZ+SFxpD9xD3+gVRnzjjxQm0VLnDm2GEt6fj7MOLCmY6dvY=");
        int skinID = 962200259;
        Location loc = new Location(Bukkit.getWorld("world"), -500.443, 65, -149.591, -179, 4);
        //NPC dmv = null;
        woodcuttingnpc = plugin.getNPCLib().createNPC(Arrays.asList("§e§lRobin", "§7Right Click to Interact"));
        woodcuttingnpc.setSkin(skin);
        woodcuttingnpc.setLocation(loc);
        woodcuttingnpc.create();
        woodcuttingnpc.show(event.getPlayer());
    }
}

I'm not creating an npc per person, just running the method npc#create on join. npc#create is the method that sends the packets to spawn the npc, but I guess your solution works too.

@Sculas
Copy link

Sculas commented Apr 2, 2021

I'm giving people a solution. I created the NPC object while the server is starting, and ran npc#create and npc#show on join. I can't find a way to fix it properly, I don't know if there is.

Yeah your fix is much better than creating individual npcs for every player which was the solution I went with before, I will note that I ran into an null error with isCreated() but it has to do with how I define the npc variable, I define the npc in the class with like:
public NPC examplenpc;
so instead of doing
if(!examplenpc.isCreated())

I switched it to

if(examplenpc != null)

I'm assuming the difference is how we are initially defining our npc variable, here is my final improvised example from your solution which works great in case anyone finds it useful:

public NPC woodcuttingnpc;
@EventHandler
public void OnJoin(PlayerJoinEvent event){
    if(woodcuttingnpc != null){
        woodcuttingnpc.show(event.getPlayer());
    }else{
        Skin skin = new Skin("ewogICJ0aW1lc3RhbXAiIDogMTYxNjExNTcwNjE5OSwKICAicHJvZmlsZUlkIiA6ICJjNjc3MGJjZWMzZjE0ODA3ODc4MTU0NWRhMGFmMDI1NCIsCiAgInByb2ZpbGVOYW1lIiA6ICJDVUNGTDE2IiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2Q1ZWQ4MDk3ZTM0YThmMGJkNDZlNzY2MTkwYzNhOWY2ODNiYThkODBjM2FiM2RiZTYwMWI1ZDU4ZWQ3MjEwMGUiLAogICAgICAibWV0YWRhdGEiIDogewogICAgICAgICJtb2RlbCIgOiAic2xpbSIKICAgICAgfQogICAgfQogIH0KfQ==", "HCPbYqjTkLRgm2VpvkCj9OMIibZCZIpJ7qd/yb5TtZdriX4T5YFYB1pUwnP/wSPHXU9eDwqYHP32G5kiXLV7W4GrTqRT55t1dtDE0l4nHzLNMFVZZDuZ9/DGCTPGdWZ2ACfijiQ+KRE3n5mrWNIG88m0GAQuwIp5WmoIPRcdEyBZieruU8Mqb6Rnk/xusJwHdj4YLZFT0HMpm2dJGnUhVNA5ZD59MMFb4bByMeQX7NHChqYxGkPyg5WIrTRDE4lfRleOOm7ZYKDsDiNGof9xytmQhGVk+BeOTqnSq2Yo2NDc/2Ag6QVYrdpFmSnSjvb2hpxAF2H0SMb0rGZDNqD8ASY0MI2LgZo95acTO9yWV5ep32ykbmUCEDuJmPbbbKiJqifiZzkPbZOihifwoVhEvFrFLBYcWdJmsCmaBeNQHbnGR5flbhR+8mY7+L7EHQndUEAc7juAGVFjWSc8DG4Wsy16eozuDSrc3YcY7ymszN2ol/VqdAt1hdhwOzcaGFBkrXJQ/t+1Dlpb4+n6Wk3Fezi+Hq7Ln74x/PahyV2SoQriEERYlikV6xj1V+4W4wTwFihqs+uH8UxAkJYq6W5wjBlF6zDwK3+bip52a+RuCYTENdrfOPIZC9lyFivoMZ+SFxpD9xD3+gVRnzjjxQm0VLnDm2GEt6fj7MOLCmY6dvY=");
        int skinID = 962200259;
        Location loc = new Location(Bukkit.getWorld("world"), -500.443, 65, -149.591, -179, 4);
        //NPC dmv = null;
        woodcuttingnpc = plugin.getNPCLib().createNPC(Arrays.asList("§e§lRobin", "§7Right Click to Interact"));
        woodcuttingnpc.setSkin(skin);
        woodcuttingnpc.setLocation(loc);
        woodcuttingnpc.create();
        woodcuttingnpc.show(event.getPlayer());
    }
}

Your solution works, yes. But it might be better to let @JitseB fix this issue, one attempt to fix this could also be to delay the show method on the player by 1 tick on joining. That's to make sure the player has joined and loaded the world since that might be the root cause. Because, yes.. the server can throw packets at the client whenever it wants to. But the client also has to accept the packets and actually do something with them! So if the client receives an entity packet while it hasn't even loaded the world yet, it might just drop that packet and thus the NPC won't exist for the client because this library is packet-based, and thus the NPC only exists on the client; NOT the server!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants