At the moment I am trying to check if a human Entity is a Player or just a spawned Human. And if it IS a player, how can I convert it into a Player object the Human is?
Entity p2 = e.getTargetEntity();
if (p2 instanceof Human) {
if (!All.getClas((Player) p2).equals("assassin")) {
//code
}
wouldn’t just checking that the Entity is instanceof User (User instead of Player just to be on the safe side of checking … I.E. Im lazy)
A Human entity is not the same as a Player entity, so if it’s an instance of Human then it must have been a human spawned by a plugin.
The parent interface Humanoid represents both player and human entities, if you’re looking for a common interface.
1 Like
When I check what Entity is damaged, it also returns Human for me, and that’s my problem. I am cheking for getTargetEntity(). What can I do?
let me boot up my laptop and ill see what i can do. As @simon816 said, you should be able to check if the entity is Human you cast it to Human or Player,with the joining interface being Humaniod.
AKA all humans and players can cast to Humanoid, but a player shouldnt be able to be casted to Human and vice versa
The thing is, that I need a Player object for one of my methods.
can you tell me exactly what your trying to do? Are you trying to check what “Class” (type) a player is? and you don’t actually need the interaction with a normal un-manned human?
The class thing is for my RPG Plugin, and the code I provided at the top is in the Damage Event. I want to see if the Entity that is hurt is a player. If yes, I want to cancel the Damage if the Player has a specific class, in this case it’s the Assassin class.
In that case, change this check:
to
if (p2 instanceof Player) {
@Listener
public void onDamage(DamageEntityEvent event){
Entity entity = event.getTargetEntity();
if(!(entity instanceof Player)){
//this part of the code checks that the entity is not a player and then stops the rest of the event from moving on.
return;
}
Player player = (Player)entity;
//code here
//the entity has got to be a player from here on
}
edit, just put more comments on the code
I had this code and tried it, but it always stops because the Entity is always a Human and not a Player when I get damage. 
So your saying another player is damaging you and the code is coming up saying the target entity (in the case you put, you said I, so the target entity would be you) but the entity is returning human? and not Player?
Yes that is what happens. I am trying this with spawning a Zombie. When I damage the Zombie, the damaged Entity is Zombie and Damager is Player. For getting damaged it returns Human for Players, and I don’t know why. I am going to sleep soon, I’ll send my whole damage method tomorrow.
ill run some tests on the latest sponge and see if i can replicate it
1 Like
I can not replicate it with the latest 1.12 release. What MC version are you using?
@Fledron if this is what you are experiencing, and can create a tiny test plugin to reproduce it, please test on SpongeForge / SpongeVanilla if possible, and report on the appropriate bug tracker, along with the test code.
1.Bug on Both? New SpongeCommon Issue
2. Only on SpongeVanilla? New SpongeVanilla Issue
3. Only on SpongeForge? New SpongeForge Issue
4. Can’t test on both for some reason? New SpongeCommon Issue
I am using 1.11.2, since there are more other mods who upgraded to it than to 1.12. I will test it now again and see what happens, if you can’t reproduce it, I might have written crap-code somewhere else.
Okay I got it to work. I just rewrote my code, not much different and it works now. And I am NOT able to reproduce it somehow… I don’t know what I did wrong. 
Sorry for the inconveniences!
1 Like