Ignore durability and drops in Creative.

Discussion in 'Plugin Development' started by BrandonHopkins, Aug 26, 2012.

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

    BrandonHopkins

    Hello, I'm not the best with java and I was wondering if someone can help me out and make it so the features are disabled if the user is in creative. Thanks.

    Code:
        @EventHandler
        public void blockBreaking(BlockBreakEvent event)
        {
            Player p = event.getPlayer();
            int id = p.getItemInHand().getTypeId();
                if (id >= 290 && id <= 294 && event.getBlock().getTypeId() == 79)
                if(p.hasPermission("machidrop.use.ice"))
                {
                    ItemStack hand = p.getItemInHand();
                    hand.setDurability((short) (p.getItemInHand().getDurability() + 10));
                    p.setItemInHand(hand.getDurability() > hand.getType().getMaxDurability() ? null : hand);
                    event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(79, 1));
                    event.getBlock().setType(Material.AIR);
                } else
                {
                    p.sendMessage(ChatColor.RED + "[MachiDrop] You don't have permission to use this tool");
                }
    Thanks :3
     
  2. So you want to damage tools and drop blocks normally ?

    You can use block.breakNaturally(iteminhand) to generate the propper drops.

    However +10 damage is kinda too much... you should consult the wiki on the actual damage values.

    And you should use .getType() == Material.NAME as it would be alot easier to figure out what blocks/items you're checking instead of starting to search for the freaking id :)
     
  3. Offline

    Giant

    Digi, he actually wants the code to NOT work when the player is in creative mode ;)

    BrandonHopkins what you could do is
    Code:
    if(p.getGameMode() == GameMode.CREATIVE)
        return;
    
     
  4. Offline

    BrandonHopkins

    Thanks :3 I tried it and it worked in one stop. Is there a more efficient place to drop it in at?
     
  5. Offline

    Giant

    it would be at the top of the event right after casting it to the player, but that is as far as I know, your only option...
     
Thread Status:
Not open for further replies.

Share This Page