Fix some issues found when using a standalone map vote

This commit is contained in:
Sam 2018-06-21 16:59:23 +01:00 committed by Alexander Meech
parent 10c7b84be0
commit 34d45d3434
3 changed files with 85 additions and 92 deletions

View File

@ -52,7 +52,6 @@ public class GameCreationManager implements Listener
private GameType _nextGame = null;
private String _lastMap = "";
private GameMode _lastMode = null;
private final List<GameType> _lastGames = new ArrayList<>();
private Map<GameType, List<String>> _maps;
@ -70,7 +69,7 @@ public class GameCreationManager implements Listener
}
@EventHandler
public void NextGame(UpdateEvent event)
public void nextGame(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST || Manager.GetGameList().isEmpty())
{
@ -188,18 +187,15 @@ public class GameCreationManager implements Listener
}
else
{
System.out.println(_nextGame == null ? "Next Game = null" : "Next Game = " + _nextGame.getName());
System.out.println("Map Pref = " + MapPref);
System.out.println("Gamemode Pref = " + ModePref);
System.out.println("Next Game Preference" + _nextGame);
System.out.println("Map Preference: " + MapPref);
System.out.println("Gamemode Preference: " + ModePref);
}
//Chosen Game
// /game set or map vote
if (_nextGame != null)
{
gameType = _nextGame;
_nextGame = null;
System.out.println("Staff Selected GameType: " + gameType);
}
//Pick Game
@ -224,24 +220,7 @@ public class GameCreationManager implements Listener
Map<GameType, List<String>> mapsToVote = new HashMap<>();
typesToVote.forEach(votingGameType ->
{
// Load the maps for this game type
loadMaps(votingGameType, votingGameType.getGameClass());
List<String> votingGameMaps = _maps.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toList());
// While there are more than 5 maps, remove a random one
while (votingGameMaps.size() > VotingManager.MAPS_TO_VOTE_ON)
{
votingGameMaps.remove(UtilMath.r(votingGameMaps.size()));
}
// Merge map names from all sources together
mapsToVote.put(votingGameType, votingGameMaps);
});
typesToVote.forEach(votingGameType -> mapsToVote.put(votingGameType, getMapsToVote(votingGameType)));
_votingManager.callVote(new GameVote(Manager, typesToVote, mapsToVote));
return;
@ -269,17 +248,16 @@ public class GameCreationManager implements Listener
Class<? extends Game> gameClass = gameType.getGameClass();
// If map voting and ONLY map voting is enabled
if (Manager.GetServerConfig().MapVoting && !Manager.GetServerConfig().GameVoting)
// Also need to make sure a map and game haven't been selected by /game set beforehand
if (MapPref == null && _nextGame == null && Manager.GetServerConfig().MapVoting && !Manager.GetServerConfig().GameVoting)
{
loadMaps(gameType, gameClass);
// Apply the same logic as game voting and merge all those names together
_votingManager.callVote(new MapVote(Manager, gameType, _maps.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toList())));
_nextGame = gameType;
_votingManager.callVote(new MapVote(Manager, gameType, getMapsToVote(gameType)));
return;
}
_nextGame = null;
//Reset Changes
Manager.GetCreature().SetDisableCustomDrops(false);
Manager.GetDamage().resetConfiguration();
@ -321,7 +299,7 @@ public class GameCreationManager implements Listener
}
// Maps
loadMaps(gameType, gameClass);
loadMaps(gameType);
ModePref = null;
@ -365,12 +343,12 @@ public class GameCreationManager implements Listener
TimingManager.stop("registerEvents");
}
private void loadMaps(GameType gameType, Class<? extends Game> gameClass)
private void loadMaps(GameType gameType)
{
_maps = new HashMap<>();
// Map
for (GameType type : Game.getWorldHostNames(gameType, gameClass))
for (GameType type : Game.getWorldHostNames(gameType, gameType.getGameClass()))
{
_maps.put(type, Manager.LoadFiles(type.getName()));
}
@ -418,42 +396,42 @@ public class GameCreationManager implements Listener
}
}
private List<String> getMapsToVote(GameType gameType)
{
// Load the maps for this game type
loadMaps(gameType);
// Merge maps from all sources
List<String> mapsToVote = _maps.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toList());
// While there are more than 5 maps, remove a random one
while (mapsToVote.size() > VotingManager.MAPS_TO_VOTE_ON)
{
mapsToVote.remove(UtilMath.r(mapsToVote.size()));
}
return mapsToVote;
}
public Pair<GameType, String> getMapFile()
{
GameType gameType = null;
String selectedMap = null;
for (int i = 0; i < MAX_ATTEMPTS; i++)
int gameTypeIndex = UtilMath.r(_maps.size());
int index = 0;
for (GameType mapType : _maps.keySet())
{
int gameTypeIndex = UtilMath.r(_maps.size());
int index = 0;
for (GameType mapType : _maps.keySet())
{
if (index++ == gameTypeIndex)
{
gameType = mapType;
break;
}
}
selectedMap = UtilAlg.Random(_maps.get(gameType));
if (selectedMap == null)
{
continue;
}
// Not the last map
if (!selectedMap.equals(_lastMap))
if (index++ == gameTypeIndex)
{
gameType = mapType;
break;
}
}
_lastMap = selectedMap;
return Pair.create(gameType, selectedMap);
return Pair.create(gameType, UtilAlg.Random(_maps.get(gameType)));
}
private GameMode randomGameMode(GameType type)

View File

@ -59,26 +59,43 @@ public class GameManager implements Listener
}
@EventHandler
public void DisplayIP(UpdateEvent event)
public void displayIP(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST)
return;
if (Manager.GetGame() != null && !Manager.GetGame().InProgress())
{
ChatColor col = ChatColor.RED;
if (_colorId == 1) col = ChatColor.YELLOW;
else if (_colorId == 2) col = ChatColor.GREEN;
else if (_colorId == 3) col = ChatColor.AQUA;
return;
}
Game game = Manager.GetGame();
if ((game != null && !game.InProgress()) || Manager.GetGameCreationManager().getVotingManager().isVoteInProgress())
{
ChatColor colour;
switch (_colorId)
{
case 1:
colour = ChatColor.YELLOW;
break;
case 2:
colour = ChatColor.GREEN;
break;
case 3:
colour = ChatColor.AQUA;
break;
default:
colour = ChatColor.RED;
break;
}
_colorId = (_colorId + 1) % 4;
String text = col + C.Bold + "US.MINEPLEX.COM EU.MINEPLEX.COM";
String text = colour + C.Bold + "US.MINEPLEX.COM EU.MINEPLEX.COM";
double health = 1;
if (Manager.GetGame().GetState() == GameState.Recruit)
if (game != null && game.GetCountdown() >= 0 && game.GetCountdown() <= 10)
{
if (Manager.GetGame().GetCountdown() >= 0 && Manager.GetGame().GetCountdown() <= 10)
health = 1 - Manager.GetGame().GetCountdown() / 10d;
health = 1 - game.GetCountdown() / 10D;
}
//Display IP
@ -93,8 +110,7 @@ public class GameManager implements Listener
if (disguise instanceof DisguiseWither)
{
((DisguiseWither) disguise).setName(text);
((DisguiseLiving) disguise).setHealth((float) Math.max(0.1,
300 * health));
((DisguiseLiving) disguise).setHealth((float) Math.max(0.1, 300 * health));
disguise.resendMetadata();
}
}

View File

@ -37,7 +37,8 @@ import nautilus.game.arcade.game.GameTeam;
public class GamePlayerManager implements Listener
{
ArcadeManager Manager;
final ArcadeManager Manager;
private static final int TEAMMATE_MESSAGE_DELAY = 40;
@ -66,12 +67,8 @@ public class GamePlayerManager implements Listener
event.GetLog().SetKillerColor(Manager.GetColor(player)+"");
}
if (event.GetEvent().getEntity() instanceof Player)
{
Player player = (Player)event.GetEvent().getEntity();
if (player != null)
event.GetLog().SetKilledColor(Manager.GetColor(player)+"");
}
Player player = event.GetEvent().getEntity();
event.GetLog().SetKilledColor(Manager.GetColor(player) + "");
}
@EventHandler
@ -79,19 +76,21 @@ public class GamePlayerManager implements Listener
{
final Player player = event.getPlayer();
Game game = Manager.GetGame();
//Player List
UtilTabTitle.setHeaderAndFooter(player,
Manager.GetGame() != null ? C.cGold + C.Bold + Manager.GetGame().GetType().getName() : " ",
C.cGoldB + (game == null ? "Waiting For Players" : game.GetType().getName()),
"Visit " + C.cGreen + "www.mineplex.com" + ChatColor.RESET + " for News, Forums and Shop");
//Lobby Spawn
if (Manager.GetGame() == null || !Manager.GetGame().InProgress())
if (game == null || !game.InProgress())
{
Manager.Clear(player);
Manager.getScoreboardManager().getScoreboards().entrySet().stream().filter(ent -> Bukkit.getPlayer(ent.getKey()) != null).forEach(ent -> Bukkit.getPlayer(ent.getKey()).setScoreboard(ent.getValue().getHandle()));
player.teleport(Manager.GetLobby().getSpawn());
//Load default kit for this game
if (Manager.GetGame() != null && Manager.GetGame().GetType().name().toLowerCase().contains("champions"))
if (game != null && game.GetType().name().toLowerCase().contains("champions"))
{
return;
}
@ -100,9 +99,9 @@ public class GamePlayerManager implements Listener
}
//Game Spawn
if (Manager.GetGame().IsAlive(player))
if (game.IsAlive(player))
{
Location loc = Manager.GetGame().GetLocationStore().remove(player.getName());
Location loc = game.GetLocationStore().remove(player.getName());
if (loc != null && !loc.getWorld().getName().equalsIgnoreCase("world"))
{
player.teleport(loc);
@ -117,10 +116,10 @@ public class GamePlayerManager implements Listener
{
Manager.Clear(player);
Manager.addSpectator(player, true);
UtilPlayer.message(player, F.main("Game", Manager.GetGame().GetName() + " is in progress, please wait for next game!"));
UtilPlayer.message(player, F.main("Game", game.GetName() + " is in progress, please wait for next game!"));
}
if (!Manager.GetGame().UseCustomScoreboard)
if (!game.UseCustomScoreboard)
{
player.setScoreboard(Manager.GetGame().GetScoreboard().getScoreboard());
}