Solved don't allow breaking paintings

Discussion in 'Plugin Development' started by moomann, Jul 17, 2014.

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

    moomann

    I made a code which prevents people from breaking paintings.

    Code:java
    1. @EventHandler
    2. public void onBlockHangingBreak(HangingBreakEvent event)
    3. {
    4. if(event.getEntity() instanceof Painting) {
    5.  
    6. event.setCancelled(true);
    7. }
    8. }

    somehow, it won't work,
    any suggestions?
     
  2. Offline

    Traks

    Try HangingBreakByEntityEvent, also, register your listener class if you haven't yet!
     
  3. Offline

    ZodiacTheories

    moomann Traks

    Also,

    you did if(even.getEntity() instanceof Painting) {

    Although your event variable is event.
     
  4. Offline

    moomann

    yes, just noticed. but that's only in the paste here. not in the main code.
     
  5. Offline

    ZodiacTheories

  6. Offline

    FabeGabeMC

    Why not just use a EntityDamageByEntity event and cancel if the entity is an instance of Painting?
     
  7. Offline

    _LB

    FabeGabeMC I don't think punching/shooting paintings counts as damaging them - they don't really have 'health'.
     
  8. Offline

    FabeGabeMC

    _LB but they are classified as entities so it works. I even tested it and it sure does work. :)
     
  9. Offline

    Traks

    FabeGabeMC EntityDamageByEntityEvent doesn't get called when the damaged entity is an instance of net.minecraft.server.EntityHanging, proof.
    Just use HangingBreakByEntityEvent, like I already suggested...
     
    _LB likes this.
  10. Offline

    moomann

    thanks, that worked ;)
    is it also possible to get the player who attempted to break the painting?
     
  11. Offline

    _LB

    Just call.getEntity() and see if it's a player, and if so, cast to a player.
     
  12. Offline

    Quaro

    PaintingBreakEvent
     
Thread Status:
Not open for further replies.

Share This Page