Merge branch 'SSM2PlayerTeams' of http://184.154.0.242:7990/scm/min/mineplex into SSM2PlayerTeams

This commit is contained in:
Sarah 2015-07-17 06:31:10 +02:00
commit 5389193cab
10 changed files with 209 additions and 154 deletions

View File

@ -1,7 +1,9 @@
package mineplex.core.common.util; package mineplex.core.common.util;
import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class UtilAction public class UtilAction
@ -37,6 +39,12 @@ public class UtilAction
//Velocity //Velocity
ent.setFallDistance(0); ent.setFallDistance(0);
ent.setVelocity(vec); ent.setVelocity(vec);
//Debug
if (ent instanceof Player && UtilGear.isMat(((Player)ent).getItemInHand(), Material.SUGAR))
{
UtilPlayer.message(ent, F.main("Debug", "Velocity Sent: " + vec.length()));
}
} }
} }

View File

@ -7,6 +7,7 @@ import java.util.TreeSet;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -260,4 +261,96 @@ public class UtilAlg
return isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getEyeLocation()), angleLimit) || return isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getEyeLocation()), angleLimit) ||
isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getLocation()), angleLimit); isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getLocation()), angleLimit);
} }
public static Location getLocationAwayFromPlayers(ArrayList<Location> locs, ArrayList<Player> players)
{
Location bestLoc = null;
double bestDist = 0;
for (Location loc : locs)
{
double closest = -1;
for (Player player : players)
{
//Different Worlds
if (!player.getWorld().equals(loc.getWorld()))
continue;
double dist = UtilMath.offsetSquared(player.getLocation(), loc);
if (closest == -1 || dist < closest)
{
closest = dist;
}
}
if (closest == -1)
continue;
if (bestLoc == null || closest > bestDist)
{
bestLoc = loc;
bestDist = closest;
}
}
return bestLoc;
}
public static Location getLocationNearPlayers(ArrayList<Location> locs, ArrayList<Player> players, ArrayList<Player> dontOverlap)
{
Location bestLoc = null;
double bestDist = 0;
for (Location loc : locs)
{
double closest = -1;
boolean valid = true;
//Dont spawn on other players
for (Player player : dontOverlap)
{
if (!player.getWorld().equals(loc.getWorld()))
continue;
double dist = UtilMath.offsetSquared(player.getLocation(), loc);
if (dist < 0.8)
{
valid = false;
break;
}
}
if (!valid)
continue;
//Find closest player
for (Player player : players)
{
if (!player.getWorld().equals(loc.getWorld()))
continue;
double dist = UtilMath.offsetSquared(player.getLocation(), loc);
if (closest == -1 || dist < closest)
{
closest = dist;
}
}
if (closest == -1)
continue;
if (bestLoc == null || closest < bestDist)
{
bestLoc = loc;
bestDist = closest;
}
}
return bestLoc;
}
} }

View File

@ -341,7 +341,7 @@ public class ClientClass
if (notify) if (notify)
{ {
ListSkills(_client.GetPlayer()); ListSkills(_client.GetPlayer());
_client.GetPlayer().getWorld().playSound(_client.GetPlayer().getLocation(), Sound.LEVEL_UP, 1f, 1f); _client.GetPlayer().playSound(_client.GetPlayer().getLocation(), Sound.LEVEL_UP, 1f, 1f);
_client.GetPlayer().sendMessage(F.main("Class", "You equipped " + F.skill(customBuild.Name) + ".")); _client.GetPlayer().sendMessage(F.main("Class", "You equipped " + F.skill(customBuild.Name) + "."));
} }

View File

@ -391,10 +391,11 @@ public class DamageManager extends MiniPlugin
trajectory.setY(Math.abs(trajectory.getY())); trajectory.setY(Math.abs(trajectory.getY()));
//Apply //Apply
UtilAction.velocity(event.GetDamageeEntity(), double vel = 0.2 + trajectory.length() * 0.8;
trajectory, 0.2 + trajectory.length() * 0.8, false, 0, Math.abs(0.2 * knockback), 0.4 + (0.04 * knockback), true);
UtilAction.velocity(event.GetDamageeEntity(), trajectory, vel,
false, 0, Math.abs(0.2 * knockback), 0.4 + (0.04 * knockback), true);
} }
} }
catch (IllegalAccessException e) catch (IllegalAccessException e)
{ {
@ -414,7 +415,7 @@ public class DamageManager extends MiniPlugin
{ {
for (Player player : UtilServer.getPlayers()) for (Player player : UtilServer.getPlayers())
{ {
if (!UtilGear.isMat(player.getItemInHand(), Material.BOOK)) if (!UtilGear.isMat(player.getItemInHand(), Material.COMMAND))
continue; continue;
UtilPlayer.message(player, " "); UtilPlayer.message(player, " ");

View File

@ -209,7 +209,10 @@ public abstract class Game implements Listener
public int TickPerTeleport = 1; public int TickPerTeleport = 1;
public int EnforceTeamSize = -1;
public boolean SpawnNearAllies = false; public boolean SpawnNearAllies = false;
public boolean SpawnNearEnemies = false;
public boolean StrictAntiHack = false; public boolean StrictAntiHack = false;
@ -613,6 +616,17 @@ public abstract class Game implements Listener
public GameTeam ChooseTeam(Player player) public GameTeam ChooseTeam(Player player)
{ {
if (EnforceTeamSize != -1)
{
for (int i = 0; i < _teamList.size(); i++)
{
if (_teamList.get(i).GetSize() < EnforceTeamSize)
{
return _teamList.get(i);
}
}
}
GameTeam team = null; GameTeam team = null;
//Random Team //Random Team

View File

@ -7,6 +7,7 @@ import java.util.Iterator;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
@ -97,88 +98,47 @@ public class GameTeam
public Location GetSpawn() public Location GetSpawn()
{ {
//Spawn Allies Together! //Keep allies together
if (Host.IsLive() && Host.SpawnNearAllies) if (!Host.IsLive() && Host.SpawnNearAllies)
{ {
Location closestLoc = null; //Find Location Nearest Ally
double closestDist = 0; Location loc = UtilAlg.getLocationNearPlayers(_spawns, GetPlayers(true), Host.GetPlayers(true));
if (loc != null)
for (Location loc : _spawns) return loc;
//No allies existed spawned yet
//Spawn near enemies (used for SG)
if (Host.SpawnNearEnemies)
{ {
//Check if Location is closer! loc = UtilAlg.getLocationNearPlayers(_spawns, Host.GetPlayers(true), Host.GetPlayers(true));
for (Player player : this.GetPlayers(true)) if (loc != null)
{ return loc;
//Different Worlds
if (!player.getWorld().equals(loc.getWorld()))
continue;
double dist = UtilMath.offset(player.getLocation(), loc);
//Dont Spawn Inside Ally
if (dist < 0.75)
continue;
//Find Closest Enemy
double closestEnemy = -1;
for (Player enemy : Host.GetPlayers(true))
{
if (!enemy.getWorld().equals(loc.getWorld()))
continue;
if (this.HasPlayer(enemy))
continue;
double enemyDist = UtilMath.offset(player.getLocation(), loc);
if (closestEnemy == -1 || enemyDist < closestEnemy)
{
closestEnemy = enemyDist;
}
}
//Dont Spawn Inside Enemy
if (closestEnemy != -1 && closestEnemy < 0.75)
continue;
//Good Location!
if (closestLoc == null || dist < closestDist)
{
closestLoc = loc;
closestDist = dist;
}
}
} }
//Spawn away from enemies
if (closestLoc != null) else
return closestLoc; {
loc = UtilAlg.getLocationAwayFromPlayers(_spawns, Host.GetPlayers(true));
if (loc != null)
return loc;
}
} }
//Spawn Furthest Away!
else else
{ {
Location furthestLoc = null; //Spawn near players
double furthestDist = 0; if (Host.SpawnNearEnemies)
for (Location loc : _spawns)
{ {
for (Player player : Host.GetPlayers(true)) Location loc = UtilAlg.getLocationAwayFromPlayers(_spawns, Host.GetPlayers(true));
{ if (loc != null)
//Different Worlds return loc;
if (!player.getWorld().equals(loc.getWorld())) }
continue; //Spawn away from players
else
double dist = UtilMath.offsetSquared(player.getLocation(), loc); {
Location loc = UtilAlg.getLocationNearPlayers(_spawns, Host.GetPlayers(true), Host.GetPlayers(true));
if (furthestLoc == null || dist > furthestDist) if (loc != null)
{ return loc;
furthestLoc = loc;
furthestDist = dist;
}
}
} }
if (furthestLoc != null)
return furthestLoc;
} }
return _spawns.get(UtilMath.r(_spawns.size())); return _spawns.get(UtilMath.r(_spawns.size()));

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
@ -22,11 +23,6 @@ import org.bukkit.event.EventHandler;
public class TeamSkywars extends Skywars public class TeamSkywars extends Skywars
{ {
public boolean ForceTeamSize = true;
public int PlayersPerTeam = 2;
public int TeamCount = 0;
public TeamSkywars(ArcadeManager manager) public TeamSkywars(ArcadeManager manager)
{ {
super(manager, GameType.SkywarsTeams, super(manager, GameType.SkywarsTeams,
@ -36,9 +32,6 @@ public class TeamSkywars extends Skywars
"Craft or loot gear for combat", "Craft or loot gear for combat",
"Last team alive wins!" "Last team alive wins!"
}); });
this.PlayersPerTeam = 2;
} }
@EventHandler @EventHandler
@ -47,85 +40,69 @@ public class TeamSkywars extends Skywars
if (event.GetState() != GameState.Recruit) if (event.GetState() != GameState.Recruit)
return; return;
ArrayList<Location> tempSpawns = this.GetTeamList().get(0).GetSpawns(); ArrayList<Location> initialSpawns = this.GetTeamList().get(0).GetSpawns();
this.GetTeamList().clear(); this.GetTeamList().clear();
ArrayList<Location> spawns = new ArrayList<Location>(); ArrayList<Location> spawns = new ArrayList<Location>();
for(Location location : tempSpawns)
TeamColors color = TeamColors.DARK_AQUA;
//Create 1 Team for each Spawn
int i = 0;
for(Location location : initialSpawns)
{ {
for(int x = -1; x <= 1; x++) i++;
spawns.add(location);
addRelativeSpawns(spawns, location);
//Got Spawns
color = getNextColor(color);
GameTeam team = new GameTeam(this, String.valueOf(i), color.getColor(), spawns);
team.SetVisible(true);
GetTeamList().add(team);
}
}
private void addRelativeSpawns(ArrayList<Location> spawns, Location location)
{
//Gather Extra Spawns
for(int x = -1; x <= 1; x++)
{
for(int z = -1; z <= 1; z++)
{ {
for(int z = -1; z <= 1; z++) if(x != 0 && z != 0)
{ {
if(x != 0 && z != 0) Location newSpawn = location.clone().add(x, 0, z);
//Search Downward for Solid
while (UtilBlock.airFoliage(newSpawn.getBlock().getRelative(BlockFace.DOWN)) && newSpawn.getY() > location.getY()-5)
{ {
Location spawnLocation = location.clone().add(x, 0, z); newSpawn.subtract(0, 1, 0);
if(spawnLocation.getWorld().getBlockAt(spawnLocation).getRelative(BlockFace.DOWN).getType() == Material.AIR) }
{
boolean foundBlock = false; //Move Up out of Solid
Location tempLocation = spawnLocation.clone(); while (!UtilBlock.airFoliage(newSpawn.getBlock()) && newSpawn.getY() < location.getY()+5)
BlockFace currentBlockFace = BlockFace.NORTH; {
while(!foundBlock) newSpawn.add(0, 1, 0);
{ }
for(BlockFace face : BlockFace.values())
{ //On Solid, with 2 Air Above
if(spawnLocation.getWorld().getBlockAt(spawnLocation).getRelative(face).getType() != Material.AIR) if (UtilBlock.airFoliage(newSpawn.getBlock()) &&
{ UtilBlock.airFoliage(newSpawn.getBlock().getRelative(BlockFace.UP)) &&
spawnLocation = tempLocation.getWorld().getBlockAt(tempLocation).getRelative(face).getLocation().add(0, 1, 0); !UtilBlock.airFoliage(newSpawn.getBlock().getRelative(BlockFace.DOWN)))
foundBlock = true; {
} spawns.add(newSpawn);
}
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)
{
for(int i = 1; i <= this.TeamCount; i++)
{
color = getNextColor(color);
GameTeam team = new GameTeam(this, String.valueOf(i), color.getColor(), spawns);
team.SetVisible(true);
GetTeamList().add(team);
}
}
else
{
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);
GetTeamList().add(team);
}
}
} }
private BlockFace getBlockface(BlockFace face) private BlockFace getBlockface(BlockFace face)
{ {
for(TeamColors faces : TeamColors.values()) { for(BlockFace faces : BlockFace.values()) {
if(faces.ordinal() == face.ordinal() + 1) if(faces.ordinal() == face.ordinal() + 1)
{ {
return face; return face;

View File

@ -33,6 +33,7 @@ public class TeamSuperSmash extends SuperSmash
}); });
this.PlayersPerTeam = 2; this.PlayersPerTeam = 2;
this.EnforceTeamSize = 2;
} }
@Override @Override
@ -213,5 +214,4 @@ public class TeamSuperSmash extends SuperSmash
return players; return players;
} }
} }

View File

@ -217,6 +217,7 @@ public abstract class SurvivalGames extends Game
WorldTimeSet = 0; WorldTimeSet = 0;
WorldBoundaryKill = false; WorldBoundaryKill = false;
SpawnNearAllies = true; SpawnNearAllies = true;
SpawnNearEnemies = true; //This is to ensure theres no 'gaps' of 1 between teams, hence forcing a team to get split.
DamageSelf = true; DamageSelf = true;
DamageTeamSelf = true; DamageTeamSelf = true;

View File

@ -37,6 +37,7 @@ public class TeamSurvivalGames extends SurvivalGames
}); });
this.PlayersPerTeam = 2; this.PlayersPerTeam = 2;
this.EnforceTeamSize = 2;
} }