Improving spawn selection in SkywarsTeams.

This commit is contained in:
Sarah 2015-07-14 08:19:33 +02:00
parent a224e5937d
commit 2b10aa2cf9
2 changed files with 66 additions and 2 deletions

View File

@ -12,9 +12,12 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.smash.TeamSuperSmash.TeamColors;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -45,9 +48,57 @@ public class TeamSkywars extends Skywars
if (event.GetState() != GameState.Recruit)
return;
ArrayList<Location> spawns = this.GetTeamList().get(0).GetSpawns();
ArrayList<Location> tempSpawns = this.GetTeamList().get(0).GetSpawns();
this.GetTeamList().clear();
ArrayList<Location> spawns = new ArrayList<Location>();
for(Location location : tempSpawns)
{
for(int x = -1; x <= 1; x++)
{
for(int z = -1; z <= 1; z++)
{
if(x != 0 && z != 0)
{
Location spawnLocation = location.clone().add(x, 0, z);
if(spawnLocation.getWorld().getBlockAt(spawnLocation).getRelative(BlockFace.DOWN).getType() == Material.AIR)
{
boolean foundBlock = false;
Location tempLocation = spawnLocation.clone();
BlockFace currentBlockFace = BlockFace.NORTH;
while(!foundBlock)
{
for(BlockFace face : BlockFace.values())
{
if(spawnLocation.getWorld().getBlockAt(spawnLocation).getRelative(face).getType() != Material.AIR)
{
spawnLocation = tempLocation.getWorld().getBlockAt(tempLocation).getRelative(face).getLocation().add(0, 1, 0);
foundBlock = true;
}
}
if(!foundBlock)
{
tempLocation = spawnLocation.getWorld().getBlockAt(spawnLocation).getRelative(currentBlockFace).getLocation();
currentBlockFace = getBlockface(currentBlockFace);
if(currentBlockFace == BlockFace.SELF)
{
currentBlockFace = getBlockface(currentBlockFace);
tempLocation = spawnLocation.getWorld().getBlockAt(spawnLocation).getRelative(currentBlockFace).getLocation();
spawnLocation = tempLocation;
}
}
}
}
while(spawnLocation.getWorld().getBlockAt(spawnLocation).getType() != Material.AIR)
{
spawnLocation.add(0, 1, 0);
}
spawns.add(spawnLocation);
}
}
}
}
TeamColors color = TeamColors.DARK_AQUA;
if(!this.ForceTeamSize)
@ -73,6 +124,17 @@ public class TeamSkywars extends Skywars
}
}
private BlockFace getBlockface(BlockFace face)
{
for(TeamColors faces : TeamColors.values()) {
if(faces.ordinal() == face.ordinal() + 1)
{
return face;
}
}
return BlockFace.NORTH;
}
private enum TeamColors
{

View File

@ -9,9 +9,12 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.skywars.TeamSkywars.TeamColors;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -103,7 +106,6 @@ public class TeamSuperSmash extends SuperSmash
{
for(int i = 1; i <= Manager.GetPlayerFull() / this.PlayersPerTeam; i++)
{
System.out.println("Test");
color = getNextColor(color);
GameTeam team = new GameTeam(this, String.valueOf(i), color.getColor(), spawns);
team.SetVisible(true);