Esempio n. 1
0
  public static void loadPlayersHomes(GSPlayer player) {
    List<Home> homes = DatabaseManager.homes.getHomesForPlayer(player);

    for (Home home : homes) {
      if (home.loc.getServer() == null) {
        geSuit
            .instance
            .getLogger()
            .warning(
                "Invalid server for home \""
                    + home.name
                    + "\" of player "
                    + player.getName()
                    + "!");
        continue;
      }

      if (player.getHomes().get(home.loc.getServer().getName()) == null) {
        ArrayList<Home> list = new ArrayList<>();
        list.add(home);
        player.getHomes().put(home.loc.getServer().getName(), list);
      } else {
        player.getHomes().get(home.loc.getServer().getName()).add(home);
      }
    }
  }
 private static CommandSender getSender(String sender) {
   if (sender != null) {
     GSPlayer p = PlayerManager.getPlayer(sender);
     return (p == null ? ProxyServer.getInstance().getConsole() : p.getProxiedPlayer());
   }
   return null;
 }
Esempio n. 3
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. 4
0
  private static int getPlayersServerHomeCount(GSPlayer player) {
    ArrayList<Home> list = player.getHomes().get(player.getServer());

    if (list == null) {
      return 0;
    } else {
      return list.size();
    }
  }
Esempio n. 5
0
  public static void listOtherPlayersHomes(GSPlayer sender, String playername) {
    GSPlayer player = DatabaseManager.players.loadPlayer(playername);

    if (player == null) {
      PlayerManager.sendMessageToTarget(
          sender, ConfigManager.messages.PLAYER_DOES_NOT_EXIST.replace("{player}", playername));
      return;
    }

    loadPlayersHomes(player);

    if (player.getHomes().isEmpty()) {
      PlayerManager.sendMessageToTarget(
          sender, ConfigManager.messages.NO_OTHER_HOMES.replace("{player}", player.getName()));
      return;
    }

    int currcount = 0;
    PlayerManager.sendMessageToTarget(
        sender, ConfigManager.messages.SHOWING_OTHER_HOMES.replace("{player}", player.getName()));
    for (String server : player.getHomes().keySet()) {
      // Skip if the home list for this server is empty (shouldn't happen)
      if (player.getHomes().get(server).isEmpty()) {
        continue;
      }

      String homes;
      if (server.equals(sender.getServer())) {
        homes = ConfigManager.messages.HOMES_PREFIX_THIS_SERVER.replace("{server}", server);
      } else {
        homes = ConfigManager.messages.HOMES_PREFIX_OTHER_SERVER.replace("{server}", server);
      }

      for (Home h : player.getHomes().get(server)) {
        homes += h.name + ", ";
        currcount++;
      }

      // V: Was handled earlier, but in case getHomes().isEmpty() didn't work - which it didn't when
      // I tested..
      if (currcount == 0) {
        PlayerManager.sendMessageToTarget(
            sender, ConfigManager.messages.NO_OTHER_HOMES.replace("{player}", player.getName()));
        return;
      }

      PlayerManager.sendMessageToTarget(sender, homes.substring(0, homes.length() - 2));
    }

    String showCount =
        ConfigManager.messages.MAXIMUM_HOMES_OTHER.replace("{player}", player.getName());
    showCount += " " + currcount + " " + ConfigManager.messages.HOMES_SET;
    PlayerManager.sendMessageToTarget(sender, showCount);
  }
Esempio n. 6
0
  public static List<GSPlayer> getPlayersByIP(String ip) {
    List<GSPlayer> matchingPlayers = new ArrayList<GSPlayer>();
    if (ip == null) {
      Exception exception = new Exception("test");
      exception.printStackTrace();
      geSuit.instance.getLogger().severe("getPlayersByIP() ip is null");
      return null;
    }

    for (GSPlayer p : onlinePlayers.values()) {
      if (p.getProxiedPlayer().getAddress().getHostString().equalsIgnoreCase(ip)) {
        matchingPlayers.add(p);
      }
    }

    return matchingPlayers;
  }
Esempio n. 7
0
  private static int getPlayersGlobalHomeCount(GSPlayer player) {
    int count = 0;

    for (ArrayList<Home> list : player.getHomes().values()) {
      count += list.size();
    }

    return count;
  }
Esempio n. 8
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);
    }
  }
Esempio n. 9
0
  public static Home getHome(GSPlayer player, String home) {
    HashMap<String, Home> found = new HashMap<>();

    for (ArrayList<Home> list : player.getHomes().values()) {
      for (Home h : list) {
        if (h.name.toLowerCase().equals(home.toLowerCase())) {
          found.put(h.loc.getServer().getName(), h);
        }
      }
    }

    if (found.size() == 0) {
      return null;
    } else {
      if (found.containsKey(player.getServer())) {
        return found.get(player.getServer());
      }

      return found.values().iterator().next();
    }
  }
Esempio n. 10
0
  public static void deleteHome(String player, String home) {
    GSPlayer p = PlayerManager.getPlayer(player);
    Home h = getHome(p, home);

    if (h == null) {
      PlayerManager.sendMessageToTarget(
          p, ConfigManager.messages.HOME_DOES_NOT_EXIST.replace("{home}", home));
      return;
    }

    for (ArrayList<Home> list : p.getHomes().values()) {
      if (list.contains(h)) {
        list.remove(h);
        break;
      }
    }

    DatabaseManager.homes.deleteHome(h);

    PlayerManager.sendMessageToTarget(
        p, ConfigManager.messages.HOME_DELETED.replace("{home}", home));
  }
Esempio n. 11
0
  public static GSPlayer getSimilarPlayer(String player) {
    for (GSPlayer p : onlinePlayers.values()) {
      if ((p.getProxiedPlayer() != null
              && p.getProxiedPlayer().getDisplayName() != null
              && p.getProxiedPlayer()
                  .getDisplayName()
                  .toLowerCase()
                  .startsWith(player.toLowerCase()))
          || p.getName().toLowerCase().startsWith(player.toLowerCase())
          || (p.getUuid() != null && p.getUuid().equals(player))) {
        return p;
      }
    }

    return null;
  }
Esempio n. 12
0
  public static void listPlayersHomes(GSPlayer player, int maxhomes) {
    if (player.getHomes().isEmpty()) {
      PlayerManager.sendMessageToTarget(player, ConfigManager.messages.NO_HOMES);
      return;
    }

    PlayerManager.sendMessageToTarget(
        player, ConfigManager.messages.SHOWING_YOUR_HOMES.replace("{player}", player.getName()));
    int currcount = 0;
    for (String server : player.getHomes().keySet()) {
      // Skip if the home list for this server is empty (shouldn't happen)
      if (player.getHomes().get(server).isEmpty()) {
        continue;
      }

      String homes;
      if (server.equals(player.getServer())) {
        homes = ConfigManager.messages.HOMES_PREFIX_THIS_SERVER.replace("{server}", server);
      } else {
        homes = ConfigManager.messages.HOMES_PREFIX_OTHER_SERVER.replace("{server}", server);
      }

      for (Home h : player.getHomes().get(server)) {
        homes += h.name + ", ";
        currcount++;
      }

      // V: Was handled earlier, but in case getHomes().isEmpty() didn't work - which it didn't when
      // I tested..
      if (currcount == 0) {
        PlayerManager.sendMessageToTarget(player, ConfigManager.messages.NO_HOMES);
        return;
      }

      PlayerManager.sendMessageToTarget(player, homes.substring(0, homes.length() - 2));
    }

    // V: Added showing global current/max homes to player
    String showmax = ConfigManager.messages.MAXIMUM_HOMES;
    showmax +=
        " " + (currcount) + " " + ConfigManager.messages.MAXIMUM_HOMES_OF + " " + (maxhomes) + " ";
    showmax += ConfigManager.messages.MAXIMUM_HOMES2;
    PlayerManager.sendMessageToTarget(player, showmax);
  }
Esempio n. 13
0
 public static String getLastSeeninfos(String player) {
   SimpleDateFormat sdf = new SimpleDateFormat();
   sdf.applyPattern("dd MMM yyyy HH:mm");
   GSPlayer p = getPlayer(player);
   if (p == null) { // Offline
     p = DatabaseManager.players.loadPlayer(player);
     if (p == null) // Unknown player
     {
       return ConfigManager.messages.PLAYER_DOES_NOT_EXIST;
     } else {
       return ConfigManager.messages
           .PLAYER_SEEN_OFFLINE
           .replace("{player}", p.getName())
           .replace("{ip}", p.getIp())
           .replace("{seen}", sdf.format(p.getLastOnline()));
     }
   } else { // Online
     return ConfigManager.messages
         .PLAYER_SEEN_ONLINE
         .replace("{player}", p.getName())
         .replace("{ip}", p.getIp())
         .replace("{server}", p.getServer());
   }
 }
Esempio n. 14
0
  public static void createNewHome(
      GSPlayer player, int serverLimit, int globalLimit, String home, Location loc) {
    if (getHome(player, home) == null) {
      int globalHomeCount = getPlayersGlobalHomeCount(player);
      int serverHomeCount = getPlayersServerHomeCount(player);

      if (globalHomeCount >= globalLimit) {
        PlayerManager.sendMessageToTarget(player, ConfigManager.messages.NO_HOMES_ALLOWED_GLOBAL);
        return;
      }

      if (serverHomeCount >= serverLimit) {
        PlayerManager.sendMessageToTarget(player, ConfigManager.messages.NO_HOMES_ALLOWED_SERVER);
        return;
      }

      if (player.getHomes().get(player.getServer()) == null) {
        player.getHomes().put(player.getServer(), new ArrayList<Home>());
      }

      Home homeObject = new Home(player, home, loc);
      player.getHomes().get(player.getServer()).add(homeObject);
      DatabaseManager.homes.addHome(homeObject);

      PlayerManager.sendMessageToTarget(
          player, ConfigManager.messages.HOME_SET.replace("{home}", home));
    } else {
      Home home1 = getHome(player, home);
      if (home1.loc.getServer().getName().equals(loc.getServer().getName())) {
        home1.setLoc(loc);
        DatabaseManager.homes.updateHome(home1);
        PlayerManager.sendMessageToTarget(
            player, ConfigManager.messages.HOME_UPDATED.replace("{home}", home));
      } else {
        PlayerManager.sendMessageToTarget(
            player, ConfigManager.messages.HOME_EXISTS_OTHER_SERVER.replace("{home}", home));
      }
    }
  }
Esempio n. 15
0
 public static void sendMessageToTarget(GSPlayer target, String message) {
   sendMessageToTarget(target.getProxiedPlayer(), message);
 }