Need help with my fortune plugin

Discussion in 'Plugin Development' started by PerezHD, Dec 30, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    PerezHD

    Hey guys I need some help here because I am attempting to make my fortune high as possible and so you can earn more blocks per fortune, this is making my code really long due to the method I am doing this

    CODE:
    Code:
          if (type.equals(Material.ENDER_STONE))
          {
            block.setType(Material.AIR);
            e.setCancelled(true);
              if (amount <= 10) {
                p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 2) });
              }
              if ((amount > 10) && (amount <= 20)) {
                p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 3) });
              }
              if ((amount > 20) && (amount <= 30)) {
                p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 6) });
              }
              if ((amount > 30) && (amount <= 40)) {
                p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 7) });
              }
              if ((amount > 40) && (amount <= 50)) {
                p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 9) });
              }
              if ((amount > 50) && (amount <= 60)) {
                p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 11) });
              }
              if ((amount > 60) && (amount <= 90)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 13) });
                }
              if ((amount > 90) && (amount <= 110)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 15) });
                }
              if ((amount > 110) && (amount <= 125)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 17) });
                }
              if ((amount > 125) && (amount <= 140)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 21) });
                }
              if ((amount > 140) && (amount <= 155)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 23) });
                }
              if ((amount > 155) && (amount <= 160)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 24) });
                }
              if ((amount > 160) && (amount <= 165)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 25) });
                }
              if ((amount > 165) && (amount <= 170)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 30) });
                }
              if ((amount > 170) && (amount <= 175)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 32) });
                }
              if ((amount > 175) && (amount <= 182)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 35) });
                }
              if ((amount > 182) && (amount <= 190)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 40) });
                }
              if ((amount > 190) && (amount <= 201)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 41) });
                }
              if ((amount > 201) && (amount <= 205)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 43) });
                }
              if ((amount > 205) && (amount <= 230)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 44) });
                }
              if ((amount > 230) && (amount <= 344)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 47) });
                }
              if ((amount > 344) && (amount <= 350)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 49) });
                }
              if ((amount > 350) && (amount <= 355)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 50) });
                }
              if ((amount > 355) && (amount <= 380)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 55) });
                }
              if ((amount > 380) && (amount <= 400)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 57) });
                }
              if ((amount > 400) && (amount <= 415)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 60) });
                }
              if ((amount > 415) && (amount <= 435)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 64) });
                }
              if ((amount > 435) && (amount <= 440)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 66) });
                }
              if ((amount > 440) && (amount <= 450)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 67) });
                }
              if ((amount > 450) && (amount <= 460)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 70) });
                }
              if ((amount > 460) && (amount <= 470)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 75) });
                }
              if ((amount > 470) && (amount <= 480)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 79) });
                }
              if ((amount > 480) && (amount <= 490)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 82) });
                }
              if ((amount > 490) && (amount <= 500)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 85) });
                }
              if ((amount > 500) && (amount <= 510)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 90) });
                }
              if ((amount > 510) && (amount <= 520)) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 120) });
                }
              if (amount > 520) {
                  p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.ENDER_STONE, 120) });
                }
            }
    And basically since it takes up so much space, I wonder if someone can tell me on how I could make it so every 2 fortunes you have added, would add 2 blocks

    For example, if I have Fortune 2 enchanted on my pickaxe, and I mine, I would only get 2 blocks per endstone broken, so if I added another 2 to my fortune which is Fortune 4, it would add 2 blocks per endstone broken so it would give 4 blocks on endstone mined. Please help me. I totally need a new method.
     
  2. Offline

    teej107

    Get the fortune enchantment. Make a new ItemStack with the amount equal to the fortune enchantment level. Btw the addItem method doesn't need a new array in the parameters.
     
  3. Invisible

    nverdier

    So the player gets the level on their pickaxe? You could just get the level of fortune from that item in their hand, and then it's pretty straightforwards from there.
     
  4. Offline

    PerezHD

    @nverdier May I get an example on this please?
     
  5. Invisible

    nverdier

    Code:
    int level = player.getInventory().getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
    
    player.getInventory.addItem(new ItemStack(Material.ENDER_STONE, level));
    And add null checks and if it's 0 then give 1 or whatever.
     
  6. Offline

    PerezHD

    O I see, picture perfect!
     
    nverdier likes this.
Thread Status:
Not open for further replies.

Share This Page