コード例 #1
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerTeleport(PlayerTeleportEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
    // Check absolute value to account for negatives
    if (Math.abs(event.getTo().getX()) >= MAX_XY_COORD
        || Math.abs(event.getTo().getZ()) >= MAX_XY_COORD) {
      event.setCancelled(true); // illegal position, cancel it
    }

    if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) {
      TFM_Util.setFlying(player, true);
      event.setTo(playerdata.getFreezeLocation());
      return; // Don't process adminworld validation
    }

    TFM_AdminWorld.getInstance().validateMovement(event);
  }
コード例 #2
0
  @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();
    }
  }
コード例 #3
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onPlayerTeleport(PlayerTeleportEvent event) {
   TFM_AdminWorld.getInstance().validateMovement(event);
 }
コード例 #4
0
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (!TFM_ConfigEntry.ENABLE_ADMINWORLD.getBoolean() && !TFM_Util.isHighRank(sender)) {
      TFM_Util.playerMsg(sender, "Admin World is currently disabled!", ChatColor.RED);
      return true;
    }

    CommandMode commandMode = null;

    if (args.length == 0) {
      commandMode = CommandMode.TELEPORT;
    } else if (args.length >= 2) {
      if ("guest".equalsIgnoreCase(args[0])) {
        commandMode = CommandMode.GUEST;
      } else if ("time".equalsIgnoreCase(args[0])) {
        commandMode = CommandMode.TIME;
      } else if ("weather".equalsIgnoreCase(args[0])) {
        commandMode = CommandMode.WEATHER;
      }
    }

    if (commandMode == null) {
      return false;
    }

    try {
      switch (commandMode) {
        case TELEPORT:
          {
            if (!(sender instanceof Player) || sender_p == null) {
              return true;
            }

            World adminWorld = null;
            try {
              adminWorld = TFM_AdminWorld.getInstance().getWorld();
            } catch (Exception ex) {
            }

            if (adminWorld == null || sender_p.getWorld() == adminWorld) {
              playerMsg("Going to the main world.");
              sender_p.teleport(server.getWorlds().get(0).getSpawnLocation());
            } else {
              if (TFM_AdminWorld.getInstance().canAccessWorld(sender_p)) {
                playerMsg("Going to the AdminWorld.");
                TFM_AdminWorld.getInstance().sendToWorld(sender_p);
              } else {
                playerMsg("You don't have permission to access the AdminWorld.");
              }
            }

            break;
          }
        case GUEST:
          {
            if (args.length == 2) {
              if ("list".equalsIgnoreCase(args[1])) {
                playerMsg(
                    "AdminWorld guest list: " + TFM_AdminWorld.getInstance().guestListToString());
              } else if ("purge".equalsIgnoreCase(args[1])) {
                assertCommandPerms(sender, sender_p);
                TFM_AdminWorld.getInstance().purgeGuestList();
                TFM_Util.adminAction(sender.getName(), "AdminWorld guest list purged.", false);
              } else {
                return false;
              }
            } else if (args.length == 3) {
              assertCommandPerms(sender, sender_p);

              if ("add".equalsIgnoreCase(args[1])) {
                final Player player = getPlayer(args[2]);

                if (player == null) {
                  sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
                  return true;
                }

                if (TFM_AdminWorld.getInstance().addGuest(player, sender_p)) {
                  TFM_Util.adminAction(
                      sender.getName(), "AdminWorld guest added: " + player.getName(), false);
                } else {
                  playerMsg("Could not add player to guest list.");
                }
              } else if ("remove".equals(args[1])) {
                final Player player = TFM_AdminWorld.getInstance().removeGuest(args[2]);
                if (player != null) {
                  TFM_Util.adminAction(
                      sender.getName(), "AdminWorld guest removed: " + player.getName(), false);
                } else {
                  playerMsg("Can't find guest entry for: " + args[2]);
                }
              } else {
                return false;
              }
            }

            break;
          }
        case TIME:
          {
            assertCommandPerms(sender, sender_p);

            if (args.length == 2) {
              TFM_AdminWorld.TimeOfDay timeOfDay = TFM_AdminWorld.TimeOfDay.getByAlias(args[1]);
              if (timeOfDay != null) {
                TFM_AdminWorld.getInstance().setTimeOfDay(timeOfDay);
                playerMsg("AdminWorld time set to: " + timeOfDay.name());
              } else {
                playerMsg("Invalid time of day. Can be: sunrise, noon, sunset, midnight");
              }
            } else {
              return false;
            }

            break;
          }
        case WEATHER:
          {
            assertCommandPerms(sender, sender_p);

            if (args.length == 2) {
              TFM_AdminWorld.WeatherMode weatherMode =
                  TFM_AdminWorld.WeatherMode.getByAlias(args[1]);
              if (weatherMode != null) {
                TFM_AdminWorld.getInstance().setWeatherMode(weatherMode);
                playerMsg("AdminWorld weather set to: " + weatherMode.name());
              } else {
                playerMsg("Invalid weather mode. Can be: off, rain, storm");
              }
            } else {
              return false;
            }

            break;
          }
        default:
          {
            return false;
          }
      }
    } catch (PermissionDeniedException ex) {
      sender.sendMessage(ex.getMessage());
    }

    return true;
  }