mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-04-24 18:40:34 +08:00
Code Cleaning
Cleaned code up to DBCallableProcessor (com.djrapitops.plan.cache)
This commit is contained in:
parent
8cf22de4b6
commit
4cbc00d87d
Plan
Class Diagram.xmlcheckstyle.xmlpom.xml
src
main/java/com/djrapitops/plan
Permissions.javaPlan.javaSettings.java
api
command
Condition.javaConditionUtils.javaPlanCommand.java
commands
data
AnalysisData.javaKillData.javaRawAnalysisData.javaSessionData.javaTPS.javaUserData.java
cache
handling
listeners
database
ui
utilities
test/java/main/java/com/djrapitops/plan
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"/>
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
<artifactId>BukkitPluginDependency</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.4.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- SoftDepended Plugins-->
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,12 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.javaplugin.api.ColorScheme;
|
||||
import com.djrapitops.javaplugin.RslPlugin;
|
||||
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.api.ColorScheme;
|
||||
import com.djrapitops.javaplugin.api.TimeAmount;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslTask;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
@ -38,16 +39,14 @@ import main.java.com.djrapitops.plan.api.API;
|
||||
import main.java.com.djrapitops.plan.command.PlanCommand;
|
||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
import main.java.com.djrapitops.plan.data.cache.*;
|
||||
import main.java.com.djrapitops.plan.data.listeners.TPSCountTimer;
|
||||
import main.java.com.djrapitops.plan.data.listeners.*;
|
||||
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.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
/**
|
||||
* Javaplugin class that contains methods for starting the plugin, logging to
|
||||
@ -59,16 +58,19 @@ import org.bukkit.plugin.PluginManager;
|
||||
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.
|
||||
@ -81,66 +83,83 @@ 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();
|
||||
|
||||
initLocale();
|
||||
serverVariableHolder = new ServerVariableHolder(getServer());
|
||||
|
||||
Server server = getServer();
|
||||
variable = new ServerVariableHolder(server);
|
||||
|
||||
databases = new HashSet<>();
|
||||
databases.add(new MySQLDB(this));
|
||||
databases.add(new SQLiteDB(this));
|
||||
|
||||
// Copy config
|
||||
getConfig().options().copyDefaults(true);
|
||||
getConfig().options().header(Phrase.CONFIG_HEADER + "");
|
||||
saveConfig();
|
||||
|
||||
// Initialize 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;
|
||||
}
|
||||
|
||||
// Initialize DataCache
|
||||
this.handler = new DataCacheHandler(this);
|
||||
|
||||
this.inspectCache = new InspectCacheHandler(this);
|
||||
|
||||
this.analysisCache = new AnalysisCacheHandler(this);
|
||||
|
||||
// TPS Count Task
|
||||
super.getRunnableFactory().createNew(new TPSCountTimer(this)).runTaskTimer(1000, TimeAmount.SECOND.ticks());
|
||||
|
||||
registerListeners();
|
||||
getRunnableFactory().createNew(new TPSCountTimer(this)).runTaskTimer(1000, 20);
|
||||
|
||||
registerCommand(new PlanCommand(this));
|
||||
|
||||
this.api = new API(this);
|
||||
|
||||
handler.handleReload();
|
||||
|
||||
bootAnalysisTaskID = -1;
|
||||
if (Settings.WEBSERVER_ENABLED.isTrue()) {
|
||||
// Analysis refresh settings
|
||||
boolean bootAnalysisIsEnabled = Settings.ANALYSIS_REFRESH_ON_ENABLE.isTrue();
|
||||
int analysisRefreshMinutes = Settings.ANALYSIS_AUTO_REFRESH.getNumber();
|
||||
boolean analysisRefreshTaskIsEnabled = analysisRefreshMinutes > 0;
|
||||
|
||||
// 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;
|
||||
|
||||
// Analysis refresh tasks
|
||||
if (bootAnalysisIsEnabled) {
|
||||
startBootAnalysisTask();
|
||||
}
|
||||
if (analysisRefreshTaskIsEnabled) {
|
||||
startAnalysisRefreshTask(analysisRefreshMinutes);
|
||||
}
|
||||
|
||||
// Webserver
|
||||
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 + "");
|
||||
}
|
||||
|
||||
// Hook plugins
|
||||
hookHandler = new HookHandler(this);
|
||||
|
||||
Log.debug("Verboose debug messages are enabled.");
|
||||
@ -154,46 +173,45 @@ 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)) {
|
||||
|
||||
// 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();
|
||||
});
|
||||
scheduler.shutdown();
|
||||
}
|
||||
scheduler.shutdown(); // Schedules the save to shutdown after it has ran the execute method.
|
||||
|
||||
}
|
||||
Log.info(Phrase.DISABLED + "");
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
final PluginManager pluginManager = getServer().getPluginManager();
|
||||
|
||||
pluginManager.registerEvents(new PlanPlayerListener(this), this);
|
||||
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 + "");
|
||||
|
||||
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));
|
||||
@ -208,43 +226,44 @@ 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 {
|
||||
RslTask task = getRunnableFactory().createNew("PeriodicalAnalysisTask", new RslRunnable() {
|
||||
private void startAnalysisRefreshTask(int everyXMinutes) throws IllegalStateException {
|
||||
if (!Verify.positive(everyXMinutes)) {
|
||||
return;
|
||||
}
|
||||
getRunnableFactory().createNew("PeriodicalAnalysisTask", new RslRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
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(analysisRefreshMinutes * 60 * 20, analysisRefreshMinutes * 60 * 20);
|
||||
}).runTaskTimerAsynchronously(everyXMinutes * TimeAmount.MINUTE.ticks(), everyXMinutes * TimeAmount.MINUTE.ticks());
|
||||
}
|
||||
|
||||
private void startBootAnalysisTask() throws IllegalStateException, IllegalArgumentException {
|
||||
private void startBootAnalysisTask() throws IllegalStateException {
|
||||
Log.info(Phrase.ANALYSIS_BOOT_NOTIFY + "");
|
||||
RslTask bootAnalysisTask = getRunnableFactory().createNew("BootAnalysisTask", new RslRunnable() {
|
||||
@Override
|
||||
@ -253,10 +272,66 @@ public class Plan extends RslPlugin<Plan> {
|
||||
analysisCache.updateCache();
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskLaterAsynchronously(30 * 20);
|
||||
}).runTaskLaterAsynchronously(30 * TimeAmount.SECOND.ticks());
|
||||
bootAnalysisTaskID = bootAnalysisTask.getTaskId();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to access AnalysisCache.
|
||||
*
|
||||
@ -331,73 +406,6 @@ public class Plan extends RslPlugin<Plan> {
|
||||
return bootAnalysisTaskID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old method for getting the API.
|
||||
*
|
||||
* @deprecated Use Plan.getAPI() (static method) instead.
|
||||
* @return the Plan API.
|
||||
*/
|
||||
@Deprecated
|
||||
public API getAPI() {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the object storing server variables that are constant after
|
||||
* boot.
|
||||
@ -406,7 +414,18 @@ public class Plan extends RslPlugin<Plan> {
|
||||
* @see ServerVariableHolder
|
||||
*/
|
||||
public ServerVariableHolder getVariable() {
|
||||
return variable;
|
||||
return serverVariableHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old method for getting the API.
|
||||
*
|
||||
* @deprecated Use Plan.getPlanAPI() (static method) instead.
|
||||
* @return the Plan API.
|
||||
*/
|
||||
@Deprecated
|
||||
public API getAPI() {
|
||||
return api;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -84,10 +85,10 @@ public enum Settings {
|
||||
// StringList
|
||||
HIDE_FACTIONS("Customization.Plugins.Factions.HideFactions"),
|
||||
HIDE_TOWNS("Customization.Plugins.Towny.HideTowns");
|
||||
|
||||
|
||||
private final String configPath;
|
||||
private Boolean value;
|
||||
|
||||
|
||||
private Settings(String path) {
|
||||
this.configPath = path;
|
||||
}
|
||||
@ -98,12 +99,12 @@ public enum Settings {
|
||||
* @return Boolean value of the config setting, false if not boolean.
|
||||
*/
|
||||
public boolean isTrue() {
|
||||
if (value != null) {
|
||||
if (Verify.notNull(value)) {
|
||||
return value;
|
||||
}
|
||||
return Plan.getInstance().getConfig().getBoolean(configPath);
|
||||
}
|
||||
|
||||
|
||||
public void setValue(Boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
@ -126,7 +127,7 @@ public enum Settings {
|
||||
public int getNumber() {
|
||||
return Plan.getInstance().getConfig().getInt(configPath);
|
||||
}
|
||||
|
||||
|
||||
public List<String> getStringList() {
|
||||
return Plan.getInstance().getConfig().getStringList(configPath);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.api;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.UUIDFetcher;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -36,7 +37,7 @@ import org.bukkit.OfflinePlayer;
|
||||
*/
|
||||
public class API {
|
||||
|
||||
private Plan plugin;
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Construcor.
|
||||
@ -168,7 +169,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);
|
||||
@ -203,7 +204,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);
|
||||
@ -299,7 +300,8 @@ public class API {
|
||||
* 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.
|
||||
* @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() {
|
||||
|
@ -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,44 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
/**
|
||||
* Container class for boolean and a string.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.4.3
|
||||
* @deprecated Stupid idea.
|
||||
*/
|
||||
@Deprecated
|
||||
public class Condition {
|
||||
|
||||
final private String failMsg;
|
||||
final private boolean pass;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param pass Did the condition pass?
|
||||
* @param failMsg Message to send if the condition failed.
|
||||
*/
|
||||
@Deprecated
|
||||
public Condition(boolean pass, String failMsg) {
|
||||
this.failMsg = failMsg;
|
||||
this.pass = pass;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public String getFailMsg() {
|
||||
return failMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean pass() {
|
||||
return pass;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
@ -42,16 +43,6 @@ public class ConditionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if uuid is not null.
|
||||
*
|
||||
* @param uuid UUID
|
||||
* @return is the uuid null?
|
||||
*/
|
||||
public static boolean uuidIsValid(UUID uuid) {
|
||||
return uuid != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has played.
|
||||
*
|
||||
@ -59,7 +50,7 @@ public class ConditionUtils {
|
||||
* @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);
|
||||
|
@ -1,21 +1,9 @@
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.StatusCommand;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.TreeCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
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.AnalyzeCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.InfoCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.InspectCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.ManageCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.QuickAnalyzeCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.QuickInspectCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.ReloadCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.SearchCommand;
|
||||
import org.bukkit.command.Command;
|
||||
import main.java.com.djrapitops.plan.command.commands.*;
|
||||
|
||||
/**
|
||||
* CommandExecutor for the /plan command, and all subcommands.
|
||||
@ -33,15 +21,8 @@ public class PlanCommand extends TreeCommand<Plan> {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public PlanCommand(Plan plugin) {
|
||||
super(plugin, new SubCommand("plan", CommandType.CONSOLE, "") {
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
return true;
|
||||
}
|
||||
}, "plan");
|
||||
super(plugin, "plan", CommandType.CONSOLE, "", "", "plan");
|
||||
super.setDefaultCommand("inspect");
|
||||
// commands.add(new HelpCommand(plugin, this));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
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;
|
||||
@ -13,9 +14,11 @@ import main.java.com.djrapitops.plan.Settings;
|
||||
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.CommandException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
@ -42,26 +45,33 @@ public class AnalyzeCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!ConditionUtils.pluginHasViewCapability()) {
|
||||
sender.sendMessage(Phrase.ERROR_WEBSERVER_OFF_ANALYSIS + "");
|
||||
if (!Check.ifTrue(ConditionUtils.pluginHasViewCapability(), Phrase.ERROR_WEBSERVER_OFF_ANALYSIS + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
if (!analysisCache.isAnalysisEnabled()) {
|
||||
sender.sendMessage(Phrase.ERROR_ANALYSIS_DISABLED_TEMPORARILY + "");
|
||||
if (!Check.ifTrue(analysisCache.isAnalysisEnabled(), Phrase.ERROR_ANALYSIS_DISABLED_TEMPORARILY + "", sender)) {
|
||||
if (!analysisCache.isCached()) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
}
|
||||
if (!analysisCache.isCached() || MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
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 RslTask task = plugin.getRunnableFactory().createNew("AnalysisMessageSenderTask", new RslRunnable() {
|
||||
}
|
||||
|
||||
private void runMessageSenderTask(ISender sender) {
|
||||
plugin.getRunnableFactory().createNew("AnalysisMessageSenderTask", new RslRunnable() {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
@ -78,8 +88,7 @@ public class AnalyzeCommand extends SubCommand {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskTimer(1 * 20, 5 * 20);
|
||||
return true;
|
||||
}).runTaskTimer(TimeAmount.SECOND.ticks(), 5 * TimeAmount.SECOND.ticks());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +98,7 @@ public class AnalyzeCommand extends SubCommand {
|
||||
*
|
||||
* @param sender Command sender.
|
||||
*/
|
||||
final public void sendAnalysisMessage(ISender sender) {
|
||||
private void sendAnalysisMessage(ISender sender) {
|
||||
boolean textUI = Settings.USE_ALTERNATIVE_UI.isTrue();
|
||||
sender.sendMessage(Phrase.CMD_ANALYZE_HEADER + "");
|
||||
if (textUI) {
|
||||
@ -103,13 +112,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 + "\"}}]");
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ 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.
|
||||
@ -35,7 +33,6 @@ public class InfoCommand extends SubCommand {
|
||||
@Override
|
||||
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,25 +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 com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslTask;
|
||||
import main.java.com.djrapitops.plan.command.ConditionUtils;
|
||||
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.entity.Player;
|
||||
import org.bukkit.command.CommandException;
|
||||
|
||||
/**
|
||||
* This command is used to cache UserData to InspectCache and display the link.
|
||||
@ -46,75 +47,93 @@ public class InspectCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!ConditionUtils.pluginHasViewCapability()) {
|
||||
sender.sendMessage(Phrase.ERROR_WEBSERVER_OFF_INSPECT + "");
|
||||
if (!Check.ifTrue(ConditionUtils.pluginHasViewCapability(), Phrase.ERROR_WEBSERVER_OFF_INSPECT + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String playerName = MiscUtils.getPlayerName(args, sender);
|
||||
final RslTask inspectTask = plugin.getRunnableFactory().createNew(new RslRunnable("InspectTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = ConditionUtils.getUUID(playerName);
|
||||
Condition[] preConditions = new Condition[]{
|
||||
new Condition(ConditionUtils.uuidIsValid(uuid), Phrase.USERNAME_NOT_VALID.toString()),
|
||||
new Condition(ConditionUtils.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 RslTask inspectMessageSenderTask = 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(1 * 20, 5 * 20);
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
runInspectTask(playerName, sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
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,15 +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 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 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.
|
||||
@ -27,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(ISender sender, 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,17 +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.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslTask;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -39,25 +41,32 @@ public class QuickAnalyzeCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!analysisCache.isAnalysisEnabled()) {
|
||||
sender.sendMessage(Phrase.ERROR_ANALYSIS_DISABLED_TEMPORARILY + "");
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
}
|
||||
if (!analysisCache.isCached()) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
RslTask analysisMessageSenderTask = plugin.getRunnableFactory().createNew(new RslRunnable("QanalysisMessageSenderTask") {
|
||||
private void runMessageSenderTask(ISender sender) {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("QanalysisMessageSenderTask") {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
@ -75,7 +84,6 @@ public class QuickAnalyzeCommand extends SubCommand {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskTimer(1 * 20, 5 * 20);
|
||||
return true;
|
||||
}).runTaskTimer(TimeAmount.SECOND.ticks(), 5 * TimeAmount.SECOND.ticks());
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +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.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslTask;
|
||||
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.ConditionUtils;
|
||||
import main.java.com.djrapitops.plan.command.Condition;
|
||||
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;
|
||||
|
||||
/**
|
||||
* This command is used to cache UserData to InspectCache and to view some of
|
||||
@ -46,47 +44,50 @@ public class QuickInspectCommand extends SubCommand {
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.QUICK_INSPECT_OTHER);
|
||||
final RslTask inspectTask = plugin.getRunnableFactory().createNew(new RslRunnable("QinspectTask") {
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("QinspectTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = ConditionUtils.getUUID(playerName);
|
||||
Condition[] preConditions = new Condition[]{
|
||||
new Condition(ConditionUtils.uuidIsValid(uuid), Phrase.USERNAME_NOT_VALID.toString()),
|
||||
new Condition(ConditionUtils.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 RslTask inspectMessageSenderTask = 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();
|
||||
}
|
||||
if (!Check.ifTrue(ConditionUtils.playerHasPlayed(uuid), Phrase.USERNAME_NOT_SEEN.toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
}).runTaskTimer(1 * 20, 5 * 20);
|
||||
this.cancel();
|
||||
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();
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,6 @@ 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.
|
||||
|
@ -3,9 +3,7 @@ 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.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslTask;
|
||||
import com.djrapitops.javaplugin.utilities.FormattingUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -15,8 +13,7 @@ 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 main.java.com.djrapitops.plan.command.Condition;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
@ -29,7 +26,6 @@ import org.bukkit.OfflinePlayer;
|
||||
public class SearchCommand extends SubCommand {
|
||||
|
||||
private final Plan plugin;
|
||||
private final InspectCacheHandler inspectCache;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -39,18 +35,21 @@ 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(ISender sender, String commandLabel, String[] args) {
|
||||
Condition c = new Condition(args.length != 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString());
|
||||
if (c.pass()) {
|
||||
sender.sendMessage(c.getFailMsg());
|
||||
if (!Check.ifTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString(), sender)) {
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(Phrase.CMD_SEARCH_SEARCHING + "");
|
||||
final RslTask searchTask =plugin.getRunnableFactory().createNew(new RslRunnable("SearchTask: " + Arrays.toString(args)) {
|
||||
|
||||
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 {
|
||||
@ -70,6 +69,5 @@ public class SearchCommand extends SubCommand {
|
||||
}
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,14 @@ 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.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.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;
|
||||
|
||||
/**
|
||||
@ -20,7 +21,7 @@ import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
*/
|
||||
public class ManageBackupCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -36,46 +37,48 @@ public class ManageBackupCommand extends SubCommand {
|
||||
@Override
|
||||
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;
|
||||
plugin.getRunnableFactory().createNew(new RslRunnable("BackupTask") {
|
||||
@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();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,15 @@ 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.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.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 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.
|
||||
@ -36,39 +36,37 @@ public class ManageCleanCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "");
|
||||
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;
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,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.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.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 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.
|
||||
@ -36,40 +37,41 @@ public class ManageClearCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, 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])));
|
||||
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;
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,14 @@ 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 java.sql.SQLException;
|
||||
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
|
||||
@ -36,30 +36,37 @@ public class ManageHotswapCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "");
|
||||
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();
|
||||
|
@ -4,7 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslTask;
|
||||
import com.djrapitops.javaplugin.utilities.FormattingUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -15,6 +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 main.java.com.djrapitops.plan.utilities.Check;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayers;
|
||||
|
||||
/**
|
||||
@ -41,55 +42,56 @@ public class ManageImportCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
|
||||
if (args.length < 1) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString() + " " + Phrase.USE_IMPORT);
|
||||
if (!Check.ifTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + " " + Phrase.USE_IMPORT, sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String importFromPlugin = args[0].toLowerCase();
|
||||
if (importFromPlugin.equals("list")) {
|
||||
list(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
String[] arguments = new String[args.length - 1];
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
arguments[i - 1] = args[i];
|
||||
}
|
||||
String[] importArguments = FormattingUtils.removeFirstArgument(args);
|
||||
|
||||
final Importer importer = importPlugins.get(importFromPlugin);
|
||||
RslTask asyncImportTask = plugin.getRunnableFactory().createNew(new RslRunnable("ImportTask") {
|
||||
@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, arguments)) {
|
||||
sender.sendMessage(Phrase.MANAGE_SUCCESS + "");
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
runImportTask(sender, importer, importArguments);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void list(ISender sender) {
|
||||
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 = Arrays.stream(getOfflinePlayers()).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());
|
||||
Map<String, Importer> importers = ImportUtils.getImporters();
|
||||
for (String key : importers.keySet()) {
|
||||
sender.sendMessage(Phrase.CMD_BALL + " " + key + ": " + importers.get(key).getInfo());
|
||||
}
|
||||
importers.entrySet().stream().forEach(e -> {
|
||||
sender.sendMessage(Phrase.CMD_BALL + " " + e.getKey() + ": " + e.getValue().getInfo());
|
||||
});
|
||||
sender.sendMessage(Phrase.CMD_FOOTER.parse());
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,8 @@ 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.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import java.util.Arrays;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
@ -13,6 +12,7 @@ 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;
|
||||
|
||||
/**
|
||||
@ -25,7 +25,7 @@ import main.java.com.djrapitops.plan.utilities.ManageUtils;
|
||||
*/
|
||||
public class ManageMoveCommand extends SubCommand {
|
||||
|
||||
private Plan plugin;
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -40,76 +40,73 @@ public class ManageMoveCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, 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])));
|
||||
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;
|
||||
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() {
|
||||
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 + "");
|
||||
try {
|
||||
final Collection<UUID> uuids = ManageUtils.getUUIDS(fromDatabase);
|
||||
if (Check.ifTrue(Verify.isEmpty(uuids), Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + fromDatabase.getName() + ")", sender)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
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();
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType;
|
||||
import com.djrapitops.javaplugin.command.SubCommand;
|
||||
import com.djrapitops.javaplugin.command.sender.ISender;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
@ -11,6 +12,7 @@ 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;
|
||||
|
||||
@ -37,53 +39,51 @@ public class ManageRemoveCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString());
|
||||
if (!Check.ifTrue(args.length >= 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE + "", sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.MANAGE);
|
||||
|
||||
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() {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
throw new Exception("Username doesn't exist.");
|
||||
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;
|
||||
}
|
||||
} 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_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 + "");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
sender.sendMessage(Phrase.MANAGE_PROCESS_FAIL + "");
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,9 @@ 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.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslTask;
|
||||
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;
|
||||
@ -16,6 +14,7 @@ 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;
|
||||
|
||||
/**
|
||||
@ -41,77 +40,71 @@ public class ManageRestoreCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(ISender sender, 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;
|
||||
RslTask asyncRestoreTask = plugin.getRunnableFactory().createNew(new RslRunnable("RestoreTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
String backupDBName = args[0];
|
||||
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();
|
||||
} catch (NullPointerException e) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,6 @@ 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.
|
||||
|
@ -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.
|
||||
|
@ -104,6 +104,5 @@ public class KillData {
|
||||
hash = 89 * hash + Objects.hashCode(this.weapon);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ public class RawAnalysisData {
|
||||
public Map<UUID, List<SessionData>> getSortedSessionData() {
|
||||
return sortedSessionData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uuid
|
||||
|
@ -34,12 +34,14 @@ public class SessionData {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -92,6 +92,6 @@ public class TPS {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TPS{" + date + "|" + tps + "|" + players+'}';
|
||||
return "TPS{" + date + "|" + tps + "|" + players + '}';
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.data;
|
||||
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -222,7 +223,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);
|
||||
}
|
||||
}
|
||||
@ -236,7 +237,7 @@ 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()));
|
||||
|
||||
}
|
||||
|
||||
@ -248,7 +249,7 @@ public class UserData {
|
||||
* @param loc Location of the player.
|
||||
*/
|
||||
public void addLocation(Location loc) {
|
||||
if (loc != null) {
|
||||
if (Verify.notNull(loc)) {
|
||||
locations.add(loc);
|
||||
location = loc;
|
||||
}
|
||||
@ -280,7 +281,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) {
|
||||
@ -299,7 +300,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()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,10 +310,10 @@ public class UserData {
|
||||
* @param time Milliseconds spent in the gamemode.
|
||||
*/
|
||||
public void setGMTime(GameMode gm, long time) {
|
||||
if (gmTimes == null) {
|
||||
if (!Verify.notNull(gmTimes)) {
|
||||
gmTimes = new HashMap<>();
|
||||
}
|
||||
if (gm != null) {
|
||||
if (Verify.notNull(time)) {
|
||||
gmTimes.put(gm, time);
|
||||
}
|
||||
}
|
||||
@ -344,7 +345,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);
|
||||
}
|
||||
}
|
||||
@ -358,7 +359,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()) {
|
||||
@ -621,7 +622,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;
|
||||
}
|
||||
}
|
||||
@ -632,7 +633,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;
|
||||
}
|
||||
}
|
||||
@ -643,7 +644,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;
|
||||
}
|
||||
}
|
||||
@ -707,7 +708,7 @@ public class UserData {
|
||||
* (After 1.8) keys.
|
||||
*/
|
||||
public void setGmTimes(Map<GameMode, Long> gmTimes) {
|
||||
if (gmTimes != null) {
|
||||
if (Verify.notNull(gmTimes)) {
|
||||
this.gmTimes = gmTimes;
|
||||
}
|
||||
}
|
||||
@ -799,7 +800,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;
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class AnalysisCacheHandler {
|
||||
public boolean isCached() {
|
||||
return (cache != null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
@ -72,16 +72,16 @@ public class AnalysisCacheHandler {
|
||||
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,8 @@
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
|
||||
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslTask;
|
||||
import com.djrapitops.javaplugin.utilities.Verify;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -11,17 +11,12 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
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;
|
||||
@ -32,16 +27,8 @@ 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 static org.bukkit.Bukkit.getPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
* This Class contains the Cache.
|
||||
@ -434,7 +421,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
*/
|
||||
public void clearFromCache(UUID uuid) {
|
||||
Log.debug(uuid + ": Clear");
|
||||
if (getOfflinePlayer(uuid).isOnline()) {
|
||||
if (Verify.notNull(getPlayer(uuid))) {
|
||||
Log.debug(uuid + ": Online, did not clear");
|
||||
UserData data = dataCache.get(uuid);
|
||||
if (data != null) {
|
||||
@ -483,15 +470,6 @@ public class DataCacheHandler extends LocationCache {
|
||||
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) {
|
||||
newPlayer(NewPlayerCreator.createNewPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a new player's data to be saved to the Database.
|
||||
*
|
||||
|
@ -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() {
|
||||
|
@ -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.
|
||||
@ -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));
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -9,7 +9,7 @@ import main.java.com.djrapitops.plan.Plan;
|
||||
* @param <T> Object this queue consumes.
|
||||
*/
|
||||
public abstract class Setup<T> {
|
||||
|
||||
|
||||
private final Consumer<T>[] consumers;
|
||||
|
||||
/**
|
||||
@ -20,13 +20,13 @@ public abstract class Setup<T> {
|
||||
public Setup(Consumer<T>... consumers) {
|
||||
this.consumers = consumers;
|
||||
}
|
||||
|
||||
|
||||
void go() {
|
||||
for (Consumer<T> consumer : consumers) {
|
||||
Plan.getInstance().getRunnableFactory().createNew(consumer).runTaskAsynchronously();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void stop() {
|
||||
for (Consumer<T> consumer : consumers) {
|
||||
consumer.stop();
|
||||
|
@ -34,14 +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;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ 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;
|
||||
|
@ -16,37 +16,30 @@ public enum InfoType {
|
||||
*
|
||||
*/
|
||||
CHAT,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
DEATH,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
KILL,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
GM,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
LOGIN,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
LOGOUT,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
KICK,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -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,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslTask;
|
||||
import java.util.UUID;
|
||||
|
@ -49,7 +49,7 @@ public class TPSCountTimer extends RslRunnable {
|
||||
|
||||
public TPS calculateTPS(long diff, long now) {
|
||||
if (diff < TimeAmount.SECOND.ns()) { // No tick count above 20
|
||||
diff = TimeAmount.SECOND.ns();
|
||||
diff = TimeAmount.SECOND.ns();
|
||||
}
|
||||
int playersOnline = plugin.getServer().getOnlinePlayers().size();
|
||||
long twentySeconds = 20L * TimeAmount.SECOND.ns();
|
||||
|
@ -26,8 +26,8 @@ public class DBUtils {
|
||||
* BATCH_SIZE.
|
||||
*
|
||||
* @param <T> Object type
|
||||
* @param objects Collection of the objects.
|
||||
// * @return Lists with max size of BATCH_SIZE.
|
||||
* @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<>();
|
||||
|
@ -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,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.database.databases;
|
||||
|
||||
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import java.net.InetAddress;
|
||||
import java.sql.Connection;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -112,14 +112,14 @@ public class GMTimesTable extends Table {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
Map<GameMode, Long> gmTimes = new HashMap<>();
|
||||
int id = set.getInt(columnUserID);
|
||||
@ -132,7 +132,7 @@ public class GMTimesTable extends Table {
|
||||
try {
|
||||
gmTimes.put(GameMode.SPECTATOR, set.getLong(columnSpectatorTime));
|
||||
} catch (NoSuchFieldError e) {
|
||||
}
|
||||
}
|
||||
times.put(id, gmTimes);
|
||||
}
|
||||
return times;
|
||||
@ -245,7 +245,7 @@ public class GMTimesTable extends Table {
|
||||
}
|
||||
gamemodeTimes.keySet().removeAll(savedIDs);
|
||||
} finally {
|
||||
close(statement);
|
||||
close(statement);
|
||||
}
|
||||
addNewGMTimesRows(gamemodeTimes);
|
||||
Benchmark.stop("Save GMTimes");
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,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 {
|
||||
@ -229,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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,8 +55,7 @@ public class TPSTable extends Table {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws SQLException
|
||||
* @return @throws SQLException
|
||||
*/
|
||||
public List<TPS> getTPSData() throws SQLException {
|
||||
Benchmark.start("Get TPS");
|
||||
@ -79,7 +78,7 @@ public class TPSTable extends Table {
|
||||
Benchmark.stop("Get TPS");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
@ -91,7 +90,7 @@ public class TPSTable extends Table {
|
||||
saveTPSBatch(batch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void saveTPSBatch(List<TPS> batch) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
@ -119,7 +118,7 @@ public class TPSTable extends Table {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws SQLException
|
||||
@ -129,8 +128,8 @@ public class TPSTable extends Table {
|
||||
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);
|
||||
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,7 +125,7 @@ public abstract class Table {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <T>
|
||||
|
@ -21,8 +21,8 @@ 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;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -31,7 +31,7 @@ public class SessionLengthDistributionGraphCreator {
|
||||
List<Long> lengths = AnalysisUtils.transformSessionDataToLengths(data);
|
||||
return generateDataArray(lengths);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param lengths
|
||||
|
@ -15,11 +15,12 @@ import main.java.com.djrapitops.plan.utilities.comparators.TPSComparator;
|
||||
* @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());
|
||||
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());
|
||||
|
@ -5,11 +5,11 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -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,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.ui.webserver;
|
||||
|
||||
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@ -77,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) {
|
||||
@ -86,7 +85,7 @@ public class WebSocketServer {
|
||||
closeable.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import main.java.com.djrapitops.plan.Plan;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class Benchmark {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
@ -17,7 +17,7 @@ public class Benchmark {
|
||||
Plan.getInstance().benchmark().start(source);
|
||||
Log.debug(source);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
@ -26,7 +26,7 @@ public class Benchmark {
|
||||
public static long stop(String 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;
|
||||
}
|
||||
}
|
@ -54,9 +54,9 @@ public class HtmlUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String getServerAnalysisUrlWithProtocol() {
|
||||
return Settings.LINK_PROTOCOL.toString()+":"+getServerAnalysisUrl();
|
||||
return Settings.LINK_PROTOCOL.toString() + ":" + getServerAnalysisUrl();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
@ -69,7 +69,7 @@ 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;
|
||||
}
|
||||
|
||||
@ -79,9 +79,9 @@ public class HtmlUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String getInspectUrlWithProtocol(String playerName) {
|
||||
return Settings.LINK_PROTOCOL.toString()+":"+getInspectUrl(playerName);
|
||||
return Settings.LINK_PROTOCOL.toString() + ":" + getInspectUrl(playerName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param playerName
|
||||
@ -95,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;
|
||||
}
|
||||
|
||||
@ -133,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()) {
|
||||
@ -158,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,8 +70,9 @@ 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());
|
||||
@ -141,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;
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,10 @@ import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
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
|
||||
*/
|
||||
|
@ -55,5 +55,5 @@ public class NewPlayerCreator {
|
||||
Log.debug(player.getUniqueId() + ": Created a new UserData object.");
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
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 java.io.FileNotFoundException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -18,6 +16,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 main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
/**
|
||||
|
@ -1,11 +1,9 @@
|
||||
package main.java.com.djrapitops.plan.utilities.analysis;
|
||||
|
||||
import com.djrapitops.javaplugin.api.TimeAmount;
|
||||
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslRunnable;
|
||||
import com.djrapitops.javaplugin.task.RslTask;
|
||||
import java.util.ArrayList;
|
||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -24,6 +22,7 @@ import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
@ -115,7 +114,7 @@ public class Analysis {
|
||||
List<TPS> tpsData = new ArrayList<>();
|
||||
try {
|
||||
tpsData = db.getTpsTable().getTPSData();
|
||||
Log.debug("TPS Data Size: "+tpsData.size());
|
||||
Log.debug("TPS Data Size: " + tpsData.size());
|
||||
} catch (Exception ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
}
|
||||
@ -153,7 +152,7 @@ public class Analysis {
|
||||
log(Phrase.ANALYSIS_BEGIN_ANALYSIS.parse(rawData.size() + "", Benchmark.stop("Analysis Fetch Phase") + ""));
|
||||
String playersTable = SortablePlayersTableCreator.createSortablePlayersTable(rawData);
|
||||
analysisData.setSortablePlayersTable(playersTable);
|
||||
|
||||
|
||||
analysisData.setTpsData(TPSGraphCreator.generateDataArray(tpsData, now));
|
||||
analysisData.setAverageTPS(MathUtils.averageDouble(tpsData.stream().map(t -> t.getTps())));
|
||||
|
||||
@ -452,7 +451,7 @@ public class Analysis {
|
||||
public boolean isAnalysisBeingRun() {
|
||||
return taskId != -1;
|
||||
}
|
||||
|
||||
|
||||
public void setTaskId(int id) {
|
||||
if (id == -2) {
|
||||
plugin.processStatus().setStatus("Analysis", "Temporarily Disabled");
|
||||
@ -460,5 +459,5 @@ public class Analysis {
|
||||
plugin.processStatus().setStatus("Analysis", "Enabled");
|
||||
}
|
||||
taskId = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,7 @@ public class ExportUtility {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @return @throws IOException
|
||||
*/
|
||||
public static File getFolder() throws IOException {
|
||||
String path = Settings.ANALYSIS_EXPORT_PATH.toString();
|
||||
|
@ -18,5 +18,5 @@ public class HandlingInfoTimeComparator implements Comparator<HandlingInfo> {
|
||||
public int compare(HandlingInfo o1, HandlingInfo o2) {
|
||||
return ((Long) o1.getTime()).compareTo((Long) o2.getTime());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,11 +8,11 @@ import main.java.com.djrapitops.plan.data.TPS;
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class TPSComparator implements Comparator<TPS>{
|
||||
public class TPSComparator implements Comparator<TPS> {
|
||||
|
||||
@Override
|
||||
public int compare(TPS o1, TPS o2) {
|
||||
return Long.compare(o1.getDate(), o2.getDate());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import main.java.com.djrapitops.plan.data.UserData;
|
||||
* @author Risto
|
||||
*/
|
||||
public class UserDataLastPlayedComparator implements Comparator<UserData> {
|
||||
|
||||
@Override
|
||||
public int compare(UserData u1, UserData u2) {
|
||||
return Long.compare(u2.getLastPlayed(), u1.getLastPlayed());
|
||||
|
@ -22,10 +22,13 @@ public class UUIDUtility {
|
||||
*
|
||||
* @param playername
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static UUID getUUIDOf(String playername) throws Exception {
|
||||
return getUUIDOf(playername, Plan.getInstance().getDB());
|
||||
public static UUID getUUIDOf(String playername) {
|
||||
try {
|
||||
return getUUIDOf(playername, Plan.getInstance().getDB());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,15 +38,18 @@ public class UUIDUtility {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static UUID getUUIDOf(String playername, Database db) throws Exception {
|
||||
public static UUID getUUIDOf(String playername, Database db) {
|
||||
UUID uuid = null;
|
||||
try {
|
||||
uuid = db.getUsersTable().getUuidOf(playername);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog("UUIDUtility", e);
|
||||
}
|
||||
if (uuid == null) {
|
||||
uuid = UUIDFetcher.getUUIDOf(playername);
|
||||
try {
|
||||
if (uuid == null) {
|
||||
uuid = UUIDFetcher.getUUIDOf(playername);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
@ -6,8 +6,8 @@
|
||||
package test.java.main.java.com.djrapitops.plan;
|
||||
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import test.java.utils.MockUtils;
|
||||
|
||||
/**
|
||||
@ -15,21 +15,13 @@ import test.java.utils.MockUtils;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PermissionsTest {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PermissionsTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testUserHasThisPermission() {
|
||||
assertTrue(Permissions.INSPECT_OTHER.userHasThisPermission(MockUtils.mockPlayer()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -37,5 +29,5 @@ public class PermissionsTest {
|
||||
public void testGetPermission() {
|
||||
assertEquals("plan.inspect.other", Permissions.INSPECT_OTHER.getPermission());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public class SettingsTest {
|
||||
List<String> result = Settings.HIDE_TOWNS.getStringList();
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -39,7 +39,7 @@ public class DemographicsDataTest {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -15,7 +15,7 @@ import org.junit.Test;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class KillDataTest {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -61,5 +61,5 @@ public class KillDataTest {
|
||||
KillData k = new KillData(uuid, 1, "TestWeapon", 100L);
|
||||
assertEquals(k.getVictimUserID(), 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import org.junit.Test;
|
||||
public class SessionDataTest {
|
||||
|
||||
private SessionData test;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -57,7 +57,7 @@ public class SessionDataTest {
|
||||
test.endSession(1L);
|
||||
assertTrue("Supposed to be valid.", test.isValid());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -65,7 +65,7 @@ public class SessionDataTest {
|
||||
public void testInvalid() {
|
||||
assertTrue("Supposed to be invalid.", !test.isValid());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -75,7 +75,7 @@ public class SessionDataTest {
|
||||
test.endSession(2);
|
||||
assertTrue("Supposed to be invalid.", !test.isValid());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -85,7 +85,7 @@ public class SessionDataTest {
|
||||
test.endSession(3);
|
||||
assertTrue("Supposed to be valid.", test.isValid());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -95,7 +95,7 @@ public class SessionDataTest {
|
||||
String result = test.toString();
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -106,7 +106,7 @@ public class SessionDataTest {
|
||||
long result = test.getLength();
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -22,6 +22,8 @@ import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -29,8 +31,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -6,21 +6,21 @@
|
||||
package test.java.main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class AnalysisTypeTest {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AnalysisTypeTest() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -36,5 +36,5 @@ public class AnalysisTypeTest {
|
||||
public void testGetPlaceholderModifier() {
|
||||
assertEquals("totalInt_", AnalysisType.INT_TOTAL.getPlaceholderModifier());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,17 +21,17 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -69,10 +69,10 @@ public class DataCacheHandlerTest {
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,7 +61,7 @@ public class LocationCacheTest {
|
||||
assertTrue("Didn't contain location", result.contains(loc));
|
||||
assertTrue("Didn't contain location", result.contains(loc2));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -11,6 +11,7 @@ import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.cache.SessionCache;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -18,7 +19,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -43,7 +43,7 @@ public class SessionCacheTest {
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue(t.setUp());
|
||||
test = new SessionCache();
|
||||
test = new SessionCache();
|
||||
}
|
||||
|
||||
/**
|
||||
|
12
Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueueTest.java
vendored
12
Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueueTest.java
vendored
@ -25,16 +25,16 @@ import test.java.utils.TestInit;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({JavaPlugin.class})
|
||||
public class DataCacheClearQueueTest {
|
||||
|
||||
|
||||
private Plan plan;
|
||||
private DataCacheHandler handler;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DataCacheClearQueueTest() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -43,9 +43,9 @@ public class DataCacheClearQueueTest {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
plan = t.getPlanMock();
|
||||
handler = new DataCacheHandler(plan) {
|
||||
handler = new DataCacheHandler(plan) {
|
||||
@Override
|
||||
public boolean getCommandUseFromDb() {
|
||||
public boolean getCommandUseFromDb() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -89,5 +89,5 @@ public class DataCacheClearQueueTest {
|
||||
@Test
|
||||
public void testStop() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
2
Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueueTest.java
vendored
2
Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueueTest.java
vendored
@ -18,10 +18,10 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -27,7 +27,7 @@ import test.java.utils.TestInit;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class ChatHandlingTest {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -43,7 +43,7 @@ public class ChatHandlingTest {
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -64,7 +64,7 @@ public class ChatHandlingTest {
|
||||
ChatHandling.updateDemographicInformation("I'm male", data);
|
||||
assertTrue("Didn't update gender", data.getDemData().getGender() == Gender.MALE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -75,7 +75,7 @@ public class ChatHandlingTest {
|
||||
assertTrue("Updated gender", data.getDemData().getGender() == Gender.UNKNOWN);
|
||||
assertTrue("Updated age", data.getDemData().getAge() == -1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -85,7 +85,7 @@ public class ChatHandlingTest {
|
||||
ChatHandling.updateDemographicInformation("I'm 100", data);
|
||||
assertTrue("Updated age", data.getDemData().getAge() == -1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -96,7 +96,7 @@ public class ChatHandlingTest {
|
||||
assertTrue("Updated gender", data.getDemData().getGender() == Gender.UNKNOWN);
|
||||
assertTrue("Updated age", data.getDemData().getAge() == -1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -107,7 +107,7 @@ public class ChatHandlingTest {
|
||||
assertTrue("Updated gender", data.getDemData().getGender() == Gender.UNKNOWN);
|
||||
assertTrue("Updated age", data.getDemData().getAge() == -1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -117,5 +117,5 @@ public class ChatHandlingTest {
|
||||
ChatHandling.updateDemographicInformation("im 18", data);
|
||||
assertTrue("Didn't update age", data.getDemData().getAge() == 18);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import test.java.utils.TestInit;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class GamemodeHandlingTest {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -41,7 +41,7 @@ public class GamemodeHandlingTest {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -55,17 +55,17 @@ public class GamemodeHandlingTest {
|
||||
long time = 2000L;
|
||||
GamemodeHandling.processGamemodeInfo(data, time, GameMode.SURVIVAL);
|
||||
Long result = data.getGmTimes().get(GameMode.CREATIVE);
|
||||
assertTrue("Gamemode time was "+result, result == 1050L);
|
||||
assertTrue("Gamemode time was " + result, result == 1050L);
|
||||
result = data.getPlayTime();
|
||||
assertTrue("Playtime was"+result, result == 1100L);
|
||||
assertTrue("Playtime was" + result, result == 1100L);
|
||||
result = data.getLastPlayed();
|
||||
assertTrue("Last Played was"+result, result == 2000L);
|
||||
assertTrue("Last Played was" + result, result == 2000L);
|
||||
GameMode lastGM = data.getLastGamemode();
|
||||
assertTrue("Last gm not Survival", lastGM == GameMode.SURVIVAL);
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 1100L);
|
||||
assertTrue("Last swaptime was " + result, result == 1100L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -79,17 +79,17 @@ public class GamemodeHandlingTest {
|
||||
long time = 2000L;
|
||||
GamemodeHandling.processGamemodeInfo(data, time, GameMode.SURVIVAL);
|
||||
Long result = data.getGmTimes().get(GameMode.SURVIVAL);
|
||||
assertTrue("Gamemode time was "+result, result == 1050L);
|
||||
assertTrue("Gamemode time was " + result, result == 1050L);
|
||||
result = data.getPlayTime();
|
||||
assertTrue("Playtime was"+result, result == 1100L);
|
||||
assertTrue("Playtime was" + result, result == 1100L);
|
||||
result = data.getLastPlayed();
|
||||
assertTrue("Last Played was"+result, result == 2000L);
|
||||
assertTrue("Last Played was" + result, result == 2000L);
|
||||
GameMode lastGM = data.getLastGamemode();
|
||||
assertTrue("Last gm not Survival", lastGM == GameMode.SURVIVAL);
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 1100L);
|
||||
assertTrue("Last swaptime was " + result, result == 1100L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -103,17 +103,17 @@ public class GamemodeHandlingTest {
|
||||
long time = 2000L;
|
||||
GamemodeHandling.processGamemodeInfo(data, time, null);
|
||||
Long result = data.getGmTimes().get(GameMode.SURVIVAL);
|
||||
assertTrue("Gamemode time was "+result, result == 0L);
|
||||
assertTrue("Gamemode time was " + result, result == 0L);
|
||||
result = data.getPlayTime();
|
||||
assertTrue("Playtime was"+result, result == 100L);
|
||||
assertTrue("Playtime was" + result, result == 100L);
|
||||
result = data.getLastPlayed();
|
||||
assertTrue("Last Played was"+result, result == 1000L);
|
||||
assertTrue("Last Played was" + result, result == 1000L);
|
||||
GameMode lastGM = data.getLastGamemode();
|
||||
assertTrue("Last gm not Survival", lastGM == GameMode.SURVIVAL);
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 50L);
|
||||
assertTrue("Last swaptime was " + result, result == 50L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -127,17 +127,17 @@ public class GamemodeHandlingTest {
|
||||
long time = 2000L;
|
||||
GamemodeHandling.processGamemodeInfo(data, time, GameMode.SURVIVAL);
|
||||
Long result = data.getGmTimes().get(GameMode.SURVIVAL);
|
||||
assertTrue("Gamemode time was "+result, result == 1050L);
|
||||
assertTrue("Gamemode time was " + result, result == 1050L);
|
||||
result = data.getPlayTime();
|
||||
assertTrue("Playtime was"+result, result == 1100L);
|
||||
assertTrue("Playtime was" + result, result == 1100L);
|
||||
result = data.getLastPlayed();
|
||||
assertTrue("Last Played was"+result, result == 2000L);
|
||||
assertTrue("Last Played was" + result, result == 2000L);
|
||||
GameMode lastGM = data.getLastGamemode();
|
||||
assertTrue("Last gm not Survival", lastGM == GameMode.SURVIVAL);
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 1100L);
|
||||
assertTrue("Last swaptime was " + result, result == 1100L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -152,15 +152,15 @@ public class GamemodeHandlingTest {
|
||||
long time = 2000L;
|
||||
GamemodeHandling.processGamemodeInfo(data, time, GameMode.SURVIVAL);
|
||||
Long result = data.getGmTimes().get(GameMode.SURVIVAL);
|
||||
assertTrue("Gamemode time was "+result, result == 1050L);
|
||||
assertTrue("Gamemode time was " + result, result == 1050L);
|
||||
result = data.getPlayTime();
|
||||
assertTrue("Playtime was"+result, result == 1100L);
|
||||
assertTrue("Playtime was" + result, result == 1100L);
|
||||
result = data.getLastPlayed();
|
||||
assertTrue("Last Played was"+result, result == 2000L);
|
||||
assertTrue("Last Played was" + result, result == 2000L);
|
||||
GameMode lastGM = data.getLastGamemode();
|
||||
assertTrue("Last gm not Survival", lastGM == GameMode.SURVIVAL);
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 1100L);
|
||||
assertTrue("Last swaptime was " + result, result == 1100L);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -18,17 +18,17 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -26,7 +26,7 @@ import test.java.utils.TestInit;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class ChatInfoTest {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -35,7 +35,7 @@ public class ChatInfoTest {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -54,7 +54,7 @@ public class ChatInfoTest {
|
||||
assertTrue("Didn't add nickname", data.getNicknames().contains(expected));
|
||||
assertTrue("Didn't update gender", data.getDemData().getGender() == Gender.MALE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -66,7 +66,7 @@ public class ChatInfoTest {
|
||||
assertTrue("Didn't succeed", i.process(data));
|
||||
assertTrue("Didn't update age", data.getDemData().getAge() == 18);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -78,7 +78,7 @@ public class ChatInfoTest {
|
||||
assertTrue("Didn't succeed", i.process(data));
|
||||
assertTrue("Didn't update gender", data.getDemData().getGender() == Gender.MALE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -51,7 +51,7 @@ public class DeathInfoTest {
|
||||
assertTrue(i.process(data));
|
||||
assertEquals(1, data.getDeaths());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -56,17 +56,17 @@ public class GamemodeInfoTest {
|
||||
GamemodeInfo i = new GamemodeInfo(data.getUuid(), time, GameMode.SURVIVAL);
|
||||
assertTrue(i.process(data));
|
||||
Long result = data.getGmTimes().get(GameMode.CREATIVE);
|
||||
assertTrue("Gamemode time was "+result, result == 1050L);
|
||||
assertTrue("Gamemode time was " + result, result == 1050L);
|
||||
result = data.getPlayTime();
|
||||
assertTrue("Playtime was"+result, result == 1100L);
|
||||
assertTrue("Playtime was" + result, result == 1100L);
|
||||
result = data.getLastPlayed();
|
||||
assertTrue("Last Played was"+result, result == 2000L);
|
||||
assertTrue("Last Played was" + result, result == 2000L);
|
||||
GameMode lastGM = data.getLastGamemode();
|
||||
assertTrue("Last gm not Survival", lastGM == GameMode.SURVIVAL);
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 1100L);
|
||||
assertTrue("Last swaptime was " + result, result == 1100L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -81,17 +81,17 @@ public class GamemodeInfoTest {
|
||||
GamemodeInfo i = new GamemodeInfo(null, time, GameMode.SURVIVAL);
|
||||
assertTrue(!i.process(data));
|
||||
Long result = data.getGmTimes().get(GameMode.CREATIVE);
|
||||
assertTrue("Gamemode time was "+result, result == 0L);
|
||||
assertTrue("Gamemode time was " + result, result == 0L);
|
||||
result = data.getPlayTime();
|
||||
assertTrue("Playtime was"+result, result == 100L);
|
||||
assertTrue("Playtime was" + result, result == 100L);
|
||||
result = data.getLastPlayed();
|
||||
assertTrue("Last Played was"+result, result == 1000L);
|
||||
assertTrue("Last Played was" + result, result == 1000L);
|
||||
GameMode lastGM = data.getLastGamemode();
|
||||
assertTrue("Last gm not Survival", lastGM == GameMode.CREATIVE);
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 50L);
|
||||
assertTrue("Last swaptime was " + result, result == 50L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -106,15 +106,15 @@ public class GamemodeInfoTest {
|
||||
GamemodeInfo i = new GamemodeInfo(data.getUuid(), time, null);
|
||||
assertTrue(!i.process(data));
|
||||
Long result = data.getGmTimes().get(GameMode.CREATIVE);
|
||||
assertTrue("Gamemode time was "+result, result == 0L);
|
||||
assertTrue("Gamemode time was " + result, result == 0L);
|
||||
result = data.getPlayTime();
|
||||
assertTrue("Playtime was"+result, result == 100L);
|
||||
assertTrue("Playtime was" + result, result == 100L);
|
||||
result = data.getLastPlayed();
|
||||
assertTrue("Last Played was"+result, result == 1000L);
|
||||
assertTrue("Last Played was" + result, result == 1000L);
|
||||
GameMode lastGM = data.getLastGamemode();
|
||||
assertTrue("Last gm not Survival", lastGM == GameMode.CREATIVE);
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 50L);
|
||||
assertTrue("Last swaptime was " + result, result == 50L);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import org.junit.Test;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class HandlingInfoTest {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -30,13 +30,13 @@ public class HandlingInfoTest {
|
||||
@Test
|
||||
public void testGetUuid() {
|
||||
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L ) {
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L) {
|
||||
@Override
|
||||
public boolean process(UserData data) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
assertEquals(uuid,i.getUuid());
|
||||
assertEquals(uuid, i.getUuid());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,13 +45,13 @@ public class HandlingInfoTest {
|
||||
@Test
|
||||
public void testGetType() {
|
||||
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L ) {
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L) {
|
||||
@Override
|
||||
public boolean process(UserData data) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
assertEquals(InfoType.CHAT,i.getType());
|
||||
assertEquals(InfoType.CHAT, i.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,12 +60,12 @@ public class HandlingInfoTest {
|
||||
@Test
|
||||
public void testGetTime() {
|
||||
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L ) {
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L) {
|
||||
@Override
|
||||
public boolean process(UserData data) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
assertEquals(10L,i.getTime());
|
||||
assertEquals(10L, i.getTime());
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user