static {
    for (EntityType type : EntityType.values()) {
      try {
        if (TFM_DepreciationAggregator.getName_EntityType(type) != null) {
          if (Creature.class.isAssignableFrom(type.getEntityClass())) {
            mobtypes.put(TFM_DepreciationAggregator.getName_EntityType(type).toLowerCase(), type);
          }
        }
      } catch (Exception ex) {
      }
    }

    for (ChatColor chatColor : CHAT_COLOR_POOL) {
      CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
    }
  }
Beispiel #2
0
  public static ShopsNPC createNewShopsNPC(final LivingEntity e, final Shop shop) throws Exception {

    EntityType type = e.getType();
    boolean baby = false;
    boolean sheared = false;
    boolean villager = false;
    List<String> lore = new ArrayList<>();

    if (Ageable.class.isAssignableFrom(type.getEntityClass())) {
      baby = !(boolean) type.getEntityClass().getMethod("isAdult").invoke(e);
    }
    if (type == EntityType.SHEEP) {
      sheared = (boolean) type.getEntityClass().getMethod("isSheared").invoke(e);
    }
    if (type == EntityType.ZOMBIE) {
      villager = (boolean) type.getEntityClass().getMethod("isVillager").invoke(e);
      baby = (boolean) type.getEntityClass().getMethod("isBaby").invoke(e);
    }

    if (Colorable.class.isAssignableFrom(type.getEntityClass())) {
      DyeColor color = (DyeColor) type.getEntityClass().getMethod("getColor").invoke(e);
      lore.add(Language.getString("NPCs", "DyeColor") + " §7" + color.name());
    }

    if (type == EntityType.WOLF) {
      DyeColor color = (DyeColor) type.getEntityClass().getMethod("getCollarColor").invoke(e);
      lore.add(Language.getString("NPCs", "DyeColor") + " §7" + color.name());
    }

    for (int i = 0; i < type.getEntityClass().getDeclaredClasses().length; i++) {
      final Class c = type.getEntityClass().getClasses()[i];
      if (c.isEnum()) {
        for (Method m : type.getEntityClass().getMethods()) {
          if (m.getParameterTypes().length == 0)
            if (m.invoke(e).getClass().equals(c)) {
              final Enum e1 = (Enum) m.invoke(e);
              if (c.getSimpleName().equals("Type") && type == EntityType.OCELOT) {

                lore.add(Language.getString("NPCs", "OcelotType") + " §7" + e1.name());
              } else if (c.getSimpleName().equals("Type") && type == EntityType.RABBIT) {
                lore.add(Language.getString("NPCs", "RabbitType") + " §7" + e1.name());
              } else {
                lore.add(Language.getString("NPCs", c.getSimpleName()) + " §7" + e1.name());
              }
              break;
            }
        }
      }
    }

    if (type == EntityType.SLIME || type == EntityType.MAGMA_CUBE) {
      int i = (int) type.getEntityClass().getMethod("getSize").invoke(e);
      lore.add(Language.getString("NPCs", "Size") + " §7" + i);
    }

    if (type == EntityType.PLAYER) {
      String name = (String) type.getEntityClass().getMethod("getName").invoke(e);
      lore.add(Language.getString("NPCs", "Player") + " §7" + name);
    }

    e.remove();

    return new NPCShop(type, lore, shop, baby, sheared, villager);
  }
  @Override
  public void trigger(ChipState chip) {

    if (!location.getChunk().isLoaded()) return;

    if (!chip.getInput(0)) return;
    Block left = SignUtil.getLeftBlock(BukkitUtil.toSign(getSign()).getBlock());
    ChangedSign effectSign = null;
    if (left.getTypeId() == BlockID.WALL_SIGN) {
      effectSign = BukkitUtil.toChangedSign(left);
    }

    Block right = SignUtil.getRightBlock(BukkitUtil.toSign(getSign()).getBlock());
    ChangedSign armourSign = null;
    if (right.getTypeId() == BlockID.WALL_SIGN) {
      armourSign = BukkitUtil.toChangedSign(right);
    }

    for (int i = 0; i < amount; i++) {
      Entity ent = BukkitUtil.toSign(getSign()).getWorld().spawn(location, type.getEntityClass());

      if (armourSign != null) { // Apply armor
        if (ent instanceof LivingEntity) {

          for (int s = 0; s < 4; s++) {
            String bit = armourSign.getLine(s);

            ItemStack slot = ItemUtil.makeItemValid(ItemUtil.getItem(bit));

            if (s == 0) ((LivingEntity) ent).getEquipment().setHelmet(slot);
            if (s == 1) ((LivingEntity) ent).getEquipment().setChestplate(slot);
            if (s == 2) ((LivingEntity) ent).getEquipment().setLeggings(slot);
            if (s == 3) ((LivingEntity) ent).getEquipment().setBoots(slot);
          }
        }
      }

      Boolean upwards = null;

      while (effectSign != null) { // Apply effects
        for (int s = 0; s < 4; s++) {
          String bit = effectSign.getLine(s);
          if (bit == null || bit.trim().isEmpty()) continue;

          String[] data = RegexUtil.COLON_PATTERN.split(bit);

          if (data[0].equalsIgnoreCase("e")) CreatureSpawner.setEntityData(ent, bit.substring(2));
          else if (data[0].equalsIgnoreCase("r")) {
            EntityType rider = EntityType.fromName(data[1].trim());
            Entity rid = BukkitUtil.toSign(getSign()).getWorld().spawnEntity(location, rider);
            ent.setPassenger(rid);
          } else if (data[0].equalsIgnoreCase("p") && ent instanceof LivingEntity) {
            for (int a = 1; a < data.length; a++) {
              try {
                String[] potionBits = RegexUtil.SEMICOLON_PATTERN.split(data[a]);
                PotionEffect effect =
                    new PotionEffect(
                        PotionEffectType.getById(Integer.parseInt(potionBits[0])),
                        Integer.parseInt(potionBits[1]),
                        Integer.parseInt(potionBits[2]));
                ((LivingEntity) ent).addPotionEffect(effect, true);
              } catch (Exception e) {
              }
            }
          } else if (data[0].equalsIgnoreCase("v")) {
            try {
              double x, y, z;
              String[] coords = RegexUtil.COMMA_PATTERN.split(data[1]);
              x = Double.parseDouble(coords[0]);
              y = Double.parseDouble(coords[1]);
              z = Double.parseDouble(coords[2]);
              ent.setVelocity(new org.bukkit.util.Vector(x, y, z));
            } catch (Exception ignored) {
            }
          } else if (data[0].equalsIgnoreCase("s")) {
            if (!(ent instanceof LivingEntity)) continue;

            ItemStack slot = ItemUtil.makeItemValid(ItemUtil.getItem(bit.replace("s:", "")));
            ((LivingEntity) ent).getEquipment().setItemInHand(slot);
          }
        }
        if (upwards == null) {
          if (BukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0).getTypeId()
              == BlockID.WALL_SIGN) {
            effectSign =
                BukkitUtil.toChangedSign(
                    BukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0));
            upwards = true;
          } else if (BukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0).getTypeId()
              == BlockID.WALL_SIGN) {
            effectSign =
                BukkitUtil.toChangedSign(
                    BukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0));
            upwards = false;
          } else break;
        } else {
          if (BukkitUtil.toSign(effectSign)
                  .getBlock()
                  .getRelative(0, upwards ? 1 : -1, 0)
                  .getTypeId()
              == BlockID.WALL_SIGN)
            effectSign =
                BukkitUtil.toChangedSign(
                    BukkitUtil.toSign(effectSign).getBlock().getRelative(0, upwards ? 1 : -1, 0));
          else break;
        }
      }
    }
  }
Beispiel #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);
    }
  }