Solved Flint drop rates

Discussion in 'Plugin Development' started by StarRocket, Feb 6, 2016.

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

    StarRocket

    Code:
        @EventHandler
        public void flintDrop(BlockBreakEvent e) {
            if (e.getBlock().getType().equals(new ItemStack(Material.GRAVEL))) {
                if (e.getPlayer().hasPermission("archer.use")) {
                    e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(Material.FLINT));
                }
            }
        }
    I'm sure I'm making a stupid mistake, but I am making a kit that when selected will give you a permission and then when you break gravel it will check if you have permissions and drop flint each time. Could someone point me in the right direct to fix it?
    Edit: I have looked around on google and can't seem to find anything useful about block drop rates, I have permissions registered, and I already have a command that can be run to give players permission

    Dropping flint on each break now works, but it always drops gravel with it.
    Code:
        @EventHandler
        public void flintDrop(BlockBreakEvent e) {
            Player p = e.getPlayer();
            if (e.getBlock().getType() == Material.GRAVEL) {
                if (p.hasPermission("archer.use")) {
                    e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(Material.FLINT));
                }
            }
        }
    I've tried adding in
    Code:
    e.getBlock().getDrops().clear();
    before running the flint drop line but it did not seem to work, does anyone have a solution?
     
    Last edited by a moderator: Feb 6, 2016
  2. Offline

    Xerox262

    @StarRocket Cancel the event and set the block to Air.
     
  3. Offline

    q8minecraft

    @Xerox262 As this is BlockBreakEvent, you'd not be able to break blocks if you cancel it.

    @StarRocket Listen to the event, store the drops in a list, clear them and spawn a flint on the block's location. This should work.
     
  4. Offline

    Xerox262

    @q8minecraft That is what setting the type to air is for. It makes it look as though the block was broken, it will disappear.
     
  5. Offline

    StarRocket

    @Xerox262 @q8minecraft Will try those ideas, thanks

    Edit: Got it working with this:
    Code:
        @EventHandler
        public void flintDrop(BlockBreakEvent e) {
            Player p = e.getPlayer();
            if (e.getBlock().getType() == Material.GRAVEL) {
                if (p.hasPermission("archer.use")) {
                    e.getBlock().setType(Material.AIR);
                    e.setCancelled(true);
                    e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(Material.FLINT));
                }
            }
        }
     
    Xerox262 likes this.
Thread Status:
Not open for further replies.

Share This Page