Add ability to bypass warzone lobby. Fixes gh-669

If a zone has the property autojoin & autoassign set to true, then
players will be directly assigned to a team when they go through the
Warhub portal for the zone and brought back to the Warhub when they
leave the zone.
This commit is contained in:
cmastudios 2013-09-07 18:10:23 -05:00
parent 890e78fd5d
commit b367cc53ad
6 changed files with 53 additions and 6 deletions

View File

@ -187,6 +187,7 @@ public class War extends JavaPlugin {
warzoneDefaultConfig.put(WarzoneConfig.UNBREAKABLE, false);
warzoneDefaultConfig.put(WarzoneConfig.DEATHMESSAGES, true);
warzoneDefaultConfig.put(WarzoneConfig.JOINMIDBATTLE, true);
warzoneDefaultConfig.put(WarzoneConfig.AUTOJOIN, false);
teamDefaultConfig.put(TeamConfig.FLAGMUSTBEHOME, true);
teamDefaultConfig.put(TeamConfig.FLAGPOINTSONLY, false);

View File

@ -1448,6 +1448,8 @@ public class Warzone {
public void gameEndTeleport(Player tp) {
if (this.getRallyPoint() != null) {
tp.teleport(this.getRallyPoint());
} else if (this.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN)) {
tp.teleport(War.war.getWarHub().getLocation());
} else {
tp.teleport(this.getTeleport());
}

View File

@ -4,7 +4,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.WarzoneConfig;
/**
* Leaves a game.
@ -33,7 +35,8 @@ public class LeaveCommand extends AbstractWarCommand {
return false;
}
zone.handlePlayerLeave(player, zone.getTeleport(), true);
zone.handlePlayerLeave(player, zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN) ?
War.war.getWarHub().getLocation() : zone.getTeleport(), true);
return true;
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.structure.ZoneLobby;
import java.util.Iterator;
import org.kitteh.tag.TagAPI;
@ -55,7 +56,8 @@ public class ResetZoneCommand extends AbstractZoneMakerCommand {
TagAPI.refreshPlayer(p);
}
zone.restorePlayerState(p);
p.teleport(zone.getTeleport());
p.teleport(zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN) ?
War.war.getWarHub().getLocation() : zone.getTeleport());
War.war.msg(p, "You have left the warzone. Your inventory is being restored.");
}
team.resetPoints();

View File

@ -20,7 +20,8 @@ public enum WarzoneConfig {
RESETONLOAD (Boolean.class),
RESETONUNLOAD (Boolean.class),
UNBREAKABLE (Boolean.class),
JOINMIDBATTLE (Boolean.class);
JOINMIDBATTLE (Boolean.class),
AUTOJOIN (Boolean.class);
private final Class<?> configType;

View File

@ -66,7 +66,8 @@ public class WarPlayerListener implements Listener {
Player player = event.getPlayer();
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
if (zone != null) {
zone.handlePlayerLeave(player, zone.getTeleport(), true);
zone.handlePlayerLeave(player, zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN) ?
War.war.getWarHub().getLocation() : zone.getTeleport(), true);
}
if (War.war.isWandBearer(player)) {
@ -197,7 +198,8 @@ public class WarPlayerListener implements Listener {
if (warzone != null) {
// kick player from warzone as well
warzone.handlePlayerLeave(player, warzone.getTeleport(), true);
warzone.handlePlayerLeave(player, warzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN) ?
War.war.getWarHub().getLocation() : warzone.getTeleport(), true);
}
}
}
@ -375,6 +377,41 @@ public class WarPlayerListener implements Listener {
if (hub != null && hub.getVolume().contains(player.getLocation())) {
Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
if (zone != null && zone.getTeleport() != null) {
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN)
&& zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)
&& zone.getTeams().size() >= 1) {
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
event.setTo(hub.getLocation());
War.war.badMsg(player, "This warzone is disabled.");
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
event.setTo(hub.getLocation());
War.war.badMsg(player, "You cannot join a battle in progress in this warzone.");
} else {
this.dropFromOldTeamIfAny(player);
int noOfPlayers = 0;
int totalCap = 0;
for (Team t : zone.getTeams()) {
noOfPlayers += t.getPlayers().size();
totalCap += t.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE);
}
if (noOfPlayers < totalCap) {
boolean assigned = zone.autoAssign(player) != null ? true : false;
if (!assigned) {
event.setTo(hub.getLocation());
War.war.badMsg(player, "You don't have permission for any of the available teams in this warzone");
}
if (War.war.getWarHub() != null && assigned) {
War.war.getWarHub().resetZoneSign(zone);
}
} else {
event.setTo(hub.getLocation());
War.war.badMsg(player, "All teams are full.");
}
}
return;
}
event.setTo(zone.getTeleport());
War.war.msg(player, "Welcome to warzone " + zone.getName() + ".");
return;
@ -388,7 +425,8 @@ public class WarPlayerListener implements Listener {
if (playerTeam != null) {
boolean atSpawnAlready = playerTeam.isSpawnLocation(playerLoc);
if (!atSpawnAlready) {
playerWarzone.handlePlayerLeave(player, playerWarzone.getTeleport(), event, true);
playerWarzone.handlePlayerLeave(player, playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN) ?
War.war.getWarHub().getLocation() : playerWarzone.getTeleport(), event, true);
return;
}
}