Пример #1
0
  public static void checkObjects() {
    Collection<String> guilds = BasicUtils.getNames(GuildUtils.getGuilds());
    Collection<String> regions = BasicUtils.getNames(RegionUtils.getRegions());
    int i = 0;
    for (Guild guild : GuildUtils.getGuilds()) {
      if (guild.getName() != null && regions.contains(guild.getName())) {
        guilds.remove(guild.getName());
        continue;
      }
      GuildUtils.deleteGuild(guild);
      i++;
    }

    guilds = BasicUtils.getNames(GuildUtils.getGuilds());
    regions = BasicUtils.getNames(RegionUtils.getRegions());

    for (Region region : RegionUtils.getRegions()) {
      if (region.getName() != null && guilds.contains(region.getName())) {
        regions.remove(region.getName());
        continue;
      }
      RegionUtils.delete(region);
      i++;
    }
    if (i > 0) FunnyGuilds.warning("Repaired conflicts: " + i);
  }
 protected void removeGuild(Guild guild) {
   if (guild == null || guild.getTag() == null || guild.getTag().isEmpty()) return;
   Team team = getUser().getScoreboard().getTeam(guild.getTag());
   if (team != null) team.unregister();
 }
 private void initialize() {
   if (getUser() == null) return;
   List<Guild> guilds = GuildUtils.getGuilds();
   Scoreboard scoreboard = getUser().getScoreboard();
   Guild guild = getUser().getGuild();
   if (guild != null) {
     guilds.remove(guild);
     Settings config = Settings.getInstance();
     String our = config.prefixOur;
     String ally = config.prefixAllies;
     String enemy = config.prefixEnemies;
     String other = config.prefixOther;
     Team team = scoreboard.getTeam(guild.getTag());
     if (team == null) team = scoreboard.registerNewTeam(guild.getTag());
     for (User u : guild.getMembers()) {
       if (u.getName() == null) continue;
       OfflineUser player = new OfflineUser(u.getName());
       if (!team.hasPlayer(player)) team.addPlayer(player);
     }
     team.setPrefix(replace(our, "{TAG}", guild.getTag()));
     for (Guild one : guilds) {
       if (one == null || one.getTag() == null) continue;
       team = scoreboard.getTeam(one.getTag());
       if (team == null) team = scoreboard.registerNewTeam(one.getTag());
       for (User u : one.getMembers()) {
         if (u.getName() == null) continue;
         OfflineUser player = new OfflineUser(u.getName());
         if (!team.hasPlayer(player)) team.addPlayer(player);
       }
       if (guild.getAllies().contains(one)) team.setPrefix(replace(ally, "{TAG}", one.getTag()));
       else if (guild.getEnemies().contains(one))
         team.setPrefix(replace(enemy, "{TAG}", one.getTag()));
       else team.setPrefix(replace(other, "{TAG}", one.getTag()));
     }
   } else {
     String other = Settings.getInstance().prefixOther;
     for (Guild one : guilds) {
       if (one == null || one.getTag() == null) continue;
       Team team = scoreboard.getTeam(one.getTag());
       if (team == null) team = scoreboard.registerNewTeam(one.getTag());
       for (User u : one.getMembers()) {
         if (u.getName() == null) continue;
         OfflineUser player = new OfflineUser(u.getName());
         if (!team.hasPlayer(player)) team.addPlayer(player);
       }
       team.setPrefix(replace(other, "{TAG}", one.getTag()));
     }
   }
 }
 public void addGuild(Guild to) {
   if (to == null) return;
   Scoreboard scoreboard = getUser().getScoreboard();
   Guild guild = getUser().getGuild();
   if (guild != null) {
     if (guild.equals(to)) {
       initialize();
       return;
     }
     Team team = scoreboard.getTeam(to.getTag());
     if (team == null) team = scoreboard.registerNewTeam(to.getTag());
     for (User u : to.getMembers()) {
       OfflineUser player = new OfflineUser(u.getName());
       if (!team.hasPlayer(player)) team.addPlayer(player);
     }
     String prefix = Settings.getInstance().prefixOther;
     if (guild.getAllies().contains(to)) prefix = Settings.getInstance().prefixAllies;
     if (guild.getEnemies().contains(to)) prefix = Settings.getInstance().prefixEnemies;
     prefix = prefix.replace("{TAG}", to.getTag());
     if (prefix.length() > 16) prefix = prefix.substring(0, 16);
     team.setPrefix(prefix);
   } else {
     Team team = scoreboard.getTeam(to.getTag());
     if (team == null) team = scoreboard.registerNewTeam(to.getTag());
     for (User u : to.getMembers()) {
       OfflineUser player = new OfflineUser(u.getName());
       if (!team.hasPlayer(player)) team.addPlayer(player);
     }
     team.setPrefix(replace(Settings.getInstance().prefixOther, "{TAG}", to.getTag()));
   }
 }