Esempio n. 1
0
  @Override
  public List<String> getTreeString(int depth) {
    List<String> out = new ArrayList<String>();
    out.add(getTreeDepth(depth) + "Universe (" + getName() + ")");
    if (plugin != null) {
      out.add(getTreeDepth(depth + 1) + "Server (" + plugin.getServer().getName() + ")");
      out.add(getTreeDepth(depth + 2) + "Version: " + plugin.getServer().getVersion());
      out.add(
          getTreeDepth(depth + 2)
              + "Players: "
              + plugin.getServer().getOnlinePlayers().length
              + "/"
              + plugin.getServer().getMaxPlayers());
      out.add(
          getTreeDepth(depth + 2)
              + "Worlds ("
              + plugin.getServer().getWorlds().size()
              + "): "
              + Arrays.toString(plugin.getServer().getWorlds().toArray(new World[0])));
    }
    out.add(getTreeDepth(depth + 1) + "Worlds (" + getDataSource().getWorlds().size() + "):");
    for (TownyWorld world : getDataSource().getWorlds()) out.addAll(world.getTreeString(depth + 2));

    out.add(getTreeDepth(depth + 1) + "Nations (" + getDataSource().getNations().size() + "):");
    for (Nation nation : getDataSource().getNations()) out.addAll(nation.getTreeString(depth + 2));

    Collection<Town> townsWithoutNation = getDataSource().getTownsWithoutNation();
    out.add(getTreeDepth(depth + 1) + "Towns (" + townsWithoutNation.size() + "):");
    for (Town town : townsWithoutNation) out.addAll(town.getTreeString(depth + 2));

    Collection<Resident> residentsWithoutTown = getDataSource().getResidentsWithoutTown();
    out.add(getTreeDepth(depth + 1) + "Residents (" + residentsWithoutTown.size() + "):");
    for (Resident resident : residentsWithoutTown) out.addAll(resident.getTreeString(depth + 2));
    return out;
  }
Esempio n. 2
0
 public Location getTownSpawnLocation(Player player) throws TownyException {
   try {
     Resident resident = getDataSource().getResident(player.getName());
     Town town = resident.getTown();
     return town.getSpawn();
   } catch (TownyException x) {
     throw new TownyException("Unable to get spawn location");
   }
 }
Esempio n. 3
0
 public void onLogout(Player player) {
   try {
     Resident resident = getDataSource().getResident(player.getName());
     resident.setLastOnline(System.currentTimeMillis());
     getDataSource().saveResident(resident);
   } catch (NotRegisteredException e) {
   }
   setChangedNotify(PLAYER_LOGOUT);
 }
Esempio n. 4
0
  public List<Resident> getOnlineResidents(ResidentList residentList) {
    List<Resident> onlineResidents = new ArrayList<Resident>();
    for (Player player : plugin.getServer().getOnlinePlayers()) {
      for (Resident resident : residentList.getResidents()) {
        if (resident.getName().equalsIgnoreCase(player.getName())) onlineResidents.add(resident);
      }
    }

    return onlineResidents;
  }
Esempio n. 5
0
  public void onLogin(Player player) throws AlreadyRegisteredException, NotRegisteredException {

    if (!player.isOnline()) return;

    // Test and kick any players with invalid names.
    if ((player.getName().trim() == null) || (player.getName().contains(" "))) {
      player.kickPlayer("Invalid name!");
      return;
    }

    Resident resident;

    if (!getDataSource().hasResident(player.getName())) {
      getDataSource().newResident(player.getName());
      resident = getDataSource().getResident(player.getName());

      TownyMessaging.sendMessage(player, TownySettings.getRegistrationMsg(player.getName()));
      resident.setRegistered(System.currentTimeMillis());
      if (!TownySettings.getDefaultTownName().equals(""))
        try {
          Town town = getDataSource().getTown(TownySettings.getDefaultTownName());
          town.addResident(resident);
          getDataSource().saveTown(town);
        } catch (NotRegisteredException e) {
        } catch (AlreadyRegisteredException e) {
        }

      getDataSource().saveResident(resident);
      getDataSource().saveResidentList();

    } else {
      resident = getDataSource().getResident(player.getName());
      resident.setLastOnline(System.currentTimeMillis());

      getDataSource().saveResident(resident);
    }

    try {
      TownyMessaging.sendTownBoard(player, resident.getTown());
    } catch (NotRegisteredException e) {
    }

    if (isWarTime()) getWarEvent().sendScores(player, 3);

    // Schedule to setup default modes when the player has finished loading
    if (getPlugin()
            .getServer()
            .getScheduler()
            .scheduleSyncDelayedTask(getPlugin(), new SetDefaultModes(this, player, false), 1)
        == -1)
      TownyMessaging.sendErrorMsg("Could not set default modes for " + player.getName() + ".");

    setChangedNotify(PLAYER_LOGIN);
  }
Esempio n. 6
0
 public boolean isEnemy(String a, String b) {
   try {
     Resident residentA = getDataSource().getResident(a);
     Resident residentB = getDataSource().getResident(b);
     if (residentA.getTown() == residentB.getTown()) return false;
     if (residentA.getTown().getNation() == residentB.getTown().getNation()) return false;
     if (residentA.getTown().getNation().hasEnemy(residentB.getTown().getNation())) return true;
   } catch (NotRegisteredException e) {
     return false;
   }
   return false;
 }
Esempio n. 7
0
 public boolean canAttackEnemy(String a, String b) {
   try {
     Resident residentA = getDataSource().getResident(a);
     Resident residentB = getDataSource().getResident(b);
     if (residentA.getTown() == residentB.getTown()) return false;
     if (residentA.getTown().getNation() == residentB.getTown().getNation()) return false;
     Nation nationA = residentA.getTown().getNation();
     Nation nationB = residentB.getTown().getNation();
     if (nationA.isNeutral() || nationB.isNeutral()) return false;
     if (nationA.hasEnemy(nationB)) return true;
   } catch (NotRegisteredException e) {
     return false;
   }
   return false;
 }
Esempio n. 8
0
 public boolean isActiveResident(Resident resident) {
   return ((System.currentTimeMillis() - resident.getLastOnline()
           < (20 * TownySettings.getInactiveAfter()))
       || (plugin.isOnline(resident.getName())));
 }
Esempio n. 9
0
 public static Player getPlayer(Resident resident) throws TownyException {
   for (Player player : getOnlinePlayers())
     if (player.getName().equals(resident.getName())) return player;
   throw new TownyException(String.format("%s is not online", resident.getName()));
 }