Beginning changes for stats from PlayerName to PlayerUUID

This commit is contained in:
Peter Miller 2014-05-06 17:06:19 -04:00
parent a9d3d31339
commit e0dd0116a2
3 changed files with 54 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.stats.column.Column; import mineplex.core.stats.column.Column;
import mineplex.core.stats.column.ColumnInt; import mineplex.core.stats.column.ColumnInt;
import mineplex.core.stats.column.ColumnUuid;
import mineplex.core.stats.column.ColumnVarChar; import mineplex.core.stats.column.ColumnVarChar;
public class StatsManager extends MiniPlugin public class StatsManager extends MiniPlugin
@ -53,6 +54,7 @@ public class StatsManager extends MiniPlugin
{ {
if (!_tables.containsKey(tableName)) if (!_tables.containsKey(tableName))
{ {
// Change
ColumnVarChar playerColumn = new ColumnVarChar("playerName", 16); ColumnVarChar playerColumn = new ColumnVarChar("playerName", 16);
List<Column<?>> columnList = new ArrayList<Column<?>>(); List<Column<?>> columnList = new ArrayList<Column<?>>();
columnList.add(playerColumn); columnList.add(playerColumn);
@ -79,9 +81,11 @@ public class StatsManager extends MiniPlugin
public void addStat(Player player, String table, String statName, int value) public void addStat(Player player, String table, String statName, int value)
{ {
// getName -> getUniqueId
addStat(player.getName(), table, statName, value); addStat(player.getName(), table, statName, value);
} }
// playerName -> uuid
public void addStat(String playerName, String table, String statName, int value) public void addStat(String playerName, String table, String statName, int value)
{ {
if (!_playerStatList.containsKey(table)) if (!_playerStatList.containsKey(table))
@ -95,6 +99,7 @@ public class StatsManager extends MiniPlugin
Row row = _tables.get(table).createRow(); Row row = _tables.get(table).createRow();
// bad playername!
((ColumnVarChar)row.Columns.get("playerName")).Value = playerName; ((ColumnVarChar)row.Columns.get("playerName")).Value = playerName;
_playerStatList.get(table).put(playerName, row); _playerStatList.get(table).put(playerName, row);
@ -133,10 +138,13 @@ public class StatsManager extends MiniPlugin
try try
{ {
// playerName -> column name of UUID or uuid or UniqueID, whichever you choose
// and event.getPlayerName() is still in this event, but so is getUniqueId
List<Column<?>> columnList = new ArrayList<Column<?>>(); List<Column<?>> columnList = new ArrayList<Column<?>>();
columnList.add(new ColumnVarChar("playerName", 16, event.getPlayerName())); columnList.add(new ColumnUuid("playerUuid", 256, event.getUniqueId()));
List<Row> rows = table.retrieve(columnList); List<Row> rows = table.retrieve(columnList);
// Same here.
Row row = table.createRow(); Row row = table.createRow();
((ColumnVarChar)row.Columns.get("playerName")).Value = event.getPlayerName(); ((ColumnVarChar)row.Columns.get("playerName")).Value = event.getPlayerName();

View File

@ -0,0 +1,41 @@
package mineplex.core.stats.column;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
public class ColumnUuid extends Column<String>
{
public int Length = 256;
public UUID Value = UUID.fromString("");
public ColumnUuid(String name, int length)
{
this(name, length, UUID.fromString(""));
}
public ColumnUuid(String name, int length, UUID value)
{
super(name);
Length = length;
Value = value;
}
public String getCreateString()
{
return Name + " VARCHAR(" + Length + ")";
}
@Override
public String getValue(ResultSet resultSet) throws SQLException
{
return resultSet.getString(Name);
}
@Override
public ColumnUuid clone()
{
return new ColumnUuid(Name, Length, Value);
}
}

View File

@ -87,6 +87,10 @@ public class SuperSmash extends SoloGame
this.SpawnDistanceRequirement = 16; this.SpawnDistanceRequirement = 16;
this.InventoryOpen = false; this.InventoryOpen = false;
// Add stat table here
// Example
//Manager.GetStatsManager().addTable("SuperSmashMobStats", "Kills", "Deaths", "Wins", "Losses");
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)