Esempio n. 1
0
  public static void loadPlayer(ProxiedPlayer player) {
    if (playerExists(player, FeatureDetector.canUseUUID())) {
      boolean tps;

      if (FeatureDetector.canUseUUID()) {
        tps = DatabaseManager.players.getPlayerTPS(player.getUUID());
      } else {
        tps = DatabaseManager.players.getPlayerTPS(player.getName());
      }

      GSPlayer gsPlayer =
          new GSPlayer(
              player.getName(),
              (FeatureDetector.canUseUUID()) ? player.getUUID() : null,
              tps,
              player.getAddress().getHostString());
      onlinePlayers.put(player.getName(), gsPlayer);

      DatabaseManager.players.updatePlayer(gsPlayer);

      LoggingManager.log(
          ConfigManager.messages.PLAYER_LOAD.replace("{player}", gsPlayer.getName()));

      HomesManager.loadPlayersHomes(gsPlayer);
    } else {
      createNewPlayer(player);
    }
  }
Esempio n. 2
0
  @Override
  public void checkUpdate() {
    // What current Version of the Database is this ?
    int installedVersion = ConfigManager.main.Version_Database_Ban;

    System.out.println("Current Version of the Ban Database: " + installedVersion);

    if (installedVersion < 2) {
      // Version 2 adds UUIDs as Field
      if (FeatureDetector.canUseUUID()) {
        ConnectionHandler connectionHandler = DatabaseManager.connectionPool.getConnection();

        // Convert all Names to UUIDs
        PreparedStatement getBans = connectionHandler.getPreparedStatement("getBans");
        try {
          ResultSet res = getBans.executeQuery();
          while (res.next()) {
            String bannedEntity = res.getString("banned_entity");

            if (!Utilities.isIPAddress(bannedEntity)) {
              String uuid = Utilities.getUUID(bannedEntity);

              if (uuid != null) {
                ConnectionHandler connectionHandler1 =
                    DatabaseManager.connectionPool.getConnection();

                try {
                  PreparedStatement updateToUUID =
                      connectionHandler1.getPreparedStatement("updateToUUID");
                  updateToUUID.setString(1, uuid);
                  updateToUUID.setInt(2, res.getInt("id"));
                  updateToUUID.executeUpdate();
                } catch (SQLException e) {
                  System.out.println("Could not update Ban for update to version 2");
                  e.printStackTrace();
                } finally {
                  connectionHandler1.release();
                }
              }
            }
          }
        } catch (SQLException e) {
          System.out.println("Could not get Bans for update to version 2");
          e.printStackTrace();
          return;
        } finally {
          connectionHandler.release();
        }
      }
    }

    ConfigManager.main.Version_Database_Ban = 2;
    try {
      ConfigManager.main.save();
    } catch (InvalidConfigurationException e) {
      e.printStackTrace();
    }
  }
Esempio n. 3
0
  private static void createNewPlayer(final ProxiedPlayer player) {
    String ip = player.getAddress().getAddress().toString();
    final GSPlayer gsPlayer =
        new GSPlayer(
            player.getName(), (FeatureDetector.canUseUUID()) ? player.getUUID() : null, true);

    DatabaseManager.players.insertPlayer(gsPlayer, ip.substring(1, ip.length()));

    if (ConfigManager.main.NewPlayerBroadcast) {
      String welcomeMsg = null;
      sendBroadcast(
          welcomeMsg =
              ConfigManager.messages.NEW_PLAYER_BROADCAST.replace("{player}", player.getName()));
      // Firing custom event
      ProxyServer.getInstance()
          .getPluginManager()
          .callEvent(new NewPlayerJoinEvent(player.getName(), welcomeMsg));
    }

    onlinePlayers.put(player.getName(), gsPlayer);
    LoggingManager.log(ConfigManager.messages.PLAYER_LOAD.replace("{player}", gsPlayer.getName()));

    if (ConfigManager.spawn.SpawnNewPlayerAtNewspawn && SpawnManager.NewPlayerSpawn != null) {
      SpawnManager.newPlayers.add(player);

      ProxyServer.getInstance()
          .getScheduler()
          .schedule(
              geSuit.instance,
              new Runnable() {

                @Override
                public void run() {
                  SpawnManager.sendPlayerToNewPlayerSpawn(gsPlayer);
                  SpawnManager.newPlayers.remove(player);
                }
              },
              300,
              TimeUnit.MILLISECONDS);
    }
  }