/**
   * Handle the Leaf Blower ability.
   *
   * @param player Player using the ability
   * @param block Block being broken
   */
  public static void leafBlower(Player player, Block block) {
    FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
    mcMMO.p.getServer().getPluginManager().callEvent(armswing);

    if (Config.getInstance().getWoodcuttingRequiresTool()) {
      Skills.abilityDurabilityLoss(
          player.getItemInHand(), Config.getInstance().getAbilityToolDamage());
    }

    if (mcMMO.spoutEnabled) {
      SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
    }
  }
  /**
   * Check XP gain for woodcutting.
   *
   * @param player The player breaking the block
   * @param block The block being broken
   */
  public static void woodcuttingBlockCheck(Player player, Block block) {
    PlayerProfile profile = Users.getProfile(player);
    int xp = 0;

    if (mcMMO.placeStore.isTrue(block)) {
      return;
    }

    if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
      xp = ModChecks.getCustomBlock(block).getXpGain();
    } else {
      byte type = block.getData();

      if ((type & 0x4) == 0x4) type ^= 0x4;

      if ((type & 0x8) == 0x8) type ^= 0x8;

      TreeSpecies species = TreeSpecies.getByData(type);

      // Apparently species can be null in certain cases (custom server mods?)
      // https://github.com/mcMMO-Dev/mcMMO/issues/229
      if (species == null) return;

      switch (species) {
        case GENERIC:
          xp += Config.getInstance().getWoodcuttingXPOak();
          break;

        case REDWOOD:
          xp += Config.getInstance().getWoodcuttingXPSpruce();
          break;

        case BIRCH:
          xp += Config.getInstance().getWoodcuttingXPBirch();
          break;

        case JUNGLE:
          xp += Config.getInstance().getWoodcuttingXPJungle();
          break;

        default:
          break;
      }
    }

    WoodCutting.woodCuttingProcCheck(player, block);
    Skills.xpProcessing(player, profile, SkillType.WOODCUTTING, xp);
  }
Exemple #3
0
  /**
   * Handle triple drops from Giga Drill Breaker.
   *
   * @param player The player using the ability
   * @param block The block to check
   */
  public static void gigaDrillBreaker(Player player, Block block) {
    Skills.abilityDurabilityLoss(
        player.getItemInHand(), Config.getInstance().getAbilityToolDamage());

    if (!mcMMO.placeStore.isTrue(block)) {
      FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
      mcMMO.p.getServer().getPluginManager().callEvent(armswing);

      Excavation.excavationProcCheck(block, player);
      Excavation.excavationProcCheck(block, player);
    }

    if (mcMMO.p.spoutEnabled) {
      SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
    }
  }
  @Override
  protected void effectsDisplay() {
    if (lucky) {
      String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix");
      player.sendMessage(
          perkPrefix
              + LocaleLoader.getString(
                  "Effects.Template",
                  new Object[] {
                    LocaleLoader.getString("Perks.lucky.name"),
                    LocaleLoader.getString(
                        "Perks.lucky.desc",
                        new Object[] {Skills.localizeSkillName(SkillType.EXCAVATION)})
                  }));
    }

    if (canGigaDrill) {
      player.sendMessage(
          LocaleLoader.getString(
              "Effects.Template",
              new Object[] {
                LocaleLoader.getString("Excavation.Effect.0"),
                LocaleLoader.getString("Excavation.Effect.1")
              }));
    }

    if (canTreasureHunt) {
      player.sendMessage(
          LocaleLoader.getString(
              "Effects.Template",
              new Object[] {
                LocaleLoader.getString("Excavation.Effect.2"),
                LocaleLoader.getString("Excavation.Effect.3")
              }));
    }
  }
Exemple #5
0
  /**
   * Check to see if treasures were found.
   *
   * @param block The block to check
   * @param player The player who broke the block
   */
  public static void excavationProcCheck(Block block, Player player) {
    Material type = block.getType();
    Location loc = block.getLocation();

    PlayerProfile PP = Users.getProfile(player);
    int skillLevel = PP.getSkillLevel(SkillType.EXCAVATION);
    ArrayList<ItemStack> is = new ArrayList<ItemStack>();

    List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();

    int xp;

    if (Config.getInstance().getBlockModsEnabled()
        && CustomBlocksConfig.getInstance()
            .customExcavationBlocks
            .contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
      xp = ModChecks.getCustomBlock(block).getXpGain();
    } else {
      xp = Config.getInstance().getExcavationBaseXP();
    }

    if (Permissions.getInstance().excavationTreasures(player)) {
      switch (type) {
        case DIRT:
          treasures = TreasuresConfig.getInstance().excavationFromDirt;
          break;

        case GRASS:
          treasures = TreasuresConfig.getInstance().excavationFromGrass;
          break;

        case SAND:
          treasures = TreasuresConfig.getInstance().excavationFromSand;
          break;

        case GRAVEL:
          treasures = TreasuresConfig.getInstance().excavationFromGravel;
          break;

        case CLAY:
          treasures = TreasuresConfig.getInstance().excavationFromClay;
          break;

        case MYCEL:
          treasures = TreasuresConfig.getInstance().excavationFromMycel;
          break;

        case SOUL_SAND:
          treasures = TreasuresConfig.getInstance().excavationFromSoulSand;
          break;

        default:
          break;
      }

      for (ExcavationTreasure treasure : treasures) {
        if (skillLevel >= treasure.getDropLevel()) {
          if (random.nextDouble() * 100 <= treasure.getDropChance()) {
            xp += treasure.getXp();
            is.add(treasure.getDrop());
          }
        }
      }

      // Drop items
      for (ItemStack x : is) {
        if (x != null) {
          Misc.dropItem(loc, x);
        }
      }
    }

    // Handle XP related tasks
    PP.addXP(player, SkillType.EXCAVATION, xp);
    Skills.XpCheckSkill(SkillType.EXCAVATION, player);
  }
  /**
   * Handles removing & dropping the blocks from Tree Feller.
   *
   * @param toBeFelled List of Blocks to be removed from the tree
   * @param player The player using the ability
   * @param profile The PlayerProfile of the player
   */
  private static void removeBlocks(
      ArrayList<Block> toBeFelled, Player player, PlayerProfile profile) {
    if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) {
      player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
      return;
    }

    int xp = 0;
    ItemStack inHand = player.getItemInHand();
    int level = 0;
    if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
      level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
    }
    int durabilityLoss = durabilityLossCalulate(toBeFelled, level);

    /* This is to prevent using wood axes everytime you tree fell */
    if (ModChecks.isCustomTool(inHand)) {
      if (inHand.getDurability() + durabilityLoss
          >= ModChecks.getToolFromItemStack(inHand).getDurability()) {
        player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));

        int health = player.getHealth();

        if (health >= 2) {
          Combat.dealDamage(player, random.nextInt(health - 1));
        }
        inHand.setDurability((short) (inHand.getType().getMaxDurability()));
        return;
      }
    } else if ((inHand.getDurability() + durabilityLoss >= inHand.getType().getMaxDurability())
        || inHand.getType().equals(Material.AIR)) {
      player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));

      int health = player.getHealth();

      if (health >= 2) {
        Combat.dealDamage(player, random.nextInt(health - 1));
      }
      inHand.setDurability((short) (inHand.getType().getMaxDurability()));
      return;
    }

    /* Damage the tool */
    inHand.setDurability((short) (inHand.getDurability() + durabilityLoss));

    // Prepare ItemStacks
    ItemStack item = null;
    ItemStack oak = (new MaterialData(Material.LOG, TreeSpecies.GENERIC.getData())).toItemStack(1);
    ItemStack spruce =
        (new MaterialData(Material.LOG, TreeSpecies.REDWOOD.getData())).toItemStack(1);
    ItemStack birch = (new MaterialData(Material.LOG, TreeSpecies.BIRCH.getData())).toItemStack(1);
    ItemStack jungle =
        (new MaterialData(Material.LOG, TreeSpecies.JUNGLE.getData())).toItemStack(1);

    for (Block x : toBeFelled) {
      if (Misc.blockBreakSimulate(x, player, true)) {
        if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x)) {
          if (ModChecks.isCustomLogBlock(x)) {
            CustomBlock block = ModChecks.getCustomBlock(x);
            item = block.getItemDrop();

            if (!mcMMO.placeStore.isTrue(x)) {
              WoodCutting.woodCuttingProcCheck(player, x);
              xp = block.getXpGain();
            }

            /* Remove the block */
            x.setData((byte) 0x0);
            x.setType(Material.AIR);

            int minimumDropAmount = block.getMinimumDropAmount();
            int maximumDropAmount = block.getMaximumDropAmount();

            item = block.getItemDrop();

            if (minimumDropAmount != maximumDropAmount) {
              Misc.dropItems(x.getLocation(), item, minimumDropAmount);
              Misc.randomDropItems(
                  x.getLocation(), item, 50, maximumDropAmount - minimumDropAmount);
            } else {
              Misc.dropItems(x.getLocation(), item, minimumDropAmount);
            }
          } else if (ModChecks.isCustomLeafBlock(x)) {
            CustomBlock block = ModChecks.getCustomBlock(x);
            item = block.getItemDrop();

            final int SAPLING_DROP_CHANCE = 10;

            /* Remove the block */
            x.setData((byte) 0x0);
            x.setType(Material.AIR);

            Misc.randomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE);
          }
        } else if (x.getType() == Material.LOG) {
          Tree tree = (Tree) x.getState().getData();
          TreeSpecies species = tree.getSpecies();

          switch (species) {
            case GENERIC:
              item = oak;
              break;

            case REDWOOD:
              item = spruce;
              break;

            case BIRCH:
              item = birch;
              break;

            case JUNGLE:
              item = jungle;
              break;

            default:
              break;
          }

          if (!mcMMO.placeStore.isTrue(x)) {
            WoodCutting.woodCuttingProcCheck(player, x);

            switch (species) {
              case GENERIC:
                xp += Config.getInstance().getWoodcuttingXPOak();
                break;

              case REDWOOD:
                xp += Config.getInstance().getWoodcuttingXPSpruce();
                break;

              case BIRCH:
                xp += Config.getInstance().getWoodcuttingXPBirch();
                break;

              case JUNGLE:
                xp +=
                    Config.getInstance().getWoodcuttingXPJungle()
                        / 2; // Nerf XP from Jungle Trees when using Tree Feller
                break;

              default:
                break;
            }
          }

          /* Remove the block */
          x.setData((byte) 0x0);
          x.setType(Material.AIR);

          /* Drop the block */
          Misc.dropItem(x.getLocation(), item);
        } else if (x.getType() == Material.LEAVES) {
          final int SAPLING_DROP_CHANCE = 10;

          // Drop the right type of sapling
          item = (new MaterialData(Material.SAPLING, (byte) (x.getData() & 3))).toItemStack(1);

          Misc.randomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE);

          // Remove the block
          x.setData((byte) 0);
          x.setType(Material.AIR);
        }
      }
    }

    if (Permissions.getInstance().woodcutting(player)) {
      Skills.xpProcessing(player, profile, SkillType.WOODCUTTING, xp);
    }
  }
Exemple #7
0
  /**
   * Monitor PlayerInteract events.
   *
   * @param event The event to watch
   */
  @EventHandler(priority = EventPriority.LOW)
  public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    Action action = event.getAction();
    Block block = event.getClickedBlock();
    ItemStack inHand = player.getItemInHand();
    Material material;

    /* Fix for NPE on interacting with air */
    if (block == null) {
      material = Material.AIR;
    } else {
      material = block.getType();
    }

    switch (action) {
      case RIGHT_CLICK_BLOCK:

        /* REPAIR CHECKS */
        if (Permissions.getInstance().repair(player)
            && block.getTypeId() == Config.getInstance().getRepairAnvilId()) {
          if (mcMMO.repairManager.isRepairable(inHand)) {
            mcMMO.repairManager.handleRepair(player, inHand);
            event.setCancelled(true);
            player.updateInventory();
          }
        }

        /* ACTIVATION CHECKS */
        if (Config.getInstance().getAbilitiesEnabled() && BlockChecks.abilityBlockCheck(block)) {
          if (!material.equals(Material.DIRT)
              && !material.equals(Material.GRASS)
              && !material.equals(Material.SOIL)) {
            Skills.activationCheck(player, SkillType.HERBALISM);
          }

          Skills.activationCheck(player, SkillType.AXES);
          Skills.activationCheck(player, SkillType.EXCAVATION);
          Skills.activationCheck(player, SkillType.MINING);
          Skills.activationCheck(player, SkillType.SWORDS);
          Skills.activationCheck(player, SkillType.UNARMED);
          Skills.activationCheck(player, SkillType.WOODCUTTING);
        }

        /* GREEN THUMB CHECK */
        if (inHand.getType().equals(Material.SEEDS)
            && BlockChecks.makeMossy(block)
            && Permissions.getInstance().greenThumbBlocks(player)) {
          Herbalism.greenThumbBlocks(inHand, player, block);
        }

        /* ITEM CHECKS */
        if (BlockChecks.abilityBlockCheck(block)) {
          Item.itemChecks(player);
        }

        /* BLAST MINING CHECK */
        if (player.isSneaking()
            && inHand.getTypeId() == Config.getInstance().getDetonatorItemID()
            && Permissions.getInstance().blastMining(player)) {
          BlastMining.detonate(event, player, plugin);
        }

        break;

      case RIGHT_CLICK_AIR:

        /* ACTIVATION CHECKS */
        if (Config.getInstance().getAbilitiesEnabled()) {
          Skills.activationCheck(player, SkillType.AXES);
          Skills.activationCheck(player, SkillType.EXCAVATION);
          Skills.activationCheck(player, SkillType.HERBALISM);
          Skills.activationCheck(player, SkillType.MINING);
          Skills.activationCheck(player, SkillType.SWORDS);
          Skills.activationCheck(player, SkillType.UNARMED);
          Skills.activationCheck(player, SkillType.WOODCUTTING);
        }

        /* ITEM CHECKS */
        Item.itemChecks(player);

        /* BLAST MINING CHECK */
        if (player.isSneaking()
            && inHand.getTypeId() == Config.getInstance().getDetonatorItemID()
            && Permissions.getInstance().blastMining(player)) {
          BlastMining.detonate(event, player, plugin);
        }

        break;

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:

        /* CALL OF THE WILD CHECKS */
        if (player.isSneaking()) {
          Material type = inHand.getType();

          if (type == Material.RAW_FISH) {
            TamingManager tamingManager = new TamingManager(player);
            tamingManager.summonOcelot();
          } else if (type == Material.BONE) {
            TamingManager tamingManager = new TamingManager(player);
            tamingManager.summonWolf();
          }
        }

        break;

      default:
        break;
    }
  }