Пример #1
0
 @Override
 public void run() {
   for (Pet cosmetic : this.module.getParent().getApi().getAllCosmetics(Pet.class)) {
     Creature entity = cosmetic.getEntity();
     Player p = cosmetic.getPlayer();
     if (!entity.getWorld().getName().equalsIgnoreCase(p.getWorld().getName())
         || entity.getLocation().distance(p.getLocation())
             >= this.module.getConfig().getTeleportDistance()) {
       entity.teleport(p);
       entity.setTarget(p);
     }
   }
 }
Пример #2
0
 private void makeInvisible(Player player) {
   // make player invisible
   for (Player p : Bukkit.getOnlinePlayers()) {
     p.hidePlayer(player);
   }
   // detarget monsters
   Creature creature;
   for (Entity e : player.getNearbyEntities(30, 30, 30)) {
     if (e instanceof Creature) {
       creature = (Creature) e;
       if (creature.getTarget() != null && creature.getTarget().equals(player)) {
         creature.setTarget(null);
       }
     }
   }
 }
Пример #3
0
 public void manageDeath(PlayerKilledEvent event) {
   Gamer killed = event.getKilled();
   final Player p = killed.getPlayer();
   p.setHealth(20);
   if (event.isCancelled()) return;
   for (HumanEntity human : p.getInventory().getViewers()) human.closeInventory();
   p.leaveVehicle();
   p.eject();
   p.setLevel(0);
   p.setExp(0F);
   if (event.getDeathMessage().equals(ChatColor.stripColor(event.getDeathMessage())))
     event.setDeathMessage(ChatColor.DARK_RED + event.getDeathMessage());
   event.setDeathMessage(
       this.formatDeathMessage(
           event.getDeathMessage().replace("%Remaining%", "" + (getAliveGamers().size() - 1)), p));
   if (event.getKillerPlayer() != null) {
     event.getKillerPlayer().addKill();
     event.setDeathMessage(
         this.formatDeathMessage(event.getDeathMessage(), event.getKillerPlayer().getPlayer()));
   }
   Bukkit.broadcastMessage(event.getDeathMessage());
   int reward = hg.getPrize(getAliveGamers().size());
   if (reward > 0) killed.addBalance(reward);
   hg.cannon();
   killed.clearInventory();
   World world = p.getWorld();
   for (ItemStack item : event.getDrops()) {
     if (item == null
         || item.getType() == Material.AIR
         || item.containsEnchantment(EnchantmentManager.UNLOOTABLE)) continue;
     else if (item.hasItemMeta())
       world
           .dropItemNaturally(event.getDropsLocation(), item.clone())
           .getItemStack()
           .setItemMeta(item.getItemMeta());
     else world.dropItemNaturally(event.getDropsLocation(), item);
   }
   setSpectator(killed);
   ScoreboardManager.makeScore(
       "Main", DisplaySlot.SIDEBAR, cm.getScoreboardPlayersLength(), getAliveGamers().size());
   hg.checkWinner();
   p.setVelocity(new Vector());
   for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType());
   p.teleport(p.getWorld().getHighestBlockAt(p.getLocation()).getLocation().clone().add(0, 10, 0));
   p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 9), true);
   p.sendBlockChange(p.getLocation(), Material.PORTAL.getId(), (byte) 0);
   p.sendBlockChange(p.getLocation(), Material.AIR.getId(), (byte) 0);
   for (Entity entity : p.getWorld().getEntities()) {
     if (entity instanceof Tameable
         && ((Tameable) entity).isTamed()
         && ((Tameable) entity).getOwner().getName().equals(p.getName())) {
       if (entity instanceof Wolf) ((Wolf) entity).setSitting(true);
       else if (entity instanceof Ocelot) ((Ocelot) entity).setSitting(true);
       else entity.remove();
     }
     if (entity instanceof Creature && ((Creature) entity).getTarget() == p)
       ((Creature) entity).setTarget(null);
   }
   if (HungergamesApi.getConfigManager().getMainConfig().isKickOnDeath()
       && !p.hasPermission("hungergames.spectate"))
     p.kickPlayer(String.format(cm.getKickDeathMessage(), event.getDeathMessage()));
   HungergamesApi.getAbilityManager().unregisterPlayer(p);
   HungergamesApi.getInventoryManager().updateSpectatorHeads();
 }
Пример #4
0
  /**
   * Spawn guard wolves to this prisoner to kill him
   *
   * @param num Number of guards to spawn
   * @param location Spawning location
   * @param player Player, associated with this JailPrisoner
   */
  public void spawnGuards(int num, Location location, Player player) {
    List<BlockFace> checkedCorners = new ArrayList<BlockFace>();
    for (int i = 0; i < num; i++) {
      Location spawn = null;
      for (int ci = 0; ci < 4; ci++) {
        Block block = location.getBlock().getRelative(BlockFace.values()[ci]);
        if (!checkedCorners.contains(BlockFace.values()[ci])
            && (block.getType() == Material.AIR
                || block.getType() == Material.STATIONARY_WATER
                || block.getType() == Material.WATER)) {
          spawn = block.getLocation();
          checkedCorners.add(BlockFace.values()[ci]);
          break;
        }
      }
      if (spawn == null) {
        checkedCorners.clear();
        for (int ci = 0; ci < 3; ci++) {
          if (!checkedCorners.contains(BlockFace.values()[ci])
                  && location.getBlock().getRelative(BlockFace.values()[ci]).getType()
                      == Material.AIR
              || location.getBlock().getRelative(BlockFace.values()[ci]).getType()
                  == Material.STATIONARY_WATER) {
            spawn = location.getBlock().getRelative(BlockFace.NORTH).getLocation();
            checkedCorners.add(BlockFace.values()[ci]);
          }
        }
        if (spawn == null) spawn = location;
      }

      List<String> guardTypes = (List<String>) jail.getSettings().getList(Setting.GuardTypes);
      String pickedType = guardTypes.get(new Random().nextInt(guardTypes.size()));

      EntityType type = EntityType.fromName(pickedType);

      if (type == null
          || !type.isSpawnable()
          || !Creature.class.isAssignableFrom(type.getEntityClass())) {
        Jail.log.severe("[Jail] Invalid GuardTypes config! " + pickedType + " cannot be spawned.");
        type = EntityType.CHICKEN;
      }

      Creature guard = (Creature) location.getWorld().spawn(spawn, type.getEntityClass());

      if (!(guard.getWorld().getEntities().contains(guard))) {
        canSpawnGuards = false;
        return;
      }

      int health = getJail().getSettings().getInt(Setting.GuardHealth);
      if (health > guard.getMaxHealth()) {
        Jail.log.warning(
            "[Jail] Guard health cannot be more than "
                + guard.getMaxHealth()
                + "! Use Armor to increase toughness of your guards!");
        health = guard.getMaxHealth();
      }

      guardTargets.add(player);

      guard.setHealth(health);

      guard.setTarget(player);

      getGuards().add(guard);
      Jail.guards.put(guard, this);
    }
  }
Пример #5
0
  // -1, false, false are defaults, attackmob and attack player are only processed when damage = -1.
  public void entityAttack(EntityDamageByEntityEvent ed, double customDamage) {
    double damage = 0;

    event = ed;

    // Reset all globals.
    setGlobalDefaults();

    // Set event damage to 0.
    ed.setDamage(0);

    LivingEntity entity;
    Entity eEntity = ed.getEntity();

    if (eEntity instanceof Arrow) {
      Arrow ca = (Arrow) eEntity;
      entity = ca.getShooter();
    } else if (eEntity instanceof LargeFireball) {
      LargeFireball cf = (LargeFireball) eEntity;
      entity = cf.getShooter();
    } else if (eEntity instanceof ExperienceOrb) {
      return;
    } else if (eEntity instanceof Item) {
      return;
    } else {
      // Set entity equal to the entity that got hit.
      try {
        entity = (LivingEntity) ed.getEntity();
      } catch (ClassCastException e) {
        FC_Rpg.plugin
            .getLogger()
            .info(
                "Failed to cast an entity to living entity, damage cancelled -> "
                    + eEntity.toString()
                    + " <- report to a FC_Rpg developer via a ticket please.");
        return;
      }
    }

    // Prepare the defender and attacker variables.
    prepareDefender(entity);

    // If a damage was passed in, then we don't want to set damage. Else, store new damage
    damage = prepareAttacker(ed);

    // When two players are fighting, then...
    boolean isPvp = false;

    // set whether in pvp or not.
    if (playerAttacker != null && playerDefender != null) isPvp = true;

    if (isPvp == true && cancelRpgDamage == true) {
      MessageLib msgLib = new MessageLib(playerAttacker);
      msgLib.standardMessage("This player can't be attacked currently.");
      return;
    }

    // Check player tiers.
    if (isPvp == true) {
      int attackerTier = getTier(rpgAttacker.playerConfig.getClassLevel());
      int defenderTier = getTier(rpgDefender.playerConfig.getClassLevel());

      if (attackerTier != defenderTier) {
        MessageLib msgLib = new MessageLib(playerAttacker);
        msgLib.infiniteMessage(
            "You can't fight this target because they are in tier ",
            defenderTier + "",
            " and you are in tier ",
            attackerTier + "",
            "!");
        return;
      }
    }

    // If we are cancelling rpg damage, then return.
    if (cancelRpgDamage == true) return;

    if (customDamage > -1) damage = customDamage;

    /**
     * *********************************************************
     *
     * <p>SET THE BASE DAMAGE BASED ON IF A PLAYER, MOB, OR ENVIROMENT CAUSED DAMAGE
     *
     * <p>*********************************************************
     */

    // We do a sword check for atttackers.
    if (rpgAttacker != null) {
      // Check the attackers sword.
      rpgAttacker.swordAttackRequirementCheck();

      // We handle spells on non-fireball player attacks.
      if (damageType != 2) {
        if (rpgAttacker.playerConfig.getAutoCast() == true) rpgAttacker.prepareSpell(false);

        double spellDamage = -1;

        // Attempt to cast a spell.
        if (rpgMobDefender != null)
          spellDamage = rpgAttacker.castSpell(rpgMobDefender.getEntity(), damage, damageType);
        else spellDamage = rpgAttacker.castSpell(rpgDefender.getPlayer(), damage, damageType);

        // If the spell failed to cast, then we want to do spells/enchantment stuff.
        if (spellDamage == -1) {
          // Cast auto spells/enchantment stuff.
          if (rpgMobDefender != null)
            spellDamage = rpgAttacker.autocastOffense(rpgMobDefender.getEntity(), damage);
          else spellDamage = rpgAttacker.autocastOffense(rpgDefender.getPlayer(), damage);
        }

        // If the spell damage isn't -1, then we want to store the spell damage.
        if (spellDamage != -1) damage = spellDamage;
      }
    }

    // Apply randomization to damage.
    damage = getRandomDamageModifier(damage);

    // We do a armor check for defenders.
    if (rpgDefender != null) {
      rpgDefender.fullArmorCheck();

      // Cast armor enchantment stuff.
      rpgDefender.autocastDefense();
    }

    if (rpgMobDefender != null) {
      // Prevent mobs from damaging friendly mobs.
      if (rpgMobAttacker != null) return;

      // If no player attacked, then we want to nuke the mob (enviromental damage).
      if (rpgAttacker == null) {
        edm.nukeMob(rpgMobDefender.getEntity());
        return;
      }

      // Attack the mob defender
      if (edm.attackMobDefender(rpgMobDefender, rpgAttacker, damage, damageType) == false) {
        MessageLib msgLib = new MessageLib(playerAttacker);
        msgLib.standardMessage("Attack Missed.");
      }

      // Make creatures forcibly attack attacker.
      if (playerAttacker != null && mobDefender != null) {
        // Set wolves to angry.
        if (mobDefender instanceof Wolf) ((Wolf) mobDefender).setAngry(true);

        if (mobDefender instanceof Creature) {
          // Change aggro
          ((Creature) mobDefender).setTarget(playerAttacker);
        }
      }
    } else if (rpgDefender != null) {
      // Attack the player Defender.
      if (rpgAttacker != null) {
        if (edm.attackPlayerDefender(
                rpgDefender,
                rpgAttacker,
                null,
                damage,
                damageType,
                rpgAttacker.getPlayer().getName().substring(0, nameTrimEnd))
            == false) {
          MessageLib msgLib = new MessageLib(playerAttacker);
          msgLib.standardMessage("Attack Missed.");
        }
      } else if (rpgMobAttacker != null)
        edm.attackPlayerDefender(
            rpgDefender,
            null,
            rpgMobAttacker,
            damage,
            damageType,
            rpgMobAttacker.getEntity().getType().toString());
    }
  }
Пример #6
0
    public List<LivingEntity> spawn(Location location, Player player) {
      List<LivingEntity> entities = new ArrayList<LivingEntity>(this.num);
      World world = location.getWorld();

      for (int num = 0; num < this.num; num++) {
        if (spread > 0) {
          int minX = location.getBlockX() - spread / 2;
          int minY = location.getBlockY() - spread / 2;
          int minZ = location.getBlockZ() - spread / 2;
          int maxX = location.getBlockX() + spread / 2;
          int maxY = location.getBlockY() + spread / 2;
          int maxZ = location.getBlockZ() + spread / 2;

          int tries = spread * 10;
          boolean found = false;

          while (tries-- > 0) {
            int x = minX + RecipeManager.random.nextInt(maxX - minX);
            int z = minZ + RecipeManager.random.nextInt(maxZ - minZ);
            int y = 0;

            for (y = maxY; y >= minY; y--) {
              if (!Material.getMaterial(world.getBlockTypeIdAt(x, y, z)).isSolid()) {
                found = true;
                break;
              }
            }

            if (found) {
              location.setX(x);
              location.setY(y);
              location.setZ(z);
              break;
            }
          }

          if (!found) {
            Messages.debug(
                "Couldn't find suitable location after " + (spread * 10) + " tries, using center.");
          }

          location.add(0.5, 0, 0.5);
        }

        LivingEntity ent = (LivingEntity) world.spawnEntity(location, type);
        entities.add(ent);

        if (!noEffect) {
          world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 20);
        }

        if (name != null) {
          ent.setCustomName(name);
          ent.setCustomNameVisible(noHideName);
        }

        if (onFire > 0.0f) {
          ent.setFireTicks((int) Math.ceil(onFire * 20.0));
        }

        if (pickup != null) {
          ent.setCanPickupItems(pickup);
        }

        if (pet && ent instanceof Tameable) {
          Tameable npc = (Tameable) ent;
          npc.setOwner(player);
          npc.setTamed(true);
        }

        if (ent instanceof Wolf) {
          Wolf npc = (Wolf) ent;

          if (pet) {
            if (noSit) {
              npc.setSitting(false);
            }

            if (color != null) {
              npc.setCollarColor(color);
            }
          } else if (angry) {
            npc.setAngry(true);
          }
        }

        if (ent instanceof Ocelot) {
          Ocelot npc = (Ocelot) ent;

          if (pet && noSit) {
            npc.setSitting(false);
          }

          if (cat != null) {
            npc.setCatType(cat);
          }
        }

        if (hp > 0) {
          ent.setHealth(hp);

          if (maxHp > 0) {
            ent.setMaxHealth(maxHp);
          }
        }

        if (ent instanceof Ageable) {
          Ageable npc = (Ageable) ent;

          if (baby) {
            npc.setBaby();
          }

          if (ageLock) {
            npc.setAgeLock(true);
          }

          if (noBreed) {
            npc.setBreed(false);
          }
        }

        if (saddle && ent instanceof Pig) {
          Pig npc = (Pig) ent;
          npc.setSaddle(true);

          if (mount) {
            npc.setPassenger(player);
          }
        }

        if (ent instanceof Zombie) {
          Zombie npc = (Zombie) ent;

          if (baby) {
            npc.setBaby(true);
          }

          if (zombieVillager) {
            npc.setVillager(true);
          }
        }

        if (villager != null && ent instanceof Villager) {
          Villager npc = (Villager) ent;
          npc.setProfession(villager);
        }

        if (poweredCreeper && ent instanceof Creeper) {
          Creeper npc = (Creeper) ent;
          npc.setPowered(true);
        }

        if (playerIronGolem && ent instanceof IronGolem) {
          IronGolem npc = (IronGolem) ent;
          npc.setPlayerCreated(true); // TODO what exacly does this do ?
        }

        if (shearedSheep && ent instanceof Sheep) {
          Sheep npc = (Sheep) ent;
          npc.setSheared(true);
        }

        if (color != null && ent instanceof Colorable) {
          Colorable npc = (Colorable) ent;
          npc.setColor(color);
        }

        if (skeleton != null && ent instanceof Skeleton) {
          Skeleton npc = (Skeleton) ent;
          npc.setSkeletonType(skeleton);
        }

        if (target && ent instanceof Creature) {
          Creature npc = (Creature) ent;
          npc.setTarget(player);
        }

        if (pigAnger > 0 && ent instanceof PigZombie) {
          PigZombie npc = (PigZombie) ent;
          npc.setAnger(pigAnger);
        }

        if (hit) {
          ent.damage(0, player);
          ent.setVelocity(new Vector());
        }

        if (!potions.isEmpty()) {
          for (PotionEffect effect : potions) {
            ent.addPotionEffect(effect, true);
          }
        }

        ent.setRemoveWhenFarAway(!noRemove);

        EntityEquipment eq = ent.getEquipment();

        for (int i = 0; i < equip.length; i++) {
          ItemStack item = equip[i];

          if (item == null) {
            continue;
          }

          switch (i) {
            case 0:
              eq.setHelmet(item);
              eq.setHelmetDropChance(drop[i]);
              break;

            case 1:
              eq.setChestplate(item);
              eq.setChestplateDropChance(drop[i]);
              break;

            case 2:
              eq.setLeggings(item);
              eq.setLeggingsDropChance(drop[i]);
              break;

            case 3:
              eq.setBoots(item);
              eq.setBootsDropChance(drop[i]);
              break;

            case 4:
              {
                if (ent instanceof Enderman) {
                  Enderman npc = (Enderman) ent;
                  npc.setCarriedMaterial(item.getData());
                } else {
                  eq.setItemInHand(item);
                  eq.setItemInHandDropChance(drop[i]);
                }

                break;
              }
          }
        }
      }

      return entities;
    }
 @Override
 public void setTarget(LivingEntity entity, LivingEntity target) {
   if (entity instanceof Creature) {
     ((Creature) entity).setTarget(target);
   }
 }