mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-01 00:10:12 +01:00
[2.6.0-DEV] Replaced ServerData with Sessions, Added KillData
- Playerkills untested - PlanLite analysis part disabled, will be replaced soon. Known bugs: - One empty nickname somehow manages to get into nicknames - SessionData cleared when DataCache clears data from cache - UnIntended. Will need a seperate save spot for current session data.
This commit is contained in:
parent
ae94733da5
commit
a2cd3af688
@ -4,14 +4,14 @@ import com.djrapitops.plan.Phrase;
|
|||||||
import com.djrapitops.plan.Plan;
|
import com.djrapitops.plan.Plan;
|
||||||
import com.djrapitops.plan.command.CommandType;
|
import com.djrapitops.plan.command.CommandType;
|
||||||
import com.djrapitops.plan.command.SubCommand;
|
import com.djrapitops.plan.command.SubCommand;
|
||||||
import com.djrapitops.plan.data.ServerData;
|
import com.djrapitops.plan.data.UserData;
|
||||||
import com.djrapitops.plan.database.Database;
|
import com.djrapitops.plan.database.Database;
|
||||||
import com.djrapitops.plan.database.databases.SQLiteDB;
|
import com.djrapitops.plan.database.databases.SQLiteDB;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import main.java.com.djrapitops.plan.utilities.DataCombineUtils;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -72,7 +72,7 @@ public class ManageBackupCommand extends SubCommand {
|
|||||||
plugin.logError(db + " was null!");
|
plugin.logError(db + " was null!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final Database copyfromDB = database;
|
final Database copyFromDB = database;
|
||||||
(new BukkitRunnable() {
|
(new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -87,13 +87,13 @@ public class ManageBackupCommand extends SubCommand {
|
|||||||
}
|
}
|
||||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||||
backupDB.removeAllData();
|
backupDB.removeAllData();
|
||||||
Set<UUID> uuids = copyfromDB.getSavedUUIDs();
|
Set<UUID> uuids = copyFromDB.getSavedUUIDs();
|
||||||
|
List<UserData> allUserData = new ArrayList<>();
|
||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
backupDB.saveUserData(uuid, copyfromDB.getUserData(uuid));
|
allUserData.add(copyFromDB.getUserData(uuid));
|
||||||
}
|
}
|
||||||
HashMap<Long, ServerData> serverDataHashMap = copyfromDB.getServerDataHashMap();
|
backupDB.saveMultipleUserData(allUserData);
|
||||||
backupDB.saveServerDataHashMap(serverDataHashMap);
|
backupDB.saveCommandUse(copyFromDB.getCommandUse());
|
||||||
backupDB.saveCommandUse(DataCombineUtils.getCommandUse(serverDataHashMap));
|
|
||||||
sender.sendMessage(Phrase.MANAGE_COPY_SUCCESS.toString());
|
sender.sendMessage(Phrase.MANAGE_COPY_SUCCESS.toString());
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import com.djrapitops.plan.Phrase;
|
|||||||
import com.djrapitops.plan.Plan;
|
import com.djrapitops.plan.Plan;
|
||||||
import com.djrapitops.plan.command.CommandType;
|
import com.djrapitops.plan.command.CommandType;
|
||||||
import com.djrapitops.plan.command.SubCommand;
|
import com.djrapitops.plan.command.SubCommand;
|
||||||
import com.djrapitops.plan.data.ServerData;
|
|
||||||
import com.djrapitops.plan.data.UserData;
|
import com.djrapitops.plan.data.UserData;
|
||||||
|
|
||||||
import com.djrapitops.plan.database.Database;
|
import com.djrapitops.plan.database.Database;
|
||||||
@ -127,15 +126,10 @@ public class ManageCombineCommand extends SubCommand {
|
|||||||
|
|
||||||
List<UserData> combinedUserData = DataCombineUtils.combineUserDatas(allFromUserData, allToUserData, uuids);
|
List<UserData> combinedUserData = DataCombineUtils.combineUserDatas(allFromUserData, allToUserData, uuids);
|
||||||
|
|
||||||
HashMap<Long, ServerData> fromServerData = moveFromDB.getServerDataHashMap();
|
HashMap<String, Integer> commandUse = DataCombineUtils.combineCommandUses(moveFromDB.getCommandUse(), moveToDB.getCommandUse());
|
||||||
HashMap<Long, ServerData> toServerData = moveToDB.getServerDataHashMap();
|
|
||||||
HashMap<Long, ServerData> combinedServerData = DataCombineUtils.combineServerDatas(fromServerData, toServerData);
|
|
||||||
|
|
||||||
HashMap<String, Integer> commandUse = DataCombineUtils.combineCommandUses(DataCombineUtils.getCommandUse(fromServerData), DataCombineUtils.getCommandUse(toServerData));
|
|
||||||
|
|
||||||
moveToDB.removeAllData();
|
moveToDB.removeAllData();
|
||||||
|
|
||||||
moveToDB.saveServerDataHashMap(combinedServerData);
|
|
||||||
moveToDB.saveMultipleUserData(combinedUserData);
|
moveToDB.saveMultipleUserData(combinedUserData);
|
||||||
moveToDB.saveCommandUse(commandUse);
|
moveToDB.saveCommandUse(commandUse);
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public class ManageHotswapCommand extends SubCommand {
|
|||||||
if (dbToSwapTo.equalsIgnoreCase(database.getConfigName())) {
|
if (dbToSwapTo.equalsIgnoreCase(database.getConfigName())) {
|
||||||
db = database;
|
db = database;
|
||||||
db.init();
|
db.init();
|
||||||
db.getNewestServerData();
|
db.getVersion(); //Test db connection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
|
@ -21,6 +21,7 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||||
|
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -4,13 +4,11 @@ import com.djrapitops.plan.Phrase;
|
|||||||
import com.djrapitops.plan.Plan;
|
import com.djrapitops.plan.Plan;
|
||||||
import com.djrapitops.plan.command.CommandType;
|
import com.djrapitops.plan.command.CommandType;
|
||||||
import com.djrapitops.plan.command.SubCommand;
|
import com.djrapitops.plan.command.SubCommand;
|
||||||
import com.djrapitops.plan.data.ServerData;
|
|
||||||
import com.djrapitops.plan.data.UserData;
|
import com.djrapitops.plan.data.UserData;
|
||||||
|
|
||||||
import com.djrapitops.plan.database.Database;
|
import com.djrapitops.plan.database.Database;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -33,7 +31,7 @@ public class ManageMoveCommand extends SubCommand {
|
|||||||
* @param plugin Current instance of Plan
|
* @param plugin Current instance of Plan
|
||||||
*/
|
*/
|
||||||
public ManageMoveCommand(Plan plugin) {
|
public ManageMoveCommand(Plan plugin) {
|
||||||
super("move", "plan.manage", Phrase.CMD_USG_MANAGE_MOVE+"", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_MOVE+"");
|
super("move", "plan.manage", Phrase.CMD_USG_MANAGE_MOVE + "", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_MOVE + "");
|
||||||
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
@ -54,7 +52,7 @@ public class ManageMoveCommand extends SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_MOVE+""));
|
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_MOVE + ""));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String fromDB = args[0].toLowerCase();
|
String fromDB = args[0].toLowerCase();
|
||||||
@ -98,7 +96,7 @@ public class ManageMoveCommand extends SubCommand {
|
|||||||
plugin.logError(toDB + " was null!");
|
plugin.logError(toDB + " was null!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final Set<UUID> uuids = fromDatabase.getSavedUUIDs();
|
final Set<UUID> uuids = fromDatabase.getSavedUUIDs();
|
||||||
if (uuids.isEmpty()) {
|
if (uuids.isEmpty()) {
|
||||||
sender.sendMessage(Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + fromDB + ")");
|
sender.sendMessage(Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + fromDB + ")");
|
||||||
return true;
|
return true;
|
||||||
@ -117,16 +115,7 @@ public class ManageMoveCommand extends SubCommand {
|
|||||||
allUserData.add(moveFromDB.getUserData(uuid));
|
allUserData.add(moveFromDB.getUserData(uuid));
|
||||||
}
|
}
|
||||||
moveToDB.saveMultipleUserData(allUserData);
|
moveToDB.saveMultipleUserData(allUserData);
|
||||||
HashMap<Long, ServerData> serverData = moveFromDB.getServerDataHashMap();
|
moveToDB.saveCommandUse(moveFromDB.getCommandUse());
|
||||||
moveToDB.saveServerDataHashMap(serverData);
|
|
||||||
ServerData sData = null;
|
|
||||||
for (long sDataKey : serverData.keySet()) {
|
|
||||||
sData = serverData.get(sDataKey);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (sData != null) {
|
|
||||||
moveToDB.saveCommandUse(sData.getCommandUsage());
|
|
||||||
}
|
|
||||||
sender.sendMessage(Phrase.MANAGE_MOVE_SUCCESS + "");
|
sender.sendMessage(Phrase.MANAGE_MOVE_SUCCESS + "");
|
||||||
if (!toDB.equals(plugin.getDB().getConfigName())) {
|
if (!toDB.equals(plugin.getDB().getConfigName())) {
|
||||||
sender.sendMessage(Phrase.MANAGE_DB_CONFIG_REMINDER + "");
|
sender.sendMessage(Phrase.MANAGE_DB_CONFIG_REMINDER + "");
|
||||||
@ -134,9 +123,12 @@ public class ManageMoveCommand extends SubCommand {
|
|||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
}).runTaskAsynchronously(plugin);
|
}).runTaskAsynchronously(plugin);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,7 @@ public class ManageRemoveCommand extends SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||||
|
plugin.getHandler().clearFromCache(uuid);
|
||||||
plugin.getDB().removeAccount(uuid.toString());
|
plugin.getDB().removeAccount(uuid.toString());
|
||||||
sender.sendMessage(Phrase.MANAGE_REMOVE_SUCCESS.parse(playerName, plugin.getDB().getConfigName()));
|
sender.sendMessage(Phrase.MANAGE_REMOVE_SUCCESS.parse(playerName, plugin.getDB().getConfigName()));
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -4,19 +4,20 @@ import com.djrapitops.plan.Phrase;
|
|||||||
import com.djrapitops.plan.Plan;
|
import com.djrapitops.plan.Plan;
|
||||||
import com.djrapitops.plan.command.CommandType;
|
import com.djrapitops.plan.command.CommandType;
|
||||||
import com.djrapitops.plan.command.SubCommand;
|
import com.djrapitops.plan.command.SubCommand;
|
||||||
import com.djrapitops.plan.data.ServerData;
|
import com.djrapitops.plan.data.UserData;
|
||||||
import com.djrapitops.plan.database.Database;
|
import com.djrapitops.plan.database.Database;
|
||||||
import com.djrapitops.plan.database.databases.SQLiteDB;
|
import com.djrapitops.plan.database.databases.SQLiteDB;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import main.java.com.djrapitops.plan.utilities.DataCombineUtils;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -78,7 +79,7 @@ public class ManageRestoreCommand extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final Database copyToDB = database;
|
final Database copyToDB = database;
|
||||||
(new BukkitRunnable() {
|
BukkitTask asyncRestoreTask = (new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String backupDBName = args[0];
|
String backupDBName = args[0];
|
||||||
@ -101,12 +102,12 @@ public class ManageRestoreCommand extends SubCommand {
|
|||||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||||
copyToDB.removeAllData();
|
copyToDB.removeAllData();
|
||||||
Set<UUID> uuids = backupDB.getSavedUUIDs();
|
Set<UUID> uuids = backupDB.getSavedUUIDs();
|
||||||
|
List<UserData> allUserData = new ArrayList<>();
|
||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
copyToDB.saveUserData(uuid, backupDB.getUserData(uuid));
|
allUserData.add(backupDB.getUserData(uuid));
|
||||||
}
|
}
|
||||||
HashMap<Long, ServerData> serverDataHashMap = backupDB.getServerDataHashMap();
|
copyToDB.saveMultipleUserData(allUserData);
|
||||||
copyToDB.saveServerDataHashMap(serverDataHashMap);
|
copyToDB.saveCommandUse(backupDB.getCommandUse());
|
||||||
copyToDB.saveCommandUse(DataCombineUtils.getCommandUse(serverDataHashMap));
|
|
||||||
sender.sendMessage(Phrase.MANAGE_COPY_SUCCESS.toString());
|
sender.sendMessage(Phrase.MANAGE_COPY_SUCCESS.toString());
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
|
38
Plan/src/main/java/com/djrapitops/plan/data/KillData.java
Normal file
38
Plan/src/main/java/com/djrapitops/plan/data/KillData.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package main.java.com.djrapitops.plan.data;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class KillData {
|
||||||
|
|
||||||
|
private UUID victim;
|
||||||
|
private int victimUserID;
|
||||||
|
private long date;
|
||||||
|
private String weapon;
|
||||||
|
|
||||||
|
public KillData(UUID victim, int victimID, String weapon, long date) {
|
||||||
|
this.victim = victim;
|
||||||
|
this.weapon = weapon;
|
||||||
|
victimUserID = victimID;
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getVictim() {
|
||||||
|
return victim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWeapon() {
|
||||||
|
return weapon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVictimUserID() {
|
||||||
|
return victimUserID;
|
||||||
|
}
|
||||||
|
}
|
@ -29,6 +29,7 @@ public class RawAnalysisData {
|
|||||||
private HashMap<String, Long> playtimes;
|
private HashMap<String, Long> playtimes;
|
||||||
private List<SessionData> sessiondata;
|
private List<SessionData> sessiondata;
|
||||||
private HashMap<String, Integer> commandUse;
|
private HashMap<String, Integer> commandUse;
|
||||||
|
private List<Long> registered;
|
||||||
|
|
||||||
public RawAnalysisData() {
|
public RawAnalysisData() {
|
||||||
gmZero = 0;
|
gmZero = 0;
|
||||||
@ -47,8 +48,9 @@ public class RawAnalysisData {
|
|||||||
ages = new ArrayList<>();
|
ages = new ArrayList<>();
|
||||||
latestLogins = new HashMap<>();
|
latestLogins = new HashMap<>();
|
||||||
playtimes = new HashMap<>();
|
playtimes = new HashMap<>();
|
||||||
sessiondata = new ArrayList<>();
|
sessiondata = new ArrayList<>();
|
||||||
commandUse = new HashMap<>();
|
commandUse = new HashMap<>();
|
||||||
|
registered = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addToGmZero(long gmZero) {
|
public void addToGmZero(long gmZero) {
|
||||||
@ -186,4 +188,8 @@ public class RawAnalysisData {
|
|||||||
public HashMap<String, Integer> getCommandUse() {
|
public HashMap<String, Integer> getCommandUse() {
|
||||||
return commandUse;
|
return commandUse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Long> getRegistered() {
|
||||||
|
return registered;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,121 +0,0 @@
|
|||||||
package com.djrapitops.plan.data;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.Plan;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class ServerData {
|
|
||||||
|
|
||||||
private final HashMap<String, Integer> commandUsage;
|
|
||||||
private int playersOnline;
|
|
||||||
private int newPlayers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Constructor.
|
|
||||||
*
|
|
||||||
* Creates a new DataPoint of ServerData with the currently known player
|
|
||||||
* count.
|
|
||||||
*
|
|
||||||
* @param commandUsage HashMap of Commands used and times they have been
|
|
||||||
* used.
|
|
||||||
* @param newPlayers Amount of new players that have joined that day.
|
|
||||||
*/
|
|
||||||
public ServerData(HashMap<String, Integer> commandUsage, int newPlayers) {
|
|
||||||
this.commandUsage = commandUsage;
|
|
||||||
this.playersOnline = Bukkit.getServer().getOnlinePlayers().size();
|
|
||||||
this.newPlayers = newPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Constructor with playersOnline.
|
|
||||||
*
|
|
||||||
* Creates a new DataPoint of ServerData with defined player count.
|
|
||||||
*
|
|
||||||
* @param commandUsage HashMap of Commands used and times they have been
|
|
||||||
* used.
|
|
||||||
* @param newPlayers Amount of new players that have joined that day.
|
|
||||||
* @param playersOnline Amount of players at the time of save.
|
|
||||||
*/
|
|
||||||
public ServerData(HashMap<String, Integer> commandUsage, int newPlayers, int playersOnline) {
|
|
||||||
this.commandUsage = commandUsage;
|
|
||||||
this.playersOnline = playersOnline;
|
|
||||||
this.newPlayers = newPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates PlayerCount if the player is new.
|
|
||||||
*
|
|
||||||
* @param newPlayer If data for player is not found in the database this is
|
|
||||||
* true.
|
|
||||||
*/
|
|
||||||
public void playerJoined(boolean newPlayer) {
|
|
||||||
updatePlayerCount();
|
|
||||||
if (newPlayer) {
|
|
||||||
newPlayers++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates playersOnline to current playercount.
|
|
||||||
*/
|
|
||||||
public void updatePlayerCount() {
|
|
||||||
playersOnline = Bukkit.getServer().getOnlinePlayers().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates playersOnline after 5 seconds to wait for Player to leave.
|
|
||||||
*/
|
|
||||||
public void playerLeft() {
|
|
||||||
(new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updatePlayerCount();
|
|
||||||
this.cancel();
|
|
||||||
}
|
|
||||||
}).runTaskLater(getPlugin(Plan.class), 5 * 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds command to the commandUse Map and adds 1 to the amount it has been
|
|
||||||
* used.
|
|
||||||
*
|
|
||||||
* @param command Used command (eg. /plan)
|
|
||||||
*/
|
|
||||||
public void commandRegistered(String command) {
|
|
||||||
if (!commandUsage.containsKey(command)) {
|
|
||||||
commandUsage.put(command, 0);
|
|
||||||
}
|
|
||||||
commandUsage.put(command, commandUsage.get(command) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return HashMap of used Commands and how many times they've been used.
|
|
||||||
*/
|
|
||||||
public HashMap<String, Integer> getCommandUsage() {
|
|
||||||
return commandUsage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return How many players were online at the time of save.
|
|
||||||
*/
|
|
||||||
public int getPlayersOnline() {
|
|
||||||
return playersOnline;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return How many players were new at the time of save.
|
|
||||||
*/
|
|
||||||
public int getNewPlayers() {
|
|
||||||
return newPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNewPlayers(int newPlayers) {
|
|
||||||
this.newPlayers = newPlayers;
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,6 +8,7 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import main.java.com.djrapitops.plan.data.KillData;
|
||||||
import main.java.com.djrapitops.plan.data.PlanLitePlayerData;
|
import main.java.com.djrapitops.plan.data.PlanLitePlayerData;
|
||||||
import main.java.com.djrapitops.plan.data.SessionData;
|
import main.java.com.djrapitops.plan.data.SessionData;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -24,6 +25,7 @@ public class UserData {
|
|||||||
private List<Location> locations;
|
private List<Location> locations;
|
||||||
private HashSet<InetAddress> ips;
|
private HashSet<InetAddress> ips;
|
||||||
private HashSet<String> nicknames;
|
private HashSet<String> nicknames;
|
||||||
|
private String lastNick;
|
||||||
private long registered;
|
private long registered;
|
||||||
private long lastPlayed;
|
private long lastPlayed;
|
||||||
private long playTime;
|
private long playTime;
|
||||||
@ -37,7 +39,7 @@ public class UserData {
|
|||||||
private DemographicsData demData;
|
private DemographicsData demData;
|
||||||
|
|
||||||
private int mobKills;
|
private int mobKills;
|
||||||
private int playerKills;
|
private List<KillData> playerKills;
|
||||||
private int deaths;
|
private int deaths;
|
||||||
|
|
||||||
private boolean planLiteFound;
|
private boolean planLiteFound;
|
||||||
@ -72,6 +74,8 @@ public class UserData {
|
|||||||
name = player.getName();
|
name = player.getName();
|
||||||
isOnline = player.isOnline();
|
isOnline = player.isOnline();
|
||||||
sessions = new ArrayList<>();
|
sessions = new ArrayList<>();
|
||||||
|
lastNick = "";
|
||||||
|
playerKills = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserData(OfflinePlayer player, DemographicsData demData, Database db) {
|
public UserData(OfflinePlayer player, DemographicsData demData, Database db) {
|
||||||
@ -95,6 +99,8 @@ public class UserData {
|
|||||||
name = player.getName();
|
name = player.getName();
|
||||||
isOnline = player.isOnline();
|
isOnline = player.isOnline();
|
||||||
sessions = new ArrayList<>();
|
sessions = new ArrayList<>();
|
||||||
|
lastNick = "";
|
||||||
|
playerKills = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIpAddress(InetAddress ip) {
|
public void addIpAddress(InetAddress ip) {
|
||||||
@ -119,10 +125,14 @@ public class UserData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNickname(String nick) {
|
public boolean addNickname(String nick) {
|
||||||
if (!nicknames.contains(nick)) {
|
if (!nicknames.contains(nick)) {
|
||||||
nicknames.add(nick);
|
if (!nick.isEmpty()) {
|
||||||
|
nicknames.add(nick);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNicknames(Collection<String> addNicks) {
|
public void addNicknames(Collection<String> addNicks) {
|
||||||
@ -339,13 +349,17 @@ public class UserData {
|
|||||||
this.mobKills = mobKills;
|
this.mobKills = mobKills;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPlayerKills() {
|
public List<KillData> getPlayerKills() {
|
||||||
return playerKills;
|
return playerKills;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerKills(int playerKills) {
|
public void setPlayerKills(List<KillData> playerKills) {
|
||||||
this.playerKills = playerKills;
|
this.playerKills = playerKills;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPlayerKill(KillData kill) {
|
||||||
|
playerKills.add(kill);
|
||||||
|
}
|
||||||
|
|
||||||
public int getDeaths() {
|
public int getDeaths() {
|
||||||
return deaths;
|
return deaths;
|
||||||
@ -358,4 +372,12 @@ public class UserData {
|
|||||||
public List<SessionData> getSessions() {
|
public List<SessionData> getSessions() {
|
||||||
return sessions;
|
return sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLastNick() {
|
||||||
|
return lastNick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastNick(String lastNick) {
|
||||||
|
this.lastNick = lastNick;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import com.djrapitops.plan.Plan;
|
|||||||
import com.djrapitops.plan.database.Database;
|
import com.djrapitops.plan.database.Database;
|
||||||
import com.djrapitops.plan.data.*;
|
import com.djrapitops.plan.data.*;
|
||||||
import com.djrapitops.plan.data.handlers.*;
|
import com.djrapitops.plan.data.handlers.*;
|
||||||
import com.djrapitops.plan.utilities.MiscUtils;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -34,8 +33,8 @@ public class DataCacheHandler {
|
|||||||
private final DemographicsHandler demographicsHandler;
|
private final DemographicsHandler demographicsHandler;
|
||||||
private final BasicInfoHandler basicInfoHandler;
|
private final BasicInfoHandler basicInfoHandler;
|
||||||
private final RuleBreakingHandler ruleBreakingHandler;
|
private final RuleBreakingHandler ruleBreakingHandler;
|
||||||
private final ServerData serverData;
|
private final HashMap<String, Integer> commandUse;
|
||||||
private final ServerDataHandler serverDataHandler;
|
private final CommandUseHandler commandUseHandler;
|
||||||
private final PlanLiteHandler planLiteHandler;
|
private final PlanLiteHandler planLiteHandler;
|
||||||
private final KillHandler killHandler;
|
private final KillHandler killHandler;
|
||||||
private final Database db;
|
private final Database db;
|
||||||
@ -43,7 +42,6 @@ public class DataCacheHandler {
|
|||||||
|
|
||||||
private int timesSaved;
|
private int timesSaved;
|
||||||
private int maxPlayers;
|
private int maxPlayers;
|
||||||
private Date lastServerDataSave;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Constructor.
|
* Class Constructor.
|
||||||
@ -63,15 +61,14 @@ public class DataCacheHandler {
|
|||||||
demographicsHandler = new DemographicsHandler(plugin, this);
|
demographicsHandler = new DemographicsHandler(plugin, this);
|
||||||
basicInfoHandler = new BasicInfoHandler(plugin, this);
|
basicInfoHandler = new BasicInfoHandler(plugin, this);
|
||||||
ruleBreakingHandler = new RuleBreakingHandler(plugin, this);
|
ruleBreakingHandler = new RuleBreakingHandler(plugin, this);
|
||||||
serverData = db.getNewestServerData();
|
commandUse = db.getCommandUse();
|
||||||
serverDataHandler = new ServerDataHandler(serverData);
|
commandUseHandler = new CommandUseHandler(commandUse);
|
||||||
planLiteHandler = new PlanLiteHandler(plugin);
|
planLiteHandler = new PlanLiteHandler(plugin);
|
||||||
newPlayerCreator = new NewPlayerCreator(plugin, this);
|
newPlayerCreator = new NewPlayerCreator(plugin, this);
|
||||||
killHandler = new KillHandler(plugin);
|
killHandler = new KillHandler(plugin);
|
||||||
|
|
||||||
timesSaved = 0;
|
timesSaved = 0;
|
||||||
maxPlayers = plugin.getServer().getMaxPlayers();
|
maxPlayers = plugin.getServer().getMaxPlayers();
|
||||||
lastServerDataSave = new Date();
|
|
||||||
|
|
||||||
int minutes = Settings.SAVE_CACHE_MIN.getNumber();
|
int minutes = Settings.SAVE_CACHE_MIN.getNumber();
|
||||||
if (minutes <= 0) {
|
if (minutes <= 0) {
|
||||||
@ -97,13 +94,7 @@ public class DataCacheHandler {
|
|||||||
if (timesSaved % clearAfterXsaves == 0) {
|
if (timesSaved % clearAfterXsaves == 0) {
|
||||||
handler.clearCache();
|
handler.clearCache();
|
||||||
}
|
}
|
||||||
Date serverDataSave = new Date();
|
saveCommandUse();
|
||||||
if (MiscUtils.isOnSameDay(serverDataSave, lastServerDataSave)) {
|
|
||||||
serverData.setNewPlayers(0);
|
|
||||||
}
|
|
||||||
serverData.updatePlayerCount();
|
|
||||||
saveServerData();
|
|
||||||
lastServerDataSave = serverDataSave;
|
|
||||||
handler.clearNulls();
|
handler.clearNulls();
|
||||||
timesSaved++;
|
timesSaved++;
|
||||||
}
|
}
|
||||||
@ -185,8 +176,12 @@ public class DataCacheHandler {
|
|||||||
// });
|
// });
|
||||||
List<UserData> data = new ArrayList<>();
|
List<UserData> data = new ArrayList<>();
|
||||||
data.addAll(dataCache.values());
|
data.addAll(dataCache.values());
|
||||||
|
long now = new Date().toInstant().getEpochSecond() * (long) 1000;
|
||||||
|
for (UserData userData : data) {
|
||||||
|
userData.endSession(now);
|
||||||
|
}
|
||||||
db.saveMultipleUserData(data);
|
db.saveMultipleUserData(data);
|
||||||
db.saveServerData(serverData);
|
db.saveCommandUse(commandUse);
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,11 +208,11 @@ public class DataCacheHandler {
|
|||||||
*
|
*
|
||||||
* Data is saved on a new line with a long value matching current Date
|
* Data is saved on a new line with a long value matching current Date
|
||||||
*/
|
*/
|
||||||
public void saveServerData() {
|
public void saveCommandUse() {
|
||||||
(new BukkitRunnable() {
|
(new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
db.saveServerData(serverData);
|
db.saveCommandUse(commandUse);
|
||||||
}
|
}
|
||||||
}).runTaskAsynchronously(plugin);
|
}).runTaskAsynchronously(plugin);
|
||||||
}
|
}
|
||||||
@ -395,21 +390,15 @@ public class DataCacheHandler {
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public HashMap<String, Integer> getCommandUse() {
|
||||||
* Updates the player count and returns cached ServerData.
|
return commandUse;
|
||||||
*
|
|
||||||
* @return Cached serverData
|
|
||||||
*/
|
|
||||||
public ServerData getServerData() {
|
|
||||||
serverData.updatePlayerCount();
|
|
||||||
return serverData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Current instance of ServerDataHandler
|
* @return Current instance of ServerDataHandler
|
||||||
*/
|
*/
|
||||||
public ServerDataHandler getServerDataHandler() {
|
public CommandUseHandler getServerDataHandler() {
|
||||||
return serverDataHandler;
|
return commandUseHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -424,7 +413,6 @@ public class DataCacheHandler {
|
|||||||
if (isNewPlayer) {
|
if (isNewPlayer) {
|
||||||
newPlayer(player);
|
newPlayer(player);
|
||||||
}
|
}
|
||||||
serverDataHandler.handleLogin(isNewPlayer);
|
|
||||||
UserData data = getCurrentData(uuid);
|
UserData data = getCurrentData(uuid);
|
||||||
activityHandler.handleReload(player, data);
|
activityHandler.handleReload(player, data);
|
||||||
basicInfoHandler.handleReload(player, data);
|
basicInfoHandler.handleReload(player, data);
|
||||||
|
@ -97,8 +97,10 @@ public class ActivityHandler {
|
|||||||
* @param data UserData matching the Player
|
* @param data UserData matching the Player
|
||||||
*/
|
*/
|
||||||
public void handleReload(Player player, UserData data) {
|
public void handleReload(Player player, UserData data) {
|
||||||
long timeNow = new Date().getTime();
|
Date now = new Date();
|
||||||
|
long timeNow = now.getTime();
|
||||||
data.setPlayTime(data.getPlayTime() + (timeNow - data.getLastPlayed()));
|
data.setPlayTime(data.getPlayTime() + (timeNow - data.getLastPlayed()));
|
||||||
data.setLastPlayed(timeNow);
|
data.setLastPlayed(timeNow);
|
||||||
|
data.startSession(now.toInstant().getEpochSecond() * (long) 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,10 @@ public class BasicInfoHandler {
|
|||||||
*/
|
*/
|
||||||
public void handleLogin(PlayerJoinEvent event, UserData data) {
|
public void handleLogin(PlayerJoinEvent event, UserData data) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
data.addNickname(player.getDisplayName());
|
String nick = player.getDisplayName();
|
||||||
|
if (data.addNickname(nick)) {
|
||||||
|
data.setLastNick(nick);
|
||||||
|
}
|
||||||
data.addIpAddress(player.getAddress().getAddress());
|
data.addIpAddress(player.getAddress().getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +46,10 @@ public class BasicInfoHandler {
|
|||||||
* @param data UserData matching the Player
|
* @param data UserData matching the Player
|
||||||
*/
|
*/
|
||||||
public void handleReload(Player player, UserData data) {
|
public void handleReload(Player player, UserData data) {
|
||||||
data.addNickname(player.getDisplayName());
|
String nick = player.getDisplayName();
|
||||||
|
if (data.addNickname(nick)) {
|
||||||
|
data.setLastNick(nick);
|
||||||
|
}
|
||||||
data.addIpAddress(player.getAddress().getAddress());
|
data.addIpAddress(player.getAddress().getAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.djrapitops.plan.data.handlers;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class CommandUseHandler {
|
||||||
|
|
||||||
|
private HashMap<String, Integer> commandUse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param serverData ServerData in the DataCacheHandler.
|
||||||
|
*/
|
||||||
|
public CommandUseHandler(HashMap<String, Integer> serverData) {
|
||||||
|
this.commandUse = serverData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds command to the command usage.
|
||||||
|
* @param command Used command, first part (eg. /plan)
|
||||||
|
*/
|
||||||
|
public void handleCommand(String command) {
|
||||||
|
if (!commandUse.containsKey(command)) {
|
||||||
|
commandUse.put(command, 0);
|
||||||
|
}
|
||||||
|
commandUse.put(command, commandUse.get(command) + 1);
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,9 @@ package com.djrapitops.plan.data.handlers;
|
|||||||
|
|
||||||
import com.djrapitops.plan.Plan;
|
import com.djrapitops.plan.Plan;
|
||||||
import com.djrapitops.plan.data.UserData;
|
import com.djrapitops.plan.data.UserData;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.UUID;
|
||||||
|
import main.java.com.djrapitops.plan.data.KillData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -15,8 +18,11 @@ public class KillHandler {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePlayerKill(UserData data) {
|
public void handlePlayerKill(UserData killerData, UserData victim, String weapon) {
|
||||||
data.setPlayerKills(data.getPlayerKills()+1);
|
UUID victimUUID = victim.getUuid();
|
||||||
|
long now = new Date().toInstant().getEpochSecond()*(long)1000;
|
||||||
|
int victimID = plugin.getDB().getUserId(victimUUID+"");
|
||||||
|
killerData.addPlayerKill(new KillData(victimUUID, victimID, weapon, now));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePlayerDeath(UserData data) {
|
public void handlePlayerDeath(UserData data) {
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||||
|
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -59,7 +59,6 @@ public class NewPlayerCreator {
|
|||||||
data.setLastGmSwapTime(zero);
|
data.setLastGmSwapTime(zero);
|
||||||
data.setDeaths(0);
|
data.setDeaths(0);
|
||||||
data.setMobKills(0);
|
data.setMobKills(0);
|
||||||
data.setPlayerKills(0);
|
|
||||||
db.saveUserData(player.getUniqueId(), data);
|
db.saveUserData(player.getUniqueId(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
package com.djrapitops.plan.data.handlers;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.ServerData;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class ServerDataHandler {
|
|
||||||
|
|
||||||
private ServerData serverData;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param serverData ServerData in the DataCacheHandler.
|
|
||||||
*/
|
|
||||||
public ServerDataHandler(ServerData serverData) {
|
|
||||||
this.serverData = serverData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates playercount and adds new player if player is new.
|
|
||||||
*
|
|
||||||
* @param newPlayer true if player not in database.
|
|
||||||
*/
|
|
||||||
public void handleLogin(boolean newPlayer) {
|
|
||||||
serverData.playerJoined(newPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates playercount.
|
|
||||||
*/
|
|
||||||
public void handleLogout() {
|
|
||||||
serverData.playerLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates playercount.
|
|
||||||
*/
|
|
||||||
public void handleKick() {
|
|
||||||
handleLogout();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds command to the command usage.
|
|
||||||
* @param command Used command, first part (eg. /plan)
|
|
||||||
*/
|
|
||||||
public void handleCommand(String command) {
|
|
||||||
serverData.commandRegistered(command);
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,7 @@ package com.djrapitops.plan.data.listeners;
|
|||||||
|
|
||||||
import com.djrapitops.plan.Plan;
|
import com.djrapitops.plan.Plan;
|
||||||
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
import com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||||
import com.djrapitops.plan.data.handlers.ServerDataHandler;
|
import com.djrapitops.plan.data.handlers.CommandUseHandler;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -16,7 +16,7 @@ public class PlanCommandPreprocessListener implements Listener {
|
|||||||
|
|
||||||
private final Plan plugin;
|
private final Plan plugin;
|
||||||
private final DataCacheHandler handler;
|
private final DataCacheHandler handler;
|
||||||
private final ServerDataHandler serverH;
|
private final CommandUseHandler serverH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Constructor.
|
* Class Constructor.
|
||||||
|
@ -45,7 +45,8 @@ public class PlanDeathEventListener implements Listener {
|
|||||||
Player killed = (Player) dead;
|
Player killed = (Player) dead;
|
||||||
UserData killedsData = handler.getCurrentData(killed.getUniqueId());
|
UserData killedsData = handler.getCurrentData(killed.getUniqueId());
|
||||||
if (killerIsPlayer) {
|
if (killerIsPlayer) {
|
||||||
kH.handlePlayerKill(killersData);
|
String weaponName = killer.getInventory().getItemInMainHand().getType().name();
|
||||||
|
kH.handlePlayerKill(killersData, killedsData, weaponName);
|
||||||
}
|
}
|
||||||
kH.handlePlayerDeath(killedsData);
|
kH.handlePlayerDeath(killedsData);
|
||||||
} else if (killerIsPlayer) {
|
} else if (killerIsPlayer) {
|
||||||
|
@ -29,7 +29,7 @@ public class PlanPlayerListener implements Listener {
|
|||||||
private final DemographicsHandler demographicH;
|
private final DemographicsHandler demographicH;
|
||||||
private final RuleBreakingHandler rulebreakH;
|
private final RuleBreakingHandler rulebreakH;
|
||||||
private final PlanLiteHandler planLiteH;
|
private final PlanLiteHandler planLiteH;
|
||||||
private final ServerDataHandler serverHandler;
|
private final CommandUseHandler serverHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Constructor.
|
* Class Constructor.
|
||||||
@ -68,7 +68,6 @@ public class PlanPlayerListener implements Listener {
|
|||||||
if (isNewPlayer) {
|
if (isNewPlayer) {
|
||||||
handler.newPlayer(player);
|
handler.newPlayer(player);
|
||||||
}
|
}
|
||||||
serverHandler.handleLogin(isNewPlayer);
|
|
||||||
UserData data = handler.getCurrentData(uuid);
|
UserData data = handler.getCurrentData(uuid);
|
||||||
activityH.handleLogin(event, data);
|
activityH.handleLogin(event, data);
|
||||||
basicInfoH.handleLogin(event, data);
|
basicInfoH.handleLogin(event, data);
|
||||||
@ -98,7 +97,6 @@ public class PlanPlayerListener implements Listener {
|
|||||||
activityH.handleLogOut(event, data);
|
activityH.handleLogOut(event, data);
|
||||||
locationH.handleLogOut(event, data);
|
locationH.handleLogOut(event, data);
|
||||||
gmTimesH.handleLogOut(event, data);
|
gmTimesH.handleLogOut(event, data);
|
||||||
serverHandler.handleLogout();
|
|
||||||
handler.saveCachedData(uuid);
|
handler.saveCachedData(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +115,6 @@ public class PlanPlayerListener implements Listener {
|
|||||||
UUID uuid = event.getPlayer().getUniqueId();
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
UserData data = handler.getCurrentData(uuid);
|
UserData data = handler.getCurrentData(uuid);
|
||||||
rulebreakH.handleKick(event, data);
|
rulebreakH.handleKick(event, data);
|
||||||
serverHandler.handleKick();
|
|
||||||
handler.saveCachedData(uuid);
|
handler.saveCachedData(uuid);
|
||||||
handler.clearFromCache(uuid);
|
handler.clearFromCache(uuid);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.djrapitops.plan.database;
|
package com.djrapitops.plan.database;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.UserData;
|
import com.djrapitops.plan.data.UserData;
|
||||||
import com.djrapitops.plan.data.ServerData;
|
|
||||||
import com.djrapitops.plan.Plan;
|
import com.djrapitops.plan.Plan;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
@ -63,13 +62,6 @@ public abstract class Database {
|
|||||||
*/
|
*/
|
||||||
public abstract boolean wasSeenBefore(UUID uuid);
|
public abstract boolean wasSeenBefore(UUID uuid);
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the settings to the config for each database type.
|
|
||||||
*
|
|
||||||
* @param section
|
|
||||||
*/
|
|
||||||
public abstract void getConfigDefaults(ConfigurationSection section);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans the database.
|
* Cleans the database.
|
||||||
*/
|
*/
|
||||||
@ -114,36 +106,15 @@ public abstract class Database {
|
|||||||
*/
|
*/
|
||||||
public abstract void setVersion(int version);
|
public abstract void setVersion(int version);
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves new server data to the table
|
|
||||||
*
|
|
||||||
* @param serverData Current serverdata
|
|
||||||
*/
|
|
||||||
public abstract void saveServerData(ServerData serverData);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the newest serverdata from the database.
|
|
||||||
*
|
|
||||||
* @return ServerData with the highest save date.
|
|
||||||
*/
|
|
||||||
public abstract ServerData getNewestServerData();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the database.
|
* Closes the database.
|
||||||
*/
|
*/
|
||||||
public abstract void close();
|
public abstract void close();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns raw data for analysis, contains all of player activity history.
|
|
||||||
*
|
|
||||||
* @return HashMap with save date (long in ms) and ServerData.
|
|
||||||
*/
|
|
||||||
public abstract HashMap<Long, ServerData> getServerDataHashMap();
|
|
||||||
|
|
||||||
public abstract void removeAccount(String uuid);
|
public abstract void removeAccount(String uuid);
|
||||||
public abstract void removeAllData();
|
public abstract void removeAllData();
|
||||||
public abstract void saveServerDataHashMap(HashMap<Long, ServerData> serverData);
|
|
||||||
public abstract void saveCommandUse(HashMap<String, Integer> data);
|
public abstract void saveCommandUse(HashMap<String, Integer> data);
|
||||||
public abstract Set<UUID> getSavedUUIDs();
|
public abstract Set<UUID> getSavedUUIDs();
|
||||||
public abstract HashMap<String, Integer> getCommandUse();
|
public abstract HashMap<String, Integer> getCommandUse();
|
||||||
|
public abstract int getUserId(String uuid);
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,6 @@ public class MySQLDB extends SQLDB {
|
|||||||
protected Connection getNewConnection() {
|
protected Connection getNewConnection() {
|
||||||
FileConfiguration config = getPlugin(Plan.class).getConfig();
|
FileConfiguration config = getPlugin(Plan.class).getConfig();
|
||||||
|
|
||||||
|
|
||||||
setUserName(config.getString("mysql.tables.users"));
|
|
||||||
setLocationName(config.getString("mysql.tables.locations"));
|
|
||||||
setNicknamesName(config.getString("mysql.tables.nicknames"));
|
|
||||||
setGamemodetimesName(config.getString("mysql.tables.gamemodetimes"));
|
|
||||||
setIpsName(config.getString("mysql.tables.ips"));
|
|
||||||
setCommanduseName(config.getString("mysql.tables.commandusages"));
|
|
||||||
setServerdataName(config.getString("mysql.tables.serverdata"));
|
|
||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
|
||||||
@ -53,35 +45,6 @@ public class MySQLDB extends SQLDB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private ConfigurationSection getSection(ConfigurationSection parent, String childName) {
|
|
||||||
// ConfigurationSection child = parent.getConfigurationSection(childName);
|
|
||||||
//
|
|
||||||
// if (child == null) {
|
|
||||||
// child = parent.createSection(childName);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return child;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getConfigDefaults(ConfigurationSection section) {
|
|
||||||
// section.addDefault("host", "localhost");
|
|
||||||
// section.addDefault("port", 3306);
|
|
||||||
// section.addDefault("user", "root");
|
|
||||||
// section.addDefault("password", "minecraft");
|
|
||||||
// section.addDefault("database", "Plan");
|
|
||||||
//
|
|
||||||
// ConfigurationSection tables = getSection(section, "tables");
|
|
||||||
//
|
|
||||||
// tables.addDefault("users", "plan_users");
|
|
||||||
// tables.addDefault("locations", "plan_locations");
|
|
||||||
// tables.addDefault("nicknames", "plan_nicknames");
|
|
||||||
// tables.addDefault("gamemodetimes", "plan_gamemodetimes");
|
|
||||||
// tables.addDefault("ips", "plan_ips");
|
|
||||||
// tables.addDefault("commandusages", "plan_commandusages");
|
|
||||||
// tables.addDefault("serverdata", "plan_serverdata");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "MySQL";
|
return "MySQL";
|
||||||
|
@ -4,7 +4,6 @@ import com.djrapitops.plan.Plan;
|
|||||||
import com.djrapitops.plan.api.Gender;
|
import com.djrapitops.plan.api.Gender;
|
||||||
import com.djrapitops.plan.database.Database;
|
import com.djrapitops.plan.database.Database;
|
||||||
import com.djrapitops.plan.data.*;
|
import com.djrapitops.plan.data.*;
|
||||||
import com.djrapitops.plan.utilities.MiscUtils;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@ -12,14 +11,13 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import main.java.com.djrapitops.plan.data.KillData;
|
||||||
import java.util.logging.Logger;
|
import main.java.com.djrapitops.plan.data.SessionData;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -35,46 +33,59 @@ public abstract class SQLDB extends Database {
|
|||||||
|
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
private String userName;
|
private final String userName;
|
||||||
private String locationName;
|
private final String locationName;
|
||||||
private String serverdataName;
|
private final String serverdataName;
|
||||||
private String commanduseName;
|
private final String commanduseName;
|
||||||
private String gamemodetimesName;
|
private final String gamemodetimesName;
|
||||||
private String nicknamesName;
|
private final String nicknamesName;
|
||||||
private String ipsName;
|
private final String ipsName;
|
||||||
|
private final String sessionName;
|
||||||
|
private final String killsName;
|
||||||
|
|
||||||
private String userColumnUUID;
|
private final String userColumnUUID;
|
||||||
private final String userColumnID;
|
private final String userColumnID;
|
||||||
private String userColumnPlayTime;
|
private final String userColumnPlayTime;
|
||||||
private String userColumnDemGeoLocation;
|
private final String userColumnDemGeoLocation;
|
||||||
private String userColumnDemAge;
|
private final String userColumnDemAge;
|
||||||
private String userColumnDemGender;
|
private final String userColumnDemGender;
|
||||||
private String userColumnLastGM;
|
private final String userColumnLastGM;
|
||||||
private String userColumnLastGMSwapTime;
|
private final String userColumnLastGMSwapTime;
|
||||||
private String userColumnLoginTimes;
|
private final String userColumnLoginTimes;
|
||||||
private String userColumnLastPlayed;
|
private final String userColumnLastPlayed;
|
||||||
private String userColumnMobKills;
|
private final String userColumnMobKills;
|
||||||
private String userColumnPlayerKills;
|
private final String userColumnPlayerKills;
|
||||||
private String userColumnDeaths;
|
private final String userColumnDeaths;
|
||||||
|
|
||||||
private final String locationColumnUserID;
|
private final String locationColumnUserID;
|
||||||
private String locationColumnID;
|
private final String locationColumnID;
|
||||||
private String locationColumnCoordinatesX;
|
private final String locationColumnCoordinatesX;
|
||||||
private String locationColumnCoordinatesZ;
|
private final String locationColumnCoordinatesZ;
|
||||||
private String locationColumnWorld;
|
private final String locationColumnWorld;
|
||||||
private String serverdataColumnDate;
|
|
||||||
private String serverdataColumnPlayersOnline;
|
private final String commanduseColumnCommand;
|
||||||
private String serverdataColumnNewPlayers;
|
private final String commanduseColumnTimesUsed;
|
||||||
private String commanduseColumnCommand;
|
|
||||||
private String commanduseColumnTimesUsed;
|
|
||||||
private final String gamemodetimesColumnUserID;
|
private final String gamemodetimesColumnUserID;
|
||||||
private String gamemodetimesColumnSurvivalTime;
|
private final String gamemodetimesColumnSurvivalTime;
|
||||||
private String gamemodetimesColumnCreativeTime;
|
private final String gamemodetimesColumnCreativeTime;
|
||||||
private String gamemodetimesColumnAdventureTime;
|
private final String gamemodetimesColumnAdventureTime;
|
||||||
private String gamemodetimesColumnSpectatorTime;
|
private final String gamemodetimesColumnSpectatorTime;
|
||||||
private String nicknamesColumnUserID;
|
|
||||||
private String nicknamesColumnNick;
|
private final String nicknamesColumnUserID;
|
||||||
|
private final String nicknamesColumnNick;
|
||||||
|
private final String nicknamesColumnCurrent;
|
||||||
private final String ipsColumnUserID;
|
private final String ipsColumnUserID;
|
||||||
private String ipsColumnIP;
|
private final String ipsColumnIP;
|
||||||
|
|
||||||
|
private final String sessionColumnUserID;
|
||||||
|
private final String sessionColumnSessionStart;
|
||||||
|
private final String sessionColumnSessionEnd;
|
||||||
|
|
||||||
|
private final String killsColumnKillerUserID;
|
||||||
|
private final String killsColumnVictimUserID;
|
||||||
|
private final String killsColumnWeapon;
|
||||||
|
private final String killsColumnDate;
|
||||||
|
|
||||||
private String versionName;
|
private String versionName;
|
||||||
|
|
||||||
@ -90,6 +101,8 @@ public abstract class SQLDB extends Database {
|
|||||||
gamemodetimesName = "plan_gamemodetimes";
|
gamemodetimesName = "plan_gamemodetimes";
|
||||||
serverdataName = "plan_serverdata";
|
serverdataName = "plan_serverdata";
|
||||||
ipsName = "plan_ips";
|
ipsName = "plan_ips";
|
||||||
|
sessionName = "plan_sessions";
|
||||||
|
killsName = "plan_kills";
|
||||||
|
|
||||||
userColumnID = "id";
|
userColumnID = "id";
|
||||||
locationColumnID = "id";
|
locationColumnID = "id";
|
||||||
@ -98,6 +111,9 @@ public abstract class SQLDB extends Database {
|
|||||||
nicknamesColumnUserID = "user_id";
|
nicknamesColumnUserID = "user_id";
|
||||||
gamemodetimesColumnUserID = "user_id";
|
gamemodetimesColumnUserID = "user_id";
|
||||||
ipsColumnUserID = "user_id";
|
ipsColumnUserID = "user_id";
|
||||||
|
sessionColumnUserID = "user_id";
|
||||||
|
killsColumnKillerUserID = "killer_id";
|
||||||
|
killsColumnVictimUserID = "victim_id";
|
||||||
|
|
||||||
userColumnDemAge = "age";
|
userColumnDemAge = "age";
|
||||||
userColumnDemGender = "gender";
|
userColumnDemGender = "gender";
|
||||||
@ -116,6 +132,7 @@ public abstract class SQLDB extends Database {
|
|||||||
locationColumnWorld = "world_name";
|
locationColumnWorld = "world_name";
|
||||||
|
|
||||||
nicknamesColumnNick = "nickname";
|
nicknamesColumnNick = "nickname";
|
||||||
|
nicknamesColumnCurrent = "current_nick";
|
||||||
|
|
||||||
gamemodetimesColumnSurvivalTime = "survival";
|
gamemodetimesColumnSurvivalTime = "survival";
|
||||||
gamemodetimesColumnCreativeTime = "creative";
|
gamemodetimesColumnCreativeTime = "creative";
|
||||||
@ -127,9 +144,11 @@ public abstract class SQLDB extends Database {
|
|||||||
commanduseColumnCommand = "command";
|
commanduseColumnCommand = "command";
|
||||||
commanduseColumnTimesUsed = "times_used";
|
commanduseColumnTimesUsed = "times_used";
|
||||||
|
|
||||||
serverdataColumnDate = "date";
|
sessionColumnSessionStart = "session_start";
|
||||||
serverdataColumnNewPlayers = "new_players";
|
sessionColumnSessionEnd = "session_end";
|
||||||
serverdataColumnPlayersOnline = "players_online";
|
|
||||||
|
killsColumnWeapon = "weapon";
|
||||||
|
killsColumnDate = "date";
|
||||||
|
|
||||||
versionName = "plan_version";
|
versionName = "plan_version";
|
||||||
|
|
||||||
@ -222,6 +241,23 @@ public abstract class SQLDB extends Database {
|
|||||||
+ "FOREIGN KEY(" + nicknamesColumnUserID + ") REFERENCES " + userName + "(" + userColumnID + ")"
|
+ "FOREIGN KEY(" + nicknamesColumnUserID + ") REFERENCES " + userName + "(" + userColumnID + ")"
|
||||||
+ ")"
|
+ ")"
|
||||||
);
|
);
|
||||||
|
query("CREATE TABLE IF NOT EXISTS " + sessionName + " ("
|
||||||
|
+ sessionColumnUserID + " integer NOT NULL, "
|
||||||
|
+ sessionColumnSessionStart + " bigint NOT NULL, "
|
||||||
|
+ sessionColumnSessionEnd + " bigint NOT NULL, "
|
||||||
|
+ "FOREIGN KEY(" + sessionColumnUserID + ") REFERENCES " + userName + "(" + userColumnID + ")"
|
||||||
|
+ ")"
|
||||||
|
);
|
||||||
|
|
||||||
|
query("CREATE TABLE IF NOT EXISTS " + killsName + " ("
|
||||||
|
+ killsColumnKillerUserID + " integer NOT NULL, "
|
||||||
|
+ killsColumnVictimUserID + " integer NOT NULL, "
|
||||||
|
+ killsColumnWeapon + " varchar(30) NOT NULL, "
|
||||||
|
+ killsColumnDate + " bigint NOT NULL, "
|
||||||
|
+ "FOREIGN KEY(" + killsColumnKillerUserID + ") REFERENCES " + userName + "(" + userColumnID + "), "
|
||||||
|
+ "FOREIGN KEY(" + killsColumnVictimUserID + ") REFERENCES " + userName + "(" + userColumnID + ")"
|
||||||
|
+ ")"
|
||||||
|
);
|
||||||
|
|
||||||
query("CREATE TABLE IF NOT EXISTS " + commanduseName + " ("
|
query("CREATE TABLE IF NOT EXISTS " + commanduseName + " ("
|
||||||
+ commanduseColumnCommand + " varchar(20) NOT NULL, "
|
+ commanduseColumnCommand + " varchar(20) NOT NULL, "
|
||||||
@ -229,28 +265,41 @@ public abstract class SQLDB extends Database {
|
|||||||
+ ")"
|
+ ")"
|
||||||
);
|
);
|
||||||
|
|
||||||
query("CREATE TABLE IF NOT EXISTS " + serverdataName + " ("
|
|
||||||
+ serverdataColumnDate + " bigint NOT NULL, "
|
|
||||||
+ serverdataColumnNewPlayers + " integer NOT NULL, "
|
|
||||||
+ serverdataColumnPlayersOnline + " integer NOT NULL"
|
|
||||||
+ ")"
|
|
||||||
);
|
|
||||||
|
|
||||||
query("CREATE TABLE IF NOT EXISTS " + versionName + " ("
|
query("CREATE TABLE IF NOT EXISTS " + versionName + " ("
|
||||||
+ "version integer NOT NULL"
|
+ "version integer NOT NULL"
|
||||||
+ ")"
|
+ ")"
|
||||||
);
|
);
|
||||||
int version = getVersion();
|
int version = getVersion();
|
||||||
version = 0;
|
version = 1;
|
||||||
if (version < 1) {
|
if (version < 1) {
|
||||||
try {
|
String[] queries = new String[]{
|
||||||
query("ALTER TABLE " + userName + " ADD " + userColumnDeaths + " integer NOT NULL DEFAULT 0");
|
"ALTER TABLE " + userName + " ADD " + userColumnDeaths + " integer NOT NULL DEFAULT 0",
|
||||||
query("ALTER TABLE " + userName + " ADD " + userColumnMobKills + " integer NOT NULL DEFAULT 0");
|
"ALTER TABLE " + userName + " ADD " + userColumnMobKills + " integer NOT NULL DEFAULT 0",
|
||||||
query("ALTER TABLE " + userName + " ADD " + userColumnPlayerKills + " integer NOT NULL DEFAULT 0");
|
"ALTER TABLE " + nicknamesName + " ADD " + nicknamesColumnCurrent + " boolean NOT NULL DEFAULT (false)",
|
||||||
} catch (Exception e) {
|
"DROP TABLE IF EXISTS " + serverdataName
|
||||||
|
};
|
||||||
|
for (String query : queries) {
|
||||||
|
try {
|
||||||
|
query(query);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
setVersion(1);
|
||||||
|
} else if (version < 2) {
|
||||||
|
String[] queries = new String[]{
|
||||||
|
"ALTER TABLE " + userName + " DROP INDEX " + userColumnPlayerKills,
|
||||||
|
"ALTER TABLE " + nicknamesName + " ADD " + nicknamesColumnCurrent + " boolean NOT NULL DEFAULT 0",
|
||||||
|
"DROP TABLE IF EXISTS " + serverdataName
|
||||||
|
};
|
||||||
|
for (String query : queries) {
|
||||||
|
try {
|
||||||
|
query(query);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setVersion(2);
|
||||||
}
|
}
|
||||||
setVersion(1);
|
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -317,6 +366,7 @@ public abstract class SQLDB extends Database {
|
|||||||
return getUserId(uuid.toString()) != -1;
|
return getUserId(uuid.toString()) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getUserId(String uuid) {
|
public int getUserId(String uuid) {
|
||||||
int userId = -1;
|
int userId = -1;
|
||||||
try {
|
try {
|
||||||
@ -333,6 +383,22 @@ public abstract class SQLDB extends Database {
|
|||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private UUID getUserUUID(String userID) {
|
||||||
|
UUID uuid = null;
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = connection.prepareStatement("SELECT " + userColumnUUID + " FROM " + userName + " WHERE UPPER(" + userColumnID + ") LIKE UPPER(?)");
|
||||||
|
statement.setString(1, userID);
|
||||||
|
ResultSet set = statement.executeQuery();
|
||||||
|
while (set.next()) {
|
||||||
|
uuid = UUID.fromString(set.getString(userColumnUUID));
|
||||||
|
}
|
||||||
|
set.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> getSavedUUIDs() {
|
public Set<UUID> getSavedUUIDs() {
|
||||||
Set<UUID> uuids = new HashSet<>();
|
Set<UUID> uuids = new HashSet<>();
|
||||||
@ -349,105 +415,6 @@ public abstract class SQLDB extends Database {
|
|||||||
return uuids;
|
return uuids;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public HashMap<Long, ServerData> getServerDataHashMap() {
|
|
||||||
HashMap<String, Integer> commandUse = getCommandUse();
|
|
||||||
HashMap<Long, ServerData> rawServerData = new HashMap<>();
|
|
||||||
try {
|
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + serverdataName
|
|
||||||
+ " ORDER BY " + serverdataColumnDate + " DESC");
|
|
||||||
|
|
||||||
ResultSet set = statement.executeQuery();
|
|
||||||
while (set.next()) {
|
|
||||||
int newPlayers = set.getInt(serverdataColumnNewPlayers);
|
|
||||||
int playersOnline = set.getInt(serverdataColumnPlayersOnline);
|
|
||||||
rawServerData.put(new Date(set.getLong(serverdataColumnDate)).toInstant().getEpochSecond() * (long) 1000,
|
|
||||||
new ServerData(commandUse, newPlayers, playersOnline));
|
|
||||||
}
|
|
||||||
set.close();
|
|
||||||
statement.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return rawServerData;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ServerData getNewestServerData() {
|
|
||||||
HashMap<String, Integer> commandUse = getCommandUse();
|
|
||||||
int newPlayers = 0;
|
|
||||||
Date now = new Date();
|
|
||||||
try {
|
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + serverdataName
|
|
||||||
+ " ORDER BY " + serverdataColumnDate + " DESC LIMIT 1");
|
|
||||||
|
|
||||||
ResultSet set = statement.executeQuery();
|
|
||||||
while (set.next()) {
|
|
||||||
Date lastSave = new Date(set.getLong(serverdataColumnDate));
|
|
||||||
if (MiscUtils.isOnSameDay(now, lastSave)) {
|
|
||||||
newPlayers = set.getInt(serverdataColumnNewPlayers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set.close();
|
|
||||||
statement.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return new ServerData(commandUse, newPlayers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveServerDataHashMap(HashMap<Long, ServerData> serverData) {
|
|
||||||
try {
|
|
||||||
connection.setAutoCommit(false);
|
|
||||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO " + serverdataName + " ("
|
|
||||||
+ serverdataColumnDate + ", "
|
|
||||||
+ serverdataColumnNewPlayers + ", "
|
|
||||||
+ serverdataColumnPlayersOnline
|
|
||||||
+ ") VALUES (?, ?, ?)");
|
|
||||||
|
|
||||||
boolean commitRequired = false;
|
|
||||||
for (long date : serverData.keySet()) {
|
|
||||||
statement.setLong(1, date);
|
|
||||||
ServerData sData = serverData.get(date);
|
|
||||||
statement.setInt(2, sData.getNewPlayers());
|
|
||||||
statement.setInt(3, sData.getPlayersOnline());
|
|
||||||
statement.addBatch();
|
|
||||||
commitRequired = true;
|
|
||||||
}
|
|
||||||
statement.executeBatch();
|
|
||||||
if (commitRequired) {
|
|
||||||
connection.commit();
|
|
||||||
}
|
|
||||||
statement.close();
|
|
||||||
connection.setAutoCommit(true);
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveServerData(ServerData data) {
|
|
||||||
try {
|
|
||||||
saveCommandUse(data.getCommandUsage());
|
|
||||||
long now = new Date().toInstant().getEpochSecond() * (long) 1000;
|
|
||||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO " + serverdataName + " ("
|
|
||||||
+ serverdataColumnDate + ", "
|
|
||||||
+ serverdataColumnNewPlayers + ", "
|
|
||||||
+ serverdataColumnPlayersOnline
|
|
||||||
+ ") VALUES (?, ?, ?)");
|
|
||||||
|
|
||||||
statement.setLong(1, now);
|
|
||||||
statement.setInt(2, data.getNewPlayers());
|
|
||||||
statement.setInt(3, data.getPlayersOnline());
|
|
||||||
statement.execute();
|
|
||||||
statement.close();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
Logger.getLogger(SQLDB.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveCommandUse(HashMap<String, Integer> data) {
|
public void saveCommandUse(HashMap<String, Integer> data) {
|
||||||
try {
|
try {
|
||||||
@ -528,6 +495,15 @@ public abstract class SQLDB extends Database {
|
|||||||
statement.setString(1, "" + userId);
|
statement.setString(1, "" + userId);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
statement.close();
|
statement.close();
|
||||||
|
statement = connection.prepareStatement("DELETE FROM " + sessionName + " WHERE UPPER(" + sessionColumnUserID + ") LIKE UPPER(?)");
|
||||||
|
statement.setString(1, "" + userId);
|
||||||
|
statement.execute();
|
||||||
|
statement.close();
|
||||||
|
statement = connection.prepareStatement("DELETE FROM " + killsName + " WHERE " + killsColumnKillerUserID + " = ? OR " + killsColumnVictimUserID + " = ?");
|
||||||
|
statement.setString(1, "" + userId);
|
||||||
|
statement.setString(2, "" + userId);
|
||||||
|
statement.execute();
|
||||||
|
statement.close();
|
||||||
statement = connection.prepareStatement("DELETE FROM " + userName + " WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)");
|
statement = connection.prepareStatement("DELETE FROM " + userName + " WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)");
|
||||||
statement.setString(1, uuid);
|
statement.setString(1, uuid);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
@ -569,76 +545,33 @@ public abstract class SQLDB extends Database {
|
|||||||
data.setLastPlayed(set.getLong(userColumnLastPlayed));
|
data.setLastPlayed(set.getLong(userColumnLastPlayed));
|
||||||
data.setDeaths(set.getInt(userColumnDeaths));
|
data.setDeaths(set.getInt(userColumnDeaths));
|
||||||
data.setMobKills(set.getInt(userColumnMobKills));
|
data.setMobKills(set.getInt(userColumnMobKills));
|
||||||
data.setPlayerKills(set.getInt(userColumnPlayerKills));
|
|
||||||
}
|
}
|
||||||
set.close();
|
set.close();
|
||||||
statement.close();
|
statement.close();
|
||||||
String userId = "" + getUserId(uuid.toString());
|
String userId = "" + getUserId(uuid.toString());
|
||||||
|
|
||||||
statement = connection.prepareStatement("SELECT * FROM " + locationName + " WHERE UPPER(" + locationColumnUserID + ") LIKE UPPER(?)");
|
List<Location> locations = getLocations(userId, worlds);
|
||||||
statement.setString(1, userId);
|
|
||||||
set = statement.executeQuery();
|
|
||||||
|
|
||||||
List<Location> locations = new ArrayList<>();
|
|
||||||
while (set.next()) {
|
|
||||||
locations.add(new Location(worlds.get(set.getString(locationColumnWorld)), set.getInt(locationColumnCoordinatesX), 0, set.getInt(locationColumnCoordinatesZ)));
|
|
||||||
}
|
|
||||||
set.close();
|
|
||||||
statement.close();
|
|
||||||
data.addLocations(locations);
|
data.addLocations(locations);
|
||||||
|
|
||||||
if (locations.isEmpty()) {
|
if (locations.isEmpty()) {
|
||||||
data.setLocation(new Location(defaultWorld, 0, 0, 0));
|
data.setLocation(new Location(defaultWorld, 0, 0, 0));
|
||||||
} else {
|
} else {
|
||||||
data.setLocation(locations.get(locations.size() - 1));
|
data.setLocation(locations.get(locations.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setLocation(new Location(defaultWorld, 0, 0, 0));
|
List<String> nicknames = getNicknames(userId);
|
||||||
|
|
||||||
statement = connection.prepareStatement("SELECT * FROM " + nicknamesName + " WHERE UPPER(" + nicknamesColumnUserID + ") LIKE UPPER(?)");
|
|
||||||
statement.setString(1, userId);
|
|
||||||
set = statement.executeQuery();
|
|
||||||
|
|
||||||
List<String> nicknames = new ArrayList<>();
|
|
||||||
while (set.next()) {
|
|
||||||
nicknames.add(set.getString(nicknamesColumnNick));
|
|
||||||
}
|
|
||||||
set.close();
|
|
||||||
statement.close();
|
|
||||||
data.addNicknames(nicknames);
|
data.addNicknames(nicknames);
|
||||||
|
if (nicknames.size() > 0) {
|
||||||
statement = connection.prepareStatement("SELECT * FROM " + ipsName + " WHERE UPPER(" + ipsColumnUserID + ") LIKE UPPER(?)");
|
data.setLastNick(nicknames.get(nicknames.size() - 1));
|
||||||
statement.setString(1, userId);
|
|
||||||
set = statement.executeQuery();
|
|
||||||
|
|
||||||
List<InetAddress> ips = new ArrayList<>();
|
|
||||||
while (set.next()) {
|
|
||||||
try {
|
|
||||||
ips.add(InetAddress.getByName(set.getString(ipsColumnIP)));
|
|
||||||
} catch (SQLException | UnknownHostException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
set.close();
|
|
||||||
statement.close();
|
List<InetAddress> ips = getIPAddresses(userId);
|
||||||
data.addIpAddresses(ips);
|
data.addIpAddresses(ips);
|
||||||
|
|
||||||
statement = connection.prepareStatement("SELECT * FROM " + gamemodetimesName + " WHERE UPPER(" + gamemodetimesColumnUserID + ") LIKE UPPER(?)");
|
HashMap<GameMode, Long> times = getGMTimes(userId);
|
||||||
statement.setString(1, userId);
|
|
||||||
set = statement.executeQuery();
|
|
||||||
|
|
||||||
HashMap<GameMode, Long> times = new HashMap<>();
|
|
||||||
while (set.next()) {
|
|
||||||
times.put(GameMode.SURVIVAL, set.getLong(gamemodetimesColumnSurvivalTime));
|
|
||||||
times.put(GameMode.CREATIVE, set.getLong(gamemodetimesColumnCreativeTime));
|
|
||||||
times.put(GameMode.ADVENTURE, set.getLong(gamemodetimesColumnAdventureTime));
|
|
||||||
try {
|
|
||||||
times.put(GameMode.SPECTATOR, set.getLong(gamemodetimesColumnSpectatorTime));
|
|
||||||
} catch (NoSuchFieldError e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set.close();
|
|
||||||
statement.close();
|
|
||||||
data.setGmTimes(times);
|
data.setGmTimes(times);
|
||||||
|
|
||||||
|
data.addSessions(getSessionData(userId));
|
||||||
|
data.setPlayerKills(getPlayerKills(userId));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
data = null;
|
data = null;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -646,6 +579,120 @@ public abstract class SQLDB extends Database {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashMap<GameMode, Long> getGMTimes(String userId) throws SQLException {
|
||||||
|
PreparedStatement statement;
|
||||||
|
ResultSet set;
|
||||||
|
statement = connection.prepareStatement("SELECT * FROM " + gamemodetimesName + " WHERE UPPER(" + gamemodetimesColumnUserID + ") LIKE UPPER(?)");
|
||||||
|
statement.setString(1, userId);
|
||||||
|
set = statement.executeQuery();
|
||||||
|
HashMap<GameMode, Long> times = new HashMap<>();
|
||||||
|
while (set.next()) {
|
||||||
|
times.put(GameMode.SURVIVAL, set.getLong(gamemodetimesColumnSurvivalTime));
|
||||||
|
times.put(GameMode.CREATIVE, set.getLong(gamemodetimesColumnCreativeTime));
|
||||||
|
times.put(GameMode.ADVENTURE, set.getLong(gamemodetimesColumnAdventureTime));
|
||||||
|
try {
|
||||||
|
times.put(GameMode.SPECTATOR, set.getLong(gamemodetimesColumnSpectatorTime));
|
||||||
|
} catch (NoSuchFieldError e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set.close();
|
||||||
|
statement.close();
|
||||||
|
return times;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<InetAddress> getIPAddresses(String userId) throws SQLException {
|
||||||
|
PreparedStatement statement;
|
||||||
|
ResultSet set;
|
||||||
|
statement = connection.prepareStatement("SELECT * FROM " + ipsName + " WHERE UPPER(" + ipsColumnUserID + ") LIKE UPPER(?)");
|
||||||
|
statement.setString(1, userId);
|
||||||
|
set = statement.executeQuery();
|
||||||
|
List<InetAddress> ips = new ArrayList<>();
|
||||||
|
while (set.next()) {
|
||||||
|
try {
|
||||||
|
ips.add(InetAddress.getByName(set.getString(ipsColumnIP)));
|
||||||
|
} catch (SQLException | UnknownHostException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set.close();
|
||||||
|
statement.close();
|
||||||
|
return ips;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SessionData> getSessionData(String userId) throws SQLException {
|
||||||
|
PreparedStatement statement;
|
||||||
|
ResultSet set;
|
||||||
|
statement = connection.prepareStatement("SELECT * FROM " + sessionName + " WHERE UPPER(" + sessionColumnUserID + ") LIKE UPPER(?)");
|
||||||
|
statement.setString(1, userId);
|
||||||
|
set = statement.executeQuery();
|
||||||
|
List<SessionData> sessions = new ArrayList<>();
|
||||||
|
while (set.next()) {
|
||||||
|
try {
|
||||||
|
sessions.add(new SessionData(set.getLong(sessionColumnSessionStart), set.getLong(sessionColumnSessionEnd)));
|
||||||
|
} catch (SQLException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set.close();
|
||||||
|
statement.close();
|
||||||
|
return sessions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getNicknames(String userId) throws SQLException {
|
||||||
|
PreparedStatement statement;
|
||||||
|
ResultSet set;
|
||||||
|
statement = connection.prepareStatement("SELECT * FROM " + nicknamesName + " WHERE UPPER(" + nicknamesColumnUserID + ") LIKE UPPER(?)");
|
||||||
|
statement.setString(1, userId);
|
||||||
|
set = statement.executeQuery();
|
||||||
|
List<String> nicknames = new ArrayList<>();
|
||||||
|
String lastNick = "";
|
||||||
|
while (set.next()) {
|
||||||
|
String nickname = set.getString(nicknamesColumnNick);
|
||||||
|
if (nickname.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
nicknames.add(nickname);
|
||||||
|
if (set.getBoolean(nicknamesColumnCurrent)) {
|
||||||
|
lastNick = nickname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nicknames.remove(lastNick);
|
||||||
|
nicknames.add(lastNick);
|
||||||
|
set.close();
|
||||||
|
statement.close();
|
||||||
|
return nicknames;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Location> getLocations(String userId, HashMap<String, World> worlds) throws SQLException {
|
||||||
|
PreparedStatement statement;
|
||||||
|
ResultSet set;
|
||||||
|
statement = connection.prepareStatement("SELECT * FROM " + locationName + " WHERE UPPER(" + locationColumnUserID + ") LIKE UPPER(?)");
|
||||||
|
statement.setString(1, userId);
|
||||||
|
set = statement.executeQuery();
|
||||||
|
List<Location> locations = new ArrayList<>();
|
||||||
|
while (set.next()) {
|
||||||
|
locations.add(new Location(worlds.get(set.getString(locationColumnWorld)), set.getInt(locationColumnCoordinatesX), 0, set.getInt(locationColumnCoordinatesZ)));
|
||||||
|
}
|
||||||
|
set.close();
|
||||||
|
statement.close();
|
||||||
|
return locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<KillData> getPlayerKills(String userId) throws SQLException {
|
||||||
|
PreparedStatement statement;
|
||||||
|
ResultSet set;
|
||||||
|
statement = connection.prepareStatement("SELECT * FROM " + killsName + " WHERE UPPER(" + killsColumnKillerUserID + ") LIKE UPPER(?)");
|
||||||
|
statement.setString(1, userId);
|
||||||
|
set = statement.executeQuery();
|
||||||
|
List<KillData> killData = new ArrayList<>();
|
||||||
|
while (set.next()) {
|
||||||
|
int victimID = set.getInt(killsColumnVictimUserID);
|
||||||
|
UUID victimUUID = getUserUUID(victimID + "");
|
||||||
|
killData.add(new KillData(victimUUID, victimID, set.getString(killsColumnWeapon), set.getLong(killsColumnDate)));
|
||||||
|
}
|
||||||
|
set.close();
|
||||||
|
statement.close();
|
||||||
|
return killData;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveMultipleUserData(List<UserData> data) {
|
public void saveMultipleUserData(List<UserData> data) {
|
||||||
List<UserData> saveLast = new ArrayList<>();
|
List<UserData> saveLast = new ArrayList<>();
|
||||||
@ -659,8 +706,7 @@ public abstract class SQLDB extends Database {
|
|||||||
+ userColumnLoginTimes + "=?, "
|
+ userColumnLoginTimes + "=?, "
|
||||||
+ userColumnLastPlayed + "=?, "
|
+ userColumnLastPlayed + "=?, "
|
||||||
+ userColumnDeaths + "=?, "
|
+ userColumnDeaths + "=?, "
|
||||||
+ userColumnMobKills + "=?, "
|
+ userColumnMobKills + "=? "
|
||||||
+ userColumnPlayerKills + "=? "
|
|
||||||
+ "WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)";
|
+ "WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)";
|
||||||
try {
|
try {
|
||||||
connection.setAutoCommit(false);
|
connection.setAutoCommit(false);
|
||||||
@ -672,25 +718,28 @@ public abstract class SQLDB extends Database {
|
|||||||
saveLast.add(uData);
|
saveLast.add(uData);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
uStatement.setInt(1, uData.getDemData().getAge());
|
uStatement.setInt(1, uData.getDemData().getAge());
|
||||||
uStatement.setString(2, uData.getDemData().getGender().toString().toLowerCase());
|
uStatement.setString(2, uData.getDemData().getGender().toString().toLowerCase());
|
||||||
uStatement.setString(3, uData.getDemData().getGeoLocation());
|
uStatement.setString(3, uData.getDemData().getGeoLocation());
|
||||||
GameMode gm = uData.getLastGamemode();
|
GameMode gm = uData.getLastGamemode();
|
||||||
if (gm != null) {
|
if (gm != null) {
|
||||||
uStatement.setString(4, uData.getLastGamemode().name());
|
uStatement.setString(4, uData.getLastGamemode().name());
|
||||||
} else {
|
} else {
|
||||||
uStatement.setString(4, GameMode.SURVIVAL.name());
|
uStatement.setString(4, GameMode.SURVIVAL.name());
|
||||||
|
}
|
||||||
|
uStatement.setLong(5, uData.getLastGmSwapTime());
|
||||||
|
uStatement.setLong(6, uData.getPlayTime());
|
||||||
|
uStatement.setInt(7, uData.getLoginTimes());
|
||||||
|
uStatement.setLong(8, uData.getLastPlayed());
|
||||||
|
uStatement.setString(9, uData.getUuid().toString());
|
||||||
|
uStatement.setInt(10, uData.getDeaths());
|
||||||
|
uStatement.setInt(11, uData.getMobKills());
|
||||||
|
uStatement.addBatch();
|
||||||
|
} catch (SQLException | NullPointerException e) {
|
||||||
|
saveLast.add(uData);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
uStatement.setLong(5, uData.getLastGmSwapTime());
|
|
||||||
uStatement.setLong(6, uData.getPlayTime());
|
|
||||||
uStatement.setInt(7, uData.getLoginTimes());
|
|
||||||
uStatement.setLong(8, uData.getLastPlayed());
|
|
||||||
uStatement.setString(9, uData.getUuid().toString());
|
|
||||||
uStatement.setInt(10, uData.getDeaths());
|
|
||||||
uStatement.setInt(11, uData.getMobKills());
|
|
||||||
uStatement.setInt(12, uData.getPlayerKills());
|
|
||||||
uStatement.addBatch();
|
|
||||||
commitRequired = true;
|
commitRequired = true;
|
||||||
}
|
}
|
||||||
uStatement.executeBatch();
|
uStatement.executeBatch();
|
||||||
@ -703,8 +752,10 @@ public abstract class SQLDB extends Database {
|
|||||||
for (UserData uData : data) {
|
for (UserData uData : data) {
|
||||||
int userId = getUserId(uData.getUuid().toString());
|
int userId = getUserId(uData.getUuid().toString());
|
||||||
saveLocationList(userId, uData.getLocations());
|
saveLocationList(userId, uData.getLocations());
|
||||||
saveNickList(userId, uData.getNicknames());
|
saveNickList(userId, uData.getNicknames(), uData.getLastNick());
|
||||||
saveIPList(userId, uData.getIps());
|
saveIPList(userId, uData.getIps());
|
||||||
|
saveSessionList(userId, uData.getSessions());
|
||||||
|
savePlayerKills(userId, uData.getPlayerKills());
|
||||||
connection.setAutoCommit(true);
|
connection.setAutoCommit(true);
|
||||||
saveGMTimes(userId, uData.getGmTimes());
|
saveGMTimes(userId, uData.getGmTimes());
|
||||||
}
|
}
|
||||||
@ -734,8 +785,7 @@ public abstract class SQLDB extends Database {
|
|||||||
+ userColumnLoginTimes + "=?, "
|
+ userColumnLoginTimes + "=?, "
|
||||||
+ userColumnLastPlayed + "=?, "
|
+ userColumnLastPlayed + "=?, "
|
||||||
+ userColumnDeaths + "=?, "
|
+ userColumnDeaths + "=?, "
|
||||||
+ userColumnMobKills + "=?, "
|
+ userColumnMobKills + "=? "
|
||||||
+ userColumnPlayerKills + "=? "
|
|
||||||
+ "WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)";
|
+ "WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)";
|
||||||
|
|
||||||
PreparedStatement statement = connection.prepareStatement(sql);
|
PreparedStatement statement = connection.prepareStatement(sql);
|
||||||
@ -755,7 +805,6 @@ public abstract class SQLDB extends Database {
|
|||||||
statement.setString(9, uuid.toString());
|
statement.setString(9, uuid.toString());
|
||||||
statement.setInt(10, data.getDeaths());
|
statement.setInt(10, data.getDeaths());
|
||||||
statement.setInt(11, data.getMobKills());
|
statement.setInt(11, data.getMobKills());
|
||||||
statement.setInt(12, data.getPlayerKills());
|
|
||||||
update = statement.executeUpdate();
|
update = statement.executeUpdate();
|
||||||
}
|
}
|
||||||
if (update == 0) {
|
if (update == 0) {
|
||||||
@ -770,9 +819,8 @@ public abstract class SQLDB extends Database {
|
|||||||
+ userColumnLoginTimes + ", "
|
+ userColumnLoginTimes + ", "
|
||||||
+ userColumnLastPlayed + ", "
|
+ userColumnLastPlayed + ", "
|
||||||
+ userColumnDeaths + ", "
|
+ userColumnDeaths + ", "
|
||||||
+ userColumnMobKills + ", "
|
+ userColumnMobKills
|
||||||
+ userColumnPlayerKills
|
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
||||||
|
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
statement.setInt(2, data.getDemData().getAge());
|
statement.setInt(2, data.getDemData().getAge());
|
||||||
@ -790,15 +838,16 @@ public abstract class SQLDB extends Database {
|
|||||||
statement.setLong(9, data.getLastPlayed());
|
statement.setLong(9, data.getLastPlayed());
|
||||||
statement.setInt(10, data.getDeaths());
|
statement.setInt(10, data.getDeaths());
|
||||||
statement.setInt(11, data.getMobKills());
|
statement.setInt(11, data.getMobKills());
|
||||||
statement.setInt(12, data.getPlayerKills());
|
|
||||||
|
|
||||||
statement.execute();
|
statement.execute();
|
||||||
statement.close();
|
statement.close();
|
||||||
userId = getUserId(uuid.toString());
|
userId = getUserId(uuid.toString());
|
||||||
}
|
}
|
||||||
saveLocationList(userId, data.getLocations());
|
saveLocationList(userId, data.getLocations());
|
||||||
saveNickList(userId, data.getNicknames());
|
saveNickList(userId, data.getNicknames(), data.getLastNick());
|
||||||
saveIPList(userId, data.getIps());
|
saveIPList(userId, data.getIps());
|
||||||
|
saveSessionList(userId, data.getSessions());
|
||||||
|
savePlayerKills(userId, data.getPlayerKills());
|
||||||
connection.setAutoCommit(true);
|
connection.setAutoCommit(true);
|
||||||
saveGMTimes(userId, data.getGmTimes());
|
saveGMTimes(userId, data.getGmTimes());
|
||||||
} catch (SQLException | NullPointerException e) {
|
} catch (SQLException | NullPointerException e) {
|
||||||
@ -847,7 +896,7 @@ public abstract class SQLDB extends Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveNickList(int userId, HashSet<String> names) {
|
public void saveNickList(int userId, HashSet<String> names, String lastNick) {
|
||||||
try {
|
try {
|
||||||
PreparedStatement statement = connection.prepareStatement(
|
PreparedStatement statement = connection.prepareStatement(
|
||||||
"DELETE FROM " + nicknamesName + " WHERE UPPER(" + nicknamesColumnUserID + ") LIKE UPPER(?)");
|
"DELETE FROM " + nicknamesName + " WHERE UPPER(" + nicknamesColumnUserID + ") LIKE UPPER(?)");
|
||||||
@ -857,12 +906,80 @@ public abstract class SQLDB extends Database {
|
|||||||
connection.setAutoCommit(false);
|
connection.setAutoCommit(false);
|
||||||
statement = connection.prepareStatement("INSERT INTO " + nicknamesName + " ("
|
statement = connection.prepareStatement("INSERT INTO " + nicknamesName + " ("
|
||||||
+ nicknamesColumnUserID + ", "
|
+ nicknamesColumnUserID + ", "
|
||||||
|
+ nicknamesColumnCurrent + ", "
|
||||||
+ nicknamesColumnNick
|
+ nicknamesColumnNick
|
||||||
+ ") VALUES (?, ?)");
|
+ ") VALUES (?, ?, ?)");
|
||||||
boolean commitRequired = false;
|
boolean commitRequired = false;
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
statement.setInt(1, userId);
|
statement.setInt(1, userId);
|
||||||
statement.setString(2, name);
|
statement.setInt(2, (name.equals(lastNick)) ? 1 : 0);
|
||||||
|
statement.setString(3, name);
|
||||||
|
statement.addBatch();
|
||||||
|
commitRequired = true;
|
||||||
|
}
|
||||||
|
statement.executeBatch();
|
||||||
|
if (commitRequired) {
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
statement.close();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveSessionList(int userId, List<SessionData> sessions) {
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = connection.prepareStatement(
|
||||||
|
"DELETE FROM " + sessionName + " WHERE UPPER(" + sessionColumnUserID + ") LIKE UPPER(?)");
|
||||||
|
statement.setString(1, "" + userId);
|
||||||
|
statement.execute();
|
||||||
|
|
||||||
|
connection.setAutoCommit(false);
|
||||||
|
statement = connection.prepareStatement("INSERT INTO " + sessionName + " ("
|
||||||
|
+ sessionColumnUserID + ", "
|
||||||
|
+ sessionColumnSessionStart + ", "
|
||||||
|
+ sessionColumnSessionEnd
|
||||||
|
+ ") VALUES (?, ?, ?)");
|
||||||
|
boolean commitRequired = false;
|
||||||
|
for (SessionData session : sessions) {
|
||||||
|
statement.setInt(1, userId);
|
||||||
|
statement.setLong(2, session.getSessionStart());
|
||||||
|
statement.setLong(3, session.getSessionEnd());
|
||||||
|
statement.addBatch();
|
||||||
|
commitRequired = true;
|
||||||
|
}
|
||||||
|
statement.executeBatch();
|
||||||
|
if (commitRequired) {
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
statement.close();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void savePlayerKills(int userId, List<KillData> kills) {
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = connection.prepareStatement(
|
||||||
|
"DELETE FROM " + killsName + " WHERE UPPER(" + killsColumnKillerUserID + ") LIKE UPPER(?)");
|
||||||
|
statement.setString(1, "" + userId);
|
||||||
|
statement.execute();
|
||||||
|
|
||||||
|
connection.setAutoCommit(false);
|
||||||
|
statement = connection.prepareStatement("INSERT INTO " + killsName + " ("
|
||||||
|
+ killsColumnKillerUserID + ", "
|
||||||
|
+ killsColumnVictimUserID + ", "
|
||||||
|
+ killsColumnWeapon + ", "
|
||||||
|
+ killsColumnDate
|
||||||
|
+ ") VALUES (?, ?, ?, ?)");
|
||||||
|
boolean commitRequired = false;
|
||||||
|
for (KillData kill : kills) {
|
||||||
|
statement.setInt(1, userId);
|
||||||
|
statement.setInt(2, kill.getVictimUserID());
|
||||||
|
statement.setString(2, kill.getWeapon());
|
||||||
|
statement.setLong(4, kill.getDate());
|
||||||
statement.addBatch();
|
statement.addBatch();
|
||||||
commitRequired = true;
|
commitRequired = true;
|
||||||
}
|
}
|
||||||
@ -949,7 +1066,11 @@ public abstract class SQLDB extends Database {
|
|||||||
@Override
|
@Override
|
||||||
public void clean() {
|
public void clean() {
|
||||||
checkConnection();
|
checkConnection();
|
||||||
plugin.log("Database Cleaning has not yet been implemented.");
|
try {
|
||||||
|
query("DROP TABLE " + serverdataName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -957,140 +1078,19 @@ public abstract class SQLDB extends Database {
|
|||||||
checkConnection();
|
checkConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection.prepareStatement("DELETE FROM " + locationName).executeUpdate();
|
query("DROP TABLE " + locationName);
|
||||||
connection.prepareStatement("DELETE FROM " + nicknamesName).executeUpdate();
|
query("DROP TABLE " + ipsName);
|
||||||
connection.prepareStatement("DELETE FROM " + ipsName).executeUpdate();
|
query("DROP TABLE " + gamemodetimesName);
|
||||||
connection.prepareStatement("DELETE FROM " + gamemodetimesName).executeUpdate();
|
query("DROP TABLE " + nicknamesName);
|
||||||
connection.prepareStatement("DELETE FROM " + commanduseName).executeUpdate();
|
query("DROP TABLE " + killsName);
|
||||||
connection.prepareStatement("DELETE FROM " + serverdataName).executeUpdate();
|
query("DROP TABLE " + sessionName);
|
||||||
connection.prepareStatement("DELETE FROM " + userName).executeUpdate();
|
query("DROP TABLE " + commanduseName);
|
||||||
|
query("DROP TABLE " + userName);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters ---
|
|
||||||
public void setUserName(String userName) {
|
|
||||||
this.userName = userName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocationName(String locationName) {
|
|
||||||
this.locationName = locationName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServerdataName(String serverdataName) {
|
|
||||||
this.serverdataName = serverdataName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommanduseName(String commanduseName) {
|
|
||||||
this.commanduseName = commanduseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGamemodetimesName(String gamemodetimesName) {
|
|
||||||
this.gamemodetimesName = gamemodetimesName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNicknamesName(String nicknamesName) {
|
|
||||||
this.nicknamesName = nicknamesName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIpsName(String ipsName) {
|
|
||||||
this.ipsName = ipsName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserColumnUUID(String userColumnUUID) {
|
|
||||||
this.userColumnUUID = userColumnUUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserColumnPlayTime(String userColumnPlayTime) {
|
|
||||||
this.userColumnPlayTime = userColumnPlayTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserColumnDemGeoLocation(String userColumnDemGeoLocation) {
|
|
||||||
this.userColumnDemGeoLocation = userColumnDemGeoLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserColumnDemAge(String userColumnDemAge) {
|
|
||||||
this.userColumnDemAge = userColumnDemAge;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserColumnDemGender(String userColumnDemGender) {
|
|
||||||
this.userColumnDemGender = userColumnDemGender;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserColumnLastGM(String userColumnLastGM) {
|
|
||||||
this.userColumnLastGM = userColumnLastGM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserColumnLastGMSwapTime(String userColumnLastGMSwapTime) {
|
|
||||||
this.userColumnLastGMSwapTime = userColumnLastGMSwapTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocationColumnCoordinatesZ(String locationColumnCoordinates) {
|
|
||||||
this.locationColumnCoordinatesZ = locationColumnCoordinates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocationColumnCoordinatesX(String locationColumnCoordinates) {
|
|
||||||
this.locationColumnCoordinatesX = locationColumnCoordinates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocationColumnWorld(String locationColumnWorld) {
|
|
||||||
this.locationColumnWorld = locationColumnWorld;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServerdataColumnDate(String serverdataColumnDate) {
|
|
||||||
this.serverdataColumnDate = serverdataColumnDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServerdataColumnPlayersOnline(String serverdataColumnPlayersOnline) {
|
|
||||||
this.serverdataColumnPlayersOnline = serverdataColumnPlayersOnline;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServerdataColumnNewPlayers(String serverdataColumnNewPlayers) {
|
|
||||||
this.serverdataColumnNewPlayers = serverdataColumnNewPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommanduseColumnCommand(String commanduseColumnCommand) {
|
|
||||||
this.commanduseColumnCommand = commanduseColumnCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCommanduseColumnTimesUsed(String commanduseColumnTimesUsed) {
|
|
||||||
this.commanduseColumnTimesUsed = commanduseColumnTimesUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserColumnLoginTimes(String userColumnLoginTimes) {
|
|
||||||
this.userColumnLoginTimes = userColumnLoginTimes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGamemodetimesColumnSurvivalTime(String gamemodetimesColumnSurvivalTime) {
|
|
||||||
this.gamemodetimesColumnSurvivalTime = gamemodetimesColumnSurvivalTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGamemodetimesColumnCreativeTime(String gamemodetimesColumnCreativeTime) {
|
|
||||||
this.gamemodetimesColumnCreativeTime = gamemodetimesColumnCreativeTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGamemodetimesColumnAdventureTime(String gamemodetimesColumnAdventureTime) {
|
|
||||||
this.gamemodetimesColumnAdventureTime = gamemodetimesColumnAdventureTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGamemodetimesColumnSpectatorTime(String gamemodetimesColumnSpectatorTime) {
|
|
||||||
this.gamemodetimesColumnSpectatorTime = gamemodetimesColumnSpectatorTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNicknamesColumnUserID(String nicknamesColumnUserID) {
|
|
||||||
this.nicknamesColumnUserID = nicknamesColumnUserID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNicknamesColumnNick(String nicknamesColumnNick) {
|
|
||||||
this.nicknamesColumnNick = nicknamesColumnNick;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIpsColumnIP(String ipsColumnIP) {
|
|
||||||
this.ipsColumnIP = ipsColumnIP;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters
|
|
||||||
public boolean supportsModification() {
|
public boolean supportsModification() {
|
||||||
return supportsModification;
|
return supportsModification;
|
||||||
}
|
}
|
||||||
|
@ -53,11 +53,6 @@ public class SQLiteDB extends SQLDB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getConfigDefaults(ConfigurationSection section) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "SQLite";
|
return "SQLite";
|
||||||
|
@ -2,7 +2,6 @@ package main.java.com.djrapitops.plan.ui.graphs;
|
|||||||
|
|
||||||
import com.djrapitops.plan.Phrase;
|
import com.djrapitops.plan.Phrase;
|
||||||
import com.djrapitops.plan.Plan;
|
import com.djrapitops.plan.Plan;
|
||||||
import com.djrapitops.plan.data.ServerData;
|
|
||||||
import com.djrapitops.plan.utilities.FormatUtils;
|
import com.djrapitops.plan.utilities.FormatUtils;
|
||||||
import com.googlecode.charts4j.AxisLabels;
|
import com.googlecode.charts4j.AxisLabels;
|
||||||
import com.googlecode.charts4j.AxisLabelsFactory;
|
import com.googlecode.charts4j.AxisLabelsFactory;
|
||||||
@ -14,8 +13,8 @@ import com.googlecode.charts4j.Plots;
|
|||||||
import com.googlecode.charts4j.XYLine;
|
import com.googlecode.charts4j.XYLine;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import main.java.com.djrapitops.plan.data.SessionData;
|
||||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,12 +26,19 @@ public class PlayerActivityGraphCreator {
|
|||||||
/**
|
/**
|
||||||
* Creates a new url for a PlayerActivity graph.
|
* Creates a new url for a PlayerActivity graph.
|
||||||
*
|
*
|
||||||
* @param rawServerData HashMap of all ServerData
|
* @param sessionData SessionData of Players in scale.
|
||||||
* @param scale Long in ms, time the graph will be limited to.
|
* @param scale Long in ms, time the graph will be limited to.
|
||||||
* @return Url of charts4j image link.
|
* @return Url of charts4j image link.
|
||||||
*/
|
*/
|
||||||
public static String createChart(HashMap<Long, ServerData> rawServerData, long scale) {
|
public static String createChart(List<SessionData> sessionData, long scale) {
|
||||||
|
|
||||||
|
List<Long> sessionStarts = new ArrayList<>();
|
||||||
|
List<Long> sessionEnds = new ArrayList<>();
|
||||||
|
sessionData.parallelStream().forEach(
|
||||||
|
(session) -> {
|
||||||
|
sessionEnds.add(session.getSessionEnd());
|
||||||
|
sessionStarts.add(session.getSessionStart());
|
||||||
|
});
|
||||||
List<Double> xListDate = new ArrayList<>();
|
List<Double> xListDate = new ArrayList<>();
|
||||||
List<Double> pYList = new ArrayList<>();
|
List<Double> pYList = new ArrayList<>();
|
||||||
|
|
||||||
@ -48,14 +54,28 @@ public class PlayerActivityGraphCreator {
|
|||||||
int lastSavedPValue = -1;
|
int lastSavedPValue = -1;
|
||||||
long lastSaveI = 0;
|
long lastSaveI = 0;
|
||||||
for (long i = nowMinusScale; i <= now; i += 1000) {
|
for (long i = nowMinusScale; i <= now; i += 1000) {
|
||||||
if (rawServerData.containsKey(i)) {
|
if (sessionStarts.contains(i)) {
|
||||||
ServerData serverData = rawServerData.get(i);
|
int amount = 0;
|
||||||
lastPValue = serverData.getPlayersOnline();
|
for (long start : sessionStarts) {
|
||||||
|
if (start == i) {
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastPValue += amount;
|
||||||
|
}
|
||||||
|
if (sessionEnds.contains(i)) {
|
||||||
|
int amount = 0;
|
||||||
|
for (long end : sessionEnds) {
|
||||||
|
if (end == i) {
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastPValue -= amount;
|
||||||
}
|
}
|
||||||
Double scaledDateValue = ((i - nowMinusScale) * 1.0 / scale) * 100;
|
Double scaledDateValue = ((i - nowMinusScale) * 1.0 / scale) * 100;
|
||||||
Double scaledPlayerValue = (lastPValue * 1.0 / maxPlayers) * 100;
|
Double scaledPlayerValue = (lastPValue * 1.0 / maxPlayers) * 100;
|
||||||
|
|
||||||
if (lastSavedPValue != lastPValue || i - lastSaveI > (scale / (long) 50)) {
|
if (lastSavedPValue != lastPValue || i - lastSaveI > (scale / (long) 100)) {
|
||||||
lastSaveI = i;
|
lastSaveI = i;
|
||||||
xListDate.add(scaledDateValue);
|
xListDate.add(scaledDateValue);
|
||||||
pYList.add((lastSavedPValue * 1.0 / maxPlayers) * 100);
|
pYList.add((lastSavedPValue * 1.0 / maxPlayers) * 100);
|
||||||
|
@ -4,12 +4,10 @@ import com.djrapitops.plan.Phrase;
|
|||||||
import com.djrapitops.plan.Plan;
|
import com.djrapitops.plan.Plan;
|
||||||
import com.djrapitops.plan.PlanLiteHook;
|
import com.djrapitops.plan.PlanLiteHook;
|
||||||
import com.djrapitops.plan.data.AnalysisData;
|
import com.djrapitops.plan.data.AnalysisData;
|
||||||
import com.djrapitops.plan.data.ServerData;
|
|
||||||
import com.djrapitops.plan.data.UserData;
|
import com.djrapitops.plan.data.UserData;
|
||||||
import com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
import com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||||
import com.djrapitops.plan.data.cache.InspectCacheHandler;
|
import com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -18,6 +16,7 @@ import java.util.UUID;
|
|||||||
import main.java.com.djrapitops.plan.Settings;
|
import main.java.com.djrapitops.plan.Settings;
|
||||||
import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData;
|
import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData;
|
||||||
import main.java.com.djrapitops.plan.data.RawAnalysisData;
|
import main.java.com.djrapitops.plan.data.RawAnalysisData;
|
||||||
|
import main.java.com.djrapitops.plan.data.SessionData;
|
||||||
import main.java.com.djrapitops.plan.ui.Html;
|
import main.java.com.djrapitops.plan.ui.Html;
|
||||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -34,7 +33,6 @@ public class Analysis {
|
|||||||
private final Plan plugin;
|
private final Plan plugin;
|
||||||
private final InspectCacheHandler inspectCache;
|
private final InspectCacheHandler inspectCache;
|
||||||
private final List<UserData> rawData;
|
private final List<UserData> rawData;
|
||||||
private HashMap<Long, ServerData> rawServerData;
|
|
||||||
private final List<UUID> added;
|
private final List<UUID> added;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,12 +88,9 @@ public class Analysis {
|
|||||||
// Create empty Dataset
|
// Create empty Dataset
|
||||||
final RawAnalysisData raw = new RawAnalysisData();
|
final RawAnalysisData raw = new RawAnalysisData();
|
||||||
raw.setCommandUse(plugin.getDB().getCommandUse());
|
raw.setCommandUse(plugin.getDB().getCommandUse());
|
||||||
rawServerData = plugin.getDB().getServerDataHashMap();
|
|
||||||
log(Phrase.ANALYSIS_BEGIN_ANALYSIS + "");
|
log(Phrase.ANALYSIS_BEGIN_ANALYSIS + "");
|
||||||
AnalysisData data = new AnalysisData();
|
AnalysisData data = new AnalysisData();
|
||||||
|
|
||||||
createPlayerActivityGraphs(data);
|
|
||||||
|
|
||||||
// DEPRECATED - WILL BE REMOVED
|
// DEPRECATED - WILL BE REMOVED
|
||||||
boolean planLiteEnabled = isPlanLiteEnabled();
|
boolean planLiteEnabled = isPlanLiteEnabled();
|
||||||
PlanLiteAnalyzedData plData = new PlanLiteAnalyzedData();
|
PlanLiteAnalyzedData plData = new PlanLiteAnalyzedData();
|
||||||
@ -142,16 +137,19 @@ public class Analysis {
|
|||||||
} else {
|
} else {
|
||||||
raw.addInactive(1);
|
raw.addInactive(1);
|
||||||
}
|
}
|
||||||
raw.addTotalKills(uData.getPlayerKills());
|
raw.addTotalKills(uData.getPlayerKills().size());
|
||||||
raw.addTotalMobKills(uData.getMobKills());
|
raw.addTotalMobKills(uData.getMobKills());
|
||||||
raw.addTotalDeaths(uData.getDeaths());
|
raw.addTotalDeaths(uData.getDeaths());
|
||||||
raw.getSessiondata().addAll(uData.getSessions());
|
raw.getSessiondata().addAll(uData.getSessions());
|
||||||
|
raw.getRegistered().add(uData.getRegistered());
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
plugin.logError(Phrase.DATA_CORRUPTION_WARN.parse(uData.getUuid() + ""));
|
plugin.logError(Phrase.DATA_CORRUPTION_WARN.parse(uData.getUuid() + ""));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Analyze & Save RawAnalysisData to AnalysisData
|
// Analyze & Save RawAnalysisData to AnalysisData
|
||||||
|
createPlayerActivityGraphs(data, raw.getSessiondata(), raw.getRegistered());
|
||||||
|
|
||||||
data.setTop20ActivePlayers(AnalysisUtils.createActivePlayersTable(raw.getPlaytimes(), 20));
|
data.setTop20ActivePlayers(AnalysisUtils.createActivePlayersTable(raw.getPlaytimes(), 20));
|
||||||
data.setRecentPlayers(AnalysisUtils.createListStringOutOfHashMapLong(raw.getLatestLogins(), 20));
|
data.setRecentPlayers(AnalysisUtils.createListStringOutOfHashMapLong(raw.getLatestLogins(), 20));
|
||||||
|
|
||||||
@ -254,64 +252,20 @@ public class Analysis {
|
|||||||
data.setGm3Perc((gmThree * 1.0 / gmTotal));
|
data.setGm3Perc((gmThree * 1.0 / gmTotal));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createPlayerActivityGraphs(AnalysisData data) {
|
private void createPlayerActivityGraphs(AnalysisData data, List<SessionData> sData, List<Long> registered) {
|
||||||
|
long now = new Date().toInstant().getEpochSecond() * (long) 1000;
|
||||||
long scaleMonth = (long) 2592000 * (long) 1000;
|
long scaleMonth = (long) 2592000 * (long) 1000;
|
||||||
String playerActivityHtmlMonth = AnalysisUtils.createPlayerActivityGraph(rawServerData, scaleMonth);
|
String[] urlAndNumber = AnalysisUtils.analyzeSessionData(sData, registered, scaleMonth, now);
|
||||||
data.setPlayersChartImgHtmlMonth(playerActivityHtmlMonth);
|
data.setPlayersChartImgHtmlMonth(urlAndNumber[0]);
|
||||||
data.setNewPlayersMonth(getHighestNPValueForScale(scaleMonth));
|
data.setNewPlayersMonth(Integer.parseInt(urlAndNumber[1]));
|
||||||
long scaleWeek = 604800 * 1000;
|
long scaleWeek = 604800 * 1000;
|
||||||
String playerActivityHtmlWeek = AnalysisUtils.createPlayerActivityGraph(rawServerData, scaleWeek);
|
urlAndNumber = AnalysisUtils.analyzeSessionData(sData, registered, scaleWeek, now);
|
||||||
data.setPlayersChartImgHtmlWeek(playerActivityHtmlWeek);
|
data.setPlayersChartImgHtmlWeek(urlAndNumber[0]);
|
||||||
data.setNewPlayersWeek(getHighestNPValueForScale(scaleWeek));
|
data.setNewPlayersWeek(Integer.parseInt(urlAndNumber[1]));
|
||||||
long scaleDay = 86400 * 1000;
|
long scaleDay = 86400 * 1000;
|
||||||
String playerActivityHtmlDay = AnalysisUtils.createPlayerActivityGraph(rawServerData, scaleDay);
|
urlAndNumber = AnalysisUtils.analyzeSessionData(sData, registered, scaleDay, now);
|
||||||
data.setPlayersChartImgHtmlDay(playerActivityHtmlDay);
|
data.setPlayersChartImgHtmlDay(urlAndNumber[0]);
|
||||||
data.setNewPlayersDay(getHighestNPValueForScale(scaleDay));
|
data.setNewPlayersDay(Integer.parseInt(urlAndNumber[1]));
|
||||||
}
|
|
||||||
|
|
||||||
private int getHighestNPValueForScale(long scale) {
|
|
||||||
List<List<ServerData>> sDataForEachDay = sortServerDatasByDay(scale);
|
|
||||||
int NPTotalInsideScaleTimeFrame = 0;
|
|
||||||
NPTotalInsideScaleTimeFrame = sDataForEachDay.parallelStream()
|
|
||||||
.map((serverDataList) -> {
|
|
||||||
int highestNPValue = 0;
|
|
||||||
for (ServerData serverData : serverDataList) {
|
|
||||||
int newPlayers = serverData.getNewPlayers();
|
|
||||||
if (newPlayers > highestNPValue) {
|
|
||||||
highestNPValue = newPlayers;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return highestNPValue;
|
|
||||||
}).map((highestNPValue) -> highestNPValue)
|
|
||||||
.reduce(NPTotalInsideScaleTimeFrame, Integer::sum);
|
|
||||||
return NPTotalInsideScaleTimeFrame;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<List<ServerData>> sortServerDatasByDay(long scale) {
|
|
||||||
List<List<ServerData>> sDataForEachDay = new ArrayList<>();
|
|
||||||
Date lastStartOfDay = null;
|
|
||||||
List<Long> keys = new ArrayList<>();
|
|
||||||
keys.addAll(rawServerData.keySet());
|
|
||||||
Collections.sort(keys);
|
|
||||||
for (long date : keys) {
|
|
||||||
Date startOfDate = MiscUtils.getStartOfDate(new Date(date));
|
|
||||||
if (lastStartOfDay == null) {
|
|
||||||
sDataForEachDay.add(new ArrayList<>());
|
|
||||||
lastStartOfDay = startOfDate;
|
|
||||||
}
|
|
||||||
// If data is older than one month, ignore
|
|
||||||
if (new Date().getTime() - startOfDate.getTime() > scale) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (startOfDate.getTime() != lastStartOfDay.getTime()) {
|
|
||||||
sDataForEachDay.add(new ArrayList<>());
|
|
||||||
}
|
|
||||||
int lastIndex = sDataForEachDay.size() - 1;
|
|
||||||
ServerData serverData = rawServerData.get(date);
|
|
||||||
sDataForEachDay.get(lastIndex).add(serverData);
|
|
||||||
lastStartOfDay = startOfDate;
|
|
||||||
}
|
|
||||||
return sDataForEachDay;
|
|
||||||
}
|
}
|
||||||
}).runTaskAsynchronously(plugin);
|
}).runTaskAsynchronously(plugin);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package com.djrapitops.plan.utilities;
|
package com.djrapitops.plan.utilities;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.ServerData;
|
|
||||||
import com.djrapitops.plan.ui.graphs.GMTimesPieChartCreator;
|
import com.djrapitops.plan.ui.graphs.GMTimesPieChartCreator;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import main.java.com.djrapitops.plan.Settings;
|
import main.java.com.djrapitops.plan.Settings;
|
||||||
|
import main.java.com.djrapitops.plan.data.SessionData;
|
||||||
import main.java.com.djrapitops.plan.ui.Html;
|
import main.java.com.djrapitops.plan.ui.Html;
|
||||||
import main.java.com.djrapitops.plan.ui.graphs.ActivityPieChartCreator;
|
import main.java.com.djrapitops.plan.ui.graphs.ActivityPieChartCreator;
|
||||||
import main.java.com.djrapitops.plan.ui.graphs.PlayerActivityGraphCreator;
|
import main.java.com.djrapitops.plan.ui.graphs.PlayerActivityGraphCreator;
|
||||||
@ -45,13 +46,11 @@ public class AnalysisUtils {
|
|||||||
return Html.IMG.parse(url);
|
return Html.IMG.parse(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String createPlayerActivityGraph(List<SessionData> sessionData, long scale) {
|
||||||
static String createPlayerActivityGraph(HashMap<Long, ServerData> rawServerData, long scale) {
|
String url = PlayerActivityGraphCreator.createChart(sessionData, scale);
|
||||||
String url = PlayerActivityGraphCreator.createChart(rawServerData, scale);
|
|
||||||
return Html.IMG.parse(url);
|
return Html.IMG.parse(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static boolean isActive(long lastPlayed, long playTime, int loginTimes) {
|
static boolean isActive(long lastPlayed, long playTime, int loginTimes) {
|
||||||
int timeToActive = Settings.ANALYSIS_MINUTES_FOR_ACTIVE.getNumber();
|
int timeToActive = Settings.ANALYSIS_MINUTES_FOR_ACTIVE.getNumber();
|
||||||
if (timeToActive < 0) {
|
if (timeToActive < 0) {
|
||||||
@ -108,4 +107,23 @@ public class AnalysisUtils {
|
|||||||
html += "</p>";
|
html += "</p>";
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String[] analyzeSessionData(List<SessionData> sessionData, List<Long> registered, long scale, long now) {
|
||||||
|
String[] returnA = new String[2];
|
||||||
|
List<SessionData> inScale = new ArrayList<>();
|
||||||
|
sessionData.stream()
|
||||||
|
.filter((s) -> (s.getSessionStart() > now - scale))
|
||||||
|
.forEach((s) -> {
|
||||||
|
inScale.add(s);
|
||||||
|
});
|
||||||
|
returnA[0] = createPlayerActivityGraph(inScale, scale);
|
||||||
|
|
||||||
|
int newPlayers = 0;
|
||||||
|
// Filters out register dates before scale
|
||||||
|
newPlayers = registered.stream()
|
||||||
|
.filter((reg) -> (reg > now - scale))
|
||||||
|
.map((_item) -> 1).reduce(newPlayers, Integer::sum);
|
||||||
|
returnA[1] = "" + newPlayers;
|
||||||
|
return returnA;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package main.java.com.djrapitops.plan.utilities;
|
|||||||
|
|
||||||
import com.djrapitops.plan.Phrase;
|
import com.djrapitops.plan.Phrase;
|
||||||
import com.djrapitops.plan.data.DemographicsData;
|
import com.djrapitops.plan.data.DemographicsData;
|
||||||
import com.djrapitops.plan.data.ServerData;
|
|
||||||
import com.djrapitops.plan.data.UserData;
|
import com.djrapitops.plan.data.UserData;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -77,34 +76,6 @@ public class DataCombineUtils {
|
|||||||
return fData;
|
return fData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Combines two conflicting ServerDatasets
|
|
||||||
*
|
|
||||||
* @param fData First Dataset
|
|
||||||
* @param tData Second Dataset
|
|
||||||
* @return Combined ServerDataset
|
|
||||||
*/
|
|
||||||
public static HashMap<Long, ServerData> combineServerDatas(HashMap<Long, ServerData> fData, HashMap<Long, ServerData> tData) {
|
|
||||||
HashMap<Long, ServerData> combinedData = new HashMap<>();
|
|
||||||
Set<Long> allDates = new HashSet<>();
|
|
||||||
allDates.addAll(fData.keySet());
|
|
||||||
allDates.addAll(tData.keySet());
|
|
||||||
allDates.parallelStream().forEach((Long date) -> {
|
|
||||||
ServerData fServerData = fData.get(date);
|
|
||||||
ServerData tServerData = tData.get(date);
|
|
||||||
if (fServerData == null) {
|
|
||||||
combinedData.put(date, tServerData);
|
|
||||||
} else if (tServerData == null) {
|
|
||||||
combinedData.put(date, fServerData);
|
|
||||||
} else if (fServerData.getPlayersOnline() > tServerData.getPlayersOnline()) {
|
|
||||||
combinedData.put(date, fServerData);
|
|
||||||
} else {
|
|
||||||
combinedData.put(date, tServerData);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return combinedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines Two conflicting command usage datasets.
|
* Combines Two conflicting command usage datasets.
|
||||||
*
|
*
|
||||||
@ -141,18 +112,4 @@ public class DataCombineUtils {
|
|||||||
}
|
}
|
||||||
return combinedData;
|
return combinedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String, Integer> getCommandUse(HashMap<Long, ServerData> fromServerData) {
|
|
||||||
ServerData sData = null;
|
|
||||||
for (long sDataKey : fromServerData.keySet()) {
|
|
||||||
sData = fromServerData.get(sDataKey);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
HashMap<String, Integer> fromCommandUse = null;
|
|
||||||
if (sData != null) {
|
|
||||||
fromCommandUse = sData.getCommandUsage();
|
|
||||||
}
|
|
||||||
return fromCommandUse;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,11 +62,3 @@ mysql:
|
|||||||
user: root
|
user: root
|
||||||
password: minecraft
|
password: minecraft
|
||||||
database: Plan
|
database: Plan
|
||||||
tables:
|
|
||||||
users: plan_users
|
|
||||||
locations: plan_locations
|
|
||||||
nicknames: plan_nicknames
|
|
||||||
gamemodetimes: plan_gamemodetimes
|
|
||||||
ips: plan_ips
|
|
||||||
commandusages: plan_commandusages
|
|
||||||
serverdata: plan_serverdata
|
|
||||||
|
Loading…
Reference in New Issue
Block a user