Added getRepoElo to EloRepository

Added Bukkit.broadcastMessage() calls to test code

Methods that needed to throw SQLExceptions now throw SQLExceptions
This commit is contained in:
Joseph Prezioso Jr. 2016-04-14 15:21:28 -04:00
parent 9e8a7b582b
commit eb67c12108
6 changed files with 113 additions and 10 deletions

View File

@ -1,5 +1,6 @@
package mineplex.core.account;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@ -378,7 +379,12 @@ public class CoreClientManager extends MiniPlugin
@Override
public void run()
{
client.setAccountId(_repository.login(_loginProcessors, uuid, client.GetPlayerName()));
try {
client.setAccountId(_repository.login(_loginProcessors, uuid, client.GetPlayerName()));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
_clientLoginLock.remove(client.GetPlayerName());
}
});

View File

@ -57,7 +57,7 @@ public class AccountRepository extends MinecraftRepository
//executeUpdate(CREATE_ACCOUNT_TABLE);
}
public int login(final List<ILoginProcessor> loginProcessors, final UUID uuid, final String name)
public int login(final List<ILoginProcessor> loginProcessors, final UUID uuid, final String name) throws SQLException
{
// First we try to grab the account id from cache - this saves an extra trip to database
int accountId = PlayerCache.getInstance().getAccountId(uuid);
@ -117,10 +117,7 @@ public class AccountRepository extends MinecraftRepository
statement.getMoreResults();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
return accountId;
}

View File

@ -46,7 +46,17 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
{
if (_playerElos.get(uuid.toString()).containsKey(gameType))
{
elo = _playerElos.get(uuid.toString()).get(gameType);
//let's try getting Elo directly from the repository
try
{
elo = _repository.getRepoElo(uuid.toString(), gameType);
Bukkit.broadcastMessage("Fetching Elo...");
}
catch (SQLException e)
{
e.printStackTrace();
}
//elo = _playerElos.get(uuid.toString()).get(gameType);
}
}
}
@ -97,6 +107,7 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
{
try {
_repository.saveElo(uuid, gameType, elo);
Bukkit.broadcastMessage("Attempting to saveElo...");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -143,7 +154,14 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
public String getPlayerDivision(UUID uuid, String gameType)
{
//get playerElo for gameType (need to store this to check it against other Elo's)
int playerElo = getElo(uuid, gameType);
int playerElo = 1000;
try {
playerElo = _repository.getRepoElo(uuid.toString(), gameType);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//this list will be filled with ELO's from other players (but only for the same game type
ArrayList<Integer> allElos = new ArrayList<Integer>();
@ -153,6 +171,7 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
if(_playerElos.containsKey(gameType))
{
//add elo's to the list
allElos.add(_playerElos.get(uuid.toString()).get(gameType));
}
}

View File

@ -9,4 +9,7 @@ public class EloPlayer
{
System.out.println(UniqueId + "'s elo is " + Rating);
}
}

View File

@ -5,6 +5,8 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import com.mysql.jdbc.Statement;
@ -31,7 +33,34 @@ 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
{
Connection con = getConnection();
java.sql.Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
String selectQuery = "SELECT elo FROM eloRating WHERE uuid = '" + uuid + "' AND gameType = '" + gameType + "';";
ResultSet rs = stmt.executeQuery(selectQuery);
//elo set to 1000 by default
int elo = 1000;
//if something was found, return the elo
if(rs.next())
{
elo = rs.getInt(1);
Bukkit.broadcastMessage("getRepoElo pulled " + elo + "from database for " + uuid);
return elo;
}
//make a new entry into eloRatings, if there is no elo for the player for this gameType
saveElo(uuid, gameType, elo);
//then return the elo (should be 1000)
return elo;
}
public void saveElo(String uuid, String gameType, int elo) throws SQLException
{
Connection con = getConnection();
@ -45,13 +74,15 @@ public class EloRepository extends MinecraftRepository
{
contains = true;
//update elo
String updateQuery = "UPDATE eloRating SET elo='" + elo + "';";
String updateQuery = "UPDATE eloRating SET elo='" + elo + "' WHERE uuid = '" + uuid + "' AND gametype = '" + gameType + "';";
executeQuery(updateQuery, null, new ColumnVarChar("elo", 100, uuid));
Bukkit.broadcastMessage("Updating existing 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...");
}

View File

@ -0,0 +1,47 @@
package mineplex.core.incognito.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Called when an Incognito player is getting hidden from all other players.
*/
public class IncognitoHidePlayerEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Player _player;
private boolean _cancelled;
public IncognitoHidePlayerEvent(Player player)
{
_player = player;
}
public Player getPlayer()
{
return _player;
}
public void setCancelled(boolean cancelled)
{
_cancelled = cancelled;
}
public boolean isCancelled()
{
return _cancelled;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}