コード例 #1
0
ファイル: EchoPetAPI.java プロジェクト: sgdc3/EchoPet
 /**
  * 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);
 }
コード例 #2
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));
    }
  }