Rewrite team balancing...

This commit is contained in:
Sam 2018-06-20 17:00:28 +01:00 committed by Alexander Meech
parent 47b88ee8fe
commit 108f2d7f16
36 changed files with 624 additions and 1475 deletions

View File

@ -1,6 +1,7 @@
package mineplex.core.party; package mineplex.core.party;
import java.io.File; import java.io.File;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -140,6 +141,11 @@ public class PartyManager extends MiniPlugin
return _partiesByPlayer.get(player.getUniqueId()); return _partiesByPlayer.get(player.getUniqueId());
} }
public Collection<Party> getAllParties()
{
return _partiesById.values();
}
public void addParty(Party party) public void addParty(Party party)
{ {
_partiesById.put(party.getUniqueId(), party); _partiesById.put(party.getUniqueId(), party);

View File

@ -2,7 +2,6 @@ package nautilus.game.arcade;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -28,7 +27,6 @@ import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
@ -41,6 +39,7 @@ import org.bukkit.util.Vector;
import mineplex.core.Managers; import mineplex.core.Managers;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.PlayerSelector;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.Permission;
@ -57,8 +56,8 @@ import mineplex.core.common.timing.TimingManager;
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.UtilAction; import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilLambda;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.communities.CommunityManager; import mineplex.core.communities.CommunityManager;
@ -88,7 +87,6 @@ import mineplex.core.hologram.HologramManager;
import mineplex.core.incognito.IncognitoManager; import mineplex.core.incognito.IncognitoManager;
import mineplex.core.incognito.events.IncognitoStatusChangeEvent; import mineplex.core.incognito.events.IncognitoStatusChangeEvent;
import mineplex.core.inventory.InventoryManager; import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.menu.MenuManager; import mineplex.core.menu.MenuManager;
import mineplex.core.movement.Movement; import mineplex.core.movement.Movement;
import mineplex.core.npc.NpcManager; import mineplex.core.npc.NpcManager;
@ -162,7 +160,6 @@ import nautilus.game.arcade.managers.GamePlayerManager;
import nautilus.game.arcade.managers.GameRewardManager; import nautilus.game.arcade.managers.GameRewardManager;
import nautilus.game.arcade.managers.GameSpectatorManager; import nautilus.game.arcade.managers.GameSpectatorManager;
import nautilus.game.arcade.managers.GameStatManager; import nautilus.game.arcade.managers.GameStatManager;
import nautilus.game.arcade.managers.GameTournamentManager;
import nautilus.game.arcade.managers.GameWorldManager; import nautilus.game.arcade.managers.GameWorldManager;
import nautilus.game.arcade.managers.IdleManager; import nautilus.game.arcade.managers.IdleManager;
import nautilus.game.arcade.managers.NextBestGameManager; import nautilus.game.arcade.managers.NextBestGameManager;
@ -228,7 +225,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private GameManager _gameManager; private GameManager _gameManager;
private LobbyManager _gameLobbyManager; private LobbyManager _gameLobbyManager;
private GamePlayerManager _gamePlayerManager; private GamePlayerManager _gamePlayerManager;
private GameTournamentManager _gameTournamentManager;
private GameWorldManager _gameWorldManager; private GameWorldManager _gameWorldManager;
private GameHostManager _gameHostManager; private GameHostManager _gameHostManager;
private GameChatManager _gameChatManager; private GameChatManager _gameChatManager;
@ -343,7 +339,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
new GameFlagManager(this); new GameFlagManager(this);
_gamePlayerManager = new GamePlayerManager(this); _gamePlayerManager = new GamePlayerManager(this);
new GameAchievementManager(this); new GameAchievementManager(this);
_gameTournamentManager = new GameTournamentManager(this);
new GameStatManager(this); new GameStatManager(this);
YoutubeManager youtubeManager = new YoutubeManager(plugin, clientManager, donationManager); YoutubeManager youtubeManager = new YoutubeManager(plugin, clientManager, donationManager);
_bonusManager = new BonusManager(plugin, _gameLobbyManager.getCarl(), clientManager, donationManager, pollManager, npcManager, hologramManager, statsManager, _inventoryManager, petManager, youtubeManager, _cosmeticManager.getGadgetManager(), thankManager, "Carl"); _bonusManager = new BonusManager(plugin, _gameLobbyManager.getCarl(), clientManager, donationManager, pollManager, npcManager, hologramManager, statsManager, _inventoryManager, petManager, youtubeManager, _cosmeticManager.getGadgetManager(), thankManager, "Carl");
@ -534,7 +529,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
scoreboard.setSidebarName(ChatColor.GREEN + "§l" + "Waiting for game"); scoreboard.setSidebarName(ChatColor.GREEN + "§l" + "Waiting for game");
} }
scoreboard.get(ArcadeScoreboardLine.PLAYERS_VALUE).write(_gameManager.getValidPlayersForGameStart().size() + "/" + GetPlayerFull()); scoreboard.get(ArcadeScoreboardLine.PLAYERS_VALUE).write(getValidPlayersForGameStart().size() + "/" + GetPlayerFull());
if (GetGame() != null && GetGame().CrownsEnabled) if (GetGame() != null && GetGame().CrownsEnabled)
{ {
scoreboard.get(ArcadeScoreboardLine.GEM_NAME).write(C.cGold + C.Bold + "Crowns"); scoreboard.get(ArcadeScoreboardLine.GEM_NAME).write(C.cGold + C.Bold + "Crowns");
@ -813,11 +808,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return _gamePlayerManager; return _gamePlayerManager;
} }
public GameTournamentManager GetGameTournamentManager()
{
return _gameTournamentManager;
}
public GameWorldManager GetGameWorldManager() public GameWorldManager GetGameWorldManager()
{ {
return _gameWorldManager; return _gameWorldManager;
@ -947,7 +937,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
if (_game != null && _game.GetCountdown() > 0) //Lobby is counting down if (_game != null && _game.GetCountdown() > 0) //Lobby is counting down
{ {
// Remove Data // Remove Data
_game.RemoveTeamPreference(event.getPlayer()); _game.getTeamModule().getPreferences().remove(event.getPlayer());
_game.GetPlayerKits().remove(event.getPlayer()); _game.GetPlayerKits().remove(event.getPlayer());
_game.GetPlayerGems().remove(event.getPlayer()); _game.GetPlayerGems().remove(event.getPlayer());
@ -1435,7 +1425,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
if (_game != null) if (_game != null)
{ {
// Remove Data // Remove Data
_game.RemoveTeamPreference(player); _game.getTeamModule().getPreferences().remove(player);
_game.GetPlayerKits().remove(player); _game.GetPlayerKits().remove(player);
_game.GetPlayerGems().remove(player); _game.GetPlayerGems().remove(player);
@ -1584,7 +1574,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
if (_game != null) if (_game != null)
{ {
// Remove Data // Remove Data
_game.RemoveTeamPreference(player); _game.getTeamModule().getPreferences().remove(player);
_game.GetPlayerKits().remove(player); _game.GetPlayerKits().remove(player);
_game.GetPlayerGems().remove(player); _game.GetPlayerGems().remove(player);
@ -1984,6 +1974,15 @@ public class ArcadeManager extends MiniPlugin implements IRelation
} }
} }
public List<Player> getValidPlayersForGameStart()
{
return PlayerSelector.selectPlayers(
UtilLambda.and(
PlayerSelector.NOT_VANISHED,
player -> !IsObserver(player)
)
);
}
public KitProgressionManager getKitProgressionManager() public KitProgressionManager getKitProgressionManager()
{ {

View File

@ -60,7 +60,6 @@ import nautilus.game.arcade.game.games.minestrike.Minestrike;
import nautilus.game.arcade.game.games.minestrike.modes.SuperPaintstrike; import nautilus.game.arcade.game.games.minestrike.modes.SuperPaintstrike;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles; import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.moba.MobaClassic; import nautilus.game.arcade.game.games.moba.MobaClassic;
import nautilus.game.arcade.game.games.moba.training.MobaTraining;
import nautilus.game.arcade.game.games.monstermaze.MonsterMaze; import nautilus.game.arcade.game.games.monstermaze.MonsterMaze;
import nautilus.game.arcade.game.games.oldmineware.OldMineWare; import nautilus.game.arcade.game.games.oldmineware.OldMineWare;
import nautilus.game.arcade.game.games.paintball.Paintball; import nautilus.game.arcade.game.games.paintball.Paintball;
@ -211,7 +210,6 @@ public enum GameType
AlienInvasion(AlienInvasion.class, GameDisplay.AlienInvasion), AlienInvasion(AlienInvasion.class, GameDisplay.AlienInvasion),
MOBA(MobaClassic.class, GameDisplay.MOBA), MOBA(MobaClassic.class, GameDisplay.MOBA),
MOBATraining(MobaTraining.class, GameDisplay.MOBATraining),
BattleRoyale(BattleRoyaleSolo.class, GameDisplay.BattleRoyale, new Pair[] BattleRoyale(BattleRoyaleSolo.class, GameDisplay.BattleRoyale, new Pair[]
{ {

View File

@ -1,42 +0,0 @@
package nautilus.game.arcade;
import java.util.EnumSet;
import java.util.Set;
public enum TournamentType
{
SUPER_SMASH_MOBS(GameType.Smash),
SURVIVAL_GAMES(GameType.SurvivalGames),
MIXED_ARCADE(
GameType.Dragons,
GameType.DragonEscape,
GameType.DeathTag,
GameType.Runner,
GameType.Snake,
GameType.Spleef,
GameType.SneakyAssassins,
GameType.Quiver);
private final Set<GameType> _gameTypes;
TournamentType(GameType firstGameType, GameType... rest)
{
_gameTypes = EnumSet.of(firstGameType, rest);
}
public Set<GameType> getGameTypes()
{
return _gameTypes;
}
public static TournamentType getTournamentType(GameType gameType)
{
for (TournamentType type : values())
{
if (type.getGameTypes().contains(gameType))
return type;
}
return null;
}
}

View File

@ -96,6 +96,9 @@ import nautilus.game.arcade.game.modules.AntiExpOrbModule;
import nautilus.game.arcade.game.modules.HubClockModule; import nautilus.game.arcade.game.modules.HubClockModule;
import nautilus.game.arcade.game.modules.Module; import nautilus.game.arcade.game.modules.Module;
import nautilus.game.arcade.game.modules.gamesummary.GameSummaryModule; import nautilus.game.arcade.game.modules.gamesummary.GameSummaryModule;
import nautilus.game.arcade.game.team.GameTeamModule;
import nautilus.game.arcade.game.team.selectors.EvenTeamSelector;
import nautilus.game.arcade.game.team.selectors.TeamSelector;
import nautilus.game.arcade.kit.ChampionsKit; import nautilus.game.arcade.kit.ChampionsKit;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.LinearUpgradeKit; import nautilus.game.arcade.kit.LinearUpgradeKit;
@ -174,11 +177,12 @@ public abstract class Game extends ListenerComponent implements Lifetimed
private Kit[] _kits; private Kit[] _kits;
// Teams // Teams
private final GameTeamModule _teamModule;
protected ArrayList<GameTeam> _teamList = new ArrayList<GameTeam>(); protected ArrayList<GameTeam> _teamList = new ArrayList<GameTeam>();
protected TeamSelector _teamSelector = new EvenTeamSelector();
// Player Preferences // Player Preferences
protected NautHashMap<Player, Kit> _playerKit = new NautHashMap<Player, Kit>(); protected NautHashMap<Player, Kit> _playerKit = new NautHashMap<Player, Kit>();
private NautHashMap<GameTeam, ArrayList<Player>> _teamPreference = new NautHashMap<GameTeam, ArrayList<Player>>();
// Player Data // Player Data
private NautHashMap<Player, HashMap<String, GemData>> _gemCount = new NautHashMap<Player, HashMap<String, GemData>>(); private NautHashMap<Player, HashMap<String, GemData>> _gemCount = new NautHashMap<Player, HashMap<String, GemData>>();
@ -284,8 +288,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed
public int TickPerTeleport = 1; public int TickPerTeleport = 1;
public int FillTeamsInOrderToCount = -1;
public boolean SpawnNearAllies = false; public boolean SpawnNearAllies = false;
public boolean SpawnNearEnemies = false; public boolean SpawnNearEnemies = false;
@ -381,20 +383,12 @@ public abstract class Game extends ListenerComponent implements Lifetimed
public boolean FixSpawnFacing = true; public boolean FixSpawnFacing = true;
public boolean AllowEntitySpectate = true; public boolean AllowEntitySpectate = true;
public boolean TeamMode = false;
public boolean TeamPerSpawn = false;
// Used for "%player% is your teammate" // Used for "%player% is your teammate"
public boolean ShowTeammateMessage = false; public boolean ShowTeammateMessage = false;
public boolean ShowEveryoneSpecChat = true; public boolean ShowEveryoneSpecChat = true;
public boolean ForceTeamSize = true;
public int PlayersPerTeam = 2;
public int TeamCount = 0;
// Split Kit XP // Split Kit XP
public boolean SplitKitXP = false; public boolean SplitKitXP = false;
@ -518,6 +512,8 @@ public abstract class Game extends ListenerComponent implements Lifetimed
new AntiExpOrbModule().register(this); new AntiExpOrbModule().register(this);
new GameSummaryModule() new GameSummaryModule()
.register(this); .register(this);
_teamModule = new GameTeamModule();
_teamModule.register(this);
if (getArcadeManager().IsHotbarHubClock()) if (getArcadeManager().IsHotbarHubClock())
{ {
@ -691,6 +687,11 @@ public abstract class Game extends ListenerComponent implements Lifetimed
return _teamList; return _teamList;
} }
public GameTeamModule getTeamModule()
{
return _teamModule;
}
public int GetCountdown() public int GetCountdown()
{ {
return _countdown; return _countdown;
@ -711,11 +712,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed
_countdownForce = value; _countdownForce = value;
} }
public NautHashMap<GameTeam, ArrayList<Player>> GetTeamPreferences()
{
return _teamPreference;
}
public NautHashMap<Player, Kit> GetPlayerKits() public NautHashMap<Player, Kit> GetPlayerKits()
{ {
return _playerKit; return _playerKit;
@ -1011,38 +1007,13 @@ public abstract class Game extends ListenerComponent implements Lifetimed
// Lobby Scoreboard // Lobby Scoreboard
Manager.GetLobby().AddPlayerToScoreboards(player, team); Manager.GetLobby().AddPlayerToScoreboards(player, team);
// Save Tournament Team
Manager.GetGameTournamentManager().setTournamentTeam(player, team);
// Ensure Valid Kit // Ensure Valid Kit
ValidateKit(player, team); ValidateKit(player, team);
} }
public GameTeam ChooseTeam(Player player) public TeamSelector getTeamSelector()
{ {
if (FillTeamsInOrderToCount != -1) return _teamSelector;
{
for (int i = 0; i < _teamList.size(); i++)
{
if (_teamList.get(i).GetSize() < FillTeamsInOrderToCount)
{
return _teamList.get(i);
}
}
}
GameTeam team = null;
// Random Team
for (int i = 0; i < _teamList.size(); i++)
{
if (team == null || _teamList.get(i).GetSize() < team.GetSize())
{
team = _teamList.get(i);
}
}
return team;
} }
public double GetKillsGems(Player killer, Player killed, boolean assist) public double GetKillsGems(Player killer, Player killed, boolean assist)
@ -1209,18 +1180,14 @@ public abstract class Game extends ListenerComponent implements Lifetimed
public boolean HasKit(Player player, Kit kit) public boolean HasKit(Player player, Kit kit)
{ {
if (!IsAlive(player)) Kit playerKit = GetKit(player);
return false;
if (GetKit(player) == null) return IsAlive(player) && playerKit != null && playerKit.equals(kit);
return false;
return GetKit(player).GetName().equals(kit.GetName());
} }
public void disqualify(Player player) public void disqualify(Player player)
{ {
RemoveTeamPreference(player); _teamModule.getPreferences().remove(player);
GetPlayerKits().remove(player); GetPlayerKits().remove(player);
GetPlayerGems().remove(player); GetPlayerGems().remove(player);
@ -1229,9 +1196,13 @@ public abstract class Game extends ListenerComponent implements Lifetimed
if (team != null) if (team != null)
{ {
if (InProgress()) if (InProgress())
{
SetPlayerState(player, PlayerState.OUT); SetPlayerState(player, PlayerState.OUT);
}
else else
{
team.RemovePlayer(player); team.RemovePlayer(player);
}
} }
Manager.addSpectator(player, false); Manager.addSpectator(player, false);
@ -1420,15 +1391,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed
return DeathMessageType.Simple; return DeathMessageType.Simple;
} }
public boolean CanJoinTeam(GameTeam team)
{
if (TeamMode)
{
return team.GetSize() < PlayersPerTeam;
}
return !Manager.IsTeamBalance() || team.GetSize() < Math.max(1, UtilServer.getPlayers().length / GetTeamList().size());
}
@EventHandler @EventHandler
public final void onFoodLevelChangeEvent(FoodLevelChangeEvent event) public final void onFoodLevelChangeEvent(FoodLevelChangeEvent event)
{ {
@ -1436,52 +1398,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed
// food level changes // food level changes
} }
public GameTeam GetTeamPreference(Player player)
{
for (GameTeam team : _teamPreference.keySet())
{
if (_teamPreference.get(team).contains(player))
return team;
}
return null;
}
public void RemoveTeamPreference(Player player)
{
for (ArrayList<Player> queue : _teamPreference.values())
queue.remove(player);
}
public String GetTeamQueuePosition(Player player)
{
for (ArrayList<Player> queue : _teamPreference.values())
{
for (int i = 0; i < queue.size(); i++)
{
if (queue.get(i).equals(player))
return (i + 1) + "/" + queue.size();
}
}
return "Unknown";
}
public void InformQueuePositions()
{
for (GameTeam team : _teamPreference.keySet())
{
for (Player player : _teamPreference.get(team))
{
UtilPlayer.message(
player,
F.main("Team",
"You are " + F.elem(GetTeamQueuePosition(player)) + " in queue for "
+ F.elem(team.GetFormattedName() + " Team") + "."));
}
}
}
public void AnnounceGame() public void AnnounceGame()
{ {
for (Player player : UtilServer.getPlayers()) for (Player player : UtilServer.getPlayers())
@ -1522,15 +1438,12 @@ public abstract class Game extends ListenerComponent implements Lifetimed
if (WinEffectEnabled && team != null && !team.GetPlacements(true).isEmpty()) if (WinEffectEnabled && team != null && !team.GetPlacements(true).isEmpty())
{ {
List<Player> teamList = new ArrayList<>();
List<Player> otherList = new ArrayList<>();
Map<Player, Integer> teamGemCount = new HashMap<>(); Map<Player, Integer> teamGemCount = new HashMap<>();
teamList.addAll(team.GetPlacements(true).stream() List<Player> teamList = team.GetPlacements(true).stream()
.distinct()
.filter((p) -> !getArcadeManager().isVanished(p)) .filter((p) -> !getArcadeManager().isVanished(p))
// Get the gem count for each member of the team, // Get the gem count for each member of the team,
// and save it to the HashMap, so it can be sorted // and save it to the HashMap, so it can be sorted
.peek((p) -> .peek((p) ->
{ {
Map<String, GemData> gemDataMap = GetGems(p); Map<String, GemData> gemDataMap = GetGems(p);
@ -1544,15 +1457,14 @@ public abstract class Game extends ListenerComponent implements Lifetimed
teamGemCount.put(p, gemCount); teamGemCount.put(p, gemCount);
}) })
// Sort based on gem count in descending order // Sort based on gem count in descending order
.sorted((p1, p2) -> teamGemCount.get(p2) - teamGemCount.get(p1)) .sorted((p1, p2) -> teamGemCount.get(p2) - teamGemCount.get(p1))
.collect(Collectors.toList())); .collect(Collectors.toList());
otherList.addAll(UtilServer.getPlayersCollection() List<Player> otherList = UtilServer.getPlayersCollection()
.stream() .stream()
.distinct()
.filter((p) -> !getArcadeManager().isVanished(p) && !teamList.contains(p)) .filter((p) -> !getArcadeManager().isVanished(p) && !teamList.contains(p))
.collect(Collectors.toList())); .collect(Collectors.toList());
// This sets the "winner" player as the player with the // This sets the "winner" player as the player with the
// most gems, since it's been previously sorted as such // most gems, since it's been previously sorted as such
@ -1631,8 +1543,7 @@ public abstract class Game extends ListenerComponent implements Lifetimed
if (WinEffectEnabled && places != null && !places.isEmpty()) if (WinEffectEnabled && places != null && !places.isEmpty())
{ {
List<Player> teamList = new ArrayList<>(); List<Player> teamList = new ArrayList<>();
List<Player> nonTeamList = new ArrayList<>(); List<Player> nonTeamList = new ArrayList<>(places);
nonTeamList.addAll(places);
Player player = places.get(0); Player player = places.get(0);
nonTeamList.remove(player); nonTeamList.remove(player);

View File

@ -60,17 +60,7 @@ public abstract class RankedTeamGame extends TeamGame
{ {
if (MaxPerTeam != -1) if (MaxPerTeam != -1)
{ {
SetPlayerState(event.GetPlayer(), GameTeam.PlayerState.OUT); disqualify(event.GetPlayer());
Manager.addSpectator(event.GetPlayer(), true);
RemoveTeamPreference(event.GetPlayer());
GetPlayerKits().remove(event.GetPlayer());
GetPlayerGems().remove(event.GetPlayer());
GameTeam team = GetTeam(event.GetPlayer());
if (team != null)
{
team.RemovePlayer(event.GetPlayer());
}
event.GetPlayer().sendMessage(F.main("Game", "This game has reached maximum capacity!")); event.GetPlayer().sendMessage(F.main("Game", "This game has reached maximum capacity!"));
return; return;
} }

View File

@ -20,7 +20,7 @@ import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.build.Build; import nautilus.game.arcade.game.games.build.Build;
import nautilus.game.arcade.game.games.build.BuildData; import nautilus.game.arcade.game.games.build.BuildData;
import nautilus.game.arcade.game.games.build.BuildQuality; import nautilus.game.arcade.game.games.build.BuildQuality;
import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.game.team.TeamRequestsModule;
/** /**
* TeamBuild gamemode for Master builders * TeamBuild gamemode for Master builders
@ -38,11 +38,10 @@ public class TeamBuild extends Build
TeamMode = true; TeamMode = true;
new TeamModule().register(this); new TeamRequestsModule().register(this);
TeamPerSpawn = true; TeamPerSpawn = true;
FillTeamsInOrderToCount = 2;
_winners = new ArrayList<>(); _winners = new ArrayList<>();
} }

View File

@ -32,7 +32,7 @@ import nautilus.game.arcade.game.games.cakewars.CakeWars;
public class CakeBatModule extends CakeModule public class CakeBatModule extends CakeModule
{ {
private static final int DAMAGE_SECONDS = 30; private static final int DAMAGE_SECONDS = 20;
private final Map<Player, Integer> _unsafeSeconds; private final Map<Player, Integer> _unsafeSeconds;
private final Set<Bat> _bats; private final Set<Bat> _bats;

View File

@ -49,7 +49,8 @@ public class CakeSheep extends CakeSpecialItem implements Listener
"After " + C.cRed + "5 seconds" + C.cGray + " she explodes destroying", "After " + C.cRed + "5 seconds" + C.cGray + " she explodes destroying",
"all player placed blocks around her.", "all player placed blocks around her.",
"If she is killed she does not explode.", "If she is killed she does not explode.",
"Warning! Polly has a", C.cRed + "20 second" + C.cGray + " cooldown between uses.") "Warning! Polly has a", C.cRed + "20 second" + C.cGray + " cooldown between uses."
)
.setUnbreakable(true) .setUnbreakable(true)
.build(); .build();
private static final long EXPLOSION_TIME = TimeUnit.SECONDS.toMillis(5); private static final long EXPLOSION_TIME = TimeUnit.SECONDS.toMillis(5);
@ -120,11 +121,12 @@ public class CakeSheep extends CakeSpecialItem implements Listener
if (left <= 0) if (left <= 0)
{ {
Map<Block, Double> blocks = UtilBlock.getInRadius(location, EXPLOSION_RADIUS); Location sheepLocation = sheep.getLocation();
Map<Block, Double> blocks = UtilBlock.getInRadius(sheepLocation, EXPLOSION_RADIUS);
Collection<Block> placedBlocks = _game.getCakePlayerModule().getPlacedBlocks(); Collection<Block> placedBlocks = _game.getCakePlayerModule().getPlacedBlocks();
location.getWorld().playSound(location, Sound.EXPLODE, 2, 1); location.getWorld().playSound(sheepLocation, Sound.EXPLODE, 2, 1);
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, location.add(0, 0.5, 0), null, 0, 1, ViewDist.LONG); UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, sheepLocation.add(0, 0.5, 0), null, 0, 1, ViewDist.LONG);
blocks.entrySet().removeIf(entry -> blocks.entrySet().removeIf(entry ->
{ {
Block block = entry.getKey(); Block block = entry.getKey();
@ -172,10 +174,10 @@ public class CakeSheep extends CakeSpecialItem implements Listener
return true; return true;
}); });
_game.getArcadeManager().GetExplosion().BlockExplosion(blocks.keySet(), location, false); _game.getArcadeManager().GetExplosion().BlockExplosion(blocks.keySet(), sheepLocation, false);
UtilPlayer.getInRadius(location, EXPLOSION_RADIUS).forEach((nearby, scale) -> UtilPlayer.getInRadius(sheepLocation, EXPLOSION_RADIUS).forEach((nearby, scale) ->
{ {
_game.getArcadeManager().GetDamage().NewDamageEvent(nearby, player, null, DamageCause.CUSTOM, 40 * scale, true, true, false, player.getName(), getName()); _game.getArcadeManager().GetDamage().NewDamageEvent(nearby, player, null, sheepLocation, DamageCause.CUSTOM, 40 * scale, true, true, false, player.getName(), getName());
}); });
sheep.remove(); sheep.remove();

View File

@ -3,7 +3,8 @@ package nautilus.game.arcade.game.games.cakewars.modes;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.games.cakewars.CakeWars; import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.game.team.TeamRequestsModule;
import nautilus.game.arcade.game.team.selectors.FillToSelector;
public class CakeWarsDuos extends CakeWars public class CakeWarsDuos extends CakeWars
{ {
@ -14,8 +15,9 @@ public class CakeWarsDuos extends CakeWars
HideTeamSheep = true; HideTeamSheep = true;
ShowTeammateMessage = true; ShowTeammateMessage = true;
_teamSelector = new FillToSelector(this, 2);
new TeamModule() new TeamRequestsModule()
.register(this); .register(this);
} }
} }

View File

@ -22,7 +22,6 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.MapUtil;
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.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager; import mineplex.core.visibility.VisibilityManager;
@ -154,12 +153,6 @@ public class DeathTag extends SoloGame
RestrictKits(); RestrictKits();
} }
@Override
public GameTeam ChooseTeam(Player player)
{
return _runners;
}
@EventHandler @EventHandler
public void updateLights(UpdateEvent event) public void updateLights(UpdateEvent event)
{ {
@ -401,12 +394,6 @@ public class DeathTag extends SoloGame
Scoreboard.draw(); Scoreboard.draw();
} }
@Override
public boolean CanJoinTeam(GameTeam team)
{
return team.GetColor() != ChatColor.RED || team.GetSize() < 1 + UtilServer.getPlayers().length / 8;
}
@Override @Override
public double GetKillsGems(Player killer, Player killed, boolean assist) public double GetKillsGems(Player killer, Player killed, boolean assist)
{ {

View File

@ -9,6 +9,12 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import net.minecraft.server.v1_8_R3.EntityCreature;
import net.minecraft.server.v1_8_R3.NavigationAbstract;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Color; import org.bukkit.Color;
@ -89,6 +95,7 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager; import mineplex.core.visibility.VisibilityManager;
import mineplex.minecraft.game.core.combat.DeathMessageType; import mineplex.minecraft.game.core.combat.DeathMessageType;
import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GamePrepareCountdownCommence; import nautilus.game.arcade.events.GamePrepareCountdownCommence;
@ -109,17 +116,13 @@ import nautilus.game.arcade.game.games.hideseek.kits.KitSeekerRadar;
import nautilus.game.arcade.game.games.hideseek.kits.KitSeekerTNT; import nautilus.game.arcade.game.games.hideseek.kits.KitSeekerTNT;
import nautilus.game.arcade.game.games.hideseek.quests.DisguiseQuestTracker; import nautilus.game.arcade.game.games.hideseek.quests.DisguiseQuestTracker;
import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.game.team.selectors.RatioSelector;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.NullKit; import nautilus.game.arcade.kit.NullKit;
import nautilus.game.arcade.stats.BadHiderStatTracker; import nautilus.game.arcade.stats.BadHiderStatTracker;
import nautilus.game.arcade.stats.HunterKillerStatTracker; import nautilus.game.arcade.stats.HunterKillerStatTracker;
import nautilus.game.arcade.stats.HunterOfTheYearStatTracker; import nautilus.game.arcade.stats.HunterOfTheYearStatTracker;
import nautilus.game.arcade.stats.MeowStatTracker; import nautilus.game.arcade.stats.MeowStatTracker;
import net.minecraft.server.v1_8_R3.EntityCreature;
import net.minecraft.server.v1_8_R3.NavigationAbstract;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class HideSeek extends TeamGame public class HideSeek extends TeamGame
@ -197,6 +200,7 @@ public class HideSeek extends TeamGame
} }
public static final ItemStack PLAYER_ITEM = ItemStackFactory.Instance.CreateStack(Material.SLIME_BALL, (byte) 0, 1, C.cYellowB + "Click Block" + C.cWhiteB + " - " + C.cGreenB + "Change Form"); public static final ItemStack PLAYER_ITEM = ItemStackFactory.Instance.CreateStack(Material.SLIME_BALL, (byte) 0, 1, C.cYellowB + "Click Block" + C.cWhiteB + " - " + C.cGreenB + "Change Form");
private static final double SEEKER_TO_HIDER_RATIO = 0.2;
private GameTeam _hiders; private GameTeam _hiders;
private GameTeam _seekers; private GameTeam _seekers;
@ -467,6 +471,10 @@ public class HideSeek extends TeamGame
_seekers.SetColor(ChatColor.RED); _seekers.SetColor(ChatColor.RED);
_seekers.SetName("Hunters"); _seekers.SetName("Hunters");
_teamSelector = new RatioSelector(_seekers, 0.2);
getTeamModule().setPrioritisePreferences(true);
RestrictKits(); RestrictKits();
} }
@ -1381,26 +1389,6 @@ public class HideSeek extends TeamGame
Scoreboard.draw(); Scoreboard.draw();
} }
@Override
public GameTeam ChooseTeam(Player player)
{
if (CanJoinTeam(_seekers))
return _seekers;
return _hiders;
}
@Override
public boolean CanJoinTeam(GameTeam team)
{
if (team.GetColor() == ChatColor.RED)
{
return team.GetSize() < Math.max(1, GetPlayers(true).size() / 5);
}
return true;
}
@Override @Override
public DeathMessageType GetDeathMessageType() public DeathMessageType GetDeathMessageType()
{ {

View File

@ -29,6 +29,7 @@ import nautilus.game.arcade.game.games.milkcow.kits.KitCow;
import nautilus.game.arcade.game.games.milkcow.kits.KitFarmerJump; import nautilus.game.arcade.game.games.milkcow.kits.KitFarmerJump;
import nautilus.game.arcade.game.games.milkcow.kits.KitSturdyFarmhand; import nautilus.game.arcade.game.games.milkcow.kits.KitSturdyFarmhand;
import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.game.team.selectors.RatioSelector;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.NullKit; import nautilus.game.arcade.kit.NullKit;
import net.minecraft.server.v1_8_R3.EntityCreature; import net.minecraft.server.v1_8_R3.EntityCreature;
@ -150,13 +151,9 @@ public class MilkCow extends SoloGame
_cows = new GameTeam(this, "Cow", ChatColor.RED, _farmers.GetSpawns()); _cows = new GameTeam(this, "Cow", ChatColor.RED, _farmers.GetSpawns());
GetTeamList().add(_cows); GetTeamList().add(_cows);
RestrictKits(); _teamSelector = new RatioSelector(_cows, 0.2);
}
@Override RestrictKits();
public GameTeam ChooseTeam(Player player)
{
return _farmers;
} }
@EventHandler @EventHandler
@ -509,17 +506,6 @@ public class MilkCow extends SoloGame
Scoreboard.draw(); Scoreboard.draw();
} }
@Override
public boolean CanJoinTeam(GameTeam team)
{
int cows = (int)(GetPlayers(true).size()/5);
if (team.GetColor() == ChatColor.RED)
return team.GetSize() < cows;
return team.GetSize() < GetPlayers(true).size() - cows;
}
@EventHandler @EventHandler
public void BucketFill(PlayerBucketFillEvent event) public void BucketFill(PlayerBucketFillEvent event)
{ {

View File

@ -1067,7 +1067,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
@Override @Override
public void disqualify(Player player) public void disqualify(Player player)
{ {
RemoveTeamPreference(player); getTeamModule().getPreferences().remove(player);
GetPlayerKits().remove(player); GetPlayerKits().remove(player);
GetPlayerGems().remove(player); GetPlayerGems().remove(player);

View File

@ -75,7 +75,6 @@ import nautilus.game.arcade.game.games.moba.overtime.OvertimeManager;
import nautilus.game.arcade.game.games.moba.progression.MobaProgression; import nautilus.game.arcade.game.games.moba.progression.MobaProgression;
import nautilus.game.arcade.game.games.moba.shop.MobaShop; import nautilus.game.arcade.game.games.moba.shop.MobaShop;
import nautilus.game.arcade.game.games.moba.structure.tower.TowerManager; import nautilus.game.arcade.game.games.moba.structure.tower.TowerManager;
import nautilus.game.arcade.game.games.moba.training.MobaTraining;
import nautilus.game.arcade.game.games.moba.util.MobaUtil; import nautilus.game.arcade.game.games.moba.util.MobaUtil;
import nautilus.game.arcade.game.modules.CustomScoreboardModule; import nautilus.game.arcade.game.modules.CustomScoreboardModule;
import nautilus.game.arcade.game.modules.EnderPearlModule; import nautilus.game.arcade.game.modules.EnderPearlModule;
@ -203,30 +202,27 @@ public class Moba extends TeamGame
SpectatorSpawn = WorldData.GetCustomLocs("CENTER").get(0); SpectatorSpawn = WorldData.GetCustomLocs("CENTER").get(0);
if (!(this instanceof MobaTraining)) MobaMapType mapType = null;
for (String key : WorldData.GetAllCustomLocs().keySet())
{ {
MobaMapType mapType = null; try
for (String key : WorldData.GetAllCustomLocs().keySet())
{ {
try mapType = MobaMapType.valueOf(key);
{ break;
mapType = MobaMapType.valueOf(key);
break;
}
catch (IllegalArgumentException e)
{
}
} }
catch (IllegalArgumentException e)
if (mapType == null)
{ {
mapType = MobaMapType.HEROES_VALLEY;
} }
registerManager(mapType.createInstance(this));
} }
if (mapType == null)
{
mapType = MobaMapType.HEROES_VALLEY;
}
registerManager(mapType.createInstance(this));
if (Manager.IsRewardStats() && Manager.GetLobby() instanceof NewGameLobbyManager && !Manager.GetGameHostManager().isPrivateServer()) if (Manager.IsRewardStats() && Manager.GetLobby() instanceof NewGameLobbyManager && !Manager.GetGameHostManager().isPrivateServer())
{ {
LeaderboardManager leaderboardManager = Managers.get(LeaderboardManager.class); LeaderboardManager leaderboardManager = Managers.get(LeaderboardManager.class);

View File

@ -49,7 +49,8 @@ public class HotJoiningManager implements Listener
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
GameTeam team = _host.ChooseTeam(player); List<Player> players = _host.GetPlayers(true);
GameTeam team = _host.getTeamSelector().getTeamToJoin(_host.GetTeamList(), 1, (int) Math.ceil(players.size() / 2D), players.size());
if (team == null || team.GetSize() >= 4) if (team == null || team.GetSize() >= 4)
{ {

View File

@ -1,538 +0,0 @@
package nautilus.game.arcade.game.games.moba.training;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Predicate;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.account.permissions.Permission;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilTime;
import mineplex.core.disguise.disguises.DisguiseWither;
import mineplex.core.hologram.Hologram;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilVariant;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
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.moba.Moba;
import nautilus.game.arcade.game.games.moba.MobaPlayer;
import nautilus.game.arcade.game.games.moba.kit.HeroKit;
import nautilus.game.arcade.game.modules.CustomScoreboardModule;
import nautilus.game.arcade.game.modules.TrainingGameModule;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.scoreboard.GameScoreboard;
public class MobaTraining extends Moba
{
public enum Perm implements Permission
{
DEBUG_SKIP_COMMAND,
}
private static final String[] DESCRIPTION = {
"Heroes of GWEN",
"Training Ground"
};
private static final String[][] HELP_HOLOGRAMS =
{
{
C.cYellow + "Welcome to " + C.cGreen + "Heroes of GWEN",
C.cYellow + "Here you can use learn about the game",
C.cYellow + "and test out the Heroes.",
C.cYellow + "If you know what you are doing you can type",
C.cGreen + "/skip" + C.cYellow + " to skip to the end of the tutorial."
},
{
C.cGreen + "Heroes of GWEN" + C.cYellow + " is a MOBA style game.",
C.cYellow + "There are " + C.cGreen + "4" + C.cYellow + " Roles of Heroes to play",
C.cYellow + "with many different Heroes within each role."
},
{
C.cYellow + "This is a " + C.cGreen + "Tower",
C.cYellow + "You need to destroy these in order to be able",
C.cYellow + "to attack the other team's " + C.cGreen + "Wither" + C.cYellow + " to win the game."
},
{
C.cYellow + "This is a " + C.cGreen + "Beacon",
C.cYellow + "You can capture these for your team.",
C.cYellow + "Capturing and holding these increases the amount",
C.cYellow + "of " + C.cGold + "Gold" + C.cYellow + " your team earns."
},
{
C.cYellow + "This is the " + C.cDRedB + "Pumpkin King",
C.cYellow + "He spawns at " + C.cGreen + "10 minutes" + C.cYellow + " into the game.",
C.cYellow + "The team that kills him will be given increased",
C.cYellow + "regeneration and damage."
},
{
C.cYellow + "Once all of the enemy's towers are destroyed",
C.cYellow + "your team can attack their " + C.cGreen + "Wither",
C.cYellow + "Once the Wither is killed the game is over!"
},
{
C.cGreen + "Minions" + C.cYellow + " spawn for both teams periodically",
C.cYellow + "and make their way to each other's bases.",
C.cYellow + "They will fight each other and help destroy enemy Towers."
},
{
C.cYellow + "With the " + C.cGold + "Gold" + C.cYellow + " you earn you can",
C.cYellow + "spend it on upgrades for your weapons and armor.",
C.cYellow + "You can do this via the gold ingot in your inventory",
C.cYellow + "during the game or by clicking on the Villager."
},
{
C.cYellow + "Now you know the basics",
C.cYellow + "Click on this NPC to select a Hero",
C.cYellow + "to try out!"
}
};
private static final long GAME_TIME = TimeUnit.HOURS.toMillis(3);
private static final int GOLD = 100000;
private Location _borderA;
private Location _borderB;
private List<Location> _selectKit;
private final Map<LivingEntity, Location> _entities = new HashMap<>();
public MobaTraining(ArcadeManager manager)
{
super(manager, GameType.MOBATraining, DESCRIPTION);
DamageTeamSelf = true;
DamageFall = false;
DeathOut = false;
DeathSpectateSecs = 2;
PrepareTime = 500;
GiveClock = false;
HideTeamSheep = true;
HungerSet = 20;
// Prevent the wither from being damaged as well as to not spawn the pumpkin king
_boss.setDummyBosses(true);
_overtimeManager.disableOvertime();
_minion.disableMinions();
Predicate<Player> safeFunction = player -> UtilAlg.inBoundingBox(player.getLocation(), _borderA, _borderB);
Function<Player, GameTeam> teamFunction = player -> GetTeam(ChatColor.GRAY);
new TrainingGameModule()
.setGiveReturnToSpawn(false)
.setSkillFunction(safeFunction)
.setDamageFunction(safeFunction)
.setTeamFunction(teamFunction)
.register(this);
new CustomScoreboardModule()
.setSidebar(this::write)
.setPrefix((perspective, subject) ->
{
if (!IsAlive(subject))
{
return C.cGray;
}
GameTeam team = GetTeam(subject);
return team.GetColor().toString();
})
.setSuffix((perspective, subject) ->
{
GameState state = GetState();
GameTeam perspectiveTeam = GetTeam(perspective);
GameTeam subjectTeam = GetTeam(subject);
if (!IsAlive(subject) || perspectiveTeam == null || subjectTeam == null)
{
return "";
}
MobaPlayer mobaPlayer = getMobaData(subject);
String suffix;
if (state == GameState.Prepare && !perspectiveTeam.equals(subjectTeam))
{
suffix = C.cYellow + " Unknown";
} else if (mobaPlayer == null || mobaPlayer.getKit() == null)
{
suffix = C.cYellow + " Selecting";
} else
{
suffix = mobaPlayer.getRole().getChatColor() + " [" + mobaPlayer.getKit().GetName() + "]";
}
return suffix + C.Reset;
})
.setUnderNameObjective(C.cRed + "")
.setUnderName((perspective, subject) ->
(int) (Math.ceil(subject.getHealth() / 2D)))
.register(this);
registerDebugCommand("skip", Perm.DEBUG_SKIP_COMMAND, PermissionGroup.PLAYER, (caller, args) ->
{
if (!safeFunction.test(caller))
{
caller.teleport(GetTeam(ChatColor.YELLOW).GetSpawn());
}
});
}
private void write(Player player, GameScoreboard scoreboard)
{
boolean alive = IsAlive(player);
MobaPlayer mobaPlayer = getMobaData(player);
if (mobaPlayer != null && mobaPlayer.getRole() != null && mobaPlayer.getKit() != null)
{
scoreboard.writeNewLine();
scoreboard.write(C.cYellowB + "Hero");
scoreboard.write(mobaPlayer.getKit().GetName() + " (" + mobaPlayer.getRole().getName() + C.cWhite + ")");
}
scoreboard.writeNewLine();
// Gold
scoreboard.write(C.cGoldB + "Your Gold");
if (alive)
{
int gold = _goldManager.getGold(player);
scoreboard.write(String.valueOf(gold));
}
else
{
scoreboard.write("None");
}
scoreboard.writeNewLine();
scoreboard.write(C.cYellowB + "Time");
scoreboard.write(UtilTime.MakeStr(System.currentTimeMillis() - GetStateTime()));
scoreboard.writeNewLine();
}
@Override
public void ParseData()
{
super.ParseData();
List<Location> locations = WorldData.GetCustomLocs("PVP_AREA");
_borderA = locations.get(0);
_borderB = locations.get(1);
_selectKit = WorldData.GetCustomLocs("SELECT_KIT");
SpectatorSpawn = _selectKit.get(0);
}
@EventHandler
public void adjustSpawns(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
{
return;
}
for (Location location : GetTeam(ChatColor.YELLOW).GetSpawns())
{
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, SpectatorSpawn)));
}
for (Location location : GetTeam(ChatColor.GRAY).GetSpawns())
{
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, SpectatorSpawn)));
}
Location center = WorldData.GetCustomLocs("CENTER").get(0);
for (Location location : WorldData.GetDataLocs("LIME"))
{
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, center)));
}
}
@EventHandler
public void customTeamGeneration(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Recruit)
{
return;
}
{
GameTeam players = GetTeam(ChatColor.RED);
players.SetColor(ChatColor.GRAY);
players.SetName("Players");
players.setDisplayName(C.cYellowB + "Players");
}
{
GameTeam players = GetTeam(ChatColor.GREEN);
players.SetColor(ChatColor.YELLOW);
players.SetName("Players");
players.setDisplayName(C.cYellowB + "Players");
}
}
@Override
public GameTeam ChooseTeam(Player player)
{
return GetTeam(ChatColor.GRAY);
}
@Override
public void EndCheck()
{
if (!IsLive())
{
return;
}
if (UtilTime.elapsed(GetStateTime(), GAME_TIME))
{
SetState(GameState.Dead);
}
}
@Override
public void SetKit(Player player, Kit kit, boolean announce)
{
super.SetKit(player, kit, announce);
player.setFlying(false);
player.setAllowFlight(false);
}
@EventHandler
public void giveGold(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
{
return;
}
for (Player player : GetPlayers(true))
{
if (_goldManager.getGold(player) < 100)
{
_goldManager.addGold(player, GOLD);
}
}
}
@EventHandler
public void playerJoin(PlayerJoinEvent event)
{
if (InProgress())
{
_playerData.add(new MobaPlayer(event.getPlayer()));
}
}
@EventHandler
public void spawnTutorial(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Live)
{
return;
}
CreatureAllowOverride = true;
spawnHelpText();
spawnDummies();
spawnNPCs();
for (LivingEntity entity : _entities.keySet())
{
entity.setCustomNameVisible(true);
entity.setRemoveWhenFarAway(false);
UtilEnt.vegetate(entity);
UtilEnt.setFakeHead(entity, true);
UtilEnt.silence(entity, true);
UtilEnt.ghost(entity, true, false);
}
CreatureAllowOverride = false;
}
@EventHandler
public void entityDamage(CustomDamageEvent event)
{
if (!_entities.containsKey(event.GetDamageeEntity()))
{
return;
}
event.SetCancelled("NPC");
String name = event.GetDamageeEntity().getCustomName();
if (name != null && name.contains("Select A Hero"))
{
openMenu(event.GetDamagerPlayer(false));
}
}
@EventHandler
public void entityCombust(EntityCombustEvent event)
{
if (!_entities.containsKey(event.getEntity()))
{
return;
}
event.setCancelled(true);
}
@EventHandler
public void entityInteract(PlayerInteractAtEntityEvent event)
{
if (isKitSelectionEntity(event.getRightClicked()))
{
openMenu(event.getPlayer());
}
}
@EventHandler
public void updateEntityLocation(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
for (Entry<LivingEntity, Location> entry : _entities.entrySet())
{
LivingEntity entity = entry.getKey();
Location location = entry.getValue();
((CraftEntity) entity).getHandle().setPosition(location.getX(), location.getY(), location.getZ());
}
}
private void openMenu(Player player)
{
if (player == null)
{
return;
}
new SelectKitMenu(Manager).open(player);
}
private boolean isKitSelectionEntity(Entity entity)
{
return entity.getCustomName() != null && entity.getCustomName().contains("Select A Hero");
}
private void spawnHelpText()
{
Map<String, Location> locationMap = getLocationStartsWith("HELP");
for (Entry<String, Location> entry : locationMap.entrySet())
{
String[] split = entry.getKey().split(" ");
String index = split[1];
int indexInt = Integer.parseInt(index);
String[] display = HELP_HOLOGRAMS[indexInt - 1];
new Hologram(Manager.getHologramManager(), entry.getValue(), true, display).start();
}
}
private void spawnDummies()
{
{
Skeleton skeleton = UtilVariant.spawnWitherSkeleton(WorldData.GetCustomLocs("PUMPKIN_KING").get(0));
skeleton.setCustomName(C.cDRedB + "Pumpkin King");
skeleton.getEquipment().setHelmet(new ItemStack(Material.PUMPKIN));
_entities.put(skeleton, skeleton.getLocation());
}
{
Location location = WorldData.GetCustomLocs("DUMMY_WITHER").get(0);
ArmorStand stand = location.getWorld().spawn(location, ArmorStand.class);
stand.setGravity(false);
DisguiseWither disguise = new DisguiseWither(stand);
disguise.setName(C.cAqua + "Blue's Wither");
disguise.setCustomNameVisible(true);
Manager.GetDisguise().disguise(disguise);
_entities.put(stand, stand.getLocation());
}
{
Location location = WorldData.GetCustomLocs("DUMMY_SHOP").get(0);
Villager villager = location.getWorld().spawn(location, Villager.class);
villager.setProfession(Profession.LIBRARIAN);
villager.setCustomName(C.cGoldB + "Gold Upgrades");
_entities.put(villager, villager.getLocation());
}
}
private void spawnNPCs()
{
for (Location location : _selectKit)
{
Villager villager = WorldData.World.spawn(location, Villager.class);
villager.setCustomName(C.cYellowB + "Select A Hero");
UtilEnt.CreatureLook(villager, GetTeam(ChatColor.YELLOW).GetSpawns().get(0));
_entities.put(villager, villager.getLocation());
}
}
public void teleportIntoArena(Player player, HeroKit kit)
{
Kit currentKit = GetKit(player);
if (currentKit == null || !kit.equals(currentKit))
{
_shop.clearPurchases(player);
}
player.teleport(UtilAlg.Random(WorldData.GetDataLocs("LIME")));
SetPlayerTeam(player, GetTeam(ChatColor.YELLOW), true);
SetKit(player, kit, true);
}
@EventHandler
public void informLobbyPlayers(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC_20 || InProgress())
{
return;
}
Announce(F.main("Game", "Waiting for more players before starting the training area."), false);
}
}

View File

@ -1,75 +0,0 @@
package nautilus.game.arcade.game.games.moba.training;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilUI;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.menu.Button;
import mineplex.core.menu.Menu;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.moba.kit.HeroKit;
import nautilus.game.arcade.kit.Perk;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
public class SelectKitMenu extends Menu<ArcadeManager>
{
public SelectKitMenu(ArcadeManager plugin)
{
super("Select A Hero", plugin);
}
@Override
protected Button[] setUp(Player player)
{
MobaTraining moba = (MobaTraining) getPlugin().GetGame();
Button[] buttons = new Button[36];
int[] slots = UtilUI.getIndicesFor(moba.GetKits().length, 1);
int i = 0;
for (int slot : slots)
{
HeroKit kit = (HeroKit) moba.GetKits()[i++];
if (!kit.isVisible())
{
continue;
}
ItemBuilder builder = new ItemBuilder(kit.getSkinData().getSkull());
builder.setTitle(C.cGreen + kit.GetName());
builder.addLore("", "Skills:");
for (Perk perk : kit.GetPerks())
{
builder.addLore(C.cWhite + " - " + C.cYellow + perk.GetName());
}
builder.addLore("", C.cGreen + "Click to join the arena with this kit!");
buttons[slot] = new SelectKitButton(builder.build(), getPlugin(), kit);
}
return buttons;
}
private class SelectKitButton extends Button<ArcadeManager>
{
private final HeroKit _kit;
private SelectKitButton(ItemStack item, ArcadeManager plugin, HeroKit kit)
{
super(item, plugin);
_kit = kit;
}
@Override
public void onClick(Player player, ClickType clickType)
{
((MobaTraining) getPlugin().GetGame()).teleportIntoArena(player, _kit);
}
}
}

View File

@ -17,7 +17,7 @@ import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.game.team.TeamRequestsModule;
/** /**
* TeamSkyfall * TeamSkyfall
@ -33,8 +33,7 @@ public class TeamSkyfall extends Skyfall
super(manager, GameType.SkyfallTeams); super(manager, GameType.SkyfallTeams);
PlayersPerTeam = 2; PlayersPerTeam = 2;
FillTeamsInOrderToCount = 2;
SpawnNearAllies = true; SpawnNearAllies = true;
DamageTeamSelf = false; DamageTeamSelf = false;
@ -45,7 +44,7 @@ public class TeamSkyfall extends Skyfall
HideTeamSheep = true; HideTeamSheep = true;
registerModule(new TeamModule()); registerModule(new TeamRequestsModule());
} }
@Override @Override

View File

@ -14,7 +14,7 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.skywars.trackers.TNTStatTracker; import nautilus.game.arcade.game.games.skywars.trackers.TNTStatTracker;
import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.game.team.TeamRequestsModule;
import nautilus.game.arcade.stats.DeathBomberStatTracker; import nautilus.game.arcade.stats.DeathBomberStatTracker;
import nautilus.game.arcade.stats.WinWithoutOpeningChestStatTracker; import nautilus.game.arcade.stats.WinWithoutOpeningChestStatTracker;
import nautilus.game.arcade.stats.WinWithoutWearingArmorStatTracker; import nautilus.game.arcade.stats.WinWithoutWearingArmorStatTracker;
@ -56,9 +56,7 @@ 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!"
}); });
FillTeamsInOrderToCount = 2;
SpawnNearAllies = true; SpawnNearAllies = true;
DamageTeamSelf = false; DamageTeamSelf = false;
@ -69,7 +67,7 @@ public class TeamSkywars extends Skywars
TeamPerSpawn = true; TeamPerSpawn = true;
ShowTeammateMessage = true; ShowTeammateMessage = true;
new TeamModule() new TeamRequestsModule()
.register(this); .register(this);
} }

View File

@ -6,21 +6,18 @@ import java.util.List;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.Pair; import mineplex.core.common.Pair;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.modules.TeamArmorModule; import nautilus.game.arcade.game.modules.TeamArmorModule;
import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.game.team.TeamRequestsModule;
import nautilus.game.arcade.managers.chat.ChatStatData; import nautilus.game.arcade.managers.chat.ChatStatData;
import nautilus.game.arcade.stats.FreeKitWinStatTracker; import nautilus.game.arcade.stats.FreeKitWinStatTracker;
import nautilus.game.arcade.stats.KillFastStatTracker; import nautilus.game.arcade.stats.KillFastStatTracker;
@ -36,7 +33,6 @@ public class TeamSuperSmash extends SuperSmash
super(manager, GameType.SmashTeams, new String[] { "Each player has 3 respawns", "Attack to restore hunger!", "Last team alive wins!" }); super(manager, GameType.SmashTeams, new String[] { "Each player has 3 respawns", "Attack to restore hunger!", "Last team alive wins!" });
PlayersPerTeam = 2; PlayersPerTeam = 2;
FillTeamsInOrderToCount = 2;
SpawnNearAllies = true; SpawnNearAllies = true;
DamageTeamSelf = false; DamageTeamSelf = false;
@ -46,7 +42,7 @@ public class TeamSuperSmash extends SuperSmash
TeamMode = true; TeamMode = true;
ShowTeammateMessage = true; ShowTeammateMessage = true;
new TeamModule().register(this); new TeamRequestsModule().register(this);
registerStatTrackers(new WinWithoutDyingStatTracker(this, "MLGPro"), new FreeKitWinStatTracker(this), new OneVThreeStatTracker(this), new KillFastStatTracker(this, 3, 10, "TripleKill"), registerStatTrackers(new WinWithoutDyingStatTracker(this, "MLGPro"), new FreeKitWinStatTracker(this), new OneVThreeStatTracker(this), new KillFastStatTracker(this, 3, 10, "TripleKill"),
new RecoveryMasterStatTracker(this)); new RecoveryMasterStatTracker(this));

View File

@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.game.team.TeamRequestsModule;
public class SurvivalGamesNewTeams extends SurvivalGamesNew public class SurvivalGamesNewTeams extends SurvivalGamesNew
{ {
@ -26,7 +26,6 @@ public class SurvivalGamesNewTeams extends SurvivalGamesNew
super(manager, GameType.SurvivalGamesTeams, DESCRIPTION); super(manager, GameType.SurvivalGamesTeams, DESCRIPTION);
PlayersPerTeam = 2; PlayersPerTeam = 2;
FillTeamsInOrderToCount = 2;
TeamMode = true; TeamMode = true;
ShowTeammateMessage = true; ShowTeammateMessage = true;
@ -37,7 +36,7 @@ public class SurvivalGamesNewTeams extends SurvivalGamesNew
DontAllowOverfill = true; DontAllowOverfill = true;
new TeamModule() new TeamRequestsModule()
.register(this); .register(this);
} }

View File

@ -618,7 +618,7 @@ public abstract class UHC extends Game
double border = _border.getMaxCords(); double border = _border.getMaxCords();
// Solo Game // Solo Game
if (FillTeamsInOrderToCount == -1) if (!TeamMode)
{ {
List<Player> players = GetPlayers(true); List<Player> players = GetPlayers(true);
GameTeam gameTeam = GetTeamList().get(0); GameTeam gameTeam = GetTeamList().get(0);
@ -1798,7 +1798,7 @@ public abstract class UHC extends Game
if (killer.equals(killed)) if (killer.equals(killed))
return 0; return 0;
if (GetTeam(killer) != null && GetTeam(killed) != null && GetTeam(killer).equals(GetTeam(killed)) && FillTeamsInOrderToCount != -1) if (GetTeam(killer) != null && GetTeam(killed) != null && GetTeam(killer).equals(GetTeam(killed)) && TeamMode)
return 0; return 0;
if (assist) if (assist)

View File

@ -12,7 +12,7 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.game.team.TeamRequestsModule;
public class UHCTeams extends UHC public class UHCTeams extends UHC
{ {
@ -31,13 +31,12 @@ public class UHCTeams extends UHC
{ {
super(manager, type, speedMode); super(manager, type, speedMode);
FillTeamsInOrderToCount = 2;
DamageTeamSelf = false; DamageTeamSelf = false;
DontAllowOverfill = true; DontAllowOverfill = true;
ShowTeammateMessage = true; ShowTeammateMessage = true;
// Load the Team Module // Load the Team Module
new TeamModule().register(this); new TeamRequestsModule().register(this);
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)

View File

@ -70,6 +70,7 @@ import nautilus.game.arcade.game.games.wither.kit.KitHumanMedic;
import nautilus.game.arcade.game.games.wither.kit.KitWitherMinion; import nautilus.game.arcade.game.games.wither.kit.KitWitherMinion;
import nautilus.game.arcade.game.modules.TeamArmorModule; import nautilus.game.arcade.game.modules.TeamArmorModule;
import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.game.team.selectors.RatioSelector;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.NullKit; import nautilus.game.arcade.kit.NullKit;
import nautilus.game.arcade.kit.perks.data.IBlockRestorer; import nautilus.game.arcade.kit.perks.data.IBlockRestorer;
@ -201,28 +202,8 @@ public class WitherGame extends TeamGame implements IBlockRestorer
} }
} }
} }
}
@EventHandler _teamSelector = new RatioSelector(_withers, 0.25);
public void teamBalance(UpdateEvent event)
{
if (!InProgress())
return;
if (event.getType() != UpdateType.FAST)
return;
// Not Enough Players
if (_runners.GetPlayers(true).size() < 2)
return;
// Enough Withers
if (_withers.GetPlayers(true).size() * WITHER_FACTOR >= _runners
.GetPlayers(true).size())
return;
Player player = UtilAlg.Random(_runners.GetPlayers(true));
setWither(player, true);
} }
// Cancel wither shooting in waiting lobby // Cancel wither shooting in waiting lobby
@ -493,31 +474,6 @@ public class WitherGame extends TeamGame implements IBlockRestorer
Scoreboard.draw(); Scoreboard.draw();
} }
@Override
public GameTeam ChooseTeam(Player player)
{
if (CanJoinTeam(_withers))
return _withers;
return _runners;
}
@Override
public boolean CanJoinTeam(GameTeam team)
{
if (team.equals(_withers))
{
return team.GetSize() < getRequiredWithers();
}
return team.GetSize() < GetPlayers(true).size() - getRequiredWithers();
}
public int getRequiredWithers()
{
return (int) (GetPlayers(true).size() / WITHER_FACTOR);
}
@EventHandler @EventHandler
public void witherMovement(UpdateEvent event) public void witherMovement(UpdateEvent event)
{ {

View File

@ -4,6 +4,9 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import net.minecraft.server.v1_8_R3.EntityCreature;
import net.minecraft.server.v1_8_R3.NavigationAbstract;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -22,23 +25,25 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg; 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.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager; import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.GameTeam.PlayerState; import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.games.zombiesurvival.kits.*; import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.games.zombiesurvival.kits.KitSurvivorArcher;
import nautilus.game.arcade.game.games.zombiesurvival.kits.KitSurvivorKnight;
import nautilus.game.arcade.game.games.zombiesurvival.kits.KitSurvivorRogue;
import nautilus.game.arcade.game.games.zombiesurvival.kits.KitUndeadAlpha;
import nautilus.game.arcade.game.games.zombiesurvival.kits.KitUndeadZombie;
import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.NullKit; import nautilus.game.arcade.kit.NullKit;
import net.minecraft.server.v1_8_R3.EntityCreature;
import net.minecraft.server.v1_8_R3.NavigationAbstract;
public class ZombieSurvival extends SoloGame public class ZombieSurvival extends SoloGame
{ {
@ -114,18 +119,13 @@ public class ZombieSurvival extends SoloGame
_survivors.SetName("Survivors"); _survivors.SetName("Survivors");
//Undead Team //Undead Team
_undead = new GameTeam(this, "Undead", ChatColor.RED, WorldData.GetDataLocs("RED")); _undead = new GameTeam(this, "Undead", ChatColor.RED, WorldData.GetDataLocs("RED"));
GetTeamList().add(_undead); _undead.SetVisible(false);
AddTeam(_undead);
RestrictKits(); RestrictKits();
} }
@Override
public GameTeam ChooseTeam(Player player)
{
return _survivors;
}
@EventHandler @EventHandler
public void UpdateChasers(UpdateEvent event) public void UpdateChasers(UpdateEvent event)
{ {
@ -373,15 +373,4 @@ public class ZombieSurvival extends SoloGame
Scoreboard.draw(); Scoreboard.draw();
} }
@Override
public boolean CanJoinTeam(GameTeam team)
{
if (team.GetColor() == ChatColor.RED)
{
return team.GetSize() < 1 + UtilServer.getPlayers().length/25;
}
return true;
}
} }

View File

@ -0,0 +1,252 @@
package nautilus.game.arcade.game.team;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import mineplex.core.Managers;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.friend.FriendManager;
import mineplex.core.party.Party;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.modules.Module;
public class GameTeamModule extends Module
{
private final Map<Player, GameTeam> _preferences;
private List<GameTeam> _visibleTeams;
private int _target;
private boolean _prioritisePreferences;
public GameTeamModule()
{
_preferences = new HashMap<>();
}
@Override
public void cleanup()
{
_preferences.clear();
}
public GameTeamModule setPlayersPerTeam(int target)
{
_target = target;
return null;
}
public GameTeamModule setPrioritisePreferences(boolean prioritise)
{
_prioritisePreferences = prioritise;
return null;
}
@EventHandler(priority = EventPriority.LOWEST)
public void assignTeams(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
{
return;
}
Game game = getGame();
FriendManager friendManager = Managers.require(FriendManager.class);
boolean autoBalance = game.getArcadeManager().IsTeamBalance();
List<Player> players = game.getArcadeManager().getValidPlayersForGameStart();
_visibleTeams = game.GetTeamList().stream()
.filter(GameTeam::GetVisible)
.collect(Collectors.toList());
// Only one team. Add all players to that, no need to balance.
if (_visibleTeams.size() == 1)
{
GameTeam team = _visibleTeams.get(0);
for (Player player : players)
{
game.SetPlayerTeam(player, team, true);
}
return;
}
int target;
int total = players.size();
if (_target > 0)
{
target = _target;
}
else
{
target = (int) Math.ceil((double) total / _visibleTeams.size());
}
// Step 1 - Team Preference (If prioritised)
// This would be set in games where /team is used.
if (_prioritisePreferences)
{
assignPreferences(target, total);
}
// Step 2 - Parties
// Only worry about parties if autoBalance is on, otherwise we don't care
if (autoBalance)
{
for (Party party : game.getArcadeManager().getPartyManager().getAllParties())
{
List<Player> partyMembers = new ArrayList<>(party.getMembers());
// Remove party members that are already on a team
partyMembers.removeIf(other -> game.GetTeam(other) != null);
// Keep going until we just have 1 party member left
while (partyMembers.size() > 1)
{
int partySize = Math.min(partyMembers.size(), target);
GameTeam team = getTeamToJoin(partySize, target, total);
// Fill the team up as far as it can
for (int i = 0; i < partySize; i++)
{
game.SetPlayerTeam(partyMembers.remove(0), team, true);
}
}
}
}
// No balancing no need to worry about unbalanced teams
else if (_target == 0)
{
target = Integer.MAX_VALUE;
}
// Step 2 - Team Preferences (Again)
assignPreferences(target, total);
// Now we worry around everyone else
for (Player player : players)
{
GameTeam playerTeam = game.GetTeam(player);
// Already in a team
if (playerTeam != null)
{
continue;
}
// Step 3 - Friends
List<Player> friends = friendManager.Get(player).getFriends().stream()
.filter(friendStatus -> friendStatus.Online)
.map(friendStatus -> UtilPlayer.searchExact(friendStatus.UUID))
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (!friends.isEmpty())
{
friends = new ArrayList<>(friends);
// Remove friends that are already on a team
friends.removeIf(other -> game.GetTeam(other) != null);
// Friends operate similarly to parties however we don't need to worry about getting everyone
// on a team with at least one friend since these are friends of the current iterating player.
if (!friends.isEmpty())
{
int friendSize = Math.min(friends.size(), target) - 1;
GameTeam team = getTeamToJoin(friendSize, target, total);
game.SetPlayerTeam(player, team, true);
// Fill the team up as far as it can
for (int i = 0; i < friendSize; i++)
{
game.SetPlayerTeam(friends.get(i), team, true);
}
continue;
}
}
// Step 4 - Emptiest
GameTeam team = getTeamToJoin(1, target, total);
if (team == null)
{
continue;
}
game.SetPlayerTeam(player, team, true);
}
}
private void assignPreferences(int target, int total)
{
_preferences.forEach((player, preference) ->
{
Bukkit.broadcastMessage(player.getName() + " = " + preference.getDisplayName());
if (getGame().getTeamSelector().canJoinTeam(preference, 1, target, total))
{
Bukkit.broadcastMessage("Set!");
getGame().SetPlayerTeam(player, preference, true);
}
});
_preferences.clear();
}
public void addPlayerQueue(Player player, GameTeam team)
{
GameTeam previous = _preferences.put(player, team);
if (team.equals(previous))
{
player.sendMessage(F.main("Game", "You are already queued for " + F.name(team.GetColor() + team.getDisplayName()) + "."));
}
else
{
player.sendMessage(F.main("Game", "You are now queued for " + F.name(team.GetColor() + team.getDisplayName()) + "."));
}
}
private GameTeam getTeamToJoin(int desiredAmount, int target, int total)
{
return getGame().getTeamSelector().getTeamToJoin(_visibleTeams, desiredAmount, target, total);
}
public void clearQueue(GameTeam team)
{
if (team == null)
{
return;
}
_preferences.values().removeIf(team::equals);
}
public int getPlayersQueued(GameTeam team)
{
return (int) _preferences.values().stream()
.filter(team::equals)
.count();
}
public Map<Player, GameTeam> getPreferences()
{
return _preferences;
}
}

View File

@ -1,4 +1,4 @@
package nautilus.game.arcade.game.modules; package nautilus.game.arcade.game.team;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -7,10 +7,12 @@ import java.util.UUID;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import mineplex.core.account.permissions.Permission;
import mineplex.core.command.CommandBase;
import mineplex.core.command.ICommand;
import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.HoverEvent; import mineplex.core.common.jsonchat.HoverEvent;
import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.jsonchat.JsonMessage;
@ -19,19 +21,83 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.modules.Module;
public class TeamModule extends Module public class TeamRequestsModule extends Module
{ {
private final Map<UUID, UUID> _teamRequests; public enum Perm implements Permission
{
TEAM_COMMAND
}
public TeamModule() private final Map<UUID, UUID> _teamRequests;
private ICommand _teamCommand;
public TeamRequestsModule()
{ {
_teamRequests = new HashMap<>(); _teamRequests = new HashMap<>();
} }
@Override
protected void setup()
{
_teamCommand = new CommandBase<ArcadeManager>(getGame().getArcadeManager(), Perm.TEAM_COMMAND, "team")
{
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 0)
{
caller.sendMessage(F.main("Game", "/team <player>"));
return;
}
if (getGame().GetState() != GameState.Recruit)
{
caller.sendMessage(F.main("Game", "You cannot send team requests at this time!"));
return;
}
//Observer
if (getGame().getArcadeManager().IsObserver(caller))
{
caller.sendMessage(F.main("Game", "Spectators cannot partake in games."));
return;
}
Player target = UtilPlayer.searchOnline(caller, args[0], true);
if (target == null)
{
return;
}
if (caller.equals(target))
{
caller.sendMessage(F.main("Game", "You can't team with yourself!"));
return;
}
selectTeamMate(caller, target);
}
};
getGame().getArcadeManager().addCommand(_teamCommand);
getGame().getTeamModule().setPrioritisePreferences(true);
}
@Override
public void cleanup()
{
_teamRequests.clear();
getGame().getArcadeManager().removeCommand(_teamCommand);
}
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void teamSelectInteract(PlayerInteractEntityEvent event) public void teamSelectInteract(PlayerInteractEntityEvent event)
{ {
@ -52,85 +118,36 @@ public class TeamModule extends Module
selectTeamMate(player, (Player) event.getRightClicked()); selectTeamMate(player, (Player) event.getRightClicked());
} }
@EventHandler
public void teamSelectCommand(PlayerCommandPreprocessEvent event)
{
if (!event.getMessage().toLowerCase().startsWith("/team "))
{
return;
}
event.setCancelled(true);
if (getGame().GetState() != GameState.Recruit)
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot send team requests at this time!"));
return;
}
//Observer
if (getGame().getArcadeManager().IsObserver(event.getPlayer()))
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "Spectators cannot partake in games."));
return;
}
Player target = UtilPlayer.searchOnline(event.getPlayer(), event.getMessage().split(" ")[1], true);
if (target == null)
{
return;
}
if (event.getPlayer().equals(target))
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You can't team with yourself!"));
return;
}
selectTeamMate(event.getPlayer(), target);
}
private void selectTeamMate(Player player, Player ally) private void selectTeamMate(Player player, Player ally)
{ {
GameTeam playerTeam = getGame().GetTeam(player); Map<Player, GameTeam> preferences = getGame().getTeamModule().getPreferences();
GameTeam allyTeam = getGame().GetTeam(ally); GameTeam playerTeam = preferences.get(player);
GameTeam allyTeam = preferences.get(ally);
if (playerTeam != null && playerTeam.equals(allyTeam))
{
return;
}
//Accept Invite //Accept Invite
if (_teamRequests.containsKey(ally.getUniqueId()) && _teamRequests.get(ally.getUniqueId()).equals(player.getUniqueId())) if (player.getUniqueId().equals(_teamRequests.get(ally.getUniqueId())))
{ {
//Remove Prefs //Remove Prefs
_teamRequests.remove(player.getUniqueId()); _teamRequests.remove(player.getUniqueId());
_teamRequests.remove(ally.getUniqueId()); _teamRequests.remove(ally.getUniqueId());
//Inform //Inform
UtilPlayer.message(player, F.main("Game", "You accepted " + F.name(ally.getName()) + "'s Team Request!")); player.sendMessage(F.main("Game", "You accepted " + F.name(ally.getName()) + "'s " + F.elem("Team Request") + "!"));
UtilPlayer.message(ally, F.main("Game", F.name(player.getName()) + " accepted your Team Request!")); ally.sendMessage(F.main("Game", F.name(player.getName()) + " accepted your " + F.elem("Team Request") + "!"));
//Leave Old Teams // This ensures there is always a free team
if (playerTeam != null) getGame().getTeamModule().clearQueue(playerTeam);
{ getGame().getTeamModule().clearQueue(allyTeam);
playerTeam.DisbandTeam();
}
if (allyTeam != null)
{
allyTeam.DisbandTeam();
}
//Get Team
GameTeam team = getEmptyTeam(); GameTeam team = getEmptyTeam();
if (team == null) preferences.put(player, team);
{ preferences.put(ally, team);
return;
}
team.setDisplayName(player.getName() + " & " + ally.getName());
//Join Team
getGame().SetPlayerTeam(player, team, true);
getGame().SetPlayerTeam(ally, team, true);
} }
//Send Invite //Send Invite
else else
@ -142,12 +159,12 @@ public class TeamModule extends Module
} }
//Inform Player //Inform Player
UtilPlayer.message(player, F.main("Game", "You sent a " + F.elem("Team Request") + " to " + F.name(ally.getName()) + "!")); player.sendMessage(F.main("Game", "You sent a " + F.elem("Team Request") + " to " + F.name(ally.getName()) + "!"));
//Inform Target //Inform Target
if (Recharge.Instance.use(player, "Team Req " + ally.getName(), 2000, false, false)) if (Recharge.Instance.use(player, "Team Req " + ally.getName(), 2000, false, false))
{ {
UtilPlayer.message(ally, F.main("Game", F.name(player.getName()) + " sent you a " + F.elem("Team Request") + "!")); ally.sendMessage(F.main("Game", F.name(player.getName()) + " sent you a " + F.elem("Team Request") + "!"));
new JsonMessage(F.main("Game", F.elem(C.Bold + "CLICK HERE") + " to join their team!")) new JsonMessage(F.main("Game", F.elem(C.Bold + "CLICK HERE") + " to join their team!"))
.hover(HoverEvent.SHOW_TEXT, C.cYellow + "Click to join " + player.getName() + "'s team") .hover(HoverEvent.SHOW_TEXT, C.cYellow + "Click to join " + player.getName() + "'s team")
.click(ClickEvent.RUN_COMMAND, "/team " + player.getName()) .click(ClickEvent.RUN_COMMAND, "/team " + player.getName())
@ -181,7 +198,7 @@ public class TeamModule extends Module
private GameTeam getEmptyTeam() private GameTeam getEmptyTeam()
{ {
return getGame().GetTeamList().stream() return getGame().GetTeamList().stream()
.filter(team -> team.GetSize() == 0) .filter(team -> getGame().getTeamModule().getPlayersQueued(team) == 0)
.findFirst() .findFirst()
.orElse(null); .orElse(null);
} }

View File

@ -0,0 +1,24 @@
package nautilus.game.arcade.game.team.selectors;
import java.util.Comparator;
import java.util.List;
import nautilus.game.arcade.game.GameTeam;
public class EvenTeamSelector implements TeamSelector
{
@Override
public GameTeam getTeamToJoin(List<GameTeam> teams, int desiredAmount, int target, int total)
{
return teams.stream()
.min(Comparator.comparingInt(GameTeam::GetSize))
.orElse(null);
}
@Override
public boolean canJoinTeam(GameTeam team, int desiredAmount, int target, int total)
{
return team.GetSize() + desiredAmount <= target;
}
}

View File

@ -0,0 +1,44 @@
package nautilus.game.arcade.game.team.selectors;
import java.util.Comparator;
import java.util.List;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
public class FillToSelector extends EvenTeamSelector
{
private final int _amount;
public FillToSelector(Game game, int amount)
{
_amount = amount;
game.getTeamModule().setPlayersPerTeam(_amount);
}
@Override
public GameTeam getTeamToJoin(List<GameTeam> teams, int desiredAmount, int target, int total)
{
// Get the biggest team that can fit our desired amount
GameTeam primaryChoice = teams.stream()
.filter(team -> canJoinTeam(team, desiredAmount, target, total))
.max(Comparator.comparingInt(GameTeam::GetSize))
.orElse(null);
if (primaryChoice != null)
{
return primaryChoice;
}
// This would happen if all teams are full and we are overflowing
// Just get the emptiest team.
return super.getTeamToJoin(teams, desiredAmount, target, total);
}
@Override
public boolean canJoinTeam(GameTeam team, int desiredAmount, int target, int total)
{
return team.GetSize() + desiredAmount <= _amount;
}
}

View File

@ -0,0 +1,40 @@
package nautilus.game.arcade.game.team.selectors;
import java.util.List;
import java.util.stream.Collectors;
import mineplex.core.common.util.UtilAlg;
import nautilus.game.arcade.game.GameTeam;
public class RatioSelector implements TeamSelector
{
private final GameTeam _team;
private final double _ratio;
public RatioSelector(GameTeam team, double ratio)
{
_team = team;
_ratio = ratio;
}
@Override
public GameTeam getTeamToJoin(List<GameTeam> teams, int desiredAmount, int target, int total)
{
if (canJoinTeam(_team, desiredAmount, target, total))
{
return _team;
}
return UtilAlg.Random(teams.stream()
.filter(team -> !team.equals(_team))
.collect(Collectors.toList()));
}
@Override
public boolean canJoinTeam(GameTeam team, int desiredAmount, int target, int total)
{
return !team.equals(_team) || _team.GetSize() + desiredAmount <= Math.max(_ratio * total, 1);
}
}

View File

@ -0,0 +1,14 @@
package nautilus.game.arcade.game.team.selectors;
import java.util.List;
import nautilus.game.arcade.game.GameTeam;
public interface TeamSelector
{
GameTeam getTeamToJoin(List<GameTeam> teams, int desiredAmount, int target, int total);
boolean canJoinTeam(GameTeam team, int desiredAmount, int target, int total);
}

View File

@ -861,7 +861,7 @@ public class GameFlagManager implements Listener
UtilInv.drop(event.getPlayer(), true); UtilInv.drop(event.getPlayer(), true);
//Remove Kit //Remove Kit
game.RemoveTeamPreference(event.getPlayer()); game.getTeamModule().getPreferences().remove(event.getPlayer());
game.GetPlayerKits().remove(event.getPlayer()); game.GetPlayerKits().remove(event.getPlayer());
game.GetPlayerGems().remove(event.getPlayer()); game.GetPlayerGems().remove(event.getPlayer());

View File

@ -1,8 +1,6 @@
package nautilus.game.arcade.managers; package nautilus.game.arcade.managers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -13,12 +11,10 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import mineplex.core.PlayerSelector;
import mineplex.core.bonuses.event.CarlSpinnerEvent; import mineplex.core.bonuses.event.CarlSpinnerEvent;
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.UtilInv; import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilLambda;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom; import mineplex.core.common.util.UtilTextBottom;
@ -33,12 +29,11 @@ import mineplex.core.gadget.gadgets.mount.types.MountDragon;
import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import mineplex.core.gadget.types.WinEffectGadget; import mineplex.core.gadget.types.WinEffectGadget;
import mineplex.core.portal.GenericServer;
import mineplex.core.portal.Intent;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.RestartTriggerEvent; import mineplex.core.updater.event.RestartTriggerEvent;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.condition.Condition.ConditionType; import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GamePrepareCountdownCommence; import nautilus.game.arcade.events.GamePrepareCountdownCommence;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
@ -52,8 +47,8 @@ import nautilus.game.arcade.gametutorial.TutorialText;
public class GameManager implements Listener public class GameManager implements Listener
{ {
ArcadeManager Manager;
final ArcadeManager Manager;
private int _colorId = 0; private int _colorId = 0;
public GameManager(ArcadeManager manager) public GameManager(ArcadeManager manager)
@ -269,7 +264,7 @@ public class GameManager implements Listener
{ {
//Stop Countdown! //Stop Countdown!
if (game.GetCountdown() != -1 && if (game.GetCountdown() != -1 &&
getValidPlayersForGameStart().size() < Manager.GetPlayerMin() && Manager.getValidPlayersForGameStart().size() < Manager.GetPlayerMin() &&
!game.GetCountdownForce()) !game.GetCountdownForce())
{ {
game.SetCountdown(-1); game.SetCountdown(-1);
@ -278,10 +273,10 @@ public class GameManager implements Listener
if (Manager.IsGameAutoStart()) if (Manager.IsGameAutoStart())
{ {
if (getValidPlayersForGameStart().size() >= Manager.GetPlayerFull()) if (Manager.getValidPlayersForGameStart().size() >= Manager.GetPlayerFull())
StateCountdown(game, 20, false); StateCountdown(game, 20, false);
else if (getValidPlayersForGameStart().size() >= Manager.GetPlayerMin()) else if (Manager.getValidPlayersForGameStart().size() >= Manager.GetPlayerMin())
StateCountdown(game, 60, false); StateCountdown(game, 60, false);
else if (game.GetCountdown() != -1) else if (game.GetCountdown() != -1)
@ -345,16 +340,6 @@ public class GameManager implements Listener
} }
} }
public List<Player> getValidPlayersForGameStart()
{
return PlayerSelector.selectPlayers(
UtilLambda.and(
PlayerSelector.NOT_VANISHED,
player -> !Manager.IsObserver(player)
)
);
}
public void StateCountdown(Game game, int timer, boolean force) public void StateCountdown(Game game, int timer, boolean force)
{ {
if (Manager.GetGameHostManager().isPrivateServer() && Manager.GetGameHostManager().isVoteInProgress()) if (Manager.GetGameHostManager().isPrivateServer() && Manager.GetGameHostManager().isVoteInProgress())
@ -377,23 +362,7 @@ public class GameManager implements Listener
if (force) if (force)
game.SetCountdownForce(true); game.SetCountdownForce(true);
//Team Preference
TeamPreferenceJoin(game);
//Team Swap
TeamPreferenceSwap(game);
//Team Default
TeamDefaultJoin(game);
//Team Inform STILL Queued
if (game.GetCountdown() == -1)
{
game.InformQueuePositions();
//game.AnnounceGame();
}
//Initialise Countdown //Initialise Countdown
if (force) if (force)
game.SetCountdownForce(true); game.SetCountdownForce(true);
@ -411,13 +380,13 @@ public class GameManager implements Listener
game.SetCountdown(game.GetCountdown() - 1); game.SetCountdown(game.GetCountdown() - 1);
//Inform Countdown //Inform Countdown
if (game.GetCountdown() > 0) if (game.GetCountdown() > 0)
{ {
Manager.GetLobby().writeGameLine("starting in " + game.GetCountdown() + "...", 3, 159, (byte)13); Manager.GetLobby().writeGameLine("starting in " + game.GetCountdown() + "...", 3, 159, (byte) 13);
} }
else else
{ {
Manager.GetLobby().writeGameLine("game in progress", 3, 159, (byte)13); Manager.GetLobby().writeGameLine("game in progress", 3, 159, (byte) 13);
} }
if (game.GetCountdown() > 0 && game.GetCountdown() <= 10) if (game.GetCountdown() > 0 && game.GetCountdown() <= 10)
@ -426,7 +395,9 @@ public class GameManager implements Listener
//Countdown Ended //Countdown Ended
if (game.GetCountdown() == 0) if (game.GetCountdown() == 0)
{
game.SetState(GameState.Prepare); game.SetState(GameState.Prepare);
}
} }
@EventHandler @EventHandler
@ -482,152 +453,33 @@ public class GameManager implements Listener
} }
} }
public void TeamPreferenceJoin(Game game)
{
//Preferred Team No Longer Full
for (GameTeam team : game.GetTeamPreferences().keySet())
{
Iterator<Player> queueIterator = game.GetTeamPreferences().get(team).iterator();
while (queueIterator.hasNext())
{
Player player = queueIterator.next();
if (!game.CanJoinTeam(team))
{
break;
}
queueIterator.remove();
if (!game.IsPlaying(player))
{
PlayerAdd(game, player, team);
}
else
{
game.SetPlayerTeam(player, team, true);
}
}
}
}
public void TeamPreferenceSwap(Game game)
{
//Preferred Team No Longer Full
for (GameTeam team : game.GetTeamPreferences().keySet())
{
Iterator<Player> queueIterator = game.GetTeamPreferences().get(team).iterator();
while (queueIterator.hasNext())
{
Player player = queueIterator.next();
GameTeam currentTeam = game.GetTeam(player);
//Not on team, cannot swap
if (currentTeam == null)
continue;
// Other without concurrent (order doesn't matter as first case will fire
if (team == currentTeam)
{
queueIterator.remove();
continue;
}
for (Player other : team.GetPlayers(false))
{
if (other.equals(player))
continue;
GameTeam otherPref = game.GetTeamPreference(other);
if (otherPref == null)
continue;
if (otherPref.equals(currentTeam))
{
UtilPlayer.message(player, F.main("Team", "You swapped team with " + F.elem(team.GetColor() + other.getName()) + "."));
UtilPlayer.message(other, F.main("Team", "You swapped team with " + F.elem(currentTeam.GetColor() + player.getName()) + "."));
//Player Swap
queueIterator.remove();
game.SetPlayerTeam(player, team, true);
//Other Swap
game.SetPlayerTeam(other, currentTeam, true);
break;
}
}
}
}
}
public void TeamDefaultJoin(Game game)
{
//Team Default
for (Player player : UtilServer.getPlayers())
{
if (player.isDead())
{
player.sendMessage(F.main("Afk Monitor", "You are being sent to the Lobby for being AFK."));
Manager.GetPortal().sendPlayerToGenericServer(player, GenericServer.HUB, Intent.KICK);
}
else if (Manager.IsObserver(player))
{
}
else if (!game.IsPlaying(player) && Manager.IsTeamAutoJoin())
{
PlayerAdd(game, player, null);
}
}
}
@EventHandler @EventHandler
public void TeamQueueSizeUpdate(UpdateEvent event) public void TeamQueueSizeUpdate(UpdateEvent event)
{ {
if (event.getType() != UpdateType.TICK) if (event.getType() != UpdateType.SEC)
{
return; return;
}
Game game = Manager.GetGame(); Game game = Manager.GetGame();
if (game == null) return;
if (game == null)
{
return;
}
for (GameTeam team : game.GetTeamList()) for (GameTeam team : game.GetTeamList())
{ {
int amount = 0;
if (game.GetTeamPreferences().containsKey(team))
{
amount = game.GetTeamPreferences().get(team).size();
}
if (team.GetTeamEntity() == null) if (team.GetTeamEntity() == null)
{
continue; continue;
if (game.GetCountdown() == -1)
{
team.GetTeamEntity().setCustomName(team.GetFormattedName() + " Team" + ChatColor.RESET + " " + amount + " Queued");
}
else
{
team.GetTeamEntity().setCustomName(team.GetPlayers(false).size() + " Players " + team.GetFormattedName() + " Team" + ChatColor.RESET + " " + amount + " Queued");
} }
int amount = game.getTeamModule().getPlayersQueued(team);
team.GetTeamEntity().setCustomName(team.GetFormattedName() + " Team" + C.Reset + " " + amount + " Queued");
} }
} }
public boolean PlayerAdd(Game game, Player player, GameTeam team)
{
if (team == null)
team = game.ChooseTeam(player);
if (team == null)
return false;
game.SetPlayerTeam(player, team, true);
return true;
}
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void PlayerPrepare(GameStateChangeEvent event) public void PlayerPrepare(GameStateChangeEvent event)

View File

@ -216,46 +216,16 @@ public class GamePlayerManager implements Listener
TeamClick(player, team); TeamClick(player, team);
} }
public void TeamClick(final Player player, final GameTeam team) public void TeamClick(Player player, GameTeam team)
{ {
if (Manager.GetGame() == null) Game game = Manager.GetGame();
return;
if (Manager.GetGame().GetState() != GameState.Recruit) if (game == null || game.GetState() != GameState.Recruit || !game.HasTeam(team))
return;
if (!Manager.GetGame().HasTeam(team))
return;
AddTeamPreference(Manager.GetGame(), player, team);
}
public void AddTeamPreference(Game game, Player player, GameTeam team)
{
GameTeam past = game.GetTeamPreference(player);
GameTeam current = game.GetTeam(player);
if (current != null && current.equals(team))
{ {
game.RemoveTeamPreference(player);
UtilPlayer.message(player, F.main("Team", "You are already on " + F.elem(team.GetFormattedName()) + "."));
return; return;
} }
if (past == null || !past.equals(team)) game.getTeamModule().addPlayerQueue(player, team);
{
if (past != null)
{
game.RemoveTeamPreference(player);
}
if (!game.GetTeamPreferences().containsKey(team))
game.GetTeamPreferences().put(team, new ArrayList<Player>());
game.GetTeamPreferences().get(team).add(player);
}
UtilPlayer.message(player, F.main("Team", "You are " + F.elem(game.GetTeamQueuePosition(player)) + " in queue for " + F.elem(team.GetFormattedName() + " Team") + "."));
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)

View File

@ -1,210 +0,0 @@
package nautilus.game.arcade.managers;
import java.util.ArrayList;
import java.util.HashMap;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.scoreboard.MineplexScoreboard;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.Game.GameState;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
public class GameTournamentManager implements Listener
{
ArcadeManager Manager;
private HashMap<String, String> _tournamentTeam = new HashMap<String, String>();
private HashMap<String, Integer> _tournamentPoints = new HashMap<String, Integer>();
public GameTournamentManager(ArcadeManager manager)
{
Manager = manager;
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
}
@EventHandler
public void TeamTournamentAutoJoin(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
Game game = Manager.GetGame();
if (game == null) return;
if (game.GetState() != GameState.Recruit)
return;
for (Player player : UtilServer.getPlayers())
rejoinTournamentTeam(player);
}
public void setTournamentTeam(Player player, GameTeam team)
{
if (!Manager.IsTeamRejoin())
return;
_tournamentTeam.put(player.getName(), team.GetName());
}
public void rejoinTournamentTeam(Player player)
{
if (Manager.GetGame() == null)
return;
if (!_tournamentTeam.containsKey(player.getName()))
return;
GameTeam curPref = Manager.GetGame().GetTeamPreference(player);
if (curPref != null)
return;
GameTeam curTeam = Manager.GetGame().GetTeam(player);
if (curTeam != null)
return;
String teamName = _tournamentTeam.get(player.getName());
for (GameTeam team : Manager.GetGame().GetTeamList())
{
if (team.GetName().equalsIgnoreCase(teamName))
{
Manager.GetGamePlayerManager().AddTeamPreference(Manager.GetGame(), player, team);
break;
}
}
}
@EventHandler
public void pointsReward(GameStateChangeEvent event)
{
if (!Manager.IsTournamentPoints())
return;
if (event.GetState() != GameState.End)
return;
ArrayList<Player> places = event.GetGame().GetTeamList().get(0).GetPlacements(true);
for (int i=0 ; i<places.size() ; i++)
{
Player player = places.get(i);
int points = places.size() - i;
addTournamentPoints(player, points);
UtilPlayer.message(player,
F.main("Tournament", "You received " + F.elem(points + " Points") + " for placing " + F.elem((i+1)+"/"+places.size()) + "."));
}
}
@EventHandler
public void pointsScoreboard(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!Manager.IsTournamentPoints())
return;
for (MineplexScoreboard mpscoreboard : Manager.getScoreboardManager().getScoreboards().values())
{
Scoreboard scoreboard = mpscoreboard.getHandle();
Objective objective = scoreboard.getObjective(DisplaySlot.BELOW_NAME);
if (objective == null)
{
objective = scoreboard.registerNewObjective("Points", "dummy");
objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
}
for (Player player : UtilServer.getPlayers())
objective.getScore(player.getName()).setScore(getTournamentPoints(player.getName()));
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void pointsDisplay(GameStateChangeEvent event)
{
if (!Manager.IsTournamentPoints())
return;
if (event.GetState() != GameState.Dead)
return;
ArrayList<String> ranks = new ArrayList<String>();
while (ranks.size() < _tournamentPoints.size())
{
int bestPoints = 0;
String bestPlayer = null;
for (String cur : _tournamentPoints.keySet())
{
if (ranks.contains(cur))
continue;
int points = _tournamentPoints.get(cur);
if (points == 0)
continue;
if (bestPlayer == null || points < bestPoints)
{
bestPlayer = cur;
bestPoints = points;
}
}
if (bestPlayer == null)
break;
ranks.add(bestPlayer);
}
Bukkit.broadcastMessage(C.cBlue + C.Strike + C.Bold + "--------------------------------------------");
for (int i=0 ; i<ranks.size() ; i++)
{
Bukkit.broadcastMessage(C.cGold + getTournamentPoints(ranks.get(i)) + " Points" + " " + C.cWhite + ranks.get(i));
}
Bukkit.broadcastMessage(C.cBlue + C.Strike + C.Bold + "--------------------------------------------");
}
public int getTournamentPoints(String player)
{
if (!_tournamentPoints.containsKey(player))
_tournamentPoints.put(player, 0);
return _tournamentPoints.get(player);
}
public void addTournamentPoints(Player player, int points)
{
_tournamentPoints.put(player.getName(), points + getTournamentPoints(player.getName()));
}
@EventHandler
public void clean(PlayerQuitEvent event)
{
_tournamentTeam.remove(event.getPlayer().getName());
}
}