Example #1
0
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();

    if (!isEnable) return;

    //
    if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)
        && PlayerUtil.getItemInHand(player) != null
        && PlayerUtil.getItemInHand(player).getType() == Material.GLOWSTONE_DUST
        && Permissions.has(player, Permissions.USE)) {
      // Clicked location
      Location clickedLoc = event.getClickedBlock().getLocation();

      // Création de la lumière
      LightsApi.createLight(player, clickedLoc, lightlevel);
    }

    //
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && PlayerUtil.getItemInHand(player) != null
        && PlayerUtil.getItemInHand(player).getType() == Material.GLOWSTONE_DUST
        && Permissions.has(player, Permissions.USE)) {
      if (Minecraft.Version.getVersion().newerThan(Minecraft.Version.v1_8_R4)) {
        EquipmentSlot e = event.getHand();
        if (e.equals(EquipmentSlot.OFF_HAND)) return;
      }

      // Clicked location
      Location clickedLoc = event.getClickedBlock().getLocation();

      // Suppression de la lumière
      LightsApi.removeLight(player, clickedLoc);
    }

    //
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && PlayerUtil.getItemInHand(player) != null
        && PlayerUtil.getItemInHand(player).getType() == Material.AIR
        && Permissions.has(player, Permissions.DEBUG)) {
      if (Minecraft.Version.getVersion().newerThan(Minecraft.Version.v1_8_R4)) {
        EquipmentSlot e = event.getHand();
        if (e.equals(EquipmentSlot.OFF_HAND)) return;
      }

      // Clicked location
      Location clickedLoc = event.getClickedBlock().getLocation();

      // Brightness
      SimpleMessage.toPlayer(player, "Block : " + clickedLoc.getBlock().getState().getData());
      SimpleMessage.toPlayer(
          player,
          "Location : "
              + clickedLoc.getBlockX()
              + " ,"
              + clickedLoc.getBlockY()
              + " ,"
              + clickedLoc.getBlockZ());
      SimpleMessage.toPlayer(
          player, "Brightness (SKY) : " + NmsChunkUtil.getBrightness(15, clickedLoc));
      SimpleMessage.toPlayer(
          player, "Brightness (BLOCK) : " + NmsChunkUtil.getBrightness(0, clickedLoc));
    }
  }