Example #1
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);
   }
 }
Example #2
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);
 }
Example #3
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();
 }