Esempio n. 1
0
 /**
  * Opens the Pet Data GUI Menu
  *
  * @param player {@link org.bukkit.entity.Player} to view the Menu
  * @param sendMessage defines if the plugin sends a message to the target {@link
  *     org.bukkit.entity.Player}
  */
 public void openPetDataMenu(Player player, boolean sendMessage) {
   IPet pet = EchoPet.getManager().getPet(player);
   if (pet == null) {
     return;
   }
   ArrayList<MenuOption> options = MenuUtil.createOptionList(pet.getPetType());
   PetMenu menu = new PetMenu(pet, options, pet.getPetType() == PetType.HORSE ? 18 : 9);
   menu.open(sendMessage);
 }
Esempio n. 2
0
 /**
  * Teleports a {@link com.dsh105.echopet.api.pet.Pet} to a {@link org.bukkit.Location}
  *
  * @param pet the {@link com.dsh105.echopet.api.pet.Pet} to be teleported
  * @param location the {@link org.bukkit.Location} to teleport the {@link
  *     com.dsh105.echopet.api.pet.Pet} to
  * @return success of teleportation
  */
 public boolean teleportPet(IPet pet, Location location) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to teleport Pet to Location through the EchoPetAPI. {@link com.dsh105.echopet.api.pet.Pet} cannot be null.");
     return false;
   }
   if (pet.isHat() || pet.isOwnerRiding()) {
     return false;
   }
   return pet.teleport(location);
 }
Esempio n. 3
0
 /**
  * Set a target for the {@link com.dsh105.echopet.api.pet.Pet} to attack
  *
  * @param pet the attacker
  * @param target the {@link org.bukkit.entity.LivingEntity} for the {@link
  *     com.dsh105.echopet.api.pet.Pet} to attack
  */
 public void setAttackTarget(IPet pet, LivingEntity target) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to set attack target for Pet through the EchoPetAPI. Pet cannot be null.");
     return;
   }
   if (target == null) {
     EchoPet.LOG.severe(
         "Failed to set attack target for Pet through the EchoPetAPI. Target cannot be null.");
     return;
   }
   if (pet.getEntityPet().getPetGoalSelector().getGoal("Attack") != null) {
     pet.getCraftPet().setTarget(target);
   }
 }
Esempio n. 4
0
 /**
  * Get the {@link org.bukkit.entity.LivingEntity} that a {@link com.dsh105.echopet.api.pet.Pet} is
  * targeting
  *
  * @param pet the attacker
  * @return {@link org.bukkit.entity.LivingEntity} being attacked, null if none
  */
 public LivingEntity getAttackTarget(IPet pet) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to get attack target for Pet through the EchoPetAPI. Pet cannot be null.");
   }
   return pet.getCraftPet().getTarget();
 }
Esempio n. 5
0
 /**
  * Remove a goal from a {@link com.dsh105.echopet.api.pet.Pet}'s AI
  *
  * <p>The goal is identified using a string, initiated when the goal is added to the {@link
  * com.dsh105.echopet.api.pet.Pet}
  *
  * @param pet {@link com.dsh105.echopet.api.pet.Pet} to remove the goal from
  * @param identifier String that identifies a {@link com.dsh105.echopet.compat.api.ai.PetGoal}
  */
 public void removeGoal(IPet pet, String identifier) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to remove PetGoal from Pet AI through the EchoPetAPI. Pet cannot be null.");
     return;
   }
   pet.getEntityPet().getPetGoalSelector().removeGoal(identifier);
 }
Esempio n. 6
0
 private void initiateEntityPet() {
   this.setSize();
   this.fireProof = true;
   if (this.FIELD_JUMP == null) {
     try {
       this.FIELD_JUMP = EntityLiving.class.getDeclaredField("bd");
       this.FIELD_JUMP.setAccessible(true);
     } catch (NoSuchFieldException e) {
       e.printStackTrace();
     }
   }
   this.getBukkitEntity().setMaxHealth(pet.getPetType().getMaxHealth());
   this.setHealth((float) pet.getPetType().getMaxHealth());
   this.jumpHeight = EchoPet.getOptions().getRideJumpHeight(this.getPet().getPetType());
   this.rideSpeed = EchoPet.getOptions().getRideSpeed(this.getPet().getPetType());
   this.setPathfinding();
 }
Esempio n. 7
0
 /**
  * Checks if a {@link com.dsh105.echopet.api.pet.Pet} has specific {@link PetData}
  *
  * @param pet the {@link com.dsh105.echopet.api.pet.Pet} to search
  * @param petData the {@link PetData} searched for in the {@link com.dsh105.echopet.api.pet.Pet}
  *     instance
  * @return true if the {@link com.dsh105.echopet.api.pet.Pet} has the specified {@link PetData}
  */
 public boolean hasData(IPet pet, PetData petData) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to check PetData ["
             + petData.toString()
             + "] of Pet through the EchoPetAPI. Pet cannot be null.");
     return false;
   }
   return pet.getPetData().contains(petData);
 }
Esempio n. 8
0
 /**
  * Add an implementation of {@link com.dsh105.echopet.compat.api.ai.PetGoal} to a {@link
  * com.dsh105.echopet.api.pet.Pet}
  *
  * @param pet the {@link com.dsh105.echopet.api.pet.Pet} to add the {@link
  *     com.dsh105.echopet.compat.api.ai.PetGoal} to
  * @param goal the {@link com.dsh105.echopet.compat.api.ai.PetGoal} to add
  * @param identifier a {@link java.lang.String} to identify the goal
  */
 public void addGoal(IPet pet, PetGoal goal, String identifier, int priority) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to add PetGoal to Pet AI through the EchoPetAPI. Pet cannot be null.");
     return;
   }
   if (goal == null) {
     EchoPet.LOG.severe(
         "Failed to add PetGoal to Pet AI through the EchoPetAPI. Goal cannot be null.");
     return;
   }
   pet.getEntityPet().getPetGoalSelector().addGoal(identifier, goal, priority);
 }
Esempio n. 9
0
 /**
  * Add a predefined {@link com.dsh105.echopet.compat.api.ai.PetGoal} to a {@link
  * com.dsh105.echopet.api.pet.Pet} from the API
  *
  * @param pet the {@link com.dsh105.echopet.api.pet.Pet} to add the goal to
  * @param goalType type of goal
  */
 public void addGoal(IPet pet, GoalType goalType) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to add PetGoal to Pet AI through the EchoPetAPI. Pet cannot be null.");
     return;
   }
   if (goalType == GoalType.ATTACK) {
     pet.getEntityPet()
         .getPetGoalSelector()
         .addGoal(
             new SafeConstructor<APetGoalMeleeAttack>(
                     ReflectionUtil.getVersionedClass("entity.ai.PetGoalMeleeAttack"),
                     ReflectionUtil.getVersionedClass("entity.EntityPet"),
                     double.class,
                     int.class)
                 .newInstance(
                     pet.getEntityPet(),
                     EchoPet.getConfig().getDouble("attack.lockRange", 0.0D),
                     EchoPet.getConfig().getInt("attack.ticksBetweenAttacks", 20)),
             3);
   } else if (goalType == GoalType.FLOAT) {
     pet.getEntityPet()
         .getPetGoalSelector()
         .addGoal(
             new SafeConstructor<APetGoalFloat>(
                     ReflectionUtil.getVersionedClass("entity.ai.PetGoalFloat"),
                     ReflectionUtil.getVersionedClass("entity.EntityPet"))
                 .newInstance(pet.getEntityPet()),
             0);
   } else if (goalType == GoalType.FOLLOW_OWNER) {
     pet.getEntityPet()
         .getPetGoalSelector()
         .addGoal(
             new SafeConstructor<APetGoalFollowOwner>(
                     ReflectionUtil.getVersionedClass("entity.ai.PetGoalFollowOwner"),
                     ReflectionUtil.getVersionedClass("entity.EntityPet"),
                     double.class,
                     double.class,
                     double.class)
                 .newInstance(
                     pet.getEntityPet(),
                     pet.getEntityPet().getSizeCategory().getStartWalk(pet.getPetType()),
                     pet.getEntityPet().getSizeCategory().getStopWalk(pet.getPetType()),
                     pet.getEntityPet().getSizeCategory().getTeleport(pet.getPetType())),
             1);
   } else if (goalType == GoalType.LOOK_AT_PLAYER) {
     pet.getEntityPet()
         .getPetGoalSelector()
         .addGoal(
             new SafeConstructor<APetGoalLookAtPlayer>(
                     ReflectionUtil.getVersionedClass("entity.ai.PetGoalLookAtPlayer"),
                     ReflectionUtil.getVersionedClass("entity.EntityPet"),
                     Class.class,
                     float.class)
                 .newInstance(pet.getEntityPet(), ReflectionUtil.getNMSClass("EntityHuman"), 8.0F),
             2);
   }
 }
Esempio n. 10
0
 public Player getPlayerOwner() {
   return pet.getOwner();
 }
Esempio n. 11
0
  public void onLive() {
    if (this.pet == null) {
      this.remove(false);
      return;
    }

    if (this.getPlayerOwner() == null || !this.getPlayerOwner().isOnline()) {
      EchoPet.getManager().removePet(this.getPet(), true);
      return;
    }

    if (pet.isOwnerRiding() && this.passenger == null && !pet.isOwnerInMountingProcess()) {
      pet.ownerRidePet(false);
    }

    if (!forceInvisible
        && ((CraftPlayer) this.getPlayerOwner()).getHandle().isInvisible() != this.isInvisible()
        && !this.shouldVanish) {
      this.setInvisible(!this.isInvisible());
    }

    if (((CraftPlayer) this.getPlayerOwner()).getHandle().isSneaking() != this.isSneaking()) {
      this.setSneaking(!this.isSneaking());
    }

    if (((CraftPlayer) this.getPlayerOwner()).getHandle().isSprinting() != this.isSprinting()) {
      this.setSprinting(!this.isSprinting());
    }

    if (this.getPet().isHat()) {
      this.lastYaw =
          this.yaw =
              (this.getPet().getPetType() == PetType.ENDERDRAGON
                  ? this.getPlayerOwner().getLocation().getYaw() - 180
                  : this.getPlayerOwner().getLocation().getYaw());
    }

    if (this.getPlayerOwner().isFlying()
        && EchoPet.getOptions().canFly(this.getPet().getPetType())) {
      Location petLoc = this.getLocation();
      Location ownerLoc = this.getPlayerOwner().getLocation();
      Vector v = ownerLoc.toVector().subtract(petLoc.toVector());

      double x = v.getX();
      double y = v.getY();
      double z = v.getZ();

      Vector vo = this.getPlayerOwner().getLocation().getDirection();
      if (vo.getX() > 0) {
        x -= 1.5;
      } else if (vo.getX() < 0) {
        x += 1.5;
      }
      if (vo.getZ() > 0) {
        z -= 1.5;
      } else if (vo.getZ() < 0) {
        z += 1.5;
      }

      this.setVelocity(new Vector(x, y, z).normalize().multiply(0.3F));
    }
  }