I have this class and was wondering how to make it so he won't attack the owner or any other players. Code (Text): package crafthappy.me.max.pets; import java.util.Random; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftCreature; import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; import crafthappy.me.max.hub.Hub; public class ZombiePet implements Listener{ public ZombiePet() { } public ZombiePet(Hub hub) { // TODO Auto-generated constructor stub } public void createPet(Player player, EntityType type) { Entity entity = (Entity) player.getWorld().spawnEntity(player.getLocation(), type); entity.setCustomName(ChatColor.AQUA + "" + ChatColor.BOLD + player.getName() + "'s Zombie"); entity.setCustomNameVisible(true); entity.setInvulnerable(true); Hub.ZombiePet.put(player.getName(), entity); } public void followPlayer(Creature creature, Player player, double Speed) { Location loc = player.getLocation(); creature.setLeashHolder(player); creature.setFireTicks(0); creature.setFireTicks(0); Random rnd = new Random(); int nofall = rnd.nextInt(6); switch(nofall){ case 0: loc.add(1.5,0,1.5); break; case 1: loc.add(0,0,1.5); break; case 2: loc.add(1.5,0,0); break; case 3: loc.subtract(1.5,0,1.5); break; case 4: loc.subtract(0,0,1.5); break; case 5: loc.subtract(1.5,0,0); break; } if (loc.distanceSquared(creature.getLocation()) > 100) { if (!player.isOnGround()) { return; } creature.teleport(loc); } else { ((CraftCreature)creature).getHandle().getNavigation().a(loc.getX(),loc.getY(),loc.getZ(),Speed); } } }
You could detect whether the target of the mob is a player who put NULL target Code (Text): if (entity.getTarget().getType() == EntityType.Player) { entity.setTarget(null); }
Rofl, people like you shouldn't be here. Nms is fine, the only problem with it is that it doesn't work through version changes. It's still better than reflection. He's here for help, not to get bashed on. If I took a look at the code in your resources I could easily find many many things wrong with it.
You can use this method. EDIT: Will not work if you're setting the navigation, missed that part in your post.
Didn't catch the part where he messed with the Entity's navigation, only saw him teleporting. Fixed original post.
He also follows the player but if another player is in survival it will attack him. Is there a way to make the entity think that all other players are in creative mode? They just don't attack.
Create custom zombie entity clear its goals and add the ones you want or use entitytargetevent if you don't want to go the NMS way
Since I read all the comments I had to help this guy... There is a thing called PathfinderGoals which is really hard to do especially if you aren't doing to make this plugin for your server but for a plugin you are gonna upload, because by itself it won't support every avaliable spigot version but only the api version you have loaded on your ide so you will have to use reflection but anyways this might help you:https://www.spigotmc.org/threads/tutorial-creating-custom-entities-with-pathfindergoals.18519/
It is just my opinion can you shut up God of java? You are not helping the situation at all by saying it is so ezzz for me...
He's not wrong mate. You should get started with Java programming before you go straight to plugin development. Just saying.