@Override
public void doBusiness() throws Exception {
//If it is a pvp world, make sure that the two teams have equal number of players.
World pvpWorld = client.getServer().getActivePvPWorld(worldName);
if (pvpWorld != null) {//The world is a pvp world.
PvPWorldMap map = client.getServer().getPvPWorldMap(pvpWorld.getID());
System.out.println("Original PvP Map:");
map.printObject();
if (map != null) {
int team0PlayerNum = map.getTeam0().size();
int team1PlayerNum = map.getTeam1().size();
if (team0PlayerNum > team1PlayerNum) {
int diff = team0PlayerNum - team1PlayerNum;
for (int i = 0; i < diff; i++) {
int playerPosition = map.removeLastOnePlayerFromTeamN(0);
//Remove the environment in row: 0, position: playerPosition of the current world.
Environment removedEnv = client.getServer().removeAnEnvFromWorld(pvpWorld.getID(), Constants.GAME_TYPE_PVP, 0, playerPosition);
EnvironmentDAO.deleteEnvironmentByID(removedEnv.getID());
AvatarDAO.deleteAvatarByID(client.getAvatar().getID());
}
} else if (team1PlayerNum > team0PlayerNum) {
int diff = team1PlayerNum - team0PlayerNum;
for (int i = 0; i < diff; i++) {
int playerPosition = map.removeLastOnePlayerFromTeamN(1);
//Remove the environment in row: 0, position: playerPosition of the current world.
Environment removedEnv = client.getServer().removeAnEnvFromWorld(pvpWorld.getID(), Constants.GAME_TYPE_PVP, 0, playerPosition);
EnvironmentDAO.deleteEnvironmentByID(removedEnv.getID());