コード例 #1
0
    @Override
    public void verify(ChangedSign sign) throws ICVerificationException {

      String[] splitLine3 = RegexUtil.ASTERISK_PATTERN.split(sign.getLine(3).trim());
      if (EntityType.fromName(splitLine3[0].trim().toLowerCase()) == null) {
        throw new ICVerificationException("Invalid Entity! See bukkit EntityType list!");
      } else if (!EntityType.fromName(splitLine3[0].trim().toLowerCase()).isSpawnable()) {
        throw new ICVerificationException("Entity is not spawnable!");
      }
    }
コード例 #2
0
 public boolean spawn(String world, double x, double y, double z, String mobName) {
   return getServer()
           .getWorld(world)
           .spawnEntity(
               new Location(getServer().getWorld(world), x, y, z), EntityType.fromName(mobName))
       != null;
 }
コード例 #3
0
  public static AbstractRewardSettings<EntityType> parseConfig(ConfigurationSection config) {
    Map<EntityType, List<AbstractRewardSource>> sources =
        new HashMap<EntityType, List<AbstractRewardSource>>();
    ConfigurationSection rewardTable = config.getConfigurationSection("RewardTable");

    if (rewardTable != null) {
      for (String typeName : rewardTable.getKeys(false)) {
        EntityType type = EntityType.fromName(typeName);

        if (type != null) {
          AbstractRewardSource source =
              configureRewardSource(
                  RewardSourceFactory.createSource(
                      typeName, rewardTable.getConfigurationSection(typeName)),
                  config);

          if (!sources.containsKey(type)) {
            sources.put(type, new ArrayList<AbstractRewardSource>());
          }

          sources
              .get(type)
              .add(
                  mergeSets(
                      source,
                      rewardTable.getConfigurationSection(typeName),
                      config.getConfigurationSection("RewardSets")));
        }
      }
    }

    EntityRewardSettings settings = new EntityRewardSettings(sources);
    settings.setHuntingRules(loadHuntingRules(config));
    return settings;
  }
コード例 #4
0
 public void setCreatureTypeByName(String creatureType) {
   // Verify input
   EntityType type = EntityType.fromName(creatureType);
   if (type == null) {
     return;
   }
   setSpawnedType(type);
 }
コード例 #5
0
  private boolean killDecision(
      Entity e,
      List<String> thingsToKill,
      boolean negateAnimals,
      boolean negateMonsters,
      boolean specifiedAnimals,
      boolean specifiedMonsters) {
    boolean negate = false;
    boolean specified = false;
    if (e instanceof Golem || e instanceof Squid || e instanceof Animals) {
      // it's an animal
      if (specifiedAnimals && !negateAnimals) {
        Logging.finest(
            "Removing an entity because I was told to remove all animals in world %s: %s",
            e.getWorld().getName(), e);
        return true;
      }
      if (specifiedAnimals) specified = true;
      negate = negateAnimals;
    } else if (e instanceof Monster || e instanceof Ghast || e instanceof Slime) {
      // it's a monster
      if (specifiedMonsters && !negateMonsters) {
        Logging.finest(
            "Removing an entity because I was told to remove all monsters in world %s: %s",
            e.getWorld().getName(), e);
        return true;
      }
      if (specifiedMonsters) specified = true;
      negate = negateMonsters;
    }
    for (String s : thingsToKill) {
      EntityType type = EntityType.fromName(s);
      if (type != null && type.equals(e.getType())) {
        specified = true;
        if (!negate) {
          Logging.finest(
              "Removing an entity because it WAS specified and we are NOT negating in world %s: %s",
              e.getWorld().getName(), e);
          return true;
        }
        break;
      }
    }
    if (!specified && negate) {
      Logging.finest(
          "Removing an entity because it was NOT specified and we ARE negating in world %s: %s",
          e.getWorld().getName(), e);
      return true;
    }

    return false;
  }
コード例 #6
0
  @Override
  public Set<EntityType> decodeList(List<String> list) {
    Set<EntityType> types = EnumSet.noneOf(EntityType.class);

    for (String entry : list) {
      EntityType type = EntityType.fromName(entry.replace(' ', '_'));
      if (type != null) {
        types.add(type);
      }
    }

    return types;
  }
コード例 #7
0
  @Override
  public void load() {

    String[] splitLine3 = RegexUtil.ASTERISK_PATTERN.split(getSign().getLine(3).trim());
    type = EntityType.fromName(splitLine3[0].trim().toLowerCase());
    if (type == null) {
      type = EntityType.PIG;
    }

    try {
      amount = Integer.parseInt(splitLine3[1]);
    } catch (Exception e) {
      amount = 1;
    }

    location = ICUtil.parseBlockLocation(getSign(), 2).getLocation();
  }
コード例 #8
0
 public static boolean isValidCreature(String name) {
   return EntityType.fromName(name).isAlive();
 }
コード例 #9
0
  @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;
        }
      }
    }
  }
コード例 #10
0
ファイル: JailPrisoner.java プロジェクト: matejdro/Jail
  /**
   * 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);
    }
  }
コード例 #11
0
  @Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;

    if (args.length < 2) {
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return false;
    }

    if (!args[0].equalsIgnoreCase("give")) {
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return false;
    }

    String statisticString = args[1];
    Player player = null;

    if (args.length > 2) {
      player = Bukkit.getPlayer(args[1]);
    } else if (sender instanceof Player) {
      player = (Player) sender;
    }

    if (player == null) {
      sender.sendMessage("You must specify which player you wish to perform this action on.");
      return true;
    }

    if (statisticString.equals("*")) {
      for (Achievement achievement : Achievement.values()) {
        if (player.hasAchievement(achievement)) {
          continue;
        }
        PlayerAchievementAwardedEvent event =
            new PlayerAchievementAwardedEvent(player, achievement);
        Bukkit.getServer().getPluginManager().callEvent(event);
        if (!event.isCancelled()) {
          player.awardAchievement(achievement);
        }
      }
      Command.broadcastCommandMessage(
          sender, String.format("Successfully given all achievements to %s", player.getName()));
      return true;
    }

    Achievement achievement = Bukkit.getUnsafe().getAchievementFromInternalName(statisticString);
    Statistic statistic = Bukkit.getUnsafe().getStatisticFromInternalName(statisticString);

    if (achievement != null) {
      if (player.hasAchievement(achievement)) {
        sender.sendMessage(
            String.format("%s already has achievement %s", player.getName(), statisticString));
        return true;
      }

      PlayerAchievementAwardedEvent event = new PlayerAchievementAwardedEvent(player, achievement);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        sender.sendMessage(
            String.format(
                "Unable to award %s the achievement %s", player.getName(), statisticString));
        return true;
      }
      player.awardAchievement(achievement);

      Command.broadcastCommandMessage(
          sender,
          String.format("Successfully given %s the stat %s", player.getName(), statisticString));
      return true;
    }

    if (statistic == null) {
      sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
      return true;
    }

    if (statistic.getType() == Type.UNTYPED) {
      PlayerStatisticIncrementEvent event =
          new PlayerStatisticIncrementEvent(
              player,
              statistic,
              player.getStatistic(statistic),
              player.getStatistic(statistic) + 1);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        sender.sendMessage(
            String.format("Unable to increment %s for %s", statisticString, player.getName()));
        return true;
      }
      player.incrementStatistic(statistic);
      Command.broadcastCommandMessage(
          sender,
          String.format("Successfully given %s the stat %s", player.getName(), statisticString));
      return true;
    }

    if (statistic.getType() == Type.ENTITY) {
      EntityType entityType =
          EntityType.fromName(statisticString.substring(statisticString.lastIndexOf(".") + 1));

      if (entityType == null) {
        sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
        return true;
      }

      PlayerStatisticIncrementEvent event =
          new PlayerStatisticIncrementEvent(
              player,
              statistic,
              player.getStatistic(statistic),
              player.getStatistic(statistic) + 1,
              entityType);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        sender.sendMessage(
            String.format("Unable to increment %s for %s", statisticString, player.getName()));
        return true;
      }

      try {
        player.incrementStatistic(statistic, entityType);
      } catch (IllegalArgumentException e) {
        sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
        return true;
      }
    } else {
      int id;
      try {
        id =
            getInteger(
                sender,
                statisticString.substring(statisticString.lastIndexOf(".") + 1),
                0,
                Integer.MAX_VALUE,
                true);
      } catch (NumberFormatException e) {
        sender.sendMessage(e.getMessage());
        return true;
      }

      Material material = Material.getMaterial(id);

      if (material == null) {
        sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
        return true;
      }

      PlayerStatisticIncrementEvent event =
          new PlayerStatisticIncrementEvent(
              player,
              statistic,
              player.getStatistic(statistic),
              player.getStatistic(statistic) + 1,
              material);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        sender.sendMessage(
            String.format("Unable to increment %s for %s", statisticString, player.getName()));
        return true;
      }

      try {
        player.incrementStatistic(statistic, material);
      } catch (IllegalArgumentException e) {
        sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
        return true;
      }
    }

    Command.broadcastCommandMessage(
        sender,
        String.format("Successfully given %s the stat %s", player.getName(), statisticString));
    return true;
  }
コード例 #12
0
 public EntityType getSpawnedType() {
   return EntityType.fromName(spawner.getMobID());
 }
コード例 #13
0
ファイル: MobType.java プロジェクト: jrbudda/CitizensAPI
 @Override
 public void load(DataKey key) {
   type = EntityType.fromName(key.getString(""));
   if (type == null) type = EntityType.PLAYER;
 }