@EventHandler public void onHangingBreak(HangingBreakEvent event) { if(event.isCancelled()) return; if(event.getCause() == RemoveCause.ENTITY) event.setCancelled(true); }
@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); } }
@EventHandler public void onHangingBreak(HangingBreakEvent event) { if (event.getCause() == RemoveCause.ENTITY) { HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent) event; if (entityEvent.getRemover() instanceof Player) { Player remover = (Player) entityEvent.getRemover(); if (remover.isOp() && remover.getGameMode() == GameMode.CREATIVE) { return; } } } event.setCancelled(true); }
/** * On hanging break. * * @param event the event */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onHangingBreak(HangingBreakEvent event) { if (conf.isOverrideExplosions()) { // Check for painting if (event.getCause() == RemoveCause.EXPLOSION) { Factoid.getThisPlugin().iLog().write("Cancel HangingBreak : " + event.getEntity() + ", Cause: " + event.getCause()); event.setCancelled(true); } } }
@EventHandler public void onHangingBreak(HangingBreakEvent event) { if (event.getCause() == RemoveCause.DEFAULT || event.getCause() == RemoveCause.EXPLOSION) event.setCancelled(true); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onHangingBreak(HangingBreakEvent event) { //don't track in worlds where claims are not enabled if(!GriefPrevention.instance.claimsEnabledForWorld(event.getEntity().getWorld())) return; //FEATURE: claimed paintings are protected from breakage //explosions don't destroy hangings if(event.getCause() == RemoveCause.EXPLOSION) { event.setCancelled(true); return; } //only allow players to break paintings, not anything else (like water and explosions) if(!(event instanceof HangingBreakByEntityEvent)) { event.setCancelled(true); return; } HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent)event; //who is removing it? Entity remover = entityEvent.getRemover(); //again, making sure the breaker is a player if(!(remover instanceof Player)) { event.setCancelled(true); return; } //if the player doesn't have build permission, don't allow the breakage Player playerRemover = (Player)entityEvent.getRemover(); String noBuildReason = GriefPrevention.instance.allowBuild(playerRemover, event.getEntity().getLocation(), Material.AIR); if(noBuildReason != null) { event.setCancelled(true); GriefPrevention.sendMessage(playerRemover, TextMode.Err, noBuildReason); } }
@EventHandler public void onHangingBreak(final HangingBreakEvent event) { if (!this.module.canBeProtected(event.getEntity().getType(), event.getEntity().getLocation())) { return; } Optional<EntityProtection> prot = this.module.cache.getByUniqueId(event.getEntity().getUniqueId()); if (!prot.isPresent()) { return; } if (event.getCause().equals(RemoveCause.EXPLOSION) || event.getCause().equals(RemoveCause.OBSTRUCTION) || event.getCause().equals(RemoveCause.OBSTRUCTION) || event.getCause().equals(RemoveCause.DEFAULT)) { event.setCancelled(true); return; } if (event instanceof HangingBreakByEntityEvent) { Entity breaker = ((HangingBreakByEntityEvent)event).getRemover(); breaker = Utility.getRealDamager(breaker); if (!(breaker instanceof Player)) { event.setCancelled(true); return; } if (this.canInteract(event.getEntity(), (Player) breaker)) { this.module.unprotect(prot.get()); } else { debug(event.getEntity().getName() + " tried to break hanging!"); event.setCancelled(true); } } else { // Check if leash ib roken if (!event.getEntity().getType().equals(EntityType.LEASH_HITCH) || !event.getCause().equals(RemoveCause.ENTITY)) { return; } debug("hangingBreak() called!"); // Leash broken so check if an protected entity was attached to it final LeashHitch leash = (LeashHitch) event.getEntity(); Entity leashedEntity = null; final HashSet<Integer> nearbyPlayers = new HashSet<>(); // Find owner & leashholder for (final Entity entity : leash.getNearbyEntities(16, 16, 16)) { if (entity instanceof LivingEntity && !(entity instanceof Player)) { final LivingEntity living = (LivingEntity) entity; if (living.isLeashed() && living.getLeashHolder().getUniqueId().equals(leash.getUniqueId())) { debug("Leashholder of " + living.getType() + " is: " + living.getLeashHolder().getType()); leashedEntity = living; } } else if (entity instanceof Player) { final Optional<CraftoPlayer> player = CraftoPlayer.getPlayer(entity.getUniqueId()); if (!player.isPresent()) { warn("Player " + entity.getName() + " is missing a craftoplayer instance!"); continue; } nearbyPlayers.add(player.get().getId()); debug("Found a player nearby with id: " + player.get().getId()); } } // If leashed was found check protectionse etc if (leashedEntity != null) { prot = this.module.cache.getByUniqueId(leashedEntity.getUniqueId()); if (!prot.isPresent()) { debug("failed to find protection for " + leashedEntity.getType()); return; } debug("Found entityprotection with id: " + prot.get().getId()); if (nearbyPlayers.contains(prot.get().getOwnerId())) { debug("Owner is nearby! Returning..."); return; } for (final int playerId : nearbyPlayers) { final Optional<CraftoPlayer> otherPlayer = CraftoPlayer.getPlayer(playerId); if (!otherPlayer.isPresent()) { continue; } if (this.module.isAllowedToInteract(prot.get(), otherPlayer.get())) { debug("WhitelistedPlayer nearby! Returning..."); return; } } event.setCancelled(true); } } }
public HangingBreakByEntityEvent(Hanging hanging, Entity remover) { super(hanging, RemoveCause.ENTITY); }
public HangingBreakEvent(Hanging hanging, HangingBreakEvent.RemoveCause cause) { super(hanging); }
public HangingBreakEvent.RemoveCause getCause() { return null; }