mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-07 17:28:03 +08:00
[3.5.0] Merge pull request #142 from Rsl1122/3.5.0
Pull Request for 3.5.0
This commit is contained in:
commit
4a78790638
File diff suppressed because one or more lines are too long
@ -18,10 +18,10 @@
|
||||
<module name='RightCurly' />
|
||||
<module name='AvoidNestedBlocks' />
|
||||
<module name="NestedIfDepth">
|
||||
<property name="max" value="2"/>
|
||||
<property name="max" value="2"/>
|
||||
</module>
|
||||
<module name="NestedForDepth">
|
||||
<property name="max" value="2"/>
|
||||
<property name="max" value="2"/>
|
||||
</module>
|
||||
<module name="NestedTryDepth"/>
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>Plan</artifactId>
|
||||
<version>3.4.3</version>
|
||||
<version>3.5.0</version>
|
||||
<build>
|
||||
<sourceDirectory>${basedir}/src</sourceDirectory>
|
||||
<defaultGoal>clean package install</defaultGoal>
|
||||
@ -98,11 +98,17 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
30
Plan/pom.xml
30
Plan/pom.xml
@ -3,26 +3,34 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>Plan</artifactId>
|
||||
<version>3.4.3</version>
|
||||
<version>3.5.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<!-- Spigot 1.12 built with Buildtools for Database classes.-->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Library for easier plugin development-->
|
||||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>BukkitPluginDependency</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- SoftDepended Plugins-->
|
||||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>BukkitPluginDependency</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>PlanPluginBridge</artifactId>
|
||||
<version>3.4.3</version>
|
||||
<version>3.5.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- -->
|
||||
|
@ -19,6 +19,11 @@ public class Log {
|
||||
Plan.getInstance().getPluginLogger().info(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the console with the chatcolors.
|
||||
*
|
||||
* @param message Message to send.
|
||||
*/
|
||||
public static void infoColor(String message) {
|
||||
Plan.getInstance().getPluginLogger().infoColor(message);
|
||||
}
|
||||
@ -71,6 +76,11 @@ public class Log {
|
||||
Plan.getInstance().getPluginLogger().toLog(message, filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the name for the error log file.
|
||||
*
|
||||
* @return Name of the error log file.
|
||||
*/
|
||||
public static String getErrorsFilename() {
|
||||
return Plan.getInstance().getPluginLogger().getErrorsFilename();
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Permissions class is used easily check every permission node.
|
||||
*
|
||||
@ -11,17 +9,22 @@ import org.bukkit.command.CommandSender;
|
||||
public enum Permissions {
|
||||
|
||||
HELP("plan.?"),
|
||||
//
|
||||
INSPECT("plan.inspect"),
|
||||
QUICK_INSPECT("plan.qinspect"),
|
||||
QUICK_INSPECT_OTHER("plan.qinspect.other"),
|
||||
INSPECT_OTHER("plan.inspect.other"),
|
||||
QUICK_INSPECT_OTHER("plan.qinspect.other"),
|
||||
//
|
||||
ANALYZE("plan.analyze"),
|
||||
QUICK_ANALYZE("plan.qanalyze"),
|
||||
//
|
||||
SEARCH("plan.search"),
|
||||
//
|
||||
RELOAD("plan.reload"),
|
||||
INFO("plan.info"),
|
||||
IGNORE_COMMANDUSE("plan.ignore.commanduse"),
|
||||
MANAGE("plan.manage");
|
||||
MANAGE("plan.manage"),
|
||||
//
|
||||
IGNORE_COMMANDUSE("plan.ignore.commanduse");
|
||||
|
||||
private final String permission;
|
||||
|
||||
@ -29,17 +32,6 @@ public enum Permissions {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the CommandSender has the permission.
|
||||
*
|
||||
* @param p entity sending the command (console/player/other)
|
||||
* @return CommandSender#hasPermission
|
||||
* @see CommandSender
|
||||
*/
|
||||
public boolean userHasThisPermission(CommandSender p) {
|
||||
return p.hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string of the permission node in plugin.yml.
|
||||
*
|
||||
@ -48,4 +40,15 @@ public enum Permissions {
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string of the permission node in plugin.yml.
|
||||
*
|
||||
* Shortcut for getPermission
|
||||
*
|
||||
* @return line of the permission eg. plan.inspect
|
||||
*/
|
||||
public String getPerm() {
|
||||
return getPermission();
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public enum Phrase {
|
||||
NOTIFY_DISABLED_GMLISTENER(ChatColor.YELLOW + "Gamemode change listener disabled, Gm times info inaccurate."),
|
||||
NOTIFY_DISABLED_COMMANDLISTENER(ChatColor.YELLOW + "Command usage listener disabled."),
|
||||
NOTIFY_DISABLED_DEATHLISTENER(ChatColor.YELLOW + "Death listener disabled, player & mob kills not recorded."),
|
||||
//
|
||||
//
|
||||
CACHE_SAVETASK_DISABLED("Attempted to schedule data for save after task was shut down."),
|
||||
CACHE_GETTASK_DISABLED("Attempted to schedule data grab after task was shut down."),
|
||||
CACHE_CLEARTASK_DISABLED("Attempted to schedule data for clear after task was shut down."),
|
||||
@ -65,7 +65,7 @@ public enum Phrase {
|
||||
NOT_IN_FAC("Not in a faction"),
|
||||
//
|
||||
ANALYSIS("Analysis | "),
|
||||
COMMAND_TIMEOUT(ChatColor.RED + "" + PREFIX + "REPLACE0 Command timed out! Error most likely on console."),
|
||||
COMMAND_TIMEOUT(ChatColor.RED + "" + PREFIX + "REPLACE0 Command timed out! Check '/plan status' & console."),
|
||||
ANALYSIS_START(ANALYSIS + "Beginning analysis of user data.."),
|
||||
ANALYSIS_BOOT_NOTIFY(ANALYSIS + "Boot analysis in 30 seconds.."),
|
||||
ANALYSIS_BOOT(ANALYSIS + "Starting Boot Analysis.."),
|
||||
@ -74,7 +74,7 @@ public enum Phrase {
|
||||
ANALYSIS_FAIL_NO_PLAYERS(ANALYSIS + "Analysis failed, no known players."),
|
||||
ANALYSIS_FAIL_NO_DATA(ANALYSIS + "Analysis failed, no data in the database."),
|
||||
ANALYSIS_BEGIN_ANALYSIS(ANALYSIS + "Data Fetched (REPLACE0 users, took REPLACE1ms), beginning Analysis of data.."),
|
||||
ANALYSIS_THIRD_PARTY(ANALYSIS+"Analyzing additional data sources (3rd party)"),
|
||||
ANALYSIS_THIRD_PARTY(ANALYSIS + "Analyzing additional data sources (3rd party)"),
|
||||
ANALYSIS_COMPLETE(ANALYSIS + "Analysis Complete. (took REPLACE0ms) REPLACE1"),
|
||||
DATA_CORRUPTION_WARN("Some data might be corrupted: " + REPLACE0),
|
||||
//
|
||||
@ -85,6 +85,7 @@ public enum Phrase {
|
||||
ERROR_LOGGED("Caught " + REPLACE0 + ". It has been logged to the Errors.txt"),
|
||||
ERROR_SESSIONDATA_INITIALIZATION("Player's session was initialized in a wrong way! (" + REPLACE0 + ")"),
|
||||
ERROR_ANALYSIS_FETCH_FAIL("Failed to fetch data for Analysis, Exception occurred."),
|
||||
ERROR_ANALYSIS_DISABLED_TEMPORARILY(ChatColor.YELLOW + "Analysis has been temporarily disabled due to expensive task, use /plan status for info."),
|
||||
//
|
||||
CMD_FOOTER(COLOR_TER.color() + "" + ARROWS_RIGHT),
|
||||
MANAGE_ERROR_INCORRECT_PLUGIN(ChatColor.RED + "" + PREFIX + "Plugin not supported: "),
|
||||
@ -110,20 +111,21 @@ public enum Phrase {
|
||||
CMD_INFO_HEADER(CMD_FOOTER + "" + COLOR_MAIN.color() + " Player Analytics - Info"),
|
||||
CMD_INFO_VERSION(CMD_BALL + "" + COLOR_MAIN.color() + " Version: " + COLOR_SEC.color() + REPLACE0),
|
||||
CMD_SEARCH_HEADER(CMD_FOOTER + "" + COLOR_MAIN.color() + " Player Analytics - Search results for: "),
|
||||
CMD_SEARCH_SEARCHING(CMD_FOOTER + "" + COLOR_MAIN.color() + " Searching.."),
|
||||
CMD_HELP_HEADER(CMD_FOOTER + "" + COLOR_MAIN.color() + " Player Analytics - Help"),
|
||||
CMD_MANAGE_HELP_HEADER(CMD_FOOTER + "" + COLOR_MAIN.color() + " Player Analytics - Managment Help"),
|
||||
CMD_MANAGE_STATUS_HEADER(CMD_FOOTER + "" + COLOR_MAIN.color() + " Player Analytics - Database status"),
|
||||
CMD_MANAGE_STATUS_ACTIVE_DB(CMD_BALL + "" + COLOR_MAIN.color() + " Active Database: " + COLOR_SEC.color() + "REPLACE0"),
|
||||
CMD_MANAGE_STATUS_QUEUE_SAVE(CMD_BALL + "" + COLOR_MAIN.color() + " Save Queue Size: " + COLOR_SEC.color() + "REPLACE0/"+Settings.PROCESS_SAVE_LIMIT.getNumber()),
|
||||
CMD_MANAGE_STATUS_QUEUE_GET(CMD_BALL + "" + COLOR_MAIN.color() + " Get Queue Size: " + COLOR_SEC.color() + "REPLACE0/"+Settings.PROCESS_GET_LIMIT.getNumber()),
|
||||
CMD_MANAGE_STATUS_QUEUE_CLEAR(CMD_BALL + "" + COLOR_MAIN.color() + " Clear Queue Size: " + COLOR_SEC.color() + "REPLACE0/"+Settings.PROCESS_CLEAR_LIMIT.getNumber()),
|
||||
CMD_MANAGE_STATUS_QUEUE_SAVE(CMD_BALL + "" + COLOR_MAIN.color() + " Save Queue Size: " + COLOR_SEC.color() + "REPLACE0/" + Settings.PROCESS_SAVE_LIMIT.getNumber()),
|
||||
CMD_MANAGE_STATUS_QUEUE_GET(CMD_BALL + "" + COLOR_MAIN.color() + " Get Queue Size: " + COLOR_SEC.color() + "REPLACE0/" + Settings.PROCESS_GET_LIMIT.getNumber()),
|
||||
CMD_MANAGE_STATUS_QUEUE_CLEAR(CMD_BALL + "" + COLOR_MAIN.color() + " Clear Queue Size: " + COLOR_SEC.color() + "REPLACE0/" + Settings.PROCESS_CLEAR_LIMIT.getNumber()),
|
||||
CMD_MANAGE_STATUS_QUEUE_PROCESS(CMD_BALL + "" + COLOR_MAIN.color() + " Process Queue Size: " + COLOR_SEC.color() + "REPLACE0/20000"),
|
||||
CMD_CLICK_ME("Click Me"),
|
||||
CMD_LINK(COLOR_SEC.color() + " " + BALL + COLOR_MAIN.color() + " Link: " + COLOR_TER.color()),
|
||||
CMD_PASS_PLANLITE("UNUSED"),
|
||||
CMD_RESULTS_AVAILABLE(COLOR_SEC.color() + " Results will be available for " + COLOR_TER.color() + REPLACE0 + COLOR_SEC.color() + " minutes."),
|
||||
CMD_NO_RESULTS(CMD_BALL + " No results for " + COLOR_SEC.color() + REPLACE0 + COLOR_MAIN.color() + "."),
|
||||
CMD_MATCH(COLOR_SEC.color() + " Matching player: " + COLOR_TER.color()),
|
||||
CMD_MATCH(COLOR_SEC.color() + " Matching players: " + COLOR_TER.color()),
|
||||
//
|
||||
CMD_USG_ANALYZE("View the Server Analysis"),
|
||||
CMD_USG_QANALYZE("View the Server QuickAnalysis"),
|
||||
@ -148,7 +150,7 @@ public enum Phrase {
|
||||
ARG_SEARCH("<part of playername>"),
|
||||
ARG_PLAYER("<player>"),
|
||||
ARG_RESTORE("<Filename.db> <dbTo> [-a]"),
|
||||
ARG_IMPORT("<plugin> [-a]"),
|
||||
ARG_IMPORT("<plugin>/list [import args]"),
|
||||
ARG_MOVE("<fromDB> <toDB> [-a]"),
|
||||
//
|
||||
USE_BACKUP("Use /plan manage backup <DB>"),
|
||||
@ -157,7 +159,7 @@ public enum Phrase {
|
||||
USE_PLAN("Use /plan for help"),
|
||||
USE_MOVE("Use /plan manage move <fromDB> <toDB> [-a]"),
|
||||
USE_COMBINE("Use /plan manage combine <fromDB> <toDB> [-a]"),
|
||||
USE_IMPORT("Use /plan manage import <plugin> [-a]"),
|
||||
USE_IMPORT("Use /plan manage import " + ARG_IMPORT),
|
||||
//
|
||||
WARN_REWRITE("Data in REPLACE0-database will be rewritten!"),
|
||||
WARN_OVERWRITE("Data in REPLACE0-database will be overwritten!"),
|
||||
|
@ -19,8 +19,11 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.javaplugin.ColorScheme;
|
||||
import com.djrapitops.javaplugin.RslPlugin;
|
||||
import com.djrapitops.javaplugin.api.ColorScheme;
|
||||
import com.djrapitops.javaplugin.api.TimeAmount;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
@ -40,12 +43,13 @@ import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.*;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.ui.webserver.WebSocketServer;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import com.djrapitops.javaplugin.task.ITask;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Javaplugin class that contains methods for starting the plugin, logging to
|
||||
@ -57,16 +61,19 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
public class Plan extends RslPlugin<Plan> {
|
||||
|
||||
private API api;
|
||||
|
||||
private DataCacheHandler handler;
|
||||
private InspectCacheHandler inspectCache;
|
||||
private AnalysisCacheHandler analysisCache;
|
||||
private HookHandler hookHandler;
|
||||
|
||||
private Database db;
|
||||
private HashSet<Database> databases;
|
||||
private WebSocketServer uiServer;
|
||||
private HookHandler hookHandler;
|
||||
private ServerVariableHolder variable;
|
||||
|
||||
private int bootAnalysisTaskID;
|
||||
private WebSocketServer uiServer;
|
||||
|
||||
private ServerVariableHolder serverVariableHolder;
|
||||
private int bootAnalysisTaskID = -1;
|
||||
|
||||
/**
|
||||
* OnEnable method.
|
||||
@ -79,76 +86,95 @@ public class Plan extends RslPlugin<Plan> {
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Sets the Required variables for RslPlugin instance to function correctly
|
||||
setInstance(this);
|
||||
super.setDebugMode(Settings.DEBUG.toString());
|
||||
super.setColorScheme(new ColorScheme(Phrase.COLOR_MAIN.color(), Phrase.COLOR_SEC.color(), Phrase.COLOR_TER.color()));
|
||||
super.setLogPrefix("[Plan]");
|
||||
super.setUpdateCheckUrl("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml");
|
||||
super.setUpdateUrl("https://www.spigotmc.org/resources/plan-player-analytics.32536/");
|
||||
|
||||
// Initializes RslPlugin variables, Checks version & Logs the debug header
|
||||
super.onEnableDefaultTasks();
|
||||
|
||||
processStatus().startExecution("Enable");
|
||||
|
||||
initLocale();
|
||||
Benchmark.start("Enable: Reading server variables");
|
||||
serverVariableHolder = new ServerVariableHolder(getServer());
|
||||
Benchmark.stop("Enable: Reading server variables");
|
||||
|
||||
Server server = getServer();
|
||||
variable = new ServerVariableHolder(server);
|
||||
|
||||
Log.debug("-------------------------------------");
|
||||
Log.debug("Debug log: Plan v." + getDescription().getVersion());
|
||||
Log.debug("Implements RslPlugin v." + getRslVersion());
|
||||
Log.debug("Server: " + server.getBukkitVersion());
|
||||
Log.debug("Version: " + server.getVersion());
|
||||
Log.debug("-------------------------------------");
|
||||
|
||||
databases = new HashSet<>();
|
||||
databases.add(new MySQLDB(this));
|
||||
databases.add(new SQLiteDB(this));
|
||||
|
||||
Benchmark.start("Enable: Copy default config");
|
||||
getConfig().options().copyDefaults(true);
|
||||
getConfig().options().header(Phrase.CONFIG_HEADER + "");
|
||||
saveConfig();
|
||||
Benchmark.stop("Enable: Copy default config");
|
||||
|
||||
Benchmark.start("Enable: Init Database");
|
||||
Log.info(Phrase.DB_INIT + "");
|
||||
if (initDatabase()) {
|
||||
if (Check.ifTrue_Error(initDatabase(), Phrase.DB_FAILURE_DISABLE.toString())) {
|
||||
Log.info(Phrase.DB_ESTABLISHED.parse(db.getConfigName()));
|
||||
} else {
|
||||
Log.error(Phrase.DB_FAILURE_DISABLE.toString());
|
||||
server.getPluginManager().disablePlugin(this);
|
||||
disablePlugin();
|
||||
return;
|
||||
}
|
||||
Benchmark.stop("Enable: Init Database");
|
||||
|
||||
Benchmark.start("Enable: Init DataCache");
|
||||
this.handler = new DataCacheHandler(this);
|
||||
this.inspectCache = new InspectCacheHandler(this);
|
||||
this.analysisCache = new AnalysisCacheHandler(this);
|
||||
registerListeners();
|
||||
Benchmark.stop("Enable: Init DataCache");
|
||||
|
||||
getCommand("plan").setExecutor(new PlanCommand(this));
|
||||
super.getRunnableFactory().createNew(new TPSCountTimer(this)).runTaskTimer(1000, TimeAmount.SECOND.ticks());
|
||||
registerListeners();
|
||||
registerCommand(new PlanCommand(this));
|
||||
|
||||
this.api = new API(this);
|
||||
Benchmark.start("Enable: Handle Reload");
|
||||
handler.handleReload();
|
||||
Benchmark.stop("Enable: Handle Reload");
|
||||
|
||||
bootAnalysisTaskID = -1;
|
||||
if (Settings.WEBSERVER_ENABLED.isTrue()) {
|
||||
Benchmark.start("Enable: Analysis refresh task registration");
|
||||
// Analysis refresh settings
|
||||
boolean bootAnalysisIsEnabled = Settings.ANALYSIS_REFRESH_ON_ENABLE.isTrue();
|
||||
int analysisRefreshMinutes = Settings.ANALYSIS_AUTO_REFRESH.getNumber();
|
||||
boolean analysisRefreshTaskIsEnabled = analysisRefreshMinutes > 0;
|
||||
|
||||
// Analysis refresh tasks
|
||||
if (bootAnalysisIsEnabled) {
|
||||
startBootAnalysisTask();
|
||||
}
|
||||
if (analysisRefreshTaskIsEnabled) {
|
||||
startAnalysisRefreshTask(analysisRefreshMinutes);
|
||||
}
|
||||
Benchmark.stop("Enable: Analysis refresh task registration");
|
||||
|
||||
Benchmark.start("Enable: Webserver Initialization");
|
||||
// Data view settings
|
||||
boolean webserverIsEnabled = Settings.WEBSERVER_ENABLED.isTrue();
|
||||
boolean usingAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
|
||||
boolean usingAlternativeUI = Settings.USE_ALTERNATIVE_UI.isTrue();
|
||||
boolean hasDataViewCapability = usingAlternativeIP || usingAlternativeUI || webserverIsEnabled;
|
||||
|
||||
if (webserverIsEnabled) {
|
||||
uiServer = new WebSocketServer(this);
|
||||
uiServer.initServer();
|
||||
if (Settings.ANALYSIS_REFRESH_ON_ENABLE.isTrue()) {
|
||||
startBootAnalysisTask();
|
||||
}
|
||||
int analysisRefreshMinutes = Settings.ANALYSIS_AUTO_REFRESH.getNumber();
|
||||
if (analysisRefreshMinutes != -1) {
|
||||
startAnalysisRefreshTask(analysisRefreshMinutes);
|
||||
}
|
||||
} else if (!(Settings.SHOW_ALTERNATIVE_IP.isTrue())
|
||||
|| (Settings.USE_ALTERNATIVE_UI.isTrue())) {
|
||||
} else if (!hasDataViewCapability) {
|
||||
Log.infoColor(Phrase.ERROR_NO_DATA_VIEW + "");
|
||||
}
|
||||
if (!Settings.SHOW_ALTERNATIVE_IP.isTrue() && variable.getIp().isEmpty()) {
|
||||
if (!usingAlternativeIP && serverVariableHolder.getIp().isEmpty()) {
|
||||
Log.infoColor(Phrase.NOTIFY_EMPTY_IP + "");
|
||||
}
|
||||
Benchmark.stop("Enable: Webserver Initialization");
|
||||
|
||||
hookHandler = new HookHandler();
|
||||
Benchmark.start("Enable: Hook to 3rd party plugins");
|
||||
hookHandler = new HookHandler(this);
|
||||
Benchmark.stop("Enable: Hook to 3rd party plugins");
|
||||
|
||||
Log.debug("Verboose debug messages are enabled.");
|
||||
Log.info(Phrase.ENABLED + "");
|
||||
processStatus().finishExecution("Enable");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,50 +184,51 @@ public class Plan extends RslPlugin<Plan> {
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (uiServer != null) {
|
||||
// Stop the UI Server
|
||||
if (Verify.notNull(uiServer)) {
|
||||
uiServer.stop();
|
||||
}
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
if (handler != null) {
|
||||
if (Verify.notNull(handler) && Verify.notNull(db)) {
|
||||
Benchmark.start("DataCache OnDisable Save");
|
||||
// Saves the datacache to the database without Bukkit's Schedulers.
|
||||
Log.info(Phrase.CACHE_SAVE + "");
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
scheduler.execute(() -> {
|
||||
handler.saveCacheOnDisable();
|
||||
taskStatus().cancelAllKnownTasks();
|
||||
Benchmark.stop("DataCache OnDisable Save");
|
||||
});
|
||||
scheduler.shutdown(); // Schedules the save to shutdown after it has ran the execute method.
|
||||
|
||||
scheduler.shutdown();
|
||||
}
|
||||
Log.info(Phrase.DISABLED + "");
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
final PluginManager pluginManager = getServer().getPluginManager();
|
||||
Benchmark.start("Enable: Register Listeners");
|
||||
registerListener(new PlanPlayerListener(this));
|
||||
boolean chatListenerIsEnabled = Check.ifTrue(Settings.GATHERCHAT.isTrue(), Phrase.NOTIFY_DISABLED_CHATLISTENER + "");
|
||||
boolean gamemodeChangeListenerIsEnabled = Check.ifTrue(Settings.GATHERGMTIMES.isTrue(), Phrase.NOTIFY_DISABLED_GMLISTENER + "");
|
||||
boolean commandListenerIsEnabled = Check.ifTrue(Settings.GATHERCOMMANDS.isTrue(), Phrase.NOTIFY_DISABLED_COMMANDLISTENER + "");
|
||||
boolean deathListenerIsEnabled = Check.ifTrue(Settings.GATHERKILLS.isTrue(), Phrase.NOTIFY_DISABLED_DEATHLISTENER + "");
|
||||
|
||||
pluginManager.registerEvents(new PlanPlayerListener(this), this);
|
||||
|
||||
if (Settings.GATHERCHAT.isTrue()) {
|
||||
if (chatListenerIsEnabled) {
|
||||
registerListener(new PlanChatListener(this));
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_CHATLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERGMTIMES.isTrue()) {
|
||||
if (gamemodeChangeListenerIsEnabled) {
|
||||
registerListener(new PlanGamemodeChangeListener(this));
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_GMLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERCOMMANDS.isTrue()) {
|
||||
if (commandListenerIsEnabled) {
|
||||
registerListener(new PlanCommandPreprocessListener(this));
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_COMMANDLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERKILLS.isTrue()) {
|
||||
if (deathListenerIsEnabled) {
|
||||
registerListener(new PlanDeathEventListener(this));
|
||||
} else {
|
||||
Log.infoColor(Phrase.NOTIFY_DISABLED_DEATHLISTENER + "");
|
||||
}
|
||||
if (Settings.GATHERLOCATIONS.isTrue()) {
|
||||
registerListener(new PlanPlayerMoveListener(this));
|
||||
}
|
||||
Benchmark.stop("Enable: Register Listeners");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -212,53 +239,123 @@ public class Plan extends RslPlugin<Plan> {
|
||||
* @return true if init was successful, false if not.
|
||||
*/
|
||||
public boolean initDatabase() {
|
||||
String type = Settings.DB_TYPE + "";
|
||||
databases = new HashSet<>();
|
||||
databases.add(new MySQLDB(this));
|
||||
databases.add(new SQLiteDB(this));
|
||||
|
||||
String dbType = (Settings.DB_TYPE + "").toLowerCase().trim();
|
||||
|
||||
db = null;
|
||||
for (Database database : databases) {
|
||||
if (type.equalsIgnoreCase(database.getConfigName())) {
|
||||
String databaseType = database.getConfigName().toLowerCase().trim();
|
||||
Log.debug(databaseType + ": " + Verify.equalsIgnoreCase(dbType, databaseType));
|
||||
if (Verify.equalsIgnoreCase(dbType, databaseType)) {
|
||||
this.db = database;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (db == null) {
|
||||
Log.info(Phrase.DB_TYPE_DOES_NOT_EXIST.toString());
|
||||
if (!Verify.notNull(db)) {
|
||||
Log.info(Phrase.DB_TYPE_DOES_NOT_EXIST.toString() + " " + dbType);
|
||||
return false;
|
||||
}
|
||||
if (!db.init()) {
|
||||
Log.info(Phrase.DB_FAILURE_DISABLE.toString());
|
||||
setEnabled(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return Check.ifTrue_Error(db.init(), Phrase.DB_FAILURE_DISABLE.toString());
|
||||
}
|
||||
|
||||
private void startAnalysisRefreshTask(int analysisRefreshMinutes) throws IllegalStateException, IllegalArgumentException {
|
||||
BukkitTask asyncPeriodicalAnalysisTask = new BukkitRunnable() {
|
||||
private void startAnalysisRefreshTask(int everyXMinutes) throws IllegalStateException {
|
||||
Benchmark.start("Enable: Schedule PeriodicAnalysisTask");
|
||||
if (!Verify.positive(everyXMinutes)) {
|
||||
return;
|
||||
}
|
||||
getRunnableFactory().createNew("PeriodicalAnalysisTask", new RslRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.debug("Running PeriodicalAnalysisTask");
|
||||
if (!analysisCache.isCached()) {
|
||||
analysisCache.updateCache();
|
||||
} else if (MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
} else if (MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > TimeAmount.MINUTE.ms()) {
|
||||
analysisCache.updateCache();
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(this, analysisRefreshMinutes * 60 * 20, analysisRefreshMinutes * 60 * 20);
|
||||
}).runTaskTimerAsynchronously(everyXMinutes * TimeAmount.MINUTE.ticks(), everyXMinutes * TimeAmount.MINUTE.ticks());
|
||||
Benchmark.stop("Enable: Schedule PeriodicAnalysisTask");
|
||||
}
|
||||
|
||||
private void startBootAnalysisTask() throws IllegalStateException, IllegalArgumentException {
|
||||
private void startBootAnalysisTask() throws IllegalStateException {
|
||||
Benchmark.start("Enable: Schedule boot analysis task");
|
||||
Log.info(Phrase.ANALYSIS_BOOT_NOTIFY + "");
|
||||
BukkitTask bootAnalysisTask = new BukkitRunnable() {
|
||||
ITask bootAnalysisTask = getRunnableFactory().createNew("BootAnalysisTask", new RslRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.debug("Running BootAnalysisTask");
|
||||
Log.info(Phrase.ANALYSIS_BOOT + "");
|
||||
analysisCache.updateCache();
|
||||
this.cancel();
|
||||
}
|
||||
}.runTaskLater(this, 30 * 20);
|
||||
}).runTaskLaterAsynchronously(30 * TimeAmount.SECOND.ticks());
|
||||
bootAnalysisTaskID = bootAnalysisTask.getTaskId();
|
||||
Benchmark.stop("Enable: Schedule boot analysis task");
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to write a new Locale file in the plugin's datafolder.
|
||||
*/
|
||||
public void writeNewLocaleFile() {
|
||||
File genLocale = new File(getDataFolder(), "locale_EN.txt");
|
||||
try {
|
||||
genLocale.createNewFile();
|
||||
FileWriter fw = new FileWriter(genLocale, true);
|
||||
PrintWriter pw = new PrintWriter(fw);
|
||||
for (Phrase p : Phrase.values()) {
|
||||
pw.println(p.name() + " <> " + p.parse());
|
||||
pw.flush();
|
||||
}
|
||||
pw.println("<<<<<<HTML>>>>>>");
|
||||
for (Html h : Html.values()) {
|
||||
pw.println(h.name() + " <> " + h.parse());
|
||||
pw.flush();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void initLocale() {
|
||||
String locale = Settings.LOCALE.toString().toUpperCase();
|
||||
Benchmark.start("Enable: Initializing locale");
|
||||
File localeFile = new File(getDataFolder(), "locale.txt");
|
||||
boolean skipLoc = false;
|
||||
String usingLocale = "";
|
||||
if (localeFile.exists()) {
|
||||
Phrase.loadLocale(localeFile);
|
||||
Html.loadLocale(localeFile);
|
||||
skipLoc = true;
|
||||
usingLocale = "locale.txt";
|
||||
}
|
||||
if (!locale.equals("DEFAULT")) {
|
||||
try {
|
||||
if (!skipLoc) {
|
||||
URL localeURL = new URL("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/localization/locale_" + locale + ".txt");
|
||||
InputStream inputStream = localeURL.openStream();
|
||||
OutputStream outputStream = new FileOutputStream(localeFile);
|
||||
int read = 0;
|
||||
byte[] bytes = new byte[1024];
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, read);
|
||||
}
|
||||
Phrase.loadLocale(localeFile);
|
||||
Html.loadLocale(localeFile);
|
||||
usingLocale = locale;
|
||||
localeFile.delete();
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
Log.error("Attempted using locale that doesn't exist.");
|
||||
usingLocale = "Default: EN";
|
||||
} catch (IOException e) {
|
||||
}
|
||||
} else {
|
||||
usingLocale = "Default: EN";
|
||||
}
|
||||
Benchmark.stop("Enable: Initializing locale");
|
||||
Log.info("Using locale: " + usingLocale);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -335,10 +432,21 @@ public class Plan extends RslPlugin<Plan> {
|
||||
return bootAnalysisTaskID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the object storing server variables that are constant after
|
||||
* boot.
|
||||
*
|
||||
* @return ServerVariableHolder
|
||||
* @see ServerVariableHolder
|
||||
*/
|
||||
public ServerVariableHolder getVariable() {
|
||||
return serverVariableHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old method for getting the API.
|
||||
*
|
||||
* @deprecated Use Plan.getAPI() (static method) instead.
|
||||
* @deprecated Use Plan.getPlanAPI() (static method) instead.
|
||||
* @return the Plan API.
|
||||
*/
|
||||
@Deprecated
|
||||
@ -346,66 +454,6 @@ public class Plan extends RslPlugin<Plan> {
|
||||
return api;
|
||||
}
|
||||
|
||||
private void initLocale() {
|
||||
String locale = Settings.LOCALE.toString().toUpperCase();
|
||||
/*// Used to write a new Locale file
|
||||
File genLocale = new File(getDataFolder(), "locale_EN.txt");
|
||||
try {
|
||||
genLocale.createNewFile();
|
||||
FileWriter fw = new FileWriter(genLocale, true);
|
||||
PrintWriter pw = new PrintWriter(fw);
|
||||
for (Phrase p : Phrase.values()) {
|
||||
pw.println(p.name()+" <> "+p.parse());
|
||||
pw.flush();
|
||||
}
|
||||
pw.println("<<<<<<HTML>>>>>>");
|
||||
for (Html h : Html.values()) {
|
||||
pw.println(h.name()+" <> "+h.parse());
|
||||
pw.flush();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Plan.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}*/
|
||||
File localeFile = new File(getDataFolder(), "locale.txt");
|
||||
boolean skipLoc = false;
|
||||
String usingLocale = "";
|
||||
if (localeFile.exists()) {
|
||||
Phrase.loadLocale(localeFile);
|
||||
Html.loadLocale(localeFile);
|
||||
skipLoc = true;
|
||||
usingLocale = "locale.txt";
|
||||
}
|
||||
if (!locale.equals("DEFAULT")) {
|
||||
try {
|
||||
if (!skipLoc) {
|
||||
URL localeURL = new URL("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/localization/locale_" + locale + ".txt");
|
||||
InputStream inputStream = localeURL.openStream();
|
||||
OutputStream outputStream = new FileOutputStream(localeFile);
|
||||
int read = 0;
|
||||
byte[] bytes = new byte[1024];
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, read);
|
||||
}
|
||||
Phrase.loadLocale(localeFile);
|
||||
Html.loadLocale(localeFile);
|
||||
usingLocale = locale;
|
||||
localeFile.delete();
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
Log.error("Attempted using locale that doesn't exist.");
|
||||
usingLocale = "Default: EN";
|
||||
} catch (IOException e) {
|
||||
}
|
||||
} else {
|
||||
usingLocale = "Default: EN";
|
||||
}
|
||||
Log.info("Using locale: " + usingLocale);
|
||||
}
|
||||
|
||||
public ServerVariableHolder getVariable() {
|
||||
return variable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the PlanAPI. @see API
|
||||
*
|
||||
@ -414,14 +462,19 @@ public class Plan extends RslPlugin<Plan> {
|
||||
* Plan and the instance is null.
|
||||
*/
|
||||
public static API getPlanAPI() throws IllegalStateException {
|
||||
Plan INSTANCE = getInstance();
|
||||
if (INSTANCE == null) {
|
||||
Plan instance = getInstance();
|
||||
if (instance == null) {
|
||||
throw new IllegalStateException("Plugin not enabled properly, Singleton instance is null.");
|
||||
}
|
||||
return INSTANCE.api;
|
||||
return instance.api;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to get the plugin-instance singleton.
|
||||
*
|
||||
* @return this object.
|
||||
*/
|
||||
public static Plan getInstance() {
|
||||
return (Plan) getPluginInstance();
|
||||
return (Plan) getPluginInstance(Plan.class);
|
||||
}
|
||||
}
|
||||
|
@ -11,18 +11,33 @@ import org.bukkit.Server;
|
||||
*/
|
||||
public class ServerVariableHolder {
|
||||
|
||||
private int maxPlayers;
|
||||
private String ip;
|
||||
private final int maxPlayers;
|
||||
private final String ip;
|
||||
|
||||
/**
|
||||
* Constructor, grabs the variables.
|
||||
*
|
||||
* @param server instance the plugin is running on.
|
||||
*/
|
||||
public ServerVariableHolder(Server server) {
|
||||
maxPlayers = server.getMaxPlayers();
|
||||
ip = server.getIp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum amount of players defined in server.properties.
|
||||
*
|
||||
* @return number.
|
||||
*/
|
||||
public int getMaxPlayers() {
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ip string in server.properties.
|
||||
*
|
||||
* @return the ip.
|
||||
*/
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
@ -26,14 +26,7 @@ public enum Settings {
|
||||
GATHERCOMMANDS("Settings.Data.GatherCommandUsage"),
|
||||
SECURITY_IP_UUID("Settings.WebServer.Security.DisplayIPsAndUUIDs"),
|
||||
GRAPH_PLAYERS_USEMAXPLAYERS_SCALE("Customization.Graphs.PlayersOnlineGraph.UseMaxPlayersAsScale"),
|
||||
ENABLED_AA("Customization.Plugins.Enabled.AdvancedAchievements"),
|
||||
ENABLED_ESS("Customization.Plugins.Enabled.Essentials"),
|
||||
ENABLED_FAC("Customization.Plugins.Enabled.Factions"),
|
||||
ENABLED_JOB("Customization.Plugins.Enabled.Jobs"),
|
||||
ENABLED_MCM("Customization.Plugins.Enabled.McMMO"),
|
||||
ENABLED_ONT("Customization.Plugins.Enabled.OnTime"),
|
||||
ENABLED_TOW("Customization.Plugins.Enabled.Towny"),
|
||||
ENABLED_VAU("Customization.Plugins.Enabled.Vault"),
|
||||
PLAYERLIST_SHOW_IMAGES("Customization.SmallHeadImagesOnAnalysisPlayerlist"),
|
||||
LINK_PROTOCOL("Settings.WebServer.LinkProtocol"),
|
||||
// Integer
|
||||
ANALYSIS_MINUTES_FOR_ACTIVE("Settings.Analysis.MinutesPlayedUntilConsidiredActive"),
|
||||
|
@ -1,10 +1,15 @@
|
||||
package main.java.com.djrapitops.plan.api;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.UUIDFetcher;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import com.djrapitops.javaplugin.utilities.player.IOfflinePlayer;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.AnalysisData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
@ -15,8 +20,6 @@ import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
import main.java.com.djrapitops.plan.ui.DataRequestHandler;
|
||||
import main.java.com.djrapitops.plan.ui.webserver.WebSocketServer;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
* This class contains the API methods.
|
||||
@ -33,7 +36,7 @@ import org.bukkit.OfflinePlayer;
|
||||
*/
|
||||
public class API {
|
||||
|
||||
private Plan plugin;
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Construcor.
|
||||
@ -165,7 +168,7 @@ public class API {
|
||||
*/
|
||||
public String getPlayerHtmlAsString(UUID uuid) {
|
||||
WebSocketServer server = plugin.getUiServer();
|
||||
if (server != null) {
|
||||
if (Verify.notNull(server)) {
|
||||
return server.getDataReqHandler().getInspectHtml(uuid);
|
||||
}
|
||||
DataRequestHandler reqH = new DataRequestHandler(plugin);
|
||||
@ -182,8 +185,8 @@ public class API {
|
||||
}
|
||||
|
||||
/**
|
||||
* Run's the analysis with the current data in the cache and fetches rest from
|
||||
* the database.
|
||||
* Run's the analysis with the current data in the cache and fetches rest
|
||||
* from the database.
|
||||
*
|
||||
* Starts a new Asyncronous task to run the analysis.
|
||||
*/
|
||||
@ -200,7 +203,7 @@ public class API {
|
||||
*/
|
||||
public String getAnalysisHtmlAsString() {
|
||||
WebSocketServer server = plugin.getUiServer();
|
||||
if (server != null) {
|
||||
if (Verify.notNull(server)) {
|
||||
return server.getDataReqHandler().getAnalysisHtml();
|
||||
}
|
||||
DataRequestHandler reqH = new DataRequestHandler(plugin);
|
||||
@ -224,12 +227,14 @@ public class API {
|
||||
*
|
||||
* @param uuid UUID of the player.
|
||||
* @return Playername, eg "Rsl1122"
|
||||
* @throws NullPointerException If uuid is null.
|
||||
* @throws IllegalStateException If the player has not played on the server
|
||||
* before.
|
||||
*/
|
||||
public String getPlayerName(UUID uuid) throws IllegalStateException {
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(uuid);
|
||||
if (offlinePlayer.hasPlayedBefore()) {
|
||||
public String getPlayerName(UUID uuid) throws IllegalStateException, NullPointerException {
|
||||
Verify.nullCheck(uuid);
|
||||
IOfflinePlayer offlinePlayer = Plan.getInstance().fetch().getOfflinePlayer(uuid);
|
||||
if (Verify.notNull(offlinePlayer)) {
|
||||
return offlinePlayer.getName();
|
||||
}
|
||||
throw new IllegalStateException("Player has not played on this server before.");
|
||||
@ -245,12 +250,12 @@ public class API {
|
||||
public UUID playerNameToUUID(String playerName) throws Exception {
|
||||
return UUIDFetcher.getUUIDOf(playerName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the saved UUIDs in the database.
|
||||
*
|
||||
*
|
||||
* Should be called from async thread.
|
||||
*
|
||||
*
|
||||
* @return Collection of UUIDs that can be found in the database.
|
||||
* @throws SQLException If database error occurs.
|
||||
* @since 3.4.2
|
||||
@ -258,14 +263,14 @@ public class API {
|
||||
public Collection<UUID> getSavedUUIDs() throws SQLException {
|
||||
return plugin.getDB().getSavedUUIDs();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the saved UserData in the database for a collection of UUIDs.
|
||||
*
|
||||
*
|
||||
* Will not contain data for UUIDs not found in the database.
|
||||
*
|
||||
*
|
||||
* Should be called from async thread.
|
||||
*
|
||||
*
|
||||
* @param uuids Collection of UUIDs that can be found in the database.
|
||||
* @return List of all Data in the database.
|
||||
* @throws SQLException If database error occurs.
|
||||
@ -274,4 +279,33 @@ public class API {
|
||||
public List<UserData> getUserDataOfUsers(Collection<UUID> uuids) throws SQLException {
|
||||
return plugin.getDB().getUserDataForUUIDS(uuids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cached UserData objects in the InspectCache.
|
||||
*
|
||||
* This can be used with PluginData objects safely to get the data for all
|
||||
* users in Plan database, because all data is InspectCached before analysis
|
||||
* begins.
|
||||
*
|
||||
* @return List of all Data in the InspectCache.
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public List<UserData> getInspectCachedUserData() {
|
||||
return plugin.getInspectCache().getCachedUserData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cached UserData objects in the InspectCache in a Map form.
|
||||
*
|
||||
* This can be used with PluginData objects safely to get the data for all
|
||||
* users in Plan database, because all data is InspectCached before analysis
|
||||
* begins.
|
||||
*
|
||||
* @return Map of all Data in the InspectCache with UUID of the player as
|
||||
* the key.
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public Map<UUID, UserData> getInspectCachedUserDataMap() {
|
||||
return getInspectCachedUserData().stream().collect(Collectors.toMap(UserData::getUuid, Function.identity()));
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public enum Gender {
|
||||
* @return Gender Enum
|
||||
*/
|
||||
public static Gender parse(String name) {
|
||||
switch (name) {
|
||||
switch (name.toLowerCase()) {
|
||||
case "female":
|
||||
return Gender.FEMALE;
|
||||
case "male":
|
||||
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
public class Condition {
|
||||
final private String failMsg;
|
||||
final private boolean pass;
|
||||
|
||||
public Condition(boolean pass, String failMsg) {
|
||||
this.failMsg = failMsg;
|
||||
this.pass = pass;
|
||||
}
|
||||
|
||||
public String getFailMsg() {
|
||||
return failMsg;
|
||||
}
|
||||
|
||||
public boolean pass() {
|
||||
return pass;
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
* This class contains static methods used by the commands to check whether or
|
||||
@ -13,8 +13,13 @@ import org.bukkit.OfflinePlayer;
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class CommandUtils {
|
||||
public class ConditionUtils {
|
||||
|
||||
/**
|
||||
* Check if the plugin can display the data.
|
||||
*
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean pluginHasViewCapability() {
|
||||
final boolean usingAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
|
||||
final boolean webserverIsOn = Settings.WEBSERVER_ENABLED.isTrue();
|
||||
@ -22,6 +27,13 @@ public class CommandUtils {
|
||||
return webserverIsOn || usingAlternativeIP || usingTextUI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the uuid of a playername. Same as UUIDUtility
|
||||
*
|
||||
* @param playerName name of player.
|
||||
* @return UUID
|
||||
* @see UUIDUtility
|
||||
*/
|
||||
public static UUID getUUID(String playerName) {
|
||||
try {
|
||||
return UUIDUtility.getUUIDOf(playerName);
|
||||
@ -30,15 +42,16 @@ public class CommandUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean uuidIsValid(UUID uuid) {
|
||||
return uuid != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has played.
|
||||
*
|
||||
* @param uuid UUID of player
|
||||
* @return has the player played before?
|
||||
*/
|
||||
public static boolean playerHasPlayed(UUID uuid) {
|
||||
if (!uuidIsValid(uuid)) {
|
||||
if (!Verify.notNull(uuid)) {
|
||||
return false;
|
||||
}
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(uuid);
|
||||
return p.hasPlayedBefore();
|
||||
return Plan.getInstance().fetch().hasPlayedBefore(uuid);
|
||||
}
|
||||
}
|
@ -1,15 +1,9 @@
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.TreeCommand;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.djrapitops.javaplugin.command.*;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.commands.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* CommandExecutor for the /plan command, and all subcommands.
|
||||
@ -17,7 +11,7 @@ import org.bukkit.command.CommandSender;
|
||||
* @author Rsl1122
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class PlanCommand extends TreeCommand<Plan> implements CommandExecutor {
|
||||
public class PlanCommand extends TreeCommand<Plan> {
|
||||
|
||||
/**
|
||||
* CommandExecutor class Constructor.
|
||||
@ -27,15 +21,8 @@ public class PlanCommand extends TreeCommand<Plan> implements CommandExecutor {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public PlanCommand(Plan plugin) {
|
||||
super(plugin, new SubCommand("plan", CommandType.CONSOLE, "") {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
return true;
|
||||
}
|
||||
}, "plan");
|
||||
super(plugin, "plan", CommandType.CONSOLE, "", "", "plan");
|
||||
super.setDefaultCommand("inspect");
|
||||
// commands.add(new HelpCommand(plugin, this));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,5 +35,6 @@ public class PlanCommand extends TreeCommand<Plan> implements CommandExecutor {
|
||||
commands.add(new InfoCommand(plugin));
|
||||
commands.add(new ReloadCommand(plugin));
|
||||
commands.add(new ManageCommand(plugin));
|
||||
commands.add(new StatusCommand(plugin, Permissions.MANAGE.getPermission()));
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,24 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.api.TimeAmount;
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import main.java.com.djrapitops.plan.command.ConditionUtils;
|
||||
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* This subcommand is used to run the analysis and access the /server link.
|
||||
@ -42,26 +43,40 @@ public class AnalyzeCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (!CommandUtils.pluginHasViewCapability()) {
|
||||
sender.sendMessage(Phrase.ERROR_WEBSERVER_OFF_ANALYSIS + "");
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(ConditionUtils.pluginHasViewCapability(), Phrase.ERROR_WEBSERVER_OFF_ANALYSIS + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
if (!Check.ifTrue(analysisCache.isAnalysisEnabled(), Phrase.ERROR_ANALYSIS_DISABLED_TEMPORARILY + "", sender)) {
|
||||
if (!analysisCache.isCached()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
if (!analysisCache.isCached() || MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
updateCache();
|
||||
runMessageSenderTask(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateCache() {
|
||||
if (!analysisCache.isCached() || MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > TimeAmount.MINUTE.ms()) {
|
||||
int bootAnID = plugin.getBootAnalysisTaskID();
|
||||
if (bootAnID != -1) {
|
||||
plugin.getServer().getScheduler().cancelTask(bootAnID);
|
||||
}
|
||||
analysisCache.updateCache();
|
||||
}
|
||||
final BukkitTask analysisMessageSenderTask = new BukkitRunnable() {
|
||||
}
|
||||
|
||||
private void runMessageSenderTask(ISender sender) {
|
||||
plugin.getRunnableFactory().createNew("AnalysisMessageSenderTask", new RslRunnable() {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
timesrun++;
|
||||
if (analysisCache.isCached() && !analysisCache.isAnalysisBeingRun()) {
|
||||
if (analysisCache.isCached() && (!analysisCache.isAnalysisBeingRun() || !analysisCache.isAnalysisEnabled())) {
|
||||
sendAnalysisMessage(sender);
|
||||
this.cancel();
|
||||
return;
|
||||
@ -72,8 +87,7 @@ public class AnalyzeCommand extends SubCommand {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 1 * 20, 5 * 20);
|
||||
return true;
|
||||
}).runTaskTimer(TimeAmount.SECOND.ticks(), 5 * TimeAmount.SECOND.ticks());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,7 +97,7 @@ public class AnalyzeCommand extends SubCommand {
|
||||
*
|
||||
* @param sender Command sender.
|
||||
*/
|
||||
final public void sendAnalysisMessage(CommandSender sender) {
|
||||
private void sendAnalysisMessage(ISender sender) {
|
||||
boolean textUI = Settings.USE_ALTERNATIVE_UI.isTrue();
|
||||
sender.sendMessage(Phrase.CMD_ANALYZE_HEADER + "");
|
||||
if (textUI) {
|
||||
@ -97,13 +111,17 @@ public class AnalyzeCommand extends SubCommand {
|
||||
sender.sendMessage(message + url);
|
||||
} else {
|
||||
sender.sendMessage(message);
|
||||
Player player = (Player) sender;
|
||||
Bukkit.getServer().dispatchCommand(
|
||||
Bukkit.getConsoleSender(),
|
||||
"tellraw " + player.getName() + " [\"\",{\"text\":\"" + Phrase.CMD_CLICK_ME + "\",\"underlined\":true,"
|
||||
+ "\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}}]");
|
||||
sendLink(sender, url);
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
}
|
||||
|
||||
@Deprecated // TODO Will be rewritten to the RslPlugin abstractions in the future.
|
||||
private void sendLink(ISender sender, String url) throws CommandException {
|
||||
plugin.getServer().dispatchCommand(
|
||||
Bukkit.getConsoleSender(),
|
||||
"tellraw " + sender.getName() + " [\"\",{\"text\":\"" + Phrase.CMD_CLICK_ME + "\",\"underlined\":true,"
|
||||
+ "\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}}]");
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,16 @@ package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.utilities.VersionUtils;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* This subcommand is used to view the version and the database type in use.
|
||||
*
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ -26,15 +25,14 @@ public class InfoCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public InfoCommand(Plan plugin) {
|
||||
super("info", CommandType.CONSOLE,Permissions.INFO.getPermission(), Phrase.CMD_USG_INFO + "");
|
||||
super("info", CommandType.CONSOLE, Permissions.INFO.getPermission(), Phrase.CMD_USG_INFO + "");
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
ChatColor tColor = Phrase.COLOR_SEC.color();
|
||||
|
||||
String[] messages = {
|
||||
Phrase.CMD_INFO_HEADER + "",
|
||||
Phrase.CMD_INFO_VERSION.parse(plugin.getDescription().getVersion()),
|
||||
|
@ -1,26 +1,26 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.api.TimeAmount;
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.CommandUtils;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.command.Condition;
|
||||
import main.java.com.djrapitops.plan.command.ConditionUtils;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* This command is used to cache UserData to InspectCache and display the link.
|
||||
@ -46,75 +46,94 @@ public class InspectCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (!CommandUtils.pluginHasViewCapability()) {
|
||||
sender.sendMessage(Phrase.ERROR_WEBSERVER_OFF_INSPECT + "");
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(ConditionUtils.pluginHasViewCapability(), Phrase.ERROR_WEBSERVER_OFF_INSPECT + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String playerName = MiscUtils.getPlayerName(args, sender);
|
||||
final BukkitTask inspectTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = CommandUtils.getUUID(playerName);
|
||||
Condition[] preConditions = new Condition[]{
|
||||
new Condition(CommandUtils.uuidIsValid(uuid), Phrase.USERNAME_NOT_VALID.toString()),
|
||||
new Condition(CommandUtils.playerHasPlayed(uuid), Phrase.USERNAME_NOT_SEEN.toString()),
|
||||
new Condition(plugin.getDB().wasSeenBefore(uuid), Phrase.USERNAME_NOT_KNOWN.toString())
|
||||
};
|
||||
|
||||
for (Condition condition : preConditions) {
|
||||
if (!condition.pass()) {
|
||||
sender.sendMessage(condition.getFailMsg());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
inspectCache.cache(uuid);
|
||||
final BukkitTask inspectMessageSenderTask = new BukkitRunnable() {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
timesrun++;
|
||||
if (inspectCache.isCached(uuid)) {
|
||||
sendInspectMsg(sender, playerName, uuid);
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (timesrun > 10) {
|
||||
Log.debug("Command Timeout Message, Inspect.");
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Inspect"));
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}.runTaskTimer(plugin, 1 * 20, 5 * 20);
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
runInspectTask(playerName, sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendInspectMsg(CommandSender sender, String playerName, UUID uuid) throws CommandException {
|
||||
private void runInspectTask(String playerName, ISender sender) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("InspectTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
UUID uuid = ConditionUtils.getUUID(playerName);
|
||||
if (!Check.ifTrue(Verify.notNull(uuid), Phrase.USERNAME_NOT_VALID.toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
if (!Check.ifTrue(ConditionUtils.playerHasPlayed(uuid), Phrase.USERNAME_NOT_SEEN.toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
if (!Check.ifTrue(plugin.getDB().wasSeenBefore(uuid), Phrase.USERNAME_NOT_KNOWN.toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
|
||||
inspectCache.cache(uuid);
|
||||
runMessageSenderTask(uuid, sender, playerName);
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
|
||||
private void runMessageSenderTask(UUID uuid, ISender sender, String playerName) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("InspectMessageSenderTask") {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
timesrun++;
|
||||
if (inspectCache.isCached(uuid)) {
|
||||
sendInspectMsg(sender, playerName, uuid);
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (timesrun > 10) {
|
||||
Log.debug("Command Timeout Message, Inspect.");
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Inspect"));
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}).runTaskTimer(TimeAmount.SECOND.ticks(), 5 * TimeAmount.SECOND.ticks());
|
||||
}
|
||||
|
||||
private void sendInspectMsg(ISender sender, String playerName, UUID uuid) {
|
||||
|
||||
boolean usingTextUI = Settings.USE_ALTERNATIVE_UI.isTrue();
|
||||
|
||||
sender.sendMessage(Phrase.CMD_INSPECT_HEADER + playerName);
|
||||
if (Settings.USE_ALTERNATIVE_UI.isTrue()) {
|
||||
|
||||
if (usingTextUI) {
|
||||
sender.sendMessage(TextUI.getInspectMessages(uuid));
|
||||
} else {
|
||||
// Link
|
||||
String url = HtmlUtils.getInspectUrlWithProtocol(playerName);
|
||||
String message = Phrase.CMD_LINK + "";
|
||||
boolean console = !(sender instanceof Player);
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
if (console) {
|
||||
sender.sendMessage(message + url);
|
||||
} else {
|
||||
sender.sendMessage(message);
|
||||
Player player = (Player) sender;
|
||||
Bukkit.getServer().dispatchCommand(
|
||||
Bukkit.getConsoleSender(),
|
||||
"tellraw " + player.getName() + " [\"\",{\"text\":\"" + Phrase.CMD_CLICK_ME + "\",\"underlined\":true,"
|
||||
+ "\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}}]");
|
||||
sendLink(sender, url);
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
}
|
||||
|
||||
@Deprecated // TODO Will be rewritten to the RslPlugin abstractions in the future.
|
||||
private void sendLink(ISender sender, String url) throws CommandException {
|
||||
plugin.getServer().dispatchCommand(
|
||||
Bukkit.getConsoleSender(),
|
||||
"tellraw " + sender.getName() + " [\"\",{\"text\":\"" + Phrase.CMD_CLICK_ME + "\",\"underlined\":true,"
|
||||
+ "\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}}]");
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.TreeCommand;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.commands.manage.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* This command is used to manage the database of the plugin.
|
||||
@ -26,12 +23,7 @@ public class ManageCommand extends TreeCommand<Plan> {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public ManageCommand(Plan plugin) {
|
||||
super(plugin, new SubCommand("manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE + "") {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
return true;
|
||||
}
|
||||
}, "plan manage");
|
||||
super(plugin, "manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Phrase.CMD_USG_MANAGE + "", "plan manage");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,18 +1,19 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.api.TimeAmount;
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.ConditionUtils;
|
||||
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* This subcommand is used to run the analysis and to view some of the data in
|
||||
@ -38,25 +39,39 @@ public class QuickAnalyzeCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
if (!analysisCache.isCached()) {
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(ConditionUtils.pluginHasViewCapability(), Phrase.ERROR_WEBSERVER_OFF_ANALYSIS + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
if (!Check.ifTrue(analysisCache.isAnalysisEnabled(), Phrase.ERROR_ANALYSIS_DISABLED_TEMPORARILY + "", sender)) {
|
||||
if (!analysisCache.isCached()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
updateCache();
|
||||
|
||||
runMessageSenderTask(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateCache() {
|
||||
if (!analysisCache.isCached() || MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > TimeAmount.MINUTE.ms()) {
|
||||
int bootAnID = plugin.getBootAnalysisTaskID();
|
||||
if (bootAnID != -1) {
|
||||
plugin.getServer().getScheduler().cancelTask(bootAnID);
|
||||
}
|
||||
analysisCache.updateCache();
|
||||
} else if (MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
analysisCache.updateCache();
|
||||
}
|
||||
}
|
||||
|
||||
BukkitTask analysisMessageSenderTask = new BukkitRunnable() {
|
||||
private void runMessageSenderTask(ISender sender) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("QanalysisMessageSenderTask") {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
timesrun++;
|
||||
if (analysisCache.isCached() && !analysisCache.isAnalysisBeingRun()) {
|
||||
if (analysisCache.isCached() && (!analysisCache.isAnalysisBeingRun() || !analysisCache.isAnalysisEnabled())) {
|
||||
sender.sendMessage(Phrase.CMD_ANALYZE_HEADER + "");
|
||||
sender.sendMessage(TextUI.getAnalysisMessages());
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
@ -68,7 +83,6 @@ public class QuickAnalyzeCommand extends SubCommand {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 1 * 20, 5 * 20);
|
||||
return true;
|
||||
}).runTaskTimer(TimeAmount.SECOND.ticks(), 5 * TimeAmount.SECOND.ticks());
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.api.TimeAmount;
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import main.java.com.djrapitops.plan.command.Condition;
|
||||
import main.java.com.djrapitops.plan.command.ConditionUtils;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* This command is used to cache UserData to InspectCache and to view some of
|
||||
@ -35,55 +35,59 @@ public class QuickInspectCommand extends SubCommand {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public QuickInspectCommand(Plan plugin) {
|
||||
super("qinspect", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.QUICK_INSPECT.getPermission(), Phrase.CMD_USG_QINSPECT + "", Phrase.ARG_PLAYER + "");
|
||||
super("qinspect", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.QUICK_INSPECT.getPermission(), Phrase.CMD_USG_QINSPECT + "", Phrase.ARG_PLAYER + "");
|
||||
|
||||
this.plugin = plugin;
|
||||
inspectCache = plugin.getInspectCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.QUICK_INSPECT_OTHER);
|
||||
final BukkitTask inspectTask = new BukkitRunnable() {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("QinspectTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = CommandUtils.getUUID(playerName);
|
||||
Condition[] preConditions = new Condition[]{
|
||||
new Condition(CommandUtils.uuidIsValid(uuid), Phrase.USERNAME_NOT_VALID.toString()),
|
||||
new Condition(CommandUtils.playerHasPlayed(uuid), Phrase.USERNAME_NOT_SEEN.toString()),
|
||||
new Condition(plugin.getDB().wasSeenBefore(uuid), Phrase.USERNAME_NOT_KNOWN.toString())
|
||||
};
|
||||
|
||||
for (Condition condition : preConditions) {
|
||||
if (!condition.pass()) {
|
||||
sender.sendMessage(condition.getFailMsg());
|
||||
this.cancel();
|
||||
try {
|
||||
UUID uuid = ConditionUtils.getUUID(playerName);
|
||||
if (!Check.ifTrue(Verify.notNull(uuid), Phrase.USERNAME_NOT_VALID.toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
inspectCache.cache(uuid);
|
||||
final BukkitTask inspectMessageSenderTask = new BukkitRunnable() {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
timesrun++;
|
||||
if (inspectCache.isCached(uuid)) {
|
||||
sender.sendMessage(Phrase.CMD_INSPECT_HEADER + playerName);
|
||||
sender.sendMessage(TextUI.getInspectMessages(uuid));
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
this.cancel();
|
||||
}
|
||||
if (timesrun > 10) {
|
||||
Log.debug("Command Timeout Message, QuickInspect.");
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Qinspect"));
|
||||
this.cancel();
|
||||
}
|
||||
if (!Check.ifTrue(ConditionUtils.playerHasPlayed(uuid), Phrase.USERNAME_NOT_SEEN.toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
}.runTaskTimer(plugin, 1 * 20, 5 * 20);
|
||||
if (!Check.ifTrue(plugin.getDB().wasSeenBefore(uuid), Phrase.USERNAME_NOT_KNOWN.toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
inspectCache.cache(uuid);
|
||||
runMessageSenderTask(uuid, sender, playerName);
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}).runTaskAsynchronously();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runMessageSenderTask(UUID uuid, ISender sender, String playerName) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("QinspectMessageSenderTask") {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
timesrun++;
|
||||
if (inspectCache.isCached(uuid)) {
|
||||
sender.sendMessage(Phrase.CMD_INSPECT_HEADER + playerName);
|
||||
sender.sendMessage(TextUI.getInspectMessages(uuid));
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
this.cancel();
|
||||
}
|
||||
if (timesrun > 10) {
|
||||
Log.debug("Command Timeout Message, QuickInspect.");
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Qinspect"));
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskTimer(TimeAmount.SECOND.ticks(), 5 * TimeAmount.SECOND.ticks());
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,10 @@ package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* This subcommand is used to reload the plugin.
|
||||
@ -30,7 +29,7 @@ public class ReloadCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
plugin.onDisable();
|
||||
plugin.reloadConfig();
|
||||
plugin.onEnable();
|
||||
|
@ -2,25 +2,16 @@ package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.FormattingUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import main.java.com.djrapitops.plan.command.Condition;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* This subcommand is used to search for a user, and to view all matches' data.
|
||||
@ -31,7 +22,6 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
public class SearchCommand extends SubCommand {
|
||||
|
||||
private final Plan plugin;
|
||||
private final InspectCacheHandler inspectCache;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -41,70 +31,37 @@ public class SearchCommand extends SubCommand {
|
||||
public SearchCommand(Plan plugin) {
|
||||
super("search", CommandType.CONSOLE_WITH_ARGUMENTS, Permissions.SEARCH.getPermission(), Phrase.CMD_USG_SEARCH + "", Phrase.ARG_SEARCH + "");
|
||||
this.plugin = plugin;
|
||||
inspectCache = plugin.getInspectCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (!CommandUtils.pluginHasViewCapability()) {
|
||||
sender.sendMessage(Phrase.ERROR_WEBSERVER_OFF_ANALYSIS.toString());
|
||||
return true;
|
||||
}
|
||||
Condition c = new Condition(args.length != 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString());
|
||||
if (c.pass()) {
|
||||
sender.sendMessage(c.getFailMsg());
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString(), sender)) {
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(Phrase.CMD_SEARCH_SEARCHING + "");
|
||||
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
Set<OfflinePlayer> matches = MiscUtils.getMatchingDisplaynames(args[0]);
|
||||
final BukkitTask searchTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
for (OfflinePlayer match : matches) {
|
||||
UUID uuid = match.getUniqueId();
|
||||
if (plugin.getDB().wasSeenBefore(uuid)) {
|
||||
uuids.add(uuid);
|
||||
inspectCache.cache(uuid);
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Phrase.CMD_SEARCH_HEADER + args[0]);
|
||||
// Results
|
||||
if (uuids.isEmpty()) {
|
||||
sender.sendMessage(Phrase.CMD_NO_RESULTS.parse(Arrays.toString(args)));
|
||||
} else {
|
||||
for (OfflinePlayer match : matches) {
|
||||
if (!uuids.contains(match.getUniqueId())) {
|
||||
continue;
|
||||
}
|
||||
String name = match.getName();
|
||||
sender.sendMessage(Phrase.CMD_MATCH + name);
|
||||
// Link
|
||||
String url = HtmlUtils.getInspectUrlWithProtocol(name);
|
||||
String message = Phrase.CMD_LINK + "";
|
||||
boolean console = !(sender instanceof Player);
|
||||
if (console) {
|
||||
sender.sendMessage(message + url);
|
||||
} else {
|
||||
sender.sendMessage(message);
|
||||
Player player = (Player) sender;
|
||||
final BukkitTask link = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.getServer().dispatchCommand(
|
||||
Bukkit.getConsoleSender(),
|
||||
"tellraw " + player.getName() + " [\"\",{\"text\":\"Click Me\",\"underlined\":true,"
|
||||
+ "\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}}]");
|
||||
}
|
||||
}.runTask(plugin);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
runSearchTask(args, sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runSearchTask(String[] args, ISender sender) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("SearchTask: " + Arrays.toString(args)) {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<String> names = MiscUtils.getMatchingPlayerNames(args[0]);
|
||||
sender.sendMessage(Phrase.CMD_SEARCH_HEADER + args[0] + " (" + names.size() + ")");
|
||||
// Results
|
||||
if (names.isEmpty()) {
|
||||
sender.sendMessage(Phrase.CMD_NO_RESULTS.parse(Arrays.toString(args)));
|
||||
} else {
|
||||
sender.sendMessage(Phrase.CMD_MATCH + "" + FormattingUtils.collectionToStringNoBrackets(names));
|
||||
}
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,16 @@ package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to backup a database to a .db file.
|
||||
@ -20,7 +21,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
*/
|
||||
public class ManageBackupCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -34,48 +35,50 @@ public class ManageBackupCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
try {
|
||||
if (args.length < 1) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_BACKUP + ""));
|
||||
if (!Check.ifTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_BACKUP + ""), sender)) {
|
||||
return true;
|
||||
}
|
||||
String db = args[0].toLowerCase();
|
||||
if (!db.equals("mysql") && !db.equals("sqlite")) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_INCORRECT_DB + db);
|
||||
String dbName = args[0].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
|
||||
if (Check.ifTrue(isCorrectDB, Phrase.MANAGE_ERROR_INCORRECT_DB + dbName, sender)) {
|
||||
return true;
|
||||
}
|
||||
Database database = null;
|
||||
for (Database sqldb : plugin.getDatabases()) {
|
||||
if (db.equalsIgnoreCase(sqldb.getConfigName())) {
|
||||
database = sqldb;
|
||||
if (!database.init()) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (database == null) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
Log.error(db + " was null!");
|
||||
|
||||
final Database database = ManageUtils.getDB(plugin, dbName);
|
||||
|
||||
// If DB is null return
|
||||
if (!Check.ifTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) {
|
||||
Log.error(dbName + " was null!");
|
||||
return true;
|
||||
}
|
||||
final Database copyFromDB = database;
|
||||
(new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
if (ManageUtils.backup(args[0], copyFromDB)) {
|
||||
sender.sendMessage(Phrase.MANAGE_COPY_SUCCESS.toString());
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString());
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
|
||||
runBackupTask(sender, args, database);
|
||||
} catch (NullPointerException e) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runBackupTask(ISender sender, String[] args, final Database database) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("BackupTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
if (ManageUtils.backup(args[0], database)) {
|
||||
sender.sendMessage(Phrase.MANAGE_COPY_SUCCESS.toString());
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName() + " " + getTaskName(), e);
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString());
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,16 @@ package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to clear a database of all data.
|
||||
@ -35,40 +35,38 @@ public class ManageCleanCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "");
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(args.length != 0, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
String dbToClear = args[0].toLowerCase();
|
||||
if (!dbToClear.equals("mysql") && !dbToClear.equals("sqlite")) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_INCORRECT_DB + dbToClear);
|
||||
String dbName = args[0].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
|
||||
|
||||
if (!Check.ifTrue(isCorrectDB, Phrase.MANAGE_ERROR_INCORRECT_DB + dbName, sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Database clearDB = null;
|
||||
for (Database database : plugin.getDatabases()) {
|
||||
if (dbToClear.equalsIgnoreCase(database.getConfigName())) {
|
||||
clearDB = database;
|
||||
clearDB.init();
|
||||
}
|
||||
}
|
||||
if (clearDB == null) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
Log.error(dbToClear + " was null!");
|
||||
final Database database = ManageUtils.getDB(plugin, dbName);
|
||||
|
||||
// If DB is null return
|
||||
if (!Check.ifTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) {
|
||||
Log.error(dbName + " was null!");
|
||||
return true;
|
||||
}
|
||||
|
||||
final Database clearThisDB = clearDB;
|
||||
(new BukkitRunnable() {
|
||||
runCleanTask(sender, database);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runCleanTask(ISender sender, final Database database) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("DBCleanTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
clearThisDB.clean();
|
||||
database.clean();
|
||||
sender.sendMessage(Phrase.MANAGE_SUCCESS + "");
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
return true;
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,17 @@ package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to clear a database of all data.
|
||||
@ -35,41 +36,42 @@ public class ManageClearCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "");
|
||||
return true;
|
||||
}
|
||||
String dbToClear = args[0].toLowerCase();
|
||||
if (!dbToClear.equals("mysql") && !dbToClear.equals("sqlite")) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_INCORRECT_DB + dbToClear);
|
||||
return true;
|
||||
}
|
||||
if (!Arrays.asList(args).contains("-a")) {
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_REMOVE.parse(args[0])));
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Database clearDB = null;
|
||||
for (Database database : plugin.getDatabases()) {
|
||||
if (dbToClear.equalsIgnoreCase(database.getConfigName())) {
|
||||
clearDB = database;
|
||||
clearDB.init();
|
||||
}
|
||||
}
|
||||
if (clearDB == null) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
Log.error(dbToClear + " was null!");
|
||||
String dbName = args[0].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
|
||||
|
||||
if (!Check.ifTrue(isCorrectDB, Phrase.MANAGE_ERROR_INCORRECT_DB + dbName, sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Database clearThisDB = clearDB;
|
||||
(new BukkitRunnable() {
|
||||
if (!Check.ifTrue(Verify.contains("-a", args), Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_REMOVE.parse(args[0])), sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Database database = ManageUtils.getDB(plugin, dbName);
|
||||
|
||||
// If DB is null return
|
||||
if (!Check.ifTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) {
|
||||
Log.error(dbName + " was null!");
|
||||
return true;
|
||||
}
|
||||
|
||||
runClearTask(sender, database);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runClearTask(ISender sender, final Database database) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("DBClearTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
try {
|
||||
if (clearThisDB.removeAllData()) {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
|
||||
if (database.removeAllData()) {
|
||||
sender.sendMessage(Phrase.MANAGE_CLEAR_SUCCESS + "");
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
@ -77,10 +79,10 @@ public class ManageClearCommand extends SubCommand {
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
return true;
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,15 @@ package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.sql.SQLException;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to swap to a different database and reload the
|
||||
@ -34,31 +35,38 @@ public class ManageHotswapCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "");
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
String dbToSwapTo = args[0].toLowerCase();
|
||||
if (!dbToSwapTo.equals("mysql") && !dbToSwapTo.equals("sqlite")) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_INCORRECT_DB + dbToSwapTo);
|
||||
String dbName = args[0].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
|
||||
|
||||
if (!Check.ifTrue(isCorrectDB, Phrase.MANAGE_ERROR_INCORRECT_DB + dbName, sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Check.ifTrue(dbName.equals(plugin.getDB().getConfigName()), Phrase.MANAGE_ERROR_SAME_DB + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Database database = ManageUtils.getDB(plugin, dbName);
|
||||
|
||||
// If DB is null return
|
||||
if (!Check.ifTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) {
|
||||
Log.error(dbName + " was null!");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
Database db = null;
|
||||
for (Database database : plugin.getDatabases()) {
|
||||
if (dbToSwapTo.equalsIgnoreCase(database.getConfigName())) {
|
||||
db = database;
|
||||
db.init();
|
||||
db.getVersion(); //Test db connection
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException | SQLException e) {
|
||||
database.getVersion(); //Test db connection
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
return true;
|
||||
}
|
||||
plugin.getConfig().set("database.type", dbToSwapTo);
|
||||
|
||||
plugin.getConfig().set("database.type", dbName);
|
||||
plugin.saveConfig();
|
||||
plugin.onDisable();
|
||||
plugin.onEnable();
|
||||
|
@ -2,7 +2,10 @@ package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.util.Arrays;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.FormattingUtils;
|
||||
import com.djrapitops.javaplugin.utilities.player.Fetch;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -12,11 +15,7 @@ import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.handling.importing.ImportUtils;
|
||||
import main.java.com.djrapitops.plan.data.handling.importing.Importer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayers;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to import data from 3rd party plugins.
|
||||
@ -41,44 +40,57 @@ public class ManageImportCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
|
||||
if (args.length < 1) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString() + " " + Phrase.USE_IMPORT);
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + " " + Phrase.USE_IMPORT, sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String importFromPlugin = args[0].toLowerCase();
|
||||
|
||||
Map<String, Importer> importPlugins = ImportUtils.getImporters();
|
||||
if (!importPlugins.keySet().contains(importFromPlugin)) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_INCORRECT_PLUGIN + importFromPlugin);
|
||||
if (importFromPlugin.equals("list")) {
|
||||
list(importPlugins, sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ImportUtils.isPluginEnabled(importFromPlugin)) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_PLUGIN_NOT_ENABLED + importFromPlugin);
|
||||
if (!Check.ifTrue(importPlugins.keySet().contains(importFromPlugin), Phrase.MANAGE_ERROR_INCORRECT_PLUGIN + importFromPlugin, sender)) {
|
||||
return true;
|
||||
}
|
||||
if (!Check.ifTrue(ImportUtils.isPluginEnabled(importFromPlugin), Phrase.MANAGE_ERROR_PLUGIN_NOT_ENABLED + importFromPlugin, sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Arrays.asList(args).contains("-a")) {
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_OVERWRITE_SOME.parse(plugin.getDB().getConfigName())));
|
||||
return true;
|
||||
}
|
||||
String[] importArguments = FormattingUtils.removeFirstArgument(args);
|
||||
|
||||
final Importer importer = importPlugins.get(importFromPlugin);
|
||||
BukkitTask asyncImportTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sender.sendMessage(Phrase.MANAGE_IMPORTING + "");
|
||||
List<UUID> uuids = Arrays.stream(getOfflinePlayers()).map(p -> p.getUniqueId()).collect(Collectors.toList());
|
||||
if (importer.importData(uuids)) {
|
||||
sender.sendMessage(Phrase.MANAGE_SUCCESS + "");
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
runImportTask(sender, importer, importArguments);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runImportTask(ISender sender, final Importer importer, String... importArguments) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("ImportTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sender.sendMessage(Phrase.MANAGE_IMPORTING + "");
|
||||
List<UUID> uuids = Fetch.getIOfflinePlayers().stream().map(p -> p.getUniqueId()).collect(Collectors.toList());
|
||||
if (importer.importData(uuids, importArguments)) {
|
||||
sender.sendMessage(Phrase.MANAGE_SUCCESS + "");
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
}
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
|
||||
private void list(Map<String, Importer> importers, ISender sender) {
|
||||
sender.sendMessage(Phrase.CMD_FOOTER.parse());
|
||||
importers.entrySet().stream().forEach(e -> {
|
||||
sender.sendMessage(Phrase.CMD_BALL + " " + e.getKey() + ": " + e.getValue().getInfo());
|
||||
});
|
||||
sender.sendMessage(Phrase.CMD_FOOTER.parse());
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import java.util.Arrays;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
@ -10,10 +12,8 @@ import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to move all data from one database to another.
|
||||
@ -25,7 +25,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
*/
|
||||
public class ManageMoveCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -39,77 +39,74 @@ public class ManageMoveCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_MOVE + ""));
|
||||
return true;
|
||||
}
|
||||
String fromDB = args[0].toLowerCase();
|
||||
String toDB = args[1].toLowerCase();
|
||||
if (!fromDB.equals("mysql") && !fromDB.equals("sqlite")) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_INCORRECT_DB + fromDB);
|
||||
return true;
|
||||
}
|
||||
if (!toDB.equals("mysql") && !toDB.equals("sqlite")) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_INCORRECT_DB + toDB);
|
||||
return true;
|
||||
}
|
||||
if (fromDB.equals(toDB)) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_SAME_DB + "");
|
||||
return true;
|
||||
}
|
||||
if (!Arrays.asList(args).contains("-a")) {
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_OVERWRITE.parse(args[1])));
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(args.length >= 2, Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_MOVE + ""), sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Database fromDatabase = null;
|
||||
Database toDatabase = null;
|
||||
for (Database database : plugin.getDatabases()) {
|
||||
if (fromDB.equalsIgnoreCase(database.getConfigName())) {
|
||||
fromDatabase = database;
|
||||
fromDatabase.init();
|
||||
}
|
||||
if (toDB.equalsIgnoreCase(database.getConfigName())) {
|
||||
toDatabase = database;
|
||||
toDatabase.init();
|
||||
}
|
||||
String fromDB = args[0].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(fromDB) || "mysql".equals(fromDB);
|
||||
|
||||
if (!Check.ifTrue(isCorrectDB, Phrase.MANAGE_ERROR_INCORRECT_DB + fromDB, sender)) {
|
||||
return true;
|
||||
}
|
||||
if (fromDatabase == null) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
|
||||
String toDB = args[1].toLowerCase();
|
||||
isCorrectDB = "sqlite".equals(toDB) || "mysql".equals(toDB);
|
||||
|
||||
if (!Check.ifTrue(isCorrectDB, Phrase.MANAGE_ERROR_INCORRECT_DB + toDB, sender)) {
|
||||
return true;
|
||||
}
|
||||
if (!Check.ifTrue(!Verify.equalsIgnoreCase(fromDB, toDB), Phrase.MANAGE_ERROR_SAME_DB + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
if (!Check.ifTrue(Verify.contains("-a", args), Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_REMOVE.parse(args[1])), sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Database fromDatabase = ManageUtils.getDB(plugin, fromDB);
|
||||
|
||||
if (!Check.ifTrue(Verify.notNull(fromDatabase), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) {
|
||||
Log.error(fromDB + " was null!");
|
||||
return true;
|
||||
}
|
||||
if (toDatabase == null) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
|
||||
final Database toDatabase = ManageUtils.getDB(plugin, toDB);
|
||||
|
||||
if (!Check.ifTrue(Verify.notNull(toDatabase), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) {
|
||||
Log.error(toDB + " was null!");
|
||||
return true;
|
||||
}
|
||||
|
||||
final Database moveFromDB = fromDatabase;
|
||||
final Database moveToDB = toDatabase;
|
||||
(new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Collection<UUID> uuids = ManageUtils.getUUIDS(moveFromDB);
|
||||
if (uuids.isEmpty()) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + fromDB + ")");
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
if (ManageUtils.clearAndCopy(moveToDB, moveFromDB, uuids)) {
|
||||
sender.sendMessage(Phrase.MANAGE_MOVE_SUCCESS + "");
|
||||
if (!toDB.equals(plugin.getDB().getConfigName())) {
|
||||
sender.sendMessage(Phrase.MANAGE_DB_CONFIG_REMINDER + "");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
|
||||
runMoveTask(fromDatabase, toDatabase, sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runMoveTask(final Database fromDatabase, final Database toDatabase, ISender sender) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("DBMoveTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final Collection<UUID> uuids = ManageUtils.getUUIDS(fromDatabase);
|
||||
if (Check.ifTrue(Verify.isEmpty(uuids), Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + fromDatabase.getName() + ")", sender)) {
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
if (ManageUtils.clearAndCopy(toDatabase, fromDatabase, uuids)) {
|
||||
sender.sendMessage(Phrase.MANAGE_MOVE_SUCCESS + "");
|
||||
boolean movedToCurrentDatabase = Verify.equalsIgnoreCase(toDatabase.getConfigName(), plugin.getDB().getConfigName());
|
||||
|
||||
Check.ifTrue(!movedToCurrentDatabase, Phrase.MANAGE_DB_CONFIG_REMINDER + "", sender);
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName() + " " + getTaskName(), e);
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString());
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,18 @@ package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to remove a single player's data from the
|
||||
@ -37,54 +37,52 @@ public class ManageRemoveCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString());
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.MANAGE);
|
||||
|
||||
(new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
throw new Exception("Username doesn't exist.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_VALID.toString());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDB().wasSeenBefore(uuid)) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_KNOWN.toString());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (!Arrays.asList(args).contains("-a")) {
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_REMOVE.parse(plugin.getDB().getConfigName())));
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
try {
|
||||
plugin.getHandler().getDataCache().remove(uuid);
|
||||
if (plugin.getDB().removeAccount(uuid.toString())) {
|
||||
sender.sendMessage(Phrase.MANAGE_REMOVE_SUCCESS.parse(playerName, plugin.getDB().getConfigName()));
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
runRemoveTask(playerName, sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runRemoveTask(String playerName, ISender sender, String[] args) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("DBRemoveTask " + playerName) {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
String message = Phrase.USERNAME_NOT_VALID.toString();
|
||||
if (!Check.ifTrue(Verify.notNull(uuid), message, sender)) {
|
||||
return;
|
||||
}
|
||||
message = Phrase.USERNAME_NOT_KNOWN.toString();
|
||||
if (!Check.ifTrue(plugin.getDB().wasSeenBefore(uuid), message, sender)) {
|
||||
return;
|
||||
}
|
||||
message = Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_REMOVE.parse(plugin.getDB().getConfigName()));
|
||||
if (!Check.ifTrue(Verify.contains("-a", args), message, sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
try {
|
||||
plugin.getHandler().getDataCache().remove(uuid);
|
||||
if (plugin.getDB().removeAccount(uuid.toString())) {
|
||||
sender.sendMessage(Phrase.MANAGE_REMOVE_SUCCESS.parse(playerName, plugin.getDB().getConfigName()));
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
}
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
@ -12,11 +14,8 @@ import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to restore a backup.db file in the
|
||||
@ -40,78 +39,72 @@ public class ManageRestoreCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
try {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_RESTORE + ""));
|
||||
return true;
|
||||
}
|
||||
String db = args[1].toLowerCase();
|
||||
if (!db.equals("mysql") && !db.equals("sqlite")) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_INCORRECT_DB + db);
|
||||
return true;
|
||||
}
|
||||
if (!Arrays.asList(args).contains("-a")) {
|
||||
sender.sendMessage(Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_REWRITE.parse(args[1])));
|
||||
return true;
|
||||
}
|
||||
Database database = null;
|
||||
for (Database sqldb : plugin.getDatabases()) {
|
||||
if (db.equalsIgnoreCase(sqldb.getConfigName())) {
|
||||
database = sqldb;
|
||||
if (!database.init()) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (database == null) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
Log.error(db + " was null!");
|
||||
return true;
|
||||
}
|
||||
final Database copyToDB = database;
|
||||
BukkitTask asyncRestoreTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String backupDBName = args[0];
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Check.ifTrue(args.length >= 2, Phrase.COMMAND_REQUIRES_ARGUMENTS.parse(Phrase.USE_RESTORE + ""), sender)) {
|
||||
return true;
|
||||
}
|
||||
String db = args[1].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(db) || "mysql".equals(db);
|
||||
|
||||
File backupDBFile = new File(plugin.getDataFolder(), backupDBName + (backupDBName.contains(".db") ? "" : ".db"));
|
||||
if (!backupDBFile.exists()) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_BACKUP_FILE_NOT_FOUND + " " + args[0]);
|
||||
this.cancel();
|
||||
if (!Check.ifTrue(isCorrectDB, Phrase.MANAGE_ERROR_INCORRECT_DB + db, sender)) {
|
||||
return true;
|
||||
}
|
||||
if (!Check.ifTrue(Verify.contains("-a", args), Phrase.COMMAND_ADD_CONFIRMATION_ARGUMENT.parse(Phrase.WARN_REWRITE.parse(args[1])), sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Database database = ManageUtils.getDB(plugin, db);
|
||||
|
||||
if (!Check.ifTrue(Verify.notNull(database), Phrase.MANAGE_DATABASE_FAILURE + "", sender)) {
|
||||
Log.error(db + " was null!");
|
||||
return true;
|
||||
}
|
||||
|
||||
runRestoreTask(args, sender, database);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runRestoreTask(String[] args, ISender sender, final Database database) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("RestoreTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String backupDBName = args[0];
|
||||
boolean containsDBFileExtension = backupDBName.contains(".db");
|
||||
|
||||
File backupDBFile = new File(plugin.getDataFolder(), backupDBName + (containsDBFileExtension ? "" : ".db"));
|
||||
if (!Check.ifTrue(Verify.exists(backupDBFile), Phrase.MANAGE_ERROR_BACKUP_FILE_NOT_FOUND + " " + args[0], sender)) {
|
||||
return;
|
||||
}
|
||||
if (backupDBName.contains(".db")) {
|
||||
|
||||
if (containsDBFileExtension) {
|
||||
backupDBName = backupDBName.replace(".db", "");
|
||||
}
|
||||
SQLiteDB backupDB = new SQLiteDB(plugin, backupDBName);
|
||||
if (!backupDB.init()) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());
|
||||
final Collection<UUID> uuids = ManageUtils.getUUIDS(backupDB);
|
||||
if (uuids.isEmpty()) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + backupDBName + ")");
|
||||
this.cancel();
|
||||
if (!Check.ifTrue(!Verify.isEmpty(uuids), Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + backupDBName + ")", sender)) {
|
||||
return;
|
||||
}
|
||||
if (ManageUtils.clearAndCopy(copyToDB, backupDB, uuids)) {
|
||||
if (copyToDB.getConfigName().equals(plugin.getDB().getConfigName())) {
|
||||
if (ManageUtils.clearAndCopy(database, backupDB, uuids)) {
|
||||
if (database.getConfigName().equals(plugin.getDB().getConfigName())) {
|
||||
plugin.getHandler().getCommandUseFromDb();
|
||||
}
|
||||
sender.sendMessage(Phrase.MANAGE_COPY_SUCCESS.toString());
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName() + " " + getTaskName(), e);
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL.toString());
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
} catch (NullPointerException e) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,10 @@ package main.java.com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to check the status of the database.
|
||||
@ -29,7 +28,7 @@ public class ManageStatusCommand extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
String[] messages = new String[]{
|
||||
Phrase.CMD_MANAGE_STATUS_HEADER + "",
|
||||
Phrase.CMD_MANAGE_STATUS_ACTIVE_DB.parse(plugin.getDB().getConfigName()),
|
||||
|
@ -9,9 +9,9 @@ import main.java.com.djrapitops.plan.ui.RecentPlayersButtonsCreator;
|
||||
import main.java.com.djrapitops.plan.ui.graphs.PlayerActivityGraphCreator;
|
||||
import main.java.com.djrapitops.plan.ui.tables.SortableCommandUseTableCreator;
|
||||
import main.java.com.djrapitops.plan.ui.tables.SortablePlayersTableCreator;
|
||||
import main.java.com.djrapitops.plan.utilities.PlaceholderUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.Analysis;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.PlaceholderUtils;
|
||||
|
||||
/**
|
||||
* This class is used to store result data from Analysis at runtime.
|
||||
@ -40,6 +40,8 @@ public class AnalysisData {
|
||||
private String punchCardData;
|
||||
private String[] sessionDistributionData;
|
||||
private String[] playtimeDistributionData;
|
||||
private String[] tpsData;
|
||||
private double averageTPS;
|
||||
|
||||
private int newPlayersMonth;
|
||||
private int newPlayersWeek;
|
||||
@ -92,6 +94,7 @@ public class AnalysisData {
|
||||
uniqueJoinsDay = 0;
|
||||
uniqueJoinsWeek = 0;
|
||||
uniqueJoinsMonth = 0;
|
||||
averageTPS = 0;
|
||||
sortablePlayersTable = Html.ERROR_NOT_SET + "";
|
||||
commandUseTableHtml = Html.ERROR_NOT_SET + "";
|
||||
recentPlayers = Html.ERROR_NOT_SET + "";
|
||||
@ -101,6 +104,7 @@ public class AnalysisData {
|
||||
punchCardData = "[]";
|
||||
sessionDistributionData = new String[]{"[]", "[]"};
|
||||
playtimeDistributionData = new String[]{"[]", "[]"};
|
||||
tpsData = new String[]{"[]", "[]", "[]"};
|
||||
playersDataArray = new String[]{"[0]", "[\"No data\"]", "[0]", "[\"No data\"]", "[0]", "[\"No data\"]"};
|
||||
additionalDataReplaceMap = new HashMap<>();
|
||||
}
|
||||
@ -928,59 +932,131 @@ public class AnalysisData {
|
||||
this.playtimeDistributionData = playtimeDistributionData;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getAvgUniqJoins() {
|
||||
return avgUniqJoins;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getAvgUniqJoinsDay() {
|
||||
return avgUniqJoinsDay;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getAvgUniqJoinsWeek() {
|
||||
return avgUniqJoinsWeek;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getAvgUniqJoinsMonth() {
|
||||
return avgUniqJoinsMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param avgUniqJoins
|
||||
*/
|
||||
public void setAvgUniqJoins(int avgUniqJoins) {
|
||||
this.avgUniqJoins = avgUniqJoins;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param avgUniqJoinsDay
|
||||
*/
|
||||
public void setAvgUniqJoinsDay(int avgUniqJoinsDay) {
|
||||
this.avgUniqJoinsDay = avgUniqJoinsDay;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param avgUniqJoinsWeek
|
||||
*/
|
||||
public void setAvgUniqJoinsWeek(int avgUniqJoinsWeek) {
|
||||
this.avgUniqJoinsWeek = avgUniqJoinsWeek;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param avgUniqJoinsMonth
|
||||
*/
|
||||
public void setAvgUniqJoinsMonth(int avgUniqJoinsMonth) {
|
||||
this.avgUniqJoinsMonth = avgUniqJoinsMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getUniqueJoinsDay() {
|
||||
return uniqueJoinsDay;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uniqueJoinsDay
|
||||
*/
|
||||
public void setUniqueJoinsDay(int uniqueJoinsDay) {
|
||||
this.uniqueJoinsDay = uniqueJoinsDay;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getUniqueJoinsWeek() {
|
||||
return uniqueJoinsWeek;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uniqueJoinsWeek
|
||||
*/
|
||||
public void setUniqueJoinsWeek(int uniqueJoinsWeek) {
|
||||
this.uniqueJoinsWeek = uniqueJoinsWeek;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getUniqueJoinsMonth() {
|
||||
return uniqueJoinsMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uniqueJoinsMonth
|
||||
*/
|
||||
public void setUniqueJoinsMonth(int uniqueJoinsMonth) {
|
||||
this.uniqueJoinsMonth = uniqueJoinsMonth;
|
||||
}
|
||||
|
||||
public String[] getTpsData() {
|
||||
return tpsData;
|
||||
}
|
||||
|
||||
public void setTpsData(String[] tpsData) {
|
||||
this.tpsData = tpsData;
|
||||
}
|
||||
|
||||
public double getAverageTPS() {
|
||||
return averageTPS;
|
||||
}
|
||||
|
||||
public void setAverageTPS(double averageTPS) {
|
||||
this.averageTPS = averageTPS;
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +95,14 @@ public class KillData {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 89 * hash + Objects.hashCode(this.victim);
|
||||
hash = 89 * hash + (int) (this.date ^ (this.date >>> 32));
|
||||
hash = 89 * hash + Objects.hashCode(this.weapon);
|
||||
return hash;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.data;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -17,48 +18,27 @@ import main.java.com.djrapitops.plan.utilities.analysis.Analysis;
|
||||
*/
|
||||
public class RawAnalysisData {
|
||||
|
||||
private long gmZero;
|
||||
private long gmOne;
|
||||
private long gmTwo;
|
||||
private long gmThree;
|
||||
private long totalLoginTimes;
|
||||
private long totalPlaytime;
|
||||
private int totalBanned;
|
||||
private int active;
|
||||
private int joinleaver;
|
||||
private int inactive;
|
||||
private long totalKills;
|
||||
private long totalMobKills;
|
||||
private long totalDeaths;
|
||||
private int ops;
|
||||
private List<Integer> ages;
|
||||
private Map<String, Long> latestLogins;
|
||||
private Map<String, Long> playtimes;
|
||||
private List<SessionData> sessiondata;
|
||||
private Map<UUID, List<SessionData>> sortedSessionData;
|
||||
private Map<String, Integer> commandUse;
|
||||
private Map<String, Integer> geolocations;
|
||||
private Map<String, String> geocodes;
|
||||
private List<Long> registered;
|
||||
private final Map<RawData, Long> longValues;
|
||||
private final Map<RawData, Integer> intValues;
|
||||
|
||||
private final List<Integer> ages;
|
||||
private final List<Long> registered;
|
||||
private final Map<String, Long> latestLogins;
|
||||
private final Map<String, Long> playtimes;
|
||||
private final List<SessionData> sessiondata;
|
||||
private final Map<UUID, List<SessionData>> sortedSessionData;
|
||||
private final Map<String, Integer> commandUse;
|
||||
private final Map<String, Integer> geolocations;
|
||||
private final Map<String, String> geocodes;
|
||||
|
||||
/**
|
||||
* Constructor for a new empty dataset.
|
||||
*/
|
||||
public RawAnalysisData() {
|
||||
gmZero = 0;
|
||||
gmOne = 0;
|
||||
gmTwo = 0;
|
||||
gmThree = 0;
|
||||
totalLoginTimes = 0;
|
||||
totalPlaytime = 0;
|
||||
totalBanned = 0;
|
||||
active = 0;
|
||||
joinleaver = 0;
|
||||
inactive = 0;
|
||||
totalKills = 0;
|
||||
totalMobKills = 0;
|
||||
totalDeaths = 0;
|
||||
ops = 0;
|
||||
longValues = new HashMap<>();
|
||||
intValues = new HashMap<>();
|
||||
placeDefaultValues();
|
||||
|
||||
ages = new ArrayList<>();
|
||||
latestLogins = new HashMap<>();
|
||||
playtimes = new HashMap<>();
|
||||
@ -70,6 +50,49 @@ public class RawAnalysisData {
|
||||
registered = new ArrayList<>();
|
||||
}
|
||||
|
||||
private void placeDefaultValues() {
|
||||
longValues.put(RawData.TIME_GM0, 0L);
|
||||
longValues.put(RawData.TIME_GM1, 0L);
|
||||
longValues.put(RawData.TIME_GM2, 0L);
|
||||
longValues.put(RawData.TIME_GM3, 0L);
|
||||
longValues.put(RawData.LOGINTIMES, 0L);
|
||||
longValues.put(RawData.PLAYTIME, 0L);
|
||||
longValues.put(RawData.KILLS, 0L);
|
||||
longValues.put(RawData.MOBKILLS, 0L);
|
||||
longValues.put(RawData.DEATHS, 0L);
|
||||
intValues.put(RawData.AMOUNT_ACTIVE, 0);
|
||||
intValues.put(RawData.AMOUNT_BANNED, 0);
|
||||
intValues.put(RawData.AMOUNT_INACTIVE, 0);
|
||||
intValues.put(RawData.AMOUNT_UNKNOWN, 0);
|
||||
intValues.put(RawData.AMOUNT_OPS, 0);
|
||||
}
|
||||
|
||||
public long getLong(RawData key) {
|
||||
return Verify.nullCheck(longValues.get(key));
|
||||
}
|
||||
|
||||
public int getInt(RawData key) {
|
||||
return Verify.nullCheck(intValues.get(key));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void add(RawData key, long amount) {
|
||||
addTo(key, amount);
|
||||
}
|
||||
|
||||
public void addTo(RawData key, long amount) {
|
||||
Verify.nullCheck(key);
|
||||
Long l = longValues.get(key);
|
||||
Integer i = intValues.get(key);
|
||||
if (Verify.notNull(l)) {
|
||||
longValues.replace(key, l + amount);
|
||||
} else if (Verify.notNull(i)) {
|
||||
intValues.replace(key, i + (int) amount);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Incorrect key: " + key.name());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param country
|
||||
@ -114,230 +137,6 @@ public class RawAnalysisData {
|
||||
return geocodes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param gmZero
|
||||
*/
|
||||
public void addToGmZero(long gmZero) {
|
||||
this.gmZero += gmZero;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param gmOne
|
||||
*/
|
||||
public void addToGmOne(long gmOne) {
|
||||
this.gmOne += gmOne;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param gmTwo
|
||||
*/
|
||||
public void addToGmTwo(long gmTwo) {
|
||||
this.gmTwo += gmTwo;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param gmThree
|
||||
*/
|
||||
public void addGmThree(long gmThree) {
|
||||
this.gmThree += gmThree;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param totalLoginTimes
|
||||
*/
|
||||
public void addTotalLoginTimes(long totalLoginTimes) {
|
||||
this.totalLoginTimes += totalLoginTimes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param totalPlaytime
|
||||
*/
|
||||
public void addTotalPlaytime(long totalPlaytime) {
|
||||
this.totalPlaytime += totalPlaytime;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param totalBanned
|
||||
*/
|
||||
public void addTotalBanned(int totalBanned) {
|
||||
this.totalBanned += totalBanned;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param active
|
||||
*/
|
||||
public void addActive(int active) {
|
||||
this.active += active;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param joinleaver
|
||||
*/
|
||||
public void addJoinleaver(int joinleaver) {
|
||||
this.joinleaver += joinleaver;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param inactive
|
||||
*/
|
||||
public void addInactive(int inactive) {
|
||||
this.inactive += inactive;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param totalKills
|
||||
*/
|
||||
public void addTotalKills(long totalKills) {
|
||||
this.totalKills += totalKills;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param totalMobKills
|
||||
*/
|
||||
public void addTotalMobKills(long totalMobKills) {
|
||||
this.totalMobKills += totalMobKills;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param totalDeaths
|
||||
*/
|
||||
public void addTotalDeaths(long totalDeaths) {
|
||||
this.totalDeaths += totalDeaths;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ops
|
||||
*/
|
||||
public void addOps(int ops) {
|
||||
this.ops += ops;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getGmZero() {
|
||||
return gmZero;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getGmOne() {
|
||||
return gmOne;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getGmTwo() {
|
||||
return gmTwo;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getGmThree() {
|
||||
return gmThree;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getTotalLoginTimes() {
|
||||
return totalLoginTimes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getTotalPlaytime() {
|
||||
return totalPlaytime;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getTotalBanned() {
|
||||
return totalBanned;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getJoinleaver() {
|
||||
return joinleaver;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getInactive() {
|
||||
return inactive;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getTotalKills() {
|
||||
return totalKills;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getTotalMobKills() {
|
||||
return totalMobKills;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getTotalDeaths() {
|
||||
return totalDeaths;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getOps() {
|
||||
return ops;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
@ -370,10 +169,19 @@ public class RawAnalysisData {
|
||||
return sessiondata;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<UUID, List<SessionData>> getSortedSessionData() {
|
||||
return sortedSessionData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uuid
|
||||
* @param sessions
|
||||
*/
|
||||
public void addSessions(UUID uuid, List<SessionData> sessions) {
|
||||
sessiondata.addAll(sessions);
|
||||
sortedSessionData.put(uuid, sessions);
|
||||
@ -384,7 +192,7 @@ public class RawAnalysisData {
|
||||
* @param commandUse
|
||||
*/
|
||||
public void setCommandUse(Map<String, Integer> commandUse) {
|
||||
this.commandUse = commandUse;
|
||||
this.commandUse.putAll(commandUse);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -402,4 +210,5 @@ public class RawAnalysisData {
|
||||
public List<Long> getRegistered() {
|
||||
return registered;
|
||||
}
|
||||
|
||||
}
|
||||
|
27
Plan/src/main/java/com/djrapitops/plan/data/RawData.java
Normal file
27
Plan/src/main/java/com/djrapitops/plan/data/RawData.java
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public enum RawData {
|
||||
TIME_GM0,
|
||||
TIME_GM1,
|
||||
TIME_GM2,
|
||||
TIME_GM3,
|
||||
LOGINTIMES,
|
||||
PLAYTIME,
|
||||
AMOUNT_BANNED,
|
||||
AMOUNT_ACTIVE,
|
||||
AMOUNT_INACTIVE,
|
||||
AMOUNT_UNKNOWN,
|
||||
KILLS,
|
||||
MOBKILLS,
|
||||
DEATHS,
|
||||
AMOUNT_OPS
|
||||
}
|
@ -8,7 +8,7 @@ package main.java.com.djrapitops.plan.data;
|
||||
*/
|
||||
public class SessionData {
|
||||
|
||||
private long sessionStart;
|
||||
private final long sessionStart;
|
||||
private long sessionEnd;
|
||||
|
||||
/**
|
||||
@ -32,10 +32,16 @@ public class SessionData {
|
||||
this.sessionEnd = sessionEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for copying the object.
|
||||
*
|
||||
* @param s SessionData to copy.
|
||||
*/
|
||||
public SessionData(SessionData s) {
|
||||
this.sessionStart = s.getSessionStart();
|
||||
this.sessionEnd = s.getSessionEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the session with given end point.
|
||||
*
|
||||
@ -108,4 +114,12 @@ public class SessionData {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 97 * hash + (int) (this.sessionStart ^ (this.sessionStart >>> 32));
|
||||
hash = 97 * hash + (int) (this.sessionEnd ^ (this.sessionEnd >>> 32));
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
97
Plan/src/main/java/com/djrapitops/plan/data/TPS.java
Normal file
97
Plan/src/main/java/com/djrapitops/plan/data/TPS.java
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.data;
|
||||
|
||||
/**
|
||||
* Class containing single datapoint of TPS/players online.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class TPS {
|
||||
|
||||
private final long date;
|
||||
private final double tps;
|
||||
private final int players;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param date time of the average calculation.
|
||||
* @param tps average tps for the last minute.
|
||||
* @param players average players for the last minute.
|
||||
*/
|
||||
public TPS(long date, double tps, int players) {
|
||||
this.date = date;
|
||||
this.tps = tps;
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time of the average calculation.
|
||||
*
|
||||
* @return epoch ms.
|
||||
*/
|
||||
public long getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the average tps for the minute.
|
||||
*
|
||||
* @return 0-20 double
|
||||
*/
|
||||
public double getTps() {
|
||||
return tps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the average players for the minute.
|
||||
*
|
||||
* @return Players online.
|
||||
*/
|
||||
public int getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 97 * hash + (int) (this.date ^ (this.date >>> 32));
|
||||
hash = 97 * hash + (int) (Double.doubleToLongBits(this.tps) ^ (Double.doubleToLongBits(this.tps) >>> 32));
|
||||
hash = 97 * hash + this.players;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final TPS other = (TPS) obj;
|
||||
if (this.date != other.date) {
|
||||
return false;
|
||||
}
|
||||
if (Double.doubleToLongBits(this.tps) != Double.doubleToLongBits(other.tps)) {
|
||||
return false;
|
||||
}
|
||||
if (this.players != other.players) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TPS{" + date + "|" + tps + "|" + players + '}';
|
||||
}
|
||||
}
|
@ -1,5 +1,11 @@
|
||||
package main.java.com.djrapitops.plan.data;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import com.djrapitops.javaplugin.utilities.player.BukkitOfflinePlayer;
|
||||
import com.djrapitops.javaplugin.utilities.player.BukkitPlayer;
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import com.djrapitops.javaplugin.utilities.player.IOfflinePlayer;
|
||||
import com.djrapitops.javaplugin.utilities.player.IPlayer;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -14,8 +20,6 @@ import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* This class is used for storing information about a player during runtime.
|
||||
@ -28,7 +32,6 @@ public class UserData {
|
||||
private boolean clearAfterSave;
|
||||
|
||||
private UUID uuid;
|
||||
private Location location;
|
||||
private List<Location> locations;
|
||||
private Set<InetAddress> ips;
|
||||
private Set<String> nicknames;
|
||||
@ -39,8 +42,8 @@ public class UserData {
|
||||
private int loginTimes;
|
||||
private int timesKicked;
|
||||
private long lastGmSwapTime;
|
||||
private GameMode lastGamemode;
|
||||
private Map<GameMode, Long> gmTimes;
|
||||
private Gamemode lastGamemode;
|
||||
private Map<Gamemode, Long> gmTimes;
|
||||
private boolean isOp;
|
||||
private boolean isBanned;
|
||||
private DemographicsData demData;
|
||||
@ -55,6 +58,11 @@ public class UserData {
|
||||
private SessionData currentSession;
|
||||
private List<SessionData> sessions;
|
||||
|
||||
@Deprecated
|
||||
public UserData(UUID uuid, long reg, Location loc, boolean op, GameMode lastGM, DemographicsData demData, String name, boolean online) {
|
||||
this(uuid, reg, loc, op, Gamemode.wrap(lastGM), demData, name, online);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new UserData object with given values and default values.
|
||||
*
|
||||
@ -79,22 +87,21 @@ public class UserData {
|
||||
* @param name Name of the player.
|
||||
* @param online Is the player online?
|
||||
*/
|
||||
public UserData(UUID uuid, long reg, Location loc, boolean op, GameMode lastGM, DemographicsData demData, String name, boolean online) {
|
||||
public UserData(UUID uuid, long reg, Location loc, boolean op, Gamemode lastGM, DemographicsData demData, String name, boolean online) {
|
||||
accessing = 0;
|
||||
this.uuid = uuid;
|
||||
registered = reg;
|
||||
location = loc;
|
||||
isOp = op;
|
||||
locations = new ArrayList<>();
|
||||
nicknames = new HashSet<>();
|
||||
ips = new HashSet<>();
|
||||
gmTimes = new HashMap<>();
|
||||
long zero = 0;
|
||||
gmTimes.put(GameMode.SURVIVAL, zero);
|
||||
gmTimes.put(GameMode.CREATIVE, zero);
|
||||
gmTimes.put(GameMode.ADVENTURE, zero);
|
||||
gmTimes.put(Gamemode.SURVIVAL, zero);
|
||||
gmTimes.put(Gamemode.CREATIVE, zero);
|
||||
gmTimes.put(Gamemode.ADVENTURE, zero);
|
||||
try {
|
||||
gmTimes.put(GameMode.SPECTATOR, zero);
|
||||
gmTimes.put(Gamemode.SPECTATOR, zero);
|
||||
} catch (NoSuchFieldError e) {
|
||||
}
|
||||
lastGamemode = lastGM;
|
||||
@ -123,8 +130,12 @@ public class UserData {
|
||||
* @param player Player object.
|
||||
* @param demData Demographics data.
|
||||
*/
|
||||
public UserData(Player player, DemographicsData demData) {
|
||||
this(player.getUniqueId(), player.getFirstPlayed(), player.getLocation(), player.isOp(), player.getGameMode(), demData, player.getName(), player.isOnline());
|
||||
public UserData(org.bukkit.entity.Player player, DemographicsData demData) {
|
||||
this(BukkitPlayer.wrap(player), demData);
|
||||
}
|
||||
|
||||
public UserData(IPlayer player, DemographicsData demData) {
|
||||
this(player.getUuid(), player.getFirstPlayed(), null, player.isOp(), player.getGamemode(), demData, player.getName(), player.isOnline());
|
||||
try {
|
||||
isBanned = player.isBanned();
|
||||
} catch (Exception e) {
|
||||
@ -155,8 +166,13 @@ public class UserData {
|
||||
* @param player OfflinePlayer object.
|
||||
* @param demData Demographics data.
|
||||
*/
|
||||
public UserData(OfflinePlayer player, DemographicsData demData) {
|
||||
this(player.getUniqueId(), player.getFirstPlayed(), null, player.isOp(), GameMode.SURVIVAL, demData, player.getName(), player.isOnline());
|
||||
@Deprecated
|
||||
public UserData(org.bukkit.OfflinePlayer player, DemographicsData demData) {
|
||||
this(BukkitOfflinePlayer.wrap(player), demData);
|
||||
}
|
||||
|
||||
public UserData(IOfflinePlayer player, DemographicsData demData) {
|
||||
this(player.getUniqueId(), player.getFirstPlayed(), null, player.isOp(), Gamemode.SURVIVAL, demData, player.getName(), player.isOnline());
|
||||
try {
|
||||
isBanned = player.isBanned();
|
||||
} catch (Exception e) {
|
||||
@ -174,7 +190,6 @@ public class UserData {
|
||||
public UserData(UserData data) {
|
||||
this.accessing = 0;
|
||||
this.uuid = data.getUuid();
|
||||
this.location = data.getLocation();
|
||||
this.locations = new ArrayList<>();
|
||||
locations.addAll(data.getLocations());
|
||||
this.ips = new HashSet<>();
|
||||
@ -209,7 +224,11 @@ public class UserData {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" + "accessing:" + accessing + "|uuid:" + uuid + "|location:" + location + "|locations:" + locations.size() + "|ips:" + ips + "|nicknames:" + nicknames + "|lastNick:" + lastNick + "|registered:" + registered + "|lastPlayed:" + lastPlayed + "|playTime:" + playTime + "|loginTimes:" + loginTimes + "|timesKicked:" + timesKicked + "|lastGmSwapTime:" + lastGmSwapTime + "|lastGamemode:" + lastGamemode + "|gmTimes:" + gmTimes + "|isOp:" + isOp + "|isBanned:" + isBanned + "|demData:" + demData + "|mobKills:" + mobKills + "|playerKills:" + playerKills + "|deaths:" + deaths + "|name:" + name + "|isOnline:" + isOnline + "|currentSession:" + currentSession + "|sessions:" + sessions + '}';
|
||||
try {
|
||||
return "{" + "accessing:" + accessing + "|uuid:" + uuid + "|locations:" + locations.size() + "|ips:" + ips + "|nicknames:" + nicknames + "|lastNick:" + lastNick + "|registered:" + registered + "|lastPlayed:" + lastPlayed + "|playTime:" + playTime + "|loginTimes:" + loginTimes + "|timesKicked:" + timesKicked + "|lastGmSwapTime:" + lastGmSwapTime + "|lastGamemode:" + lastGamemode + "|gmTimes:" + gmTimes + "|isOp:" + isOp + "|isBanned:" + isBanned + "|demData:" + demData + "|mobKills:" + mobKills + "|playerKills:" + playerKills + "|deaths:" + deaths + "|name:" + name + "|isOnline:" + isOnline + "|currentSession:" + currentSession + "|sessions:" + sessions + '}';
|
||||
} catch (Throwable e) {
|
||||
return "UserData: Error on toString:" + e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,7 +237,7 @@ public class UserData {
|
||||
* @param ip InetAddress of the player.
|
||||
*/
|
||||
public void addIpAddress(InetAddress ip) {
|
||||
if (ip != null) {
|
||||
if (Verify.notNull(ip)) {
|
||||
ips.add(ip);
|
||||
}
|
||||
}
|
||||
@ -232,21 +251,20 @@ public class UserData {
|
||||
if (addIps.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ips.addAll(addIps.stream().filter(ip -> ip != null).collect(Collectors.toList()));
|
||||
ips.addAll(addIps.stream().filter(ip -> Verify.notNull(ip)).collect(Collectors.toList()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a location to the locations list.
|
||||
*
|
||||
* null value filtered. loc will be set as the latest location.
|
||||
* null value filtered.
|
||||
*
|
||||
* @param loc Location of the player.
|
||||
*/
|
||||
public void addLocation(Location loc) {
|
||||
if (loc != null) {
|
||||
if (Verify.notNull(loc)) {
|
||||
locations.add(loc);
|
||||
location = loc;
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,7 +279,6 @@ public class UserData {
|
||||
if (!addLocs.isEmpty()) {
|
||||
List<Location> locs = addLocs.stream().filter(l -> l != null).collect(Collectors.toList());
|
||||
locations.addAll(locs);
|
||||
location = locations.get(locations.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,7 +293,7 @@ public class UserData {
|
||||
* @return was lastNick updated?
|
||||
*/
|
||||
public boolean addNickname(String nick) {
|
||||
if (nick != null && !nick.isEmpty()) {
|
||||
if (!Verify.isEmpty(nick)) {
|
||||
boolean isNew = !nicknames.contains(nick);
|
||||
nicknames.add(nick);
|
||||
if (isNew) {
|
||||
@ -295,7 +312,7 @@ public class UserData {
|
||||
* @param addNicks Collection of nicknames.
|
||||
*/
|
||||
public void addNicknames(Collection<String> addNicks) {
|
||||
nicknames.addAll(addNicks.stream().filter(nick -> nick != null && !nick.isEmpty()).collect(Collectors.toList()));
|
||||
nicknames.addAll(addNicks.stream().filter(nick -> !Verify.isEmpty(nick)).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -304,11 +321,11 @@ public class UserData {
|
||||
* @param gm GameMode.
|
||||
* @param time Milliseconds spent in the gamemode.
|
||||
*/
|
||||
public void setGMTime(GameMode gm, long time) {
|
||||
if (gmTimes == null) {
|
||||
public void setGMTime(Gamemode gm, long time) {
|
||||
if (!Verify.notNull(gmTimes)) {
|
||||
gmTimes = new HashMap<>();
|
||||
}
|
||||
if (gm != null) {
|
||||
if (Verify.notNull(gm)) {
|
||||
gmTimes.put(gm, time);
|
||||
}
|
||||
}
|
||||
@ -323,11 +340,11 @@ public class UserData {
|
||||
*/
|
||||
public void setAllGMTimes(long survivalTime, long creativeTime, long adventureTime, long spectatorTime) {
|
||||
gmTimes.clear();
|
||||
gmTimes.put(GameMode.SURVIVAL, survivalTime);
|
||||
gmTimes.put(GameMode.CREATIVE, creativeTime);
|
||||
gmTimes.put(GameMode.ADVENTURE, adventureTime);
|
||||
gmTimes.put(Gamemode.SURVIVAL, survivalTime);
|
||||
gmTimes.put(Gamemode.CREATIVE, creativeTime);
|
||||
gmTimes.put(Gamemode.ADVENTURE, adventureTime);
|
||||
try {
|
||||
gmTimes.put(GameMode.SPECTATOR, spectatorTime);
|
||||
gmTimes.put(Gamemode.SPECTATOR, spectatorTime);
|
||||
} catch (NoSuchFieldError e) {
|
||||
}
|
||||
}
|
||||
@ -340,7 +357,7 @@ public class UserData {
|
||||
* @param session SessionData object
|
||||
*/
|
||||
public void addSession(SessionData session) {
|
||||
if (session != null && session.isValid()) {
|
||||
if (Verify.notNull(session) && session.isValid()) {
|
||||
sessions.add(session);
|
||||
}
|
||||
}
|
||||
@ -354,7 +371,7 @@ public class UserData {
|
||||
*/
|
||||
public void addSessions(Collection<SessionData> sessions) {
|
||||
Collection<SessionData> filteredSessions = sessions.stream()
|
||||
.filter(session -> session != null)
|
||||
.filter(session -> Verify.notNull(session))
|
||||
.filter(session -> session.isValid())
|
||||
.collect(Collectors.toList());
|
||||
if (sessions.size() != filteredSessions.size()) {
|
||||
@ -427,17 +444,6 @@ public class UserData {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the latest location.
|
||||
*
|
||||
* NOT INITIALIZED BY CONSTRUCTORS
|
||||
*
|
||||
* @return Location.
|
||||
*/
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of all locations inside the UserData object.
|
||||
*
|
||||
@ -526,7 +532,7 @@ public class UserData {
|
||||
* @return a GameMode map with 4 keys: SURVIVAL, CREATIVE, ADVENTURE,
|
||||
* SPECTATOR.
|
||||
*/
|
||||
public Map<GameMode, Long> getGmTimes() {
|
||||
public Map<Gamemode, Long> getGmTimes() {
|
||||
if (gmTimes == null) {
|
||||
gmTimes = new HashMap<>();
|
||||
}
|
||||
@ -549,7 +555,7 @@ public class UserData {
|
||||
*
|
||||
* @return Gamemode.
|
||||
*/
|
||||
public GameMode getLastGamemode() {
|
||||
public Gamemode getLastGamemode() {
|
||||
return lastGamemode;
|
||||
}
|
||||
|
||||
@ -598,17 +604,6 @@ public class UserData {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current location.
|
||||
*
|
||||
* Not in use.
|
||||
*
|
||||
* @param location a location in the world.
|
||||
*/
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of locations the user has been in.
|
||||
*
|
||||
@ -617,7 +612,7 @@ public class UserData {
|
||||
* @param locations a list of Locations.
|
||||
*/
|
||||
public void setLocations(List<Location> locations) {
|
||||
if (locations != null) {
|
||||
if (Verify.notNull(locations)) {
|
||||
this.locations = locations;
|
||||
}
|
||||
}
|
||||
@ -628,7 +623,7 @@ public class UserData {
|
||||
* @param ips ips of the user.
|
||||
*/
|
||||
public void setIps(Set<InetAddress> ips) {
|
||||
if (ips != null) {
|
||||
if (Verify.notNull(ips)) {
|
||||
this.ips = ips;
|
||||
}
|
||||
}
|
||||
@ -639,7 +634,7 @@ public class UserData {
|
||||
* @param nicknames nicknames of the user.
|
||||
*/
|
||||
public void setNicknames(Set<String> nicknames) {
|
||||
if (nicknames != null) {
|
||||
if (Verify.notNull(nicknames)) {
|
||||
this.nicknames = nicknames;
|
||||
}
|
||||
}
|
||||
@ -702,8 +697,8 @@ public class UserData {
|
||||
* @param gmTimes Map containing SURVIVAL, CREATIVE, ADVENTURE and SPECTATOR
|
||||
* (After 1.8) keys.
|
||||
*/
|
||||
public void setGmTimes(Map<GameMode, Long> gmTimes) {
|
||||
if (gmTimes != null) {
|
||||
public void setGmTimes(Map<Gamemode, Long> gmTimes) {
|
||||
if (Verify.notNull(gmTimes)) {
|
||||
this.gmTimes = gmTimes;
|
||||
}
|
||||
}
|
||||
@ -722,7 +717,7 @@ public class UserData {
|
||||
*
|
||||
* @param lastGamemode gamemode.
|
||||
*/
|
||||
public void setLastGamemode(GameMode lastGamemode) {
|
||||
public void setLastGamemode(Gamemode lastGamemode) {
|
||||
this.lastGamemode = lastGamemode;
|
||||
}
|
||||
|
||||
@ -795,7 +790,7 @@ public class UserData {
|
||||
* @param playerKills list of players kills.
|
||||
*/
|
||||
public void setPlayerKills(List<KillData> playerKills) {
|
||||
if (playerKills != null) {
|
||||
if (Verify.notNull(playerKills)) {
|
||||
this.playerKills = playerKills;
|
||||
}
|
||||
}
|
||||
@ -955,6 +950,7 @@ public class UserData {
|
||||
|
||||
/**
|
||||
* Set the online value.
|
||||
*
|
||||
* @param isOnline true/false
|
||||
*/
|
||||
public void setOnline(boolean isOnline) {
|
||||
|
@ -41,21 +41,21 @@ public enum AnalysisType {
|
||||
*
|
||||
* -1 values will be disregarded from the calculation (size will not grow).
|
||||
*/
|
||||
INT_TOTAL("totalInt_"),
|
||||
INT_TOTAL("totalInt_", "Total "),
|
||||
/**
|
||||
* Used when the getValue() method returns a long and total should be
|
||||
* calculated.
|
||||
*
|
||||
* -1 values will be disregarded from the calculation (size will not grow).
|
||||
*/
|
||||
LONG_TOTAL("totalLong_"),
|
||||
LONG_TOTAL("totalLong_", "Total "),
|
||||
/**
|
||||
* Used when the getValue() method returns a double and total should be
|
||||
* calculated.
|
||||
*
|
||||
* -1 values will be disregarded from the calculation (size will not grow).
|
||||
*/
|
||||
DOUBLE_TOTAL("totalDouble_"),
|
||||
DOUBLE_TOTAL("totalDouble_", "Total "),
|
||||
/**
|
||||
* Used when the getValue() method returns an amount of milliseconds as long
|
||||
* and average should be calculated.
|
||||
|
@ -9,6 +9,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
|
||||
/**
|
||||
@ -21,12 +22,16 @@ import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
public class HookHandler {
|
||||
|
||||
private List<PluginData> additionalDataSources;
|
||||
private final PluginConfigSectionHandler configHandler;
|
||||
|
||||
/**
|
||||
* Class constructor, hooks to plugins.
|
||||
*
|
||||
* @param plugin Current instance of plan.
|
||||
*/
|
||||
public HookHandler() {
|
||||
public HookHandler(Plan plugin) {
|
||||
additionalDataSources = new ArrayList<>();
|
||||
configHandler = new PluginConfigSectionHandler(plugin);
|
||||
try {
|
||||
Bridge.hook(this);
|
||||
} catch (Throwable e) {
|
||||
@ -46,8 +51,18 @@ public class HookHandler {
|
||||
* @param dataSource an object extending the PluginData class.
|
||||
*/
|
||||
public void addPluginDataSource(PluginData dataSource) {
|
||||
Log.debug("Registered a new datasource: " + dataSource.getPlaceholder("").replace("%", ""));
|
||||
additionalDataSources.add(dataSource);
|
||||
try {
|
||||
if (!configHandler.hasSection(dataSource)) {
|
||||
configHandler.createSection(dataSource);
|
||||
}
|
||||
if (configHandler.isEnabled(dataSource)) {
|
||||
Log.debug("Registered a new datasource: " + dataSource.getPlaceholder("").replace("%", ""));
|
||||
additionalDataSources.add(dataSource);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
Log.error("Attempting to register PluginDataSource caused an exception.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,58 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* Class responsible for generating and generating settings for PluginData
|
||||
* objects to the config.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class PluginConfigSectionHandler {
|
||||
|
||||
private final Plan plan;
|
||||
|
||||
public PluginConfigSectionHandler(Plan plan) {
|
||||
this.plan = plan;
|
||||
}
|
||||
|
||||
public boolean hasSection(PluginData dataSource) {
|
||||
ConfigurationSection section = getPluginsSection();
|
||||
String pluginName = dataSource.getSourcePlugin();
|
||||
if (!section.contains(pluginName)) {
|
||||
return false;
|
||||
}
|
||||
ConfigurationSection pluginSection = section.getConfigurationSection(pluginName);
|
||||
return pluginSection.contains(dataSource.getPlaceholder(""));
|
||||
}
|
||||
|
||||
private ConfigurationSection getPluginsSection() {
|
||||
FileConfiguration config = plan.getConfig();
|
||||
ConfigurationSection section = config.getConfigurationSection("Customization.Plugins");
|
||||
return section;
|
||||
}
|
||||
|
||||
public void createSection(PluginData dataSource) {
|
||||
ConfigurationSection section = getPluginsSection();
|
||||
String pluginName = dataSource.getSourcePlugin();
|
||||
String source = dataSource.placeholder;
|
||||
section.addDefault(pluginName + ".Enabled", true);
|
||||
section.addDefault(pluginName + ".Data." + source, true);
|
||||
FileConfiguration config = plan.getConfig();
|
||||
config.set("Customization.Plugins", section);
|
||||
plan.saveConfig();
|
||||
}
|
||||
|
||||
public boolean isEnabled(PluginData dataSource) {
|
||||
ConfigurationSection section = getPluginsSection();
|
||||
String pluginName = dataSource.getSourcePlugin();
|
||||
if (!section.getBoolean(pluginName + ".Enabled")) {
|
||||
return false;
|
||||
}
|
||||
String source = dataSource.placeholder;
|
||||
return section.getBoolean(pluginName + ".Data." + source);
|
||||
}
|
||||
}
|
@ -148,7 +148,7 @@ public abstract class PluginData {
|
||||
* @see AnalysisType
|
||||
*/
|
||||
public final String parseContainer(String modifier, String contents) {
|
||||
return "<div class=\"plugin-data\">" + Html.FONT_AWESOME_ICON.parse(icon) + " " + modifier + prefix + contents + suffix + "</div>";
|
||||
return "<div class=\"plugin-data\">" + (icon.isEmpty() ? "<br>" : Html.FONT_AWESOME_ICON.parse(icon)) + " " + modifier + prefix + contents + suffix + "</div>";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ public class AnalysisCacheHandler {
|
||||
private final Plan plugin;
|
||||
private AnalysisData cache;
|
||||
private final Analysis analysis;
|
||||
private boolean analysisEnabled;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -27,6 +28,7 @@ public class AnalysisCacheHandler {
|
||||
public AnalysisCacheHandler(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
analysis = new Analysis(plugin);
|
||||
analysisEnabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,8 +64,26 @@ public class AnalysisCacheHandler {
|
||||
public boolean isCached() {
|
||||
return (cache != null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isAnalysisBeingRun() {
|
||||
return analysis.isAnalysisBeingRun();
|
||||
}
|
||||
|
||||
public boolean isAnalysisEnabled() {
|
||||
return analysisEnabled;
|
||||
}
|
||||
|
||||
public void disableAnalysisTemporarily() {
|
||||
analysisEnabled = false;
|
||||
analysis.setTaskId(-2);
|
||||
}
|
||||
|
||||
public void enableAnalysis() {
|
||||
analysis.setTaskId(-1);
|
||||
analysisEnabled = true;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -13,10 +14,7 @@ import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.*;
|
||||
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheClearQueue;
|
||||
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheGetQueue;
|
||||
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheProcessQueue;
|
||||
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheSaveQueue;
|
||||
import main.java.com.djrapitops.plan.data.cache.queue.*;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.LogoutInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.ReloadInfo;
|
||||
@ -24,21 +22,18 @@ import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.NewPlayerCreator;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.HandlingInfoTimeComparator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import com.djrapitops.javaplugin.task.ITask;
|
||||
import com.djrapitops.javaplugin.utilities.player.IPlayer;
|
||||
|
||||
/**
|
||||
* This Class contains the Cache.
|
||||
*
|
||||
* This class is the main processing class that initializes Save, Clear, Process
|
||||
* This class is the main processing class that initialises Save, Clear, Process
|
||||
* and Get queue and Starts the asyncronous save task.
|
||||
*
|
||||
* It is used to store commanduse, locations, active sessions and UserData
|
||||
* It is used to store command use, locations, active sessions and UserData
|
||||
* objects in memory.
|
||||
*
|
||||
* It's methods can be used to access all the data it stores and to clear them.
|
||||
@ -51,6 +46,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
// Cache
|
||||
private final HashMap<UUID, UserData> dataCache;
|
||||
private Map<String, Integer> commandUse;
|
||||
private List<List<TPS>> unsavedTPSHistory;
|
||||
|
||||
// Plan
|
||||
private final Plan plugin;
|
||||
@ -63,7 +59,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
private DataCacheGetQueue getTask;
|
||||
|
||||
// Variables
|
||||
private int timesSaved;
|
||||
private boolean periodicTaskIsSaving = false;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -74,21 +70,21 @@ public class DataCacheHandler extends LocationCache {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public DataCacheHandler(Plan plugin) {
|
||||
super();
|
||||
super(); // Initializes Session & Location cache.
|
||||
|
||||
this.plugin = plugin;
|
||||
db = plugin.getDB();
|
||||
|
||||
dataCache = new HashMap<>();
|
||||
|
||||
startQueues();
|
||||
|
||||
timesSaved = 0;
|
||||
|
||||
commandUse = new HashMap<>();
|
||||
if (!getCommandUseFromDb()) {
|
||||
Log.error(Phrase.DB_FAILURE_DISABLE + "");
|
||||
plugin.getServer().getPluginManager().disablePlugin(plugin);
|
||||
plugin.disablePlugin();
|
||||
return;
|
||||
}
|
||||
unsavedTPSHistory = new ArrayList<>();
|
||||
startAsyncPeriodicSaveTask();
|
||||
}
|
||||
|
||||
@ -111,10 +107,10 @@ public class DataCacheHandler extends LocationCache {
|
||||
* Used to start all processing Queue Threads.
|
||||
*/
|
||||
public void startQueues() {
|
||||
clearTask = new DataCacheClearQueue(this);
|
||||
saveTask = new DataCacheSaveQueue(plugin, clearTask);
|
||||
getTask = new DataCacheGetQueue(plugin);
|
||||
processTask = new DataCacheProcessQueue(this);
|
||||
clearTask = new DataCacheClearQueue(this);
|
||||
saveTask = new DataCacheSaveQueue(plugin, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,7 +122,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
*/
|
||||
public void startAsyncPeriodicSaveTask() throws IllegalArgumentException, IllegalStateException {
|
||||
int minutes = Settings.SAVE_CACHE_MIN.getNumber();
|
||||
if (minutes <= 0) {
|
||||
if (!Verify.positive(minutes)) {
|
||||
minutes = 5;
|
||||
}
|
||||
final int clearAfterXsaves;
|
||||
@ -136,19 +132,32 @@ public class DataCacheHandler extends LocationCache {
|
||||
} else {
|
||||
clearAfterXsaves = configValue;
|
||||
}
|
||||
BukkitTask asyncPeriodicCacheSaveTask = new BukkitRunnable() {
|
||||
ITask asyncPeriodicCacheSaveTask = plugin.getRunnableFactory().createNew(new RslRunnable("PeriodicCacheSaveTask") {
|
||||
private int timesSaved = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
DataCacheHandler handler = Plan.getInstance().getHandler();
|
||||
handler.saveHandlerDataToCache();
|
||||
handler.saveCachedUserData();
|
||||
if (timesSaved % clearAfterXsaves == 0) {
|
||||
handler.clearCache();
|
||||
if (periodicTaskIsSaving) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
periodicTaskIsSaving = true;
|
||||
DataCacheHandler handler = Plan.getInstance().getHandler();
|
||||
handler.saveHandlerDataToCache();
|
||||
handler.saveCachedUserData();
|
||||
if (timesSaved % clearAfterXsaves == 0) {
|
||||
handler.clearCache();
|
||||
}
|
||||
saveCommandUse();
|
||||
saveUnsavedTPSHistory();
|
||||
timesSaved++;
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName() + "(" + this.getName() + ")", e);
|
||||
} finally {
|
||||
periodicTaskIsSaving = false;
|
||||
}
|
||||
saveCommandUse();
|
||||
timesSaved++;
|
||||
}
|
||||
}.runTaskTimerAsynchronously(plugin, 60 * 20 * minutes, 60 * 20 * minutes);
|
||||
}).runTaskTimerAsynchronously(60 * 20 * minutes, 60 * 20 * minutes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,6 +242,9 @@ public class DataCacheHandler extends LocationCache {
|
||||
* @param i Object that extends HandlingInfo.
|
||||
*/
|
||||
public void addToPool(HandlingInfo i) {
|
||||
if (i == null) {
|
||||
return;
|
||||
}
|
||||
Log.debug(i.getUuid() + ": Adding to pool, type:" + i.getType().name());
|
||||
processTask.addToPool(i);
|
||||
}
|
||||
@ -254,15 +266,15 @@ public class DataCacheHandler extends LocationCache {
|
||||
List<HandlingInfo> toProcess = processTask.stopAndReturnLeftovers();
|
||||
Benchmark.start("ProcessOnlineHandlingInfo");
|
||||
Log.debug("ToProcess size: " + toProcess.size() + " DataCache size: " + dataCache.keySet().size());
|
||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
List<IPlayer> onlinePlayers = plugin.fetch().getOnlinePlayers();
|
||||
Log.debug("Online: " + onlinePlayers.size());
|
||||
for (Player p : onlinePlayers) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
for (IPlayer p : onlinePlayers) {
|
||||
UUID uuid = p.getUuid();
|
||||
endSession(uuid);
|
||||
if (dataCache.containsKey(uuid)) {
|
||||
dataCache.get(uuid).addLocations(getLocationsForSaving(uuid));
|
||||
}
|
||||
toProcess.add(new LogoutInfo(uuid, time, p.isBanned(), p.getGameMode(), getSession(uuid)));
|
||||
toProcess.add(new LogoutInfo(uuid, time, p.isBanned(), p.getGamemode(), getSession(uuid)));
|
||||
}
|
||||
Log.debug("ToProcess size_AFTER: " + toProcess.size() + " DataCache size: " + dataCache.keySet().size());
|
||||
Collections.sort(toProcess, new HandlingInfoTimeComparator());
|
||||
@ -281,6 +293,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
saveUnsavedTPSHistory();
|
||||
try {
|
||||
db.close();
|
||||
} catch (SQLException e) {
|
||||
@ -341,25 +354,54 @@ public class DataCacheHandler extends LocationCache {
|
||||
}
|
||||
}
|
||||
|
||||
public void saveUnsavedTPSHistory() {
|
||||
List<TPS> averages = calculateAverageTpsForEachMinute();
|
||||
if (averages.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
db.getTpsTable().saveTPSData(averages);
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private List<TPS> calculateAverageTpsForEachMinute() {
|
||||
final List<TPS> averages = new ArrayList<>();
|
||||
if (unsavedTPSHistory.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<List<TPS>> copy = new ArrayList<>(unsavedTPSHistory);;
|
||||
for (List<TPS> history : copy) {
|
||||
final long lastdate = history.get(history.size() - 1).getDate();
|
||||
final double averageTPS = MathUtils.averageDouble(history.stream().map(t -> t.getTps()));
|
||||
final int averagePlayersOnline = (int) MathUtils.averageInt(history.stream().map(t -> t.getPlayers()));
|
||||
averages.add(new TPS(lastdate, averageTPS, averagePlayersOnline));
|
||||
}
|
||||
unsavedTPSHistory.removeAll(copy);
|
||||
return averages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the calculations for all online players with ReloadInfo.
|
||||
*/
|
||||
public void saveHandlerDataToCache() {
|
||||
Bukkit.getServer().getOnlinePlayers().stream().forEach((p) -> {
|
||||
final List<IPlayer> onlinePlayers = plugin.fetch().getOnlinePlayers();
|
||||
onlinePlayers.stream().forEach((p) -> {
|
||||
saveHandlerDataToCache(p, false);
|
||||
});
|
||||
}
|
||||
|
||||
private void saveHandlerDataToCache(Player player, boolean pool) {
|
||||
private void saveHandlerDataToCache(IPlayer player, boolean pool) {
|
||||
long time = MiscUtils.getTime();
|
||||
UUID uuid = player.getUniqueId();
|
||||
ReloadInfo info = new ReloadInfo(uuid, time, player.getAddress().getAddress(), player.isBanned(), player.getDisplayName(), player.getGameMode());
|
||||
UUID uuid = player.getUuid();
|
||||
ReloadInfo info = new ReloadInfo(uuid, time, player.getAddress().getAddress(), player.isBanned(), player.getDisplayName(), player.getGamemode());
|
||||
if (!pool) {
|
||||
UserData data = dataCache.get(uuid);
|
||||
if (data != null) {
|
||||
info.process(data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
addToPool(info);
|
||||
}
|
||||
@ -378,7 +420,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
*/
|
||||
public void clearFromCache(UUID uuid) {
|
||||
Log.debug(uuid + ": Clear");
|
||||
if (getOfflinePlayer(uuid).isOnline()) {
|
||||
if (Verify.notNull(plugin.fetch().getPlayer(uuid))) {
|
||||
Log.debug(uuid + ": Online, did not clear");
|
||||
UserData data = dataCache.get(uuid);
|
||||
if (data != null) {
|
||||
@ -423,16 +465,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
*
|
||||
* @param player Player the new UserData is created for
|
||||
*/
|
||||
public void newPlayer(Player player) {
|
||||
newPlayer(NewPlayerCreator.createNewPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new UserData instance and saves it to the Database.
|
||||
*
|
||||
* @param player Player the new UserData is created for
|
||||
*/
|
||||
public void newPlayer(OfflinePlayer player) {
|
||||
public void newPlayer(IPlayer player) {
|
||||
newPlayer(NewPlayerCreator.createNewPlayer(player));
|
||||
}
|
||||
|
||||
@ -470,11 +503,12 @@ public class DataCacheHandler extends LocationCache {
|
||||
* Calls all the methods that are ran when PlayerJoinEvent is fired
|
||||
*/
|
||||
public void handleReload() {
|
||||
BukkitTask asyncReloadCacheUpdateTask = (new BukkitRunnable() {
|
||||
ITask asyncReloadCacheUpdateTask = plugin.getRunnableFactory().createNew(new RslRunnable("ReloadCacheUpdateTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
final List<IPlayer> onlinePlayers = plugin.fetch().getOnlinePlayers();
|
||||
for (IPlayer player : onlinePlayers) {
|
||||
UUID uuid = player.getUuid();
|
||||
boolean isNewPlayer = !db.wasSeenBefore(uuid);
|
||||
if (isNewPlayer) {
|
||||
newPlayer(player);
|
||||
@ -484,7 +518,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -499,19 +533,40 @@ public class DataCacheHandler extends LocationCache {
|
||||
commandUse.put(command, commandUse.get(command) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DataCacheSaveQueue getSaveTask() {
|
||||
return saveTask;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DataCacheClearQueue getClearTask() {
|
||||
return clearTask;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DataCacheProcessQueue getProcessTask() {
|
||||
return processTask;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DataCacheGetQueue getGetTask() {
|
||||
return getTask;
|
||||
}
|
||||
|
||||
public void addTPSLastMinute(List<TPS> history) {
|
||||
// Copy the contents to avoid reference, thus making the whole calculation pointless.
|
||||
unsavedTPSHistory.add(new ArrayList<>(history));
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class SessionCache {
|
||||
* Used to get the Map of active sessions.
|
||||
*
|
||||
* Used for testing.
|
||||
*
|
||||
*
|
||||
* @return key:value UUID:SessionData
|
||||
*/
|
||||
public Map<UUID, SessionData> getActiveSessions() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.data.cache.queue;
|
||||
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
/**
|
||||
@ -8,7 +9,7 @@ import java.util.concurrent.BlockingQueue;
|
||||
* @author Rsl1122
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class Consumer<T> implements Runnable {
|
||||
public abstract class Consumer<T> extends RslRunnable {
|
||||
|
||||
boolean run;
|
||||
final BlockingQueue<T> queue;
|
||||
@ -17,8 +18,10 @@ public abstract class Consumer<T> implements Runnable {
|
||||
* Constructor, defines queue.
|
||||
*
|
||||
* @param queue Queue to consume from.
|
||||
* @param name Name of the queue.
|
||||
*/
|
||||
public Consumer(BlockingQueue<T> queue) {
|
||||
public Consumer(BlockingQueue<T> queue, String name) {
|
||||
super(name);
|
||||
this.queue = queue;
|
||||
run = true;
|
||||
}
|
||||
@ -35,6 +38,7 @@ public abstract class Consumer<T> implements Runnable {
|
||||
|
||||
void stop() {
|
||||
run = false;
|
||||
super.cancel();
|
||||
}
|
||||
|
||||
abstract void clearVariables();
|
||||
|
@ -16,7 +16,7 @@ import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
* @author Rsl1122
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class DataCacheClearQueue extends Queue<UUID>{
|
||||
public class DataCacheClearQueue extends Queue<UUID> {
|
||||
|
||||
/**
|
||||
* Class constructor, starts the new Thread for clearing.
|
||||
@ -63,7 +63,7 @@ class ClearConsumer extends Consumer<UUID> implements Runnable {
|
||||
private DataCacheHandler handler;
|
||||
|
||||
ClearConsumer(BlockingQueue q, DataCacheHandler handler) {
|
||||
super(q);
|
||||
super(q, "ClearQueueConsumer");
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@ -93,6 +93,7 @@ class ClearConsumer extends Consumer<UUID> implements Runnable {
|
||||
}
|
||||
|
||||
class ClearSetup extends Setup<UUID> {
|
||||
|
||||
public ClearSetup(BlockingQueue<UUID> q, DataCacheHandler handler) {
|
||||
super(new ClearConsumer(q, handler));
|
||||
}
|
||||
|
@ -46,15 +46,19 @@ public class DataCacheGetQueue extends Queue<Map<UUID, List<DBCallableProcessor>
|
||||
Log.debug(uuid + ": Scheduling for get");
|
||||
try {
|
||||
Map<UUID, List<DBCallableProcessor>> map = new HashMap<>();
|
||||
if (map.get(uuid) == null) {
|
||||
map.put(uuid, new ArrayList<>());
|
||||
}
|
||||
map.get(uuid).addAll(Arrays.asList(processors));
|
||||
map.put(uuid, Arrays.asList(processors));
|
||||
queue.add(map);
|
||||
} catch (IllegalStateException e) {
|
||||
Log.error(Phrase.ERROR_TOO_SMALL_QUEUE.parse("Get Queue", Settings.PROCESS_GET_LIMIT.getNumber() + ""));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsUUIDtoBeCached(UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return false;
|
||||
}
|
||||
return new ArrayList<>(queue).stream().anyMatch((map) -> (map.get(uuid) != null && map.get(uuid).size() >= 2)); // Map has 2 processors if being cached
|
||||
}
|
||||
}
|
||||
|
||||
class GetConsumer extends Consumer<Map<UUID, List<DBCallableProcessor>>> {
|
||||
@ -62,7 +66,7 @@ class GetConsumer extends Consumer<Map<UUID, List<DBCallableProcessor>>> {
|
||||
private Database db;
|
||||
|
||||
GetConsumer(BlockingQueue q, Database db) {
|
||||
super(q);
|
||||
super(q, "GetQueueConsumer");
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
|
||||
@ -66,7 +65,10 @@ public class DataCacheProcessQueue extends Queue<HandlingInfo> {
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean containsUUID(UUID uuid) {
|
||||
return new ArrayList<>(queue).stream().map(d -> d.getUuid()).collect(Collectors.toList()).contains(uuid);
|
||||
if (uuid == null) {
|
||||
return false;
|
||||
}
|
||||
return new ArrayList<>(queue).stream().anyMatch(info -> info.getUuid().equals(uuid));
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +77,7 @@ class ProcessConsumer extends Consumer<HandlingInfo> {
|
||||
private DataCacheHandler handler;
|
||||
|
||||
ProcessConsumer(BlockingQueue q, DataCacheHandler h) {
|
||||
super(q);
|
||||
super(q, "ProcessQueueConsumer");
|
||||
handler = h;
|
||||
}
|
||||
|
||||
@ -84,6 +86,10 @@ class ProcessConsumer extends Consumer<HandlingInfo> {
|
||||
if (handler == null) {
|
||||
return;
|
||||
}
|
||||
if (handler.getGetTask().containsUUIDtoBeCached(info.getUuid())) { // Wait for get queue.
|
||||
queue.add(info);
|
||||
return;
|
||||
}
|
||||
Log.debug(info.getUuid() + ": Processing type: " + info.getType().name());
|
||||
DBCallableProcessor p = new DBCallableProcessor() {
|
||||
@Override
|
||||
@ -105,6 +111,7 @@ class ProcessConsumer extends Consumer<HandlingInfo> {
|
||||
}
|
||||
|
||||
class ProcessSetup extends Setup<HandlingInfo> {
|
||||
|
||||
ProcessSetup(BlockingQueue<HandlingInfo> q, DataCacheHandler h) {
|
||||
super(new ProcessConsumer(q, h), new ProcessConsumer(q, h));
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
|
||||
/**
|
||||
@ -20,18 +21,17 @@ import main.java.com.djrapitops.plan.database.Database;
|
||||
* @author Rsl1122
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class DataCacheSaveQueue extends Queue<UserData>{
|
||||
public class DataCacheSaveQueue extends Queue<UserData> {
|
||||
|
||||
/**
|
||||
* Class constructor, starts the new Thread for saving.
|
||||
*
|
||||
* @param plugin current instance of Plan
|
||||
* @param clear current instance of the Clear task to schedule clear if
|
||||
* UserData.clearAfterSave() is true
|
||||
* @param handler DataCacheHandler
|
||||
*/
|
||||
public DataCacheSaveQueue(Plan plugin, DataCacheClearQueue clear) {
|
||||
public DataCacheSaveQueue(Plan plugin, DataCacheHandler handler) {
|
||||
super(new ArrayBlockingQueue(Settings.PROCESS_SAVE_LIMIT.getNumber()));
|
||||
setup = new SaveSetup(queue, clear, plugin.getDB());
|
||||
setup = new SaveSetup(queue, handler, plugin.getDB());
|
||||
setup.go();
|
||||
}
|
||||
|
||||
@ -84,19 +84,22 @@ public class DataCacheSaveQueue extends Queue<UserData>{
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean containsUUID(UUID uuid) {
|
||||
return new ArrayList<>(queue).stream().map(d -> d.getUuid()).collect(Collectors.toList()).contains(uuid);
|
||||
if (uuid == null) {
|
||||
return false;
|
||||
}
|
||||
return new ArrayList<>(queue).stream().anyMatch(d -> d.getUuid().equals(uuid));
|
||||
}
|
||||
}
|
||||
|
||||
class SaveConsumer extends Consumer<UserData> {
|
||||
|
||||
private Database db;
|
||||
private DataCacheClearQueue clear;
|
||||
private DataCacheHandler handler;
|
||||
|
||||
SaveConsumer(BlockingQueue q, DataCacheClearQueue clear, Database db) {
|
||||
super(q);
|
||||
SaveConsumer(BlockingQueue q, DataCacheHandler handler, Database db) {
|
||||
super(q, "SaveQueueConsumer");
|
||||
this.db = db;
|
||||
this.clear = clear;
|
||||
this.handler = handler;
|
||||
run = true;
|
||||
}
|
||||
|
||||
@ -106,14 +109,18 @@ class SaveConsumer extends Consumer<UserData> {
|
||||
return;
|
||||
}
|
||||
UUID uuid = data.getUuid();
|
||||
if (handler.getProcessTask().containsUUID(uuid)) { // Wait for process queue.
|
||||
queue.add(data);
|
||||
return;
|
||||
}
|
||||
Log.debug(uuid + ": Saving: " + uuid);
|
||||
try {
|
||||
db.saveUserData(data);
|
||||
data.stopAccessing();
|
||||
Log.debug(uuid + ": Saved!");
|
||||
if (data.shouldClearAfterSave()) {
|
||||
if (clear != null) {
|
||||
clear.scheduleForClear(uuid);
|
||||
if (handler != null) {
|
||||
handler.getClearTask().scheduleForClear(uuid);
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
@ -127,14 +134,15 @@ class SaveConsumer extends Consumer<UserData> {
|
||||
if (db != null) {
|
||||
db = null;
|
||||
}
|
||||
if (clear != null) {
|
||||
clear = null;
|
||||
if (handler != null) {
|
||||
handler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SaveSetup extends Setup<UserData>{
|
||||
SaveSetup(BlockingQueue<UserData> q, DataCacheClearQueue clear, Database db) {
|
||||
super(new SaveConsumer(q, clear, db), new SaveConsumer(q, clear, db));
|
||||
class SaveSetup extends Setup<UserData> {
|
||||
|
||||
SaveSetup(BlockingQueue<UserData> q, DataCacheHandler handler, Database db) {
|
||||
super(new SaveConsumer(q, handler, db), new SaveConsumer(q, handler, db));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.data.cache.queue;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
|
||||
/**
|
||||
* Abstract representation of a queue setup.
|
||||
*
|
||||
@ -21,7 +23,7 @@ public abstract class Setup<T> {
|
||||
|
||||
void go() {
|
||||
for (Consumer<T> consumer : consumers) {
|
||||
new Thread(consumer).start();
|
||||
Plan.getInstance().getRunnableFactory().createNew(consumer).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package main.java.com.djrapitops.plan.data.handling;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import java.util.Map;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
/**
|
||||
* Class containing static methods for processing information contained in a
|
||||
@ -21,17 +21,17 @@ public class GamemodeHandling {
|
||||
* @param time Epoch ms the event occurred.
|
||||
* @param newGM The Gamemode the player changed to.
|
||||
*/
|
||||
public static void processGamemodeInfo(UserData data, long time, GameMode newGM) {
|
||||
public static void processGamemodeInfo(UserData data, long time, Gamemode newGM) {
|
||||
if (newGM == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameMode lastGamemode = data.getLastGamemode();
|
||||
Gamemode lastGamemode = data.getLastGamemode();
|
||||
if (lastGamemode == null) {
|
||||
data.setLastGamemode(newGM);
|
||||
}
|
||||
lastGamemode = data.getLastGamemode();
|
||||
Map<GameMode, Long> times = data.getGmTimes();
|
||||
Map<Gamemode, Long> times = data.getGmTimes();
|
||||
Long currentGMTime = times.get(lastGamemode);
|
||||
if (currentGMTime == null) {
|
||||
currentGMTime = 0L;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.data.handling.importing;
|
||||
|
||||
import com.djrapitops.pluginbridge.plan.Bridge;
|
||||
import com.djrapitops.pluginbridge.plan.importing.OnTimeImporter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -10,7 +9,7 @@ import static org.bukkit.Bukkit.getPluginManager;
|
||||
/**
|
||||
* This class is responsible for static utility methods used for importing.
|
||||
*
|
||||
* @author Risto
|
||||
* @author Rsl1122
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public class ImportUtils {
|
||||
@ -22,6 +21,9 @@ public class ImportUtils {
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean isPluginEnabled(String pluginName) {
|
||||
if ("offline".equals(pluginName)) {
|
||||
return true;
|
||||
}
|
||||
return getPluginManager().isPluginEnabled(pluginName);
|
||||
}
|
||||
|
||||
@ -32,13 +34,14 @@ public class ImportUtils {
|
||||
*/
|
||||
public static Map<String, Importer> getImporters() {
|
||||
Map<String, Importer> importers = new HashMap<>();
|
||||
try {
|
||||
try {
|
||||
importers.put("ontime", new OnTimeImporter());
|
||||
importers.put("offline", new OfflinePlayerImporter());
|
||||
} catch (Throwable e) {
|
||||
Log.toLog("ImportUtils.getImporters", e);
|
||||
Log.error("Plan Plugin Bridge not included in the plugin jar.");
|
||||
}
|
||||
|
||||
|
||||
return importers;
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,25 @@
|
||||
package main.java.com.djrapitops.plan.data.handling.importing;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.IOfflinePlayer;
|
||||
import com.djrapitops.javaplugin.utilities.player.Fetch;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.InfoType;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.NewPlayerCreator;
|
||||
|
||||
/**
|
||||
* Abstract class used for importing data from other plugins.
|
||||
@ -22,11 +29,25 @@ import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
*/
|
||||
public abstract class Importer {
|
||||
|
||||
private String info;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Importer() {
|
||||
info = "No info specified";
|
||||
}
|
||||
|
||||
/**
|
||||
* Import data from users.
|
||||
*
|
||||
* @param uuids UUIDs of players to import
|
||||
* @return Success of import
|
||||
* @deprecated Use importData(Collection, String...) instead (new system)
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean importData(Collection<UUID> uuids) {
|
||||
return importData(uuids, new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,37 +56,104 @@ public abstract class Importer {
|
||||
* Creates UserData for players that have not been saved to the database.
|
||||
*
|
||||
* @param uuids UUIDs to be imported
|
||||
* @param args arguments for the import
|
||||
* @return success
|
||||
*/
|
||||
public boolean importData(Collection<UUID> uuids) {
|
||||
public boolean importData(Collection<UUID> uuids, String... args) {
|
||||
Plan plan = Plan.getInstance();
|
||||
DataCacheHandler handler = plan.getHandler();
|
||||
Database db = plan.getDB();
|
||||
Set<UUID> saved;
|
||||
plan.getAnalysisCache().disableAnalysisTemporarily();
|
||||
try {
|
||||
saved = db.getSavedUUIDs();
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
}
|
||||
List<UUID> unSaved = new ArrayList<>(uuids);
|
||||
unSaved.removeAll(saved);
|
||||
for (UUID uuid : unSaved) {
|
||||
OfflinePlayer player = getOfflinePlayer(uuid);
|
||||
handler.newPlayer(player);
|
||||
}
|
||||
for (UUID uuid : uuids) {
|
||||
handler.addToPool(importData(uuid));
|
||||
String processName = "Import, " + getClass().getSimpleName();
|
||||
plan.processStatus().startExecution(processName);
|
||||
DataCacheHandler handler = plan.getHandler();
|
||||
Database db = plan.getDB();
|
||||
Set<UUID> saved;
|
||||
try {
|
||||
saved = db.getSavedUUIDs();
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
}
|
||||
List<UUID> unSaved = new ArrayList<>(uuids);
|
||||
unSaved.removeAll(saved);
|
||||
String createUserObjects = "Creating new UserData objects for: " + unSaved.size();
|
||||
plan.processStatus().setStatus(processName, createUserObjects);
|
||||
Map<UUID, IOfflinePlayer> offlinePlayers = Fetch.getIOfflinePlayers().stream().collect(Collectors.toMap(IOfflinePlayer::getUuid, Function.identity()));
|
||||
Benchmark.start(createUserObjects);
|
||||
List<IOfflinePlayer> offlineP = unSaved.stream().map(uuid
|
||||
-> offlinePlayers.get(uuid)).collect(Collectors.toList());
|
||||
List<UserData> newUsers = new ArrayList<>();
|
||||
for (IOfflinePlayer p : offlineP) {
|
||||
UserData newPlayer = NewPlayerCreator.createNewOfflinePlayer(p);
|
||||
newPlayer.setLastPlayed(newPlayer.getRegistered());
|
||||
newUsers.add(newPlayer);
|
||||
plan.processStatus().setStatus(processName, "Creating new UserData objects: " + newUsers.size() + "/" + unSaved.size());
|
||||
}
|
||||
Benchmark.stop(createUserObjects);
|
||||
plan.processStatus().setStatus(processName, "Save new UserData objects (" + unSaved.size() + ")");
|
||||
try {
|
||||
plan.getDB().saveMultipleUserData(newUsers);
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
}
|
||||
for (UUID uuid : uuids) {
|
||||
handler.addToPool(importData(uuid, args));
|
||||
}
|
||||
plan.processStatus().finishExecution(processName);
|
||||
} finally {
|
||||
plan.getAnalysisCache().enableAnalysis();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the info for import command.
|
||||
*
|
||||
* @return Information about the import options
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public final String getInfo() {
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the info for import command.
|
||||
*
|
||||
* @param info Information about the import options
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public final void setInfo(String info) {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import data of a single player.
|
||||
*
|
||||
* @param uuid UUID of the player
|
||||
* @return HandlingInfo used to modify saved userdata.
|
||||
* @deprecated Deprecated (new system), use importData(UUID, String...)
|
||||
* instead
|
||||
*/
|
||||
@Deprecated
|
||||
public HandlingInfo importData(UUID uuid) {
|
||||
return importData(uuid, new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used for getting the HandlingInfo object for the import data.
|
||||
*
|
||||
* @param uuid UUID of the player
|
||||
* @param args Arguments for import
|
||||
* @return HandlingInfo object that modifies the UserData so that the data
|
||||
* is imported.
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public abstract HandlingInfo importData(UUID uuid);
|
||||
public HandlingInfo importData(UUID uuid, String... args) {
|
||||
return new HandlingInfo(uuid, InfoType.OTHER, 0) {
|
||||
@Override
|
||||
public boolean process(UserData uData) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package main.java.com.djrapitops.plan.data.handling.importing;
|
||||
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
|
||||
/**
|
||||
* Imports all players who have not joined since Plan was installed.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class OfflinePlayerImporter extends Importer {
|
||||
|
||||
public OfflinePlayerImporter() {
|
||||
super.setInfo("Import all players who have not joined since Plan was installed.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlingInfo importData(UUID uuid, String... args) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.GamemodeHandling;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
/**
|
||||
* HandlingInfo Class for GamemodeChangeEvent information.
|
||||
@ -13,7 +13,7 @@ import org.bukkit.GameMode;
|
||||
*/
|
||||
public class GamemodeInfo extends HandlingInfo {
|
||||
|
||||
private GameMode currentGamemode;
|
||||
private final Gamemode currentGamemode;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -22,7 +22,7 @@ public class GamemodeInfo extends HandlingInfo {
|
||||
* @param time Epoch ms of the event.
|
||||
* @param gm Gamemode the player changed to.
|
||||
*/
|
||||
public GamemodeInfo(UUID uuid, long time, GameMode gm) {
|
||||
public GamemodeInfo(UUID uuid, long time, Gamemode gm) {
|
||||
super(uuid, InfoType.GM, time);
|
||||
currentGamemode = gm;
|
||||
}
|
||||
|
@ -12,13 +12,37 @@ package main.java.com.djrapitops.plan.data.handling.info;
|
||||
*/
|
||||
public enum InfoType {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
CHAT,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
DEATH,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
KILL,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
GM,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
LOGIN,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
LOGOUT,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
KICK,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
RELOAD,
|
||||
/**
|
||||
* Used for events registered with the API.
|
||||
|
@ -1,10 +1,10 @@
|
||||
package main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import java.net.InetAddress;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.LoginHandling;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
/**
|
||||
* HandlingInfo Class for JoinEvent information.
|
||||
@ -31,7 +31,7 @@ public class LoginInfo extends HandlingInfo {
|
||||
* @param gm current gamemode of the player
|
||||
* @param loginTimes number the loginTimes should be incremented with.
|
||||
*/
|
||||
public LoginInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, GameMode gm, int loginTimes) {
|
||||
public LoginInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, Gamemode gm, int loginTimes) {
|
||||
super(uuid, InfoType.LOGIN, time);
|
||||
this.ip = ip;
|
||||
this.banned = banned;
|
||||
@ -50,7 +50,7 @@ public class LoginInfo extends HandlingInfo {
|
||||
* @param nickname Nickname of the player
|
||||
* @param gm current gamemode of the player
|
||||
*/
|
||||
public LoginInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, GameMode gm) {
|
||||
public LoginInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, Gamemode gm) {
|
||||
this(uuid, time, ip, banned, nickname, gm, 0);
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
package main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.LogoutHandling;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
/**
|
||||
* HandlingInfo Class for QuitEvent information.
|
||||
@ -28,7 +28,7 @@ public class LogoutInfo extends HandlingInfo {
|
||||
* @param sData session that has been ended at the moment of the logout
|
||||
* event.
|
||||
*/
|
||||
public LogoutInfo(UUID uuid, long time, boolean banned, GameMode gm, SessionData sData) {
|
||||
public LogoutInfo(UUID uuid, long time, boolean banned, Gamemode gm, SessionData sData) {
|
||||
super(uuid, InfoType.LOGOUT, time);
|
||||
this.banned = banned;
|
||||
this.sData = sData;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import java.net.InetAddress;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.LoginHandling;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
/**
|
||||
* HandlingInfo Class for refreshing data in the cache for online players.
|
||||
@ -29,7 +29,7 @@ public class ReloadInfo extends HandlingInfo {
|
||||
* @param nickname Nickname of the player
|
||||
* @param gm current gamemode of the player
|
||||
*/
|
||||
public ReloadInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, GameMode gm) {
|
||||
public ReloadInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, Gamemode gm) {
|
||||
super(uuid, InfoType.RELOAD, time);
|
||||
this.ip = ip;
|
||||
this.banned = banned;
|
||||
|
@ -4,6 +4,7 @@ import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -39,7 +40,9 @@ public class PlanCommandPreprocessListener implements Listener {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (Permissions.IGNORE_COMMANDUSE.userHasThisPermission(event.getPlayer())) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player.hasPermission(Permissions.IGNORE_COMMANDUSE.getPermission())) {
|
||||
Log.debug("Ignored command, player had ignore permission.");
|
||||
return;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.GamemodeInfo;
|
||||
@ -42,6 +43,6 @@ public class PlanGamemodeChangeListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Player p = event.getPlayer();
|
||||
handler.addToPool(new GamemodeInfo(p.getUniqueId(), MiscUtils.getTime(), event.getNewGameMode()));
|
||||
handler.addToPool(new GamemodeInfo(p.getUniqueId(), MiscUtils.getTime(), Gamemode.wrap(event.getNewGameMode())));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
@ -17,8 +18,9 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import com.djrapitops.javaplugin.task.ITask;
|
||||
import com.djrapitops.javaplugin.utilities.player.BukkitPlayer;
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
|
||||
/**
|
||||
* Event Listener for PlayerJoin, PlayerQuit and PlayerKickEvents.
|
||||
@ -57,13 +59,13 @@ public class PlanPlayerListener implements Listener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
handler.startSession(uuid);
|
||||
Log.debug(uuid + ": PlayerJoinEvent");
|
||||
BukkitTask asyncNewPlayerCheckTask = new BukkitRunnable() {
|
||||
ITask asyncNewPlayerCheckTask = plugin.getRunnableFactory().createNew(new RslRunnable("NewPlayerCheckTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
LoginInfo loginInfo = new LoginInfo(uuid, MiscUtils.getTime(), player.getAddress().getAddress(), player.isBanned(), player.getDisplayName(), player.getGameMode(), 1);
|
||||
LoginInfo loginInfo = new LoginInfo(uuid, MiscUtils.getTime(), player.getAddress().getAddress(), player.isBanned(), player.getDisplayName(), Gamemode.wrap(player.getGameMode()), 1);
|
||||
boolean isNewPlayer = !plugin.getDB().wasSeenBefore(uuid);
|
||||
if (isNewPlayer) {
|
||||
UserData newUserData = NewPlayerCreator.createNewPlayer(player);
|
||||
UserData newUserData = NewPlayerCreator.createNewPlayer(BukkitPlayer.wrap(player));
|
||||
loginInfo.process(newUserData);
|
||||
handler.newPlayer(newUserData);
|
||||
} else {
|
||||
@ -72,7 +74,7 @@ public class PlanPlayerListener implements Listener {
|
||||
Log.debug(uuid + ": PlayerJoinEvent_AsyncTask_END, New:" + isNewPlayer);
|
||||
this.cancel();
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}).runTaskAsynchronously();
|
||||
Log.debug(uuid + ": PlayerJoinEvent_END");
|
||||
}
|
||||
|
||||
@ -90,7 +92,7 @@ public class PlanPlayerListener implements Listener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
handler.endSession(uuid);
|
||||
Log.debug(uuid + ": PlayerQuitEvent");
|
||||
handler.addToPool(new LogoutInfo(uuid, MiscUtils.getTime(), player.isBanned(), player.getGameMode(), handler.getSession(uuid)));
|
||||
handler.addToPool(new LogoutInfo(uuid, MiscUtils.getTime(), player.isBanned(), Gamemode.wrap(player.getGameMode()), handler.getSession(uuid)));
|
||||
handler.saveCachedData(uuid);
|
||||
Log.debug(uuid + ": PlayerQuitEvent_END");
|
||||
}
|
||||
@ -110,7 +112,7 @@ public class PlanPlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
handler.endSession(uuid);
|
||||
handler.addToPool(new LogoutInfo(uuid, MiscUtils.getTime(), player.isBanned(), player.getGameMode(), handler.getSession(uuid)));
|
||||
handler.addToPool(new LogoutInfo(uuid, MiscUtils.getTime(), player.isBanned(), Gamemode.wrap(player.getGameMode()), handler.getSession(uuid)));
|
||||
handler.addToPool(new KickInfo(uuid));
|
||||
handler.saveCachedData(uuid);
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.javaplugin.api.TimeAmount;
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
|
||||
/**
|
||||
* Class responsible for calculating TPS every second.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TPSCountTimer extends RslRunnable {
|
||||
|
||||
private long lastCheckNano;
|
||||
private final Plan plugin;
|
||||
private final DataCacheHandler handler;
|
||||
private final List<TPS> history;
|
||||
|
||||
public TPSCountTimer(Plan plugin) {
|
||||
super("TPSCountTimer");
|
||||
lastCheckNano = -1;
|
||||
this.handler = plugin.getHandler();
|
||||
this.plugin = plugin;
|
||||
history = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long nanotime = System.nanoTime();
|
||||
long now = MiscUtils.getTime();
|
||||
long diff = nanotime - lastCheckNano;
|
||||
lastCheckNano = nanotime;
|
||||
if (diff > nanotime) { // First run's diff = nanotime + 1, no calc possible.
|
||||
Log.debug("First run of TPSCountTimer Task.");
|
||||
return;
|
||||
}
|
||||
diff -= TimeAmount.MILLISECOND.ns() * 40L; // 40ms Removed because the run appears to take 40-50ms, scewing the tps.
|
||||
TPS tps = calculateTPS(diff, now);
|
||||
history.add(tps);
|
||||
if (history.size() >= 60) {
|
||||
handler.addTPSLastMinute(history);
|
||||
history.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public TPS calculateTPS(long diff, long now) {
|
||||
if (diff < TimeAmount.SECOND.ns()) { // No tick count above 20
|
||||
diff = TimeAmount.SECOND.ns();
|
||||
}
|
||||
int playersOnline = plugin.getServer().getOnlinePlayers().size();
|
||||
long twentySeconds = 20L * TimeAmount.SECOND.ns();
|
||||
while (diff > twentySeconds) {
|
||||
history.add(new TPS(now, 0, playersOnline));
|
||||
diff -= twentySeconds;
|
||||
}
|
||||
double tpsN = twentySeconds / diff;
|
||||
|
||||
TPS tps = new TPS(now, tpsN, playersOnline);
|
||||
return tps;
|
||||
}
|
||||
}
|
@ -1,29 +1,42 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.database;
|
||||
|
||||
/**
|
||||
* Class to contain objects in the batches.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.4.3
|
||||
* @param <T>
|
||||
* @param <T> Object stored.
|
||||
*/
|
||||
public class Container<T> {
|
||||
private T object;
|
||||
private int id;
|
||||
|
||||
private final T object;
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* Constructor for the object.
|
||||
*
|
||||
* @param object Object to place inside the container.
|
||||
* @param id UserID related to the object.
|
||||
*/
|
||||
public Container(T object, int id) {
|
||||
this.object = object;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object in the container.
|
||||
*
|
||||
* @return object.
|
||||
*/
|
||||
public T getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the UserID related to the object.
|
||||
*
|
||||
* @return userID
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -6,19 +6,55 @@
|
||||
package main.java.com.djrapitops.plan.database;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* Class containing static utility methods used by the Database classes.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.4.3
|
||||
*/
|
||||
public class DBUtils {
|
||||
|
||||
public static <T> List<List<Container<T>>> splitIntoBatches(Map<Integer, List<T>> objects) {
|
||||
int batchSize = 2048;
|
||||
private static final int BATCH_SIZE = 2048;
|
||||
|
||||
/**
|
||||
* Splits a collection of objects into lists with the size defined by
|
||||
* BATCH_SIZE.
|
||||
*
|
||||
* @param <T> Object type
|
||||
* @param objects Collection of the objects. // * @return Lists with max
|
||||
* size of BATCH_SIZE.
|
||||
*/
|
||||
public static <T> List<List<T>> splitIntoBatches(Collection<T> objects) {
|
||||
List<List<T>> batches = new ArrayList<>();
|
||||
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
for (T obj : objects) {
|
||||
if (batches.size() - 1 <= j) {
|
||||
batches.add(new ArrayList<>());
|
||||
}
|
||||
batches.get(j).add(obj);
|
||||
i++;
|
||||
if (i % BATCH_SIZE == 0) {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return batches;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <T>
|
||||
* @param objects
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<List<Container<T>>> splitIntoBatchesId(Map<Integer, List<T>> objects) {
|
||||
List<List<Container<T>>> wrappedBatches = new ArrayList<>();
|
||||
|
||||
int i = 0;
|
||||
@ -30,8 +66,8 @@ public class DBUtils {
|
||||
wrappedBatches.add(new ArrayList<>());
|
||||
}
|
||||
wrappedBatches.get(j).add(new Container<>(object, entry.getKey()));
|
||||
i++;
|
||||
if (i % batchSize == 0) {
|
||||
i++;
|
||||
if (i % BATCH_SIZE == 0) {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import main.java.com.djrapitops.plan.database.tables.KillsTable;
|
||||
import main.java.com.djrapitops.plan.database.tables.LocationsTable;
|
||||
import main.java.com.djrapitops.plan.database.tables.NicknamesTable;
|
||||
import main.java.com.djrapitops.plan.database.tables.SessionsTable;
|
||||
import main.java.com.djrapitops.plan.database.tables.TPSTable;
|
||||
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
||||
import main.java.com.djrapitops.plan.database.tables.VersionTable;
|
||||
|
||||
@ -70,6 +71,13 @@ public abstract class Database {
|
||||
*/
|
||||
protected CommandUseTable commandUseTable;
|
||||
|
||||
/**
|
||||
* Table representing plan_tps in the database.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*/
|
||||
protected TPSTable tpsTable;
|
||||
|
||||
/**
|
||||
* Table representing plan_version in the database.
|
||||
*/
|
||||
@ -327,4 +335,13 @@ public abstract class Database {
|
||||
public CommandUseTable getCommandUseTable() {
|
||||
return commandUseTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the tps table.
|
||||
*
|
||||
* @return Table representing plan_tps
|
||||
*/
|
||||
public TPSTable getTpsTable() {
|
||||
return tpsTable;
|
||||
}
|
||||
}
|
||||
|
@ -31,13 +31,13 @@ public class MySQLDB extends SQLDB {
|
||||
@Override
|
||||
public Connection getNewConnection() {
|
||||
FileConfiguration config = Plan.getInstance().getConfig();
|
||||
|
||||
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
|
||||
String url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getString("mysql.port") + "/" + config.getString("mysql.database");
|
||||
Connection connection = DriverManager.getConnection(url, config.getString("mysql.user"), config.getString("mysql.password"));
|
||||
|
||||
|
||||
return connection;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
Log.error(Phrase.DB_CONNECTION_FAIL.parse(getConfigName(), e.getMessage()));
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.databases;
|
||||
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import java.net.InetAddress;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
@ -7,7 +9,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -22,11 +23,7 @@ import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.tables.*;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -57,6 +54,7 @@ public abstract class SQLDB extends Database {
|
||||
nicknamesTable = new NicknamesTable(this, usingMySQL);
|
||||
commandUseTable = new CommandUseTable(this, usingMySQL);
|
||||
versionTable = new VersionTable(this, usingMySQL);
|
||||
tpsTable = new TPSTable(this, usingMySQL);
|
||||
|
||||
startConnectionPingTask(plugin);
|
||||
}
|
||||
@ -69,7 +67,7 @@ public abstract class SQLDB extends Database {
|
||||
*/
|
||||
public void startConnectionPingTask(Plan plugin) throws IllegalArgumentException, IllegalStateException {
|
||||
// Maintains Connection.
|
||||
new BukkitRunnable() {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("DBConnectionPingTask " + getName()) {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -80,7 +78,7 @@ public abstract class SQLDB extends Database {
|
||||
connection = getNewConnection();
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(plugin, 60 * 20, 60 * 20);
|
||||
}).runTaskTimerAsynchronously(60 * 20, 60 * 20);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,12 +88,14 @@ public abstract class SQLDB extends Database {
|
||||
@Override
|
||||
public boolean init() {
|
||||
super.init();
|
||||
setStatus("Init");
|
||||
Benchmark.start("Database Init " + getConfigName());
|
||||
try {
|
||||
if (!checkConnection()) {
|
||||
return false;
|
||||
}
|
||||
convertBukkitDataToDB();
|
||||
clean();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
@ -150,7 +150,7 @@ public abstract class SQLDB extends Database {
|
||||
*
|
||||
*/
|
||||
public void convertBukkitDataToDB() {
|
||||
new BukkitRunnable() {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("BukkitDataConversionTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -161,6 +161,7 @@ public abstract class SQLDB extends Database {
|
||||
Log.debug("No conversion necessary.");
|
||||
return;
|
||||
}
|
||||
setStatus("Bukkit Data Conversion");
|
||||
Log.info("Beginning Bukkit Data -> DB Conversion for " + uuids.size() + " players");
|
||||
int id = plugin.getBootAnalysisTaskID();
|
||||
if (id != -1) {
|
||||
@ -171,9 +172,12 @@ public abstract class SQLDB extends Database {
|
||||
Log.info("Conversion complete, took: " + FormatUtils.formatTimeAmount(Benchmark.stop("Convert Bukkitdata to DB data")) + " ms");
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
} finally {
|
||||
setAvailable();
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,7 +185,7 @@ public abstract class SQLDB extends Database {
|
||||
* @return
|
||||
*/
|
||||
public Table[] getAllTables() {
|
||||
return new Table[]{usersTable, locationsTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, commandUseTable};
|
||||
return new Table[]{usersTable, locationsTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, commandUseTable, tpsTable};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,7 +193,7 @@ public abstract class SQLDB extends Database {
|
||||
* @return
|
||||
*/
|
||||
public Table[] getAllTablesInRemoveOrder() {
|
||||
return new Table[]{locationsTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, usersTable, commandUseTable};
|
||||
return new Table[]{locationsTable, gmTimesTable, ipsTable, nicknamesTable, sessionsTable, killsTable, usersTable, commandUseTable, tpsTable};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,6 +211,7 @@ public abstract class SQLDB extends Database {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
setStatus("Closed");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -238,11 +243,14 @@ public abstract class SQLDB extends Database {
|
||||
if (uuid == null) {
|
||||
return false;
|
||||
}
|
||||
setStatus("User exist check");
|
||||
try {
|
||||
return usersTable.getUserId(uuid.toString()) != -1;
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
return false;
|
||||
} finally {
|
||||
setAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,6 +266,7 @@ public abstract class SQLDB extends Database {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
setStatus("Remove account " + uuid);
|
||||
Benchmark.start("Database remove Account " + uuid);
|
||||
try {
|
||||
checkConnection();
|
||||
@ -278,6 +287,7 @@ public abstract class SQLDB extends Database {
|
||||
&& usersTable.removeUser(uuid);
|
||||
} finally {
|
||||
Benchmark.stop("Database remove Account " + uuid);
|
||||
setAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -300,6 +310,7 @@ public abstract class SQLDB extends Database {
|
||||
if (!wasSeenBefore(uuid)) {
|
||||
return;
|
||||
}
|
||||
setStatus("Get single userdata for " + uuid);
|
||||
// Get the data
|
||||
UserData data = usersTable.getUserData(uuid);
|
||||
|
||||
@ -314,7 +325,7 @@ public abstract class SQLDB extends Database {
|
||||
List<InetAddress> ips = ipsTable.getIPAddresses(userId);
|
||||
data.addIpAddresses(ips);
|
||||
|
||||
HashMap<GameMode, Long> times = gmTimesTable.getGMTimes(userId);
|
||||
Map<Gamemode, Long> times = gmTimesTable.getGMTimes(userId);
|
||||
data.setGmTimes(times);
|
||||
List<SessionData> sessions = sessionsTable.getSessionData(userId);
|
||||
data.addSessions(sessions);
|
||||
@ -323,6 +334,7 @@ public abstract class SQLDB extends Database {
|
||||
processor.process(data);
|
||||
});
|
||||
Benchmark.stop("DB Give userdata to processors");
|
||||
setAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -336,7 +348,7 @@ public abstract class SQLDB extends Database {
|
||||
if (uuidsCol == null || uuidsCol.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
setStatus("Get userdata (multiple) for: " + uuidsCol.size());
|
||||
Benchmark.start("DB get UserData for " + uuidsCol.size());
|
||||
Map<UUID, Integer> userIds = usersTable.getAllUserIds();
|
||||
Set<UUID> remove = uuidsCol.stream()
|
||||
@ -358,6 +370,7 @@ public abstract class SQLDB extends Database {
|
||||
Map<Integer, Set<InetAddress>> ipList = ipsTable.getIPList(ids);
|
||||
Map<Integer, List<KillData>> playerKills = killsTable.getPlayerKills(ids, idUuidRel);
|
||||
Map<Integer, List<SessionData>> sessionData = sessionsTable.getSessionData(ids);
|
||||
Map<Integer, Map<Gamemode, Long>> gmTimes = gmTimesTable.getGMTimes(ids);
|
||||
Log.debug("Sizes: UUID:" + uuids.size() + " DATA:" + data.size() + " ID:" + userIds.size() + " N:" + nicknames.size() + " I:" + ipList.size() + " K:" + playerKills.size() + " S:" + sessionData.size());
|
||||
for (UserData uData : data) {
|
||||
UUID uuid = uData.getUuid();
|
||||
@ -366,9 +379,10 @@ public abstract class SQLDB extends Database {
|
||||
uData.addNicknames(nicknames.get(id));
|
||||
uData.addSessions(sessionData.get(id));
|
||||
uData.setPlayerKills(playerKills.get(id));
|
||||
uData.setGmTimes(gmTimesTable.getGMTimes(id));
|
||||
uData.setGmTimes(gmTimes.get(id));
|
||||
}
|
||||
Benchmark.stop("DB get UserData for " + uuidsCol.size());
|
||||
setAvailable();
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -384,6 +398,7 @@ public abstract class SQLDB extends Database {
|
||||
if (data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
setStatus("Save userdata (multiple) for " + data.size());
|
||||
usersTable.saveUserDataInformationBatch(data);
|
||||
// Transform to map
|
||||
Map<UUID, UserData> userDatas = data.stream().collect(Collectors.toMap(UserData::getUuid, Function.identity()));
|
||||
@ -397,7 +412,7 @@ public abstract class SQLDB extends Database {
|
||||
Map<Integer, List<KillData>> kills = new HashMap<>();
|
||||
Map<Integer, UUID> uuids = userIds.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
|
||||
Map<Integer, List<SessionData>> sessions = new HashMap<>();
|
||||
Map<Integer, Map<GameMode, Long>> gmTimes = new HashMap<>();
|
||||
Map<Integer, Map<Gamemode, Long>> gmTimes = new HashMap<>();
|
||||
// Put to dataset
|
||||
for (UUID uuid : userDatas.keySet()) {
|
||||
Integer id = userIds.get(uuid);
|
||||
@ -421,11 +436,7 @@ public abstract class SQLDB extends Database {
|
||||
ipsTable.saveIPList(ips);
|
||||
killsTable.savePlayerKills(kills, uuids);
|
||||
sessionsTable.saveSessionData(sessions);
|
||||
Benchmark.start("Save GMTimes");
|
||||
for (Integer id : gmTimes.keySet()) {
|
||||
gmTimesTable.saveGMTimes(id, gmTimes.get(id));
|
||||
}
|
||||
Benchmark.stop("Save GMTimes");
|
||||
gmTimesTable.saveGMTimes(gmTimes);
|
||||
userDatas.values().stream()
|
||||
.filter(u -> u != null)
|
||||
.filter(uData -> uData.isAccessed())
|
||||
@ -433,6 +444,7 @@ public abstract class SQLDB extends Database {
|
||||
uData.stopAccessing();
|
||||
});
|
||||
Benchmark.stop("DB Save multiple Userdata");
|
||||
setAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -449,6 +461,7 @@ public abstract class SQLDB extends Database {
|
||||
if (uuid == null) {
|
||||
return;
|
||||
}
|
||||
setStatus("Save userdata: " + uuid);
|
||||
checkConnection();
|
||||
Log.debug("DB_Save: " + data);
|
||||
data.access();
|
||||
@ -461,6 +474,7 @@ public abstract class SQLDB extends Database {
|
||||
killsTable.savePlayerKills(userId, new ArrayList<>(data.getPlayerKills()));
|
||||
gmTimesTable.saveGMTimes(userId, data.getGmTimes());
|
||||
data.stopAccessing();
|
||||
setAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -471,8 +485,8 @@ public abstract class SQLDB extends Database {
|
||||
Log.info("Cleaning the database.");
|
||||
try {
|
||||
checkConnection();
|
||||
commandUseTable.clean();
|
||||
sessionsTable.clean();
|
||||
tpsTable.clean();
|
||||
// sessionsTable.clean();
|
||||
Log.info("Clean complete.");
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
@ -485,11 +499,13 @@ public abstract class SQLDB extends Database {
|
||||
*/
|
||||
@Override
|
||||
public boolean removeAllData() {
|
||||
setStatus("Clearing all data");
|
||||
for (Table table : getAllTablesInRemoveOrder()) {
|
||||
if (!table.removeAllData()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
setAvailable();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -508,4 +524,12 @@ public abstract class SQLDB extends Database {
|
||||
public Connection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
private void setStatus(String status) {
|
||||
plugin.processStatus().setStatus("DB-" + getName(), status);
|
||||
}
|
||||
|
||||
private void setAvailable() {
|
||||
setStatus("Running");
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class SQLiteDB extends SQLDB {
|
||||
public SQLiteDB(Plan plugin) {
|
||||
this(plugin, "database");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param plugin
|
||||
@ -42,7 +42,7 @@ public class SQLiteDB extends SQLDB {
|
||||
public Connection getNewConnection() {
|
||||
return getNewConnection(dbName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dbName
|
||||
@ -51,8 +51,8 @@ public class SQLiteDB extends SQLDB {
|
||||
public Connection getNewConnection(String dbName) {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
Connection connection = DriverManager.getConnection("jdbc:sqlite:" + new File(plugin.getDataFolder(), dbName+".db").getAbsolutePath());
|
||||
|
||||
Connection connection = DriverManager.getConnection("jdbc:sqlite:" + new File(plugin.getDataFolder(), dbName + ".db").getAbsolutePath());
|
||||
|
||||
return connection;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
return null;
|
||||
|
@ -6,7 +6,6 @@ import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
|
||||
@ -62,7 +61,7 @@ public class CommandUseTable extends Table {
|
||||
statement = prepareStatement("SELECT * FROM " + tableName);
|
||||
set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
String cmd = set.getString(columnCommand);
|
||||
String cmd = set.getString(columnCommand).toLowerCase();
|
||||
int amountUsed = set.getInt(columnTimesUsed);
|
||||
Integer get = commandUse.get(cmd);
|
||||
if (get != null && get > amountUsed) {
|
||||
@ -157,11 +156,4 @@ public class CommandUseTable extends Table {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void clean() throws SQLException {
|
||||
Map<String, Integer> commandUse = getCommandUse();
|
||||
removeAllData();
|
||||
saveCommandUse(commandUse);
|
||||
Plan.getInstance().getHandler().getCommandUseFromDb();
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,17 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import org.bukkit.GameMode;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -85,20 +89,20 @@ public class GMTimesTable extends Table {
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public HashMap<GameMode, Long> getGMTimes(int userId) throws SQLException {
|
||||
public Map<Gamemode, Long> getGMTimes(int userId) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
statement = prepareStatement("SELECT * FROM " + tableName + " WHERE (" + columnUserID + "=?)");
|
||||
statement.setInt(1, userId);
|
||||
set = statement.executeQuery();
|
||||
HashMap<GameMode, Long> times = new HashMap<>();
|
||||
HashMap<Gamemode, Long> times = new HashMap<>();
|
||||
while (set.next()) {
|
||||
times.put(GameMode.SURVIVAL, set.getLong(columnSurvivalTime));
|
||||
times.put(GameMode.CREATIVE, set.getLong(columnCreativeTime));
|
||||
times.put(GameMode.ADVENTURE, set.getLong(columnAdventureTime));
|
||||
times.put(Gamemode.SURVIVAL, set.getLong(columnSurvivalTime));
|
||||
times.put(Gamemode.CREATIVE, set.getLong(columnCreativeTime));
|
||||
times.put(Gamemode.ADVENTURE, set.getLong(columnAdventureTime));
|
||||
try {
|
||||
times.put(GameMode.SPECTATOR, set.getLong(columnSpectatorTime));
|
||||
times.put(Gamemode.SPECTATOR, set.getLong(columnSpectatorTime));
|
||||
} catch (NoSuchFieldError e) {
|
||||
}
|
||||
}
|
||||
@ -109,19 +113,47 @@ public class GMTimesTable extends Table {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Integer, Map<Gamemode, Long>> getGMTimes(Collection<Integer> userIds) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
Map<Integer, Map<Gamemode, Long>> times = new HashMap<>();
|
||||
try {
|
||||
statement = prepareStatement("SELECT * FROM " + tableName);
|
||||
set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
Map<Gamemode, Long> gmTimes = new HashMap<>();
|
||||
int id = set.getInt(columnUserID);
|
||||
if (!userIds.contains(id)) {
|
||||
continue;
|
||||
}
|
||||
gmTimes.put(Gamemode.SURVIVAL, set.getLong(columnSurvivalTime));
|
||||
gmTimes.put(Gamemode.CREATIVE, set.getLong(columnCreativeTime));
|
||||
gmTimes.put(Gamemode.ADVENTURE, set.getLong(columnAdventureTime));
|
||||
try {
|
||||
gmTimes.put(Gamemode.SPECTATOR, set.getLong(columnSpectatorTime));
|
||||
} catch (NoSuchFieldError e) {
|
||||
}
|
||||
times.put(id, gmTimes);
|
||||
}
|
||||
return times;
|
||||
} finally {
|
||||
close(set);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId
|
||||
* @param gamemodeTimes
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void saveGMTimes(int userId, Map<GameMode, Long> gamemodeTimes) throws SQLException {
|
||||
public void saveGMTimes(int userId, Map<Gamemode, Long> gamemodeTimes) throws SQLException {
|
||||
if (gamemodeTimes == null || gamemodeTimes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PreparedStatement statement = null;
|
||||
GameMode[] gms = new GameMode[]{GameMode.SURVIVAL, GameMode.CREATIVE, GameMode.ADVENTURE, GameMode.SPECTATOR};
|
||||
Gamemode[] gms = Gamemode.values();
|
||||
int update = 0;
|
||||
try {
|
||||
statement = prepareStatement(
|
||||
@ -151,12 +183,119 @@ public class GMTimesTable extends Table {
|
||||
if (update == 0) {
|
||||
addNewGMTimesRow(userId, gamemodeTimes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addNewGMTimesRow(int userId, Map<GameMode, Long> gamemodeTimes) throws SQLException {
|
||||
private Set<Integer> getSavedIDs() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
GameMode[] gms = new GameMode[]{GameMode.SURVIVAL, GameMode.CREATIVE, GameMode.ADVENTURE, GameMode.SPECTATOR};
|
||||
ResultSet set = null;
|
||||
try {
|
||||
statement = prepareStatement("SELECT " + columnUserID + " FROM " + tableName);
|
||||
set = statement.executeQuery();
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
while (set.next()) {
|
||||
ids.add(set.getInt(columnUserID));
|
||||
}
|
||||
return ids;
|
||||
} finally {
|
||||
close(set);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveGMTimes(Map<Integer, Map<Gamemode, Long>> gamemodeTimes) throws SQLException {
|
||||
if (gamemodeTimes == null || gamemodeTimes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Benchmark.start("Save GMTimes");
|
||||
PreparedStatement statement = null;
|
||||
Gamemode[] gms = Gamemode.values();
|
||||
Set<Integer> savedIDs = getSavedIDs();
|
||||
try {
|
||||
statement = prepareStatement(
|
||||
"UPDATE " + tableName + " SET "
|
||||
+ columnSurvivalTime + "=?, "
|
||||
+ columnCreativeTime + "=?, "
|
||||
+ columnAdventureTime + "=?, "
|
||||
+ columnSpectatorTime + "=? "
|
||||
+ " WHERE (" + columnUserID + "=?)");
|
||||
boolean commitRequired = false;
|
||||
for (Integer id : gamemodeTimes.keySet()) {
|
||||
if (!savedIDs.contains(id)) {
|
||||
continue;
|
||||
}
|
||||
statement.setInt(5, id);
|
||||
for (int i = 0; i < gms.length; i++) {
|
||||
try {
|
||||
Map<Gamemode, Long> times = gamemodeTimes.get(id);
|
||||
Long time = times.get(gms[i]);
|
||||
if (time != null) {
|
||||
statement.setLong(i + 1, time);
|
||||
} else {
|
||||
statement.setLong(i + 1, 0);
|
||||
}
|
||||
} catch (NoSuchFieldError e) {
|
||||
statement.setLong(i + 1, 0);
|
||||
}
|
||||
}
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
}
|
||||
if (commitRequired) {
|
||||
statement.executeBatch();
|
||||
}
|
||||
gamemodeTimes.keySet().removeAll(savedIDs);
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
addNewGMTimesRows(gamemodeTimes);
|
||||
Benchmark.stop("Save GMTimes");
|
||||
}
|
||||
|
||||
private void addNewGMTimesRows(Map<Integer, Map<Gamemode, Long>> gamemodeTimes) throws SQLException {
|
||||
if (gamemodeTimes == null || gamemodeTimes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
Gamemode[] gms = Gamemode.values();
|
||||
try {
|
||||
statement = prepareStatement(
|
||||
"INSERT INTO " + tableName + " ("
|
||||
+ columnUserID + ", "
|
||||
+ columnSurvivalTime + ", "
|
||||
+ columnCreativeTime + ", "
|
||||
+ columnAdventureTime + ", "
|
||||
+ columnSpectatorTime
|
||||
+ ") VALUES (?, ?, ?, ?, ?)");
|
||||
boolean commitRequired = false;
|
||||
for (Integer id : gamemodeTimes.keySet()) {
|
||||
statement.setInt(1, id);
|
||||
for (int i = 0; i < gms.length; i++) {
|
||||
try {
|
||||
Map<Gamemode, Long> times = gamemodeTimes.get(id);
|
||||
Long time = times.get(gms[i]);
|
||||
if (time != null) {
|
||||
statement.setLong(i + 2, time);
|
||||
} else {
|
||||
statement.setLong(i + 2, 0);
|
||||
}
|
||||
} catch (NoSuchFieldError e) {
|
||||
statement.setLong(i + 2, 0);
|
||||
}
|
||||
}
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
}
|
||||
if (commitRequired) {
|
||||
statement.executeBatch();
|
||||
}
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
private void addNewGMTimesRow(int userId, Map<Gamemode, Long> gamemodeTimes) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
Gamemode[] gms = Gamemode.values();
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
+ columnUserID + ", "
|
||||
|
@ -224,12 +224,12 @@ public class IPsTable extends Table {
|
||||
}
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing ips batch: "+i);
|
||||
Log.debug("Executing ips batch: " + i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
Benchmark.stop("Save Ips Multiple " + ips.size());
|
||||
} finally {
|
||||
close(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -255,13 +255,13 @@ public class KillsTable extends Table {
|
||||
i++;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing kills batch: "+i);
|
||||
Log.debug("Executing kills batch: " + i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
}
|
||||
Benchmark.stop("Save Kills multiple " + kills.size());
|
||||
} finally {
|
||||
close(statement);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,12 @@ public class LocationsTable extends Table {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param worlds
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<Integer, List<Location>> getAllLocations(Map<String, World> worlds) throws SQLException {
|
||||
Benchmark.start("Get Locations Multiple");
|
||||
PreparedStatement statement = null;
|
||||
@ -174,7 +180,7 @@ public class LocationsTable extends Table {
|
||||
i++;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing locations batch: "+i);
|
||||
Log.debug("Executing locations batch: " + i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
} finally {
|
||||
@ -223,7 +229,7 @@ public class LocationsTable extends Table {
|
||||
}
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing locations batch: "+i);
|
||||
Log.debug("Executing locations batch: " + i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
} finally {
|
||||
|
@ -166,7 +166,7 @@ public class NicknamesTable extends Table {
|
||||
i++;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing nicknames batch: "+i);
|
||||
Log.debug("Executing nicknames batch: " + i);
|
||||
statement.executeBatch();
|
||||
|
||||
}
|
||||
@ -186,7 +186,7 @@ public class NicknamesTable extends Table {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
Benchmark.start("Get Nicknames Multiple "+ids.size());
|
||||
Benchmark.start("Get Nicknames Multiple " + ids.size());
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
@ -223,7 +223,7 @@ public class NicknamesTable extends Table {
|
||||
} finally {
|
||||
close(set);
|
||||
close(statement);
|
||||
Benchmark.stop("Get Nicknames Multiple "+ids.size());
|
||||
Benchmark.stop("Get Nicknames Multiple " + ids.size());
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ public class NicknamesTable extends Table {
|
||||
if (nicknames == null || nicknames.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Benchmark.start("Save Nicknames Multiple "+nicknames.size());
|
||||
Benchmark.start("Save Nicknames Multiple " + nicknames.size());
|
||||
Map<Integer, List<String>> saved = getNicknames(nicknames.keySet());
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
@ -270,7 +270,7 @@ public class NicknamesTable extends Table {
|
||||
}
|
||||
} finally {
|
||||
close(statement);
|
||||
Benchmark.stop("Save Nicknames Multiple "+nicknames.size());
|
||||
Benchmark.stop("Save Nicknames Multiple " + nicknames.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,6 +224,9 @@ public class SessionsTable extends Table {
|
||||
}
|
||||
|
||||
private void saveSessionBatch(List<Container<SessionData>> batch) throws SQLException {
|
||||
if (batch.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
@ -256,6 +259,10 @@ public class SessionsTable extends Table {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void clean() throws SQLException {
|
||||
Map<Integer, Integer> loginTimes = db.getUsersTable().getLoginTimes();
|
||||
Map<Integer, List<SessionData>> allSessions = getSessionData(loginTimes.keySet());
|
||||
|
@ -0,0 +1,138 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.javaplugin.api.TimeAmount;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
|
||||
/**
|
||||
* Class representing database table plan_tps
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class TPSTable extends Table {
|
||||
|
||||
private final String columnDate;
|
||||
private final String columnTPS;
|
||||
private final String columnPlayers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param db
|
||||
* @param usingMySQL
|
||||
*/
|
||||
public TPSTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_tps", db, usingMySQL);
|
||||
columnDate = "date";
|
||||
columnTPS = "tps";
|
||||
columnPlayers = "players_online";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
try {
|
||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
||||
+ columnDate + " bigint NOT NULL, "
|
||||
+ columnTPS + " double NOT NULL, "
|
||||
+ columnPlayers + " integer NOT NULL"
|
||||
+ ")"
|
||||
);
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return @throws SQLException
|
||||
*/
|
||||
public List<TPS> getTPSData() throws SQLException {
|
||||
Benchmark.start("Get TPS");
|
||||
List<TPS> data = new ArrayList<>();
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
statement = prepareStatement("SELECT * FROM " + tableName);
|
||||
set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
long date = set.getLong(columnDate);
|
||||
double tps = set.getDouble(columnTPS);
|
||||
int players = set.getInt(columnPlayers);
|
||||
data.add(new TPS(date, tps, players));
|
||||
}
|
||||
return data;
|
||||
} finally {
|
||||
close(set);
|
||||
close(statement);
|
||||
Benchmark.stop("Get TPS");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void saveTPSData(List<TPS> data) throws SQLException {
|
||||
List<List<TPS>> batches = DBUtils.splitIntoBatches(data);
|
||||
for (List<TPS> batch : batches) {
|
||||
saveTPSBatch(batch);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveTPSBatch(List<TPS> batch) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
+ columnDate + ", "
|
||||
+ columnTPS + ", "
|
||||
+ columnPlayers
|
||||
+ ") VALUES (?, ?, ?)");
|
||||
|
||||
boolean commitRequired = false;
|
||||
int i = 0;
|
||||
for (TPS tps : batch) {
|
||||
statement.setLong(1, tps.getDate());
|
||||
statement.setDouble(2, tps.getTps());
|
||||
statement.setInt(3, tps.getPlayers());
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing tps batch: " + i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void clean() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnDate + "<?)");
|
||||
// More than 8 days ago.
|
||||
long eightDays = TimeAmount.DAY.ms() * 8L;
|
||||
statement.setLong(1, MiscUtils.getTime() - eightDays);
|
||||
statement.execute();
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
@ -42,17 +42,16 @@ public abstract class Table {
|
||||
this.db = db;
|
||||
this.usingMySQL = usingMySQL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean createTable();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws SQLException
|
||||
* @return @throws SQLException
|
||||
*/
|
||||
protected Connection getConnection() throws SQLException {
|
||||
Connection connection = db.getConnection();
|
||||
@ -61,11 +60,10 @@ public abstract class Table {
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws SQLException
|
||||
* @return @throws SQLException
|
||||
*/
|
||||
public int getVersion() throws SQLException {
|
||||
return db.getVersion();
|
||||
@ -82,7 +80,7 @@ public abstract class Table {
|
||||
boolean success = connection.createStatement().execute(sql);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sql
|
||||
@ -92,7 +90,7 @@ public abstract class Table {
|
||||
protected PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
return getConnection().prepareStatement(sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param toClose
|
||||
@ -113,7 +111,7 @@ public abstract class Table {
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
@ -127,8 +125,14 @@ public abstract class Table {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <T>
|
||||
* @param objects
|
||||
* @return
|
||||
*/
|
||||
protected <T> List<List<Container<T>>> splitIntoBatches(Map<Integer, List<T>> objects) {
|
||||
return DBUtils.splitIntoBatches(objects);
|
||||
return DBUtils.splitIntoBatchesId(objects);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import com.djrapitops.javaplugin.utilities.player.Fetch;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@ -14,14 +16,15 @@ import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.Gender;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.GameMode;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -294,7 +297,7 @@ public class UsersTable extends Table {
|
||||
data = getUserDataForKnown(uuid);
|
||||
}
|
||||
if (data == null) {
|
||||
data = new UserData(getOfflinePlayer(uuid), new DemographicsData());
|
||||
data = new UserData(Fetch.getOfflinePlayer(uuid, Plan.class), new DemographicsData());
|
||||
addUserInformationToUserData(data);
|
||||
}
|
||||
Benchmark.stop(uuid + " Get UserData");
|
||||
@ -336,7 +339,7 @@ public class UsersTable extends Table {
|
||||
List<UserData> noBukkitData = new ArrayList<>();
|
||||
Benchmark.start("Create UserData objects for No BukkitData players " + uuids.size());
|
||||
for (UUID uuid : uuids) {
|
||||
UserData uData = new UserData(getOfflinePlayer(uuid), new DemographicsData());
|
||||
UserData uData = new UserData(Fetch.getOfflinePlayer(uuid, Plan.class), new DemographicsData());
|
||||
noBukkitData.add(uData);
|
||||
}
|
||||
Benchmark.stop("Create UserData objects for No BukkitData players " + uuids.size());
|
||||
@ -392,7 +395,7 @@ public class UsersTable extends Table {
|
||||
demData.setAge(set.getInt(columnDemAge));
|
||||
demData.setGender(Gender.parse(set.getString(columnDemGender)));
|
||||
demData.setGeoLocation(set.getString(columnDemGeoLocation));
|
||||
GameMode gm = GameMode.valueOf(set.getString(columnLastGM));
|
||||
Gamemode gm = Gamemode.valueOf(set.getString(columnLastGM));
|
||||
boolean op = set.getBoolean(columnOP);
|
||||
boolean banned = set.getBoolean(columnBanned);
|
||||
String name = set.getString(columnName);
|
||||
@ -434,7 +437,7 @@ public class UsersTable extends Table {
|
||||
demData.setAge(set.getInt(columnDemAge));
|
||||
demData.setGender(Gender.parse(set.getString(columnDemGender)));
|
||||
demData.setGeoLocation(set.getString(columnDemGeoLocation));
|
||||
GameMode gm = GameMode.valueOf(set.getString(columnLastGM));
|
||||
Gamemode gm = Gamemode.valueOf(set.getString(columnLastGM));
|
||||
boolean op = set.getBoolean(columnOP);
|
||||
boolean banned = set.getBoolean(columnBanned);
|
||||
String name = set.getString(columnName);
|
||||
@ -475,7 +478,7 @@ public class UsersTable extends Table {
|
||||
data.getDemData().setAge(set.getInt(columnDemAge));
|
||||
data.getDemData().setGender(Gender.parse(set.getString(columnDemGender)));
|
||||
data.getDemData().setGeoLocation(set.getString(columnDemGeoLocation));
|
||||
data.setLastGamemode(GameMode.valueOf(set.getString(columnLastGM)));
|
||||
data.setLastGamemode(Gamemode.valueOf(set.getString(columnLastGM)));
|
||||
data.setLastGmSwapTime(set.getLong(columnLastGMSwapTime));
|
||||
data.setPlayTime(set.getLong(columnPlayTime));
|
||||
data.setLoginTimes(set.getInt(columnLoginTimes));
|
||||
@ -513,7 +516,7 @@ public class UsersTable extends Table {
|
||||
uData.getDemData().setAge(set.getInt(columnDemAge));
|
||||
uData.getDemData().setGender(Gender.parse(set.getString(columnDemGender)));
|
||||
uData.getDemData().setGeoLocation(set.getString(columnDemGeoLocation));
|
||||
uData.setLastGamemode(GameMode.valueOf(set.getString(columnLastGM)));
|
||||
uData.setLastGamemode(Gamemode.valueOf(set.getString(columnLastGM)));
|
||||
uData.setLastGmSwapTime(set.getLong(columnLastGMSwapTime));
|
||||
uData.setPlayTime(set.getLong(columnPlayTime));
|
||||
uData.setLoginTimes(set.getInt(columnLoginTimes));
|
||||
@ -563,11 +566,11 @@ public class UsersTable extends Table {
|
||||
statement.setInt(1, data.getDemData().getAge());
|
||||
statement.setString(2, data.getDemData().getGender().toString().toLowerCase());
|
||||
statement.setString(3, data.getDemData().getGeoLocation());
|
||||
GameMode gm = data.getLastGamemode();
|
||||
Gamemode gm = data.getLastGamemode();
|
||||
if (gm != null) {
|
||||
statement.setString(4, data.getLastGamemode().name());
|
||||
} else {
|
||||
statement.setString(4, GameMode.SURVIVAL.name());
|
||||
statement.setString(4, Gamemode.SURVIVAL.name());
|
||||
}
|
||||
statement.setLong(5, data.getLastGmSwapTime());
|
||||
statement.setLong(6, data.getPlayTime());
|
||||
@ -608,11 +611,11 @@ public class UsersTable extends Table {
|
||||
statement.setInt(2, data.getDemData().getAge());
|
||||
statement.setString(3, data.getDemData().getGender().toString().toLowerCase());
|
||||
statement.setString(4, data.getDemData().getGeoLocation());
|
||||
GameMode gm = data.getLastGamemode();
|
||||
Gamemode gm = data.getLastGamemode();
|
||||
if (gm != null) {
|
||||
statement.setString(5, data.getLastGamemode().name());
|
||||
} else {
|
||||
statement.setString(5, GameMode.SURVIVAL.name());
|
||||
statement.setString(5, Gamemode.SURVIVAL.name());
|
||||
}
|
||||
statement.setLong(6, data.getLastGmSwapTime());
|
||||
statement.setLong(7, data.getPlayTime());
|
||||
@ -643,7 +646,12 @@ public class UsersTable extends Table {
|
||||
try {
|
||||
List<UserData> newUserdata = updateExistingUserData(data);
|
||||
Benchmark.start("Insert new UserInfo multiple " + newUserdata.size());
|
||||
insertNewUserData(newUserdata);
|
||||
List<List<UserData>> batches = DBUtils.splitIntoBatches(newUserdata);
|
||||
for (List<UserData> batch : batches) {
|
||||
Benchmark.start("Insert new UserInfo Batch " + batch.size());
|
||||
insertNewUserData(batch);
|
||||
Benchmark.stop("Insert new UserInfo Batch " + batch.size());
|
||||
}
|
||||
Benchmark.stop("Insert new UserInfo multiple " + newUserdata.size());
|
||||
} finally {
|
||||
Benchmark.stop("Save UserInfo multiple " + data.size());
|
||||
@ -679,7 +687,7 @@ public class UsersTable extends Table {
|
||||
statement.setInt(2, uData.getDemData().getAge());
|
||||
statement.setString(3, uData.getDemData().getGender().toString().toLowerCase());
|
||||
statement.setString(4, uData.getDemData().getGeoLocation());
|
||||
GameMode gm = uData.getLastGamemode();
|
||||
Gamemode gm = uData.getLastGamemode();
|
||||
if (gm != null) {
|
||||
statement.setString(5, uData.getLastGamemode().name());
|
||||
} else {
|
||||
@ -760,7 +768,7 @@ public class UsersTable extends Table {
|
||||
statement.setInt(1, uData.getDemData().getAge());
|
||||
statement.setString(2, uData.getDemData().getGender().toString().toLowerCase());
|
||||
statement.setString(3, uData.getDemData().getGeoLocation());
|
||||
GameMode gm = uData.getLastGamemode();
|
||||
Gamemode gm = uData.getLastGamemode();
|
||||
if (gm != null) {
|
||||
statement.setString(4, uData.getLastGamemode().name());
|
||||
} else {
|
||||
@ -848,6 +856,10 @@ public class UsersTable extends Table {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return @throws SQLException
|
||||
*/
|
||||
public Map<Integer, Integer> getLoginTimes() throws SQLException {
|
||||
Benchmark.start("Get Logintimes");
|
||||
PreparedStatement statement = null;
|
||||
@ -876,6 +888,12 @@ public class UsersTable extends Table {
|
||||
return columnID;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param playername
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public UUID getUuidOf(String playername) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
@ -895,6 +913,11 @@ public class UsersTable extends Table {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uuids
|
||||
* @return
|
||||
*/
|
||||
public Map<Integer, Long> getLoginTimes(Collection<UUID> uuids) {
|
||||
//TODO
|
||||
return new HashMap<>();
|
||||
|
@ -79,7 +79,7 @@ public class DataRequestHandler {
|
||||
} catch (FileNotFoundException ex) {
|
||||
return "<h1>404 analysis.html was not found</h1>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the AnalysisData is cached.
|
||||
|
@ -7,10 +7,10 @@ import main.java.com.djrapitops.plan.data.AnalysisData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,6 @@ package main.java.com.djrapitops.plan.ui.graphs;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -16,6 +15,7 @@ import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
|
||||
/**
|
||||
@ -32,7 +32,7 @@ public class PlayerActivityGraphCreator {
|
||||
*/
|
||||
public static String[] generateDataArray(List<SessionData> sessionData, long scale) {
|
||||
Benchmark.start("Generate Player Activity Graph " + sessionData.size() + " " + scale + " |");
|
||||
long now = new Date().toInstant().getEpochSecond() * (long) 1000;
|
||||
long now = MiscUtils.getTime();
|
||||
long nowMinusScale = now - scale;
|
||||
List<List<Long>> s = filterAndTransformSessions(sessionData, nowMinusScale);
|
||||
List<Long> sessionStarts = s.get(0);
|
||||
|
@ -18,7 +18,7 @@ import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SessionLengthDistributionGraphCreator {
|
||||
|
||||
@ -31,7 +31,7 @@ public class SessionLengthDistributionGraphCreator {
|
||||
List<Long> lengths = AnalysisUtils.transformSessionDataToLengths(data);
|
||||
return generateDataArray(lengths);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param lengths
|
||||
|
@ -0,0 +1,38 @@
|
||||
package main.java.com.djrapitops.plan.ui.graphs;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.TPSComparator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class TPSGraphCreator {
|
||||
|
||||
public static String[] generateDataArray(List<TPS> tpsData, long scale) {
|
||||
Benchmark.start("TPSGraph generate array");
|
||||
long now = MiscUtils.getTime();
|
||||
List<TPS> filtered = filterTPS(tpsData, now - scale);
|
||||
Log.debug("TPSGraph, filtered: " + filtered.size());
|
||||
Collections.sort(filtered, new TPSComparator());
|
||||
List<Long> dates = filtered.stream().map(t -> t.getDate()).collect(Collectors.toList());
|
||||
List<Double> tps = filtered.stream().map(t -> t.getTps()).collect(Collectors.toList());
|
||||
List<Integer> players = filtered.stream().map(t -> t.getPlayers()).collect(Collectors.toList());
|
||||
Benchmark.stop("TPSGraph generate array");
|
||||
return new String[]{dates.toString(), tps.toString(), players.toString()};
|
||||
}
|
||||
|
||||
private static List<TPS> filterTPS(List<TPS> tpsData, long nowMinusScale) {
|
||||
return tpsData.stream()
|
||||
.filter(t -> t != null)
|
||||
.filter(t -> t.getDate() >= nowMinusScale)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -27,7 +27,11 @@ public class SortableCommandUseTableCreator {
|
||||
html.append(Html.ERROR_TABLE_2.parse());
|
||||
} else {
|
||||
Collections.reverse(sorted);
|
||||
int i = 0;
|
||||
for (String[] values : sorted) {
|
||||
if (i >= 500) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
html.append(Html.TABLELINE_2.parse(values[1], values[0]));
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
@ -1,12 +1,12 @@
|
||||
package main.java.com.djrapitops.plan.ui.tables;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.Fetch;
|
||||
import com.djrapitops.javaplugin.utilities.player.IOfflinePlayer;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -30,7 +30,7 @@ public class SortableKillsTableCreator {
|
||||
break;
|
||||
}
|
||||
long date = kill.getDate();
|
||||
OfflinePlayer victim = getOfflinePlayer(kill.getVictim());
|
||||
IOfflinePlayer victim = Fetch.getIOfflinePlayer(kill.getVictim());
|
||||
String name = victim.getName();
|
||||
html += Html.TABLELINE_3_CUSTOMKEY_1.parse(
|
||||
date + "", FormatUtils.formatTimeStamp(date),
|
||||
|
@ -1,13 +1,16 @@
|
||||
package main.java.com.djrapitops.plan.ui.tables;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.ui.Html;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.UserDataLastPlayedComparator;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -20,30 +23,37 @@ public class SortablePlayersTableCreator {
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static String createSortablePlayersTable(Collection<UserData> data) {
|
||||
Benchmark.start("Create Players table "+data.size());
|
||||
String html = "";
|
||||
public static String createSortablePlayersTable(List<UserData> data) {
|
||||
Benchmark.start("Create Players table " + data.size());
|
||||
StringBuilder html = new StringBuilder();
|
||||
long now = MiscUtils.getTime();
|
||||
boolean showImages = Settings.PLAYERLIST_SHOW_IMAGES.isTrue();
|
||||
int i = 0;
|
||||
Collections.sort(data, new UserDataLastPlayedComparator());
|
||||
for (UserData uData : data) {
|
||||
if (i >= 750) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
String banOunknownOactiveOinactive = uData.isBanned() ? Html.GRAPH_BANNED.parse()
|
||||
: uData.getLoginTimes() == 1 ? Html.GRAPH_UNKNOWN.parse()
|
||||
: AnalysisUtils.isActive(now, uData.getLastPlayed(), uData.getPlayTime(), uData.getLoginTimes()) ? Html.GRAPH_ACTIVE.parse()
|
||||
: Html.GRAPH_INACTIVE.parse();
|
||||
|
||||
html += Html.TABLELINE_PLAYERS.parse(
|
||||
Html.MINOTAR_SMALL_IMG.parse(uData.getName()) + Html.LINK.parse(HtmlUtils.getInspectUrl(uData.getName()), uData.getName()),
|
||||
String img = showImages ? Html.MINOTAR_SMALL_IMG.parse(uData.getName()) : "";
|
||||
html.append(Html.TABLELINE_PLAYERS.parse(
|
||||
img + Html.LINK.parse(HtmlUtils.getInspectUrl(uData.getName()), uData.getName()),
|
||||
banOunknownOactiveOinactive,
|
||||
uData.getPlayTime() + "", FormatUtils.formatTimeAmount(uData.getPlayTime()),
|
||||
uData.getLoginTimes() + "",
|
||||
uData.getRegistered() + "", FormatUtils.formatTimeStampYear(uData.getRegistered()),
|
||||
uData.getLastPlayed() + "", FormatUtils.formatTimeStamp(uData.getLastPlayed()),
|
||||
uData.getDemData().getGeoLocation()
|
||||
);
|
||||
));
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
i++;
|
||||
}
|
||||
Benchmark.stop("Create Players table "+data.size());
|
||||
return html;
|
||||
Benchmark.stop("Create Players table " + data.size());
|
||||
return html.toString();
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ public class Request {
|
||||
|
||||
/**
|
||||
* Creates a new Request object.
|
||||
*
|
||||
* @param input InputStream to read the web request from.
|
||||
*/
|
||||
public Request(InputStream input) {
|
||||
|
@ -56,7 +56,7 @@ public class Response {
|
||||
} else {
|
||||
givenCode = requestArgs[1];
|
||||
}
|
||||
|
||||
|
||||
if (!givenCode.equals(securityCode)) {
|
||||
forbidden = true;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.ui.webserver;
|
||||
|
||||
import com.djrapitops.javaplugin.task.runnable.RslRunnable;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -12,7 +13,6 @@ import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.ui.DataRequestHandler;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -60,7 +60,7 @@ public class WebSocketServer {
|
||||
System.exit(1);
|
||||
}
|
||||
//Run server in seperate thread
|
||||
(new BukkitRunnable() {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("WebServerTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
while (!shutdown) {
|
||||
@ -76,7 +76,7 @@ public class WebSocketServer {
|
||||
Response response = new Response(output, dataReqHandler);
|
||||
response.setRequest(request);
|
||||
response.sendStaticResource();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
} finally {
|
||||
Closeable[] close = new Closeable[]{input, output, socket};
|
||||
for (Closeable closeable : close) {
|
||||
@ -85,14 +85,14 @@ public class WebSocketServer {
|
||||
closeable.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
}).runTaskAsynchronously();
|
||||
|
||||
ENABLED = true;
|
||||
|
||||
|
@ -1,32 +1,32 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.BenchmarkUtil;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class Benchmark {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public static void start(String source) {
|
||||
BenchmarkUtil.start(source);
|
||||
Plan.getInstance().benchmark().start(source);
|
||||
Log.debug(source);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public static long stop(String source) {
|
||||
long ms = BenchmarkUtil.stop(source);
|
||||
long ms = Plan.getInstance().benchmark().stop(source);
|
||||
if (ms != -1) {
|
||||
Log.debug(source + " took " + ms+" ms");
|
||||
Log.debug(source + " took " + ms + " ms");
|
||||
}
|
||||
return ms;
|
||||
}
|
||||
|
57
Plan/src/main/java/com/djrapitops/plan/utilities/Check.java
Normal file
57
Plan/src/main/java/com/djrapitops/plan/utilities/Check.java
Normal file
@ -0,0 +1,57 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
|
||||
/**
|
||||
* Class containing static check methods with message sending capabilities if
|
||||
* the check is false.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class Check {
|
||||
|
||||
/**
|
||||
* If check is false, send message.
|
||||
*
|
||||
* @param condition Condition.
|
||||
* @param message Message to send if Condition is false
|
||||
* @return Condition
|
||||
*/
|
||||
public static boolean ifTrue(boolean condition, String message) {
|
||||
if (!condition) {
|
||||
Log.infoColor(message);
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* If check is false, send message to sender.
|
||||
*
|
||||
* @param condition Condition.
|
||||
* @param message Message to send if Condition is false
|
||||
* @param sender Sender to send message to
|
||||
* @return Condition
|
||||
*/
|
||||
public static boolean ifTrue(boolean condition, String message, ISender sender) {
|
||||
if (!condition) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* If check is false, send error message.
|
||||
*
|
||||
* @param condition Condition.
|
||||
* @param message Message to send if Condition is false
|
||||
* @return Condition
|
||||
*/
|
||||
public static boolean ifTrue_Error(boolean condition, String message) {
|
||||
if (!condition) {
|
||||
Log.error(message);
|
||||
Log.toLog(message, Log.getErrorsFilename());
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
}
|
@ -39,10 +39,20 @@ public class FormatUtils {
|
||||
return FormattingUtils.formatTimeStamp(epochMs);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param epochMs
|
||||
* @return
|
||||
*/
|
||||
public static String formatTimeStampSecond(long epochMs) {
|
||||
return FormattingUtils.formatTimeStampSecond(epochMs);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param epochMs
|
||||
* @return
|
||||
*/
|
||||
public static String formatTimeStampYear(long epochMs) {
|
||||
return FormattingUtils.formatTimeStampYear(epochMs);
|
||||
}
|
||||
|
@ -49,10 +49,14 @@ public class HtmlUtils {
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getServerAnalysisUrlWithProtocol() {
|
||||
return Settings.LINK_PROTOCOL.toString()+":"+getServerAnalysisUrl();
|
||||
return Settings.LINK_PROTOCOL.toString() + ":" + getServerAnalysisUrl();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
@ -65,14 +69,19 @@ public class HtmlUtils {
|
||||
if (useAlternativeIP) {
|
||||
ip = Settings.ALTERNATIVE_IP.toString().replaceAll("%port%", "" + port);
|
||||
}
|
||||
String url = /*"http:*/"//" + ip + "/" + securityCode + "/server";
|
||||
String url = /*"http:*/ "//" + ip + "/" + securityCode + "/server";
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param playerName
|
||||
* @return
|
||||
*/
|
||||
public static String getInspectUrlWithProtocol(String playerName) {
|
||||
return Settings.LINK_PROTOCOL.toString()+":"+getInspectUrl(playerName);
|
||||
return Settings.LINK_PROTOCOL.toString() + ":" + getInspectUrl(playerName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param playerName
|
||||
@ -86,7 +95,7 @@ public class HtmlUtils {
|
||||
if (useAlternativeIP) {
|
||||
ip = Settings.ALTERNATIVE_IP.toString().replaceAll("%port%", "" + port);
|
||||
}
|
||||
String url = /*"http:*/"//" + ip + "/" + securityCode + "/player/" + playerName;
|
||||
String url = /*"http:*/ "//" + ip + "/" + securityCode + "/player/" + playerName;
|
||||
return url;
|
||||
}
|
||||
|
||||
@ -124,7 +133,7 @@ public class HtmlUtils {
|
||||
if (!sizeIsEvenNumber) {
|
||||
int lastIndex = pluginNames.size() - 1;
|
||||
String name = pluginNames.get(lastIndex);
|
||||
html.append(Html.COLUMNS_DIV_WRAPPER.parse(Html.COLUMN_DIV_WRAPPER.parse(getContent(name, placeholders.get(name)))+Html.COLUMN_DIV_WRAPPER.parse("")));
|
||||
html.append(Html.COLUMNS_DIV_WRAPPER.parse(Html.COLUMN_DIV_WRAPPER.parse(getContent(name, placeholders.get(name))) + Html.COLUMN_DIV_WRAPPER.parse("")));
|
||||
}
|
||||
String returnValue = html.toString();
|
||||
if (returnValue.isEmpty()) {
|
||||
@ -149,7 +158,7 @@ public class HtmlUtils {
|
||||
html.append("</div>");
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -30,8 +31,9 @@ public class ManageUtils {
|
||||
* @param dbName Name of database (mysql/sqlite)
|
||||
* @param copyFromDB Database you want to backup.
|
||||
* @return success?
|
||||
* @throws java.sql.SQLException
|
||||
*/
|
||||
public static boolean backup(String dbName, Database copyFromDB) {
|
||||
public static boolean backup(String dbName, Database copyFromDB) throws SQLException {
|
||||
Plan plugin = Plan.getInstance();
|
||||
Date now = new Date();
|
||||
SQLiteDB backupDB = new SQLiteDB(plugin,
|
||||
@ -68,13 +70,15 @@ public class ManageUtils {
|
||||
* @param copyFromDB Database where data will be copied from
|
||||
* @param fromDBsavedUUIDs UUID collection of saved uuids in the copyFromDB
|
||||
* @return success?
|
||||
* @throws java.sql.SQLException
|
||||
*/
|
||||
public static boolean clearAndCopy(Database clearAndCopyToDB, Database copyFromDB, Collection<UUID> fromDBsavedUUIDs) {
|
||||
public static boolean clearAndCopy(Database clearAndCopyToDB, Database copyFromDB, Collection<UUID> fromDBsavedUUIDs) throws SQLException {
|
||||
try {
|
||||
clearAndCopyToDB.removeAllData();
|
||||
List<UserData> allUserData = copyFromDB.getUserDataForUUIDS(copyFromDB.getSavedUUIDs());
|
||||
clearAndCopyToDB.saveMultipleUserData(allUserData);
|
||||
clearAndCopyToDB.getCommandUseTable().saveCommandUse(copyFromDB.getCommandUseTable().getCommandUse());
|
||||
clearAndCopyToDB.getTpsTable().saveTPSData(copyFromDB.getTpsTable().getTPSData());
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
Log.toLog("ManageUtils.move", e);
|
||||
return false;
|
||||
@ -82,6 +86,11 @@ public class ManageUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sessions
|
||||
* @return
|
||||
*/
|
||||
public static boolean containsCombinable(List<SessionData> sessions) {
|
||||
return containsCombinable(sessions, 5000);
|
||||
}
|
||||
@ -95,6 +104,12 @@ public class ManageUtils {
|
||||
.anyMatch((Long start) -> (Math.abs(s.getSessionEnd() - start) < threshold)));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sessions
|
||||
* @param loginTimes
|
||||
* @return
|
||||
*/
|
||||
public static List<SessionData> combineSessions(List<SessionData> sessions, Integer loginTimes) {
|
||||
return combineSessions(sessions, loginTimes, 5000);
|
||||
}
|
||||
@ -129,4 +144,19 @@ public class ManageUtils {
|
||||
return newSessions;
|
||||
}
|
||||
}
|
||||
|
||||
public static Database getDB(Plan plugin, String dbName) {
|
||||
Database database = null;
|
||||
for (Database sqldb : plugin.getDatabases()) {
|
||||
String dbConfigName = sqldb.getConfigName();
|
||||
if (Verify.equalsIgnoreCase(dbName, dbConfigName)) {
|
||||
database = sqldb;
|
||||
if (!database.init()) {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return database;
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,17 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import com.djrapitops.javaplugin.command.CommandUtils;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.utilities.player.Fetch;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Utility method class containing various static methods.
|
||||
*
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ -40,7 +32,7 @@ public class MiscUtils {
|
||||
* @param sender
|
||||
* @return
|
||||
*/
|
||||
public static String getPlayerName(String[] args, CommandSender sender) {
|
||||
public static String getPlayerName(String[] args, ISender sender) {
|
||||
return getPlayerName(args, sender, Permissions.INSPECT_OTHER);
|
||||
}
|
||||
|
||||
@ -52,13 +44,13 @@ public class MiscUtils {
|
||||
* @param perm
|
||||
* @return The name of the player (first argument or sender)
|
||||
*/
|
||||
public static String getPlayerName(String[] args, CommandSender sender, Permissions perm) {
|
||||
public static String getPlayerName(String[] args, ISender sender, Permissions perm) {
|
||||
String playerName = "";
|
||||
boolean isConsole = !(sender instanceof Player);
|
||||
boolean isConsole = !CommandUtils.isPlayer(sender);
|
||||
if (isConsole) {
|
||||
playerName = args[0];
|
||||
} else if (args.length > 0) {
|
||||
if (perm.userHasThisPermission(sender)) {
|
||||
if (sender.hasPermission(perm.getPermission())) {
|
||||
playerName = args[0];
|
||||
} else if (args[0].toLowerCase().equals(sender.getName().toLowerCase())) {
|
||||
playerName = sender.getName();
|
||||
@ -72,20 +64,18 @@ public class MiscUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get matching playernames from the offlineplayers
|
||||
* Get matching player names from the offline players.
|
||||
*
|
||||
* @param search Part of a name to search for.
|
||||
* @return Set of OfflinePlayers that match.
|
||||
* @return Alphabetically sorted list of matching player names.
|
||||
*/
|
||||
public static Set<OfflinePlayer> getMatchingDisplaynames(String search) {
|
||||
List<OfflinePlayer> players = new ArrayList<>();
|
||||
players.addAll(Arrays.asList(Bukkit.getOfflinePlayers()));
|
||||
Set<OfflinePlayer> matches = new HashSet<>();
|
||||
players.parallelStream()
|
||||
.filter(player -> (player.getName().toLowerCase().contains(search.toLowerCase())))
|
||||
.forEach(player -> {
|
||||
matches.add(player);
|
||||
});
|
||||
public static List<String> getMatchingPlayerNames(String search) {
|
||||
final String searchFor = search.toLowerCase();
|
||||
List<String> matches = Fetch.getIOfflinePlayers().stream()
|
||||
.map(p -> p.getName())
|
||||
.filter(name -> name.toLowerCase().contains(searchFor))
|
||||
.collect(Collectors.toList());
|
||||
Collections.sort(matches);
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import com.djrapitops.javaplugin.utilities.player.IOfflinePlayer;
|
||||
import com.djrapitops.javaplugin.utilities.player.IPlayer;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -19,8 +19,8 @@ public class NewPlayerCreator {
|
||||
* @param player Player the UserData is created for.
|
||||
* @return a new UserData object
|
||||
*/
|
||||
public static UserData createNewPlayer(Player player) {
|
||||
return createNewPlayer((OfflinePlayer) player, player.getGameMode());
|
||||
public static UserData createNewPlayer(IPlayer player) {
|
||||
return createNewPlayer((IOfflinePlayer) player, player.getGamemode());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -29,8 +29,8 @@ public class NewPlayerCreator {
|
||||
* @param player OfflinePlayer the UserData is created for.
|
||||
* @return a new UserData object
|
||||
*/
|
||||
public static UserData createNewPlayer(OfflinePlayer player) {
|
||||
return createNewPlayer(player, GameMode.SURVIVAL);
|
||||
public static UserData createNewOfflinePlayer(IOfflinePlayer player) {
|
||||
return createNewPlayer(player, Gamemode.SURVIVAL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,18 +40,19 @@ public class NewPlayerCreator {
|
||||
* @param gm Gamemode set as the starting Gamemode
|
||||
* @return a new UserData object
|
||||
*/
|
||||
public static UserData createNewPlayer(OfflinePlayer player, GameMode gm) {
|
||||
UserData data = new UserData(player, new DemographicsData());
|
||||
public static UserData createNewPlayer(IOfflinePlayer player, Gamemode gm) {
|
||||
long registered = player.getFirstPlayed();
|
||||
UserData data = new UserData(player.getUniqueId(), registered, null, player.isOp(), Gamemode.SURVIVAL, new DemographicsData(), player.getName(), player.isOnline());
|
||||
data.setLastGamemode(gm);
|
||||
data.setLastPlayed(MiscUtils.getTime());
|
||||
long zero = Long.parseLong("0");
|
||||
data.setPlayTime(zero);
|
||||
data.setPlayTime(0L);
|
||||
data.setTimesKicked(0);
|
||||
data.setLoginTimes(0);
|
||||
data.setLastGmSwapTime(zero);
|
||||
data.setLastGmSwapTime(0L);
|
||||
data.setDeaths(0);
|
||||
data.setMobKills(0);
|
||||
Log.debug(player.getUniqueId()+": Created a new UserData object.");
|
||||
data.setBanned(false);
|
||||
Log.debug(player.getUniqueId() + ": Created a new UserData object.");
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import com.djrapitops.javaplugin.utilities.player.Gamemode;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -18,7 +17,8 @@ import main.java.com.djrapitops.plan.ui.graphs.PunchCardGraphCreator;
|
||||
import main.java.com.djrapitops.plan.ui.graphs.SessionLengthDistributionGraphCreator;
|
||||
import main.java.com.djrapitops.plan.ui.tables.SortableKillsTableCreator;
|
||||
import main.java.com.djrapitops.plan.ui.tables.SortableSessionTableCreator;
|
||||
import org.bukkit.GameMode;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -35,7 +35,7 @@ public class PlaceholderUtils {
|
||||
public static Map<String, String> getAnalysisReplaceRules(AnalysisData data) {
|
||||
Benchmark.start("Replace Placeholders Anaysis");
|
||||
HashMap<String, String> replaceMap = new HashMap<>();
|
||||
replaceMap.put("%currenttime%", MiscUtils.getTime()+"");
|
||||
replaceMap.put("%currenttime%", MiscUtils.getTime() + "");
|
||||
replaceMap.put("%gm0%", (int) (data.getGm0Perc() * 100) + "%");
|
||||
replaceMap.put("%gm1%", (int) (data.getGm1Perc() * 100) + "%");
|
||||
replaceMap.put("%gm2%", (int) (data.getGm2Perc() * 100) + "%");
|
||||
@ -65,13 +65,13 @@ public class PlaceholderUtils {
|
||||
replaceMap.put("%version%", plugin.getDescription().getVersion());
|
||||
replaceMap.put("%planlite%", "");
|
||||
replaceMap.put("%sortabletable%", data.getSortablePlayersTable());
|
||||
replaceMap.put("%uniquejoinsday%", data.getUniqueJoinsDay()+"");
|
||||
replaceMap.put("%uniquejoinsweek%", data.getUniqueJoinsWeek()+"");
|
||||
replaceMap.put("%uniquejoinsmonth%", data.getUniqueJoinsMonth()+"");
|
||||
replaceMap.put("%avguniquejoins%", data.getAvgUniqJoins()+"");
|
||||
replaceMap.put("%avguniquejoinsday%", data.getAvgUniqJoinsDay()+"");
|
||||
replaceMap.put("%avguniquejoinsweek%", data.getAvgUniqJoinsWeek()+"");
|
||||
replaceMap.put("%avguniquejoinsmonth%", data.getAvgUniqJoinsMonth()+"");
|
||||
replaceMap.put("%uniquejoinsday%", data.getUniqueJoinsDay() + "");
|
||||
replaceMap.put("%uniquejoinsweek%", data.getUniqueJoinsWeek() + "");
|
||||
replaceMap.put("%uniquejoinsmonth%", data.getUniqueJoinsMonth() + "");
|
||||
replaceMap.put("%avguniquejoins%", data.getAvgUniqJoins() + "");
|
||||
replaceMap.put("%avguniquejoinsday%", data.getAvgUniqJoinsDay() + "");
|
||||
replaceMap.put("%avguniquejoinsweek%", data.getAvgUniqJoinsWeek() + "");
|
||||
replaceMap.put("%avguniquejoinsmonth%", data.getAvgUniqJoinsMonth() + "");
|
||||
replaceMap.put("%dataday%", data.getPlayersDataArray()[0]);
|
||||
replaceMap.put("%labelsday%", data.getPlayersDataArray()[1]);
|
||||
replaceMap.put("%dataweek%", data.getPlayersDataArray()[2]);
|
||||
@ -130,9 +130,14 @@ public class PlaceholderUtils {
|
||||
replaceMap.put("#" + defaultCols[i], "#" + colors[i]);
|
||||
}
|
||||
}
|
||||
replaceMap.put("%graphmaxplayers%", Settings.GRAPH_PLAYERS_USEMAXPLAYERS_SCALE.isTrue() ? plugin.getVariable().getMaxPlayers()+"" : "2");
|
||||
replaceMap.put("%refreshlong%", data.getRefreshDate()+"");
|
||||
replaceMap.put("%graphmaxplayers%", Settings.GRAPH_PLAYERS_USEMAXPLAYERS_SCALE.isTrue() ? plugin.getVariable().getMaxPlayers() + "" : "2");
|
||||
replaceMap.put("%refreshlong%", data.getRefreshDate() + "");
|
||||
replaceMap.put("%servername%", Settings.SERVER_NAME.toString());
|
||||
String[] tpsData = data.getTpsData();
|
||||
replaceMap.put("%tpsdatalabels%", tpsData[0]);
|
||||
replaceMap.put("%tpsdatatps%", tpsData[1]);
|
||||
replaceMap.put("%tpsdataplayersonline%", tpsData[2]);
|
||||
replaceMap.put("%averagetps%", FormatUtils.cutDecimals(data.getAverageTPS()) + "");
|
||||
Benchmark.stop("Replace Placeholders Anaysis");
|
||||
return replaceMap;
|
||||
}
|
||||
@ -146,7 +151,7 @@ public class PlaceholderUtils {
|
||||
*/
|
||||
public static Map<String, String> getInspectReplaceRules(UserData data) throws FileNotFoundException {
|
||||
Benchmark.start("Replace Placeholders Inspect");
|
||||
|
||||
|
||||
HashMap<String, String> replaceMap = new HashMap<>();
|
||||
boolean showIPandUUID = Settings.SECURITY_IP_UUID.isTrue();
|
||||
UUID uuid = data.getUuid();
|
||||
@ -160,10 +165,10 @@ public class PlaceholderUtils {
|
||||
int age = data.getDemData().getAge();
|
||||
replaceMap.put("%age%", (age != -1) ? "" + age : Phrase.DEM_UNKNOWN + "");
|
||||
replaceMap.put("%gender%", "" + data.getDemData().getGender().name().toLowerCase());
|
||||
Map<GameMode, Long> gmTimes = data.getGmTimes();
|
||||
Map<Gamemode, Long> gmTimes = data.getGmTimes();
|
||||
long gmThree;
|
||||
try {
|
||||
Long gm3 = gmTimes.get(GameMode.SPECTATOR);
|
||||
Long gm3 = gmTimes.get(Gamemode.SPECTATOR);
|
||||
if (gm3 == null) {
|
||||
gm3 = (long) 0;
|
||||
}
|
||||
@ -172,9 +177,9 @@ public class PlaceholderUtils {
|
||||
gmThree = 0;
|
||||
}
|
||||
long[] gmData = new long[]{
|
||||
(gmTimes.get(GameMode.SURVIVAL) != null ? gmTimes.get(GameMode.SURVIVAL) : 0L),
|
||||
(gmTimes.get(GameMode.CREATIVE) != null ? gmTimes.get(GameMode.CREATIVE) : 0L),
|
||||
(gmTimes.get(GameMode.ADVENTURE) != null ? gmTimes.get(GameMode.ADVENTURE) : 0L),
|
||||
(gmTimes.get(Gamemode.SURVIVAL) != null ? gmTimes.get(Gamemode.SURVIVAL) : 0L),
|
||||
(gmTimes.get(Gamemode.CREATIVE) != null ? gmTimes.get(Gamemode.CREATIVE) : 0L),
|
||||
(gmTimes.get(Gamemode.ADVENTURE) != null ? gmTimes.get(Gamemode.ADVENTURE) : 0L),
|
||||
gmThree
|
||||
};
|
||||
long total = gmData[0] + gmData[1] + gmData[2] + gmData[3];
|
||||
@ -207,7 +212,7 @@ public class PlaceholderUtils {
|
||||
replaceMap.put("%version%", plugin.getDescription().getVersion());
|
||||
replaceMap.put("%planlite%", "");
|
||||
String[] playersDataArray = PlayerActivityGraphCreator.generateDataArray(data.getSessions(), (long) 604800 * 1000);
|
||||
replaceMap.put("%graphmaxplayers%", 2+"");
|
||||
replaceMap.put("%graphmaxplayers%", 2 + "");
|
||||
replaceMap.put("%dataweek%", playersDataArray[0]);
|
||||
replaceMap.put("%labelsweek%", playersDataArray[1]);
|
||||
replaceMap.put("%playersgraphcolor%", Settings.HCOLOR_ACT_ONL + "");
|
||||
@ -228,8 +233,8 @@ public class PlaceholderUtils {
|
||||
replaceMap.put("#" + defaultCols[i], "#" + colors[i]);
|
||||
}
|
||||
}
|
||||
replaceMap.put("%refreshlong%", plugin.getInspectCache().getCacheTime(uuid)+"");
|
||||
replaceMap.put("%currenttime%", MiscUtils.getTime()+"");
|
||||
replaceMap.put("%refreshlong%", plugin.getInspectCache().getCacheTime(uuid) + "");
|
||||
replaceMap.put("%currenttime%", MiscUtils.getTime() + "");
|
||||
replaceMap.put("%servername%", Settings.SERVER_NAME.toString());
|
||||
String pluginsTabHtml = plugin.getHookHandler().getPluginsTabLayoutForInspect();
|
||||
Map<String, String> additionalReplaceRules = plugin.getHookHandler().getAdditionalInspectReplaceRules(uuid);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user