- cleaned up and prepped for live update

This commit is contained in:
AlexTheCoder 2016-04-21 20:57:35 -04:00
parent f86b18b603
commit d0e3b094c1
5 changed files with 75 additions and 102 deletions

View File

@ -99,7 +99,7 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
{
EloTeam newTeam = new EloTeam();
System.out.println("Old " + result + " Team Rating:" + teamA.TotalElo);
//System.out.println("Old " + result + " Team Rating:" + teamA.TotalElo);
int teamASize = teamA.getPlayers().size();
int teamBSize = teamB.getPlayers().size();
@ -111,7 +111,7 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
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);
//System.out.println("New " + result + " Team Rating:" + newTotal);
for (EloPlayer player : teamA.getPlayers())
{
@ -119,11 +119,11 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
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("Old:");
//player.printInfo();
System.out.println("New:");
newPlayer.printInfo();
//System.out.println("New:");
//newPlayer.printInfo();
newTeam.addPlayer(newPlayer);
}

View File

@ -1,6 +1,5 @@
package mineplex.core.elo;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@ -12,18 +11,16 @@ import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import org.bukkit.Bukkit;
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 eloRatingTest (uuid, $gameType$) VALUES (?, ?) ON DUPLICATE KEY UPDATE $gameType$=VALUES($gameType$);";
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 eloRatingTest WHERE uuid = ? LIMIT 1";
//private static String GET_ALL_ELOS = "SELECT $gameType$ FROM eloRating;";
private static String GET_ALL_ELOS = "SELECT $gameType$ FROM eloRatingTest;";
private static String ADD_GAME = "ALTER TABLE Accounts.eloRatingTest ADD $gameType$ INT;";
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;";
public EloRepository(JavaPlugin plugin)
{
@ -39,30 +36,29 @@ public class EloRepository extends MinecraftRepository
public void addGameType(String gameType) throws SQLException
{
String query = ADD_GAME.replace("$gameType$", gameType);
//executeUpdate(query, new ColumnInt(gameType));
Connection con = getConnection();
java.sql.Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
String query = ADD_GAME.replace("$gameType$", "MP" + gameType);
executeUpdate(query, new ColumnInt(gameType));
}
//method to return every Elo from DB
public ArrayList<Integer> getAllElos(String gameType) throws SQLException
{
ArrayList<Integer> allElos = new ArrayList<Integer>();
final ArrayList<Integer> elo = new ArrayList<Integer>();
String query = GET_ALL_ELOS.replace("$gameType$", gameType);
Connection con = getConnection();
java.sql.Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
//ResultSets start at 1, not 0
while(rs.next())
String query = GET_ALL_ELOS.replace("$gameType$", "MP" + gameType);
executeQuery(query, new ResultSetCallable()
{
allElos.add(rs.getInt(0));
}
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
elo.add(Integer.parseInt(resultSet.getString(1)));
}
}
});
return allElos;
return elo;
}
//get an elo from the database
@ -71,7 +67,7 @@ public class EloRepository extends MinecraftRepository
//elo set to 1000 by default
final List<Integer> elo = new ArrayList<Integer>();
String query = SELECT_ELO_BY_UUID.replace("$gameType$", gameType);
String query = SELECT_ELO_BY_UUID.replace("$gameType$", "MP" + gameType);
//Bukkit.broadcastMessage("GetRepoElo: " + query);
executeQuery(query, new ResultSetCallable()
{
@ -93,8 +89,8 @@ public class EloRepository extends MinecraftRepository
public void saveElo(String uuid, String gameType, int elo) throws SQLException
{
String query = INSERT_ELO.replace("$gameType$", gameType);
Bukkit.broadcastMessage("EloRepository saveElo: " + query);
String query = INSERT_ELO.replace("$gameType$", "MP" + gameType);
//Bukkit.broadcastMessage("EloRepository saveElo: " + query);
executeUpdate(query, new ColumnVarChar("uuid", 256, uuid), new ColumnInt(gameType, elo));
}

View File

@ -450,11 +450,11 @@ public abstract class Game implements Listener
//Add a column to EloRating/EloRatingTest for this game mode
public void addEloColumn()
{
Bukkit.broadcastMessage("GameID: " + this.GetType().getGameId());
//Bukkit.broadcastMessage("GameID: " + this.GetType().getGameId());
try {
this.Manager.getEloManager().addGameToDatabase("MP" + String.valueOf(this.GetType().getGameId()));
this.Manager.getEloManager().addGameToDatabase(GetType().getGameId() + "");
} catch (SQLException e) {
// TODO Auto-generated catch block
@ -1061,9 +1061,9 @@ public abstract class Game implements Listener
if (EloRanking)
{
if (Manager.getEloManager().getElo(event.getPlayer().getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId())) == -1)
if (Manager.getEloManager().getElo(event.getPlayer().getUniqueId(), GetType().getGameId() + "") == -1)
{
Manager.getEloManager().saveElo(event.getPlayer().getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()), EloStart);
Manager.getEloManager().saveElo(event.getPlayer().getUniqueId(), GetType().getGameId() + "", EloStart);
}
}
}
@ -1361,7 +1361,7 @@ public abstract class Game implements Listener
int averageElo = 0;
for (Player player : UtilServer.getPlayers())
{
averageElo += Manager.getEloManager().getElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()));
averageElo += Manager.getEloManager().getElo(player.getUniqueId(), GetType().getGameId() + "");
}
//average Elo of all players
averageElo = averageElo/places.size();
@ -1396,7 +1396,7 @@ public abstract class Game implements Listener
{
int currentElo = 1000;
currentElo = Manager.getEloManager().getElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()));
currentElo = Manager.getEloManager().getElo(player.getUniqueId(), GetType().getGameId() + "");
int lossMultiplier = 1;
int sizeModifier = 3;
@ -1408,7 +1408,7 @@ public abstract class Game implements Listener
{
int newElo = currentElo + 10;
Manager.getEloManager().saveElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()), newElo);
Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo);
}
//Top 3 players get 25, 20, and 15 points, respectively
@ -1420,7 +1420,7 @@ public abstract class Game implements Listener
{
int newElo = currentElo + 25 + (5 * eloMultiplier);
Manager.getEloManager().saveElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()), newElo);
Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo);
}
}
@ -1430,7 +1430,7 @@ public abstract class Game implements Listener
{
int newElo = currentElo + 20 + (5 * eloMultiplier);
Manager.getEloManager().saveElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()), newElo);
Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo);
}
}
@ -1445,7 +1445,7 @@ public abstract class Game implements Listener
int newElo = currentElo + 15 + (5 * eloMultiplier);
Manager.getEloManager().saveElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()), newElo);
Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo);
}
@ -1461,7 +1461,7 @@ public abstract class Game implements Listener
int newElo = currentElo - 5 + (5 * eloMultiplier);
Manager.getEloManager().saveElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()), newElo);
Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo);
}
}
@ -1476,7 +1476,7 @@ public abstract class Game implements Listener
int newElo = currentElo - 10 + (5 * eloMultiplier);
Manager.getEloManager().saveElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()), newElo);
Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo);
}
}
@ -1494,7 +1494,7 @@ public abstract class Game implements Listener
int newElo = currentElo - (5 * lossMultiplier) + (5 * eloMultiplier);
Manager.getEloManager().saveElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()), newElo);
Manager.getEloManager().saveElo(player.getUniqueId(), GetType().getGameId() + "", newElo);
if(sizeModifier >= 1)
{
@ -1818,7 +1818,7 @@ public abstract class Game implements Listener
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()));
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetType().getGameId() + "");
teamWinner.addPlayer(eloPlayer);
}
@ -1830,7 +1830,7 @@ public abstract class Game implements Listener
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()));
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetType().getGameId() + "");
teamLoser.addPlayer(eloPlayer);
@ -1842,14 +1842,14 @@ public abstract class Game implements Listener
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers())
{
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()), eloPlayer.rating);
Bukkit.broadcastMessage("MP" + String.valueOf(this.GetType().getGameId()) + " endElo " + eloPlayer.getUniqueId() + " New Elo: " + eloPlayer.rating);
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetType().getGameId() + "", eloPlayer.rating);
//Bukkit.broadcastMessage("MP" + String.valueOf(this.GetType().getGameId()) + " endElo " + eloPlayer.getUniqueId() + " New Elo: " + eloPlayer.rating);
}
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers())
{
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), "MP" + String.valueOf(this.GetType().getGameId()), eloPlayer.rating);
Bukkit.broadcastMessage("MP" + String.valueOf(this.GetType().getGameId()) + " endElo " + eloPlayer.getUniqueId() + " New Elo: " + eloPlayer.rating);
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetType().getGameId() + "", eloPlayer.rating);
//Bukkit.broadcastMessage("MP" + String.valueOf(this.GetType().getGameId()) + " endElo " + eloPlayer.getUniqueId() + " New Elo: " + eloPlayer.rating);
}
}

View File

@ -1,16 +1,32 @@
package nautilus.game.arcade.game.games.common;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.DeathMessageType;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
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.GameTeam.PlayerState;
import nautilus.game.arcade.game.TeamGame;
import nautilus.game.arcade.game.games.common.dominate_data.CapturePointTDM;
import nautilus.game.arcade.game.games.common.dominate_data.Resupply;
import nautilus.game.arcade.kit.Kit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -21,38 +37,6 @@ import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.scoreboard.Objective;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.elo.EloPlayer;
import mineplex.core.elo.EloTeam;
import mineplex.core.elo.GameResult;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.DeathMessageType;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
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.TeamGame;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.games.champions.kits.KitAssassin;
import nautilus.game.arcade.game.games.champions.kits.KitBrute;
import nautilus.game.arcade.game.games.champions.kits.KitKnight;
import nautilus.game.arcade.game.games.champions.kits.KitMage;
import nautilus.game.arcade.game.games.champions.kits.KitRanger;
import nautilus.game.arcade.game.games.common.dominate_data.CapturePoint;
import nautilus.game.arcade.game.games.common.dominate_data.CapturePointTDM;
import nautilus.game.arcade.game.games.common.dominate_data.Emerald;
import nautilus.game.arcade.game.games.common.dominate_data.Resupply;
import nautilus.game.arcade.kit.Kit;
public class TeamDeathmatch extends TeamGame
{
private ArrayList<CapturePointTDM> _points = new ArrayList<CapturePointTDM>();
@ -82,10 +66,10 @@ public class TeamDeathmatch extends TeamGame
this.WorldTimeSet = 2000;
this.CompassEnabled = true;
this.EloRanking = true;
this.EloSetting.setEloSetting(2);
//this.EloRanking = true;
//this.EloSetting.setEloSetting(2);
this.addEloColumn();
//this.addEloColumn();
/*
try
@ -372,7 +356,7 @@ public class TeamDeathmatch extends TeamGame
SetState(GameState.End);
}
//call endElo (Game.Java) if the game ends
/*//call endElo (Game.Java) if the game ends
@EventHandler
public void EloCalc(GameStateChangeEvent event)
{
@ -384,7 +368,7 @@ public class TeamDeathmatch extends TeamGame
endElo();
}
}
}
}*/
@EventHandler(priority = EventPriority.HIGHEST)
public void UsableInteract(PlayerInteractEvent event)

View File

@ -19,17 +19,13 @@ import mineplex.core.common.util.UtilBlockText.TextAlign;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.cosmetic.event.ActivateGemBoosterEvent;
import mineplex.core.donation.Donor;
import mineplex.core.event.CustomTagEvent;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.core.packethandler.PacketVerifier;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -43,9 +39,6 @@ import nautilus.game.arcade.game.games.uhc.UHC;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.KitSorter;
import net.minecraft.server.v1_8_R3.DataWatcher.WatchableObject;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -1153,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(), "MP" + String.valueOf(Manager.GetGame().GetType().getGameId())) + " ").setScore(line--);
objective.getScore(Manager.getEloManager().getElo(entry.getKey().getUniqueId(), Manager.GetGame().GetType().getGameId() + "") + " ").setScore(line--);
objective.getScore(" ").setScore(line--);
}
@ -1168,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(), "MP" + String.valueOf(Manager.GetGame().GetType().getGameId())) + " ").setScore(line--);
objective.getScore(Manager.getEloManager().getPlayerDivision(entry.getKey().getUniqueId(), Manager.GetGame().GetType().getGameId() + "") + " ").setScore(line--);
objective.getScore(" ").setScore(line--);
}