Merge branch 'SSM2PlayerTeams' of http://184.154.0.242:7990/scm/min/mineplex into SSM2PlayerTeams
This commit is contained in:
commit
5389193cab
@ -1,7 +1,9 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class UtilAction
|
||||
@ -38,5 +40,11 @@ public class UtilAction
|
||||
//Velocity
|
||||
ent.setFallDistance(0);
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.TreeSet;
|
||||
|
||||
|
||||
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -260,4 +261,96 @@ public class UtilAlg
|
||||
return isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getEyeLocation()), 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;
|
||||
}
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ public class ClientClass
|
||||
if (notify)
|
||||
{
|
||||
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) + "."));
|
||||
}
|
||||
|
@ -391,10 +391,11 @@ public class DamageManager extends MiniPlugin
|
||||
trajectory.setY(Math.abs(trajectory.getY()));
|
||||
|
||||
//Apply
|
||||
UtilAction.velocity(event.GetDamageeEntity(),
|
||||
trajectory, 0.2 + trajectory.length() * 0.8, false, 0, Math.abs(0.2 * knockback), 0.4 + (0.04 * knockback), true);
|
||||
}
|
||||
double vel = 0.2 + trajectory.length() * 0.8;
|
||||
|
||||
UtilAction.velocity(event.GetDamageeEntity(), trajectory, vel,
|
||||
false, 0, Math.abs(0.2 * knockback), 0.4 + (0.04 * knockback), true);
|
||||
}
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
@ -414,7 +415,7 @@ public class DamageManager extends MiniPlugin
|
||||
{
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if (!UtilGear.isMat(player.getItemInHand(), Material.BOOK))
|
||||
if (!UtilGear.isMat(player.getItemInHand(), Material.COMMAND))
|
||||
continue;
|
||||
|
||||
UtilPlayer.message(player, " ");
|
||||
|
@ -209,7 +209,10 @@ public abstract class Game implements Listener
|
||||
|
||||
public int TickPerTeleport = 1;
|
||||
|
||||
public int EnforceTeamSize = -1;
|
||||
|
||||
public boolean SpawnNearAllies = false;
|
||||
public boolean SpawnNearEnemies = false;
|
||||
|
||||
public boolean StrictAntiHack = false;
|
||||
|
||||
@ -613,6 +616,17 @@ public abstract class Game implements Listener
|
||||
|
||||
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;
|
||||
|
||||
//Random Team
|
||||
|
@ -7,6 +7,7 @@ import java.util.Iterator;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
@ -97,88 +98,47 @@ public class GameTeam
|
||||
|
||||
public Location GetSpawn()
|
||||
{
|
||||
//Spawn Allies Together!
|
||||
if (Host.IsLive() && Host.SpawnNearAllies)
|
||||
//Keep allies together
|
||||
if (!Host.IsLive() && Host.SpawnNearAllies)
|
||||
{
|
||||
Location closestLoc = null;
|
||||
double closestDist = 0;
|
||||
//Find Location Nearest Ally
|
||||
Location loc = UtilAlg.getLocationNearPlayers(_spawns, GetPlayers(true), Host.GetPlayers(true));
|
||||
if (loc != null)
|
||||
return loc;
|
||||
|
||||
for (Location loc : _spawns)
|
||||
//No allies existed spawned yet
|
||||
|
||||
//Spawn near enemies (used for SG)
|
||||
if (Host.SpawnNearEnemies)
|
||||
{
|
||||
//Check if Location is closer!
|
||||
for (Player player : this.GetPlayers(true))
|
||||
{
|
||||
//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;
|
||||
}
|
||||
}
|
||||
loc = UtilAlg.getLocationNearPlayers(_spawns, Host.GetPlayers(true), Host.GetPlayers(true));
|
||||
if (loc != null)
|
||||
return loc;
|
||||
}
|
||||
//Spawn away from enemies
|
||||
else
|
||||
{
|
||||
loc = UtilAlg.getLocationAwayFromPlayers(_spawns, Host.GetPlayers(true));
|
||||
if (loc != null)
|
||||
return loc;
|
||||
}
|
||||
|
||||
if (closestLoc != null)
|
||||
return closestLoc;
|
||||
}
|
||||
//Spawn Furthest Away!
|
||||
else
|
||||
{
|
||||
Location furthestLoc = null;
|
||||
double furthestDist = 0;
|
||||
|
||||
for (Location loc : _spawns)
|
||||
//Spawn near players
|
||||
if (Host.SpawnNearEnemies)
|
||||
{
|
||||
for (Player player : Host.GetPlayers(true))
|
||||
{
|
||||
//Different Worlds
|
||||
if (!player.getWorld().equals(loc.getWorld()))
|
||||
continue;
|
||||
|
||||
double dist = UtilMath.offsetSquared(player.getLocation(), loc);
|
||||
|
||||
if (furthestLoc == null || dist > furthestDist)
|
||||
{
|
||||
furthestLoc = loc;
|
||||
furthestDist = dist;
|
||||
}
|
||||
}
|
||||
Location loc = UtilAlg.getLocationAwayFromPlayers(_spawns, Host.GetPlayers(true));
|
||||
if (loc != null)
|
||||
return loc;
|
||||
}
|
||||
//Spawn away from players
|
||||
else
|
||||
{
|
||||
Location loc = UtilAlg.getLocationNearPlayers(_spawns, Host.GetPlayers(true), Host.GetPlayers(true));
|
||||
if (loc != null)
|
||||
return loc;
|
||||
}
|
||||
|
||||
if (furthestLoc != null)
|
||||
return furthestLoc;
|
||||
}
|
||||
|
||||
return _spawns.get(UtilMath.r(_spawns.size()));
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
@ -22,11 +23,6 @@ import org.bukkit.event.EventHandler;
|
||||
|
||||
public class TeamSkywars extends Skywars
|
||||
{
|
||||
|
||||
public boolean ForceTeamSize = true;
|
||||
public int PlayersPerTeam = 2;
|
||||
public int TeamCount = 0;
|
||||
|
||||
public TeamSkywars(ArcadeManager manager)
|
||||
{
|
||||
super(manager, GameType.SkywarsTeams,
|
||||
@ -36,9 +32,6 @@ public class TeamSkywars extends Skywars
|
||||
"Craft or loot gear for combat",
|
||||
"Last team alive wins!"
|
||||
});
|
||||
|
||||
this.PlayersPerTeam = 2;
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -47,85 +40,69 @@ public class TeamSkywars extends Skywars
|
||||
if (event.GetState() != GameState.Recruit)
|
||||
return;
|
||||
|
||||
ArrayList<Location> tempSpawns = this.GetTeamList().get(0).GetSpawns();
|
||||
ArrayList<Location> initialSpawns = 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)
|
||||
//Create 1 Team for each Spawn
|
||||
int i = 0;
|
||||
for(Location location : initialSpawns)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
private void addRelativeSpawns(ArrayList<Location> spawns, Location location)
|
||||
{
|
||||
//Gather Extra Spawns
|
||||
for(int x = -1; x <= 1; x++)
|
||||
{
|
||||
for(int i = 1; i <= Manager.GetPlayerFull() / this.PlayersPerTeam; i++)
|
||||
for(int z = -1; z <= 1; z++)
|
||||
{
|
||||
System.out.println("Test");
|
||||
color = getNextColor(color);
|
||||
GameTeam team = new GameTeam(this, String.valueOf(i), color.getColor(), spawns);
|
||||
team.SetVisible(true);
|
||||
GetTeamList().add(team);
|
||||
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)
|
||||
{
|
||||
newSpawn.subtract(0, 1, 0);
|
||||
}
|
||||
|
||||
//Move Up out of Solid
|
||||
while (!UtilBlock.airFoliage(newSpawn.getBlock()) && newSpawn.getY() < location.getY()+5)
|
||||
{
|
||||
newSpawn.add(0, 1, 0);
|
||||
}
|
||||
|
||||
//On Solid, with 2 Air Above
|
||||
if (UtilBlock.airFoliage(newSpawn.getBlock()) &&
|
||||
UtilBlock.airFoliage(newSpawn.getBlock().getRelative(BlockFace.UP)) &&
|
||||
!UtilBlock.airFoliage(newSpawn.getBlock().getRelative(BlockFace.DOWN)))
|
||||
{
|
||||
spawns.add(newSpawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BlockFace getBlockface(BlockFace face)
|
||||
{
|
||||
for(TeamColors faces : TeamColors.values()) {
|
||||
for(BlockFace faces : BlockFace.values()) {
|
||||
if(faces.ordinal() == face.ordinal() + 1)
|
||||
{
|
||||
return face;
|
||||
|
@ -33,6 +33,7 @@ public class TeamSuperSmash extends SuperSmash
|
||||
});
|
||||
|
||||
this.PlayersPerTeam = 2;
|
||||
this.EnforceTeamSize = 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -213,5 +214,4 @@ public class TeamSuperSmash extends SuperSmash
|
||||
|
||||
return players;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -217,6 +217,7 @@ public abstract class SurvivalGames extends Game
|
||||
WorldTimeSet = 0;
|
||||
WorldBoundaryKill = false;
|
||||
SpawnNearAllies = true;
|
||||
SpawnNearEnemies = true; //This is to ensure theres no 'gaps' of 1 between teams, hence forcing a team to get split.
|
||||
|
||||
DamageSelf = true;
|
||||
DamageTeamSelf = true;
|
||||
|
@ -37,6 +37,7 @@ public class TeamSurvivalGames extends SurvivalGames
|
||||
});
|
||||
|
||||
this.PlayersPerTeam = 2;
|
||||
this.EnforceTeamSize = 2;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user