mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 11:37:41 +01:00
Merge branch '3.7.0' into master
This commit is contained in:
commit
4f2a946203
@ -0,0 +1,39 @@
|
||||
package main.java.com.djrapitops.plan.database.sql;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
|
||||
public class Select extends SqlParser {
|
||||
|
||||
private int conditions = 0;
|
||||
|
||||
public Select(String start) {
|
||||
super(start);
|
||||
}
|
||||
|
||||
public static Select from(String table, String... columns) {
|
||||
Select parser = new Select("SELECT ");
|
||||
int size = columns.length;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (size > 1 && i > 0) {
|
||||
parser.append(", ");
|
||||
}
|
||||
parser.append(columns[i]);
|
||||
}
|
||||
|
||||
parser.append(" FROM ").append(table);
|
||||
Log.debug(parser.toString());
|
||||
return parser;
|
||||
}
|
||||
|
||||
public Select where(String... conditions) {
|
||||
append(" WHERE ");
|
||||
for (int i = 0; i < conditions.length; i++) {
|
||||
if (this.conditions > 0) {
|
||||
append(" AND ");
|
||||
}
|
||||
append("(").append(conditions[i]).append(")");
|
||||
this.conditions++;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
@ -6,7 +6,11 @@ public class Sql {
|
||||
public static final String LONG = "bigint";
|
||||
public static final String BOOL = "boolean";
|
||||
|
||||
public static String VARCHAR(int length) {
|
||||
return "varchar(" + length + ")";
|
||||
private Sql() {
|
||||
throw new IllegalStateException("Variable Class");
|
||||
}
|
||||
|
||||
public static String varchar(int length) {
|
||||
return "varchar("+length+")";
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +93,16 @@ public class TableSqlParser extends SqlParser {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for ALTER TABLE sql statements.
|
||||
*
|
||||
* @param column column to modify
|
||||
* @return TableSqlParser object
|
||||
*/
|
||||
public static TableSqlParser newColumn(String column, String type) {
|
||||
return new TableSqlParser("").column(column, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
append(")");
|
||||
|
@ -38,7 +38,7 @@ public class CommandUseTable extends Table {
|
||||
public boolean createTable() {
|
||||
try {
|
||||
execute(TableSqlParser.createTable(tableName)
|
||||
.column(columnCommand, Sql.VARCHAR(20)).notNull()
|
||||
.column(columnCommand, Sql.varchar(20)).notNull()
|
||||
.column(columnTimesUsed, Sql.INT).notNull()
|
||||
.toString()
|
||||
);
|
||||
|
@ -40,7 +40,7 @@ public class IPsTable extends UserIDTable {
|
||||
try {
|
||||
execute(TableSqlParser.createTable(tableName)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnIP, Sql.VARCHAR(20)).notNull()
|
||||
.column(columnIP, Sql.varchar(20)).notNull()
|
||||
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||
.toString()
|
||||
);
|
||||
|
@ -45,7 +45,7 @@ public class KillsTable extends Table {
|
||||
execute(TableSqlParser.createTable(tableName)
|
||||
.column(columnKillerUserID, Sql.INT).notNull()
|
||||
.column(columnVictimUserID, Sql.INT).notNull()
|
||||
.column(columnWeapon, Sql.VARCHAR(30)).notNull()
|
||||
.column(columnWeapon, Sql.varchar(30)).notNull()
|
||||
.column(columnDate, Sql.LONG).notNull()
|
||||
.foreignKey(columnKillerUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||
.foreignKey(columnVictimUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||
@ -200,7 +200,7 @@ public class KillsTable extends Table {
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void savePlayerKills(Map<Integer, List<KillData>> kills, Map<Integer, UUID> uuids) throws SQLException {
|
||||
if (kills == null || kills.isEmpty()) {
|
||||
if (Verify.isEmpty(kills)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -219,27 +219,17 @@ public class KillsTable extends Table {
|
||||
for (Map.Entry<Integer, List<KillData>> entrySet : kills.entrySet()) {
|
||||
Integer id = entrySet.getKey();
|
||||
List<KillData> playerKills = entrySet.getValue();
|
||||
|
||||
playerKills.removeIf(Objects::isNull);
|
||||
List<KillData> s = saved.get(id);
|
||||
|
||||
if (s != null) {
|
||||
playerKills.removeAll(s);
|
||||
}
|
||||
|
||||
playerKills.stream().filter(Objects::nonNull).forEach(killData -> {
|
||||
int victimUserID = killData.getVictimUserID();
|
||||
if (victimUserID == -1) {
|
||||
try {
|
||||
int newVictimID = db.getUsersTable().getUserId(killData.getVictim());
|
||||
killData.setVictimUserID(newVictimID);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
findMissingIDs(playerKills);
|
||||
|
||||
for (KillData kill : playerKills) {
|
||||
if (kill == null || kill.getVictimUserID() == -1) {
|
||||
if (kill.getVictimUserID() == -1) {
|
||||
continue;
|
||||
}
|
||||
statement.setInt(1, id);
|
||||
@ -259,4 +249,14 @@ public class KillsTable extends Table {
|
||||
Benchmark.stop("Database", "Save Kills multiple");
|
||||
}
|
||||
}
|
||||
|
||||
private void findMissingIDs(List<KillData> playerKills) throws SQLException {
|
||||
for (KillData killData : playerKills) {
|
||||
int victimUserID = killData.getVictimUserID();
|
||||
if (victimUserID == -1) {
|
||||
int newVictimID = db.getUsersTable().getUserId(killData.getVictim());
|
||||
killData.setVictimUserID(newVictimID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class NicknamesTable extends UserIDTable {
|
||||
try {
|
||||
execute(TableSqlParser.createTable(tableName)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnNick, Sql.VARCHAR(75)).notNull()
|
||||
.column(columnNick, Sql.varchar(75)).notNull()
|
||||
.column(columnCurrent, Sql.BOOL).notNull().defaultValue(false)
|
||||
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||
.toString()
|
||||
|
@ -37,8 +37,8 @@ public class SecurityTable extends Table {
|
||||
public boolean createTable() {
|
||||
try {
|
||||
execute(TableSqlParser.createTable(tableName)
|
||||
.column(columnUser, Sql.VARCHAR(100)).notNull().unique()
|
||||
.column(columnSaltedHash, Sql.VARCHAR(100)).notNull().unique()
|
||||
.column(columnUser, Sql.varchar(100)).notNull().unique()
|
||||
.column(columnSaltedHash, Sql.varchar(100)).notNull().unique()
|
||||
.column(columnPermLevel, Sql.INT).notNull()
|
||||
.toString()
|
||||
);
|
||||
|
@ -99,9 +99,9 @@ public class UsersTable extends Table {
|
||||
try {
|
||||
execute(TableSqlParser.createTable(tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnID, Sql.INT)
|
||||
.column(columnUUID, Sql.VARCHAR(36)).notNull().unique()
|
||||
.column(columnGeolocation, Sql.VARCHAR(50)).notNull()
|
||||
.column(columnLastGM, Sql.VARCHAR(15)).notNull()
|
||||
.column(columnUUID, Sql.varchar(36)).notNull().unique()
|
||||
.column(columnGeolocation, Sql.varchar(50)).notNull()
|
||||
.column(columnLastGM, Sql.varchar(15)).notNull()
|
||||
.column(columnLastGMSwapTime, Sql.LONG).notNull()
|
||||
.column(columnPlayTime, Sql.LONG).notNull()
|
||||
.column(columnLoginTimes, Sql.INT).notNull()
|
||||
@ -110,10 +110,10 @@ public class UsersTable extends Table {
|
||||
.column(columnMobKills, Sql.INT).notNull()
|
||||
.column(columnRegistered, Sql.LONG).notNull()
|
||||
.column(columnOP, Sql.BOOL).notNull().defaultValue(false)
|
||||
.column(columnName, Sql.VARCHAR(16)).notNull()
|
||||
.column(columnName, Sql.varchar(16)).notNull()
|
||||
.column(columnBanned, Sql.BOOL).notNull().defaultValue(false)
|
||||
.column(columnContainsBukkitData, Sql.BOOL).notNull().defaultValue(false)
|
||||
.column(columnLastWorld, Sql.VARCHAR(255)).notNull()
|
||||
.column(columnLastWorld, Sql.varchar(255)).notNull()
|
||||
.column(columnLastWorldSwapTime, Sql.LONG).notNull()
|
||||
.primaryKey(usingMySQL, columnID)
|
||||
.toString()
|
||||
|
@ -43,7 +43,7 @@ public class WorldTable extends Table {
|
||||
try {
|
||||
execute(TableSqlParser.createTable(tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnWorldId, Sql.INT)
|
||||
.column(columnWorldName, Sql.VARCHAR(100)).notNull()
|
||||
.column(columnWorldName, Sql.varchar(100)).notNull()
|
||||
.primaryKey(usingMySQL, columnWorldId)
|
||||
.toString()
|
||||
);
|
||||
|
@ -43,9 +43,7 @@ public class PlayersTableCreator {
|
||||
boolean isUnknown = uData.getLoginTimes() == 1;
|
||||
boolean isActive = AnalysisUtils.isActive(now, uData.getLastPlayed(), uData.getPlayTime(), uData.getLoginTimes());
|
||||
|
||||
String activityString = isActive ? "Active" : "Inactive";
|
||||
String unknownString = isUnknown ? "Unknown" : activityString;
|
||||
String combinedString = isBanned ? "Banned" : unknownString;
|
||||
String activityString = getActivityString(isBanned, isUnknown, isActive);
|
||||
|
||||
String img = showImages ? Html.MINOTAR_SMALL_IMG.parse(uData.getName()) : "";
|
||||
|
||||
@ -59,7 +57,6 @@ public class PlayersTableCreator {
|
||||
String.valueOf(uData.getGeolocation())
|
||||
));
|
||||
} catch (NullPointerException ignored) {
|
||||
/* ignored */
|
||||
}
|
||||
|
||||
i++;
|
||||
@ -67,4 +64,11 @@ public class PlayersTableCreator {
|
||||
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static String getActivityString(boolean isBanned, boolean isUnknown, boolean isActive) {
|
||||
return isBanned ? "Banned"
|
||||
: (isUnknown ? "Unknown"
|
||||
: (isActive ? "Active"
|
||||
: "Inactive"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user