@Override
 public void onPlayerInteract(PlayerInteractEvent event) {
   if (event.getAction() == Action.RIGHT_CLICK_BLOCK
       || event.getAction() == Action.RIGHT_CLICK_AIR)
     if (event.getPlayer().getItemInHand().getType() == Material.SULPHUR)
       if (event.getPlayer().getLocation().getBlock().getRelative(BlockFace.DOWN).getType()
           == Material.LAPIS_BLOCK) Cannon.fire(event.getPlayer());
 }
Exemple #2
0
 @Override
 public void onRightClick(PlayerInteractEvent event) {
   if (!plugin.getLocalConfiguration().cauldronSettings.enable) return;
   if (!BukkitUtil.toWorldVector(event.getClickedBlock()).equals(pt))
     return; // wth? our manager is insane
   if (event.getPlayer().getItemInHand().getTypeId() >= 255
       || event.getPlayer().getItemInHand().getType() == Material.AIR)
     preCauldron(event.getPlayer(), event.getPlayer().getWorld(), pt);
 }
Exemple #3
0
  @EventHandler
  public void onTurretFire(PlayerInteractEvent e) {
    if (isInTurret(e.getPlayer())) {
      Player shooter = e.getPlayer();
      Turret t = getTurret(shooter);

      t.shoot();
    }
  }
 @EventHandler(ignoreCancelled = true)
 public void onPlayerInteract(PlayerInteractEvent event) {
   if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR) {
     return;
   }
   if (!event.getPlayer().hasPermission("permissions.build")) {
     bother(event.getPlayer());
     event.setCancelled(true);
   }
 }
 @EventHandler
 public void SpectatorInteractBlock(PlayerInteractEvent event) {
   Player p = event.getPlayer();
   String pname = p.getName();
   for (i = 0; i < plugin.Watching.size(); i++) {
     if (plugin.Watching.get(i) != null) {
       if (plugin.Watching.get(i).contains(pname)) {
         event.setCancelled(true);
         p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!");
       }
     }
   }
 }
  @EventHandler
  public void playerInteractEvent(PlayerInteractEvent e) {
    if (!Minegusta.getServer().containsWorld(e.getPlayer().getWorld())) return;

    DwarfPower rage = DwarfPower.battleCryBoost(e);
    Altar altar = Altar.altarCheck(e);

    if (rage.isRightClick() && rage.isPlayer() && rage.isDwarf() && rage.hasAxe()) {
      rage.applyBattleCryBoost();
    }

    if (altar.isRightClick() && altar.isAltar() && altar.hasDiamondBlocks() && altar.isNotHuman()) {
      Cure.curePlayer(e.getPlayer());
    }
  }
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onPlayerInteracts(PlayerInteractEvent event) {
   plugin
       .getServer()
       .getScheduler()
       .runTask(plugin, new ResetIgnoreSleepTask(plugin, event.getPlayer().getName()));
 }
	@EventHandler(priority = EventPriority.NORMAL)
	public void onPlayerInteract(final PlayerInteractEvent event)
	{
		final IUser user = userMap.getUser(event.getPlayer());
		user.updateActivity(true);
		switch (event.getAction())
		{
		case RIGHT_CLICK_BLOCK:
			if (event.isCancelled())
			{
				return;
			}

			final ISettings settings = ess.getSettings();
			if (settings.getData().getCommands().getHome().isUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK)
			{
				event.getPlayer().setBedSpawnLocation(event.getClickedBlock().getLocation());
			}
			break;
		case LEFT_CLICK_AIR:
		case LEFT_CLICK_BLOCK:
			if (user.getData().hasPowerTools() && user.getData().isPowerToolsEnabled())
			{
				if (usePowertools(user))
				{
					event.setCancelled(true);
				}
			}
			break;
		default:
			break;
		}
	}
Exemple #9
0
  @EventHandler(priority = EventPriority.HIGH)
  public void protectBlockStates(PlayerInteractEvent event) {
    Material[] blockedItems = {
      Material.NOTE_BLOCK,
      Material.REDSTONE_COMPARATOR_OFF,
      Material.REDSTONE_COMPARATOR_ON,
      Material.DIODE_BLOCK_OFF,
      Material.DIODE_BLOCK_ON,
      Material.FLOWER_POT,
      Material.CAKE_BLOCK,
      Material.DAYLIGHT_DETECTOR,
      Material.DAYLIGHT_DETECTOR_INVERTED
    };
    if (event.getClickedBlock() == null) {
      return;
    }
    Player p = event.getPlayer();
    // System.out.println(event.getClickedBlock().getType());
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && Arrays.asList(blockedItems).contains(event.getClickedBlock().getType())) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }

      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.blockStateChange"));
      event.setCancelled(true);
    }
  }
  @EventHandler
  public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    GamePlayer GamePlayer = FakeboardHandler.getPlayer(player);
    String playerName = GamePlayer.getName();

    if (event.getAction() == Action.RIGHT_CLICK_AIR
        || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
      if (player.getItemInHand() != null
          && Items.itemNameContains(player.getItemInHand(), "Select & Edit Loadouts")) {
        event.setCancelled(true);
        // Open the loadout menu for the player
        GameSetupHandler.openLoadoutOptionMenu(player);
      }
    } else if (GameSetupHandler.isGameInProgress()) {
      if (!playerCooldown.isOnCooldown(playerName)) {
        if (GamePlayer.isAfk()) {
          GamePlayer.setAfk(false, false);
        }
        playerCooldown.setOnCooldown(playerName);
      }
    }
  }
 /**
  * Handles player interactions in arenas.<br>
  * If the player is in an arena, the game's onPlayerInteract method is called.<br>
  * If the player is spectating an arena, the event is cancelled.
  */
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onPlayerInteract(PlayerInteractEvent event) {
   Player player = event.getPlayer();
   String playerName = player.getName();
   if (ultimateGames.getPlayerManager().isPlayerInArena(playerName)) {
     Arena arena = ultimateGames.getPlayerManager().getPlayerArena(playerName);
     Game game = arena.getGame();
     ItemStack item = player.getItemInHand();
     if (item != null && ultimateGames.getGameItemManager().isRegistered(game, item)) {
       GameItem gameItem = ultimateGames.getGameItemManager().getGameItem(game, item);
       if (gameItem.click(arena, event) && gameItem.hasSingleUse()) {
         ItemStack itemStack = player.getItemInHand();
         itemStack.setAmount(itemStack.getAmount() - 1);
         player.setItemInHand(itemStack.getAmount() == 0 ? null : itemStack);
         event.setCancelled(true);
       }
     } else {
       game.getGamePlugin().onPlayerInteract(arena, event);
     }
   } else if (ultimateGames.getPlayerManager().isPlayerSpectatingArena(playerName)) {
     event.setCancelled(true);
   }
 }
 @EventHandler(priority = EventPriority.LOWEST)
 public void onPlayerInteract(PlayerInteractEvent event) {
   if (PConfManager.getPValBoolean(event.getPlayer(), "jailed")) event.setCancelled(true);
   Action act = event.getAction();
   if (act.equals(Action.PHYSICAL)) return;
   ItemStack id = event.getItem();
   if (id == null) return;
   int idn = id.getTypeId();
   if (idn == 0) return;
   List<String> cmds = PConfManager.getPValStringList(event.getPlayer(), "assign." + idn);
   if (cmds == null) return;
   for (String s : cmds) {
     if (s.toLowerCase().trim().startsWith("c:")) event.getPlayer().chat(s.trim().substring(2));
     else event.getPlayer().performCommand(s.trim());
   }
 }
Exemple #13
0
  public void a(Packet15Place packet15place) {
    WorldServer worldserver = this.minecraftServer.a(this.player.dimension);

    // CraftBukkit start
    if (this.player.dead) {
      return;
    }

    // This is b horrible hack needed because the client sends 2 packets on 'right mouse click'
    // aimed at b block. We shouldn't need to get the second packet if the data is handled
    // but we cannot know what the client will do, so we might still get it
    //
    // If the time between packets is small enough, and the 'signature' similar, we discard the
    // second one. This sadly has to remain until Mojang makes their packets saner. :(
    //  -- Grum

    if (packet15place.face == 255) {
      if (packet15place.itemstack != null
          && packet15place.itemstack.id == lastMaterial
          && lastPacket != null
          && packet15place.timestamp - lastPacket < 100) {
        lastPacket = null;
        return;
      }
    } else {
      lastMaterial = packet15place.itemstack == null ? -1 : packet15place.itemstack.id;
      lastPacket = packet15place.timestamp;
    }

    // CraftBukkit - if rightclick decremented the item, always send the update packet.
    // this is not here for CraftBukkit's own functionality; rather it is to fix
    // b notch bug where the item doesn't update correctly.
    boolean always = false;

    // CraftBukkit end

    ItemStack itemstack = this.player.inventory.getItemInHand();
    boolean flag =
        worldserver.weirdIsOpCache =
            worldserver.worldProvider.dimension != 0
                || this.minecraftServer.serverConfigurationManager.isOp(this.player.name);

    if (packet15place.face == 255) {
      if (itemstack == null) {
        return;
      }

      // CraftBukkit start
      int itemstackAmount = itemstack.count;
      PlayerInteractEvent event =
          CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack);
      if (event.useItemInHand() != Event.Result.DENY) {
        this.player.itemInWorldManager.useItem(this.player, this.player.world, itemstack);
      }

      // CraftBukkit - notch decrements the counter by 1 in the above method with food,
      // snowballs and so forth, but he does it in b place that doesn't cause the
      // inventory update packet to get sent
      always = (itemstack.count != itemstackAmount);
      // CraftBukkit end
    } else {
      int i = packet15place.a;
      int j = packet15place.b;
      int k = packet15place.c;
      int l = packet15place.face;
      ChunkCoordinates chunkcoordinates = worldserver.getSpawn();
      int i1 = (int) MathHelper.abs((float) (i - chunkcoordinates.x));
      int j1 = (int) MathHelper.abs((float) (k - chunkcoordinates.z));

      if (i1 > j1) {
        j1 = i1;
      }

      // CraftBukkit start - Check if we can actually do something over this large a distance
      Location eyeLoc = getPlayer().getEyeLocation();
      if (Math.pow(eyeLoc.getX() - i, 2)
              + Math.pow(eyeLoc.getY() - j, 2)
              + Math.pow(eyeLoc.getZ() - k, 2)
          > PLACE_DISTANCE_SQUARED) {
        return;
      }
      flag = true; // spawn protection moved to ItemBlock!!!
      // CraftBukkit end

      if (j1 > 16 || flag) {
        this.player.itemInWorldManager.interact(this.player, worldserver, itemstack, i, j, k, l);
      }

      this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
      if (l == 0) {
        --j;
      }

      if (l == 1) {
        ++j;
      }

      if (l == 2) {
        --k;
      }

      if (l == 3) {
        ++k;
      }

      if (l == 4) {
        --i;
      }

      if (l == 5) {
        ++i;
      }

      this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
    }

    itemstack = this.player.inventory.getItemInHand();
    if (itemstack != null && itemstack.count == 0) {
      this.player.inventory.items[this.player.inventory.itemInHandIndex] = null;
    }

    this.player.h = true;
    this.player.inventory.items[this.player.inventory.itemInHandIndex] =
        ItemStack.b(this.player.inventory.items[this.player.inventory.itemInHandIndex]);
    Slot slot =
        this.player.activeContainer.a(this.player.inventory, this.player.inventory.itemInHandIndex);

    this.player.activeContainer.a();
    this.player.h = false;
    // CraftBukkit
    if (!ItemStack.equals(this.player.inventory.getItemInHand(), packet15place.itemstack)
        || always) {
      this.sendPacket(
          new Packet103SetSlot(
              this.player.activeContainer.f, slot.a, this.player.inventory.getItemInHand()));
    }

    worldserver.weirdIsOpCache = false;
  }
 @EventHandler
 public void onPInt(PlayerInteractEvent event) {
   if (PConfManager.getPValBoolean(event.getPlayer(), "frozen")) event.setCancelled(true);
   if (plugin.buildPerm)
     if (!plugin.isAuthorized(event.getPlayer(), "rcmds.build")) event.setCancelled(true);
 }
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Action action = event.getAction();
    if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
      Block block = event.getClickedBlock();
      Material type = block.getType();
      Player player = event.getPlayer();

      GlobalConfiguration cfg = plugin.getGlobalConfiguration();
      WorldConfiguration wcfg = cfg.getWorldConfig(event.getClickedBlock().getWorld().getName());

      if (wcfg.useRegions && player.getItemInHand().getTypeId() == wcfg.regionWand) {
        Vector pt = toVector(block);

        RegionManager mgr =
            plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
        ApplicableRegionSet app = mgr.getApplicableRegions(pt);
        List<String> regions = mgr.getApplicableRegionsIDs(pt);

        if (regions.size() > 0) {
          player.sendMessage(
              ChatColor.YELLOW
                  + "Can you build? "
                  + (app.canBuild(BukkitPlayer.wrapPlayer(plugin, player)) ? "Yes" : "No"));

          StringBuilder str = new StringBuilder();
          for (Iterator<String> it = regions.iterator(); it.hasNext(); ) {
            str.append(it.next());
            if (it.hasNext()) {
              str.append(", ");
            }
          }

          player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString());
        } else {
          player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!");
        }
      }

      if (block.getType() == Material.CHEST
          || block.getType() == Material.DISPENSER
          || block.getType() == Material.FURNACE
          || block.getType() == Material.BURNING_FURNACE
          || block.getType() == Material.NOTE_BLOCK) {
        if (wcfg.useRegions) {
          Vector pt = toVector(block);
          LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);
          RegionManager mgr =
              plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());

          if (!plugin.hasPermission(player, "region.bypass")) {
            ApplicableRegionSet set = mgr.getApplicableRegions(pt);
            if (!set.isStateFlagAllowed(Flags.CHEST_ACCESS) && !set.canBuild(localPlayer)) {
              player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
              event.setCancelled(true);
              return;
            }
          }
        }
      }

      if (wcfg.useRegions && (type == Material.LEVER || type == Material.STONE_BUTTON)) {
        Vector pt = toVector(block);
        RegionManager mgr =
            cfg.getWorldGuardPlugin()
                .getGlobalRegionManager()
                .getRegionManager(player.getWorld().getName());
        ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt);
        LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);

        if (!applicableRegions.isStateFlagAllowed(Flags.LEVER_AND_BUTTON, localPlayer)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
          event.setCancelled(true);
          return;
        }
      }

      if (wcfg.useRegions && type == Material.CAKE_BLOCK) {

        Vector pt = toVector(block);

        if (!cfg.canBuild(player, pt)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");

          byte newData = (byte) (block.getData() - 1);
          newData = newData < 0 ? 0 : newData;

          block.setData(newData);
          player.setHealth(player.getHealth() - 3);

          return;
        }
      }

      if (wcfg.useRegions
          && wcfg.useiConomy
          && cfg.getiConomy() != null
          && (type == Material.SIGN_POST || type == Material.SIGN || type == Material.WALL_SIGN)) {
        BlockState blockstate = block.getState();

        if (((Sign) blockstate).getLine(0).equalsIgnoreCase("[WorldGuard]")
            && ((Sign) blockstate).getLine(1).equalsIgnoreCase("For sale")) {
          String regionId = ((Sign) blockstate).getLine(2);
          // String regionComment = ((Sign)block).getLine(3);

          if (regionId != null && regionId != "") {
            RegionManager mgr =
                cfg.getWorldGuardPlugin()
                    .getGlobalRegionManager()
                    .getRegionManager(player.getWorld().getName());
            ProtectedRegion region = mgr.getRegion(regionId);

            if (region != null) {
              RegionFlagContainer flags = region.getFlags();

              if (flags.getBooleanFlag(Flags.BUYABLE).getValue(false)) {
                if (iConomy.getBank().hasAccount(player.getName())) {
                  Account account = iConomy.getBank().getAccount(player.getName());
                  double balance = account.getBalance();
                  double regionPrice = flags.getDoubleFlag(Flags.PRICE).getValue();

                  if (balance >= regionPrice) {
                    account.subtract(regionPrice);
                    player.sendMessage(
                        ChatColor.YELLOW
                            + "You have bought the region "
                            + regionId
                            + " for "
                            + iConomy.getBank().format(regionPrice));
                    DefaultDomain owners = region.getOwners();
                    owners.addPlayer(player.getName());
                    region.setOwners(owners);
                    flags.getBooleanFlag(Flags.BUYABLE).setValue(false);
                    account.save();
                  } else {
                    player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                  }
                } else {
                  player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                }
              } else {
                player.sendMessage(ChatColor.RED + "Region: " + regionId + " is not buyable");
              }
            } else {
              player.sendMessage(
                  ChatColor.DARK_RED + "The region " + regionId + " does not exist.");
            }
          } else {
            player.sendMessage(ChatColor.DARK_RED + "No region specified.");
          }
        }
      }

      if (wcfg.getBlacklist() != null) {

        if (!wcfg.getBlacklist()
            .check(
                new BlockInteractBlacklistEvent(
                    BukkitPlayer.wrapPlayer(plugin, player), toVector(block), block.getTypeId()),
                false,
                false)) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }
Exemple #16
0
  @EventHandler(priority = EventPriority.HIGH)
  public void CropTrampleOrFireCharge(PlayerInteractEvent event) {
    if (event.getClickedBlock() == null) {
      return;
    }

    Player p = event.getPlayer();

    // trampling crops
    if (p != null
        && event.getAction().equals(Action.PHYSICAL)
        && event.getClickedBlock().getType().toString().equals("SOIL")) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.cropDestroy"));
      event.setCancelled(true);
      return;
    }

    // Using fire charge
    ItemStack item = event.getItem();
    if (p != null
        && item != null
        && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && event.getItem().getType().equals(Material.FIREBALL)) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.useFireCharge"));
      event.setCancelled(true);
    }
  }
  @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_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;
        }
    }
  }