onBlock Place & maybe onBlockBreak

Discussion in 'Plugin Development' started by Sammy, Mar 28, 2011.

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

    Sammy

    Today it's me you who needs a little help, every time i try too use onBlockPlace I get some kind of error...
    This one is not being able to break any block not only sand EDIT ON THE END
    I tried with and without the intenceof but still no cake...

    Code:
    public class sdMinningListener extends BlockListener {
    
        @Override
        public void onBlockPlace(BlockPlaceEvent event) {
            if (event.getBlock().getType().equals(Material.getMaterial("SAND")) && challengeMethods.started == true && event.getPlayer() instanceof Player) {
                Player ply = (Player) event.getPlayer();
                ply.sendMessage(ChatColor.RED + "You naughty person, you can't place the block you are looking for!!!");
                event.setCancelled(true);
            }
        }
        public static int mat;
        public static int qnt;
        private challengeMethods CM = new challengeMethods();
    
        @Override
        public void onBlockBreak(BlockBreakEvent event) {
            Player ply = (Player) event.getPlayer();
            if (event.getBlock().getType().equals(Material.getMaterial("SAND")) && challengeMethods.started == true) {
                challengeMethods.scores.put(ply.getName(), challengeMethods.scores.get(ply.getName()) + 1);
                event.setCancelled(true);
            } else {
                return;
            }
            ply.sendMessage(challengeMethods.scores.toString());
            if (challengeMethods.scores.get(ply.getName()) >= qnt) {
                challengeMethods.winner = ply;
                CM.GivePrize();
            }
        }
    }
    
    EDIT: Im not able to break sand...
    I want to be able to break it but not placing it again while the challenge is on
     
  2. Offline

    ssell

    You say you want to break it, but doesn't the following cancel the break event?

    Code:
    if( ( event.getBlock( ).getType( ).equals( Material.SAND ) ) && ( challengeMethods.started ) )
    {
        ...
        event.setCancelled( true );
    }
    
     
  3. Offline

    Sammy

    Omg you are right, silly me... sorry about the pointless threat...
    thank you man :D
     
  4. Offline

    ssell

    No problem. Sometimes you just need a second pair of eyes. So many times I just look right past an obvious problem.
     
  5. Offline

    Sammy

    That's true, I looked for hour and didn't found that silly error ^^
    Thanks again.
     
Thread Status:
Not open for further replies.

Share This Page