org.bukkit.event.hanging.HangingBreakEvent Java Examples

The following examples show how to use org.bukkit.event.hanging.HangingBreakEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LWCPlayerListener.java    From Modern-LWC with MIT License 6 votes vote down vote up
@EventHandler
public void hangingBreak(HangingBreakEvent event) {
    Entity entity = event.getEntity();
    if (plugin.getLWC().isProtectable(event.getEntity().getType())) {
        int A = 50000 + entity.getUniqueId().hashCode();

        LWC lwc = LWC.getInstance();
        Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A);
        if (protection != null) {
            if (event.getCause() == RemoveCause.PHYSICS || event.getCause() == RemoveCause.EXPLOSION
                    || event.getCause() == RemoveCause.OBSTRUCTION) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example #2
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onHangingBreak(final HangingBreakEvent event) {
  cancelUnlessInteracting(
      event,
      event instanceof HangingBreakByEntityEvent
          ? ((HangingBreakByEntityEvent) event).getRemover()
          : null);
}
 
Example #3
Source File: ProtectionHandler.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onHangingBreakEvent(HangingBreakEvent event) {
    if (event instanceof HangingBreakByEntityEvent) {
        onPaintingBreak((HangingBreakByEntityEvent) event);
        return;
    }
    shouldBlockAction(event.getEntity().getLocation(), null, "block_break");
}
 
Example #4
Source File: ExhibitionListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(priority = HIGHEST, ignoreCancelled = true)
public void onItemFrameBreak(HangingBreakEvent ev) {
    if (!(ev.getEntity() instanceof ItemFrame)) return;
    ItemFrame f = (ItemFrame) ev.getEntity();
    if (f.getItem() == null || f.getItem().getType() == Material.AIR) return;
    if (ExhibitionFrame.fromItemFrame(f).isSet()) {
        if (ev.getCause() == HangingBreakEvent.RemoveCause.EXPLOSION) { // Explosion protect
            ev.setCancelled(true);
        } else {
            plugin.getLogger().warning(String.format("Exhibition broken: Location: %s, item: %s", f.getLocation().toString(),
                    f.getItem().toString()));
            f.setItem(new ItemStack(Material.AIR));
        }
    }
}
 
Example #5
Source File: HangingListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onHangingBreak(HangingBreakEvent event) {
  Hanging hanging = event.getEntity();
  if (event.getCause().equals(RemoveCause.OBSTRUCTION)) {
    hanging.getLocation().getBlock().breakNaturally();
    event.setCancelled(true);
  } else if (event.getCause().equals(RemoveCause.EXPLOSION)) {
    event.setCancelled(true);
  }

}
 
Example #6
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onFrameBrake(HangingBreakEvent e) {
    Location l = e.getEntity().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null) {
        return;
    }

    if (e.getCause().toString().equals("EXPLOSION")) {
        if (!RedProtect.get().config.globalFlagsRoot().worlds.get(l.getWorld().getName()).entity_block_damage) {
            e.setCancelled(true);
        }
    }
}
 
Example #7
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onFrameBrake(HangingBreakEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - HangingBreakEvent event");

    Entity ent = e.getEntity();
    Location l = e.getEntity().getLocation();

    if ((ent instanceof ItemFrame || ent instanceof Painting) && (e.getCause().toString().equals("EXPLOSION"))) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canFire()) {
            e.setCancelled(true);
        }
    }
}
 
Example #8
Source File: BlockBreakRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onHangingBreak(HangingBreakEvent event) {
    if (event instanceof HangingBreakByEntityEvent) {
        if (region.contains(event.getEntity().getLocation().toVector()) && filter.evaluate(event.getEntity(), ((HangingBreakByEntityEvent) event).getRemover(), event).equals(FilterState.DENY)) {
            event.setCancelled(true);
        }
    } else {
        if (region.contains(event.getEntity().getLocation().toVector()) && filter.evaluate(event.getEntity(), event).equals(FilterState.DENY)) {
            event.setCancelled(true);
        }
    }
}
 
Example #9
Source File: BlockEventRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onHangingBreak(HangingBreakEvent event) {
    if (event instanceof HangingBreakByEntityEvent) {
        if (region.contains(event.getEntity().getLocation().toVector()) && filter.evaluate(event.getEntity(), ((HangingBreakByEntityEvent) event).getRemover(), event).equals(FilterState.DENY)) {
            event.setCancelled(true);
        }
    } else {
        if (region.contains(event.getEntity().getLocation().toVector()) && filter.evaluate(event.getEntity(), event).equals(FilterState.DENY)) {
            event.setCancelled(true);
        }
    }
}
 
Example #10
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onHangingBreak(final HangingBreakEvent event) {
    cancelUnlessInteracting(event, event instanceof HangingBreakByEntityEvent ? ((HangingBreakByEntityEvent) event).getRemover()
                                                                              : null);
}
 
Example #11
Source File: DWorldListener.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onHangingBreak(HangingBreakEvent event) {
    onTouch(event, event.getEntity(), false);
}
 
Example #12
Source File: WorldFreeze.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onHangingBreak(HangingBreakEvent event) {
    if (!match.isRunning()) {
        event.setCancelled(true);
    }
}