Fortune + Inventory plugin

Discussion in 'Plugin Development' started by andrew4543, Jun 27, 2014.

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

    andrew4543

    I cant figure it out, I had it working fine with just dropping blocks, but i wanted it to go into the persons Inventory too. But it wont register World Guard regions( I do have it on a build path), it wont add more then 1 block to your Inventory, and once you get a 64 stack, it wont add any more on a separate stack. But now (i dont know what I did), it just wont break any blocks at all!

    Plz help!!!

    Code:
        @EventHandler (priority = EventPriority.LOWEST)
        public void onBlockBreak(BlockBreakEvent event)
        {
            Block brokenBlock = event.getBlock();
            ItemStack itemInHand = event.getPlayer().getItemInHand();
            Player gp = event.getPlayer();
            ItemStack DropType = new ItemStack(getDropType(brokenBlock.getType(), getNumDrops(0)));   
            PlayerInventory pi = gp.getInventory();
            int slot = pi.firstEmpty();
            int cslot = pi.first(DropType);
            Player g = event.getPlayer();
           
            if (g == null)
                return;
     
            if (isValid(itemInHand.getType(), brokenBlock.getType()))
            {
           
                Map<Enchantment, Integer> enchantments = itemInHand.getEnchantments();
                if (enchantments.containsKey(Enchantment.LOOT_BONUS_BLOCKS))
                {
                    event.setCancelled(true);
     
                    int numDrops = getNumDrops(enchantments.get(Enchantment.LOOT_BONUS_BLOCKS));
                                       
                    if (numDrops == -1)
                        return;
                   
     
                    else
                    pi.setItem(slot, DropType);
                    pi.addItem(DropType);
                    brokenBlock.getWorld();
                    brokenBlock.getLocation();
                    brokenBlock.setType(Material.AIR);                   
                    return;
                   
                    }
                }
           
        }
     
  2. Offline

    andrew4543

    come on help me, i have absolutely no idea

    ok i got some things done, but i can not get it to check worldguard. I have this, but it will not pull the boolean from worldguard(canBuild)
    Code:java
    1. @EventHandler(priority = EventPriority.LOWEST)
    2. public void onBlockBreak(BlockBreakEvent event) {
    3. Block brokenBlock = event.getBlock();
    4. ItemStack itemInHand = event.getPlayer().getItemInHand();
    5. Player gp = event.getPlayer();
    6. PlayerInventory pi = gp.getInventory();
    7. int slot = pi.firstEmpty();
    8. Player g = event.getPlayer();
    9.  
    10.  
    11. if (g == null)
    12. return;
    13.  
    14. if (isValid(itemInHand.getType(), brokenBlock.getType())) {
    15.  
    16. Map<Enchantment, Integer> enchantments = itemInHand
    17. .getEnchantments();
    18. if (enchantments.containsKey(Enchantment.LOOT_BONUS_BLOCKS)) {
    19. event.setCancelled(true);
    20.  
    21. int numDrops = getNumDrops(enchantments
    22. .get(Enchantment.LOOT_BONUS_BLOCKS));
    23.  
    24. if (numDrops == -1)
    25. return;
    26. org.bukkit.Location loc = brokenBlock.getLocation();
    27. if (canBuild(g, loc) == false)
    28. return;
    29.  
    30.  
    31. ItemStack DropType = new ItemStack(getDropType(
    32. brokenBlock.getType(), numDrops));
    33. int cslot = pi.first(DropType);
    34.  
    35. if (cslot + slot == -2)
    36. return;
    37.  
    38. else
    39. pi.addItem(DropType);
    40. brokenBlock.setType(Material.AIR);
    41. return;
    42.  
    43. }
    44. }
    45. }
    46.  


    Pease anybody, I need help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  3. Offline

    iTornado1234

    So your issue is that you cannot hook into worldguard to check if where the player broke the block is in a region?
     
  4. Offline

    andrew4543

    thanks tornado, but i already got it working. It turns out they tell you on there wiki how to hook it into worldguard! I feel so stupid!
     
Thread Status:
Not open for further replies.

Share This Page