@Override
  public void run() {
    if (master.contchunks.isEmpty()) return;

    World world = master.team.getMatch().getWorld();
    Location loc = new Location(world, 0, 0, 0);
    Set<BlockData> goals = master.searching;
    for (int i = 0; i < 15; i++) // 15 chunks per run
    {
      Vector vec = master.entitychunks.poll();
      if (vec == null) {
        this.cancel();
        return;
      }
      BlockState[] containers =
          world
              .getChunkAt(vec.getBlockX(), vec.getBlockZ())
              .getTileEntities(); // actually chunk-coords

      for (BlockState state : containers) {
        if (state instanceof InventoryHolder) {
          Inventory inv = ((InventoryHolder) state).getInventory();
          if (state instanceof Chest) inv = ((Chest) state).getBlockInventory();
          checkInventory(inv, goals, state.getLocation(loc));
        }
        // TODO: spawners
      }
    }
  }
Exemple #2
0
  public boolean loadSign(
      final World w, final int x1, final int x2, final int z1, final int z2, final int y1) {
    final boolean usingx = (x1 == x2) ? false : true;
    HungerGames.debug(w + " " + x1 + " " + x2 + " " + z1 + " " + z2 + " " + y1 + " " + usingx);
    final BlockFace facing =
        ((org.bukkit.material.Sign) new Location(w, x1, y1, z1).getBlock().getState()).getFacing();

    if (usingx) {
      for (int a = Math.max(x1, x2); a >= Math.min(x1, x2); a--) {
        final Location l = new Location(w, a, y1, z1);
        final BlockState b = l.getBlock().getState();
        if (b instanceof Sign) {
          signs.add((Sign) b);
          LobbyManager.lobbychunks.add(b.getChunk());
          HungerGames.debug("usingx - " + b.getLocation().toString());
        } else {
          HungerGames.debug("Not a sign" + b.getType().toString());
          return false;
        }
      }
    } else {
      for (int a = Math.min(z1, z2); a <= Math.max(z1, z2); a++) {
        HungerGames.debug(a);
        final Location l = new Location(w, x1, y1, a);
        final BlockState b = l.getBlock().getState();
        if (b instanceof Sign) {
          signs.add((Sign) b);
          LobbyManager.lobbychunks.add(b.getChunk());
          HungerGames.debug("notx - " + b.getLocation().toString());
        } else {
          HungerGames.debug("Not a sign" + b.getType().toString());
          return false;
        }
      }
    }
    // HungerGames.debug("dir: " + dir);
    if (facing == BlockFace.NORTH || facing == BlockFace.EAST) {
      Collections.reverse(signs);
    }
    addMsg("HungerGames");
    addMsg("Minealot");
    addMsg("minealot.com");
    addMsg("Game id: " + gameid);
    update();
    return true;
  }
  /**
   * Process the Hylian Luck ability.
   *
   * @param blockState The {@link BlockState} to check ability activation for
   * @return true if the ability was successful, false otherwise
   */
  public boolean processHylianLuck(BlockState blockState) {
    if (!SkillUtils.activationSuccessful(
        SecondaryAbility.HYLIAN_LUCK, getPlayer(), getSkillLevel(), activationChance)) {
      return false;
    }

    List<HylianTreasure> treasures;

    switch (blockState.getType()) {
      case DEAD_BUSH:
      case LONG_GRASS:
      case SAPLING:
        treasures = TreasureConfig.getInstance().hylianFromBushes;
        break;

      case RED_ROSE:
      case YELLOW_FLOWER:
        if (mcMMO.getPlaceStore().isTrue(blockState)) {
          mcMMO.getPlaceStore().setFalse(blockState);
          return false;
        }

        treasures = TreasureConfig.getInstance().hylianFromFlowers;
        break;

      case FLOWER_POT:
        treasures = TreasureConfig.getInstance().hylianFromPots;
        break;

      default:
        return false;
    }

    Player player = getPlayer();

    if (treasures.isEmpty()
        || !EventUtils.simulateBlockBreak(blockState.getBlock(), player, false)) {
      return false;
    }

    blockState.setType(Material.AIR);

    Misc.dropItem(
        blockState.getLocation(),
        treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
    player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
    return true;
  }
 /*
  * (non-Javadoc)
  * @see com.nitnelave.CreeperHeal.block.Replaceable#getLocation()
  */
 @Override
 public Location getLocation() {
   return blockState.getLocation();
 }
  /** @param blockState The {@link BlockState} to check ability activation for */
  public void herbalismBlockCheck(BlockState blockState) {
    Player player = getPlayer();
    Material material = blockState.getType();
    boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.SUGAR_CANE_BLOCK);

    if (oneBlockPlant && mcMMO.getPlaceStore().isTrue(blockState)) {
      return;
    }

    if (!canBlockCheck()) {
      return;
    }

    Collection<ItemStack> drops = null;
    int amount = 1;
    int xp;
    boolean greenTerra = mcMMOPlayer.getAbilityMode(skill.getAbility());

    if (mcMMO.getModManager().isCustomHerbalismBlock(blockState)) {
      CustomBlock customBlock = mcMMO.getModManager().getBlock(blockState);
      xp = customBlock.getXpGain();

      if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.HERBALISM_DOUBLE_DROPS)
          && customBlock.isDoubleDropEnabled()) {
        drops = blockState.getBlock().getDrops();
      }
    } else {
      if (Permissions.greenThumbPlant(player, material)) {
        processGreenThumbPlants(blockState, greenTerra);
      }

      xp = ExperienceConfig.getInstance().getXp(skill, material);

      if (Config.getInstance().getDoubleDropsEnabled(skill, material)
          && Permissions.secondaryAbilityEnabled(player, SecondaryAbility.HERBALISM_DOUBLE_DROPS)) {
        drops = blockState.getBlock().getDrops();
      }

      if (!oneBlockPlant) {
        amount = Herbalism.calculateCatciAndSugarDrops(blockState);
        xp *= amount;
      }
    }

    applyXpGain(xp);

    if (drops == null) {
      return;
    }

    for (int i = greenTerra ? 2 : 1; i != 0; i--) {
      if (SkillUtils.activationSuccessful(
          SecondaryAbility.HERBALISM_DOUBLE_DROPS,
          getPlayer(),
          getSkillLevel(),
          activationChance)) {
        for (ItemStack item : drops) {
          Misc.dropItems(blockState.getLocation(), item, amount);
        }
      }
    }
  }