Removed bad eventhandler line
Refactored StatsManager Removed Pvp Table add for StatsManager Added commented out hooks for HG stats
This commit is contained in:
parent
8e51e4061a
commit
177f4a878b
@ -245,7 +245,6 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void clearDisguises()
|
public void clearDisguises()
|
||||||
{
|
{
|
||||||
_spawnPacketMap.clear();
|
_spawnPacketMap.clear();
|
||||||
|
9
Plugins/Mineplex.Core/src/mineplex/core/stats/Row.java
Normal file
9
Plugins/Mineplex.Core/src/mineplex/core/stats/Row.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package mineplex.core.stats;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.stats.column.Column;
|
||||||
|
|
||||||
|
public class Row
|
||||||
|
{
|
||||||
|
public NautHashMap<String, Column<?>> Columns = new NautHashMap<String, Column<?>>();
|
||||||
|
}
|
@ -1,12 +1,11 @@
|
|||||||
package mineplex.core.stats;
|
package mineplex.core.stats;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -17,23 +16,20 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import mineplex.core.MiniPlugin;
|
import mineplex.core.MiniPlugin;
|
||||||
import mineplex.core.account.event.RetrieveClientInformationEvent;
|
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.ColumnInt;
|
||||||
|
import mineplex.core.stats.column.ColumnVarChar;
|
||||||
|
|
||||||
public class StatsManager extends MiniPlugin
|
public class StatsManager extends MiniPlugin
|
||||||
{
|
{
|
||||||
private static Object _statSync = new Object();
|
private static Object _statSync = new Object();
|
||||||
private static Connection _connection;
|
|
||||||
|
|
||||||
private NautHashMap<String, NautHashMap<String, PlayerStats>> _statUploadQueue = new NautHashMap<String, NautHashMap<String, PlayerStats>>();
|
private NautHashMap<String, NautHashMap<String, Row>> _statUploadQueue = new NautHashMap<String, NautHashMap<String, Row>>();
|
||||||
private Runnable _saveRunnable;
|
private Runnable _saveRunnable;
|
||||||
|
|
||||||
private String _connectionString = "jdbc:mysql://sql.mineplex.com:3306/Stats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
private NautHashMap<String, Table> _tables = new NautHashMap<String, Table>();
|
||||||
private String _userName = "root";
|
|
||||||
private String _password = "tAbechAk3wR7tuTh";
|
|
||||||
|
|
||||||
private NautHashMap<String, String> _retrieveStatements = new NautHashMap<String, String>();
|
private NautHashMap<String, NautHashMap<String, Row>> _playerStatList = new NautHashMap<String, NautHashMap<String, Row>>();
|
||||||
private NautHashMap<String, String> _updateStatements = new NautHashMap<String, String>();
|
|
||||||
|
|
||||||
private NautHashMap<String, NautHashMap<String, PlayerStats>> _playerStatList = new NautHashMap<String, NautHashMap<String, PlayerStats>>();
|
|
||||||
|
|
||||||
public StatsManager(JavaPlugin plugin)
|
public StatsManager(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
@ -53,57 +49,29 @@ public class StatsManager extends MiniPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public StatsManager addTable(String tableName)
|
public StatsManager addTable(String tableName, String...columns)
|
||||||
{
|
{
|
||||||
if (!_retrieveStatements.containsKey(tableName))
|
if (!_tables.containsKey(tableName))
|
||||||
{
|
{
|
||||||
_retrieveStatements.put(tableName, "Select statName, statValue FROM " + tableName + " WHERE playerName = ?");
|
ColumnVarChar playerColumn = new ColumnVarChar("playerName", 16);
|
||||||
|
List<Column<?>> columnList = new ArrayList<Column<?>>();
|
||||||
|
columnList.add(playerColumn);
|
||||||
|
|
||||||
|
for (String column : columns)
|
||||||
|
{
|
||||||
|
columnList.add(new ColumnInt(column));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_updateStatements.containsKey(tableName))
|
Table statTable = new Table(tableName, columnList, columnList, playerColumn);
|
||||||
{
|
statTable.initialize();
|
||||||
_updateStatements.put(tableName, "INSERT INTO " + tableName + " (playerName, statName, statValue) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE statName = VALUES(statName), statValue = VALUES(statValue);");
|
|
||||||
|
// Can't Arrays.asList here because of weird java generics
|
||||||
|
_tables.put(tableName, statTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_playerStatList.containsKey(tableName))
|
if (!_playerStatList.containsKey(tableName))
|
||||||
{
|
{
|
||||||
_playerStatList.put(tableName, new NautHashMap<String, PlayerStats>());
|
_playerStatList.put(tableName, new NautHashMap<String, Row>());
|
||||||
}
|
|
||||||
|
|
||||||
if (!_playerStatList.containsKey(tableName))
|
|
||||||
{
|
|
||||||
_playerStatList.put(tableName, new NautHashMap<String, PlayerStats>());
|
|
||||||
}
|
|
||||||
|
|
||||||
PreparedStatement createStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
createStatement = _connection.prepareStatement("CREATE TABLE IF NOT EXISTS " + tableName + " (playerName VARCHAR(25), statName VARCHAR(256), statValue INT, PRIMARY KEY (playerName, statName), INDEX (playerName));");
|
|
||||||
|
|
||||||
createStatement.execute();
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
System.out.println("Error creating table " + tableName + ".");
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (createStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
createStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -124,16 +92,21 @@ public class StatsManager extends MiniPlugin
|
|||||||
|
|
||||||
if (!_playerStatList.get(table).containsKey(playerName))
|
if (!_playerStatList.get(table).containsKey(playerName))
|
||||||
{
|
{
|
||||||
_playerStatList.get(table).put(playerName, new PlayerStats());
|
|
||||||
|
Row row = _tables.get(table).createRow();
|
||||||
|
|
||||||
|
((ColumnVarChar)row.Columns.get("playerName")).Value = playerName;
|
||||||
|
|
||||||
|
_playerStatList.get(table).put(playerName, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
_playerStatList.get(table).get(playerName).addStat(statName, value);
|
_playerStatList.get(table).get(playerName).Columns.put(statName, new ColumnInt(statName, value));
|
||||||
|
|
||||||
synchronized (_statSync)
|
synchronized (_statSync)
|
||||||
{
|
{
|
||||||
if (!_statUploadQueue.containsKey(table))
|
if (!_statUploadQueue.containsKey(table))
|
||||||
{
|
{
|
||||||
_statUploadQueue.put(table, new NautHashMap<String, PlayerStats>());
|
_statUploadQueue.put(table, new NautHashMap<String, Row>());
|
||||||
}
|
}
|
||||||
|
|
||||||
_statUploadQueue.get(table).put(playerName, _playerStatList.get(table).get(playerName));
|
_statUploadQueue.get(table).put(playerName, _playerStatList.get(table).get(playerName));
|
||||||
@ -153,22 +126,29 @@ public class StatsManager extends MiniPlugin
|
|||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
for (String tableName : _retrieveStatements.keySet())
|
for (Entry<String, Table> tableEntry : _tables.entrySet())
|
||||||
{
|
{
|
||||||
|
Table table = tableEntry.getValue();
|
||||||
|
String tableName = tableEntry.getKey();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = event.getConnection().prepareStatement(_retrieveStatements.get(tableName));
|
List<Column<?>> columnList = new ArrayList<Column<?>>();
|
||||||
preparedStatement.setString(1, event.getClientName());
|
columnList.add(new ColumnVarChar("playerName", 16, event.getClientName()));
|
||||||
|
List<Row> rows = table.retrieve(columnList);
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
Row row = table.createRow();
|
||||||
PlayerStats playerStats = new PlayerStats();
|
((ColumnVarChar)row.Columns.get("playerName")).Value = event.getClientName();
|
||||||
|
|
||||||
while (resultSet.next())
|
if (rows.size() > 0)
|
||||||
{
|
{
|
||||||
playerStats.addStat(resultSet.getString(1), resultSet.getInt(2));
|
for (Column<?> column : rows.get(0).Columns.values())
|
||||||
|
{
|
||||||
|
row.Columns.put(column.Name, column);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_playerStatList.get(tableName).put(event.getClientName(), playerStats);
|
_playerStatList.get(tableName).put(event.getClientName(), row);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -209,13 +189,13 @@ public class StatsManager extends MiniPlugin
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NautHashMap<String, NautHashMap<String, PlayerStats>> uploadQueue = new NautHashMap<String, NautHashMap<String, PlayerStats>>();
|
NautHashMap<String, NautHashMap<String, Row>> uploadQueue = new NautHashMap<String, NautHashMap<String, Row>>();
|
||||||
|
|
||||||
synchronized (_statSync)
|
synchronized (_statSync)
|
||||||
{
|
{
|
||||||
for (String key : _statUploadQueue.keySet())
|
for (String key : _statUploadQueue.keySet())
|
||||||
{
|
{
|
||||||
uploadQueue.put(key, new NautHashMap<String, PlayerStats>());
|
uploadQueue.put(key, new NautHashMap<String, Row>());
|
||||||
|
|
||||||
for (String stat : _statUploadQueue.get(key).keySet())
|
for (String stat : _statUploadQueue.get(key).keySet())
|
||||||
{
|
{
|
||||||
@ -228,23 +208,12 @@ public class StatsManager extends MiniPlugin
|
|||||||
|
|
||||||
for (String tableName : uploadQueue.keySet())
|
for (String tableName : uploadQueue.keySet())
|
||||||
{
|
{
|
||||||
for (Iterator<Entry<String, PlayerStats>> iterator = uploadQueue.get(tableName).entrySet().iterator(); iterator.hasNext();)
|
for (Iterator<Entry<String, Row>> iterator = uploadQueue.get(tableName).entrySet().iterator(); iterator.hasNext();)
|
||||||
{
|
{
|
||||||
Entry<String, PlayerStats> entry = iterator.next();
|
Entry<String, Row> entry = iterator.next();
|
||||||
|
|
||||||
for (String statName : entry.getValue().getStatsNames())
|
if (!_tables.get(tableName).update(new ArrayList<Column<?>>(entry.getValue().Columns.values()), new ColumnVarChar("playerName", 16, entry.getKey())))
|
||||||
{
|
_tables.get(tableName).insert(new ArrayList<Column<?>>(entry.getValue().Columns.values()));
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(_updateStatements.get(tableName), Statement.RETURN_GENERATED_KEYS);
|
|
||||||
|
|
||||||
preparedStatement.setString(1, entry.getKey());
|
|
||||||
preparedStatement.setString(2, statName);
|
|
||||||
preparedStatement.setInt(3, entry.getValue().getStat(statName));
|
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
@ -289,8 +258,6 @@ public class StatsManager extends MiniPlugin
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerStats stats = _playerStatList.get(table).get(player);
|
return ((ColumnInt)_playerStatList.get(table).get(player).Columns.get(stat)).Value;
|
||||||
|
|
||||||
return stats.getStat(stat);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
417
Plugins/Mineplex.Core/src/mineplex/core/stats/Table.java
Normal file
417
Plugins/Mineplex.Core/src/mineplex/core/stats/Table.java
Normal file
@ -0,0 +1,417 @@
|
|||||||
|
package mineplex.core.stats;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.stats.column.Column;
|
||||||
|
|
||||||
|
public class Table
|
||||||
|
{
|
||||||
|
private static Connection _connection;
|
||||||
|
|
||||||
|
private String _connectionString = "jdbc:mysql://sql.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
||||||
|
private String _userName = "root";
|
||||||
|
private String _password = "tAbechAk3wR7tuTh";
|
||||||
|
|
||||||
|
private String _name;
|
||||||
|
private List<Column<?>> _primaryKeys;
|
||||||
|
private NautHashMap<String, Column<?>> _columns = new NautHashMap<String, Column<?>>();
|
||||||
|
private Column<?> _index;
|
||||||
|
|
||||||
|
public Table(String name, List<Column<?>> primaryKeys, List<Column<?>> columns, Column<?> index)
|
||||||
|
{
|
||||||
|
_name = name;
|
||||||
|
_primaryKeys = primaryKeys;
|
||||||
|
|
||||||
|
for (Column<?> column : columns)
|
||||||
|
{
|
||||||
|
_columns.put(column.Name, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
_index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize()
|
||||||
|
{
|
||||||
|
if (!doesTableExist())
|
||||||
|
{
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
private void updateSchema()
|
||||||
|
{
|
||||||
|
PreparedStatement getTableColumns = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
getTableColumns = _connection.prepareStatement("SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '`" + _name + "`' AND table_schema = 'Mineplex';");
|
||||||
|
|
||||||
|
resultSet = getTableColumns.executeQuery();
|
||||||
|
|
||||||
|
HashSet<String> columnExists = new HashSet<String>();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
columnExists.add(resultSet.getString("COLUMN_NAME"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.out.println("Error updating table `" + _name + "`.");
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (getTableColumns != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
getTableColumns.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultSet != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
resultSet.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
private void create()
|
||||||
|
{
|
||||||
|
PreparedStatement createStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringBuilder columnBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
for (Iterator<Column<?>> columnIterator = _columns.values().iterator(); columnIterator.hasNext();)
|
||||||
|
{
|
||||||
|
Column<?> column = columnIterator.next();
|
||||||
|
|
||||||
|
columnBuilder.append(column.getCreateString());
|
||||||
|
|
||||||
|
if (columnIterator.hasNext())
|
||||||
|
{
|
||||||
|
columnBuilder.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder primaryKey = new StringBuilder();
|
||||||
|
|
||||||
|
for (Column<?> column : _primaryKeys)
|
||||||
|
{
|
||||||
|
primaryKey.append(column.Name);
|
||||||
|
|
||||||
|
if (!column.equals(_primaryKeys.get(_primaryKeys.size() - 1)))
|
||||||
|
{
|
||||||
|
primaryKey.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
createStatement = _connection.prepareStatement("CREATE TABLE IF NOT EXISTS `" + _name + "` (" + columnBuilder.toString() + ", PRIMARY KEY (" + primaryKey.toString() + "), INDEX (" + _index.Name + "));");
|
||||||
|
|
||||||
|
createStatement.execute();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.out.println("Error creating table `" + _name + "`.");
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (createStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
createStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean doesTableExist()
|
||||||
|
{
|
||||||
|
PreparedStatement checkIfTableExistsStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
checkIfTableExistsStatement = _connection.prepareStatement("SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'Mineplex' AND table_name LIKE '`" + _name + "`'");
|
||||||
|
|
||||||
|
if (checkIfTableExistsStatement.executeQuery().next())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.out.println("Error updating table `" + _name + "`.");
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (checkIfTableExistsStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
checkIfTableExistsStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insert(List<Column<?>> columns)
|
||||||
|
{
|
||||||
|
StringBuilder temporaryBuilder = new StringBuilder();
|
||||||
|
StringBuilder questionBuilder = new StringBuilder();
|
||||||
|
StringBuilder updateBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
for (Column<?> column : columns)
|
||||||
|
{
|
||||||
|
temporaryBuilder.append(column.Name);
|
||||||
|
questionBuilder.append("'" + column.Value + "'");
|
||||||
|
updateBuilder.append(column.Name + " = VALUES(" + column.Name + ")");
|
||||||
|
|
||||||
|
if (!column.equals(columns.get(columns.size() - 1)))
|
||||||
|
{
|
||||||
|
temporaryBuilder.append(", ");
|
||||||
|
questionBuilder.append(", ");
|
||||||
|
updateBuilder.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement("INSERT INTO `" + _name + "` (" + temporaryBuilder.toString() + ") VALUES (" + questionBuilder.toString() + ") ON DUPLICATE KEY UPDATE " + updateBuilder.toString() + ";", Statement.RETURN_GENERATED_KEYS);
|
||||||
|
|
||||||
|
preparedStatement.execute();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.out.println("Error updating table `" + _name + "`.");
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean update(List<Column<?>> columns, Column<?> whereColumn)
|
||||||
|
{
|
||||||
|
List<Column<?>> whereColumnList = new ArrayList<Column<?>>();
|
||||||
|
whereColumnList.add(whereColumn);
|
||||||
|
|
||||||
|
return update(columns, whereColumnList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean update(List<Column<?>> columns, List<Column<?>> whereColumns)
|
||||||
|
{
|
||||||
|
String updateStatement = buildUpdateStatement(columns, whereColumns);
|
||||||
|
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(updateStatement);
|
||||||
|
|
||||||
|
if (preparedStatement.executeUpdate() != 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.out.println("Error updating table `" + _name + "`.");
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Row> retrieve(List<Column<?>> columns)
|
||||||
|
{
|
||||||
|
StringBuilder temporaryBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
for (Iterator<Column<?>> columnIterator = _columns.values().iterator(); columnIterator.hasNext();)
|
||||||
|
{
|
||||||
|
Column<?> column = columnIterator.next();
|
||||||
|
temporaryBuilder.append(column.Name);
|
||||||
|
|
||||||
|
if (columnIterator.hasNext())
|
||||||
|
temporaryBuilder.append(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
List<Row> rows = new ArrayList<Row>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement("Select " + temporaryBuilder.toString() + " FROM `" + _name + "` " + buildWhereString(columns) + ";");
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
Row row = new Row();
|
||||||
|
|
||||||
|
for (Column<?> column : columns)
|
||||||
|
{
|
||||||
|
column.getValue(resultSet);
|
||||||
|
row.Columns.put(column.Name, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
rows.add(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.out.println("Error updating table `" + _name + "`.");
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildUpdateStatement(List<Column<?>> columns, List<Column<?>> whereColumns)
|
||||||
|
{
|
||||||
|
StringBuilder setBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
if (columns.size() > 0)
|
||||||
|
setBuilder.append("SET ");
|
||||||
|
|
||||||
|
for (Column<?> column : columns)
|
||||||
|
{
|
||||||
|
setBuilder.append(column.Name + " = '" + column.Value + "'");
|
||||||
|
|
||||||
|
if (!column.equals(columns.get(columns.size() - 1)))
|
||||||
|
setBuilder.append(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
return "UPDATE `" + _name + "` " + setBuilder.toString() + " " + buildWhereString(whereColumns) + ";";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildWhereString(List<Column<?>> columns)
|
||||||
|
{
|
||||||
|
StringBuilder whereBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
if (columns.size() > 0)
|
||||||
|
{
|
||||||
|
whereBuilder.append("WHERE ");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Column<?> column : columns)
|
||||||
|
{
|
||||||
|
whereBuilder.append(column.Name + " = '" + column.Value + "'");
|
||||||
|
|
||||||
|
if (!column.equals(columns.get(columns.size() - 1)))
|
||||||
|
whereBuilder.append(" AND ");
|
||||||
|
}
|
||||||
|
|
||||||
|
return whereBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Column<?> getColumn(String columnName)
|
||||||
|
{
|
||||||
|
return _columns.get(columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Row createRow()
|
||||||
|
{
|
||||||
|
Row row = new Row();
|
||||||
|
|
||||||
|
for (Column<?> column : _columns.values())
|
||||||
|
{
|
||||||
|
row.Columns.put(column.Name, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package mineplex.core.stats.column;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public abstract class Column<Type>
|
||||||
|
{
|
||||||
|
public String Name;
|
||||||
|
public Type Value;
|
||||||
|
|
||||||
|
public Column(String name)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Column(String name, Type value)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getCreateString();
|
||||||
|
|
||||||
|
public abstract Type getValue(ResultSet resultSet) throws SQLException;
|
||||||
|
|
||||||
|
public abstract Column<Type> clone();
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package mineplex.core.stats.column;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class ColumnInt extends Column<Integer>
|
||||||
|
{
|
||||||
|
public ColumnInt(String name)
|
||||||
|
{
|
||||||
|
super(name);
|
||||||
|
Value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColumnInt(String name, int value)
|
||||||
|
{
|
||||||
|
super(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCreateString()
|
||||||
|
{
|
||||||
|
return Name + " INT";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getValue(ResultSet resultSet) throws SQLException
|
||||||
|
{
|
||||||
|
return resultSet.getInt(Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ColumnInt clone()
|
||||||
|
{
|
||||||
|
return new ColumnInt(Name, Value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package mineplex.core.stats.column;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class ColumnLong extends Column<Long>
|
||||||
|
{
|
||||||
|
public ColumnLong(String name)
|
||||||
|
{
|
||||||
|
super(name);
|
||||||
|
Value = 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColumnLong(String name, Long value)
|
||||||
|
{
|
||||||
|
super(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCreateString()
|
||||||
|
{
|
||||||
|
return Name + " LONG";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getValue(ResultSet resultSet) throws SQLException
|
||||||
|
{
|
||||||
|
return resultSet.getLong(Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ColumnLong clone()
|
||||||
|
{
|
||||||
|
return new ColumnLong(Name, Value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package mineplex.core.stats.column;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class ColumnVarChar extends Column<String>
|
||||||
|
{
|
||||||
|
public int Length = 25;
|
||||||
|
|
||||||
|
public ColumnVarChar(String name, int length)
|
||||||
|
{
|
||||||
|
this(name, length, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColumnVarChar(String name, int length, String 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 ColumnVarChar clone()
|
||||||
|
{
|
||||||
|
return new ColumnVarChar(Name, Length, Value);
|
||||||
|
}
|
||||||
|
}
|
@ -130,7 +130,6 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
|||||||
_visibilityManager = new VisibilityManager(this);
|
_visibilityManager = new VisibilityManager(this);
|
||||||
|
|
||||||
_statsManager = new StatsManager(plugin);
|
_statsManager = new StatsManager(plugin);
|
||||||
_statsManager.addTable("Pvp");
|
|
||||||
|
|
||||||
((CraftWorld)Bukkit.getWorlds().get(0)).getHandle().pvpMode = true;
|
((CraftWorld)Bukkit.getWorlds().get(0)).getHandle().pvpMode = true;
|
||||||
}
|
}
|
||||||
|
@ -220,6 +220,7 @@ public class HungerGames extends SoloGame
|
|||||||
System.out.println("===================");
|
System.out.println("===================");
|
||||||
System.out.println("CREEP TYPE: " + _spreadName);
|
System.out.println("CREEP TYPE: " + _spreadName);
|
||||||
System.out.println("===================");
|
System.out.println("===================");
|
||||||
|
//Manager.GetStatsManager().addTable(GetName(), "kills", "deaths", "chestsOpened");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -372,6 +373,8 @@ public class HungerGames extends SoloGame
|
|||||||
chest.getBlockInventory().setItem(UtilMath.r(27), GetChestItem(_supplyChests.contains(event.getClickedBlock())));
|
chest.getBlockInventory().setItem(UtilMath.r(27), GetChestItem(_supplyChests.contains(event.getClickedBlock())));
|
||||||
|
|
||||||
_supplyChests.remove(event.getClickedBlock());
|
_supplyChests.remove(event.getClickedBlock());
|
||||||
|
|
||||||
|
//Manager.GetStatsManager().addStat(event.getPlayer(), GetName(), "chestsOpened", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack GetChestItem(boolean superChest)
|
private ItemStack GetChestItem(boolean superChest)
|
||||||
@ -1517,7 +1520,15 @@ public class HungerGames extends SoloGame
|
|||||||
|
|
||||||
if (killer != null && !killer.equals(killed))
|
if (killer != null && !killer.equals(killed))
|
||||||
{
|
{
|
||||||
Manager.GetStatsManager().addStat(killer, "Pvp", "Kills", 1);
|
//Manager.GetStatsManager().addStat(killer, GetName(), "kills", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.GetLog().GetPlayer() != null)
|
||||||
|
{
|
||||||
|
if (killed != null)
|
||||||
|
{
|
||||||
|
//Manager.GetStatsManager().addStat(killed, GetName(), "deaths", 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,6 @@ public class GamePlayerManager implements Listener
|
|||||||
Manager = manager;
|
Manager = manager;
|
||||||
|
|
||||||
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
|
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
|
||||||
Manager.GetStatsManager().addTable("Pvp");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
Loading…
Reference in New Issue
Block a user