stop specific player placing blocks/entities

Discussion in 'Plugin Development' started by DanishDuckling, Jun 21, 2013.

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

    DanishDuckling

    Which event do I need to use, to check if specific players are placing something?

    I tried the "BlockCanBuildEvent" but it doesn't tell me which player is trying to place it :(

    please note, it should fire for everything placed, be that a block, tall grass/flower or whatever. (Anti build like)
     
  2. Offline

    RentAMonkey

    what about BlockPlaceEvent ? :)
     
  3. Offline

    CluelessDev


    Use the BlockPlaceEvent and BlockBreakEvent. If you don't want them to be able to place the block, cancel the event. You'll have to use interact events for certain things like Paintings and Item Frames because they're considered Entities, not blocks.
     
  4. Offline

    DanishDuckling

    Which interact events?
    and thank you :)
     
  5. Offline

    marti.2001

    PlayerInteractEvent
     
  6. Offline

    blm456

    Here is how I'd do it.
    Code:java
    1.  
    2. public final HashMap<Player, String> blacklist = new HashMap<Player, String>();
    3. @EventHandler
    4. public void onBlockPlace(BlockPlaceEvent e){
    5. Player p = e.getPlayer();
    6. if(blacklist.containsKey(p)){
    7. e.setCancelled(true);
    8. }
    9. }

    Then add people to the HashMap with:
    Code:java
    1.  
    2. blacklist.put(p, null);
    3.  

    "p" is the player
     
    ProtoTempus likes this.
  7. Offline

    ProtoTempus

    Should never save the Player class, instead save their name.
    HashMap(kinda useless and a waste) should be ArrayList and not be final.

    Otherwise great job.


    blm456 With my highly suggested changes:
    Code:java
    1.  
    2. public ArrayList<String> blacklist = new ArrayList<String>();
    3. @EventHandler
    4. public void onBlockPlace(BlockPlaceEvent e){
    5. Player p = e.getPlayer();
    6. if(blacklist.contains(p.getName())){
    7. e.setCancelled(true);
    8. }
    9. }

    Then add people to the ArrayList with:
    Code:java
    1.  
    2. blacklist.add(p.getName());
    3.  
     
  8. Offline

    blm456

  9. Offline

    DanishDuckling

Thread Status:
Not open for further replies.

Share This Page