Beispiel #1
0
	private String getLocal(final IUser user, final long radius)
	{
		final Location loc = user.getPlayer().getLocation();
		final World world = loc.getWorld();
		final StringBuilder output = new StringBuilder();
		final long radiusSquared = radius * radius;
		Player userPlayer = user.getPlayer();

		for (Player onlinePlayer : server.getOnlinePlayers())
		{
			if (!onlinePlayer.getName().equals(user.getName()) && userPlayer.canSee(onlinePlayer))
			{
				final Location playerLoc = onlinePlayer.getLocation();
				if (playerLoc.getWorld() != world)
				{
					continue;
				}

				final long delta = (long)playerLoc.distanceSquared(loc);
				if (delta < radiusSquared)
				{
					if (output.length() > 0)
					{
						output.append(", ");
					}
					output.append(onlinePlayer.getDisplayName()).append("§f(§4").append((long)Math.sqrt(delta)).append("m§f)");
				}
			}
		}
		return output.length() > 1 ? output.toString() : _("none");
	}
	@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
	public void onPlayerMove(final PlayerMoveEvent event)
	{
		final IUser user = userMap.getUser(event.getPlayer());

		final ISettings settings = ess.getSettings();

		if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers())
		{
			final Location from = event.getFrom();
			final Location to = event.getTo().clone();
			to.setX(from.getX());
			to.setY(from.getY());
			to.setZ(from.getZ());
			try
			{
				event.setTo(LocationUtil.getSafeDestination(to));
			}
			catch (Exception ex)
			{
				event.setTo(to);
			}
			return;
		}

		final Location afk = user.getAfkPosition();
		if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9)
		{
			user.updateActivity(true);
		}
	}
Beispiel #3
0
    @Override
    public void run() {
      if (!MyWarp.inst().getTimerFactory().hasRunningTimer(type, WarpWarmup.class)) {
        cancel();
        return;
      }

      Player player = MyWarp.server().getPlayerExact(type);
      if (player == null) {
        cancel();
        return;
      }

      Location loc = player.getLocation();
      if (loc.distanceSquared(originalLoc) >= 2 * 2) {
        if (!MyWarp.inst()
            .getPermissionsManager()
            .hasPermission(player, "mywarp.warmup.disobey.moveabort")) {
          WarpWarmup.this.cancel();
          player.sendMessage(
              MyWarp.inst()
                  .getLocalizationManager()
                  .getString("commands.warp-to.warmup.cancelled-move", player));
          cancel();
        }
      }
    }
  public Boolean outOfRange(Location l) {
    if (!location.getWorld().equals(l.getWorld())) return true;

    if (location.equals(l)) return false;
    if (location.distanceSquared(l) > range_squared) return true;

    return false;
  }
Beispiel #5
0
 public boolean isMatching(final Location loc) {
   if (location == null) {
     return true;
   }
   if (loc == null) {
     return false;
   }
   return location.distanceSquared(loc) <= range2;
 }
Beispiel #6
0
  /**
   * Finds a teleport location for a spectator NEAR to another location
   *
   * <p>If possible, they will be placed 5 blocks away, facing towards the destination player.
   *
   * @param l the location they are to be teleported near to
   */
  public static Location getSpectatorTeleportLocation(Location l) {
    Location lp = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    Location lxp = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    Location lxn = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    Location lzp = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    Location lzn = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    Location tpl = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    boolean xp = true, xn = true, zp = true, zn = true;

    for (int i = 0; i < 5; i++) {
      if (xp) {
        lxp.setX(lxp.getX() + 1);
        if (!TeleportUtils.isSpaceForPlayer(lxp)) xp = false;
      }
      if (xn) {
        lxn.setX(lxn.getX() - 1);
        if (!TeleportUtils.isSpaceForPlayer(lxn)) xn = false;
      }
      if (zp) {
        lzp.setZ(lzp.getZ() + 1);
        if (!TeleportUtils.isSpaceForPlayer(lzp)) zp = false;
      }
      if (zn) {
        lzn.setZ(lzn.getZ() - 1);
        if (!TeleportUtils.isSpaceForPlayer(lzn)) zn = false;
      }
    }

    if (!xp) lxp.setX(lxp.getX() - 1);
    if (!xn) lxn.setX(lxn.getX() + 1);
    if (!zp) lzp.setZ(lzp.getZ() - 1);
    if (!zn) lzn.setZ(lzn.getZ() + 1);

    tpl.setYaw(90);
    tpl.setPitch(0);

    if (lxp.distanceSquared(lp) > tpl.distanceSquared(lp)) {
      tpl = lxp;
      tpl.setYaw(90);
    }
    if (lxn.distanceSquared(lp) > tpl.distanceSquared(lp)) {
      tpl = lxn;
      tpl.setYaw(270);
    }
    if (lzp.distanceSquared(lp) > tpl.distanceSquared(lp)) {
      tpl = lzp;
      tpl.setYaw(180);
    }
    if (lzn.distanceSquared(lp) > tpl.distanceSquared(lp)) {
      tpl = lzn;
      tpl.setYaw(0);
    }
    return tpl;
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onBlockBreak(BlockBreakEvent event) {
    Player p = event.getPlayer();
    Location block_pos = event.getBlock().getLocation();

    if (TotalFreedomMod.nukeMonitor) {
      TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);

      Location player_pos = p.getLocation();

      boolean out_of_range = false;
      if (!player_pos.getWorld().equals(block_pos.getWorld())) {
        out_of_range = true;
      } else if (player_pos.distanceSquared(block_pos)
          > (TotalFreedomMod.nukeMonitorRange * TotalFreedomMod.nukeMonitorRange)) {
        out_of_range = true;
      }

      if (out_of_range) {
        playerdata.incrementFreecamDestroyCount();
        if (playerdata.getFreecamDestroyCount() > TotalFreedomMod.freecamTriggerCount) {
          TFM_Util.bcastMsg(
              p.getName() + " has been flagged for possible freecam nuking.", ChatColor.RED);
          TFM_Util.autoEject(
              p, "Freecam (extended range) block breaking is not permitted on this server.");

          playerdata.resetFreecamDestroyCount();

          event.setCancelled(true);
          return;
        }
      }

      playerdata.incrementBlockDestroyCount();
      if (playerdata.getBlockDestroyCount() > TotalFreedomMod.nukeMonitorCountBreak) {
        TFM_Util.bcastMsg(p.getName() + " is breaking blocks too fast!", ChatColor.RED);
        TFM_Util.autoEject(
            p, "You are breaking blocks too fast. Nukers are not permitted on this server.");

        playerdata.resetBlockDestroyCount();

        event.setCancelled(true);
        return;
      }
    }

    if (TotalFreedomMod.protectedAreasEnabled) {
      if (!TFM_SuperadminList.isUserSuperadmin(p)) {
        if (TFM_ProtectedArea.isInProtectedArea(block_pos)) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }
  public Player getNearestPlayer(Location l) {

    Player currclosest = null;
    double currentmin = Double.MAX_VALUE;
    double grabdist = 0;
    for (Player p : l.getWorld().getPlayers()) {
      if ((grabdist = l.distanceSquared(p.getLocation())) < currentmin) {
        currentmin = grabdist;
        currclosest = p;
      }
    }

    return currclosest;
  }
Beispiel #9
0
  public static void sendPacketNearby(Location location, Packet packet, double radius) {
    radius *= radius;
    final World world = location.getWorld();
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
      if (p == null || world != p.getWorld()) {
        continue;
      }
      if (location.distanceSquared(p.getLocation()) > radius) {
        continue;
      }

      ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
    }
  }
Beispiel #10
0
 /**
  * Returns the Player that is closest to the given Location. Returns null if no Players are within
  * 50 Blocks
  *
  * @param location The given Location
  * @return the closest Player
  */
 public static Player getNearestPlayer(Location location) {
   Player nearestPlayer = null;
   double shortestDistance = 2500;
   for (Player player : location.getWorld().getPlayers()) {
     Location playerLocation = player.getLocation();
     // Use the squared distance because is it much less resource intensive
     double distanceToPlayer = location.distanceSquared(playerLocation);
     if (distanceToPlayer < shortestDistance) {
       nearestPlayer = player;
       shortestDistance = distanceToPlayer;
     }
   }
   return nearestPlayer;
 }
Beispiel #11
0
 public static boolean removeSwipesAroundPoint(Location loc, double radius) {
   boolean removed = false;
   for (AirSwipe aswipe : getAbilities(AirSwipe.class)) {
     for (Vector vec : aswipe.elements.keySet()) {
       Location vectorLoc = aswipe.elements.get(vec);
       if (vectorLoc != null && vectorLoc.getWorld().equals(loc.getWorld())) {
         if (vectorLoc.distanceSquared(loc) <= radius * radius) {
           aswipe.remove();
           removed = true;
         }
       }
     }
   }
   return removed;
 }
Beispiel #12
0
 /**
  * Removes all instances of Suffocate at loc within the radius threshold. The location of a
  * Suffocate is defined at the benders location, not the location of the entities being
  * suffocated.
  *
  * @param causer The player causing this instance to be removed
  */
 public static boolean removeAtLocation(Player causer, Location loc, double radius) {
   if (causer == null) {
     return false;
   }
   for (Suffocate suff : getAbilities(Suffocate.class)) {
     if (!suff.player.equals(causer)) {
       Location playerLoc = suff.getPlayer().getLocation();
       if (playerLoc.getWorld().equals(loc.getWorld())
           && playerLoc.distanceSquared(loc) <= radius * radius) {
         suff.remove();
         return true;
       }
     }
   }
   return false;
 }
Beispiel #13
0
 public static void sendPacketsNearby(
     Player from, Location location, Collection<Packet> packets, double radius) {
   radius *= radius;
   final org.bukkit.World world = location.getWorld();
   for (Player ply : Bukkit.getServer().getOnlinePlayers()) {
     if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) {
       continue;
     }
     if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) {
       continue;
     }
     for (Packet packet : packets) {
       sendPacket(ply, packet);
     }
   }
 }
Beispiel #14
0
 public static void sendPacketsNearby(
     Location location, Collection<Packet> packets, double radius) {
   radius *= radius;
   final org.bukkit.World world = location.getWorld();
   for (Player ply : Bukkit.getServer().getOnlinePlayers()) {
     if (ply == null || world != ply.getWorld()) {
       continue;
     }
     if (location.distanceSquared(ply.getLocation(packetCacheLocation)) > radius) {
       continue;
     }
     for (Packet packet : packets) {
       sendPacket(ply, packet);
     }
   }
 }
Beispiel #15
0
  @Override
  public void run() {
    for (final Player player : Bukkit.getServer().getOnlinePlayers()) {
      final PlayerProfile prof = profMan.getProfile(player.getName());
      final Quest quest = prof.getQuest();
      if (quest != null) {
        // LOCATION CHECK
        if (!quest.allowedWorld(player.getWorld().getName().toLowerCase())) {
          continue;
        }
        final List<Objective> objs = quest.getObjectives();
        for (int i = 0; i < objs.size(); i++) {
          if (objs.get(i).getType().equalsIgnoreCase("REGION")) {
            if (!profMan.isObjectiveActive(prof, i)) {
              continue;
            }
            final RegionObjective obj = (RegionObjective) objs.get(i);
            if (obj.checkLocation(player.getLocation())) {
              profMan.incProgress(player, ActionSource.otherSource(null), i);
              break;
            }
          }
        }

      } else {
        final Location loc = player.getLocation();
        for (final int ID : qMan.questLocations.keySet()) {
          final Quest qst = qMan.getQuest(ID);
          final Location loc2 = qMan.questLocations.get(ID);
          if (loc2.getWorld().getName().equals(loc.getWorld().getName())) {
            if (loc2.distanceSquared(loc) <= qst.getRange() * qst.getRange()
                && qst.hasFlag(QuestFlag.ACTIVE)) {
              try {
                profMan.startQuest(
                    player,
                    qst.getName(),
                    ActionSource.otherSource(null),
                    langMan.getPlayerLang(player.getName()));
              } catch (final QuesterException e) {
              }
            }
          }
        }
      }
    }
  }
Beispiel #16
0
  @Override
  public void run(EventData data) throws BailException {
    Class<?> entClass = filterElement.myClass;
    LivingEntity entity = (LivingEntity) entityDP.get(data);
    if (entity == null) return;

    Integer r = radius.get(data);
    if (r == null) return;
    List<Entity> entities = entity.getNearbyEntities(r, r, r);
    if (entities.isEmpty()) return;

    if (nearest) {
      Location eloc = entity.getLocation();

      double distance = Float.MAX_VALUE;
      Entity nearestEntity = null;

      for (Entity e : entities) {
        if (!entClass.isAssignableFrom(e.getClass())) continue;

        double edist = eloc.distanceSquared(e.getLocation());
        if (edist < distance) {
          distance = edist;
          nearestEntity = e;
        }
      }

      if (nearestEntity != null) {
        EventData newData = myInfo.makeChainedData(data, nearestEntity);

        routines.run(newData);
      }
    } else {
      for (Entity e : entities) {
        if (entClass.isAssignableFrom(e.getClass())) {
          EventData newData = myInfo.makeChainedData(data, e);

          routines.run(newData);

          continue;
        }
      }
    }
  }
	@EventHandler(priority = EventPriority.HIGHEST)
	public void onLocalChat(final EssentialsLocalChatEvent event)
	{
		final Player sender = event.getPlayer();
		final Location loc = sender.getLocation();
		final World world = loc.getWorld();

		for (Player onlinePlayer : server.getOnlinePlayers())
		{
			String type = _("chatTypeLocal");
			final IUser user = ess.getUser(onlinePlayer);
			if (user.isIgnoringPlayer(ess.getUser(sender)))
			{
				continue;
			}
			if (!user.equals(sender))
			{
				boolean abort = false;
				final Location playerLoc = user.getLocation();
				if (playerLoc.getWorld() != world)
				{
					abort = true;
				}
				final double delta = playerLoc.distanceSquared(loc);

				if (delta > event.getRadius())
				{
					abort = true;
				}

				if (abort)
				{
					if (ChatPermissions.getPermission("spy").isAuthorized(user))
					{
						type = type.concat(_("chatTypeSpy"));
					}
				}
			}
			final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage()));
			user.sendMessage(message);
		}
	}
Beispiel #18
0
  /**
   * On entity damage.
   *
   * @param event the events
   */
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onEntityDamage(EntityDamageEvent event) {

    // Check for fire cancel
    if (event.getEntity() instanceof Player
        && (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK)) {

      Player player = (Player) event.getEntity();
      ApiPlayerConfEntry entry = playerConf.get(player);

      if (entry != null) {
        Location loc = player.getLocation();
        ApiDummyLand land = Secuboid.getThisPlugin().getLands().getLandOrOutsideArea(loc);

        // Check for fire near the player
        for (Map.Entry<Location, ApiPlayerContainerPlayer> fireEntry :
            playerFireLocation.entrySet()) {

          if (loc.getWorld() == fireEntry.getKey().getWorld()
              && loc.distanceSquared(fireEntry.getKey()) < 5) {
            Block block = loc.getBlock();
            if ((block.getType() == Material.FIRE || block.getType() == Material.AIR)
                && !isPvpValid(land, fireEntry.getValue(), entry.getPlayerContainer())) {

              // remove fire
              Secuboid.getThisPlugin()
                  .getLog()
                  .write(
                      "Anti-pvp from "
                          + entry.getPlayerContainer().getPlayer().getName()
                          + " to "
                          + player.getName());
              block.setType(Material.AIR);
              player.setFireTicks(0);
              event.setDamage(0);
              event.setCancelled(true);
            }
          }
        }
      }
    }
  }
Beispiel #19
0
  protected List<Player> getLocalRecipients(Player sender, String message, double range) {
    Location playerLocation = sender.getLocation();
    List<Player> recipients = new LinkedList<Player>();
    double squaredDistance = Math.pow(range, 2);
    PermissionManager manager = PermissionsEx.getPermissionManager();
    for (Player recipient : Bukkit.getServer().getOnlinePlayers()) {
      // Recipient are not from same world
      if (!recipient.getWorld().equals(sender.getWorld())) {
        continue;
      }

      if (playerLocation.distanceSquared(recipient.getLocation()) > squaredDistance
          && !manager.has(sender, "chatmanager.override.ranged")) {
        continue;
      }

      recipients.add(recipient);
    }
    return recipients;
  }
  public void moveLava() {
    if (sourceBlock != null) {
      targetDestination = getTargetEarthBlock((int) range).getLocation();

      if (targetDestination.distanceSquared(location) <= 1) {
        progressing = false;
        targetDestination = null;
      } else {
        progressing = true;
        settingUp = true;
        firstDestination = getToEyeLevel();
        firstDirection = getDirection(sourceBlock.getLocation(), firstDestination);
        targetDirection = getDirection(firstDestination, targetDestination);

        if (!GeneralMethods.isAdjacentToThreeOrMoreSources(sourceBlock)) {
          sourceBlock.setType(Material.AIR);
        }
        addLava(sourceBlock);
      }
    }
  }
 public static boolean inParticleRange(Player player, Location location, int viewDistance) {
   double distance;
   if (player.getLocation().getWorld() != location.getWorld()) return false;
   distance = location.distanceSquared(player.getLocation());
   return distance <= Double.MAX_VALUE && distance < viewDistance * viewDistance;
 }
  @Override
  public void onPlayerMove(final PlayerMoveEvent event) {
    if (event.isCancelled()) {
      return;
    }
    final User user = ess.getUser(event.getPlayer());

    if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) {
      final Location from = event.getFrom();
      final Location to = event.getTo().clone();
      to.setX(from.getX());
      to.setY(from.getBlock().getTypeId() == 0 ? from.getY() - 1 : from.getY());
      to.setZ(from.getZ());
      event.setTo(to);
      return;
    }

    Location afk = user.getAfkPosition();
    if (afk == null
        || !event.getTo().getWorld().equals(afk.getWorld())
        || afk.distanceSquared(event.getTo()) > 9) {
      user.updateActivity(true);
    }

    if (!ess.getSettings().getNetherPortalsEnabled()) {
      return;
    }

    final Block block =
        event
            .getPlayer()
            .getWorld()
            .getBlockAt(
                event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
    final List<World> worlds = server.getWorlds();

    if (block.getType() == Material.PORTAL
        && worlds.size() > 1
        && user.isAuthorized("essentials.portal")) {
      if (user.getJustPortaled()) {
        return;
      }

      World nether = server.getWorld(ess.getSettings().getNetherName());
      if (nether == null) {
        for (World world : worlds) {
          if (world.getEnvironment() == World.Environment.NETHER) {
            nether = world;
            break;
          }
        }
        if (nether == null) {
          return;
        }
      }
      final World world = user.getWorld() == nether ? worlds.get(0) : nether;

      double factor;
      if (user.getWorld().getEnvironment() == World.Environment.NETHER
          && world.getEnvironment() == World.Environment.NORMAL) {
        factor = ess.getSettings().getNetherRatio();
      } else if (user.getWorld().getEnvironment() == World.Environment.NORMAL
          && world.getEnvironment() == World.Environment.NETHER) {
        factor = 1.0 / ess.getSettings().getNetherRatio();
      } else {
        factor = 1.0;
      }

      Location loc = event.getTo();
      int x = loc.getBlockX();
      int y = loc.getBlockY();
      int z = loc.getBlockZ();

      if (user.getWorld().getBlockAt(x, y, z - 1).getType() == Material.PORTAL) {
        z--;
      }
      if (user.getWorld().getBlockAt(x - 1, y, z).getType() == Material.PORTAL) {
        x--;
      }

      x = (int) (x * factor);
      z = (int) (z * factor);
      loc = new Location(world, x + .5, y, z + .5);

      Block dest = world.getBlockAt(x, y, z);
      NetherPortal portal = NetherPortal.findPortal(dest);
      if (portal == null) {
        if (world.getEnvironment() == World.Environment.NETHER
            || ess.getSettings().getGenerateExitPortals()) {
          portal = NetherPortal.createPortal(dest);
          LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName()));
          user.sendMessage(Util.i18n("generatingPortal"));
          loc = portal.getSpawn();
        }
      } else {
        LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName()));
        user.sendMessage(Util.i18n("usingPortal"));
        loc = portal.getSpawn();
      }

      event.setFrom(loc);
      event.setTo(loc);
      try {
        user.getTeleport().now(loc, new Trade("portal", ess));
      } catch (Exception ex) {
        user.sendMessage(ex.getMessage());
      }
      user.setJustPortaled(true);
      user.sendMessage(Util.i18n("teleportingPortal"));

      event.setCancelled(true);
      return;
    }

    user.setJustPortaled(false);
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerMove(PlayerMoveEvent event) {
    if (!TFM_AdminWorld.getInstance().validateMovement(event)) {
      return;
    }

    Player p = event.getPlayer();
    TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);

    for (Entry<Player, Double> fuckoff : TotalFreedomMod.fuckoffEnabledFor.entrySet()) {
      Player fuckoff_player = fuckoff.getKey();

      if (fuckoff_player.equals(p) || !fuckoff_player.isOnline()) {
        continue;
      }

      double fuckoff_range = fuckoff.getValue().doubleValue();

      Location mover_pos = p.getLocation();
      Location fuckoff_pos = fuckoff_player.getLocation();

      double distanceSquared;
      try {
        distanceSquared = mover_pos.distanceSquared(fuckoff_pos);
      } catch (IllegalArgumentException ex) {
        continue;
      }

      if (distanceSquared < (fuckoff_range * fuckoff_range)) {
        event.setTo(
            fuckoff_pos
                .clone()
                .add(
                    mover_pos
                        .subtract(fuckoff_pos)
                        .toVector()
                        .normalize()
                        .multiply(fuckoff_range * 1.1)));
        break;
      }
    }

    boolean do_freeze = false;
    if (TotalFreedomMod.allPlayersFrozen) {
      if (!TFM_SuperadminList.isUserSuperadmin(p)) {
        do_freeze = true;
      }
    } else {
      if (playerdata.isFrozen()) {
        do_freeze = true;
      }
    }

    if (do_freeze) {
      Location from = event.getFrom();
      Location to = event.getTo().clone();

      to.setX(from.getX());
      to.setY(from.getY());
      to.setZ(from.getZ());

      event.setTo(to);
    }

    if (playerdata.isCaged()) {
      Location target_pos = p.getLocation().add(0, 1, 0);

      boolean out_of_cage;
      if (!target_pos.getWorld().equals(playerdata.getCagePos().getWorld())) {
        out_of_cage = true;
      } else {
        out_of_cage = target_pos.distanceSquared(playerdata.getCagePos()) > (2.5 * 2.5);
      }

      if (out_of_cage) {
        playerdata.setCaged(
            true,
            target_pos,
            playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER),
            playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
        playerdata.regenerateHistory();
        playerdata.clearHistory();
        TFM_Util.buildHistory(target_pos, 2, playerdata);
        TFM_Util.generateCube(
            target_pos, 2, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER));
        TFM_Util.generateCube(
            target_pos, 1, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
      }
    }

    if (playerdata.isOrbiting()) {
      if (p.getVelocity().length() < playerdata.orbitStrength() * (2.0 / 3.0)) {
        p.setVelocity(new Vector(0, playerdata.orbitStrength(), 0));
      }
    }

    if (TotalFreedomMod.landminesEnabled && TotalFreedomMod.allowExplosions) {
      Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
      while (landmines.hasNext()) {
        TFM_LandmineData landmine = landmines.next();

        Location landmine_pos = landmine.landmine_pos;
        if (landmine_pos.getBlock().getType() != Material.TNT) {
          landmines.remove();
          continue;
        }

        if (!landmine.player.equals(p)) {
          if (p.getWorld().equals(landmine_pos.getWorld())) {
            if (p.getLocation().distanceSquared(landmine_pos)
                <= (landmine.radius * landmine.radius)) {
              landmine.landmine_pos.getBlock().setType(Material.AIR);

              TNTPrimed tnt1 = landmine_pos.getWorld().spawn(landmine_pos, TNTPrimed.class);
              tnt1.setFuseTicks(40);
              tnt1.setPassenger(p);
              tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));

              TNTPrimed tnt2 = landmine_pos.getWorld().spawn(p.getLocation(), TNTPrimed.class);
              tnt2.setFuseTicks(1);

              p.setGameMode(GameMode.SURVIVAL);
              landmines.remove();
            }
          }
        }
      }
    }
  }
Beispiel #24
0
  public void target(TargetMode mode) {
    targetMode = mode == null ? TargetMode.STABILIZE : mode;
    switch (targetMode) {
      case FLEE:
      case HUNT:
      case DIRECTED:
        Target bestTarget = null;
        reverseTargetDistanceScore = true;
        if (targetType == TargetType.ANY || targetType == TargetType.MOB) {
          List<Entity> entities =
              CompatibilityUtils.getNearbyEntities(
                  center, huntMaxRange, huntMaxRange, huntMaxRange);
          for (Entity entity : entities) {
            // We'll get the players from the Mages list
            if (entity instanceof Player || !(entity instanceof LivingEntity) || entity.isDead())
              continue;
            if (!entity.getLocation().getWorld().equals(center.getWorld())) continue;
            LivingEntity li = (LivingEntity) entity;
            if (li.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
            Target newScore =
                new Target(center, entity, huntMinRange, huntMaxRange, huntFov, false);
            int score = newScore.getScore();
            if (bestTarget == null || score > bestTarget.getScore()) {
              bestTarget = newScore;
            }
          }
        }
        if (targetType == TargetType.MAGE
            || targetType == TargetType.AUTOMATON
            || targetType == TargetType.ANY
            || targetType == TargetType.PLAYER) {
          Collection<Mage> mages = controller.getMages();
          for (Mage mage : mages) {
            if (mage == this.mage) continue;
            if (targetType == TargetType.AUTOMATON && mage.getPlayer() != null) continue;
            if (targetType == TargetType.PLAYER && mage.getPlayer() == null) continue;
            if (mage.isDead() || !mage.isOnline() || !mage.hasLocation()) continue;
            if (!mage.getLocation().getWorld().equals(center.getWorld())) continue;
            if (!mage.getLocation().getWorld().equals(center.getWorld())) continue;

            if (!mage.isPlayer()) {
              // Check for automata of the same type, kinda hacky.. ?
              Block block = mage.getLocation().getBlock();
              if (block.getType() == Material.COMMAND) {
                BlockState blockState = block.getState();
                if (blockState != null && blockState instanceof CommandBlock) {
                  CommandBlock command = (CommandBlock) blockState;
                  String commandString = command.getCommand();
                  if (commandString != null
                      && commandString.length() > 0
                      && commandString.startsWith("cast " + spell.getKey())) {
                    continue;
                  }
                }
              }
            } else {
              Player player = mage.getPlayer();
              if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
            }

            Target newScore = new Target(center, mage, huntMinRange, huntMaxRange, huntFov, false);
            int score = newScore.getScore();
            if (bestTarget == null || score > bestTarget.getScore()) {
              bestTarget = newScore;
            }
          }
        }

        if (bestTarget != null) {
          String targetDescription =
              bestTarget.getEntity() == null
                  ? "NONE"
                  : ((bestTarget instanceof Player)
                      ? ((Player) bestTarget.getEntity()).getName()
                      : bestTarget.getEntity().getType().name());

          if (DEBUG) {
            controller
                .getLogger()
                .info(
                    " *Tracking "
                        + targetDescription
                        + " score: "
                        + bestTarget.getScore()
                        + " location: "
                        + center
                        + " -> "
                        + bestTarget.getLocation()
                        + " move "
                        + commandMoveRangeSquared);
          }
          Vector direction = null;

          if (targetMode == TargetMode.DIRECTED) {
            direction = bestTarget.getLocation().getDirection();
            if (DEBUG) {
              controller.getLogger().info(" *Directed: " + direction);
            }
          } else {
            Location targetLocation = bestTarget.getLocation();
            direction = targetLocation.toVector().subtract(center.toVector());
          }

          if (direction != null) {
            center.setDirection(direction);
          }

          // Check for obstruction
          // TODO Think about this more..
          /*
          Block block = spell.getInteractBlock();
          if (block.getType() != Material.AIR && block.getType() != POWER_MATERIAL && !!birthMaterial.is(block)) {
          	// TODO: Use location.setDirection in 1.7+
          	center = CompatibilityUtils.setDirection(center, new Vector(0, 1, 0));
          }
          */

          if (level != null
              && center.distanceSquared(bestTarget.getLocation()) < castRange * castRange) {
            level.onTick(mage, birthMaterial);
          }

          // After ticking, re-position for movement. This way spells still fire towards the target.
          if (targetMode == TargetMode.FLEE) {
            direction = direction.multiply(-1);
            // Don't Flee upward
            if (direction.getY() > 0) {
              direction.setY(-direction.getY());
            }
          }
        }
        break;
      case GLIDE:
        reverseTargetDistanceScore = true;
        break;
      default:
        reverseTargetDistanceScore = false;
    }
  }
Beispiel #25
0
  @Override
  public void progress() {
    progressCounter++;
    if (player.isDead() || !player.isOnline()) {
      remove();
      return;
    } else if (currentLoc != null && GeneralMethods.isRegionProtectedFromBuild(this, currentLoc)) {
      remove();
      return;
    }

    if (abilityName.equalsIgnoreCase("Twister")) {
      if (destination == null) {
        state = AbilityState.TWISTER_MOVING;
        direction = player.getEyeLocation().getDirection().clone().normalize();
        direction.setY(0);
        origin = player.getLocation().add(direction.clone().multiply(2));
        destination = player.getLocation().add(direction.clone().multiply(range));
        currentLoc = origin.clone();
      }
      if (origin.distanceSquared(currentLoc) < origin.distanceSquared(destination)
          && state == AbilityState.TWISTER_MOVING) {
        currentLoc.add(direction.clone().multiply(speed));
      } else if (state == AbilityState.TWISTER_MOVING) {
        state = AbilityState.TWISTER_STATIONARY;
        time = System.currentTimeMillis();
      } else if (System.currentTimeMillis() - time >= twisterRemoveDelay) {
        remove();
        return;
      } else if (GeneralMethods.isRegionProtectedFromBuild(this, currentLoc)) {
        remove();
        return;
      }

      Block topBlock = GeneralMethods.getTopBlock(currentLoc, 3, -3);
      if (topBlock == null) {
        remove();
        return;
      }
      currentLoc.setY(topBlock.getLocation().getY());

      double height = twisterHeight;
      double radius = twisterRadius;
      for (double y = 0; y < height; y += twisterHeightParticles) {
        double animRadius = ((radius / height) * y);
        for (double i = -180; i <= 180; i += twisterDegreeParticles) {
          Vector animDir = GeneralMethods.rotateXZ(new Vector(1, 0, 1), i);
          Location animLoc = currentLoc.clone().add(animDir.multiply(animRadius));
          animLoc.add(0, y, 0);
          playAirbendingParticles(animLoc, 1, 0, 0, 0);
        }
      }
      playAirbendingSound(currentLoc);

      for (int i = 0; i < height; i += 3) {
        for (Entity entity :
            GeneralMethods.getEntitiesAroundPoint(currentLoc.clone().add(0, i, 0), radius * 0.75)) {
          if (!affectedEntities.contains(entity) && !entity.equals(player)) {
            affectedEntities.add(entity);
          }
        }
      }

      for (Entity entity : affectedEntities) {
        Vector forceDir =
            GeneralMethods.getDirection(entity.getLocation(), currentLoc.clone().add(0, height, 0));
        if (entity instanceof Player) {
          if (Commands.invincible.contains(((Player) entity).getName())) {
            break;
          }
        }
        entity.setVelocity(forceDir.clone().normalize().multiply(0.3));
      }
    } else if (abilityName.equalsIgnoreCase("AirStream")) {
      if (destination == null) {
        origin = player.getEyeLocation();
        currentLoc = origin.clone();
      }
      Entity target = GeneralMethods.getTargetedEntity(player, range);
      if (target instanceof Player) {
        if (Commands.invincible.contains(((Player) target).getName())) {
          return;
        }
      }

      if (target != null && target.getLocation().distanceSquared(currentLoc) > 49) {
        destination = target.getLocation();
      } else {
        destination = GeneralMethods.getTargetedLocation(player, range, getTransparentMaterial());
      }

      direction = GeneralMethods.getDirection(currentLoc, destination).normalize();
      currentLoc.add(direction.clone().multiply(speed));

      if (player.getWorld() != currentLoc.getWorld()) {
        remove();
        return;
      } else if (!player.isSneaking()) {
        remove();
        return;
      } else if (player.getWorld().equals(currentLoc.getWorld())
          && Math.abs(player.getLocation().distanceSquared(currentLoc)) > range * range) {
        remove();
        return;
      } else if (affectedEntities.size() > 0
          && System.currentTimeMillis() - time >= airStreamEntityCarryDuration) {
        remove();
        return;
      } else if (!isTransparent(currentLoc.getBlock())) {
        remove();
        return;
      } else if (currentLoc.getY() - origin.getY() > airStreamMaxEntityHeight) {
        remove();
        return;
      } else if (GeneralMethods.isRegionProtectedFromBuild(this, currentLoc)) {
        remove();
        return;
      } else if (FireAbility.isWithinFireShield(currentLoc)) {
        remove();
        return;
      } else if (isWithinAirShield(currentLoc)) {
        remove();
        return;
      } else if (!isTransparent(currentLoc.getBlock())) {
        currentLoc.subtract(direction.clone().multiply(speed));
      }

      for (int i = 0; i < 10; i++) {
        BukkitRunnable br =
            new BukkitRunnable() {
              final Location loc = currentLoc.clone();
              final Vector dir = direction.clone();

              @Override
              public void run() {
                for (int angle = -180; angle <= 180; angle += 45) {
                  Vector orthog = GeneralMethods.getOrthogonalVector(dir.clone(), angle, 0.5);
                  playAirbendingParticles(loc.clone().add(orthog), 1, 0F, 0F, 0F);
                }
              }
            };
        br.runTaskLater(ProjectKorra.plugin, i * 2);
        tasks.add(br);
      }

      for (Entity entity : GeneralMethods.getEntitiesAroundPoint(currentLoc, 2.8)) {
        if (affectedEntities.size() == 0) {
          // Set the timer to remove the ability
          time = System.currentTimeMillis();
        }
        if (!entity.equals(player) && !affectedEntities.contains(entity)) {
          affectedEntities.add(entity);
          if (entity instanceof Player) {
            flights.add(new Flight((Player) entity, player));
          }
        }
      }

      for (Entity entity : affectedEntities) {
        Vector force = GeneralMethods.getDirection(entity.getLocation(), currentLoc);
        entity.setVelocity(force.clone().normalize().multiply(speed));
        entity.setFallDistance(0F);
      }
    } else if (abilityName.equalsIgnoreCase("AirSweep")) {
      if (origin == null) {
        direction = player.getEyeLocation().getDirection().normalize();
        origin = player.getLocation().add(direction.clone().multiply(10));
      }
      if (progressCounter < 8) {
        return;
      }
      if (destination == null) {
        destination =
            player
                .getLocation()
                .add(player.getEyeLocation().getDirection().normalize().multiply(10));
        Vector origToDest = GeneralMethods.getDirection(origin, destination);
        for (double i = 0; i < 30; i++) {
          Vector vec =
              GeneralMethods.getDirection(
                  player.getLocation(), origin.clone().add(origToDest.clone().multiply(i / 30)));

          FireComboStream fs =
              new FireComboStream(null, vec, player.getLocation(), range, speed, "AirSweep");
          fs.setDensity(1);
          fs.setSpread(0F);
          fs.setUseNewParticles(true);
          fs.setParticleEffect(getAirbendingParticles());
          fs.setCollides(false);
          fs.runTaskTimer(ProjectKorra.plugin, (long) (i / 2.5), 1L);
          tasks.add(fs);
        }
      }
      manageAirVectors();
    }
  }
  @Override
  public void progress() {
    if (!bPlayer.canBendIgnoreCooldowns(this)) {
      if (!forming) {
        breakBlock();
      }
      remove();
      return;
    }

    if (System.currentTimeMillis() - time >= interval) {
      time = System.currentTimeMillis();
      if (progressing && !player.isSneaking()) {
        remove();
        return;
      }

      if (!progressing) {
        sourceBlock.getWorld().playEffect(location, Effect.SMOKE, 4, (int) range);
        return;
      }

      if (forming) {
        ArrayList<Block> blocks = new ArrayList<Block>();
        Location loc = GeneralMethods.getTargetedLocation(player, (int) range, 8, 9, 79);
        location = loc.clone();
        Vector dir = player.getEyeLocation().getDirection();
        Vector vec;
        Block block;

        for (double i = 0; i <= radius; i += 0.5) {
          for (double angle = 0; angle < 360; angle += 10) {
            vec = GeneralMethods.getOrthogonalVector(dir.clone(), angle, i);
            block = loc.clone().add(vec).getBlock();

            if (GeneralMethods.isRegionProtectedFromBuild(
                player, "LavaSurge", block.getLocation())) {
              continue;
            }
            if (WALL_BLOCKS.containsKey(block)) {
              blocks.add(block);
            } else if (!blocks.contains(block)
                && (block.getType() == Material.AIR
                    || block.getType() == Material.FIRE
                    || isLavabendable(block))) {
              WALL_BLOCKS.put(block, player);
              addWallBlock(block);
              blocks.add(block);
              FireBlast.removeFireBlastsAroundPoint(block.getLocation(), 2);
            }
          }
        }

        for (Block blocki : WALL_BLOCKS.keySet()) {
          if (WALL_BLOCKS.get(blocki) == player && !blocks.contains(blocki)) {
            finalRemoveLava(blocki);
          }
        }

        return;
      }

      if (sourceBlock.getLocation().distanceSquared(firstDestination) < 0.5 * 0.5 && settingUp) {
        settingUp = false;
      }

      Vector direction;
      if (settingUp) {
        direction = firstDirection;
      } else {
        direction = targetDirection;
      }

      location = location.clone().add(direction);
      Block block = location.getBlock();
      if (block.getLocation().equals(sourceBlock.getLocation())) {
        location = location.clone().add(direction);
        block = location.getBlock();
      }

      if (block.getType() != Material.AIR) {
        breakBlock();
        return;
      } else if (!progressing) {
        breakBlock();
        return;
      }

      addLava(block);
      removeLava(sourceBlock);
      sourceBlock = block;
      if (location.distanceSquared(targetDestination) < 1) {
        removeLava(sourceBlock);
        forming = true;
      }
      return;
    }
  }
Beispiel #27
0
  @SuppressWarnings("deprecation")
  private void advanceSwipe() {
    affectedEntities.clear();
    for (Vector direction : elements.keySet()) {
      Location location = elements.get(direction);
      if (direction != null && location != null) {
        location = location.clone().add(direction.clone().multiply(speed));
        elements.replace(direction, location);

        if (location.distanceSquared(origin) > range * range
            || GeneralMethods.isRegionProtectedFromBuild(this, location)) {
          elements.remove(direction);
        } else {
          removeAirSpouts(location, player);
          WaterAbility.removeWaterSpouts(location, player);

          if (EarthBlast.annihilateBlasts(location, radius, player)
              || WaterManipulation.annihilateBlasts(location, radius, player)
              || FireBlast.annihilateBlasts(location, radius, player)
              || Combustion.removeAroundPoint(location, radius)) {
            elements.remove(direction);
            damage = 0;
            remove();
            continue;
          }

          Block block = location.getBlock();
          for (Block testblock : GeneralMethods.getBlocksAroundPoint(location, radius)) {
            if (testblock.getType() == Material.FIRE) {
              testblock.setType(Material.AIR);
            }
            if (isBlockBreakable(testblock)) {
              GeneralMethods.breakBlock(testblock);
            }
          }

          if (block.getType() != Material.AIR) {
            if (isBlockBreakable(block)) {
              GeneralMethods.breakBlock(block);
            } else {
              elements.remove(direction);
            }
            if (isLava(block)) {
              if (block.getData() == 0x0) {
                block.setType(Material.OBSIDIAN);
              } else {
                block.setType(Material.COBBLESTONE);
              }
            }
          } else {
            playAirbendingParticles(location, particles, 0.2F, 0.2F, 0);
            if (random.nextInt(4) == 0) {
              playAirbendingSound(location);
            }
            affectPeople(location, direction);
          }
        }
      }
    }
    if (elements.isEmpty()) {
      remove();
    }
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerMove(PlayerMoveEvent event) {
    final Location from = event.getFrom();
    final Location to = event.getTo();
    try {
      if (from.getWorld() == to.getWorld() && from.distanceSquared(to) < (0.0001 * 0.0001)) {
        // If player just rotated, but didn't move, don't process this event.
        return;
      }
    } catch (IllegalArgumentException ex) {
    }

    if (!TFM_AdminWorld.getInstance().validateMovement(event)) {
      return;
    }

    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    for (Entry<Player, Double> fuckoff : TotalFreedomMod.fuckoffEnabledFor.entrySet()) {
      Player fuckoffPlayer = fuckoff.getKey();

      if (fuckoffPlayer.equals(player) || !fuckoffPlayer.isOnline()) {
        continue;
      }

      double fuckoffRange = fuckoff.getValue();

      Location playerLocation = player.getLocation();
      Location fuckoffLocation = fuckoffPlayer.getLocation();

      double distanceSquared;
      try {
        distanceSquared = playerLocation.distanceSquared(fuckoffLocation);
      } catch (IllegalArgumentException ex) {
        continue;
      }

      if (distanceSquared < (fuckoffRange * fuckoffRange)) {
        event.setTo(
            fuckoffLocation
                .clone()
                .add(
                    playerLocation
                        .subtract(fuckoffLocation)
                        .toVector()
                        .normalize()
                        .multiply(fuckoffRange * 1.1)));
        break;
      }
    }

    // Freeze
    if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) {
      TFM_Util.setFlying(player, true);
      event.setTo(playerdata.getFreezeLocation());
    }

    if (playerdata.isCaged()) {
      Location targetPos = player.getLocation().add(0, 1, 0);

      boolean outOfCage;
      if (!targetPos.getWorld().equals(playerdata.getCagePos().getWorld())) {
        outOfCage = true;
      } else {
        outOfCage = targetPos.distanceSquared(playerdata.getCagePos()) > (2.5 * 2.5);
      }

      if (outOfCage) {
        playerdata.setCaged(
            true,
            targetPos,
            playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER),
            playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
        playerdata.regenerateHistory();
        playerdata.clearHistory();
        TFM_Util.buildHistory(targetPos, 2, playerdata);
        TFM_Util.generateHollowCube(
            targetPos, 2, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER));
        TFM_Util.generateCube(
            targetPos, 1, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
      }
    }

    if (playerdata.isOrbiting()) {
      if (player.getVelocity().length() < playerdata.orbitStrength() * (2.0 / 3.0)) {
        player.setVelocity(new Vector(0, playerdata.orbitStrength(), 0));
      }
    }

    if (TFM_Jumppads.getMode().isOn()) {
      TFM_Jumppads.PlayerMoveEvent(event);
    }

    if (!(TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean()
        && TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())) {
      return;
    }

    final Iterator<Command_landmine.TFM_LandmineData> landmines =
        Command_landmine.TFM_LandmineData.landmines.iterator();
    while (landmines.hasNext()) {
      final Command_landmine.TFM_LandmineData landmine = landmines.next();

      final Location location = landmine.location;
      if (location.getBlock().getType() != Material.TNT) {
        landmines.remove();
        continue;
      }

      if (landmine.player.equals(player)) {
        break;
      }

      if (!player.getWorld().equals(location.getWorld())) {
        continue;
      }

      if (!(player.getLocation().distanceSquared(location)
          <= (landmine.radius * landmine.radius))) {
        break;
      }

      landmine.location.getBlock().setType(Material.AIR);

      final TNTPrimed tnt1 = location.getWorld().spawn(location, TNTPrimed.class);
      tnt1.setFuseTicks(40);
      tnt1.setPassenger(player);
      tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));

      final TNTPrimed tnt2 = location.getWorld().spawn(player.getLocation(), TNTPrimed.class);
      tnt2.setFuseTicks(1);

      player.setGameMode(GameMode.SURVIVAL);
      landmines.remove();
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockPlace(BlockPlaceEvent event) {
    Player p = event.getPlayer();
    Location block_pos = event.getBlock().getLocation();

    if (TotalFreedomMod.nukeMonitor) {
      TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);

      Location player_pos = p.getLocation();

      boolean out_of_range = false;
      if (!player_pos.getWorld().equals(block_pos.getWorld())) {
        out_of_range = true;
      } else if (player_pos.distanceSquared(block_pos)
          > (TotalFreedomMod.nukeMonitorRange * TotalFreedomMod.nukeMonitorRange)) {
        out_of_range = true;
      }

      if (out_of_range) {
        playerdata.incrementFreecamPlaceCount();
        if (playerdata.getFreecamPlaceCount() > TotalFreedomMod.freecamTriggerCount) {
          TFM_Util.bcastMsg(
              p.getName() + " has been flagged for possible freecam building.", ChatColor.RED);
          TFM_Util.autoEject(
              p, "Freecam (extended range) block building is not permitted on this server.");

          playerdata.resetFreecamPlaceCount();

          event.setCancelled(true);
          return;
        }
      }

      playerdata.incrementBlockPlaceCount();
      if (playerdata.getBlockPlaceCount() > TotalFreedomMod.nukeMonitorCountPlace) {
        TFM_Util.bcastMsg(p.getName() + " is placing blocks too fast!", ChatColor.RED);
        TFM_Util.autoEject(p, "You are placing blocks too fast.");

        playerdata.resetBlockPlaceCount();

        event.setCancelled(true);
        return;
      }
    }

    if (TotalFreedomMod.protectedAreasEnabled) {
      if (!TFM_SuperadminList.isUserSuperadmin(p)) {
        if (TFM_ProtectedArea.isInProtectedArea(block_pos)) {
          event.setCancelled(true);
          return;
        }
      }
    }

    switch (event.getBlockPlaced().getType()) {
      case LAVA:
      case STATIONARY_LAVA:
        {
          if (TotalFreedomMod.allowLavaPlace) {
            TFM_Log.info(
                String.format(
                    "%s placed lava @ %s",
                    p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));

            p.getInventory().clear(p.getInventory().getHeldItemSlot());
          } else {
            p.getInventory()
                .setItem(p.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
            p.sendMessage(ChatColor.GRAY + "Lava placement is currently disabled.");

            event.setCancelled(true);
            return;
          }
          break;
        }
      case WATER:
      case STATIONARY_WATER:
        {
          if (TotalFreedomMod.allowWaterPlace) {
            TFM_Log.info(
                String.format(
                    "%s placed water @ %s",
                    p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));

            p.getInventory().clear(p.getInventory().getHeldItemSlot());
          } else {
            p.getInventory()
                .setItem(p.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
            p.sendMessage(ChatColor.GRAY + "Water placement is currently disabled.");

            event.setCancelled(true);
            return;
          }
          break;
        }
      case FIRE:
        {
          if (TotalFreedomMod.allowFirePlace) {
            TFM_Log.info(
                String.format(
                    "%s placed fire @ %s",
                    p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));

            p.getInventory().clear(p.getInventory().getHeldItemSlot());
          } else {
            p.getInventory()
                .setItem(p.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
            p.sendMessage(ChatColor.GRAY + "Fire placement is currently disabled.");

            event.setCancelled(true);
            return;
          }
          break;
        }
      case TNT:
        {
          if (TotalFreedomMod.allowExplosions) {
            TFM_Log.info(
                String.format(
                    "%s placed TNT @ %s",
                    p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));

            p.getInventory().clear(p.getInventory().getHeldItemSlot());
          } else {
            p.getInventory()
                .setItem(p.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));

            p.sendMessage(ChatColor.GRAY + "TNT is currently disabled.");
            event.setCancelled(true);
            return;
          }
          break;
        }
    }
  }