IntellJ Code Analysis clean-up

This commit is contained in:
Rsl1122 2017-08-30 19:15:41 +03:00
parent 6626875239
commit 0ef3110dea
13 changed files with 66 additions and 75 deletions

View File

@ -174,7 +174,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
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 hasDataViewCapability = usingAlternativeIP;
@ -255,7 +255,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
/**
* Disables the plugin.
* <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
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() {
return webServer;

View File

@ -80,9 +80,8 @@ public class AnalyzeCommand extends SubCommand {
boolean refresh = !analysisRefreshDate.isPresent()
|| analysisRefreshDate.get() < MiscUtils.getTime() - TimeAmount.MINUTE.ms()
|| forcedRefresh;
if (refresh) {
updateCache(sender, refresh);
}
updateCache(sender, refresh);
sender.sendMessage(Locale.get(Msg.CMD_INFO_FETCH_DATA).toString());
if (plugin.getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {

View File

@ -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.graphs.PlayerActivityGraphCreator;
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.stream.Collectors;
@ -82,7 +81,6 @@ public class ActivityPart extends RawData {
.filter(s -> s.getSessionStart() > MiscUtils.getTime() - TimeAmount.MONTH.ms())
.collect(Collectors.toList());
addValue("punchCardSeries", PunchCardGraphCreator.createDataSeries(sessionsMonth));
addValue("sessionLengthSeries", SessionLengthDistributionGraphCreator.createDataSeries(lengths));
}
private void playerActivityGraphs() {

View File

@ -26,7 +26,7 @@ public class MySQLDB extends SQLDB {
*/
@Override
public void setupDataSource() throws DatabaseInitException {
IFileConfig config = null;
IFileConfig config;
try {
config = plugin.getIConfig().getConfig();
} catch (IOException e) {

View File

@ -76,7 +76,7 @@ public class DataCache extends SessionCache {
public String getDisplayName(UUID uuid) {
String cached = displayNames.get(uuid);
if (cached == null) {
List<String> nicknames = null;
List<String> nicknames;
try {
nicknames = db.getNicknamesTable().getNicknames(uuid);
if (!nicknames.isEmpty()) {

View File

@ -47,7 +47,6 @@ public class PlanChatListener implements Listener {
String name = p.getName();
String displayName = p.getDisplayName();
DataCache dataCache = plugin.getDataCache();
if (dataCache.isFirstSession(uuid)) {
dataCache.firstSessionMessageSent(uuid);
}

View File

@ -47,9 +47,8 @@ public class PlanGamemodeChangeListener implements Listener {
String worldName = p.getWorld().getName();
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
if (cachedSession.isPresent()) {
Session session = cachedSession.get();
cachedSession.ifPresent(session -> {
session.changeState(worldName, gameMode, time);
}
});
}
}

View File

@ -29,9 +29,8 @@ public class PlanWorldChangeListener implements Listener {
long time = MiscUtils.getTime();
Optional<Session> cachedSession = plugin.getDataCache().getCachedSession(uuid);
if (cachedSession.isPresent()) {
Session session = cachedSession.get();
cachedSession.ifPresent(session -> {
session.changeState(worldName, gameMode, time);
}
});
}
}

View File

@ -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.tables.Actions;
import main.java.com.djrapitops.plan.database.tables.UserInfoTable;
import main.java.com.djrapitops.plan.database.tables.UsersTable;
import java.sql.SQLException;
import java.util.UUID;
@ -39,8 +40,12 @@ public class RegisterProcessor extends PlayerProcessor {
UUID uuid = getUUID();
Plan plugin = Plan.getInstance();
Database db = plugin.getDB();
UsersTable usersTable = db.getUsersTable();
UserInfoTable userInfoTable = db.getUserInfoTable();
try {
if (!usersTable.isRegistered(uuid)) {
usersTable.registerUser(uuid, registered, name);
}
if (userInfoTable.isRegistered(uuid)) {
return;
}

View File

@ -5,7 +5,6 @@ import com.djrapitops.plugin.task.AbsRunnable;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.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.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
@ -24,7 +23,6 @@ import java.util.List;
public class TPSCountTimer extends AbsRunnable {
private final Plan plugin;
private final DataCache dataCache;
private final List<TPS> history;
private long lastCheckNano;
@ -33,7 +31,6 @@ public class TPSCountTimer extends AbsRunnable {
public TPSCountTimer(Plan plugin) {
super("TPSCountTimer");
lastCheckNano = -1;
this.dataCache = plugin.getDataCache();
this.plugin = plugin;
history = new ArrayList<>();
}

View File

@ -96,54 +96,51 @@ public class WebServer {
server = HttpServer.create(new InetSocketAddress(port), 10);
}
server.createContext("/", new HttpHandler() {
@Override
public void handle(HttpExchange exchange) {
Headers responseHeaders = exchange.getResponseHeaders();
URI uri = exchange.getRequestURI();
String target = uri.toString();
try {
boolean apiRequest = "POST".equals(exchange.getRequestMethod());
Response response = null;
server.createContext("/", exchange -> {
Headers responseHeaders = exchange.getResponseHeaders();
URI uri = exchange.getRequestURI();
String target = uri.toString();
try {
boolean apiRequest = "POST".equals(exchange.getRequestMethod());
Response response = null;
String type = "text/html;";
String type = "text/html;";
if (apiRequest) {
response = getAPIResponse(target, exchange);
if (apiRequest) {
response = getAPIResponse(target, exchange);
if (response instanceof JsonResponse) {
type = "application/json;";
}
if (response instanceof JsonResponse) {
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) {
return PageCache.loadPage("forbidden", () -> {
return new ForbiddenResponse("Unauthorized User.<br>"
+ "Make sure your user has the correct access level.<br>"
+ "This page requires permission level of " + required + ",<br>"
+ "This user has permission level of " + permLevel);
});
return PageCache.loadPage("forbidden", () ->
new ForbiddenResponse("Unauthorized User.<br>"
+ "Make sure your user has the correct access level.<br>"
+ "This page requires permission level of " + required + ",<br>"
+ "This user has permission level of " + permLevel));
}
private Response rootPageResponse(WebUser user) {

View File

@ -44,8 +44,7 @@ public class HtmlStructure {
return "";
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < elements.length; i++) {
String element = elements[i];
for (String element : elements) {
if (element.isEmpty()) {
continue;
}
@ -74,7 +73,7 @@ public class HtmlStructure {
builder.append("Playtime: ").append(FormatUtils.formatTimeAmount(playTime)).append("<br>");
builder.append("<br>");
long longestSessionLength = AnalysisUtils.getLongestSessionLength(serverSessions);
builder.append("Longest Session: " + FormatUtils.formatTimeAmount(longestSessionLength));
builder.append("Longest Session: ").append(FormatUtils.formatTimeAmount(longestSessionLength));
// Content and box end
builder.append("</p></div>");

View File

@ -167,7 +167,7 @@
<table class="sortable table">
<thead>
<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>With</th>
</tr>
@ -216,7 +216,7 @@
<table class="sortable table">
<thead>
<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>With</th>
</tr>