Esempio n. 1
0
  /**
   * Called on player teleport.
   *
   * @param event Relevant event details
   */
  @EventHandler
  public void onPlayerTeleport(PlayerTeleportEvent event) {
    Player player = event.getPlayer();

    if (event.getCause() == PlayerTeleportEvent.TeleportCause.UNKNOWN) {
      return; // Must check to see if the event is UNKNOWN as the Vehicle Move & Player Move events
              // both use unknown teleport causes.
    }

    if (sessions.getAdminSession(player).isFrozen()) {
      player.sendMessage(ChatColor.RED + "You are frozen.");
      event.setCancelled(true);
    }
  }
Esempio n. 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());
      }
    }
  }
Esempio n. 3
0
  /**
   * Called on player movement.
   *
   * @param event Relevant event details
   */
  @EventHandler
  public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();

    if (player.getVehicle() != null) return; // handled in vehicle listener
    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.");

        Location newLoc = event.getFrom();
        newLoc.setX(newLoc.getBlockX() + 0.5);
        newLoc.setY(newLoc.getBlockY());
        newLoc.setZ(newLoc.getBlockZ() + 0.5);
        event.setTo(newLoc);
      }
    }
  }