diff --git a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloClientData.java b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloClientData.java index 2a4f86703..ffe6aa944 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloClientData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloClientData.java @@ -4,5 +4,5 @@ import mineplex.core.common.util.NautHashMap; public class EloClientData { - public NautHashMap Elos = new NautHashMap(); + public NautHashMap Elos = new NautHashMap(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java index ccc50530d..db452c0fa 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java @@ -2,266 +2,124 @@ package mineplex.core.elo; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.UUID; import mineplex.core.MiniDbClientPlugin; import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.NautHashMap; -import mineplex.serverdata.database.column.ColumnInt; -import mineplex.serverdata.database.column.ColumnVarChar; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class EloManager extends MiniDbClientPlugin { - private static Object _playerEloLock = new Object(); - private EloRepository _repository; private EloRatingSystem _ratingSystem; - private NautHashMap> _playerElos; - private NautHashMap> _playerDivisions; - - private EloDivision _division; public EloManager(JavaPlugin plugin, CoreClientManager clientManager) { super("Elo Rating", plugin, clientManager); _repository = new EloRepository(plugin); - _ratingSystem = new EloRatingSystem(new KFactor(0, 1200, 25), new KFactor(1201, 1600, 20), new KFactor(1601, 2000, 15), new KFactor(2001, 2500, 10)); - _playerElos = new NautHashMap>(); - + _ratingSystem = new EloRatingSystem + ( + new KFactor(0, 1299, 30), + new KFactor(1300, 1899, 25), + new KFactor(1900, 2499, 20), + new KFactor(2500, 3099, 15), + new KFactor(3100, 3699, 10), + new KFactor(3700, 5000, 5) + ); } - //add an EloPlayer's info to _playerElos - public void addToPlayerElos(EloPlayer player, String gameType) + public int getElo(Player player, int gameType) { - NautHashMap playerInfo = new NautHashMap(); - playerInfo.put(player.getUniqueId(), player.rating); - _playerElos.put(gameType, playerInfo); - } - - //add a column for this game in database - public void addGameToDatabase(String gameID) throws SQLException - { - _repository.addGameType(gameID); - } - - /* - * fill _playerElos with information from database - * If no entry exists, create one - */ - public void generatePlayerElos(ArrayList players, String gameType) - { - for (Player player : players) - { - int elo = getElo(player.getUniqueId(), gameType); - _playerElos.get(player.getUniqueId().toString()).put(gameType, elo); - } - } - - public int getElo(UUID uuid, String gameType) - { - int elo = 1000; + if (!Get(player).Elos.containsKey(gameType)) + Get(player).Elos.put(gameType, 1000); - //let's try getting Elo directly from the repository - //If this works, we will never hit the return at the bottom - try - { - elo = _repository.getRepoElo(uuid.toString(), gameType); - - return elo; - } - catch (SQLException e) - { - e.printStackTrace(); - } - - synchronized (_playerEloLock) - { - if (_playerElos.containsKey(uuid.toString())) - { - if (_playerElos.get(uuid.toString()).containsKey(gameType)) - { - elo = _playerElos.get(uuid.toString()).get(gameType); - } - } - } - - return elo; + return Get(player).Elos.get(gameType); } public EloTeam getNewRatings(EloTeam teamA, EloTeam teamB, GameResult result) { EloTeam newTeam = new EloTeam(); - - //System.out.println("Old " + result + " Team Rating:" + teamA.TotalElo); - - int teamASize = teamA.getPlayers().size(); - int teamBSize = teamB.getPlayers().size(); - - if(teamASize < 1) - { - teamASize = 1; - } - + int newTotal = _ratingSystem.getNewRating(teamA.TotalElo / teamA.getPlayers().size(), teamB.TotalElo / teamB.getPlayers().size(), result) * teamA.getPlayers().size(); - //System.out.println("New " + result + " Team Rating:" + newTotal); - for (EloPlayer player : teamA.getPlayers()) { - EloPlayer newPlayer = new EloPlayer(); - newPlayer.setUniqueId(player.getUniqueId()); - newPlayer.rating = (int)(player.rating + ((double)player.rating / (double)teamA.TotalElo) * (newTotal - teamA.TotalElo)); - - //System.out.println("Old:"); - //player.printInfo(); - - //System.out.println("New:"); - //newPlayer.printInfo(); - + int newRating = (int)(player.getRating() + ((double)player.getRating() / (double)teamA.TotalElo) * (newTotal - teamA.TotalElo)); + EloPlayer newPlayer = new EloPlayer(player.getPlayer(), newRating); + newTeam.addPlayer(newPlayer); } return newTeam; } - public void saveElo(UUID uuid, String gameType, int elo) + public void saveElo(final Player player, final int gameType, final int elo) { - saveElo(uuid.toString(), gameType, elo); - } - - public void saveElo(final String uuid, final String gameType, final int elo) - { - //Bukkit.broadcastMessage("EloManager saveElo called"); - Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() + runAsync(new Runnable() { public void run() { + boolean success = false; - try { - _repository.saveElo(uuid, gameType, elo); - } catch (SQLException e) { - // TODO Auto-generated catch block + try + { + success = _repository.saveElo(getClientManager().getAccountId(player), gameType, elo); + } + catch (SQLException e) + { e.printStackTrace(); } - + finally + { + System.out.println("Saving " + player.getName() + "'s new elo rating of " + elo + " for gameType " + gameType + (success ? " SUCCEEDED." : " FAILED.")); + } } }); + + Get(player).Elos.put(gameType, elo); } - //get a player's Division - public String getPlayerDivision(UUID uuid, String gameType) + public String getPlayerDivision(Player player, int gameType) { - //get playerElo for gameType (need to store this to check it against other Elo's) - int playerElo = 1000; + int playerElo = getElo(player, gameType); + String divisionName = "Player's division"; - try { - playerElo = _repository.getRepoElo(uuid.toString(), gameType); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - String pDivision = CalculateDivision(playerElo, gameType); + if (playerElo >= 3700) + divisionName = "Diamond"; + else if (playerElo < 3700 && playerElo >= 3500) + divisionName = "Emerald 3"; + else if (playerElo < 3500 && playerElo >= 3300) + divisionName = "Emerald 2"; + else if (playerElo < 3300 && playerElo >= 3100) + divisionName = "Emerald 1"; + else if (playerElo < 3100 && playerElo >= 2900) + divisionName = "Lapis 3"; + else if (playerElo < 2900 && playerElo >= 2700) + divisionName = "Lapis 2"; + else if (playerElo < 2700 && playerElo >= 2500) + divisionName = "Lapis 1"; + else if (playerElo < 2500 && playerElo >= 2300) + divisionName = "Gold 3"; + else if (playerElo < 2300 && playerElo >= 2100) + divisionName = "Gold 2"; + else if (playerElo < 2100 && playerElo >= 1900) + divisionName = "Gold 1"; + else if (playerElo < 1900 && playerElo >= 1700) + divisionName = "Iron 3"; + else if (playerElo < 1700 && playerElo >= 1500) + divisionName = "Iron 2"; + else if (playerElo < 1500 && playerElo >= 1300) + divisionName = "Iron 1"; + else if (playerElo < 1300 && playerElo >= 1100) + divisionName = "Coal 3"; + else if (playerElo < 1100 && playerElo >= 900) + divisionName = "Coal 2"; + else if (playerElo < 900) + divisionName = "Coal 1"; - return pDivision; - } - - //calculate percentile into which player falls (above 99 is the top 1%) - public double getEloPercent(int playerElo, String gameType) - { - //this list will be filled with ELO's from other players (but only for the same game type - ArrayList allElos = new ArrayList(); - try { - allElos = _repository.getAllElos(gameType); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - //sort list of Elos (needed for percentile calculations) - Collections.sort(allElos); - - double individualValue = 0; - - //let's not allow the division of things by 0... - if (allElos.size() != 0) - { - //Calculate how much going up one spot is worth - try - { - individualValue = (100/allElos.size()); - } - catch(Error e) - { - e.printStackTrace(); - } - } - - /* lastIndexOf gets the last instance of player's Elo - * Consequently, it should be easier for rank to go up than down - * and everyone at the same Elo should be in the same division - */ - double percentile = allElos.lastIndexOf(playerElo) * individualValue; - - return percentile; - } - - //only bother calculating percentile if players actually have above 3500 elo - public String CalculateDiamondPlayers(int playerElo, String gameType) - { - String newDivision = "Emerald 3"; - - if(getEloPercent(playerElo, gameType) > 99) - { - newDivision = "Diamond"; - } - - return newDivision; - } - - //return a string representing a player's division, based on elo - public String CalculateDivision(int playerElo, String gameType) - { - String pDiv = "Player's division"; - - if (playerElo >= 3500) - {pDiv = CalculateDiamondPlayers(playerElo, gameType);} - if (playerElo < 3500 && playerElo >= 3300) - {pDiv = "Emerald 2";} - if (playerElo < 3300 && playerElo >= 3100) - {pDiv = "Emerald 1";} - if (playerElo < 3100 && playerElo >= 2900) - {pDiv = "Lapis 3";} - if (playerElo < 2900 && playerElo >= 2700) - {pDiv = "Lapis 2";} - if (playerElo < 2700 && playerElo >= 2500) - {pDiv = "Lapis 1";} - if (playerElo < 2500 && playerElo >= 2300) - {pDiv = "Gold 3";} - if (playerElo < 2300 && playerElo >= 2100) - {pDiv = "Gold 2";} - if (playerElo < 2100 && playerElo >= 1900) - {pDiv = "Gold 1";} - if (playerElo < 1900 && playerElo >= 1700) - {pDiv = "Iron 3";} - if (playerElo < 1700 && playerElo >= 1500) - {pDiv = "Iron 2";} - if (playerElo < 1500 && playerElo >= 1300) - {pDiv = "Iron 1";} - if (playerElo < 1300 && playerElo >= 1100) - {pDiv = "Coal 3";} - if (playerElo < 1100 && playerElo >= 900) - {pDiv = "Coal 2";} - if (playerElo < 900 && playerElo >= 700) - {pDiv = "Coal 1";} - - return pDiv; + return divisionName; } @Override @@ -279,7 +137,6 @@ public class EloManager extends MiniDbClientPlugin @Override public String getQuery(int accountId, String uuid, String name) { - return "SELECT gameType, elo FROM eloRatingTest WHERE uuid = '" + uuid + "';"; - //return "SELECT gameType, elo FROM eloRating WHERE uuid = '" + uuid + "';"; + return "SELECT gameType, elo FROM eloRating WHERE accountId = '" + accountId + "';"; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloPlayer.java b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloPlayer.java index 987744cef..f6b3c1523 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloPlayer.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloPlayer.java @@ -1,57 +1,34 @@ package mineplex.core.elo; +import org.bukkit.entity.Player; + public class EloPlayer { - private String _uniqueId; - public int rating; - private int _killBonus; - private boolean _fullBonus = false; + private Player _player; + public int _rating; + + public EloPlayer(Player player, int rating) + { + _player = player; + } + + public Player getPlayer() + { + return _player; + } + + public void setRating(int rating) + { + _rating = rating; + } + + public int getRating() + { + return _rating; + } public void printInfo() { - System.out.println(_uniqueId + "'s elo is " + rating); + System.out.println(_player.getName() + "'s elo is " + _rating); } - - public String getUniqueId() - { - return _uniqueId; - } - - public void setUniqueId(String uuid) - { - _uniqueId = uuid; - } - - //bonus points awarded for kills/objectives, but no more than 10 - public int getKillBonus() - { - return _killBonus; - } - - public void setKillBonus(int bonus) - { - if (_killBonus < 10 && !_fullBonus) - { - _killBonus = bonus; - } - if (_killBonus > 10) - { - _killBonus = 10; - _fullBonus = true; - } - } - - public void incrementKillBonus(int toAdd) - { - if (_killBonus < 10 && !_fullBonus) - { - _killBonus += toAdd; - } - if (_killBonus > 10) - { - _killBonus = 10; - _fullBonus = true; - } - } - } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java index 82a4171eb..713d76f81 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java @@ -2,25 +2,17 @@ package mineplex.core.elo; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; import mineplex.core.database.MinecraftRepository; import mineplex.serverdata.database.DBPool; -import mineplex.serverdata.database.ResultSetCallable; import mineplex.serverdata.database.column.ColumnInt; -import mineplex.serverdata.database.column.ColumnVarChar; import org.bukkit.plugin.java.JavaPlugin; public class EloRepository extends MinecraftRepository -{ - private static String CREATE_ELO_TABLE = "CREATE TABLE IF NOT EXISTS eloRating (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), Testing INT, PRIMARY KEY (id), UNIQUE INDEX uuid (uuid));"; - private static String INSERT_ELO = "INSERT INTO eloRating (uuid, $gameType$) VALUES (?, ?) ON DUPLICATE KEY UPDATE $gameType$=VALUES($gameType$);"; - //private static String UPDATE_ELO = "UPDATE eloRating SET $gameType$=? WHERE uuid=?;"; - private static String SELECT_ELO_BY_UUID = "SELECT $gameType$ FROM eloRating WHERE uuid = ? LIMIT 1"; - private static String GET_ALL_ELOS = "SELECT $gameType$ FROM eloRating;"; - private static String ADD_GAME = "ALTER TABLE eloRating ADD $gameType$ INT;"; +{ + private static String INSERT_ELO = "INSERT INTO eloRating (accountId, gameType) VALUES (?, ?);"; + private static String UPDATE_ELO = "UPDATE eloRating SET elo=? WHERE accountId = ? AND gameType = ?;"; public EloRepository(JavaPlugin plugin) { @@ -29,69 +21,16 @@ public class EloRepository extends MinecraftRepository initialize(); } - public void initialize() - { - //executeUpdate(CREATE_ELO_TABLE); - } + public void initialize() { } - public void addGameType(String gameType) throws SQLException + public boolean saveElo(int accountId, int gameType, int elo) throws SQLException { - String query = ADD_GAME.replace("$gameType$", "MP" + gameType); - executeUpdate(query, new ColumnInt(gameType)); - } - - //method to return every Elo from DB - public ArrayList getAllElos(String gameType) throws SQLException - { - final ArrayList elo = new ArrayList(); + if (executeUpdate(UPDATE_ELO, new ColumnInt("elo", elo), new ColumnInt("accountId", accountId), new ColumnInt("gameType", gameType)) > 0) + return true; + else if (executeUpdate(INSERT_ELO, new ColumnInt("elo", elo), new ColumnInt("accountId", accountId), new ColumnInt("gameType", gameType)) > 0) + return true; - String query = GET_ALL_ELOS.replace("$gameType$", "MP" + gameType); - executeQuery(query, new ResultSetCallable() - { - @Override - public void processResultSet(ResultSet resultSet) throws SQLException - { - while (resultSet.next()) - { - elo.add(Integer.parseInt(resultSet.getString(1))); - } - } - }); - - return elo; - } - - //get an elo from the database - public int getRepoElo(String uuid, String gameType) throws SQLException - { - //elo set to 1000 by default - final List elo = new ArrayList(); - - String query = SELECT_ELO_BY_UUID.replace("$gameType$", "MP" + gameType); - //Bukkit.broadcastMessage("GetRepoElo: " + query); - executeQuery(query, new ResultSetCallable() - { - @Override - public void processResultSet(ResultSet resultSet) throws SQLException - { - while (resultSet.next()) - { - elo.add(Integer.parseInt(resultSet.getString(1))); - } - } - }, new ColumnVarChar("uuid", 100, uuid)); - - if (elo.isEmpty()) - elo.add(1000); - - return elo.get(0); - } - - public void saveElo(String uuid, String gameType, int elo) throws SQLException - { - String query = INSERT_ELO.replace("$gameType$", "MP" + gameType); - //Bukkit.broadcastMessage("EloRepository saveElo: " + query); - executeUpdate(query, new ColumnVarChar("uuid", 256, uuid), new ColumnInt(gameType, elo)); + return false; } public EloClientData loadClientInformation(ResultSet resultSet) throws SQLException @@ -100,7 +39,7 @@ public class EloRepository extends MinecraftRepository while (resultSet.next()) { - clientData.Elos.put(resultSet.getString(1), resultSet.getInt(2)); + clientData.Elos.put(resultSet.getInt(1), resultSet.getInt(2)); } return clientData; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloTeam.java b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloTeam.java index d0d2f0667..50996d227 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloTeam.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloTeam.java @@ -11,7 +11,7 @@ public class EloTeam public void addPlayer(EloPlayer player) { - TotalElo += player.rating; + TotalElo += player.getRating(); _players.add(player); } @@ -20,4 +20,14 @@ public class EloTeam { return _players; } + + public void printTeamInfo() + { + System.out.println("TotalElo: " + TotalElo); + + for (EloPlayer player : _players) + { + System.out.println(player.getPlayer().getName() + "'s Elo: " + player.getRating()); + } + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueManager.java index e1f06c6ef..19334819c 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueManager.java @@ -73,7 +73,7 @@ public class QueueManager extends MiniPlugin } } - public void queuePlayer(final String gameType, final Player...players) + public void queuePlayer(final int gameType, final Player...players) { StringBuilder stringBuilder = new StringBuilder(); @@ -103,7 +103,7 @@ public class QueueManager extends MiniPlugin for (Player player : players) { - eloCumulative = _eloManager.getElo(player.getUniqueId(), gameType); + eloCumulative = _eloManager.getElo(player, gameType); } final int elo = eloCumulative / players.length; @@ -116,7 +116,7 @@ public class QueueManager extends MiniPlugin synchronized (_queueLock) { - _queuedPlayerMatchList.put(players[0].getName(), matchStatus); + _queuedPlayerMatchList.put(players[0].getName(), matchStatus); } synchronized (_queuePlayerListLock) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java index 217e4cd49..416f6d1ba 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java @@ -12,7 +12,7 @@ public class QueueRepository { private boolean _us = true; - private static String CREATE_ELO_QUEUE_TABLE = "CREATE TABLE IF NOT EXISTS playerQueue (id INT NOT NULL AUTO_INCREMENT, playerList VARCHAR(256), gameType VARCHAR(256), playerCount INT, elo INT, state VARCHAR(256), time LONG, assignedMatch INT, US BOOLEAN NOT NULL DEFAULT '1', PRIMARY KEY (id), UNIQUE INDEX name_gametype (playerList, gameType));"; + private static String CREATE_ELO_QUEUE_TABLE = "CREATE TABLE IF NOT EXISTS playerQueue (id INT NOT NULL AUTO_INCREMENT, playerList VARCHAR(256), gameType INT, playerCount INT, elo INT, state VARCHAR(256), time LONG, assignedMatch INT, US BOOLEAN NOT NULL DEFAULT '1', PRIMARY KEY (id), UNIQUE INDEX name_gametype (playerList, gameType));"; private static String SAVE_STATE_VALUE = "UPDATE playerQueue SET state = ? WHERE id = ?;"; private static String DELETE_QUEUE_RECORD = "DELETE FROM playerQueue WHERE id = ?;"; private static String INSERT_ACCOUNT = "INSERT INTO playerQueue (playerList, gameType, elo, state, time, playerCount, assignedMatch) VALUES (?, ?, ?, 'Awaiting Match', now(), ?, -1) ON DUPLICATE KEY UPDATE time=VALUES(time);"; @@ -100,7 +100,7 @@ public class QueueRepository } } - public PlayerMatchStatus addQueueRecord(String playerList, int playerCount, String gameType, int elo) + public PlayerMatchStatus addQueueRecord(String playerList, int playerCount, int gameType, int elo) { ResultSet resultSet = null; PreparedStatement preparedStatement = null; @@ -110,7 +110,7 @@ public class QueueRepository { preparedStatement = connection.prepareStatement(INSERT_ACCOUNT, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, playerList); - preparedStatement.setString(2, gameType); + preparedStatement.setInt(2, gameType); preparedStatement.setInt(3, elo); //preparedStatement.setBoolean(4, _us); preparedStatement.setInt(4, playerCount); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java index b8794d407..f0a5122cb 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/ui/QueuePage.java @@ -105,7 +105,8 @@ public class QueuePage extends ShopPageBase @Override public void onClick(Player player, ClickType clickType) { - queuePlayer("Dominate", player); + // TODO GAMEID? + queuePlayer(1, player); } }; @@ -128,7 +129,7 @@ public class QueuePage extends ShopPageBase buildPage(); } - private void queuePlayer(String gameType, Player player) + private void queuePlayer(int gameType, Player player) { Party party = getPlugin().getPartyManager().GetParty(player); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 4ca2fdb4a..03de6b467 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -447,21 +447,6 @@ public abstract class Game implements Listener return _gameType.GetName(); } - //Add a column to EloRating/EloRatingTest for this game mode - public void addEloColumn() - { - //Bukkit.broadcastMessage("GameID: " + this.GetType().getGameId()); - - try { - - this.Manager.getEloManager().addGameToDatabase(GetType().getGameId() + ""); - - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - public GameType[] GetWorldHostNames() { GameType[] mapSource = new GameType[] @@ -1055,19 +1040,6 @@ public abstract class Game implements Listener return SpectatorSpawn; } - @EventHandler - public void eloStart(PlayerLoginEvent event) - { - if (EloRanking) - { - - if (Manager.getEloManager().getElo(event.getPlayer().getUniqueId(), GetType().getGameId() + "") == -1) - { - Manager.getEloManager().saveElo(event.getPlayer().getUniqueId(), GetType().getGameId() + "", EloStart); - } - } - } - @EventHandler public abstract void ScoreboardUpdate(UpdateEvent event); @@ -1291,9 +1263,6 @@ public abstract class Game implements Listener if (AnnounceSilence) Manager.GetChat().Silence(5000, false); - - //call adjustPlayerElo - adjustPlayerElo(places); } public void Announce(String message) @@ -1316,203 +1285,6 @@ public abstract class Game implements Listener System.out.println("[Announcement] " + message); } - - //calculate the elo multiplier for a player based on the average elo of all players - public int calculateEloMultiplier(int currentElo, int averageElo) - { - - int eloDifference = averageElo - currentElo; - - if (Math.abs(eloDifference) <= 50) - { - return 0; - } - if (eloDifference >= 200) - { - return 3; - } - if (eloDifference >= 100) - { - return 2; - } - if (eloDifference > 50) - { - return 1; - } - if (eloDifference <= -200) - { - return -3; - } - if (eloDifference <= -100) - { - return -2; - } - if (eloDifference < -50) - { - return -1; - } - - return 0; - } - - //INDIVIDUAL ELO -- adjust the elo's of every player, depending on their ranking in the game mode - public void adjustPlayerElo(List places) - { - int averageElo = 0; - for (Player player : UtilServer.getPlayers()) - { - averageElo += Manager.getEloManager().getElo(player.getUniqueId(), GetType().getGameId() + ""); - } - //average Elo of all players - averageElo = averageElo/places.size(); - - //update Elos of all players - assignEloPoints(places, averageElo); - - } - // calculate the average Elos of all players among 2 teams - public int getAverageElos(EloTeam team1, EloTeam team2) - { - EloTeam teamWinner = new EloTeam(); - EloTeam teamLoser = new EloTeam(); - List allPlayers = teamWinner.getPlayers(); - allPlayers.addAll(teamLoser.getPlayers()); - - int averageElo = 0; - for (EloPlayer player : allPlayers) - { - averageElo += player.rating; - } - //average Elo of all players - averageElo = averageElo/allPlayers.size(); - - return averageElo; - } - - //INDIVIDUAL ELO -- method to loop through every player and assign their new Elo - public void assignEloPoints(List places, int averageElo) - { - for (Player player : UtilServer.getPlayers()) - { - int currentElo = 1000; - - currentElo = Manager.getEloManager().getElo(player.getUniqueId(), GetType().getGameId() + ""); - - int lossMultiplier = 1; - int sizeModifier = 3; - int eloMultiplier = calculateEloMultiplier(currentElo, averageElo); - - //nobody won, add 10 points to all players - //Profitable enough see the match through to the end, but not enough for a stale-mate to be a more desirable outcome than 3rd place - if (places == null || places.isEmpty()) - { - int newElo = currentElo + 10; - - Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo); - - } - //Top 3 players get 25, 20, and 15 points, respectively - else - { - if (places.size() >= 1) - { - if (player.getUniqueId() == places.get(0).getUniqueId()) - { - int newElo = currentElo + 25 + (5 * eloMultiplier); - - Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo); - - } - } - if (places.size() >= 5) - { - if (player.getUniqueId() == places.get(1).getUniqueId()) - { - int newElo = currentElo + 20 + (5 * eloMultiplier); - - Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo); - - } - } - if (places.size() >= 6) - { - if (player.getUniqueId() == places.get(2).getUniqueId()) - { - if (eloMultiplier < -2) - { - eloMultiplier = -2; - } - - int newElo = currentElo + 15 + (5 * eloMultiplier); - - Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo); - - } - - } - if (places.size() > 6 && places.size() <= 7) - { - if (player.getUniqueId() == places.get(5).getUniqueId()) - { - if(eloMultiplier > 1) - { - eloMultiplier = 0; - } - - int newElo = currentElo - 5 + (5 * eloMultiplier); - - Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo); - - } - } - if (places.size() == 7) - { - if (player.getUniqueId() == places.get(6).getUniqueId()) - { - if(eloMultiplier > 2) - { - eloMultiplier = 2; - } - - int newElo = currentElo - 10 + (5 * eloMultiplier); - - Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo); - - } - } - if (places.size() >= 8) - { - //for games with 8+ players, this if statement is just going to run 3 times to check 3 different places - while(lossMultiplier != 0) - { - if (player.getUniqueId() == places.get(places.size() - sizeModifier).getUniqueId()) - { - if(eloMultiplier > lossMultiplier) - { - eloMultiplier = lossMultiplier; - } - - int newElo = currentElo - (5 * lossMultiplier) + (5 * eloMultiplier); - - Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo); - - if(sizeModifier >= 1) - { - lossMultiplier++; - sizeModifier--; - } - else - { - lossMultiplier = 0; - } - } - } - } - - } - - } - } public boolean AdvertiseText(GameLobbyManager gameLobbyManager, int _advertiseStage) { @@ -1775,7 +1547,6 @@ public abstract class Game implements Listener public void endGame(GameTeam winningTeam) { - AnnounceEnd(winningTeam); for (GameTeam team : GetTeamList()) @@ -1790,68 +1561,62 @@ public abstract class Game implements Listener if (player.isOnline()) AddGems(player, 10, "Participation", false, false); } - - //do Elo stuff -- + endElo(); // End SetState(GameState.End); } - //handle Elo at end of game -- method can be overridden in different game modes to meet their individual needs - public void endElo() + // Handle Elo at end of game -- method can be overridden in different game modes to meet their individual needs + protected void endElo() { - //Bukkit.broadcastMessage("endElo called"); if (EloRanking) { - //make a list of all players to help find average Elo + // Make a list of all players to help find average Elo EloTeam teamWinner = new EloTeam(); EloTeam teamLoser = new EloTeam(); - //populate teams + // Populate teams for (GameTeam team : GetTeamList()) { if (WinnerTeam != null && team.equals(WinnerTeam)) { for (Player player : WinnerTeam.GetPlayers(false)) { - EloPlayer eloPlayer = new EloPlayer(); - eloPlayer.setUniqueId(player.getUniqueId().toString()); - - eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetType().getGameId() + ""); - - teamWinner.addPlayer(eloPlayer); - } + teamWinner.addPlayer(new EloPlayer(player, Manager.getEloManager().getElo(player, GetType().getGameId()))); + } } else { for (Player player : team.GetPlayers(false)) { - EloPlayer eloPlayer = new EloPlayer(); - eloPlayer.setUniqueId(player.getUniqueId().toString()); - - eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetType().getGameId() + ""); - - teamLoser.addPlayer(eloPlayer); - + teamLoser.addPlayer(new EloPlayer(player, Manager.getEloManager().getElo(player, GetType().getGameId()))); } } } - //use teams to calculate Elo - for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers()) + EloTeam teamWinnerNew = Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win); + EloTeam teamLoserNew = Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss); + + System.out.println("Winning team:"); + teamWinner.printTeamInfo(); + teamWinnerNew.printTeamInfo(); + + System.out.println("Losing team:"); + teamLoser.printTeamInfo(); + teamLoserNew.printTeamInfo(); + + // Use teams to calculate Elo + for (EloPlayer eloPlayer : teamWinnerNew.getPlayers()) { - - Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetType().getGameId() + "", eloPlayer.rating); - //Bukkit.broadcastMessage("MP" + String.valueOf(this.GetType().getGameId()) + " endElo " + eloPlayer.getUniqueId() + " New Elo: " + eloPlayer.rating); + Manager.getEloManager().saveElo(eloPlayer.getPlayer(), GetType().getGameId(), eloPlayer.getRating()); } - for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers()) + for (EloPlayer eloPlayer : teamLoserNew.getPlayers()) { - Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetType().getGameId() + "", eloPlayer.rating); - //Bukkit.broadcastMessage("MP" + String.valueOf(this.GetType().getGameId()) + " endElo " + eloPlayer.getUniqueId() + " New Elo: " + eloPlayer.rating); + Manager.getEloManager().saveElo(eloPlayer.getPlayer(), GetType().getGameId(), eloPlayer.getRating()); } - } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/CaptureTheFlag.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/CaptureTheFlag.java index d1a8d9269..6ecb96ed2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/CaptureTheFlag.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/CaptureTheFlag.java @@ -551,51 +551,10 @@ public class CaptureTheFlag extends TeamGame if (player.isOnline()) AddGems(player, 10, "Participation", false, false); } - - if (EloRanking) - { - EloTeam teamWinner = new EloTeam(); - EloTeam teamLoser = new EloTeam(); - - for (GameTeam team : GetTeamList()) - { - if (WinnerTeam != null && team.equals(WinnerTeam)) - { - for (Player player : WinnerTeam.GetPlayers(false)) - { - EloPlayer eloPlayer = new EloPlayer(); - eloPlayer.setUniqueId(player.getUniqueId().toString()); - eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName()); - - teamWinner.addPlayer(eloPlayer); - } - } - else - { - for (Player player : team.GetPlayers(false)) - { - EloPlayer eloPlayer = new EloPlayer(); - eloPlayer.setUniqueId(player.getUniqueId().toString()); - eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName()); - - teamLoser.addPlayer(eloPlayer); - } - } - } - - for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers()) - { - Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating); - } - - for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers()) - { - Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating); - } - } + endElo(); //End - SetState(GameState.End); + SetState(GameState.End); } @Override diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/Domination.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/Domination.java index a1aa84a71..f8b287a10 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/Domination.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/common/Domination.java @@ -317,56 +317,7 @@ public class Domination extends TeamGame AddGems(player, 10, "Participation", false, false); } - if (EloRanking) - { - EloTeam teamWinner = new EloTeam(); - EloTeam teamLoser = new EloTeam(); - - for (GameTeam team : GetTeamList()) - { - if (WinnerTeam != null && team.equals(WinnerTeam)) - { - for (Player player : WinnerTeam.GetPlayers(false)) - { - EloPlayer eloPlayer = new EloPlayer(); - eloPlayer.setUniqueId(player.getUniqueId().toString()); - eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName()); - - //Increment Elo (in case it isn't being incremented already) - eloPlayer.rating += 20; - - teamWinner.addPlayer(eloPlayer); - } - } - else - { - for (Player player : team.GetPlayers(false)) - { - EloPlayer eloPlayer = new EloPlayer(); - eloPlayer.setUniqueId(player.getUniqueId().toString()); - eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName()); - - //Decrement Elo (in case it isn't being decremented already) - eloPlayer.rating -= 10; - - teamLoser.addPlayer(eloPlayer); - } - } - } - - for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers()) - { - eloPlayer.rating += 20; - Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating); - - } - - for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers()) - { - eloPlayer.rating -= 10; - Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating); - } - } + endElo(); //End SetState(GameState.End); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/turfforts/TurfForts.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/turfforts/TurfForts.java index 6246c632b..d633334e6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/turfforts/TurfForts.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/turfforts/TurfForts.java @@ -856,50 +856,7 @@ public class TurfForts extends TeamGame AddGems(player, 10, "Participation", false, false); } - if (EloRanking) - { - EloTeam teamWinner = new EloTeam(); - EloTeam teamLoser = new EloTeam(); - - for (GameTeam team : GetTeamList()) - { - if (WinnerTeam != null && team.equals(WinnerTeam)) - { - for (Player player : WinnerTeam.GetPlayers(false)) - { - EloPlayer eloPlayer = new EloPlayer(); - eloPlayer.setUniqueId(player.getUniqueId().toString()); - eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName()); - - teamWinner.addPlayer(eloPlayer); - Bukkit.broadcastMessage(player.getName() + "'s old Elo: " + eloPlayer.rating); - } - } - else - { - for (Player player : team.GetPlayers(false)) - { - EloPlayer eloPlayer = new EloPlayer(); - eloPlayer.setUniqueId(player.getUniqueId().toString()); - eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName()); - - teamLoser.addPlayer(eloPlayer); - Bukkit.broadcastMessage(player.getName() + "'s old Elo: " + eloPlayer.rating); - } - } - } - - for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers()) - { - Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating); - Bukkit.broadcastMessage(eloPlayer.getUniqueId() + "'s new Elo: " + eloPlayer.rating); - } - - for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers()) - { - Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating); - } - } + endElo(); //End SetState(GameState.End); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java index 1a4b5d956..2ea54a9a1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java @@ -1146,7 +1146,7 @@ public class GameLobbyManager implements Listener // Remove old entry.getValue().resetScores(_eloMap.get(entry.getKey()) + " "); - objective.getScore(Manager.getEloManager().getElo(entry.getKey().getUniqueId(), Manager.GetGame().GetType().getGameId() + "") + " ").setScore(line--); + objective.getScore(Manager.getEloManager().getElo(entry.getKey(), Manager.GetGame().GetType().getGameId()) + " ").setScore(line--); objective.getScore(" ").setScore(line--); } @@ -1161,7 +1161,7 @@ public class GameLobbyManager implements Listener entry.getValue().resetScores(_divisionMap.get(entry.getKey()) + " "); // Set new - objective.getScore(Manager.getEloManager().getPlayerDivision(entry.getKey().getUniqueId(), Manager.GetGame().GetType().getGameId() + "") + " ").setScore(line--); + objective.getScore(Manager.getEloManager().getPlayerDivision(entry.getKey(), Manager.GetGame().GetType().getGameId()) + " ").setScore(line--); objective.getScore(" ").setScore(line--); }