mirror of
https://github.com/taoneill/war.git
synced 2024-12-11 19:36:55 +01:00
Fix issues with joining a team.
Players are no longer silently kicked out of their team if they try to join a non-existant team with /join. Fix an inconsistency with the format of the team join notification message.
This commit is contained in:
parent
12b5f8350f
commit
f1ce78907e
@ -706,4 +706,8 @@ public class Team {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFull() {
|
||||||
|
return this.getPlayers().size() == this.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,25 +57,8 @@ public class JoinCommand extends AbstractWarCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = this.args[0];
|
|
||||||
TeamKind kind = TeamKind.teamKindFromString(this.args[0]);
|
TeamKind kind = TeamKind.teamKindFromString(this.args[0]);
|
||||||
|
|
||||||
// drop from old team if any
|
|
||||||
Team previousTeam = Team.getTeamByPlayerName(player.getName());
|
|
||||||
if (previousTeam != null) {
|
|
||||||
if (previousTeam.getName().startsWith(name) || previousTeam.getKind() == kind) {
|
|
||||||
// trying to join own team
|
|
||||||
War.war.badMsg(player, "Can't join your own team.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!previousTeam.removePlayer(player.getName())) {
|
|
||||||
War.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING);
|
|
||||||
}
|
|
||||||
previousTeam.resetSign();
|
|
||||||
}
|
|
||||||
|
|
||||||
// join new team
|
|
||||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||||
this.badMsg("This warzone is disabled.");
|
this.badMsg("This warzone is disabled.");
|
||||||
} else if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
|
} else if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
|
||||||
@ -83,42 +66,43 @@ public class JoinCommand extends AbstractWarCommand {
|
|||||||
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
|
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
|
||||||
this.badMsg("You cannot join a battle in progress in this warzone.");
|
this.badMsg("You cannot join a battle in progress in this warzone.");
|
||||||
} else {
|
} else {
|
||||||
List<Team> teams = zone.getTeams();
|
Team team = zone.getTeamByKind(kind);
|
||||||
boolean foundTeam = false;
|
if (kind == null) {
|
||||||
for (Team team : teams) {
|
this.badMsg("There is no team kind called " + args[0] + ".");
|
||||||
if (team.getName().startsWith(name) || team.getKind() == kind) {
|
} else if (team == null) {
|
||||||
if (!War.war.canPlayWar(player, team)) {
|
this.badMsg("This warzone does not contain a team " + kind.toString() + ".");
|
||||||
this.badMsg("You don't have permission to join this team.");
|
} else if (!War.war.canPlayWar(player, team)) {
|
||||||
return true;
|
this.badMsg("You don't have permission to join this team.");
|
||||||
}
|
} else if (team.isFull()) {
|
||||||
if (player.getWorld() != zone.getWorld()) {
|
this.badMsg("Team " + team.getName() + " is full.");
|
||||||
player.teleport(zone.getWorld().getSpawnLocation());
|
|
||||||
}
|
|
||||||
if (!zone.hasPlayerState(player.getName())) {
|
|
||||||
zone.keepPlayerState(player);
|
|
||||||
this.msg("Your inventory is in storage until you use '/war leave'.");
|
|
||||||
}
|
|
||||||
if (team.getPlayers().size() < team.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE)) {
|
|
||||||
team.addPlayer(player);
|
|
||||||
team.resetSign();
|
|
||||||
zone.respawnPlayer(team, player);
|
|
||||||
if (War.war.getWarHub() != null) {
|
|
||||||
War.war.getWarHub().resetZoneSign(zone);
|
|
||||||
}
|
|
||||||
foundTeam = true;
|
|
||||||
} else {
|
|
||||||
this.msg("Team " + team.getName() + " is full.");
|
|
||||||
foundTeam = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundTeam) {
|
|
||||||
for (Team team : teams) {
|
|
||||||
team.teamcast("" + player.getName() + " joined " + team.getName());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.msg("No such team. Try /teams.");
|
Team previousTeam = Team.getTeamByPlayerName(player.getName());
|
||||||
|
if (previousTeam != null) {
|
||||||
|
if (previousTeam == team) {
|
||||||
|
War.war.badMsg(player, "You cannot join your own team.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!previousTeam.removePlayer(player.getName())) {
|
||||||
|
War.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING);
|
||||||
|
}
|
||||||
|
previousTeam.resetSign();
|
||||||
|
}
|
||||||
|
if (player.getWorld() != zone.getWorld()) {
|
||||||
|
player.teleport(zone.getWorld().getSpawnLocation());
|
||||||
|
}
|
||||||
|
if (!zone.hasPlayerState(player.getName())) {
|
||||||
|
zone.keepPlayerState(player);
|
||||||
|
this.msg("Your inventory is in storage until you use '/war leave'.");
|
||||||
|
}
|
||||||
|
team.addPlayer(player);
|
||||||
|
team.resetSign();
|
||||||
|
zone.respawnPlayer(team, player);
|
||||||
|
if (War.war.getWarHub() != null) {
|
||||||
|
War.war.getWarHub().resetZoneSign(zone);
|
||||||
|
}
|
||||||
|
for (Team localTeam : zone.getTeams()) {
|
||||||
|
localTeam.teamcast(String.format("%s joined team %s.", player.getName(), team.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user