Posted July 7, 201510 yr I want to get an entity with a custom name, I manage to get a list of the entity on world but when i try to single out the entity i want i cant do it. I try setting .contain to get the entity displayname but it always go to the else statement screenshot of entity on the world: http://prntscr.com/7ppth1 System.out.println(world.loadedEntityList) outputs: [EntitySlime['Slime'/0, l='New World', x=405.27, y=1.00, z=-433.02], EntityOfflinePlayer['Player109'/1, l='New World', x=420.62, y=1.00, z=-436.08], EntityPlayerMP['Player13'/2, l='New World', x=423.97, y=1.00, z=-432.51]] result: Sysout shows "Not Detected" as stated in the else statement EntityPlayer player = e.player; World world = player.getEntityWorld(); EntityOfflinePlayer offline = new EntityOfflinePlayer(player.getEntityWorld(), player.posX, player.posY, player.posZ); PlayerData data = new PlayerData(); System.out.println(world.loadedEntityList); if(world.loadedEntityList.contains("Player109")) { System.out.println("Have character"); } else { System.out.println("Not Detected"); }
July 7, 201510 yr Ignoring other things in your code for now, your problem is that the loaded entity List is a List of Entity objects, not Strings, so calling contains("someString") on it cannot possibly return true. You have to iterate through each entry and compare the entity's custom name tag (or command sender name, since you're dealing with players) to the name you expect. Also, if you are only interested in players, you should use the List referenced by worldObj.playerEntities, and if the player is in game already, you can use the World#getPlayerEntityByName method directly rather than iterating through a list yourself. http://i.imgur.com/NdrFdld.png[/img]
July 7, 201510 yr Author Thank you, the entity I'm looking for is actually a custom mob that is spawned into the world every time a player logs off and the Entity is called OfflinePlayerEntity ^^
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.