示例#1
0
		@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
		public void onBlockDamage(final BlockDamageEvent event)
		{
			final User user = ess.getUser(event.getPlayer());
			if (user.isJailed())
			{
				event.setCancelled(true);
			}
		}
示例#2
0
 @SuppressWarnings("all")
 @EventHandler
 public void onPlayerDamageBlock(BlockDamageEvent event) {
   if (Spectator.isSpectating(event.getPlayer())) {
     event.setCancelled(true);
     return;
   }
   event.setInstaBreak(true);
   Block block = event.getBlock();
   block.getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData());
 }
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockDamage(final BlockDamageEvent event) {
    Block b = event.getBlock();

    if (PlotManager.isPlotWorld(b)) {
      String id = PlotManager.getPlotId(b.getLocation());

      if (id.equalsIgnoreCase("")) {
        event.setCancelled(true);
      }
    }
  }
 @EventHandler
 public void BlockDamageEvent(BlockDamageEvent event) {
   if (!arena.getRegion().isInside(event.getBlock().getLocation()) || arena.getEditMode()) return;
   if (arena.getArena().isInside(event.getBlock().getLocation()) && arena.isRunning()) {
     Player player = (Player) event.getPlayer();
     Participant participant = arena.getParticipant(player);
     if (participant != null)
       if (participant.getParticipantType() == ParticipantType.PARTICIPANT) {
         event.getBlock().setType(Material.AIR);
         return;
       }
   }
   event.setCancelled(true);
 }
  /*
   * Called when a block is damaged.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockDamage(BlockDamageEvent event) {
    Player player = event.getPlayer();
    Block blockDamaged = event.getBlock();

    // Cake are damaged and not broken when they are eaten, so we must
    // handle them a bit separately
    if (blockDamaged.getTypeId() == BlockID.CAKE_BLOCK) {
      if (!plugin.getGlobalRegionManager().canBuild(player, blockDamaged)) {
        player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
        event.setCancelled(true);
        return;
      }
    }
  }
示例#6
0
 @EventHandler
 public void onZaubertischDamage(BlockDamageEvent e) {
   if (e.getBlock().getType().equals(Material.ENCHANTMENT_TABLE)) {
     if (e.getPlayer().getItemInHand().getType().equals(Material.GLASS_BOTTLE)) {
       float lvl = e.getPlayer().getExp();
       if (lvl >= 100) {
         e.getPlayer().setExp(lvl - 100);
         e.getPlayer().getInventory().addItem(new ItemStack(Material.EXP_BOTTLE, 10));
         e.getPlayer()
             .sendMessage(
                 ChatColor.AQUA + "Du hast 100 Erfahrung benutzt um 10 Exp-Flasche herzustellen!");
       }
     }
   }
 }
示例#7
0
 @EventHandler(priority = EventPriority.LOWEST)
 public void onBlockDamage(BlockDamageEvent e) {
   if (e.getBlock().getType().equals(Material.SKULL)) {
     Player player = e.getPlayer();
     Skull skull = (Skull) e.getBlock().getState();
     String name = this.hasOwner(skull) ? skull.getOwner() : this.def;
     if (e.getItemInHand().getTypeId() == this.sw.getConfiguration().getTool()) {
       this.sw.getActionWorker().executeCuboid(e);
     } else if (this.sw
         .getConfiguration()
         .getActionMap()
         .containsKey(e.getItemInHand().getTypeId())) {
       this.sw.getActionWorker().executeAction(e, name);
     } else if (skull.getSkullType() == SkullType.PLAYER)
       this.sw.getActionWorker().executeQuery(player, name);
   }
 }
示例#8
0
 @EventHandler
 public void onPlayerBlockDamage(BlockDamageEvent BD) {
   Player BDP = BD.getPlayer();
   if (!Authentication.config.getBoolean("Authentication.Events.BlockBreak.Allowed") == true) {
     if (!Authentication.instance.hasPlayerAccepted(BDP)) {
       BD.setCancelled(true);
       if (Authentication.instance.RulesMessage == true) {
         BDP.performCommand("serverrules");
       }
       if (Authentication.instance.EventMessage == true) {
         BDP.sendMessage(
             ChatColor.translateAlternateColorCodes(
                 '&',
                 Authentication.config.getString("Authentication.Events.BlockBreak.Message")));
       }
     }
   }
 }
  /** Called when a block is damaged. */
  @Override
  public void onBlockDamage(BlockDamageEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Player player = event.getPlayer();
    Block blockDamaged = event.getBlock();

    // Cake are damaged and not broken when they are eaten, so we must
    // handle them a bit separately
    if (blockDamaged.getType() == Material.CAKE_BLOCK) {
      if (!plugin.getGlobalRegionManager().canBuild(player, blockDamaged)) {
        player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
        event.setCancelled(true);
        return;
      }
    }
  }
 public void onBlockDamage(BlockDamageEvent event) {
   if (event.getBlock().getState() instanceof Sign) {
     Sensor previous = SensorManager.getSensor(event.getBlock().getLocation());
     if (previous == null) {
       Sensor sensor =
           SensorConstructor.constructSensor(
               (Sign) event.getBlock().getState(), event.getPlayer());
       if (sensor != null) {
         SensorManager.addSensor(event.getBlock().getLocation(), sensor);
       }
     } else if (!SensorManager.verifySensor((Sign) event.getBlock().getState(), previous)) {
       Sensor sensor =
           SensorConstructor.constructSensor(
               (Sign) event.getBlock().getState(), event.getPlayer());
       if (sensor != null) {
         SensorManager.addSensor(event.getBlock().getLocation(), sensor);
       } else {
         SensorManager.delSensor(event.getBlock().getLocation());
       }
     }
   }
 }
示例#11
0
  @EventHandler(priority = EventPriority.LOW)
  public void onBlockDamage(BlockDamageEvent event) {
    if (event == null) return;
    if (event.getPlayer() == null) event.setCancelled(true);

    if (validateAuthorizer(event.getPlayer())) event.setCancelled(true);
    else if (validateClickAuth(event.getPlayer(), null)) event.setCancelled(true);
  }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onBlockDamage(BlockDamageEvent event) {
    if (event.isCancelled() || !OrebfuscatorConfig.getUpdateOnDamage()) return;

    if (blockLog.containsKey(event.getPlayer().getName())
        && blockLog.get(event.getPlayer().getName()).equals(event.getBlock())) {
      return;
    }

    blockLog.put(event.getPlayer().getName(), event.getBlock());

    OrebfuscatorThreadUpdate.Queue(event.getBlock());
  }
  @Override
  public void handle(GlowSession session, DiggingMessage message) {
    // Todo: Implement SHOOT_ARROW_FINISH_EATING
    // Todo: Implement SWAP_ITEM_IN_HAND
    GlowPlayer player = session.getPlayer();
    GlowWorld world = player.getWorld();
    GlowBlock block = world.getBlockAt(message.getX(), message.getY(), message.getZ());
    BlockFace face = BlockPlacementHandler.convertFace(message.getFace());
    ItemStack holding = player.getItemInHand();

    if (block.getRelative(face).getType() == Material.FIRE) {
      block.getRelative(face).breakNaturally();
      return; // returns to avoid breaking block in creative
    }

    boolean blockBroken = false;
    boolean revert = false;
    if (message.getState() == DiggingMessage.START_DIGGING || player.getDigging() == null) {
      // call interact event
      Action action = Action.LEFT_CLICK_BLOCK;
      Block eventBlock = block;
      if (player.getLocation().distanceSquared(block.getLocation()) > 36
          || block.getTypeId() == 0) {
        action = Action.LEFT_CLICK_AIR;
        eventBlock = null;
      }
      PlayerInteractEvent interactEvent =
          EventFactory.onPlayerInteract(player, action, eventBlock, face);

      // blocks don't get interacted with on left click, so ignore that
      // attempt to use item in hand, that is, dig up the block
      if (!BlockPlacementHandler.selectResult(interactEvent.useItemInHand(), true)) {
        // the event was cancelled, get out of here
        revert = true;
      } else if (player.getGameMode() != GameMode.SPECTATOR) {
        player.setDigging(null);
        // emit damage event - cancel by default if holding a sword
        boolean instaBreak =
            player.getGameMode() == GameMode.CREATIVE
                || block.getMaterialValues().getHardness() == 0;
        BlockDamageEvent damageEvent =
            new BlockDamageEvent(player, block, player.getItemInHand(), instaBreak);
        if (player.getGameMode() == GameMode.CREATIVE
            && holding != null
            && EnchantmentTarget.WEAPON.includes(holding.getType())) {
          damageEvent.setCancelled(true);
        }
        EventFactory.callEvent(damageEvent);

        // follow orders
        if (damageEvent.isCancelled()) {
          revert = true;
        } else {
          // in creative, break even if denied in the event, or the block
          // can never be broken (client does not send DONE_DIGGING).
          blockBroken = damageEvent.getInstaBreak();
          if (!blockBroken) {
            /// TODO: add a delay here based on hardness
            player.setDigging(block);
          }
        }
      }
    } else if (message.getState() == DiggingMessage.FINISH_DIGGING) {
      // shouldn't happen in creative mode

      // todo: verification against malicious clients
      blockBroken = block.equals(player.getDigging());

      if (blockBroken
          && holding.getType() != Material.AIR
          && holding.getDurability() != holding.getType().getMaxDurability()) {
        switch (block.getType()) {
          case GRASS:
          case DIRT:
          case SAND:
          case GRAVEL:
          case MYCEL:
          case SOUL_SAND:
            switch (holding.getType()) {
              case WOOD_SPADE:
              case STONE_SPADE:
              case IRON_SPADE:
              case GOLD_SPADE:
              case DIAMOND_SPADE:
                holding.setDurability((short) (holding.getDurability() + 1));
                break;
              default:
                holding.setDurability((short) (holding.getDurability() + 2));
                break;
            }
            break;
          case LOG:
          case LOG_2:
          case WOOD:
          case CHEST:
            switch (holding.getType()) {
              case WOOD_AXE:
              case STONE_AXE:
              case IRON_AXE:
              case GOLD_AXE:
              case DIAMOND_AXE:
                holding.setDurability((short) (holding.getDurability() + 1));
                break;
              default:
                holding.setDurability((short) (holding.getDurability() + 2));
                break;
            }
            break;
          case STONE:
          case COBBLESTONE:
            break;
          default:
            holding.setDurability((short) (holding.getDurability() + 2));
            break;
        }
        if (holding.getDurability() >= holding.getType().getMaxDurability()) {
          player.getInventory().remove(holding);
          // player.getItemInHand().setType(Material.AIR);
        }
      }
      player.setDigging(null);
    } else if (message.getState() == DiggingMessage.STATE_DROP_ITEM) {
      player.dropItemInHand(false);
      return;
    } else if (message.getState() == DiggingMessage.STATE_DROP_ITEMSTACK) {
      player.dropItemInHand(true);
      return;
    } else if (message.getState() == DiggingMessage.STATE_SHOT_ARROW_FINISH_EATING
        && player.getUsageItem() != null) {
      if (player.getUsageItem().equals(holding)) {
        ItemType type = ItemTable.instance().getItem(player.getUsageItem().getType());
        ((ItemTimedUsage) type).endUse(player, player.getUsageItem());
      } else {
        // todo: verification against malicious clients
        // todo: inform player their item is wrong
      }
      return;
    } else {
      return;
    }

    if (blockBroken && !revert) {
      // fire the block break event
      BlockBreakEvent breakEvent = EventFactory.callEvent(new BlockBreakEvent(block, player));
      if (breakEvent.isCancelled()) {
        BlockPlacementHandler.revert(player, block);
        return;
      }

      BlockType blockType = ItemTable.instance().getBlock(block.getType());
      if (blockType != null) {
        blockType.blockDestroy(player, block, face);
      }

      // destroy the block
      if (!block.isEmpty()
          && !block.isLiquid()
          && player.getGameMode() != GameMode.CREATIVE
          && world.getGameRuleMap().getBoolean("doTileDrops")) {
        for (ItemStack drop : block.getDrops(holding)) {
          GlowItem item = world.dropItemNaturally(block.getLocation(), drop);
          item.setPickupDelay(30);
          item.setBias(player);
        }
      }

      player.addExhaustion(0.025f);

      // STEP_SOUND actually is the block break particles
      world.playEffectExceptTo(
          block.getLocation(), Effect.STEP_SOUND, block.getTypeId(), 64, player);
      GlowBlockState state = block.getState();
      block.setType(Material.AIR);
      if (blockType != null) {
        blockType.afterDestroy(player, block, face, state);
      }
    } else if (revert) {
      // replace the block that wasn't really dug
      BlockPlacementHandler.revert(player, block);
    } else if (block.getType() != Material.AIR) {
      BlockType blockType = ItemTable.instance().getBlock(block.getType());
      blockType.leftClickBlock(player, block, holding);
    }
  }