Java Code Examples for org.bukkit.event.block.BlockDamageEvent#setCancelled()

The following examples show how to use org.bukkit.event.block.BlockDamageEvent#setCancelled() . 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: DestroyableMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void processBlockDamage(BlockDamageEvent event) {
  if (this.match.getWorld() != event.getBlock().getWorld()) return;

  Block block = event.getBlock();
  MaterialData material = block.getState().getData();
  MatchPlayer player = this.match.getPlayer(event.getPlayer());

  for (Destroyable destroyable : this.destroyables) {
    if (player != null
        && player.getParty() == destroyable.getOwner()
        && !destroyable.isDestroyed()
        && destroyable.getBlockRegion().contains(block)
        && destroyable.hasMaterial(material)) {

      event.setCancelled(true);
      // TODO: translate this
      player.sendWarning(TextComponent.of("You may not damage your own objective."));
    }
  }
}
 
Example 2
Source File: CoreMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void damageCheck(BlockDamageEvent event) {
  Block block = event.getBlock();
  if (block.getWorld() != this.match.getWorld()) return;
  MatchPlayer player = this.match.getPlayer(event.getPlayer());
  Vector center = BlockVectors.center(block).toVector();

  for (Core core : this.cores) {
    if (!core.hasLeaked()
        && core.getCasingRegion().contains(center)
        && player.getParty() == core.getOwner()) {
      event.setCancelled(true);
      player.sendWarning(TranslatableComponent.of("core.damageOwn"));
    }
  }
}
 
Example 3
Source File: DestroyableMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void processBlockDamage(BlockDamageEvent event) {
    if(this.match.getWorld() != event.getBlock().getWorld()) return;

    Block block = event.getBlock();
    MaterialData material = block.getState().getData();
    MatchPlayer player = this.match.getPlayer(event.getPlayer());

    for(Destroyable destroyable : this.destroyables) {
        if(player != null &&
           player.getParty() == destroyable.getOwner() &&
           !destroyable.isDestroyed() &&
           destroyable.getBlockRegion().contains(block) &&
           destroyable.hasMaterial(material)) {

            event.setCancelled(true);
            player.sendWarning(new TranslatableComponent("match.destroyable.damageOwn"), true);
        }
    }
}
 
Example 4
Source File: CoreMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void damageCheck(BlockDamageEvent event) {
    Block block = event.getBlock();
    if(block.getWorld() != this.match.getWorld()) return;
    MatchPlayer player = this.match.getPlayer(event.getPlayer());
    Vector center = BlockUtils.center(block).toVector();

    for(Core core : this.cores) {
        if(!core.hasLeaked() && core.getCasingRegion().contains(center) && player.getParty() == core.getOwner()) {
            event.setCancelled(true);
            player.sendWarning(PGMTranslations.t("match.core.damageOwn", player), true);
        }
    }
}
 
Example 5
Source File: SpectatorEvents.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockDamage(BlockDamageEvent event) {
    Player player = event.getPlayer();
    if (GameManager.getInstance().isSpectator(player)) {
        event.setCancelled(true);
    }
}
 
Example 6
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockDamage(BlockDamageEvent event) {
    Location location = BukkitUtil.adapt(event.getBlock().getLocation());

    if (manager.isPlotWorld(location)) {
        PlotId id = manager.getPlotId(location);

        if (id == null) {
            event.setCancelled(true);
        } else {
            event.setCancelled(api.isPlotLocked(id));

        }
    }
}