mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-05 15:02:26 +01:00
Merge branch '4.0.0-BungeeCord-Support' of https://github.com/Rsl1122/Plan-PlayerAnalytics
This commit is contained in:
commit
6949ca9ee9
@ -37,6 +37,7 @@ import main.java.com.djrapitops.plan.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.locale.Msg;
|
||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||
import main.java.com.djrapitops.plan.systems.cache.PageCache;
|
||||
import main.java.com.djrapitops.plan.systems.info.InformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.info.server.ServerInfoManager;
|
||||
import main.java.com.djrapitops.plan.systems.listeners.*;
|
||||
import main.java.com.djrapitops.plan.systems.processing.Processor;
|
||||
@ -73,7 +74,6 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
private API api;
|
||||
|
||||
private ProcessingQueue processingQueue;
|
||||
private DataCache dataCache;
|
||||
private HookHandler hookHandler; // Manages 3rd party data sources
|
||||
|
||||
private Database db;
|
||||
@ -81,6 +81,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
|
||||
private WebServer uiServer;
|
||||
|
||||
private InformationManager infoManager;
|
||||
private ServerInfoManager serverInfoManager;
|
||||
|
||||
private ServerVariableHolder serverVariableHolder;
|
||||
@ -158,15 +159,6 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
}
|
||||
Benchmark.stop("Enable", "Init Database");
|
||||
|
||||
Benchmark.start("Init DataCache");
|
||||
this.dataCache = new DataCache(this);
|
||||
Benchmark.stop("Enable", "Init DataCache");
|
||||
|
||||
registerListeners();
|
||||
this.api = new API(this);
|
||||
|
||||
registerTasks();
|
||||
|
||||
Benchmark.start("WebServer Initialization");
|
||||
uiServer = new WebServer(this);
|
||||
registerWebAPIs(); // TODO Move to WebServer class
|
||||
@ -176,10 +168,13 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
Log.error("WebServer was not successfully initialized.");
|
||||
}
|
||||
|
||||
//TODO Re-Enable after DB ServerTable has been initialized properly.
|
||||
// Benchmark.start("ServerInfo Registration");
|
||||
// serverInfoManager = new ServerInfoManager(this);
|
||||
// Benchmark.stop("Enable", "ServerInfo Registration");
|
||||
serverInfoManager = new ServerInfoManager(this);
|
||||
infoManager = new InformationManager(this);
|
||||
|
||||
registerListeners();
|
||||
registerTasks();
|
||||
|
||||
this.api = new API(this);
|
||||
|
||||
setupFilter(); // TODO Move to RegisterCommand Constructor
|
||||
|
||||
@ -283,7 +278,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
|
||||
if (Verify.notNull(dataCache, db)) {
|
||||
if (Verify.notNull(infoManager, db)) {
|
||||
// Saves the DataCache to the database without Bukkit's Schedulers.
|
||||
Log.info(Locale.get(Msg.DISABLE_CACHE_SAVE).toString());
|
||||
|
||||
@ -359,7 +354,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
* @return Current instance of the DataCache
|
||||
*/
|
||||
public DataCache getDataCache() {
|
||||
return dataCache;
|
||||
return getInfoManager().getDataCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -447,4 +442,8 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
public static UUID getServerUUID() {
|
||||
return getInstance().getServerInfoManager().getServerUUID();
|
||||
}
|
||||
|
||||
public InformationManager getInfoManager() {
|
||||
return infoManager;
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public class ManageRestoreCommand extends SubCommand {
|
||||
|
||||
if (ManageUtils.clearAndCopy(database, backupDB)) {
|
||||
if (database.getConfigName().equals(plugin.getDB().getConfigName())) {
|
||||
plugin.getDataCache().getCommandUseFromDb();
|
||||
// plugin.getDataCache().getCommandUseFromDb();
|
||||
}
|
||||
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
|
||||
|
@ -213,17 +213,6 @@ public abstract class Database {
|
||||
*/
|
||||
public abstract boolean removeAllData();
|
||||
|
||||
/**
|
||||
* Used to save CommandUse map.
|
||||
*
|
||||
* @param data String command (key), Integer times used
|
||||
* @throws SQLException If a database error occurs.
|
||||
* @throws NullPointerException If the database has not initialized tables.
|
||||
*/
|
||||
public void saveCommandUse(Map<String, Integer> data) throws SQLException {
|
||||
commandUseTable.saveCommandUse(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to fetch the saved UUIDs in the users table.
|
||||
*
|
||||
|
@ -1,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Select;
|
||||
@ -25,6 +24,7 @@ public class CommandUseTable extends Table {
|
||||
private final String columnCommand = "command";
|
||||
private final String columnTimesUsed = "times_used";
|
||||
private final String columnServerID = "server_id";
|
||||
|
||||
private final ServerTable serverTable;
|
||||
|
||||
/**
|
||||
@ -71,7 +71,6 @@ public class CommandUseTable extends Table {
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<String, Integer> getCommandUse(UUID serverUUID) throws SQLException {
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
Benchmark.start("Get CommandUse");
|
||||
Map<String, Integer> commandUse = new HashMap<>();
|
||||
PreparedStatement statement = null;
|
||||
@ -100,70 +99,31 @@ public class CommandUseTable extends Table {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void saveCommandUse(Map<String, Integer> data) throws SQLException {
|
||||
if (Verify.isEmpty(data)) {
|
||||
public void commandUsed(String command) throws SQLException {
|
||||
if (command.length() > 20) {
|
||||
return;
|
||||
}
|
||||
|
||||
Benchmark.start("Save Commanduse");
|
||||
Map<String, Integer> newData = new HashMap<>(data);
|
||||
Map<String, Integer> saved = getCommandUse();
|
||||
newData.keySet().removeAll(saved.keySet());
|
||||
|
||||
insertCommands(newData);
|
||||
|
||||
Map<String, Integer> updateData = new HashMap<>(data);
|
||||
updateData.keySet().removeAll(newData.keySet());
|
||||
|
||||
for (Map.Entry<String, Integer> savedEntry : saved.entrySet()) {
|
||||
String cmd = savedEntry.getKey();
|
||||
// IMPORTANT - not using saved as value
|
||||
Integer toSave = updateData.get(cmd);
|
||||
if (toSave != null && toSave <= savedEntry.getValue()) {
|
||||
updateData.remove(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
updateCommands(updateData);
|
||||
Benchmark.stop("Database", "Save Commanduse");
|
||||
db.setAvailable();
|
||||
}
|
||||
|
||||
private void updateCommands(Map<String, Integer> data) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
String updateStatement = "UPDATE " + tableName + " SET " +
|
||||
columnTimesUsed + "=? " +
|
||||
"WHERE (" + columnCommand + "=?) AND (" +
|
||||
columnServerID + "=" + serverTable.statementSelectServerID + ")";
|
||||
statement = prepareStatement(updateStatement);
|
||||
statement = prepareStatement("UPDATE " + tableName + " SET "
|
||||
+ columnTimesUsed + "=" + columnTimesUsed + "+ 1" +
|
||||
" WHERE " + columnServerID + "=" + serverTable.statementSelectServerID +
|
||||
" AND " + columnCommand + "=?");
|
||||
statement.setString(1, Plan.getServerUUID().toString());
|
||||
statement.setString(2, command);
|
||||
int success = statement.executeUpdate();
|
||||
|
||||
for (Map.Entry<String, Integer> entrySet : data.entrySet()) {
|
||||
String key = entrySet.getKey();
|
||||
Integer amount = entrySet.getValue();
|
||||
|
||||
if (key.length() > 20) {
|
||||
continue;
|
||||
}
|
||||
|
||||
statement.setInt(1, amount);
|
||||
statement.setString(2, key);
|
||||
statement.setString(3, Plan.getServerUUID().toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
|
||||
if (success == 0) {
|
||||
insertCommand(command);
|
||||
}
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
private void insertCommands(Map<String, Integer> data) throws SQLException {
|
||||
private void insertCommand(String command) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
String insertStatement = "INSERT INTO " + tableName + " ("
|
||||
@ -172,21 +132,11 @@ public class CommandUseTable extends Table {
|
||||
+ columnServerID
|
||||
+ ") VALUES (?, ?, " + serverTable.statementSelectServerID + ")";
|
||||
statement = prepareStatement(insertStatement);
|
||||
for (Map.Entry<String, Integer> entrySet : data.entrySet()) {
|
||||
String key = entrySet.getKey();
|
||||
Integer amount = entrySet.getValue();
|
||||
statement.setString(1, command);
|
||||
statement.setInt(2, 1);
|
||||
statement.setString(3, Plan.getServerUUID().toString());
|
||||
statement.execute();
|
||||
|
||||
if (key.length() > 20) {
|
||||
continue;
|
||||
}
|
||||
|
||||
statement.setString(1, key);
|
||||
statement.setInt(2, amount);
|
||||
statement.setString(3, Plan.getServerUUID().toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
commit(statement.getConnection());
|
||||
} finally {
|
||||
close(statement);
|
||||
|
@ -13,6 +13,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -63,10 +64,14 @@ public class WorldTimesTable extends UserIDTable {
|
||||
}
|
||||
|
||||
public void saveWorldTimes(UUID uuid, long sessionID, WorldTimes worldTimes) throws SQLException {
|
||||
if (Verify.isEmpty(worldTimes.getWorldTimes())) {
|
||||
Map<String, GMTimes> worldTimesMap = worldTimes.getWorldTimes();
|
||||
if (Verify.isEmpty(worldTimesMap)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> worldNames = worldTimesMap.keySet();
|
||||
db.getWorldTable().saveWorlds(worldNames);
|
||||
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " (" +
|
||||
@ -82,7 +87,7 @@ public class WorldTimesTable extends UserIDTable {
|
||||
worldTable.statementSelectID + ", " +
|
||||
"?, ?, ?, ?, ?)");
|
||||
|
||||
for (Map.Entry<String, GMTimes> entry : worldTimes.getWorldTimes().entrySet()) {
|
||||
for (Map.Entry<String, GMTimes> entry : worldTimesMap.entrySet()) {
|
||||
String worldName = entry.getKey();
|
||||
GMTimes gmTimes = entry.getValue();
|
||||
statement.setString(1, uuid.toString());
|
||||
|
@ -1,15 +1,9 @@
|
||||
package main.java.com.djrapitops.plan.systems.cache;
|
||||
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.locale.Msg;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This Class contains the Cache.
|
||||
@ -26,14 +20,10 @@ public class DataCache extends SessionCache {
|
||||
|
||||
private final Database db;
|
||||
|
||||
//Cache
|
||||
private Map<String, Integer> commandUse;
|
||||
private final Map<UUID, String> playerNames;
|
||||
private final Map<UUID, String> displayNames;
|
||||
|
||||
// Queues
|
||||
|
||||
|
||||
// Variables
|
||||
private boolean periodicTaskIsSaving = false;
|
||||
private final Set<UUID> playersWithFirstSession;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -44,94 +34,36 @@ public class DataCache extends SessionCache {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public DataCache(Plan plugin) {
|
||||
super(plugin); // Initializes Session & Location cache.
|
||||
super(plugin);
|
||||
db = plugin.getDB();
|
||||
|
||||
commandUse = new HashMap<>();
|
||||
if (!getCommandUseFromDb()) {
|
||||
Log.error(Locale.get(Msg.ENABLE_DB_FAIL_DISABLE_INFO).toString());
|
||||
plugin.disablePlugin();
|
||||
return;
|
||||
}
|
||||
startAsyncPeriodicSaveTask();
|
||||
playerNames = new HashMap<>();
|
||||
displayNames = new HashMap<>();
|
||||
playersWithFirstSession = new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the initial commandUse Map from the database.
|
||||
*
|
||||
* @return Was the fetch successful?
|
||||
*/
|
||||
public boolean getCommandUseFromDb() {
|
||||
try {
|
||||
commandUse = db.getCommandUse();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
return false;
|
||||
public void updateNames(UUID uuid, String playerName, String displayName) {
|
||||
playerNames.put(uuid, playerName);
|
||||
displayNames.put(uuid, displayName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to start the Asynchronous Save Task.
|
||||
*
|
||||
* @throws IllegalArgumentException BukkitRunnable was given wrong
|
||||
* parameters.
|
||||
* @throws IllegalStateException BukkitScheduler is in a wrong state.
|
||||
*/
|
||||
public void startAsyncPeriodicSaveTask() {
|
||||
DataCache dataCache = this;
|
||||
plugin.getRunnableFactory().createNew(new AbsRunnable("PeriodicCacheSaveTask") {
|
||||
private int timesSaved = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (periodicTaskIsSaving) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
periodicTaskIsSaving = true;
|
||||
Log.debug("Database", "Periodic Cache Save");
|
||||
saveCommandUse();
|
||||
timesSaved++;
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName() + "(" + this.getName() + ")", e);
|
||||
} finally {
|
||||
periodicTaskIsSaving = false;
|
||||
}
|
||||
}
|
||||
}).runTaskTimerAsynchronously(60L * 20L * 5, 60L * 20L * 5);
|
||||
public String getName(UUID uuid) {
|
||||
return playerNames.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the cached CommandUse.
|
||||
* <p>
|
||||
* Should be only called from an Asynchronous Thread.
|
||||
*/
|
||||
public void saveCommandUse() {
|
||||
try {
|
||||
db.saveCommandUse(new HashMap<>(commandUse));
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
public String getDisplayName(UUID uuid) {
|
||||
return displayNames.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the cached commandUse.
|
||||
*
|
||||
* @return Map with key:value - "/command":4
|
||||
*/
|
||||
public Map<String, Integer> getCommandUse() {
|
||||
return commandUse;
|
||||
public void addFirstLeaveCheck(UUID uuid) {
|
||||
playersWithFirstSession.add(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to handle a command's execution.
|
||||
*
|
||||
* @param command "/command"
|
||||
*/
|
||||
public void handleCommand(String command) {
|
||||
int amount = commandUse.getOrDefault(command, 0);
|
||||
public boolean isFirstSession(UUID uuid) {
|
||||
return playersWithFirstSession.contains(uuid);
|
||||
}
|
||||
|
||||
commandUse.put(command, amount + 1);
|
||||
public void clearFromFirstLeaveCheck(UUID uuid) {
|
||||
playersWithFirstSession.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ public class InformationManager {
|
||||
private final Database db;
|
||||
|
||||
private final DataCache dataCache;
|
||||
private final SessionCache sessionCache;
|
||||
|
||||
private boolean usingBungeeWebServer;
|
||||
private String webServerAddress;
|
||||
@ -36,7 +35,6 @@ public class InformationManager {
|
||||
.ifPresent(address -> webServerAddress = address);
|
||||
|
||||
dataCache = new DataCache(plugin);
|
||||
sessionCache = new SessionCache(plugin);
|
||||
|
||||
if (webServerAddress != null) {
|
||||
attemptBungeeConnection();
|
||||
@ -69,6 +67,6 @@ public class InformationManager {
|
||||
}
|
||||
|
||||
public SessionCache getSessionCache() {
|
||||
return sessionCache;
|
||||
return dataCache;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.systems.listeners;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||
import main.java.com.djrapitops.plan.systems.processing.player.NameProcessor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -8,6 +9,8 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Event Listener for AsyncPlayerChatEvents.
|
||||
*
|
||||
@ -16,6 +19,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
public class PlanChatListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataCache dataCache;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -24,6 +28,7 @@ public class PlanChatListener implements Listener {
|
||||
*/
|
||||
public PlanChatListener(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
dataCache = plugin.getDataCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,7 +43,10 @@ public class PlanChatListener implements Listener {
|
||||
}
|
||||
|
||||
Player p = event.getPlayer();
|
||||
// TODO NameCache to DataCache
|
||||
plugin.addToProcessQueue(new NameProcessor(p.getUniqueId(), p.getName(), p.getDisplayName()));
|
||||
UUID uuid = p.getUniqueId();
|
||||
String name = p.getName();
|
||||
String displayName = p.getDisplayName();
|
||||
|
||||
plugin.addToProcessQueue(new NameProcessor(uuid, name, displayName));
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.systems.listeners;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||
import main.java.com.djrapitops.plan.systems.processing.CommandProcessor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -19,7 +19,6 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
public class PlanCommandPreprocessListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataCache dataCache;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -28,7 +27,6 @@ public class PlanCommandPreprocessListener implements Listener {
|
||||
*/
|
||||
public PlanCommandPreprocessListener(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
dataCache = plugin.getDataCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +59,6 @@ public class PlanCommandPreprocessListener implements Listener {
|
||||
commandName = command.getName();
|
||||
}
|
||||
}
|
||||
// TODO Command Usage -> DB Save Processor
|
||||
dataCache.handleCommand(commandName);
|
||||
plugin.addToProcessQueue(new CommandProcessor(commandName));
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,6 @@ import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -31,8 +29,6 @@ public class PlanPlayerListener implements Listener {
|
||||
private final Plan plugin;
|
||||
private final DataCache cache;
|
||||
|
||||
private final Set<UUID> playersWithFirstSession;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
@ -41,17 +37,17 @@ public class PlanPlayerListener implements Listener {
|
||||
public PlanPlayerListener(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
cache = plugin.getDataCache();
|
||||
playersWithFirstSession = new HashSet<>();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
PlayerLoginEvent.Result result = event.getResult();
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
boolean op = event.getPlayer().isOp();
|
||||
if (result == PlayerLoginEvent.Result.KICK_BANNED) {
|
||||
plugin.addToProcessQueue(new BanProcessor(uuid, true));
|
||||
plugin.addToProcessQueue(new BanAndOpProcessor(uuid, true, op));
|
||||
} else {
|
||||
plugin.addToProcessQueue(new BanProcessor(uuid, false));
|
||||
plugin.addToProcessQueue(new BanAndOpProcessor(uuid, false, op));
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,9 +96,9 @@ public class PlanPlayerListener implements Listener {
|
||||
cache.cacheSession(uuid, Session.start(time, world, gm));
|
||||
|
||||
plugin.addToProcessQueue(
|
||||
new RegisterProcessor(this, uuid, player.getFirstPlayed(), playerName, playersOnline),
|
||||
new RegisterProcessor(uuid, player.getFirstPlayed(), playerName, playersOnline),
|
||||
new IPUpdateProcessor(uuid, ip),
|
||||
new NameProcessor(uuid, playerName, displayName), // TODO NameCache to DataCache
|
||||
new NameProcessor(uuid, playerName, displayName),
|
||||
new DBCommitProcessor(plugin.getDB())
|
||||
);
|
||||
}
|
||||
@ -122,19 +118,14 @@ public class PlanPlayerListener implements Listener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
plugin.addToProcessQueue(
|
||||
new BanProcessor(uuid, player.isBanned()),
|
||||
new BanAndOpProcessor(uuid, player.isBanned(), player.isOp()),
|
||||
new EndSessionProcessor(uuid, time)
|
||||
);
|
||||
|
||||
int messagesSent = 0; // TODO messages Sent on first session
|
||||
|
||||
if (playersWithFirstSession.contains(uuid)) {
|
||||
if (cache.isFirstSession(uuid)) {
|
||||
plugin.addToProcessQueue(new FirstLeaveProcessor(uuid, time, messagesSent));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO MOVE TO DATACACHE
|
||||
public void addFirstLeaveCheck(UUID uuid) {
|
||||
playersWithFirstSession.add(uuid);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.processing;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class CommandProcessor extends Processor<String> {
|
||||
|
||||
public CommandProcessor(String object) {
|
||||
super(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
try {
|
||||
Plan.getInstance().getDB().getCommandUseTable().commandUsed(object);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.processing.player;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BanAndOpProcessor extends PlayerProcessor {
|
||||
|
||||
private final boolean banned;
|
||||
private final boolean opped;
|
||||
|
||||
public BanAndOpProcessor(UUID uuid, boolean banned, boolean op) {
|
||||
super(uuid);
|
||||
this.banned = banned;
|
||||
opped = op;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
try {
|
||||
Plan.getInstance().getDB().getUserInfoTable().updateOpAndBanStatus(uuid, opped, banned);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.processing.player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BanProcessor extends PlayerProcessor {
|
||||
|
||||
private final boolean banned;
|
||||
|
||||
public BanProcessor(UUID uuid, boolean banned) {
|
||||
super(uuid);
|
||||
this.banned = banned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
// TODO DB Update Ban status
|
||||
}
|
||||
}
|
@ -29,10 +29,14 @@ public class FirstLeaveProcessor extends PlayerProcessor {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
Plan plugin = Plan.getInstance();
|
||||
UUID uuid = getUUID();
|
||||
try {
|
||||
Plan.getInstance().getDB().getActionsTable().insertAction(getUUID(), leaveAction);
|
||||
plugin.getDB().getActionsTable().insertAction(uuid, leaveAction);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
} finally {
|
||||
plugin.getDataCache().clearFromFirstLeaveCheck(uuid);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,12 +7,13 @@ package main.java.com.djrapitops.plan.systems.processing.player;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
* Processor for updating name in the database if the player has changed it.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@ -30,12 +31,23 @@ public class NameProcessor extends PlayerProcessor {
|
||||
@Override
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
Database db = Plan.getInstance().getDB();
|
||||
Plan plugin = Plan.getInstance();
|
||||
DataCache dataCache = plugin.getDataCache();
|
||||
String cachedName = dataCache.getName(uuid);
|
||||
String cachedDisplayName = dataCache.getDisplayName(uuid);
|
||||
|
||||
if (playerName.equals(cachedName) && displayName.equals(cachedDisplayName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Database db = plugin.getDB();
|
||||
try {
|
||||
db.getUsersTable().updateName(uuid, playerName);
|
||||
db.getNicknamesTable().saveUserName(uuid, displayName);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
|
||||
dataCache.updateNames(uuid, playerName, displayName);
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.processing.player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* //TODO Class Javadoc Comment
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class OPProcessor extends PlayerProcessor {
|
||||
|
||||
private final boolean banned;
|
||||
|
||||
public OPProcessor(UUID uuid, boolean banned) {
|
||||
super(uuid);
|
||||
this.banned = banned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
// TODO DB Update Ban status
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@ import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.Action;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.tables.Actions;
|
||||
import main.java.com.djrapitops.plan.systems.listeners.PlanPlayerListener;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
@ -25,11 +24,8 @@ public class RegisterProcessor extends PlayerProcessor {
|
||||
private final int playersOnline;
|
||||
private final String name;
|
||||
|
||||
private final PlanPlayerListener listener;
|
||||
|
||||
public RegisterProcessor(PlanPlayerListener listener, UUID uuid, long time, String name, int playersOnline) {
|
||||
public RegisterProcessor(UUID uuid, long time, String name, int playersOnline) {
|
||||
super(uuid);
|
||||
this.listener = listener;
|
||||
this.time = time;
|
||||
this.playersOnline = playersOnline;
|
||||
this.name = name;
|
||||
@ -38,11 +34,12 @@ public class RegisterProcessor extends PlayerProcessor {
|
||||
@Override
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
Database db = Plan.getInstance().getDB();
|
||||
Plan plugin = Plan.getInstance();
|
||||
Database db = plugin.getDB();
|
||||
if (db.wasSeenBefore(uuid)) {
|
||||
return;
|
||||
}
|
||||
listener.addFirstLeaveCheck(uuid);
|
||||
plugin.getDataCache().addFirstLeaveCheck(uuid);
|
||||
try {
|
||||
db.getUsersTable().registerUser(uuid, time, name);
|
||||
db.getActionsTable().insertAction(uuid, new Action(time, Actions.REGISTERED, "Online: " + playersOnline + " Players"));
|
||||
|
@ -49,6 +49,7 @@ class ProcessConsumer extends Consumer<Processor> {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Log.debug("Processed " + process.getClass().getSimpleName() + ".");
|
||||
process.process();
|
||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
||||
Log.toLog(this.getTaskName() + ":" + process.getClass().getSimpleName(), e);
|
||||
|
@ -66,16 +66,16 @@ public class ManageUtils {
|
||||
* @return success?
|
||||
*/
|
||||
public static boolean clearAndCopy(Database clearAndCopyToDB, Database copyFromDB) {
|
||||
try {
|
||||
// try {
|
||||
clearAndCopyToDB.removeAllData();
|
||||
//TODO List<UserInfo> allUserData = copyFromDB.getUserDataForUUIDS(copyFromDB.getSavedUUIDs());
|
||||
// clearAndCopyToDB.saveMultipleUserData(allUserData);
|
||||
clearAndCopyToDB.getCommandUseTable().saveCommandUse(copyFromDB.getCommandUseTable().getCommandUse());
|
||||
// TODO clearAndCopyToDB.getCommandUseTable().saveCommandUse(copyFromDB.getCommandUseTable().getCommandUse());
|
||||
//TODO clearAndCopyToDB.getTpsTable().saveTPSData(copyFromDB.getTpsTable().getTPSData());
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
Log.toLog("ManageUtils.move", e);
|
||||
return false;
|
||||
}
|
||||
// } catch (SQLException | NullPointerException e) {
|
||||
// Log.toLog("ManageUtils.move", e);
|
||||
// return false;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class Analysis {
|
||||
// List<UUID> uuids = rawData.stream().map(UserInfo::getUuid).collect(Collectors.toList());
|
||||
Benchmark.start("Create Empty dataset");
|
||||
DataCache dataCache = plugin.getDataCache();
|
||||
Map<String, Integer> commandUse = dataCache.getCommandUse();
|
||||
Map<String, Integer> commandUse = plugin.getDB().getCommandUse();
|
||||
|
||||
AnalysisData analysisData = new AnalysisData(commandUse, tpsData);
|
||||
analysisData.setPluginsTabLayout(plugin.getHookHandler().getPluginsTabLayoutForAnalysis());
|
||||
|
@ -47,11 +47,7 @@ public class QueueTest {
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime());
|
||||
db.init();
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
dataCache = new DataCache(plan) {
|
||||
@Override
|
||||
public void startAsyncPeriodicSaveTask() {
|
||||
}
|
||||
};
|
||||
dataCache = new DataCache(plan);
|
||||
when(plan.getDataCache()).thenReturn(dataCache);
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ import test.java.utils.TestInit;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
@ -79,15 +78,6 @@ public class DatabaseCommitTest {
|
||||
@Test
|
||||
public void testCommitToDBFile() throws SQLException {
|
||||
db.init();
|
||||
HashMap<String, Integer> c = new HashMap<>();
|
||||
c.put("/plan", 1);
|
||||
c.put("/tp", 4);
|
||||
c.put("/pla", 7);
|
||||
c.put("/help", 21);
|
||||
db.saveCommandUse(c);
|
||||
db.close();
|
||||
db.init();
|
||||
assertFalse(db.getCommandUse().isEmpty());
|
||||
}
|
||||
|
||||
@Ignore("//TODO")
|
||||
|
@ -110,28 +110,41 @@ public class DatabaseTest {
|
||||
|
||||
@Test
|
||||
public void testSaveCommandUse() throws SQLException {
|
||||
CommandUseTable commandUseTable = db.getCommandUseTable();
|
||||
Map<String, Integer> expected = new HashMap<>();
|
||||
|
||||
expected.put("plan", 1);
|
||||
expected.put("tp", 4);
|
||||
expected.put("pla", 7);
|
||||
expected.put("help", 21);
|
||||
expected.put("roiergbnougbierubieugbeigubeigubgierbgeugeg", 3);
|
||||
|
||||
db.saveCommandUse(expected);
|
||||
commandUseTable.commandUsed("plan");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
commandUseTable.commandUsed("tp");
|
||||
}
|
||||
for (int i = 0; i < 7; i++) {
|
||||
commandUseTable.commandUsed("pla");
|
||||
}
|
||||
for (int i = 0; i < 21; i++) {
|
||||
commandUseTable.commandUsed("help");
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
commandUseTable.commandUsed("roiergbnougbierubieugbeigubeigubgierbgeugeg");
|
||||
}
|
||||
|
||||
expected.remove("roiergbnougbierubieugbeigubeigubgierbgeugeg");
|
||||
|
||||
Map<String, Integer> commandUse = db.getCommandUse();
|
||||
assertEquals(expected, commandUse);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
commandUseTable.commandUsed("test");
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
commandUseTable.commandUsed("tp");
|
||||
}
|
||||
expected.put("test", 3);
|
||||
expected.put("tp", 6);
|
||||
expected.put("pla", 4);
|
||||
|
||||
db.saveCommandUse(expected);
|
||||
|
||||
expected.put("pla", 7);
|
||||
|
||||
commandUse = db.getCommandUse();
|
||||
|
||||
@ -140,15 +153,20 @@ public class DatabaseTest {
|
||||
|
||||
@Test
|
||||
public void testCommandUseTableIDSystem() throws SQLException {
|
||||
Map<String, Integer> save = new HashMap<>();
|
||||
save.put("plan", 1);
|
||||
save.put("tp", 4);
|
||||
save.put("pla", 7);
|
||||
save.put("help", 21);
|
||||
save.put("roiergbnougbierubieugbeigubeigubgierbgeugeg", 3);
|
||||
db.saveCommandUse(save);
|
||||
|
||||
CommandUseTable commandUseTable = db.getCommandUseTable();
|
||||
commandUseTable.commandUsed("plan");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
commandUseTable.commandUsed("tp");
|
||||
}
|
||||
for (int i = 0; i < 7; i++) {
|
||||
commandUseTable.commandUsed("pla");
|
||||
}
|
||||
for (int i = 0; i < 21; i++) {
|
||||
commandUseTable.commandUsed("help");
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
commandUseTable.commandUsed("roiergbnougbierubieugbeigubeigubgierbgeugeg");
|
||||
}
|
||||
Optional<Integer> id = commandUseTable.getCommandID("plan");
|
||||
assertTrue(id.isPresent());
|
||||
Optional<String> commandByID = commandUseTable.getCommandByID(id.get());
|
||||
@ -334,7 +352,6 @@ public class DatabaseTest {
|
||||
|
||||
@Test
|
||||
public void testSessionSaving() throws SQLException {
|
||||
saveTwoWorlds();
|
||||
saveUserOne();
|
||||
saveUserTwo();
|
||||
|
||||
@ -532,12 +549,12 @@ public class DatabaseTest {
|
||||
|
||||
assertTrue(usersTable.isRegistered(uuid));
|
||||
|
||||
Map<String, Integer> save = new HashMap<>();
|
||||
save.put("plan", 1);
|
||||
save.put("tp", 4);
|
||||
save.put("pla", 7);
|
||||
save.put("help", 21);
|
||||
db.saveCommandUse(save);
|
||||
db.getCommandUseTable().commandUsed("plan");
|
||||
db.getCommandUseTable().commandUsed("plan");
|
||||
db.getCommandUseTable().commandUsed("tp");
|
||||
db.getCommandUseTable().commandUsed("help");
|
||||
db.getCommandUseTable().commandUsed("help");
|
||||
db.getCommandUseTable().commandUsed("help");
|
||||
|
||||
TPSTable tpsTable = db.getTpsTable();
|
||||
List<TPS> expected = new ArrayList<>();
|
||||
|
Loading…
Reference in New Issue
Block a user