Elo calls migrated to Game.java
Consequently, elo code is actually being called now Bukkit.broadcastMessage calls have shown where things are breaking handleElo() added to EloManager to facilitate movement of team elo code preparing to use EloManager's getNewRatings() method to calculate team elos
This commit is contained in:
parent
4a4e64a3ff
commit
bbb81dd663
@ -37,6 +37,14 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
|
||||
|
||||
}
|
||||
|
||||
//add an EloPlayer's info to _playerElos
|
||||
public void addToPlayerElos(EloPlayer player, String gameType)
|
||||
{
|
||||
NautHashMap<String, Integer> playerInfo = new NautHashMap<String, Integer>();
|
||||
playerInfo.put(player.getUniqueId(), player.Rating);
|
||||
_playerElos.put(gameType, playerInfo);
|
||||
}
|
||||
|
||||
/*
|
||||
* fill _playerElos with information from database
|
||||
* If no entry exists, create one
|
||||
@ -111,32 +119,43 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
|
||||
|
||||
public void saveElo(UUID uuid, String gameType, int elo)
|
||||
{
|
||||
String playerDiv = getPlayerDivision(uuid, gameType);
|
||||
//Bukkit.broadcastMessage("SAVE_ELO - EloManager (uuid type) called");
|
||||
//String playerDiv = getPlayerDivision(uuid, gameType);
|
||||
saveElo(uuid.toString(), gameType, elo);
|
||||
saveDivision(uuid.toString(), gameType, playerDiv);
|
||||
//saveDivision(uuid.toString(), gameType, playerDiv);
|
||||
}
|
||||
|
||||
public void saveElo(final String uuid, final String gameType, final int elo)
|
||||
{
|
||||
//Bukkit.broadcastMessage("SAVE_ELO - EloManager (String type) called");
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
|
||||
try {
|
||||
//it hits this, but doesn't hit the message below.
|
||||
_repository.saveElo(uuid, gameType, elo);
|
||||
Bukkit.broadcastMessage("Attempting to saveElo...");
|
||||
Bukkit.broadcastMessage("Attempting to save " + elo + " as Elo from repository...");
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Bukkit.broadcastMessage("EloManager SaveElo (string) - CATCH hit");
|
||||
}
|
||||
|
||||
//Doesn't hit any of this, to my knowledge - JP
|
||||
synchronized (_playerEloLock)
|
||||
{
|
||||
//Bukkit.broadcastMessage("EloManager SaveElo (string) - _playerEloLock synchronized...");
|
||||
if (_playerElos.containsKey(uuid))
|
||||
{
|
||||
//Bukkit.broadcastMessage("EloManager SaveElo (string) - uuid found in _playerElos");
|
||||
if (_playerElos.get(uuid).containsKey(gameType))
|
||||
{
|
||||
//Bukkit.broadcastMessage("EloManager SaveElo (string) - gameType found in _playerElos");
|
||||
_playerElos.get(uuid).put(gameType, elo);
|
||||
//Bukkit.broadcastMessage("Attempting to save " + elo + " as Elo from hash map...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import mineplex.core.database.MinecraftRepository;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.mysql.jdbc.PreparedStatement;
|
||||
import com.mysql.jdbc.Statement;
|
||||
|
||||
import mineplex.serverdata.database.DBPool;
|
||||
@ -25,6 +26,8 @@ public class EloRepository extends MinecraftRepository
|
||||
private static String INSERT_DIVISION = "INSERT INTO eloRating (uuid, gameType, division) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE division=VALUES(division);";
|
||||
private static String UPDATE_ELO = "UPDATE eloRating SET elo=? WHERE uuid=?;";
|
||||
private static String SELECT_ELO_BY_UUID = "SELECT elo FROM eloRating WHERE uuid = ? LIMIT 1";
|
||||
private static String SELECT_DIVISION_BY_UUID = "SELECT division FROM eloRating WHERE uuid = ? LIMIT 1";
|
||||
private static String UPDATE_DIVISION = "UPDATE eloRating SET division=? WHERE uuid=?;";
|
||||
private static String ELO_NEW = "INSERT INTO eloRating (uuid, gameType, elo), values(?, ?, ?);";
|
||||
|
||||
public EloRepository(JavaPlugin plugin)
|
||||
@ -39,26 +42,30 @@ public class EloRepository extends MinecraftRepository
|
||||
//executeUpdate(CREATE_ELO_TABLE);
|
||||
}
|
||||
|
||||
//A few get methods to make grabbing info from the database easier
|
||||
|
||||
//get an elo from the database
|
||||
public int getRepoElo(String uuid, String gameType) throws SQLException
|
||||
{
|
||||
//elo set to 1000 by default
|
||||
int elo = 1000;
|
||||
|
||||
try (Connection con = getConnection(); java.sql.Statement satement = con.createStatement())
|
||||
try (Connection con = getConnection(); java.sql.PreparedStatement pStatement = con.prepareStatement(SELECT_ELO_BY_UUID);)
|
||||
{
|
||||
satement.execute(SELECT_ELO_BY_UUID);
|
||||
ResultSet resultSet = satement.getResultSet();
|
||||
pStatement.execute(SELECT_ELO_BY_UUID);
|
||||
pStatement.setString(1, uuid.toString());
|
||||
ResultSet resultSet = pStatement.executeQuery();
|
||||
|
||||
//if something was found, return the elo
|
||||
if(resultSet.next())
|
||||
{
|
||||
elo = resultSet.getInt(1);
|
||||
elo = resultSet.getInt("elo");
|
||||
Bukkit.broadcastMessage("getRepoElo pulled " + elo + "from database for " + uuid);
|
||||
return elo;
|
||||
}
|
||||
else
|
||||
{
|
||||
saveElo(uuid, gameType, elo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return elo;
|
||||
@ -67,27 +74,40 @@ public class EloRepository extends MinecraftRepository
|
||||
public void saveElo(String uuid, String gameType, int elo) throws SQLException
|
||||
{
|
||||
Connection con = getConnection();
|
||||
java.sql.Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
|
||||
String selectQuery = SELECT_ELO_BY_UUID;
|
||||
ResultSet rs = stmt.executeQuery(selectQuery);
|
||||
java.sql.PreparedStatement stmt = con.prepareStatement(SELECT_ELO_BY_UUID);
|
||||
stmt.setString(1, uuid.toString());
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
|
||||
boolean contains = false;
|
||||
|
||||
Bukkit.broadcastMessage("SAVE_ELO - EloRepository called");
|
||||
|
||||
Bukkit.broadcastMessage("Pre-loop - Result Set Boolean:" + rs.toString());
|
||||
|
||||
while (rs.next())
|
||||
{
|
||||
Bukkit.broadcastMessage("Result Set Boolean:" + rs.toString());
|
||||
contains = true;
|
||||
//update elo
|
||||
executeUpdate(UPDATE_ELO, new ColumnVarChar("elo", 100, uuid));
|
||||
Bukkit.broadcastMessage("Updating existing elo");
|
||||
java.sql.PreparedStatement updateStatement = con.prepareStatement(UPDATE_ELO);
|
||||
updateStatement.setInt(1, elo);
|
||||
updateStatement.setString(2, uuid.toString());
|
||||
updateStatement.executeUpdate();
|
||||
//executeUpdate(UPDATE_ELO, new ColumnInt("elo", elo));
|
||||
Bukkit.broadcastMessage("SAVE_ELO - EloRepository: Updating existing elo to " + elo);
|
||||
}
|
||||
if(!contains)
|
||||
{
|
||||
//insert elo
|
||||
executeUpdate(INSERT_ELO, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("gameType", 100, gameType), new ColumnInt("elo", elo));
|
||||
Bukkit.broadcastMessage("Adding new player elo to " + gameType +" elo database...");
|
||||
java.sql.PreparedStatement updateStatement = con.prepareStatement(INSERT_ELO);
|
||||
updateStatement.setInt(1, elo);
|
||||
updateStatement.setString(2, uuid.toString());
|
||||
updateStatement.executeUpdate();
|
||||
//executeUpdate(INSERT_ELO, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("gameType", 100, gameType), new ColumnInt("elo", elo));
|
||||
Bukkit.broadcastMessage("SAVE_ELO - EloRepository: Adding " + elo + " to " + gameType +" elo database...");
|
||||
}
|
||||
|
||||
|
||||
Bukkit.broadcastMessage("SAVE_ELO - EloRepository: Adding " + elo + " to " + gameType +" elo database...");
|
||||
}
|
||||
|
||||
public void saveDivision(String uuid, String gameType, String division) throws SQLException
|
||||
|
@ -55,7 +55,9 @@ import mineplex.core.common.util.UtilTabTitle;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.disguise.disguises.DisguisePlayer;
|
||||
import mineplex.core.elo.EloPlayer;
|
||||
import mineplex.core.elo.EloSettings;
|
||||
import mineplex.core.elo.EloTeam;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.packethandler.IPacketHandler;
|
||||
import mineplex.core.packethandler.PacketInfo;
|
||||
@ -1039,6 +1041,7 @@ public abstract class Game implements Listener
|
||||
@EventHandler
|
||||
public void eloStart(PlayerLoginEvent event)
|
||||
{
|
||||
Bukkit.broadcastMessage("eloStart called in Game. Player's Elo should be saved.");
|
||||
if (EloRanking)
|
||||
{
|
||||
if (Manager.getEloManager().getElo(event.getPlayer().getUniqueId(), GetName()) == -1)
|
||||
@ -1210,6 +1213,9 @@ public abstract class Game implements Listener
|
||||
}
|
||||
|
||||
UtilTextMiddle.display(winnerText, subColor + "won the game", 20, 120, 20);
|
||||
|
||||
//try to do Elo stuff
|
||||
handleElo();
|
||||
|
||||
if (AnnounceSilence)
|
||||
Manager.GetChat().Silence(5000, false);
|
||||
@ -1734,10 +1740,75 @@ public abstract class Game implements Listener
|
||||
if (player.isOnline())
|
||||
AddGems(player, 10, "Participation", false, false);
|
||||
}
|
||||
|
||||
handleElo();
|
||||
|
||||
// End
|
||||
SetState(GameState.End);
|
||||
}
|
||||
|
||||
public void handleElo()
|
||||
{
|
||||
UtilTextMiddle.display("HandleElo Called", "at Game AnnounceEnd (team)");
|
||||
//Bukkit.broadcastMessage("handleElo called");
|
||||
if (EloRanking)
|
||||
{
|
||||
Bukkit.broadcastMessage("Game Class EloRanking = True");
|
||||
|
||||
EloTeam teamWinner = new EloTeam();
|
||||
EloTeam teamLoser = new EloTeam();
|
||||
|
||||
//EloManager may make most of the code below redundant. leaving inactive, pending testing
|
||||
//Manager.getEloManager().getNewRatings(teamA, teamB, result)
|
||||
|
||||
for (GameTeam team : GetTeamList())
|
||||
{
|
||||
if (WinnerTeam != null && team.equals(WinnerTeam))
|
||||
{
|
||||
for (Player player : WinnerTeam.GetPlayers(false))
|
||||
{
|
||||
Bukkit.broadcastMessage("Game Class WinnerTeam For Loop Reached");
|
||||
|
||||
EloPlayer eloPlayer = new EloPlayer();
|
||||
eloPlayer.setUniqueId(player.getUniqueId().toString());
|
||||
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
|
||||
|
||||
teamWinner.addPlayer(eloPlayer);
|
||||
|
||||
eloPlayer.Rating += 25;
|
||||
|
||||
Manager.getEloManager().addToPlayerElos(eloPlayer, this.GetName());
|
||||
|
||||
Bukkit.broadcastMessage(player.getName() + " GetTeamList Elo: " + eloPlayer.Rating);
|
||||
|
||||
Manager.getEloManager().saveElo(player.getUniqueId(), GetName(), eloPlayer.Rating);
|
||||
Bukkit.broadcastMessage(player.getName() + " Post-Save Elo: " + eloPlayer.Rating);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player player : team.GetPlayers(false))
|
||||
{
|
||||
Bukkit.broadcastMessage("Game Class LosingTeam For Loop Reached");
|
||||
|
||||
EloPlayer eloPlayer = new EloPlayer();
|
||||
eloPlayer.setUniqueId(player.getUniqueId().toString());
|
||||
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
|
||||
teamLoser.addPlayer(eloPlayer);
|
||||
|
||||
eloPlayer.Rating -= 15;
|
||||
|
||||
Bukkit.broadcastMessage(player.getName() + " GetTeamList Elo: " + eloPlayer.Rating);
|
||||
|
||||
Manager.getEloManager().saveElo(player.getUniqueId(), GetName(), eloPlayer.Rating);
|
||||
Bukkit.broadcastMessage(player.getName() + " Post-Save Elo: " + eloPlayer.Rating);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleInteractEntityPacket(GameStateChangeEvent event)
|
||||
|
@ -354,9 +354,13 @@ public class TeamDeathmatch extends TeamGame
|
||||
if (player.isOnline())
|
||||
AddGems(player, 10, "Participation", false, false);
|
||||
}
|
||||
|
||||
Bukkit.broadcastMessage("TDM AnnounceEnd Called");
|
||||
|
||||
if (EloRanking)
|
||||
{
|
||||
Bukkit.broadcastMessage("TDM EloRanking = True");
|
||||
|
||||
EloTeam teamWinner = new EloTeam();
|
||||
EloTeam teamLoser = new EloTeam();
|
||||
|
||||
@ -366,6 +370,8 @@ public class TeamDeathmatch extends TeamGame
|
||||
{
|
||||
for (Player player : WinnerTeam.GetPlayers(false))
|
||||
{
|
||||
Bukkit.broadcastMessage("TDM WinnerTeam For Loop Reached");
|
||||
|
||||
EloPlayer eloPlayer = new EloPlayer();
|
||||
eloPlayer.setUniqueId(player.getUniqueId().toString());
|
||||
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
|
||||
@ -374,6 +380,8 @@ public class TeamDeathmatch extends TeamGame
|
||||
|
||||
eloPlayer.Rating += 25;
|
||||
|
||||
Manager.getEloManager().addToPlayerElos(eloPlayer, this.GetName());
|
||||
|
||||
Bukkit.broadcastMessage(player.getName() + " GetTeamList Elo: " + eloPlayer.Rating);
|
||||
|
||||
Manager.getEloManager().saveElo(player.getUniqueId(), GetName(), eloPlayer.Rating);
|
||||
@ -400,21 +408,21 @@ public class TeamDeathmatch extends TeamGame
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers())
|
||||
{
|
||||
eloPlayer.Rating += 20;
|
||||
Manager.getEloManager().saveElo(eloPlayer.UniqueId, GetName(), eloPlayer.Rating);
|
||||
Bukkit.broadcastMessage(eloPlayer.UniqueId + "Post-Save Elo: " + eloPlayer.Rating);
|
||||
eloPlayer.Rating += 25;
|
||||
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.Rating);
|
||||
Bukkit.broadcastMessage(eloPlayer.getUniqueId() + "Post-Save Elo: " + eloPlayer.Rating);
|
||||
}
|
||||
|
||||
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers())
|
||||
{
|
||||
eloPlayer.Rating -= 10;
|
||||
Manager.getEloManager().saveElo(eloPlayer.UniqueId, GetName(), eloPlayer.Rating);
|
||||
Bukkit.broadcastMessage(eloPlayer.UniqueId + "Post-Save Elo: " + eloPlayer.Rating);
|
||||
eloPlayer.Rating -= 15;
|
||||
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.Rating);
|
||||
Bukkit.broadcastMessage(eloPlayer.getUniqueId() + "Post-Save Elo: " + eloPlayer.Rating);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
//End
|
||||
|
Loading…
Reference in New Issue
Block a user