Пример #1
0
  // set targetLoc only if not current player location; set returnLocationOnly to true to have new
  // Location returned if they need to be moved to one, instead of directly handling it
  public static Location checkPlayer(
      Player player, Location targetLoc, boolean returnLocationOnly) {
    if (player == null || !player.isOnline()) return null;

    Location loc = (targetLoc == null) ? player.getLocation() : targetLoc;
    if (loc == null) return null;

    World world = loc.getWorld();
    if (world == null) return null;
    BorderData border = Config.Border(world.getName());
    if (border == null) return null;

    if (border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound())) return null;

    if (player.hasPermission("worldborder.ignoreborder")) return null;

    Location newLoc = newLocation(player, loc, border);

    if (Config
        .whooshEffect()) { // give some particle and sound effects where the player was beyond the
      // border
      world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
      world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.SMOKE, 4);
      world.playEffect(loc, Effect.GHAST_SHOOT, 0);
    }

    if (returnLocationOnly) return newLoc;

    if (!player.isInsideVehicle()) player.teleport(newLoc);
    else {
      Vehicle ride = (Vehicle) player.getVehicle();
      if (ride != null) { // vehicles need to be offset vertically and have velocity stopped
        double vertOffset = ride.getLocation().getY() - loc.getY();
        newLoc.setY(newLoc.getY() + vertOffset);
        ride.setVelocity(new Vector(0, 0, 0));
        ride.teleport(newLoc);
      } else { // if player.getVehicle() returns null (when riding a pig on older Bukkit releases,
        // for instance), player has to be ejected
        player.leaveVehicle();
        player.teleport(newLoc);
      }
    }

    return null;
  }
Пример #2
0
  /**
   * Called on vehicle movement.
   *
   * @param event Relevant event details
   */
  @EventHandler
  public void onVehicleMove(VehicleMoveEvent event) {
    Vehicle vehicle = event.getVehicle();
    if (vehicle.getPassenger() == null || !(vehicle.getPassenger() instanceof Player)) return;
    Player player = (Player) vehicle.getPassenger();

    if (event.getFrom().getBlockX() != event.getTo().getBlockX()
        || event.getFrom().getBlockY() != event.getTo().getBlockY()
        || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {

      if (sessions.getAdminSession(player).isFrozen()) {

        player.sendMessage(ChatColor.RED + "You are frozen.");

        vehicle.setVelocity(new org.bukkit.util.Vector(0, 0, 0));
        vehicle.teleport(event.getFrom());
      }
    }
  }