Ejemplo n.º 1
0
  public static boolean onCommand(
      PerkPlayer player, Command cmd, String commandLabel, PerkArgSet args) {

    if (cmd.getName().equalsIgnoreCase("tpr")
        || cmd.getName().equalsIgnoreCase("tphr")
        || cmd.getName().equalsIgnoreCase("tpd")
        || cmd.getName().equalsIgnoreCase("tpa")) {
      PerkPlayer toPlayer = null;

      if (args.size() == 1) {
        String playerName = args.getString(0);
        toPlayer = PerkUtils.getPlayer(PerkUtils.server().getPlayer(playerName));

        if (toPlayer == null || toPlayer.isVanished()) {
          PerkUtils.OutputToPlayer(player, playerName + " isn't online.");
          return true;
        }
      }

      if (cmd.getName().equalsIgnoreCase("tpr")) {

        if (args.size() != 1) {
          PerkUtils.OutputToPlayer(player, cmd.getUsage());
          return true;
        }

        if (!player.hasPermission("perks.teleport.tpr", true)) {
          return true;
        }

        toPlayer.sendTpRequest(player);

        return true;
      }

      if (cmd.getName().equalsIgnoreCase("tphr")) {

        if (args.size() != 1) {
          PerkUtils.OutputToPlayer(player, cmd.getUsage());
          return true;
        }

        if (!player.hasPermission("perks.teleport.tphr", true)) {
          return true;
        }

        toPlayer.sendTpHereRequest(player);

        return true;
      }

      // accepting and declining shouldn't have a permission as everyone needs to do it

      if (cmd.getName().equalsIgnoreCase("tpa")) {

        player.acceptTpRequest(toPlayer);

        return true;
      }

      if (cmd.getName().equalsIgnoreCase("tpd")) {

        player.declineTpRequest(toPlayer);

        return true;
      }
    }

    if (cmd.getName().equalsIgnoreCase("tp")) {

      if (!player.hasPermission("perks.teleport.tp", true)) return true;

      if (args.size() != 1) {
        PerkUtils.OutputToPlayer(player, cmd.getUsage());
        return true;
      }

      Location loc = null;

      // Handle coordinates
      if (args.getString(0).matches("^[\\-0-9\\.]+,[\\-0-9\\.]+,[\\-0-9\\.]+(?:.+)?$")) {

        String[] arg = args.getString(0).split(":");
        String[] parts = args.getString(0).split(",");
        double x = 0, y = 0, z = 0;

        try {
          x = Double.parseDouble(parts[0]);
          y = Double.parseDouble(parts[1]);
          z = Double.parseDouble(parts[2]);
        } catch (NumberFormatException e) {
          PerkUtils.OutputToPlayer(player, "");
        }

        if (arg.length > 1) {
          loc = new Location(PerkUtils.server().getWorld(arg[1]), x, y, z);
        } else {
          loc = new Location(player.getPlayer().getWorld(), x, y, z);
        }

        player.teleport(loc);

        PerkUtils.OutputToPlayer(player, "You have been teleported");

        return true;
      }

      PerkPlayer target = PerkUtils.getPlayer(args.getString(0));
      if (target == null) {
        PerkUtils.OutputToPlayer(player, "That player is not online");
        return true;
      }

      loc = target.getPlayer().getLocation();

      player.teleport(loc);

      PerkUtils.OutputToPlayer(player, "You have been teleported");

      return true;
    }

    if (cmd.getName().equalsIgnoreCase("tphere")
        || cmd.getName().equalsIgnoreCase("s")
        || cmd.getName().equalsIgnoreCase("bring")) {

      if (!player.hasPermission("perks.teleport.tphere", true)) return true;

      if (args.size() != 1) {
        PerkUtils.OutputToPlayer(player, cmd.getUsage());
        return true;
      }

      PerkPlayer target = PerkUtils.getPlayer(args.getString(0));

      if (target == null) {
        PerkUtils.OutputToPlayer(player, "That player is not online");
        return true;
      }

      player.teleportHere(target);

      PerkUtils.OutputToPlayer(
          player, target.getPlayer().getName() + " has been teleported to you.");

      return true;
    }

    if (cmd.getName().equalsIgnoreCase("put")) {

      if (!player.hasPermission("perks.teleport.put", true)) return true;

      if (args.size() != 1) {
        PerkUtils.OutputToPlayer(player, cmd.getUsage());
        return true;
      }

      PerkPlayer target = PerkUtils.getPlayer(args.getString(0));

      if (target == null) {
        PerkUtils.OutputToPlayer(player, "That player is not online");
        return true;
      }

      target.getPlayer().teleport(player.getPlayer().getTargetBlock(null, 300).getLocation());
      return true;
    }

    return false;
  }
Ejemplo n.º 2
0
  public static void loadDatabases() {

    // create an the database
    m_perksDB =
        bDatabaseManager.createDatabase(
            PerkConfig.DATABASE.name, PerkUtils.plugin, DatabaseType.SQL);

    if (!m_perksDB.login(
        PerkConfig.DATABASE.ip,
        PerkConfig.DATABASE.user,
        PerkConfig.DATABASE.password,
        PerkConfig.DATABASE.port)) return;

    // see if a table called properties exist
    if (!m_perksDB.tableExists("perks_homes")) {

      // the table doesn't exist, so make one.

      PerkUtils.DebugConsole("Could not find perk homes table, now creating one.");
      String query =
          "CREATE TABLE perks_homes ("
              + "player VARCHAR(64),"
              + "world VARCHAR(128),"
              + "x INT,"
              + "y INT,"
              + "z INT,"
              + "yaw INT,"
              + "pitch INT"
              + ");";

      // to create a table we pass an SQL query.
      m_perksDB.query(query, true);
    }

    // load all properties

    // select every property from the table
    String query = "SELECT * FROM perks_homes";
    ResultSet result = m_perksDB.queryResult(query);

    if (result != null) {
      try {
        // while we have another result, read in the data
        while (result.next()) {
          String worldName = result.getString("world");
          String playerName = result.getString("player");

          int x = result.getInt("x");
          int y = result.getInt("y");
          int z = result.getInt("z");
          int pitch = result.getInt("pitch");
          int yaw = result.getInt("yaw");

          World world = PerkUtils.plugin.getServer().getWorld(worldName);
          Location loc = new Location(world, x, y, z, yaw, pitch);

          tpLocation newHome = new tpLocation();
          newHome.playername = playerName;
          newHome.loc = loc;
          homes.add(newHome);
        }
      } catch (SQLException e) {
        e.printStackTrace();
        return;
      }

      m_perksDB.freeResult(result);
    }

    // see if a table called properties exist
    if (!m_perksDB.tableExists("perks_build")) {

      // the table doesn't exist, so make one.

      PerkUtils.DebugConsole("Could not find perk homes builds, now creating one.");
      query =
          "CREATE TABLE perks_build ("
              + "player VARCHAR(64),"
              + "world VARCHAR(128),"
              + "x INT,"
              + "y INT,"
              + "z INT,"
              + "yaw INT,"
              + "pitch INT"
              + ");";

      // to create a table we pass an SQL query.
      m_perksDB.query(query, true);
    }

    // select every property from the table
    query = "SELECT * FROM perks_build";
    result = m_perksDB.queryResult(query);

    if (result != null) {
      try {
        // while we have another result, read in the data
        while (result.next()) {
          String worldName = result.getString("world");
          String playerName = result.getString("player");

          int x = result.getInt("x");
          int y = result.getInt("y");
          int z = result.getInt("z");
          int pitch = result.getInt("pitch");
          int yaw = result.getInt("yaw");

          World world = PerkUtils.plugin.getServer().getWorld(worldName);
          Location loc = new Location(world, x, y, z, yaw, pitch);

          tpLocation newHome = new tpLocation();
          newHome.playername = playerName;
          newHome.loc = loc;
          builds.add(newHome);
        }
      } catch (SQLException e) {
        e.printStackTrace();
        return;
      }

      m_perksDB.freeResult(result);
    }

    // see if a table called properties exist
    if (!m_perksDB.tableExists("perks_vanish")) {

      // the table doesn't exist, so make one.

      PerkUtils.DebugConsole("Could not find perk vanish databse, now creating one.");
      query = "CREATE TABLE perks_vanish (" + "player VARCHAR(64)" + ");";

      // to create a table we pass an SQL query.
      m_perksDB.query(query, true);
    }

    // see if a table called properties exist
    if (!m_perksDB.tableExists("perks_kit")) {

      // the table doesn't exist, so make one.

      PerkUtils.DebugConsole("Could not find perk kit databse, now creating one.");
      query =
          "CREATE TABLE perks_kit ("
              + "player VARCHAR(64),"
              + "kitname VARCHAR(64),"
              + "time LONG"
              + ");";

      // to create a table we pass an SQL query.
      m_perksDB.query(query, true);
    }

    if (!m_perksDB.tableExists("perks_flying")) {

      PerkUtils.DebugConsole("Could not find flying table, creating one now");

      query = "CREATE TABLE perks_flying (name VARCHAR(64));";

      m_perksDB.query(query, true);
    }

    if (!m_perksDB.tableExists("perks_spawn")) {

      PerkUtils.DebugConsole("Could not find spawn table, creating one now");

      query =
          "CREATE TABLE perks_spawn ("
              + "world VARCHAR(64),"
              + "x INT,"
              + "y INT,"
              + "z INT,"
              + "yaw FLOAT,"
              + "pitch FLOAT"
              + ");";
      m_perksDB.query(query, true);
    }

    query = "SELECT * FROM perks_spawn";
    result = m_perksDB.queryResult(query);

    if (result != null) {
      try {
        while (result.next()) {
          World world = PerkUtils.server().getWorld(result.getString("world"));
          Location loc =
              new Location(
                  world,
                  result.getInt("x"),
                  result.getInt("y"),
                  result.getInt("z"),
                  result.getFloat("yaw"),
                  result.getFloat("pitch"));
          PerkWorldSpawn spawn = new PerkWorldSpawn(world, loc);
          spawns.add(spawn);
        }
        PerkUtils.DebugConsole("Loaded " + spawns.size() + " spawns");
      } catch (SQLException e) {
        e.printStackTrace();
      }

      m_perksDB.freeResult(result);
    }

    UpgradeDatabases();
  }