Пример #1
0
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length == 0) {
      return false;
    }

    if (TFM_Util.isStopCommand(args[0]) && sender instanceof Player) {
      TFM_Util.adminAction(sender.getName(), "Uncaging " + sender.getName(), true);
      TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p);

      playerdata.setCaged(false);
      playerdata.regenerateHistory();
      playerdata.clearHistory();

      return true;
    } else if ("purge".equalsIgnoreCase(args[0])) {
      TFM_Util.adminAction(sender.getName(), "Uncaging all players.", true);

      for (Player player : server.getOnlinePlayers()) {
        TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
        playerdata.setCaged(false);
        playerdata.regenerateHistory();
        playerdata.clearHistory();
      }

      return true;
    }

    Player player;
    try {
      player = getPlayer(args[0]);
    } catch (PlayerNotFoundException ex) {
      sender.sendMessage(ex.getMessage());
      return true;
    }

    TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    Material outerMaterial = Material.GLASS;
    Material innerMaterial = Material.AIR;

    if (args.length >= 2) {
      if (TFM_Util.isStopCommand(args[1])) {
        TFM_Util.adminAction(sender.getName(), "Uncaging " + player.getName(), true);

        playerdata.setCaged(false);
        playerdata.regenerateHistory();
        playerdata.clearHistory();

        return true;
      } else {
        if ("bloop".equalsIgnoreCase(args[1])) {
          outerMaterial = Material.SKULL;
        } else if (Material.matchMaterial(args[1]) != null) {
          outerMaterial = Material.matchMaterial(args[1]);
        }
      }
    }

    if (args.length >= 3) {
      if (args[2].equalsIgnoreCase("water")) {
        innerMaterial = Material.STATIONARY_WATER;
      } else if (args[2].equalsIgnoreCase("lava")) {
        innerMaterial = Material.STATIONARY_LAVA;
      }
    }

    Location targetPos = player.getLocation().clone().add(0, 1, 0);
    playerdata.setCaged(true, targetPos, outerMaterial, innerMaterial);
    playerdata.regenerateHistory();
    playerdata.clearHistory();
    TFM_Util.buildHistory(targetPos, 2, playerdata);
    TFM_Util.generateHollowCube(targetPos, 2, outerMaterial);
    TFM_Util.generateCube(targetPos, 1, innerMaterial);

    player.setGameMode(GameMode.SURVIVAL);

    if (outerMaterial != Material.SKULL) {
      TFM_Util.adminAction(sender.getName(), "Caging " + player.getName(), true);
    } else {
      TFM_Util.adminAction(
          sender.getName(), "Caging " + player.getName() + " in PURE_BLOOPEH", true);
    }

    return true;
  }
  @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.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();
            }
          }
        }
      }
    }
  }