@EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (!TotalFreedomMod.allowWaterPlace) {
                  player
                      .getInventory()
                      .setItem(
                          player.getInventory().getHeldItemSlot(),
                          new ItemStack(Material.COOKIE, 1));
                  player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                  event.setCancelled(true);
                }
                break;
              }
            case LAVA_BUCKET:
              {
                if (!TotalFreedomMod.allowLavaPlace) {
                  player
                      .getInventory()
                      .setItem(
                          player.getInventory().getHeldItemSlot(),
                          new ItemStack(Material.COOKIE, 1));
                  player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                  event.setCancelled(true);
                }
                break;
              }
            case EXPLOSIVE_MINECART:
              {
                if (!TotalFreedomMod.allowTntMinecarts) {
                  player.getInventory().clear(player.getInventory().getHeldItemSlot());
                  player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                  event.setCancelled(true);
                }
                break;
              }
          }
          break;
        }
      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
                if (playerdata.mobThrowerEnabled()) {
                  Location player_pos = player.getLocation();
                  Vector direction = player_pos.getDirection().normalize();

                  LivingEntity rezzed_mob =
                      (LivingEntity)
                          player
                              .getWorld()
                              .spawnEntity(
                                  player_pos.add(direction.multiply(2.0)),
                                  playerdata.mobThrowerCreature());
                  rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                  playerdata.enqueueMob(rezzed_mob);

                  event.setCancelled(true);
                }
                break;
              }
            case SULPHUR:
              {
                TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
                if (playerdata.isMP44Armed()) {
                  if (playerdata.toggleMP44Firing()) {
                    playerdata.startArrowShooter(TotalFreedomMod.plugin);
                  } else {
                    playerdata.stopArrowShooter();
                  }

                  event.setCancelled(true);
                }
                break;
              }
            case BLAZE_ROD:
              {
                if (TotalFreedomMod.allowExplosions) {
                  if (TFM_SuperadminList.isSeniorAdmin(player, true)) {
                    Block target_block;

                    if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                      target_block = player.getTargetBlock(null, 120);
                    } else {
                      target_block = event.getClickedBlock();
                    }

                    if (target_block != null) {
                      player.getWorld().createExplosion(target_block.getLocation(), 4F, true);
                      player.getWorld().strikeLightning(target_block.getLocation());
                    } else {
                      player.sendMessage("Can't resolve target block.");
                    }

                    event.setCancelled(true);
                  }
                }
                break;
              }
            case CARROT:
              {
                if (TotalFreedomMod.allowExplosions) {
                  if (TFM_SuperadminList.isSeniorAdmin(player, true)) {
                    Location player_location = player.getLocation().clone();

                    Vector player_pos = player_location.toVector().add(new Vector(0.0, 1.65, 0.0));
                    Vector player_dir = player_location.getDirection().normalize();

                    double distance = 150.0;
                    Block target_block = player.getTargetBlock(null, Math.round((float) distance));
                    if (target_block != null) {
                      distance = player_location.distance(target_block.getLocation());
                    }

                    final List<Block> affected = new ArrayList<Block>();

                    Block last_block = null;
                    for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                      Block test_block =
                          player_pos
                              .clone()
                              .add(player_dir.clone().multiply(offset))
                              .toLocation(player.getWorld())
                              .getBlock();

                      if (!test_block.equals(last_block)) {
                        if (test_block.isEmpty()) {
                          affected.add(test_block);
                          test_block.setType(Material.TNT);
                        } else {
                          break;
                        }
                      }

                      last_block = test_block;
                    }

                    new BukkitRunnable() {
                      @Override
                      public void run() {
                        for (Block tnt_block : affected) {
                          TNTPrimed tnt_primed =
                              tnt_block.getWorld().spawn(tnt_block.getLocation(), TNTPrimed.class);
                          tnt_primed.setFuseTicks(5);
                          tnt_block.setType(Material.AIR);
                        }
                      }
                    }.runTaskLater(TotalFreedomMod.plugin, 30L);

                    event.setCancelled(true);
                  }
                }
                break;
              }
          }
          break;
        }
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case LAVA_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case EXPLOSIVE_MINECART:
              {
                if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) {
                  break;
                }

                player.getInventory().clear(player.getInventory().getHeldItemSlot());
                player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                event.setCancelled(true);
                break;
              }
          }
          break;
        }

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                if (!TFM_AdminList.isSuperAdmin(player)) {
                  break;
                }

                event.setCancelled(true);

                final Location location =
                    TFM_DepreciationAggregator.getTargetBlock(player, null, 5).getLocation();
                final List<RollbackEntry> entries =
                    TFM_RollbackManager.getEntriesAtLocation(location);

                if (entries.isEmpty()) {
                  TFM_Util.playerMsg(player, "No block edits at that location.");
                  break;
                }

                TFM_Util.playerMsg(
                    player,
                    "Block edits at ("
                        + ChatColor.WHITE
                        + "x"
                        + location.getBlockX()
                        + ", y"
                        + location.getBlockY()
                        + ", z"
                        + location.getBlockZ()
                        + ChatColor.BLUE
                        + ")"
                        + ChatColor.WHITE
                        + ":",
                    ChatColor.BLUE);
                for (RollbackEntry entry : entries) {
                  TFM_Util.playerMsg(
                      player,
                      " - "
                          + ChatColor.BLUE
                          + entry.author
                          + " "
                          + entry.getType()
                          + " "
                          + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase())
                          + (entry.data == 0 ? "" : ":" + entry.data));
                }

                break;
              }

            case BONE:
              {
                if (!playerdata.mobThrowerEnabled()) {
                  break;
                }

                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();

                LivingEntity rezzed_mob =
                    (LivingEntity)
                        player
                            .getWorld()
                            .spawnEntity(
                                player_pos.add(direction.multiply(2.0)),
                                playerdata.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                playerdata.enqueueMob(rezzed_mob);

                event.setCancelled(true);
                break;
              }

            case SULPHUR:
              {
                if (!playerdata.isMP44Armed()) {
                  break;
                }

                event.setCancelled(true);

                if (playerdata.toggleMP44Firing()) {
                  playerdata.startArrowShooter(TotalFreedomMod.plugin);
                } else {
                  playerdata.stopArrowShooter();
                }
                break;
              }

            case BLAZE_ROD:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                event.setCancelled(true);
                Block targetBlock;

                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                  targetBlock = TFM_DepreciationAggregator.getTargetBlock(player, null, 120);
                } else {
                  targetBlock = event.getClickedBlock();
                }

                if (targetBlock == null) {
                  player.sendMessage("Can't resolve target block.");
                  break;
                }

                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());

                break;
              }

            case CARROT:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                Location location = player.getLocation().clone();

                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();

                double distance = 150.0;
                Block targetBlock =
                    TFM_DepreciationAggregator.getTargetBlock(
                        player, null, Math.round((float) distance));
                if (targetBlock != null) {
                  distance = location.distance(targetBlock.getLocation());
                }

                final List<Block> affected = new ArrayList<Block>();

                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                  Block block =
                      playerPostion
                          .clone()
                          .add(playerDirection.clone().multiply(offset))
                          .toLocation(player.getWorld())
                          .getBlock();

                  if (!block.equals(lastBlock)) {
                    if (block.isEmpty()) {
                      affected.add(block);
                      block.setType(Material.TNT);
                    } else {
                      break;
                    }
                  }

                  lastBlock = block;
                }

                new BukkitRunnable() {
                  @Override
                  public void run() {
                    for (Block tntBlock : affected) {
                      TNTPrimed tnt =
                          tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                      tnt.setFuseTicks(5);
                      tntBlock.setType(Material.AIR);
                    }
                  }
                }.runTaskLater(TotalFreedomMod.plugin, 30L);

                event.setCancelled(true);
                break;
              }

            case RAW_FISH:
              {
                final int RADIUS_HIT = 5;
                final int STRENGTH = 4;

                // Clownfish
                if (TFM_DepreciationAggregator.getData_MaterialData(event.getItem().getData())
                    == 2) {
                  if (TFM_AdminList.isSeniorAdmin(player, true)
                      || TFM_AdminList.isTelnetAdmin(player, true)) {
                    boolean didHit = false;

                    final Location playerLoc = player.getLocation();
                    final Vector playerLocVec = playerLoc.toVector();

                    final List<Player> players = player.getWorld().getPlayers();
                    for (final Player target : players) {
                      if (target == player) {
                        continue;
                      }

                      final Location targetPos = target.getLocation();
                      final Vector targetPosVec = targetPos.toVector();

                      try {
                        if (targetPosVec.distanceSquared(playerLocVec)
                            < (RADIUS_HIT * RADIUS_HIT)) {
                          TFM_Util.setFlying(player, false);
                          target.setVelocity(
                              targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
                          didHit = true;
                        }
                      } catch (IllegalArgumentException ex) {
                      }
                    }

                    if (didHit) {
                      final Sound[] sounds = Sound.values();
                      for (Sound sound : sounds) {
                        if (sound.toString().contains("HIT")) {
                          playerLoc
                              .getWorld()
                              .playSound(
                                  randomOffset(playerLoc, 5.0),
                                  sound,
                                  100.0f,
                                  randomDoubleRange(0.5, 2.0).floatValue());
                        }
                      }
                    }
                  } else {
                    final StringBuilder msg = new StringBuilder();
                    final char[] chars = (player.getName() + " is a clown.").toCharArray();
                    for (char c : chars) {
                      msg.append(TFM_Util.randomChatColor()).append(c);
                    }
                    TFM_Util.bcastMsg(msg.toString());

                    player.getInventory().getItemInHand().setType(Material.POTATO_ITEM);
                  }

                  event.setCancelled(true);
                  break;
                }
              }
          }
          break;
        }
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case LAVA_BUCKET:
              {
                if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case EXPLOSIVE_MINECART:
              {
                if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) {
                  break;
                }

                player.getInventory().clear(player.getInventory().getHeldItemSlot());
                player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                event.setCancelled(true);
                break;
              }
          }
          break;
        }

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                if (!TFM_AdminList.isSuperAdmin(player)) {
                  break;
                }

                event.setCancelled(true);

                final Location location = player.getTargetBlock(null, 5).getLocation();
                final List<RollbackEntry> entries =
                    TFM_RollbackManager.getEntriesAtLocation(location);

                if (entries.isEmpty()) {
                  TFM_Util.playerMsg(player, "No block edits at that location.");
                  break;
                }

                TFM_Util.playerMsg(
                    player,
                    "Block edits at ("
                        + ChatColor.WHITE
                        + "x"
                        + location.getBlockX()
                        + ", y"
                        + location.getBlockY()
                        + ", z"
                        + location.getBlockZ()
                        + ChatColor.BLUE
                        + ")"
                        + ChatColor.WHITE
                        + ":",
                    ChatColor.BLUE);
                for (RollbackEntry entry : entries) {
                  TFM_Util.playerMsg(
                      player,
                      " - "
                          + ChatColor.BLUE
                          + entry.author
                          + " "
                          + entry.getType()
                          + " "
                          + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase())
                          + (entry.data == 0 ? "" : ":" + entry.data));
                }

                break;
              }

            case BONE:
              {
                if (!playerdata.mobThrowerEnabled()) {
                  break;
                }

                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();

                LivingEntity rezzed_mob =
                    (LivingEntity)
                        player
                            .getWorld()
                            .spawnEntity(
                                player_pos.add(direction.multiply(2.0)),
                                playerdata.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                playerdata.enqueueMob(rezzed_mob);

                event.setCancelled(true);
                break;
              }

            case SULPHUR:
              {
                if (!playerdata.isMP44Armed()) {
                  break;
                }

                event.setCancelled(true);

                if (playerdata.toggleMP44Firing()) {
                  playerdata.startArrowShooter(TotalFreedomMod.plugin);
                } else {
                  playerdata.stopArrowShooter();
                }
                break;
              }

            case BLAZE_ROD:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                event.setCancelled(true);
                Block targetBlock;

                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                  targetBlock = player.getTargetBlock(null, 120);
                } else {
                  targetBlock = event.getClickedBlock();
                }

                if (targetBlock == null) {
                  player.sendMessage("Can't resolve target block.");
                  break;
                }

                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());

                break;
              }

            case CARROT:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                Location location = player.getLocation().clone();

                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();

                double distance = 150.0;
                Block targetBlock = player.getTargetBlock(null, Math.round((float) distance));
                if (targetBlock != null) {
                  distance = location.distance(targetBlock.getLocation());
                }

                final List<Block> affected = new ArrayList<Block>();

                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                  Block block =
                      playerPostion
                          .clone()
                          .add(playerDirection.clone().multiply(offset))
                          .toLocation(player.getWorld())
                          .getBlock();

                  if (!block.equals(lastBlock)) {
                    if (block.isEmpty()) {
                      affected.add(block);
                      block.setType(Material.TNT);
                    } else {
                      break;
                    }
                  }

                  lastBlock = block;
                }

                new BukkitRunnable() {
                  @Override
                  public void run() {
                    for (Block tntBlock : affected) {
                      TNTPrimed tnt =
                          tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                      tnt.setFuseTicks(5);
                      tntBlock.setType(Material.AIR);
                    }
                  }
                }.runTaskLater(TotalFreedomMod.plugin, 30L);

                event.setCancelled(true);
                break;
              }
          }
          break;
        }
    }
  }