Exemplo n.º 1
0
  /**
   * Get item results from Fishing.
   *
   * @param player The player that was fishing
   * @param event The event to modify
   */
  private static void getFishingResults(Player player, PlayerFishEvent event) {
    PlayerProfile PP = Users.getProfile(player);
    List<FishingTreasure> rewards = new ArrayList<FishingTreasure>();
    Item theCatch = (Item) event.getCaught();

    switch (getFishingLootTier(PP)) {
      case 1:
        rewards = LoadTreasures.fishingRewardsTier1;
        break;

      case 2:
        rewards = LoadTreasures.fishingRewardsTier2;
        break;

      case 3:
        rewards = LoadTreasures.fishingRewardsTier3;
        break;

      case 4:
        rewards = LoadTreasures.fishingRewardsTier4;
        break;

      case 5:
        rewards = LoadTreasures.fishingRewardsTier5;
        break;

      default:
        break;
    }

    if (LoadProperties.fishingDrops) {
      FishingTreasure treasure = rewards.get(random.nextInt(rewards.size()));

      if (random.nextDouble() * 100 <= treasure.getDropChance()) {
        Users.getProfile(player).addXP(SkillType.FISHING, treasure.getXp());
        theCatch.setItemStack(treasure.getDrop());
      }
    } else {
      theCatch.setItemStack(new ItemStack(Material.RAW_FISH));
    }

    short maxDurability = theCatch.getItemStack().getType().getMaxDurability();

    if (maxDurability > 0) {
      theCatch
          .getItemStack()
          .setDurability(
              (short) (random.nextInt(maxDurability))); // Change durability to random value
    }

    m.mcDropItem(player.getLocation(), new ItemStack(Material.RAW_FISH)); // Always drop a fish
    PP.addXP(SkillType.FISHING, LoadProperties.mfishing);
    Skills.XpCheckSkill(SkillType.FISHING, player);
  }
Exemplo n.º 2
0
  public boolean collect() {

    boolean collected = false;

    for (Entity entity : LocationUtil.getNearbyEntities(centre, radius)) {
      if (entity.isValid() && entity instanceof Item) {
        if (LocationUtil.isWithinRadius(centre, entity.getLocation(), radius)) {

          stackCheck:
          {
            ItemStack stack = ((Item) entity).getItemStack();

            if (!ItemUtil.isStackValid(stack)) return false;

            for (ItemStack filter : filters) {

              if (!ItemUtil.isStackValid(filter)) continue;

              if (include && !ItemUtil.areItemsIdentical(filter, stack)) break stackCheck;
              else if (!include && ItemUtil.areItemsIdentical(filter, stack)) break stackCheck;
            }

            BlockFace back = SignUtil.getBack(BukkitUtil.toSign(getSign()).getBlock());
            Block pipe = getBackBlock().getRelative(back);

            Pipes pipes = Pipes.Factory.setupPipes(pipe, getBackBlock(), stack);

            if (pipes != null && pipes.getItems().isEmpty()) return true;

            // Add the items to a container, and destroy them.
            List<ItemStack> leftovers =
                InventoryUtil.addItemsToInventory((InventoryHolder) chest.getState(), stack);
            if (leftovers.isEmpty()) {
              entity.remove();
              return true;
            } else {
              if (ItemUtil.areItemsIdentical(leftovers.get(0), stack)
                  && leftovers.get(0).getAmount() != stack.getAmount()) {
                ((Item) entity).setItemStack(leftovers.get(0));
                return true;
              }
            }
          }
        }
      }
    }

    return collected;
  }