Remove File headers.
This commit is contained in:
parent
680e579223
commit
562e950361
@ -1,15 +1,10 @@
|
||||
package mineplex.core.elo;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import mineplex.core.MiniDbClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -20,25 +15,25 @@ import java.sql.SQLException;
|
||||
|
||||
public class EloManager extends MiniDbClientPlugin<EloClientData>
|
||||
{
|
||||
private EloRepository _repository;
|
||||
private EloRatingSystem _ratingSystem;
|
||||
private NautHashMap<String, EloTeam> _eloTeams = new NautHashMap<>();
|
||||
|
||||
public EloManager(JavaPlugin plugin, CoreClientManager clientManager)
|
||||
{
|
||||
super("Elo Rating", plugin, clientManager);
|
||||
private EloRepository _repository;
|
||||
private EloRatingSystem _ratingSystem;
|
||||
private NautHashMap<String, EloTeam> _eloTeams = new NautHashMap<>();
|
||||
|
||||
_repository = new EloRepository(plugin);
|
||||
_ratingSystem = new EloRatingSystem
|
||||
(
|
||||
new KFactor(0, 1299, 50),
|
||||
new KFactor(1300, 1899, 45),
|
||||
new KFactor(1900, 2499, 40),
|
||||
new KFactor(2500, 3099, 30),
|
||||
new KFactor(3100, 3699, 20),
|
||||
new KFactor(3700, 5000, 10)
|
||||
);
|
||||
}
|
||||
public EloManager(JavaPlugin plugin, CoreClientManager clientManager)
|
||||
{
|
||||
super("Elo Rating", plugin, clientManager);
|
||||
|
||||
_repository = new EloRepository(plugin);
|
||||
_ratingSystem = new EloRatingSystem
|
||||
(
|
||||
new KFactor(0, 1299, 50),
|
||||
new KFactor(1300, 1899, 45),
|
||||
new KFactor(1900, 2499, 40),
|
||||
new KFactor(2500, 3099, 30),
|
||||
new KFactor(3100, 3699, 20),
|
||||
new KFactor(3700, 5000, 10)
|
||||
);
|
||||
}
|
||||
|
||||
public EloRepository getRepo()
|
||||
{
|
||||
@ -52,289 +47,252 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
|
||||
addCommand(new TopEloCommand(this));
|
||||
}
|
||||
|
||||
public int getElo(Player player, int gameType)
|
||||
{
|
||||
if (!Get(player).Elos.containsKey(gameType))
|
||||
return 1000;
|
||||
|
||||
return Get(player).Elos.get(gameType);
|
||||
}
|
||||
|
||||
public EloTeam getNewRatings(EloTeam teamA, EloTeam teamB, GameResult result)
|
||||
{
|
||||
EloTeam newTeam = new EloTeam();
|
||||
public int getElo(Player player, int gameType)
|
||||
{
|
||||
if (!Get(player).Elos.containsKey(gameType))
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
|
||||
int newTotal = _ratingSystem.getNewRating(teamA.TotalElo / teamA.getPlayers().size(), teamB.TotalElo / teamB.getPlayers().size(), result) * teamA.getPlayers().size();
|
||||
int kTotal = 0;
|
||||
|
||||
for (EloPlayer player : teamA.getPlayers())
|
||||
{
|
||||
kTotal += _ratingSystem.getKFactor(player.getRating());
|
||||
}
|
||||
|
||||
for (EloPlayer player : teamA.getPlayers())
|
||||
{
|
||||
int newRating = (int)(player.getRating() + ((double)_ratingSystem.getKFactor(player.getRating()) / (double)kTotal) * (newTotal - teamA.TotalElo));
|
||||
EloPlayer newPlayer = new EloPlayer(player.getPlayer(), player.getAccountId(), newRating);
|
||||
return Get(player).Elos.get(gameType);
|
||||
}
|
||||
|
||||
newTeam.addPlayer(newPlayer);
|
||||
}
|
||||
|
||||
return newTeam;
|
||||
}
|
||||
|
||||
public void saveElo(final Player player, final int accountId, final int gameType, final int oldElo, final int elo)
|
||||
{
|
||||
runAsync(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
boolean success = false;
|
||||
|
||||
try
|
||||
{
|
||||
success = _repository.saveElo(accountId, gameType, oldElo, elo);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
System.out.println("Saving " + accountId + "'s new elo rating of " + elo + " for gameType " + gameType + (success ? " SUCCEEDED." : " FAILED."));
|
||||
}
|
||||
|
||||
final boolean finalSuccess = success;
|
||||
|
||||
runSync(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (finalSuccess)
|
||||
{
|
||||
if (player.isOnline())
|
||||
Get(player).Elos.put(gameType, elo);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*public String getPlayerDivision(Player player, int gameType)
|
||||
{
|
||||
int playerElo = getElo(player, gameType);
|
||||
String divisionName = "Player's division";
|
||||
|
||||
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 divisionName;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
protected EloClientData AddPlayer(String player)
|
||||
{
|
||||
return new EloClientData();
|
||||
}
|
||||
public EloTeam getNewRatings(EloTeam teamA, EloTeam teamB, GameResult result)
|
||||
{
|
||||
EloTeam newTeam = new EloTeam();
|
||||
|
||||
@Override
|
||||
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
|
||||
{
|
||||
Set(playerName, _repository.loadClientInformation(resultSet));
|
||||
}
|
||||
int newTotal = _ratingSystem.getNewRating(teamA.TotalElo / teamA.getPlayers().size(), teamB.TotalElo / teamB.getPlayers().size(), result) * teamA.getPlayers().size();
|
||||
int kTotal = 0;
|
||||
|
||||
@Override
|
||||
public String getQuery(int accountId, String uuid, String name)
|
||||
{
|
||||
return "SELECT gameType, elo FROM eloRating WHERE accountId = '" + accountId + "';";
|
||||
}
|
||||
for (EloPlayer player : teamA.getPlayers())
|
||||
{
|
||||
kTotal += _ratingSystem.getKFactor(player.getRating());
|
||||
}
|
||||
|
||||
public void addTeam(String displayName, EloTeam eloTeam)
|
||||
{
|
||||
_eloTeams.put(displayName, eloTeam);
|
||||
}
|
||||
for (EloPlayer player : teamA.getPlayers())
|
||||
{
|
||||
int newRating = (int) (player.getRating() + (_ratingSystem.getKFactor(player.getRating()) / (double) kTotal) * (newTotal - teamA.TotalElo));
|
||||
EloPlayer newPlayer = new EloPlayer(player.getPlayer(), player.getAccountId(), newRating);
|
||||
|
||||
public void setWinningTeam(String displayName)
|
||||
{
|
||||
_eloTeams.get(displayName).Winner = true;
|
||||
}
|
||||
newTeam.addPlayer(newPlayer);
|
||||
}
|
||||
|
||||
public boolean isRankBanned(int accountId)
|
||||
{
|
||||
boolean banExpired = System.currentTimeMillis() >= getRankBanExpiry(accountId);
|
||||
return newTeam;
|
||||
}
|
||||
|
||||
if (banExpired)
|
||||
{
|
||||
if (System.currentTimeMillis() >= _repository.getStrikeExpiry(accountId))
|
||||
{
|
||||
_repository.resetStrikes(accountId);
|
||||
}
|
||||
}
|
||||
return !banExpired;
|
||||
}
|
||||
public void saveElo(final Player player, final int accountId, final int gameType, final int oldElo, final int elo)
|
||||
{
|
||||
runAsync(() -> {
|
||||
boolean success = false;
|
||||
|
||||
public long getRankBanExpiry(int accountId)
|
||||
{
|
||||
return _repository.getBanExpiry(accountId);
|
||||
}
|
||||
try
|
||||
{
|
||||
success = _repository.saveElo(accountId, gameType, oldElo, elo);
|
||||
} catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} finally
|
||||
{
|
||||
System.out.println("Saving " + accountId + "'s new elo rating of " + elo + " for gameType " + gameType + (success ? " SUCCEEDED." : " FAILED."));
|
||||
}
|
||||
|
||||
public void banFromRanked(int accountId)
|
||||
{
|
||||
_repository.addRankedBan(accountId);
|
||||
}
|
||||
final boolean finalSuccess = success;
|
||||
|
||||
public void endMatch(int gameId)
|
||||
{
|
||||
EloTeam teamWinner = null;
|
||||
EloTeam teamLoser = null;
|
||||
|
||||
for (EloTeam team : _eloTeams.values())
|
||||
{
|
||||
if (team.Winner)
|
||||
teamWinner = team;
|
||||
else
|
||||
teamLoser = team;
|
||||
}
|
||||
|
||||
EloTeam teamWinnerNew = getNewRatings(teamWinner, teamLoser, GameResult.Win);
|
||||
EloTeam teamLoserNew = getNewRatings(teamLoser, teamWinner, GameResult.Loss);
|
||||
|
||||
// Use teams to calculate Elo
|
||||
for (EloPlayer eloPlayer : teamWinnerNew.getPlayers())
|
||||
{
|
||||
int oldElo = teamWinner.getPlayer(eloPlayer.getPlayer().getUniqueId().toString()).getRating();
|
||||
|
||||
// If this is the first time.
|
||||
if (!Get(eloPlayer.getPlayer()).Elos.containsKey(gameId))
|
||||
oldElo = eloPlayer.getRating();
|
||||
|
||||
saveElo(eloPlayer.getPlayer(), eloPlayer.getAccountId(), gameId, oldElo, eloPlayer.getRating());
|
||||
}
|
||||
runSync(() -> {
|
||||
if (finalSuccess)
|
||||
{
|
||||
if (player.isOnline())
|
||||
{
|
||||
Get(player).Elos.put(gameType, elo);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
for (EloPlayer eloPlayer : teamLoserNew.getPlayers())
|
||||
{
|
||||
int oldElo = teamLoser.getPlayer(eloPlayer.getPlayer().getUniqueId().toString()).getRating();
|
||||
|
||||
// If this is the first time.
|
||||
if (!Get(eloPlayer.getPlayer()).Elos.containsKey(gameId))
|
||||
oldElo = eloPlayer.getRating();
|
||||
|
||||
saveElo(eloPlayer.getPlayer(), eloPlayer.getAccountId(), gameId, oldElo, eloPlayer.getRating());
|
||||
}
|
||||
|
||||
_eloTeams.clear();
|
||||
}
|
||||
@Override
|
||||
protected EloClientData AddPlayer(String player)
|
||||
{
|
||||
return new EloClientData();
|
||||
}
|
||||
|
||||
public static enum EloDivision
|
||||
{
|
||||
DIAMOND("Diamond", -1, 3700, Material.DIAMOND_BLOCK),
|
||||
EMERALD_3("Emerald 3", 3699, 3500, Material.EMERALD_BLOCK),
|
||||
EMERALD_2("Emerald 2", 3499, 3300, Material.EMERALD_BLOCK),
|
||||
EMERALD_1("Emerald 1", 3299, 3100, Material.EMERALD_BLOCK),
|
||||
LAPIS_3("Lapis 3", 3099, 2900, Material.LAPIS_BLOCK),
|
||||
LAPIS_2("Lapis 2", 2899, 2700, Material.LAPIS_BLOCK),
|
||||
LAPIS_1("Lapis 1", 2699, 2500, Material.LAPIS_BLOCK),
|
||||
GOLD_3("Gold 3", 2499, 2300, Material.GOLD_BLOCK),
|
||||
GOLD_2("Gold 2", 2299, 2100, Material.GOLD_BLOCK),
|
||||
GOLD_1("Gold 1", 2099, 1900, Material.GOLD_BLOCK),
|
||||
IRON_3("Iron 3", 1899, 1700, Material.IRON_BLOCK),
|
||||
IRON_2("Iron 2", 1699, 1500, Material.IRON_BLOCK),
|
||||
IRON_1("Iron 1", 1499, 1300, Material.IRON_BLOCK),
|
||||
COAL_3("Coal 3", 1299, 1100, Material.COAL_BLOCK),
|
||||
COAL_2("Coal 2", 1099, 900, Material.COAL_BLOCK),
|
||||
COAL_1("Coal 1", 899, -1, Material.COAL_BLOCK);
|
||||
@Override
|
||||
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
|
||||
{
|
||||
Set(playerName, _repository.loadClientInformation(resultSet));
|
||||
}
|
||||
|
||||
private String _disp;
|
||||
private int _maxElo, _minElo;
|
||||
private Material _visual;
|
||||
@Override
|
||||
public String getQuery(int accountId, String uuid, String name)
|
||||
{
|
||||
return "SELECT gameType, elo FROM eloRating WHERE accountId = '" + accountId + "';";
|
||||
}
|
||||
|
||||
private EloDivision(String display, int maxElo, int minElo, Material visual)
|
||||
{
|
||||
_disp = display;
|
||||
_maxElo = maxElo;
|
||||
_minElo = minElo;
|
||||
_visual = visual;
|
||||
}
|
||||
public void addTeam(String displayName, EloTeam eloTeam)
|
||||
{
|
||||
_eloTeams.put(displayName, eloTeam);
|
||||
}
|
||||
|
||||
public String getDisplayName()
|
||||
{
|
||||
return _disp;
|
||||
}
|
||||
public void setWinningTeam(String displayName)
|
||||
{
|
||||
_eloTeams.get(displayName).Winner = true;
|
||||
}
|
||||
|
||||
public ItemStack getVisual(int elo)
|
||||
{
|
||||
ItemBuilder build = new ItemBuilder(_visual);
|
||||
build.setTitle(C.cGreen + _disp);
|
||||
int percentage = (elo * 100)/_maxElo;
|
||||
public boolean isRankBanned(int accountId)
|
||||
{
|
||||
boolean banExpired = System.currentTimeMillis() >= getRankBanExpiry(accountId);
|
||||
|
||||
String color = C.cYellow;
|
||||
if (percentage <= 35)
|
||||
color = C.cRed;
|
||||
else if (percentage >= 65)
|
||||
color = C.cGreen;
|
||||
if (banExpired)
|
||||
{
|
||||
if (System.currentTimeMillis() >= _repository.getStrikeExpiry(accountId))
|
||||
{
|
||||
_repository.resetStrikes(accountId);
|
||||
}
|
||||
}
|
||||
return !banExpired;
|
||||
}
|
||||
|
||||
build.addLore(C.cGold + "Your Progress:", color + percentage + "% complete with this Division");
|
||||
return build.build();
|
||||
}
|
||||
public long getRankBanExpiry(int accountId)
|
||||
{
|
||||
return _repository.getBanExpiry(accountId);
|
||||
}
|
||||
|
||||
public static EloDivision getDivision(int elo)
|
||||
{
|
||||
for (EloDivision ed : EloDivision.values())
|
||||
{
|
||||
boolean applies = true;
|
||||
if (ed._maxElo != -1)
|
||||
{
|
||||
if (elo > ed._maxElo)
|
||||
{
|
||||
applies = false;
|
||||
}
|
||||
}
|
||||
if (ed._minElo != -1)
|
||||
{
|
||||
if (elo < ed._minElo)
|
||||
{
|
||||
applies = false;
|
||||
}
|
||||
}
|
||||
public void banFromRanked(int accountId)
|
||||
{
|
||||
_repository.addRankedBan(accountId);
|
||||
}
|
||||
|
||||
if (applies)
|
||||
{
|
||||
return ed;
|
||||
}
|
||||
}
|
||||
public void endMatch(int gameId)
|
||||
{
|
||||
EloTeam teamWinner = null;
|
||||
EloTeam teamLoser = null;
|
||||
|
||||
return EloDivision.COAL_2;
|
||||
}
|
||||
}
|
||||
for (EloTeam team : _eloTeams.values())
|
||||
{
|
||||
if (team.Winner)
|
||||
{
|
||||
teamWinner = team;
|
||||
} else
|
||||
{
|
||||
teamLoser = team;
|
||||
}
|
||||
}
|
||||
|
||||
EloTeam teamWinnerNew = getNewRatings(teamWinner, teamLoser, GameResult.Win);
|
||||
EloTeam teamLoserNew = getNewRatings(teamLoser, teamWinner, GameResult.Loss);
|
||||
|
||||
// Use teams to calculate Elo
|
||||
for (EloPlayer eloPlayer : teamWinnerNew.getPlayers())
|
||||
{
|
||||
int oldElo = teamWinner.getPlayer(eloPlayer.getPlayer().getUniqueId().toString()).getRating();
|
||||
|
||||
// If this is the first time.
|
||||
if (!Get(eloPlayer.getPlayer()).Elos.containsKey(gameId))
|
||||
{
|
||||
oldElo = eloPlayer.getRating();
|
||||
}
|
||||
|
||||
saveElo(eloPlayer.getPlayer(), eloPlayer.getAccountId(), gameId, oldElo, eloPlayer.getRating());
|
||||
}
|
||||
|
||||
for (EloPlayer eloPlayer : teamLoserNew.getPlayers())
|
||||
{
|
||||
int oldElo = teamLoser.getPlayer(eloPlayer.getPlayer().getUniqueId().toString()).getRating();
|
||||
|
||||
// If this is the first time.
|
||||
if (!Get(eloPlayer.getPlayer()).Elos.containsKey(gameId))
|
||||
{
|
||||
oldElo = eloPlayer.getRating();
|
||||
}
|
||||
|
||||
saveElo(eloPlayer.getPlayer(), eloPlayer.getAccountId(), gameId, oldElo, eloPlayer.getRating());
|
||||
}
|
||||
|
||||
_eloTeams.clear();
|
||||
}
|
||||
|
||||
public enum EloDivision
|
||||
{
|
||||
DIAMOND("Diamond", -1, 3700, Material.DIAMOND_BLOCK),
|
||||
EMERALD_3("Emerald 3", 3699, 3500, Material.EMERALD_BLOCK),
|
||||
EMERALD_2("Emerald 2", 3499, 3300, Material.EMERALD_BLOCK),
|
||||
EMERALD_1("Emerald 1", 3299, 3100, Material.EMERALD_BLOCK),
|
||||
LAPIS_3("Lapis 3", 3099, 2900, Material.LAPIS_BLOCK),
|
||||
LAPIS_2("Lapis 2", 2899, 2700, Material.LAPIS_BLOCK),
|
||||
LAPIS_1("Lapis 1", 2699, 2500, Material.LAPIS_BLOCK),
|
||||
GOLD_3("Gold 3", 2499, 2300, Material.GOLD_BLOCK),
|
||||
GOLD_2("Gold 2", 2299, 2100, Material.GOLD_BLOCK),
|
||||
GOLD_1("Gold 1", 2099, 1900, Material.GOLD_BLOCK),
|
||||
IRON_3("Iron 3", 1899, 1700, Material.IRON_BLOCK),
|
||||
IRON_2("Iron 2", 1699, 1500, Material.IRON_BLOCK),
|
||||
IRON_1("Iron 1", 1499, 1300, Material.IRON_BLOCK),
|
||||
COAL_3("Coal 3", 1299, 1100, Material.COAL_BLOCK),
|
||||
COAL_2("Coal 2", 1099, 900, Material.COAL_BLOCK),
|
||||
COAL_1("Coal 1", 899, -1, Material.COAL_BLOCK);
|
||||
|
||||
private String _disp;
|
||||
private int _maxElo, _minElo;
|
||||
private Material _visual;
|
||||
|
||||
EloDivision(String display, int maxElo, int minElo, Material visual)
|
||||
{
|
||||
_disp = display;
|
||||
_maxElo = maxElo;
|
||||
_minElo = minElo;
|
||||
_visual = visual;
|
||||
}
|
||||
|
||||
public static EloDivision getDivision(int elo)
|
||||
{
|
||||
for (EloDivision ed : EloDivision.values())
|
||||
{
|
||||
boolean applies = true;
|
||||
if (ed._maxElo != -1)
|
||||
{
|
||||
if (elo > ed._maxElo)
|
||||
{
|
||||
applies = false;
|
||||
}
|
||||
}
|
||||
if (ed._minElo != -1)
|
||||
{
|
||||
if (elo < ed._minElo)
|
||||
{
|
||||
applies = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (applies)
|
||||
{
|
||||
return ed;
|
||||
}
|
||||
}
|
||||
|
||||
return EloDivision.COAL_2;
|
||||
}
|
||||
|
||||
public String getDisplayName()
|
||||
{
|
||||
return _disp;
|
||||
}
|
||||
|
||||
public ItemStack getVisual(int elo)
|
||||
{
|
||||
ItemBuilder build = new ItemBuilder(_visual);
|
||||
build.setTitle(C.cGreen + _disp);
|
||||
int percentage = (elo * 100) / _maxElo;
|
||||
|
||||
String color = C.cYellow;
|
||||
if (percentage <= 35)
|
||||
{
|
||||
color = C.cRed;
|
||||
} else if (percentage >= 65)
|
||||
{
|
||||
color = C.cGreen;
|
||||
}
|
||||
|
||||
build.addLore(C.cGold + "Your Progress:", color + percentage + "% complete with this Division");
|
||||
return build.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ package mineplex.core.elo;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||
import mineplex.core.database.MinecraftRepository;
|
||||
import mineplex.serverdata.database.DBPool;
|
||||
import mineplex.serverdata.database.column.ColumnInt;
|
||||
import mineplex.serverdata.database.column.ColumnLong;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -16,9 +19,15 @@ import java.util.List;
|
||||
|
||||
public class EloRepository extends MinecraftRepository
|
||||
{
|
||||
|
||||
private static String INSERT_ELO = "INSERT INTO eloRating (accountId, gameType, elo) VALUES (?, ?, ?);";
|
||||
private static String UPDATE_ELO = "UPDATE eloRating SET elo = elo + ? WHERE accountId = ? AND gameType = ?;";
|
||||
private static String UPDATE_ELO_ONLY_IF_MATCH = "UPDATE eloRating SET elo = elo + ? WHERE accountId = ? AND gameType = ? AND elo = ?;";
|
||||
private static String GRAB_STRIKES = "SELECT strikes FROM rankedBans WHERE accountId = ?;";
|
||||
private static String GRAB_STRIKE_EXPIRY = "SELECT strikesExpire FROM rankedBans WHERE accountId = ?;";
|
||||
private static String GRAB_BAN_EXPIRY = "SELECT banEnd FROM rankedBans WHERE accountId = ?;";
|
||||
private static String UPDATE_BAN = "INSERT INTO rankedBans (accountId, strikes, strikesExpire, banEnd) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE strikes=VALUES(strikes), strikesExpire=VALUES(strikesExpire), banEnd=VALUES(banEnd);";
|
||||
private static String DELETE_STRIKES = "UPDATE rankedBans SET strikes = 1 WHERE accountId = ?;";
|
||||
private static String GET_ELO = "SELECT `elo, accountId` FROM eloRating WHERE gameType=? ORDER BY ASC LIMIT $limit;";
|
||||
private static String GET_NAME_FROM_ID = "SELECT `name` FROM `accounts` WHERE `id`=?;";
|
||||
|
||||
@ -53,7 +62,7 @@ public class EloRepository extends MinecraftRepository
|
||||
nameStatement = connection.prepareStatement(GET_NAME_FROM_ID);
|
||||
nameStatement.setInt(1, resultSet.getInt("accountId"));
|
||||
ResultSet nameSet = nameStatement.executeQuery();
|
||||
if(nameSet.next())
|
||||
if (nameSet.next())
|
||||
{
|
||||
data = new TopEloData(nameSet.getString("name"), elo);
|
||||
dataList.add(data);
|
||||
@ -67,7 +76,7 @@ public class EloRepository extends MinecraftRepository
|
||||
{
|
||||
try
|
||||
{
|
||||
if(nameStatement != null)
|
||||
if (nameStatement != null)
|
||||
{
|
||||
statement.close();
|
||||
}
|
||||
@ -127,6 +136,104 @@ public class EloRepository extends MinecraftRepository
|
||||
return clientData;
|
||||
}
|
||||
|
||||
public long getStrikeExpiry(int accountId)
|
||||
{
|
||||
final List<Long> expire = Lists.newArrayList();
|
||||
executeQuery(GRAB_STRIKE_EXPIRY, resultSet -> {
|
||||
while (resultSet.next())
|
||||
{
|
||||
expire.add(resultSet.getLong(1));
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
|
||||
if (expire.isEmpty())
|
||||
{
|
||||
expire.add(System.currentTimeMillis() - 5555);
|
||||
}
|
||||
|
||||
return expire.get(0);
|
||||
}
|
||||
|
||||
public long getBanExpiry(int accountId)
|
||||
{
|
||||
final List<Long> expire = Lists.newArrayList();
|
||||
executeQuery(GRAB_BAN_EXPIRY, resultSet -> {
|
||||
while (resultSet.next())
|
||||
{
|
||||
expire.add(resultSet.getLong(1));
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
|
||||
if (expire.isEmpty())
|
||||
{
|
||||
expire.add(System.currentTimeMillis() - 5555);
|
||||
}
|
||||
|
||||
return expire.get(0);
|
||||
}
|
||||
|
||||
public int getStrikes(int accountId)
|
||||
{
|
||||
final List<Integer> strike = Lists.newArrayList();
|
||||
executeQuery(GRAB_STRIKES, resultSet -> {
|
||||
while (resultSet.next())
|
||||
{
|
||||
strike.add(resultSet.getInt(1));
|
||||
}
|
||||
}, new ColumnInt("accountId", accountId));
|
||||
|
||||
if (strike.isEmpty())
|
||||
{
|
||||
strike.add(0);
|
||||
}
|
||||
|
||||
return strike.get(0);
|
||||
}
|
||||
|
||||
public void addRankedBan(int accountId)
|
||||
{
|
||||
int minutes = 1;
|
||||
switch (getStrikes(accountId))
|
||||
{
|
||||
case 0:
|
||||
minutes = 1;
|
||||
break;
|
||||
case 1:
|
||||
minutes = 5;
|
||||
break;
|
||||
case 2:
|
||||
minutes = 10;
|
||||
break;
|
||||
case 3:
|
||||
minutes = 20;
|
||||
break;
|
||||
case 4:
|
||||
minutes = 30;
|
||||
break;
|
||||
case 5:
|
||||
minutes = 60;
|
||||
break;
|
||||
case 6:
|
||||
minutes = 120;
|
||||
break;
|
||||
case 7:
|
||||
minutes = 180;
|
||||
break;
|
||||
case 8:
|
||||
minutes = 240;
|
||||
break;
|
||||
}
|
||||
long banEnd = System.currentTimeMillis() + UtilTime.convert(minutes, TimeUnit.MINUTES, TimeUnit.MILLISECONDS);
|
||||
long strikesExpire = System.currentTimeMillis() + UtilTime.convert(1, TimeUnit.DAYS, TimeUnit.MILLISECONDS);
|
||||
int newStrikes = Math.min(getStrikes(accountId) + 1, 8);
|
||||
executeUpdate(UPDATE_BAN, new ColumnInt("accountId", accountId), new ColumnInt("strikes", newStrikes), new ColumnLong("strikesExpire", strikesExpire), new ColumnLong("banEnd", banEnd));
|
||||
}
|
||||
|
||||
public void resetStrikes(int accountId)
|
||||
{
|
||||
executeUpdate(DELETE_STRIKES, new ColumnInt("accountId", accountId));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update()
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.elo.EloManager.EloDivision;
|
||||
import mineplex.core.slack.SlackAPI;
|
||||
import mineplex.core.slack.SlackMessage;
|
||||
import mineplex.core.slack.SlackTeam;
|
||||
@ -53,7 +54,8 @@ public class TopEloCommand extends CommandBase<EloManager>
|
||||
for(int i = 0; i < data.size(); i++){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
TopEloData topEloData = data.get(i);
|
||||
builder.append((i + 1)).append(": ").append(topEloData.getName()).append(" ").append("<division>").append("");
|
||||
builder.append((i + 1)).append(": ").append(topEloData.getName())
|
||||
.append(" ").append(EloDivision.getDivision(topEloData.getElo())).append("");
|
||||
SlackMessage slackMessage = new SlackMessage(builder.toString());
|
||||
SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, "#top-elo", slackMessage, false);
|
||||
caller.sendMessage(builder.toString());
|
||||
|
@ -1,7 +1,7 @@
|
||||
package mineplex.core.elo;
|
||||
|
||||
/**
|
||||
* @author Timothy Andis (TadahTech) on 4/28/2016.
|
||||
* Elo Wrapper for the TopEloCommand
|
||||
*/
|
||||
public class TopEloData
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user