mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 19:17:43 +01:00
IntellJ Code Analysis clean-up
This commit is contained in:
parent
6626875239
commit
0ef3110dea
@ -174,7 +174,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
|||||||
|
|
||||||
setupFilter(); // TODO Move to RegisterCommand Constructor
|
setupFilter(); // TODO Move to RegisterCommand Constructor
|
||||||
|
|
||||||
// Data view settings // TODO Rewrite. (TextUI removed & webserver might be running on bungee
|
// Data view settings // TODO Rewrite. (TextUI removed & webServer might be running on bungee
|
||||||
boolean usingAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
|
boolean usingAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
|
||||||
boolean hasDataViewCapability = usingAlternativeIP;
|
boolean hasDataViewCapability = usingAlternativeIP;
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
|||||||
/**
|
/**
|
||||||
* Disables the plugin.
|
* Disables the plugin.
|
||||||
* <p>
|
* <p>
|
||||||
* Stops the webserver, cancels all tasks and saves cache to the database.
|
* Stops the webServer, cancels all tasks and saves cache to the database.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
@ -357,9 +357,9 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to access Webserver.
|
* Used to access WebServer.
|
||||||
*
|
*
|
||||||
* @return the Webserver
|
* @return the WebServer
|
||||||
*/
|
*/
|
||||||
public WebServer getWebServer() {
|
public WebServer getWebServer() {
|
||||||
return webServer;
|
return webServer;
|
||||||
|
@ -80,9 +80,8 @@ public class AnalyzeCommand extends SubCommand {
|
|||||||
boolean refresh = !analysisRefreshDate.isPresent()
|
boolean refresh = !analysisRefreshDate.isPresent()
|
||||||
|| analysisRefreshDate.get() < MiscUtils.getTime() - TimeAmount.MINUTE.ms()
|
|| analysisRefreshDate.get() < MiscUtils.getTime() - TimeAmount.MINUTE.ms()
|
||||||
|| forcedRefresh;
|
|| forcedRefresh;
|
||||||
if (refresh) {
|
|
||||||
updateCache(sender, refresh);
|
updateCache(sender, refresh);
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(Locale.get(Msg.CMD_INFO_FETCH_DATA).toString());
|
sender.sendMessage(Locale.get(Msg.CMD_INFO_FETCH_DATA).toString());
|
||||||
if (plugin.getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {
|
if (plugin.getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {
|
||||||
|
@ -12,7 +12,6 @@ import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
|||||||
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
|
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||||
import main.java.com.djrapitops.plan.utilities.html.graphs.PlayerActivityGraphCreator;
|
import main.java.com.djrapitops.plan.utilities.html.graphs.PlayerActivityGraphCreator;
|
||||||
import main.java.com.djrapitops.plan.utilities.html.graphs.PunchCardGraphCreator;
|
import main.java.com.djrapitops.plan.utilities.html.graphs.PunchCardGraphCreator;
|
||||||
import main.java.com.djrapitops.plan.utilities.html.graphs.SessionLengthDistributionGraphCreator;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -82,7 +81,6 @@ public class ActivityPart extends RawData {
|
|||||||
.filter(s -> s.getSessionStart() > MiscUtils.getTime() - TimeAmount.MONTH.ms())
|
.filter(s -> s.getSessionStart() > MiscUtils.getTime() - TimeAmount.MONTH.ms())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
addValue("punchCardSeries", PunchCardGraphCreator.createDataSeries(sessionsMonth));
|
addValue("punchCardSeries", PunchCardGraphCreator.createDataSeries(sessionsMonth));
|
||||||
addValue("sessionLengthSeries", SessionLengthDistributionGraphCreator.createDataSeries(lengths));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void playerActivityGraphs() {
|
private void playerActivityGraphs() {
|
||||||
|
@ -26,7 +26,7 @@ public class MySQLDB extends SQLDB {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setupDataSource() throws DatabaseInitException {
|
public void setupDataSource() throws DatabaseInitException {
|
||||||
IFileConfig config = null;
|
IFileConfig config;
|
||||||
try {
|
try {
|
||||||
config = plugin.getIConfig().getConfig();
|
config = plugin.getIConfig().getConfig();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -76,7 +76,7 @@ public class DataCache extends SessionCache {
|
|||||||
public String getDisplayName(UUID uuid) {
|
public String getDisplayName(UUID uuid) {
|
||||||
String cached = displayNames.get(uuid);
|
String cached = displayNames.get(uuid);
|
||||||
if (cached == null) {
|
if (cached == null) {
|
||||||
List<String> nicknames = null;
|
List<String> nicknames;
|
||||||
try {
|
try {
|
||||||
nicknames = db.getNicknamesTable().getNicknames(uuid);
|
nicknames = db.getNicknamesTable().getNicknames(uuid);
|
||||||
if (!nicknames.isEmpty()) {
|
if (!nicknames.isEmpty()) {
|
||||||
|
@ -47,7 +47,6 @@ public class PlanChatListener implements Listener {
|
|||||||
String name = p.getName();
|
String name = p.getName();
|
||||||
String displayName = p.getDisplayName();
|
String displayName = p.getDisplayName();
|
||||||
|
|
||||||
DataCache dataCache = plugin.getDataCache();
|
|
||||||
if (dataCache.isFirstSession(uuid)) {
|
if (dataCache.isFirstSession(uuid)) {
|
||||||
dataCache.firstSessionMessageSent(uuid);
|
dataCache.firstSessionMessageSent(uuid);
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,8 @@ public class PlanGamemodeChangeListener implements Listener {
|
|||||||
String worldName = p.getWorld().getName();
|
String worldName = p.getWorld().getName();
|
||||||
|
|
||||||
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
|
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
|
||||||
if (cachedSession.isPresent()) {
|
cachedSession.ifPresent(session -> {
|
||||||
Session session = cachedSession.get();
|
|
||||||
session.changeState(worldName, gameMode, time);
|
session.changeState(worldName, gameMode, time);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,8 @@ public class PlanWorldChangeListener implements Listener {
|
|||||||
long time = MiscUtils.getTime();
|
long time = MiscUtils.getTime();
|
||||||
|
|
||||||
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
|
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
|
||||||
if (cachedSession.isPresent()) {
|
cachedSession.ifPresent(session -> {
|
||||||
Session session = cachedSession.get();
|
|
||||||
session.changeState(worldName, gameMode, time);
|
session.changeState(worldName, gameMode, time);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import main.java.com.djrapitops.plan.data.Action;
|
|||||||
import main.java.com.djrapitops.plan.database.Database;
|
import main.java.com.djrapitops.plan.database.Database;
|
||||||
import main.java.com.djrapitops.plan.database.tables.Actions;
|
import main.java.com.djrapitops.plan.database.tables.Actions;
|
||||||
import main.java.com.djrapitops.plan.database.tables.UserInfoTable;
|
import main.java.com.djrapitops.plan.database.tables.UserInfoTable;
|
||||||
|
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -39,8 +40,12 @@ public class RegisterProcessor extends PlayerProcessor {
|
|||||||
UUID uuid = getUUID();
|
UUID uuid = getUUID();
|
||||||
Plan plugin = Plan.getInstance();
|
Plan plugin = Plan.getInstance();
|
||||||
Database db = plugin.getDB();
|
Database db = plugin.getDB();
|
||||||
|
UsersTable usersTable = db.getUsersTable();
|
||||||
UserInfoTable userInfoTable = db.getUserInfoTable();
|
UserInfoTable userInfoTable = db.getUserInfoTable();
|
||||||
try {
|
try {
|
||||||
|
if (!usersTable.isRegistered(uuid)) {
|
||||||
|
usersTable.registerUser(uuid, registered, name);
|
||||||
|
}
|
||||||
if (userInfoTable.isRegistered(uuid)) {
|
if (userInfoTable.isRegistered(uuid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import com.djrapitops.plugin.task.AbsRunnable;
|
|||||||
import main.java.com.djrapitops.plan.Log;
|
import main.java.com.djrapitops.plan.Log;
|
||||||
import main.java.com.djrapitops.plan.Plan;
|
import main.java.com.djrapitops.plan.Plan;
|
||||||
import main.java.com.djrapitops.plan.data.TPS;
|
import main.java.com.djrapitops.plan.data.TPS;
|
||||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
|
||||||
import main.java.com.djrapitops.plan.systems.processing.TPSInsertProcessor;
|
import main.java.com.djrapitops.plan.systems.processing.TPSInsertProcessor;
|
||||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||||
@ -24,7 +23,6 @@ import java.util.List;
|
|||||||
public class TPSCountTimer extends AbsRunnable {
|
public class TPSCountTimer extends AbsRunnable {
|
||||||
|
|
||||||
private final Plan plugin;
|
private final Plan plugin;
|
||||||
private final DataCache dataCache;
|
|
||||||
private final List<TPS> history;
|
private final List<TPS> history;
|
||||||
private long lastCheckNano;
|
private long lastCheckNano;
|
||||||
|
|
||||||
@ -33,7 +31,6 @@ public class TPSCountTimer extends AbsRunnable {
|
|||||||
public TPSCountTimer(Plan plugin) {
|
public TPSCountTimer(Plan plugin) {
|
||||||
super("TPSCountTimer");
|
super("TPSCountTimer");
|
||||||
lastCheckNano = -1;
|
lastCheckNano = -1;
|
||||||
this.dataCache = plugin.getDataCache();
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
history = new ArrayList<>();
|
history = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
@ -96,54 +96,51 @@ public class WebServer {
|
|||||||
server = HttpServer.create(new InetSocketAddress(port), 10);
|
server = HttpServer.create(new InetSocketAddress(port), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
server.createContext("/", new HttpHandler() {
|
server.createContext("/", exchange -> {
|
||||||
@Override
|
Headers responseHeaders = exchange.getResponseHeaders();
|
||||||
public void handle(HttpExchange exchange) {
|
URI uri = exchange.getRequestURI();
|
||||||
Headers responseHeaders = exchange.getResponseHeaders();
|
String target = uri.toString();
|
||||||
URI uri = exchange.getRequestURI();
|
try {
|
||||||
String target = uri.toString();
|
boolean apiRequest = "POST".equals(exchange.getRequestMethod());
|
||||||
try {
|
Response response = null;
|
||||||
boolean apiRequest = "POST".equals(exchange.getRequestMethod());
|
|
||||||
Response response = null;
|
|
||||||
|
|
||||||
String type = "text/html;";
|
String type = "text/html;";
|
||||||
|
|
||||||
if (apiRequest) {
|
if (apiRequest) {
|
||||||
response = getAPIResponse(target, exchange);
|
response = getAPIResponse(target, exchange);
|
||||||
|
|
||||||
if (response instanceof JsonResponse) {
|
if (response instanceof JsonResponse) {
|
||||||
type = "application/json;";
|
type = "application/json;";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
responseHeaders.set("Content-Type", type);
|
|
||||||
|
|
||||||
if (apiRequest) {
|
|
||||||
sendData(responseHeaders, exchange, response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebUser user = null;
|
|
||||||
|
|
||||||
if (usingHttps) {
|
|
||||||
user = getUser(exchange.getRequestHeaders());
|
|
||||||
|
|
||||||
// Prompt authorization
|
|
||||||
if (user == null) {
|
|
||||||
responseHeaders.set("WWW-Authenticate", "Basic realm=\"/\";");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response = getResponse(target, user);
|
|
||||||
if (response instanceof CSSResponse) {
|
|
||||||
responseHeaders.set("Content-Type", "text/css");
|
|
||||||
}
|
|
||||||
sendData(responseHeaders, exchange, response);
|
|
||||||
} catch (Exception e) {
|
|
||||||
internalErrorResponse(exchange, responseHeaders, target, e);
|
|
||||||
} finally {
|
|
||||||
exchange.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
responseHeaders.set("Content-Type", type);
|
||||||
|
|
||||||
|
if (apiRequest) {
|
||||||
|
sendData(responseHeaders, exchange, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebUser user = null;
|
||||||
|
|
||||||
|
if (usingHttps) {
|
||||||
|
user = getUser(exchange.getRequestHeaders());
|
||||||
|
|
||||||
|
// Prompt authorization
|
||||||
|
if (user == null) {
|
||||||
|
responseHeaders.set("WWW-Authenticate", "Basic realm=\"/\";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
response = getResponse(target, user);
|
||||||
|
if (response instanceof CSSResponse) {
|
||||||
|
responseHeaders.set("Content-Type", "text/css");
|
||||||
|
}
|
||||||
|
sendData(responseHeaders, exchange, response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
internalErrorResponse(exchange, responseHeaders, target, e);
|
||||||
|
} finally {
|
||||||
|
exchange.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -433,12 +430,11 @@ public class WebServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Response forbiddenResponse(int permLevel, int required) {
|
private Response forbiddenResponse(int permLevel, int required) {
|
||||||
return PageCache.loadPage("forbidden", () -> {
|
return PageCache.loadPage("forbidden", () ->
|
||||||
return new ForbiddenResponse("Unauthorized User.<br>"
|
new ForbiddenResponse("Unauthorized User.<br>"
|
||||||
+ "Make sure your user has the correct access level.<br>"
|
+ "Make sure your user has the correct access level.<br>"
|
||||||
+ "This page requires permission level of " + required + ",<br>"
|
+ "This page requires permission level of " + required + ",<br>"
|
||||||
+ "This user has permission level of " + permLevel);
|
+ "This user has permission level of " + permLevel));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response rootPageResponse(WebUser user) {
|
private Response rootPageResponse(WebUser user) {
|
||||||
|
@ -44,8 +44,7 @@ public class HtmlStructure {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (String element : elements) {
|
||||||
String element = elements[i];
|
|
||||||
if (element.isEmpty()) {
|
if (element.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -74,7 +73,7 @@ public class HtmlStructure {
|
|||||||
builder.append("Playtime: ").append(FormatUtils.formatTimeAmount(playTime)).append("<br>");
|
builder.append("Playtime: ").append(FormatUtils.formatTimeAmount(playTime)).append("<br>");
|
||||||
builder.append("<br>");
|
builder.append("<br>");
|
||||||
long longestSessionLength = AnalysisUtils.getLongestSessionLength(serverSessions);
|
long longestSessionLength = AnalysisUtils.getLongestSessionLength(serverSessions);
|
||||||
builder.append("Longest Session: " + FormatUtils.formatTimeAmount(longestSessionLength));
|
builder.append("Longest Session: ").append(FormatUtils.formatTimeAmount(longestSessionLength));
|
||||||
|
|
||||||
// Content and box end
|
// Content and box end
|
||||||
builder.append("</p></div>");
|
builder.append("</p></div>");
|
||||||
|
@ -167,7 +167,7 @@
|
|||||||
<table class="sortable table">
|
<table class="sortable table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><i class="fa fa-clock-o" aria-hidden="true"> Time</th>
|
<th><i class="fa fa-clock-o" aria-hidden="true"></i> Time</th>
|
||||||
<th>Killed</th>
|
<th>Killed</th>
|
||||||
<th>With</th>
|
<th>With</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -216,7 +216,7 @@
|
|||||||
<table class="sortable table">
|
<table class="sortable table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><i class="fa fa-clock-o" aria-hidden="true"> Time</th>
|
<th><i class="fa fa-clock-o" aria-hidden="true"></i> Time</th>
|
||||||
<th>Killed</th>
|
<th>Killed</th>
|
||||||
<th>With</th>
|
<th>With</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user