Hostile Pets?

Discussion in 'Spigot Plugin Development' started by MaxNatural, May 30, 2016.

  1. I have this class and was wondering how to make it so he won't attack the owner or any other players.

    Code (Text):

    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;


    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");
            Hub.ZombiePet.put(player.getName(), entity);
        public void followPlayer(Creature creature, Player player, double Speed) {
            Location loc = player.getLocation();
            Random rnd = new Random();
            int nofall = rnd.nextInt(6);
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            if (loc.distanceSquared(creature.getLocation()) > 100) {
                if (!player.isOnGround()) {
            } else {
  2. NMS EW
    • Optimistic Optimistic x 1
  3. some more information please
  4. You could detect whether the target of the mob is a player who put NULL target
    Code (Text):
    if (entity.getTarget().getType() == EntityType.Player) {
  5. then the mob don't will attack the player?
  6. 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.
    • Agree Agree x 1
  7. You can always deny the pet from targeting players in an EntityTargetEvent.
  8. You can use this method.

    EDIT: Will not work if you're setting the navigation, missed that part in your post.
    #9 Msrules123, May 30, 2016
    Last edited: May 30, 2016
  9. This makes the Entity not move at all. I don't think that he is going for that.
  10. Didn't catch the part where he messed with the Entity's navigation, only saw him teleporting. Fixed original post.
  11. 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.
  12. EntityTargetEvent
  13. 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
  14. 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:
    • Funny Funny x 1
  15. "Really hard to do"? NMS is really simple if you have basic Java knowledge lol.
    • Agree Agree x 1
  16. 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...
  17. [​IMG]
    • Funny Funny x 3
    • Like Like x 1
    • Winner Winner x 1
  18. αρχείο λήψης.jpg
  19. He's not wrong mate. You should get started with Java programming before you go straight to plugin development. Just saying.
    • Optimistic Optimistic x 1