Block Break Event

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

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

    Omel

    Code:
    ArrayList<Integer> id = new ArrayList<>();
            id.add(20);
            id.add(355);
            id.add(24);
            id.add(121);
            id.add(30);
            id.add(95);
            id.add(46);
            id.add(54);
           
            for(Integer d : id){
            if(!(e.getBlock().getType().getId() == d)){
                e.setCancelled(true);
            }
            }
    It cancel ALLLLLL Pls help
     
  2. Offline

    Evonoucono

    ?
     
  3. Offline

    Omel

    @Evonoucono It cancel all block breaks that means i cant break any blocks ^^
     
  4. Offline

    Xerox262

    Probably because you're checking if it's not equal instead of if it is. Also you should use Material instead of the IDs, they're deprecated.
     
  5. Offline

    Omel

    I already used Material list ^^ @Xerox262
     
  6. Offline

    JoaoBM

    @Omel Why not just use Materials like @Xerox262 said and use the if(list.contains()) method instead of creating a for loop?
     
  7. Offline

    Xerox262

    @Omel You aren't using a material list, you're using an Integer list.

    Also, you don't need to do this
    Code:
    ArrayList<Integer> id = new ArrayList<>();
            id.add(20);
            id.add(355);
            id.add(24);
            id.add(121);
            id.add(30);
            id.add(95);
            id.add(46);
            id.add(54);
    You can do
    Code:
    ArrayList<Integer> id = Arrays.asList(20, 355, 24, 121, 30, 95, 46, 54);
    And rather than create that every time a player breaks a block, just create it in your constructor once.
     
Thread Status:
Not open for further replies.

Share This Page