Example #1
0
 public void lookAtPoint(final Location point) {
   if (this.getEntity().getBukkitEntity().getWorld() != point.getWorld()) return;
   final Location npcLoc = ((LivingEntity) this.getEntity().getBukkitEntity()).getEyeLocation();
   final double xDiff = point.getX() - npcLoc.getX();
   final double yDiff = point.getY() - npcLoc.getY();
   final double zDiff = point.getZ() - npcLoc.getZ();
   final double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
   final double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
   double newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI;
   final double newPitch = Math.acos(yDiff / DistanceY) * 180 / Math.PI - 90;
   if (zDiff < 0.0) newYaw = newYaw + Math.abs(180 - newYaw) * 2;
   this.setYaw((float) (newYaw - 90));
   this.setPitch((float) newPitch);
 }
Example #2
0
  /**
   * Find a position for the player to stand that is not inside a block. Blocks above the player
   * will be iteratively tested until there is a series of two free blocks. The player will be
   * teleported to that free position.
   *
   * @param player
   */
  public static void findFreePosition(Player player) {
    Location loc = player.getLocation();
    int x = loc.getBlockX();
    int y = Math.max(0, loc.getBlockY());
    int origY = y;
    int z = loc.getBlockZ();
    World world = player.getWorld();

    byte free = 0;

    while (y <= world.getMaxHeight() + 1) {
      if (BlockType.canPassThrough(world.getBlockTypeIdAt(x, y, z))) {
        free++;
      } else {
        free = 0;
      }

      if (free == 2) {
        if (y - 1 != origY || y == 1) {
          loc.setX(x + 0.5);
          loc.setY(y);
          loc.setZ(z + 0.5);
          if (y <= 2 && world.getBlockAt(x, 0, z).getTypeId() == BlockID.AIR) {
            world.getBlockAt(x, 0, z).setTypeId(20);
            loc.setY(2);
          }
          player.setFallDistance(0F);
          player.teleport(loc);
        }
        return;
      }

      y++;
    }
  }
    @EventHandler
    public void onProjectileHit(ProjectileHitEvent projectile) {
      Heroes.debug.startTask("HeroesSkillListener");

      if (!(projectile.getEntity() instanceof Arrow)) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      Arrow arrow = (Arrow) projectile.getEntity();

      if (!(arrow.getShooter() instanceof Player)) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      Player player = (Player) arrow.getShooter();
      Hero hero = SkillExplodingArrow.this.plugin.getCharacterManager().getHero(player);
      if (!hero.hasEffect("ExplodingArrowBuff")) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      int radius =
          (int)
              Math.pow(
                  SkillConfigManager.getUseSetting(hero, this.skill, "radius", 5, false), 2.0D);

      float damage = SkillConfigManager.getUseSetting(hero, this.skill, "DAMAGE", 5, false);
      float blockdamage = damage;
      int block_dmg = SkillConfigManager.getUseSetting(hero, this.skill, "block-dmg", 0, false);

      if (block_dmg == 0) {
        blockdamage = 0.0F;

        for (Entity t_entity : player.getWorld().getEntities()) {
          if ((t_entity instanceof Player)) {
            Player heroes = (Player) t_entity;
            if ((heroes.equals(player))
                || (heroes.getLocation().distanceSquared(arrow.getLocation()) > radius)) continue;
            damageEntity(
                heroes, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
          } else if ((t_entity instanceof Creature)) {
            Creature mob = (Creature) t_entity;
            if (t_entity.getLocation().distanceSquared(arrow.getLocation()) <= radius) {
              damageEntity(
                  mob, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
            }
          }
        }
      }

      arrow.getWorld().createExplosion(arrow.getLocation(), blockdamage);

      Heroes.debug.stopTask("HeroesSkillListener");
    }
  protected void processProjectiles(ProjectileDistanceTracker tracker, PlayerDeath death) {
    if (death.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) {
      EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) death.getEvent();
      Projectile projectile = (Projectile) event.getDamager();
      if (projectile.getShooter() instanceof Entity) {
        Entity shooter = (Entity) projectile.getShooter();
        double distance = projectile.getLocation().distance(tracker.getLaunchLocation(projectile));

        death.setKiller(shooter);
        death.setMisc("(" + (int) Math.round(distance) + " blocks)");
      }
    }
  }
Example #5
0
 public static void addSeconds(final Player player, final int seconds) {
   if (!b******g.fdsjfhkdsjfdsjhk().getServerHandler().isEOTW()
       && DTRBitmaskType.SAFE_ZONE.appliesAt(player.getLocation())) {
     return;
   }
   if (isTagged(player)) {
     final int secondsTaggedFor =
         (int)
             ((SpawnTagHandler.spawnTags.get(player.getName()) - System.currentTimeMillis())
                 / 1000L);
     final int newSeconds = Math.min(secondsTaggedFor + seconds, 60);
     SpawnTagHandler.spawnTags.put(
         player.getName(), System.currentTimeMillis() + newSeconds * 1000L);
   } else {
     player.sendMessage(
         ChatColor.YELLOW + "You have been spawn-tagged for §c" + seconds + " §eseconds!");
     SpawnTagHandler.spawnTags.put(player.getName(), System.currentTimeMillis() + seconds * 1000L);
   }
 }
Example #6
0
 public List<Block> getBlocks() {
   List<Block> blocks = new ArrayList<Block>();
   if (loc1 == null || loc2 == null) return blocks;
   for (int x = (int) Math.min(loc1.getX(), loc2.getX());
       x <= (int) Math.max(loc1.getX(), loc2.getX());
       x++) {
     for (int y = (int) Math.min(loc1.getY(), loc2.getY());
         y <= (int) Math.max(loc1.getY(), loc2.getY());
         y++) {
       for (int z = (int) Math.min(loc1.getZ(), loc2.getZ());
           z <= (int) Math.max(loc1.getZ(), loc2.getZ());
           z++) {
         if (loc1.getWorld().getBlockAt(x, y, z).getType() == Material.AIR) {
           blocks.add(loc1.getWorld().getBlockAt(x, y, z));
         }
       }
     }
   }
   return blocks;
 }
 @EventHandler(priority = EventPriority.HIGH)
 public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
   LivingEntity attacker = null;
   LivingEntity defender = null;
   Stat attackStat = null;
   Stat defenceStat = null;
   int attack = 0;
   int defence = 0;
   if (event.getDamager() instanceof Projectile) {
     Projectile projectile = (Projectile) event.getDamager();
     if (projectile.getShooter() instanceof LivingEntity) {
       attacker = (LivingEntity) projectile.getShooter();
       if (projectile instanceof Arrow) {
         attackStat = Stat.RANGED_ATTACK;
         defenceStat = Stat.RANGED_DEFENCE;
       } else {
         attackStat = Stat.MAGIC_ATTACK;
         defenceStat = Stat.MAGIC_DEFENCE;
       }
     }
   } else if (event.getDamager() instanceof LivingEntity) {
     attacker = (LivingEntity) event.getDamager();
     attackStat = Stat.MELEE_ATTACK;
     defenceStat = Stat.MELEE_DEFENCE;
   }
   if (event.getEntity() instanceof LivingEntity) {
     defender = (LivingEntity) event.getEntity();
   }
   if (attacker != null) {
     if (attacker instanceof Player) {
       RegisteredServiceProvider<CharacterPlugin> characterPluginProvider =
           plugin.getServer().getServicesManager().getRegistration(CharacterPlugin.class);
       if (characterPluginProvider != null) {
         CharacterPlugin characterPlugin = characterPluginProvider.getProvider();
         attack = characterPlugin.getActiveCharacter((Player) attacker).getStatValue(attackStat);
       }
     } else {
       attack = plugin.getEntityLevelManager().getEntityStatValue(attacker);
     }
   }
   if (defender != null) {
     if (defender instanceof Player) {
       RegisteredServiceProvider<CharacterPlugin> characterPluginProvider =
           plugin.getServer().getServicesManager().getRegistration(CharacterPlugin.class);
       if (characterPluginProvider != null) {
         CharacterPlugin characterPlugin = characterPluginProvider.getProvider();
         defence = characterPlugin.getActiveCharacter((Player) defender).getStatValue(defenceStat);
       }
     } else {
       defence = plugin.getEntityLevelManager().getEntityStatValue(defender);
     }
   }
   if (attacker != null && defender != null) {
     event.setDamage(
         (Math.ceil((((attack + 1D) / 2D) + 5D) * event.getDamage())) / (defence + 1D) / 2D);
   }
   if (defender != null) {
     if (defender instanceof Monster) {
       defender.setCustomName(
           "Lv"
               + plugin.getEntityLevelManager().getEntityLevel(defender)
               + " "
               + defender.getType().toString().toLowerCase().replace('_', ' ')
               + " - "
               + Math.round(defender.getHealth() * 100D) / 100D
               + "HP");
       defender.setCustomNameVisible(true);
     }
   }
 }