I want to higher the drops of crops

Discussion in 'Plugin Development' started by Bouzac, Jul 1, 2023.

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

    Bouzac

    I am doing a plugin that has classes like PVP or farmer and for farmer I want to higher the number of crops dropped by a percentage based on the xp of the player. The code I made give me an error that says that it cannot drop air. This is my code :
    Code:
    package Classes.farm;
    
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    
    public class farmer implements Listener{
    
        int level = 0;
    
        @EventHandler
        public void onBlockBreak(BlockBreakEvent event) {
            Block block = event.getBlock();
            Player player = event.getPlayer();              
    
            if(!(tools.hasTag(player, "farmer"))) return;      
            event.setDropItems(false);
    
            level = player.getLevel();
    
            if(level>100) level=100;
            int xpCount = 0;
            while(level < 20) {
                level = level - 20;
                xpCount++;
            }
    
            if(isCrop(block.getType())) {
                int dropMultiplier = 150+50*xpCount;
                ItemStack drop = new ItemStack(block.getType(), (dropMultiplier/100));
                block.getWorld().dropItemNaturally(block.getLocation(), drop);
            }
    
        }
    
    
        private boolean isCrop(Material material) {
            return material == Material.WHEAT
                    || material == Material.CARROTS
                    || material == Material.POTATOES
                    || material == Material.BEETROOTS
                    || material == Material.NETHER_WART;
        }
    }
    
    
    
     
Thread Status:
Not open for further replies.

Share This Page