Пример #1
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);
 }
Пример #2
0
 /**
  * Remove a goal from a {@link com.dsh105.echopet.api.pet.Pet}'s AI
  *
  * @param pet {@link com.dsh105.echopet.api.pet.Pet} to remove the goal from
  * @param petGoal {@link com.dsh105.echopet.compat.api.ai.PetGoal} to remove
  */
 public void removeGoal(IPet pet, PetGoal petGoal) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to remove PetGoal from Pet AI through the EchoPetAPI. Pet cannot be null.");
     return;
   }
   if (petGoal == null) {
     EchoPet.LOG.severe(
         "Failed to remove PetGoal from Pet AI through the EchoPetAPI. Goal cannot be null.");
     return;
   }
   pet.getEntityPet().getPetGoalSelector().removeGoal(petGoal);
 }
Пример #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);
   }
 }
Пример #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();
 }
Пример #5
0
 /**
  * Remove a predefined goal from a {@link com.dsh105.echopet.api.pet.Pet}'s AI
  *
  * @param pet {@link com.dsh105.echopet.api.pet.Pet} to remove the goal from
  * @param goalType type of goal
  */
 public void removeGoal(IPet pet, GoalType goalType) {
   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(goalType.getGoalString());
 }
Пример #6
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);
   }
 }
Пример #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);
 }
Пример #8
0
 /**
  * Removes {@link PetData} from a {@link com.dsh105.echopet.api.pet.Pet}
  *
  * @param pet the {@link com.dsh105.echopet.api.pet.Pet} to remove the data from
  * @param petData {@link PetData} to remove to the {@link com.dsh105.echopet.api.pet.Pet}
  */
 public void removeData(IPet pet, PetData petData) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to remove PetData ["
             + petData.toString()
             + "] from Pet through the EchoPetAPI. Pet cannot be null.");
     return;
   }
   EchoPet.getManager().setData(pet, new PetData[] {petData}, false);
 }
Пример #9
0
 /**
  * Adds {@link com.dsh105.echopet.compat.api.entity.PetData} to a {@link
  * com.dsh105.echopet.api.pet.Pet}
  *
  * @param pet the {@link com.dsh105.echopet.api.pet.Pet} to add the data to
  * @param petData {@link com.dsh105.echopet.compat.api.entity.PetData} to add to the {@link
  *     com.dsh105.echopet.api.pet.Pet}
  */
 public void addData(IPet pet, PetData petData) {
   if (pet == null) {
     EchoPet.LOG.severe(
         "Failed to add PetData ["
             + petData.toString()
             + "] to Pet through the EchoPetAPI. Pet cannot be null.");
     return;
   }
   EchoPet.getManager().setData(pet, new PetData[] {petData}, true);
 }
Пример #10
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);
 }
Пример #11
0
  /**
   * Save a {@link com.dsh105.echopet.api.pet.Pet} to file or an SQL Database
   *
   * @param pet {@link com.dsh105.echopet.api.pet.Pet} to be saved
   * @param saveType whether to save to file or SQL database
   * @return success of save
   */
  public boolean savePet(IPet pet, SaveType saveType) {
    if (pet == null) {
      EchoPet.LOG.severe("Failed to save Pet file through the EchoPetAPI. Pet cannot be null.");
      return false;
    }

    if (saveType == SaveType.SQL) {
      EchoPet.getSqlManager().saveToDatabase(pet, false);
    } else if (saveType == SaveType.FILE) {
      EchoPet.getManager().saveFileData("autosave", pet);
    }
    return true;
  }
Пример #12
0
 /**
  * Gives a {@link com.dsh105.echopet.api.pet.Pet} to the specified {@link Player}
  *
  * <p>Pets will be spawned immediately next to the target player, linked until it is removed.
  *
  * @param player the {@link org.bukkit.entity.Player} that will be provided with a {@link
  *     com.dsh105.echopet.api.pet.Pet}
  * @param petType the {@link com.dsh105.echopet.compat.api.entity.PetType} (type of {@link
  *     com.dsh105.echopet.api.pet.Pet}) that will be given to the player
  * @param sendMessage defines if the plugin sends a message to the target {@link Player}
  * @return the {@link com.dsh105.echopet.api.pet.Pet} created
  */
 public IPet givePet(Player player, PetType petType, boolean sendMessage) {
   if (player != null && petType != null) {
     IPet pet = EchoPet.getManager().createPet(player, petType, sendMessage);
     if (pet == null) {
       EchoPet.LOG.severe(
           "Failed to give "
               + petType.toString()
               + " to "
               + player.getName()
               + " through the EchoPetAPI. Maybe this PetType is disabled in the Config.yml?");
       return null;
     }
     if (sendMessage) {
       Lang.sendTo(
           player,
           Lang.CREATE_PET
               .toString()
               .replace("%type%", StringUtil.capitalise(petType.toString())));
     }
     return pet;
   }
   return null;
 }