mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-26 01:51:20 +01:00
commit
030995ffcb
@ -71,6 +71,20 @@
|
||||
<exclude>org.apache.logging.*</exclude>
|
||||
</excludes>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.maxmind</pattern>
|
||||
<shadedPattern>plan.com.maxmind</shadedPattern>
|
||||
<excludes>
|
||||
<exclude>org.apache.logging.*</exclude>
|
||||
</excludes>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.fasterxml</pattern>
|
||||
<shadedPattern>plan.com.fasterxml</shadedPattern>
|
||||
<excludes>
|
||||
<exclude>org.apache.logging.*</exclude>
|
||||
</excludes>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
14
Plan/pom.xml
14
Plan/pom.xml
@ -200,6 +200,20 @@
|
||||
<exclude>org.apache.logging.*</exclude>
|
||||
</excludes>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.maxmind</pattern>
|
||||
<shadedPattern>plan.com.maxmind</shadedPattern>
|
||||
<excludes>
|
||||
<exclude>org.apache.logging.*</exclude>
|
||||
</excludes>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.fasterxml</pattern>
|
||||
<shadedPattern>plan.com.fasterxml</shadedPattern>
|
||||
<excludes>
|
||||
<exclude>org.apache.logging.*</exclude>
|
||||
</excludes>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -23,7 +23,7 @@ import org.spongepowered.api.plugin.Plugin;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Plugin(id = "plan", name = "Plan", version = "4.3.1", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"})
|
||||
@Plugin(id = "plan", name = "Plan", version = "4.3.2", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"})
|
||||
public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
||||
|
||||
@Inject
|
||||
@ -114,7 +114,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "4.2.1";
|
||||
return "4.3.2";
|
||||
}
|
||||
|
||||
public SpongeSystem getSystem() {
|
||||
|
@ -13,7 +13,6 @@ import com.djrapitops.plan.system.cache.CacheSystem;
|
||||
import com.djrapitops.plan.system.cache.DataCache;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.Map;
|
||||
@ -53,7 +52,7 @@ public class ShutdownHook extends Thread {
|
||||
Database db = null;
|
||||
try {
|
||||
Map<UUID, Session> activeSessions = SessionCache.getActiveSessions();
|
||||
long now = MiscUtils.getTime();
|
||||
long now = System.currentTimeMillis();
|
||||
db = Database.getActive();
|
||||
saveFirstSessionInformation(db, now);
|
||||
saveActiveSessions(db, activeSessions, now);
|
||||
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.api.exceptions.connection;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* Thrown when connection is returned 401 Bad Request.
|
||||
*
|
||||
@ -12,6 +14,6 @@ package com.djrapitops.plan.api.exceptions.connection;
|
||||
public class BadRequestException extends WebException {
|
||||
|
||||
public BadRequestException(String message) {
|
||||
super(message);
|
||||
super(message, ResponseCode.BAD_REQUEST);
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.api.exceptions.connection;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* Thrown when Connection fails to connect to an address.
|
||||
*
|
||||
@ -12,10 +14,10 @@ package com.djrapitops.plan.api.exceptions.connection;
|
||||
public class ConnectionFailException extends WebException {
|
||||
|
||||
public ConnectionFailException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(message, cause, ResponseCode.CONNECTION_REFUSED);
|
||||
}
|
||||
|
||||
public ConnectionFailException(Throwable cause) {
|
||||
super(cause);
|
||||
super(cause, ResponseCode.CONNECTION_REFUSED);
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.api.exceptions.connection;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* Thrown when Connection gets a 403 response.
|
||||
*
|
||||
@ -11,6 +13,6 @@ package com.djrapitops.plan.api.exceptions.connection;
|
||||
*/
|
||||
public class ForbiddenException extends WebFailException {
|
||||
public ForbiddenException(String url) {
|
||||
super("Forbidden: " + url);
|
||||
super("Forbidden: " + url, ResponseCode.FORBIDDEN);
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.api.exceptions.connection;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* Thrown when InfoRequest can not connect to the other server.
|
||||
*
|
||||
@ -12,14 +14,6 @@ package com.djrapitops.plan.api.exceptions.connection;
|
||||
public class GatewayException extends WebException {
|
||||
|
||||
public GatewayException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public GatewayException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public GatewayException(Throwable cause) {
|
||||
super(cause);
|
||||
super(message, ResponseCode.GATEWAY_ERROR);
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.api.exceptions.connection;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* Thrown when Connection returns 500.
|
||||
*
|
||||
@ -11,10 +13,10 @@ package com.djrapitops.plan.api.exceptions.connection;
|
||||
*/
|
||||
public class InternalErrorException extends WebFailException {
|
||||
public InternalErrorException() {
|
||||
super("Internal Error occurred on receiving server");
|
||||
super("Internal Error occurred on receiving server", ResponseCode.INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
public InternalErrorException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(message, cause, ResponseCode.INTERNAL_ERROR);
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.api.exceptions.connection;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* Thrown when Connection returns 404, when page is not found.
|
||||
*
|
||||
@ -11,6 +13,6 @@ package com.djrapitops.plan.api.exceptions.connection;
|
||||
*/
|
||||
public class NotFoundException extends WebFailException {
|
||||
public NotFoundException(String message) {
|
||||
super(message);
|
||||
super(message, ResponseCode.NOT_FOUND);
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.api.exceptions.connection;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* Thrown when Connection gets a 412 response due to ServerUUID not being in the database.
|
||||
*
|
||||
@ -12,14 +14,14 @@ package com.djrapitops.plan.api.exceptions.connection;
|
||||
public class UnauthorizedServerException extends WebFailException {
|
||||
|
||||
public UnauthorizedServerException(String message) {
|
||||
super(message);
|
||||
super(message, ResponseCode.PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
public UnauthorizedServerException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(message, cause, ResponseCode.PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
public UnauthorizedServerException(Throwable cause) {
|
||||
super(cause);
|
||||
super(cause, ResponseCode.PRECONDITION_FAILED);
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.api.exceptions.connection;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* Thrown when Connection POST-request fails, general Exception.
|
||||
*
|
||||
@ -11,18 +13,47 @@ package com.djrapitops.plan.api.exceptions.connection;
|
||||
*/
|
||||
public class WebException extends Exception {
|
||||
|
||||
private final ResponseCode responseCode;
|
||||
|
||||
public WebException() {
|
||||
responseCode = ResponseCode.NONE;
|
||||
}
|
||||
|
||||
public WebException(String message) {
|
||||
super(message);
|
||||
responseCode = ResponseCode.NONE;
|
||||
}
|
||||
|
||||
public WebException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
responseCode = ResponseCode.NONE;
|
||||
}
|
||||
|
||||
public WebException(Throwable cause) {
|
||||
super(cause);
|
||||
responseCode = ResponseCode.NONE;
|
||||
}
|
||||
|
||||
public WebException(ResponseCode responseCode) {
|
||||
this.responseCode = responseCode;
|
||||
}
|
||||
|
||||
public WebException(String message, ResponseCode responseCode) {
|
||||
super(message);
|
||||
this.responseCode = responseCode;
|
||||
}
|
||||
|
||||
public WebException(String message, Throwable cause, ResponseCode responseCode) {
|
||||
super(message, cause);
|
||||
this.responseCode = responseCode;
|
||||
}
|
||||
|
||||
public WebException(Throwable cause, ResponseCode responseCode) {
|
||||
super(cause);
|
||||
this.responseCode = responseCode;
|
||||
}
|
||||
|
||||
public ResponseCode getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.api.exceptions.connection;
|
||||
|
||||
import com.djrapitops.plan.system.webserver.response.ResponseCode;
|
||||
|
||||
/**
|
||||
* Group of WebExceptions that can be considered a failed connection state on some occasions.
|
||||
*
|
||||
@ -11,18 +13,19 @@ package com.djrapitops.plan.api.exceptions.connection;
|
||||
*/
|
||||
public class WebFailException extends WebException {
|
||||
|
||||
public WebFailException() {
|
||||
}
|
||||
|
||||
public WebFailException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public WebFailException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public WebFailException(Throwable cause) {
|
||||
super(cause);
|
||||
public WebFailException(String message, ResponseCode responseCode) {
|
||||
super(message, responseCode);
|
||||
}
|
||||
|
||||
public WebFailException(String message, Throwable cause, ResponseCode responseCode) {
|
||||
super(message, cause, responseCode);
|
||||
}
|
||||
|
||||
public WebFailException(Throwable cause, ResponseCode responseCode) {
|
||||
super(cause, responseCode);
|
||||
}
|
||||
}
|
@ -18,7 +18,6 @@ import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -53,7 +52,7 @@ public class AnalyzeCommand extends CommandNode {
|
||||
sendWebUserNotificationIfNecessary(sender);
|
||||
sendLink(server, sender);
|
||||
} catch (DBException | WebException e) {
|
||||
sender.sendMessage(ChatColor.RED + " Error occurred: " + e.toString());
|
||||
sender.sendMessage("§cError occurred: " + e.toString());
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
});
|
||||
@ -80,7 +79,7 @@ public class AnalyzeCommand extends CommandNode {
|
||||
|
||||
boolean senderHasWebUser = Database.getActive().check().doesWebUserExists(sender.getName());
|
||||
if (!senderHasWebUser) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register <password>");
|
||||
sender.sendMessage("§e[Plan] You might not have a web user, use /plan register <password>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,12 @@
|
||||
*/
|
||||
package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
/**
|
||||
* Command used for testing functions that are too difficult to unit test.
|
||||
@ -27,25 +26,8 @@ public class DevCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String cmd, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
String feature = args[0];
|
||||
switch (feature) {
|
||||
case "connection":
|
||||
if (!Condition.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
|
||||
break;
|
||||
}
|
||||
sender.sendMessage("[Plan] No implementation.");
|
||||
break;
|
||||
case "web":
|
||||
ConnectionSystem connectionSystem = ConnectionSystem.getInstance();
|
||||
String accessAddress = connectionSystem.getMainAddress();
|
||||
sender.sendMessage((connectionSystem.isServerAvailable())
|
||||
? "Bungee: " + accessAddress : "Local: " + accessAddress);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Verify.isTrue(args.length >= 1, () -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
|
||||
|
||||
sender.sendMessage("No features currently implemented in the command.");
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
@ -41,6 +42,7 @@ public class InfoCommand extends CommandNode {
|
||||
ball + mColor + " Version: " + sColor + plugin.getVersion(),
|
||||
ball + mColor + " Up to date: " + sColor + upToDate,
|
||||
ball + mColor + " Active Database: " + tColor + Database.getActive().getConfigName(),
|
||||
ball + mColor + " Connected to Bungee: " + tColor + (ConnectionSystem.getInstance().isServerAvailable() ? "Yes" : "No"),
|
||||
Locale.get(Msg.CMD_CONSTANT_FOOTER).toString()
|
||||
};
|
||||
sender.sendMessage(messages);
|
||||
|
@ -9,7 +9,6 @@ import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.system.webserver.WebServer;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
@ -19,8 +18,6 @@ import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -51,28 +48,32 @@ public class InspectCommand extends CommandNode {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Database activeDB = Database.getActive();
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (!Condition.isTrue(Verify.notNull(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString(), sender)) {
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString());
|
||||
return;
|
||||
}
|
||||
if (!Condition.isTrue(activeDB.check().isPlayerRegistered(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString(), sender)) {
|
||||
|
||||
Database activeDB = Database.getActive();
|
||||
if (!activeDB.check().isPlayerRegistered(uuid)) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (CommandUtils.isPlayer(sender) && WebServer.getInstance().isAuthRequired()) {
|
||||
boolean senderHasWebUser = activeDB.check().doesWebUserExists(sender.getName());
|
||||
|
||||
if (!senderHasWebUser) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register <password>");
|
||||
sender.sendMessage("§e[Plan] You might not have a web user, use /plan register <password>");
|
||||
}
|
||||
}
|
||||
Processing.submit(new InspectCacheRequestProcessor(uuid, sender, playerName));
|
||||
} catch (FatalDBException ex) {
|
||||
Log.toLog(this.getClass(), ex);
|
||||
sender.sendMessage(ChatColor.RED + "Fatal database exception occurred: " + ex.getMessage());
|
||||
sender.sendMessage("§cFatal database exception occurred: " + ex.getMessage());
|
||||
} catch (DBException ex) {
|
||||
Log.toLog(this.getClass(), ex);
|
||||
sender.sendMessage(ChatColor.YELLOW + "Non-Fatal database exception occurred: " + ex.getMessage());
|
||||
sender.sendMessage("§eNon-Fatal database exception occurred: " + ex.getMessage());
|
||||
} finally {
|
||||
this.cancel();
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class ManageCommand extends TreeCmdNode {
|
||||
new ManageRestoreCommand(plugin),
|
||||
new ManageRemoveCommand(),
|
||||
new ManageHotSwapCommand(plugin),
|
||||
new ManageClearCommand(plugin),
|
||||
new ManageClearCommand(),
|
||||
},
|
||||
new CommandNode[]{
|
||||
new ManageSetupCommand(),
|
||||
|
@ -8,7 +8,6 @@ import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
@ -20,7 +19,6 @@ import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.djrapitops.plugin.settings.DefaultMessages;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -61,18 +59,20 @@ public class QInspectCommand extends CommandNode {
|
||||
public void run() {
|
||||
try {
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (!Condition.isTrue(Verify.notNull(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString(), sender)) {
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString());
|
||||
return;
|
||||
}
|
||||
|
||||
Database database = Database.getActive();
|
||||
if (!Condition.isTrue(database.check().isPlayerRegistered(uuid), Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString(), sender)) {
|
||||
if (!database.check().isPlayerRegistered(uuid)) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString());
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerProfile playerProfile = database.fetch().getPlayerProfile(uuid);
|
||||
|
||||
sendMsgs(sender, playerProfile);
|
||||
|
||||
sendMessages(sender, playerProfile);
|
||||
} catch (DBException ex) {
|
||||
Log.toLog(this.getClass(), ex);
|
||||
} finally {
|
||||
@ -82,8 +82,8 @@ public class QInspectCommand extends CommandNode {
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
|
||||
private void sendMsgs(ISender sender, PlayerProfile profile) {
|
||||
long now = MiscUtils.getTime();
|
||||
private void sendMessages(ISender sender, PlayerProfile profile) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
ColorScheme colorScheme = plugin.getColorScheme();
|
||||
|
||||
@ -97,7 +97,7 @@ public class QInspectCommand extends CommandNode {
|
||||
|
||||
ActivityIndex activityIndex = profile.getActivityIndex(now);
|
||||
|
||||
sender.sendMessage(colT + ball + " " + colM + " Activity Index: " + colS + activityIndex.getFormattedValue() + " | " + activityIndex.getColor());
|
||||
sender.sendMessage(colT + ball + " " + colM + " Activity Index: " + colS + activityIndex.getFormattedValue() + " | " + activityIndex.getGroup());
|
||||
sender.sendMessage(colT + ball + " " + colM + " Registered: " + colS + FormatUtils.formatTimeStampYear(profile.getRegistered()));
|
||||
sender.sendMessage(colT + ball + " " + colM + " Last Seen: " + colS + FormatUtils.formatTimeStampYear(profile.getLastSeen()));
|
||||
sender.sendMessage(colT + ball + " " + colM + " Logged in from: " + colS + profile.getMostRecentGeoInfo().getGeolocation());
|
||||
|
@ -5,7 +5,6 @@ import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
@ -15,6 +14,7 @@ import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -31,6 +31,9 @@ import java.util.Arrays;
|
||||
*/
|
||||
public class RegisterCommand extends CommandNode {
|
||||
|
||||
private final String notEnoughArgsMsg;
|
||||
private final String hashErrorMsg;
|
||||
|
||||
public RegisterCommand() {
|
||||
// No Permission Requirement
|
||||
super("register", "", CommandType.PLAYER_OR_ARGS);
|
||||
@ -40,13 +43,13 @@ public class RegisterCommand extends CommandNode {
|
||||
if (Check.isBukkitAvailable()) {
|
||||
setupFilter();
|
||||
}
|
||||
|
||||
notEnoughArgsMsg = Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse("(3) " + Arrays.toString(getArguments()));
|
||||
hashErrorMsg = "§cPassword hash error.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
String notEnoughArgsMsg = Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse("(3) " + Arrays.toString(getArguments()));
|
||||
String hashErrorMsg = "§cPassword hash error.";
|
||||
String permLvlErrorMsg = "§cIncorrect perm level, not a number: ";
|
||||
try {
|
||||
if (CommandUtils.isPlayer(sender)) {
|
||||
Log.info(sender.getName() + " issued WebUser register command.");
|
||||
@ -58,23 +61,22 @@ public class RegisterCommand extends CommandNode {
|
||||
Log.toLog(this.getClass().getSimpleName(), e);
|
||||
sender.sendMessage(hashErrorMsg);
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(permLvlErrorMsg + args[2]);
|
||||
throw new NumberFormatException(args[2]);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void consoleRegister(String[] args, ISender sender, String notEnoughArgsMsg) throws PassEncryptUtil.CannotPerformOperationException {
|
||||
if (Condition.isTrue(args.length >= 3, notEnoughArgsMsg, sender)) {
|
||||
int permLevel;
|
||||
permLevel = Integer.parseInt(args[2]);
|
||||
String passHash = PassEncryptUtil.createHash(args[0]);
|
||||
registerUser(new WebUser(args[1], passHash, permLevel), sender);
|
||||
}
|
||||
Verify.isTrue(args.length >= 3, () -> new IllegalArgumentException(notEnoughArgsMsg));
|
||||
|
||||
int permLevel;
|
||||
permLevel = Integer.parseInt(args[2]);
|
||||
String passHash = PassEncryptUtil.createHash(args[0]);
|
||||
registerUser(new WebUser(args[1], passHash, permLevel), sender);
|
||||
}
|
||||
|
||||
private void playerRegister(String[] args, ISender sender) throws PassEncryptUtil.CannotPerformOperationException {
|
||||
final String notEnoughArgsMsg = Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse("(1 or 3) " + super.getArguments());
|
||||
boolean registerSenderAsUser = args.length == 1;
|
||||
if (registerSenderAsUser) {
|
||||
String user = sender.getName();
|
||||
@ -114,7 +116,8 @@ public class RegisterCommand extends CommandNode {
|
||||
try {
|
||||
Database database = Database.getActive();
|
||||
boolean userExists = database.check().doesWebUserExists(userName);
|
||||
if (!Condition.isTrue(!userExists, existsMsg, sender)) {
|
||||
if (userExists) {
|
||||
sender.sendMessage(existsMsg);
|
||||
return;
|
||||
}
|
||||
database.save().webUser(webUser);
|
||||
|
@ -3,7 +3,6 @@ package com.djrapitops.plan.command.commands;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
@ -33,9 +32,8 @@ public class SearchCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 1, () -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
|
||||
|
||||
sender.sendMessage(Locale.get(Msg.CMD_INFO_SEARCHING).toString());
|
||||
|
||||
runSearchTask(args, sender);
|
||||
|
@ -1,13 +1,14 @@
|
||||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plan.utilities.ManageUtils;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
@ -16,8 +17,13 @@ import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This manage subcommand is used to backup a database to a .db file.
|
||||
* This command is used to backup a database to a .db file.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 2.3.0
|
||||
@ -34,47 +40,69 @@ public class ManageBackupCommand extends CommandNode {
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
try {
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
|
||||
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
|
||||
return;
|
||||
}
|
||||
String dbName = args[0].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
|
||||
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Database database = DBSystem.getActiveDatabaseByName(dbName);
|
||||
boolean isCorrectDB = Verify.equalsOne(dbName, "sqlite", "mysql");
|
||||
Verify.isTrue(isCorrectDB,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName));
|
||||
|
||||
Database database = DBSystem.getActiveDatabaseByName(dbName);
|
||||
|
||||
Verify.nullCheck(database, NullPointerException::new);
|
||||
|
||||
// If DB is null return
|
||||
if (!Condition.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
|
||||
Log.error(dbName + " was null!");
|
||||
return;
|
||||
}
|
||||
Log.debug("Backup", "Start");
|
||||
runBackupTask(sender, args, database);
|
||||
} catch (DBInitException | NullPointerException e) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
|
||||
} finally {
|
||||
Log.logDebug("Backup");
|
||||
}
|
||||
}
|
||||
|
||||
private void runBackupTask(ISender sender, String[] args, final Database database) {
|
||||
private void runBackupTask(ISender sender, String[] args, Database database) {
|
||||
RunnableFactory.createNew(new AbsRunnable("BackupTask") {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Log.debug("Backup", "Start");
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse());
|
||||
ManageUtils.backup(args[0], database);
|
||||
createNewBackup(args[0], database);
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
Log.toLog(ManageBackupCommand.class, e);
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
|
||||
} finally {
|
||||
Log.logDebug("Backup");
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new backup sqlite file with the data of given database.
|
||||
*
|
||||
* @param dbName Name of database (mysql/sqlite)
|
||||
* @param copyFromDB Database you want to backup.
|
||||
*/
|
||||
private void createNewBackup(String dbName, Database copyFromDB) throws SQLException {
|
||||
SQLiteDB backupDB = null;
|
||||
try {
|
||||
String timeStamp = FormatUtils.formatTimeStampISO8601NoClock(System.currentTimeMillis());
|
||||
String fileName = dbName + "-backup-" + timeStamp;
|
||||
backupDB = new SQLiteDB(fileName);
|
||||
Collection<UUID> uuids = copyFromDB.fetch().getSavedUUIDs();
|
||||
if (uuids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
backupDB.init();
|
||||
copyFromDB.backup().backup(backupDB);
|
||||
} catch (DBException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
} finally {
|
||||
if (backupDB != null) {
|
||||
backupDB.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.api.exceptions.database.FatalDBException;
|
||||
@ -9,8 +8,6 @@ import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
@ -27,31 +24,27 @@ import com.djrapitops.plugin.utilities.Verify;
|
||||
*/
|
||||
public class ManageClearCommand extends CommandNode {
|
||||
|
||||
private final PlanPlugin plugin;
|
||||
|
||||
public ManageClearCommand(PlanPlugin plugin) {
|
||||
public ManageClearCommand() {
|
||||
super("clear", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
setShortHelp(Locale.get(Msg.CMD_USG_MANAGE_CLEAR).toString());
|
||||
setArguments("<DB>", "[-a]");
|
||||
setInDepthHelp(Locale.get(Msg.CMD_HELP_MANAGE_CLEAR).toArray());
|
||||
this.plugin = plugin;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
|
||||
|
||||
String dbName = args[0].toLowerCase();
|
||||
|
||||
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
|
||||
Verify.isTrue(isCorrectDB,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName));
|
||||
|
||||
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Condition.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(args[0])), sender)) {
|
||||
if (!Verify.contains("-a", args)) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(args[0])));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -72,7 +65,6 @@ public class ManageClearCommand extends CommandNode {
|
||||
|
||||
database.remove().everything();
|
||||
|
||||
long now = MiscUtils.getTime();
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_CLEAR_SUCCESS).toString());
|
||||
} catch (FatalDBException e) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString()
|
||||
|
@ -4,10 +4,12 @@ import com.djrapitops.plan.system.listeners.bukkit.PlayerOnlineListener;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* This manage SubCommand is used to disable some features of the plugin temporarily.
|
||||
@ -27,9 +29,9 @@ public class ManageDisableCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "kickcount":
|
||||
PlayerOnlineListener.setCountKicks(false);
|
||||
|
@ -7,7 +7,6 @@ import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
@ -36,32 +35,29 @@ public class ManageHotSwapCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
|
||||
|
||||
String dbName = args[0].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(dbName) || "mysql".equals(dbName);
|
||||
|
||||
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName, sender)) {
|
||||
return;
|
||||
}
|
||||
boolean isCorrectDB = Verify.equalsOne(dbName, "sqlite", "mysql");
|
||||
Verify.isTrue(isCorrectDB,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + dbName));
|
||||
|
||||
if (Condition.isTrue(dbName.equals(Database.getActive().getConfigName()), Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isFalse(dbName.equals(Database.getActive().getConfigName()),
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString()));
|
||||
|
||||
try {
|
||||
final Database database = DBSystem.getActiveDatabaseByName(dbName);
|
||||
|
||||
// If DB is null return
|
||||
if (!Condition.isTrue(Verify.notNull(database), Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString(), sender)) {
|
||||
Log.error(dbName + " was null!");
|
||||
return;
|
||||
}
|
||||
Verify.nullCheck(database, NullPointerException::new);
|
||||
|
||||
if (!database.isOpen()) {
|
||||
return;
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
|
||||
|
@ -5,12 +5,12 @@ import com.djrapitops.plan.system.processing.importing.importers.Importer;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -31,9 +31,8 @@ public class ManageImportCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG) + " " + Arrays.toString(this.getArguments()), sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
|
||||
|
||||
String importArg = args[0];
|
||||
|
||||
|
@ -5,8 +5,6 @@ import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plan.utilities.ManageUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
@ -15,6 +13,8 @@ import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* This manage SubCommand is used to move all data from one database to another.
|
||||
* <p>
|
||||
@ -33,29 +33,24 @@ public class ManageMoveCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 2,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
|
||||
|
||||
String fromDB = args[0].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(fromDB) || "mysql".equals(fromDB);
|
||||
|
||||
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + fromDB, sender)) {
|
||||
return;
|
||||
}
|
||||
boolean isCorrectDB = Verify.equalsOne(fromDB, "sqlite", "mysql");
|
||||
Verify.isTrue(isCorrectDB,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + fromDB));
|
||||
|
||||
String toDB = args[1].toLowerCase();
|
||||
isCorrectDB = "sqlite".equals(toDB) || "mysql".equals(toDB);
|
||||
isCorrectDB = Verify.equalsOne(toDB, "sqlite", "mysql");
|
||||
Verify.isTrue(isCorrectDB,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + fromDB));
|
||||
|
||||
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + toDB, sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isFalse(fromDB.equalsIgnoreCase(toDB),
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString()));
|
||||
|
||||
if (!Condition.isTrue(!Verify.equalsIgnoreCase(fromDB, toDB), Locale.get(Msg.MANAGE_FAIL_SAME_DB).toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Condition.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(args[1])), sender)) {
|
||||
if (!Verify.contains("-a", args)) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_OVERWRITE).parse(args[0])));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -76,10 +71,14 @@ public class ManageMoveCommand extends CommandNode {
|
||||
try {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse());
|
||||
|
||||
ManageUtils.clearAndCopy(toDatabase, fromDatabase);
|
||||
fromDatabase.backup().backup(toDatabase);
|
||||
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_MOVE_SUCCESS).toString());
|
||||
boolean movedToCurrentDatabase = Verify.equalsIgnoreCase(toDatabase.getConfigName(), Database.getActive().getConfigName());
|
||||
Condition.isTrue(!movedToCurrentDatabase, Locale.get(Msg.MANAGE_INFO_CONFIG_REMINDER).toString(), sender);
|
||||
|
||||
boolean movingToCurrentDB = toDatabase.getConfigName().equalsIgnoreCase(Database.getActive().getConfigName());
|
||||
if (movingToCurrentDB) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_CONFIG_REMINDER).toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
|
||||
|
@ -5,7 +5,6 @@ import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
@ -35,9 +34,8 @@ public class ManageRemoveCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
|
||||
|
||||
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.MANAGE);
|
||||
|
||||
@ -50,20 +48,20 @@ public class ManageRemoveCommand extends CommandNode {
|
||||
public void run() {
|
||||
try {
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
String message = Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString();
|
||||
|
||||
if (!Condition.isTrue(Verify.notNull(uuid), message, sender)) {
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_VALID).toString());
|
||||
return;
|
||||
}
|
||||
|
||||
message = Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString();
|
||||
Database database = Database.getActive();
|
||||
if (!Condition.isTrue(database.check().isPlayerRegistered(uuid), message, sender)) {
|
||||
if (!database.check().isPlayerRegistered(uuid)) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString());
|
||||
return;
|
||||
}
|
||||
|
||||
message = Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(Database.getActive().getConfigName()));
|
||||
if (!Condition.isTrue(Verify.contains("-a", args), message, sender)) {
|
||||
if (!Verify.contains("-a", args)) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REMOVE).parse(database.getName())));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,6 @@ import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plan.utilities.ManageUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
@ -40,18 +38,16 @@ public class ManageRestoreCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 2, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments())), sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 2,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
|
||||
|
||||
String db = args[1].toLowerCase();
|
||||
boolean isCorrectDB = "sqlite".equals(db) || "mysql".equals(db);
|
||||
boolean isCorrectDB = Verify.equalsOne(db, "sqlite", "mysql");
|
||||
Verify.isTrue(isCorrectDB,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB).toString()));
|
||||
|
||||
if (!Condition.isTrue(isCorrectDB, Locale.get(Msg.MANAGE_FAIL_INCORRECT_DB) + db, sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Condition.isTrue(Verify.contains("-a", args), Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REWRITE).parse(args[1])), sender)) {
|
||||
if (!Verify.contains("-a", args)) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_CONFIRM).parse(Locale.get(Msg.MANAGE_NOTIFY_REWRITE).parse(args[1])));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -73,7 +69,9 @@ public class ManageRestoreCommand extends CommandNode {
|
||||
boolean containsDBFileExtension = backupDBName.endsWith(".db");
|
||||
|
||||
File backupDBFile = new File(plugin.getDataFolder(), backupDBName + (containsDBFileExtension ? "" : ".db"));
|
||||
if (!Condition.isTrue(Verify.exists(backupDBFile), Locale.get(Msg.MANAGE_FAIL_FILE_NOT_FOUND) + " " + args[0], sender)) {
|
||||
|
||||
if (!backupDBFile.exists()) {
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FILE_NOT_FOUND) + " " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -86,7 +84,7 @@ public class ManageRestoreCommand extends CommandNode {
|
||||
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse());
|
||||
|
||||
ManageUtils.clearAndCopy(database, backupDB);
|
||||
database.backup().restore(backupDB);
|
||||
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
|
||||
} catch (Exception e) {
|
||||
|
@ -8,11 +8,11 @@ import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
/**
|
||||
* This manage SubCommand is used to request settings from Bungee so that connection can be established.
|
||||
@ -31,9 +31,9 @@ public class ManageSetupCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString()));
|
||||
|
||||
if (!WebServerSystem.isWebServerEnabled()) {
|
||||
sender.sendMessage("§cWebServer is not enabled on this server! Make sure it enables on boot!");
|
||||
return;
|
||||
|
@ -5,14 +5,15 @@ import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import org.bukkit.ChatColor;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Subcommand for checking WebUser permission level.
|
||||
@ -30,9 +31,9 @@ public class WebCheckCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).parse() + " <username>", sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
|
||||
|
||||
Database database = Database.getActive();
|
||||
String user = args[0];
|
||||
|
||||
@ -40,7 +41,8 @@ public class WebCheckCommand extends CommandNode {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!Condition.isTrue(database.check().doesWebUserExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
|
||||
if (!database.check().doesWebUserExists(user)) {
|
||||
sender.sendMessage("§c[Plan] User Doesn't exist.");
|
||||
return;
|
||||
}
|
||||
WebUser info = database.fetch().getWebUser(user);
|
||||
|
@ -4,14 +4,15 @@ import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.Condition;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Subcommand for deleting a WebUser.
|
||||
@ -29,9 +30,9 @@ public class WebDeleteCommand extends CommandNode {
|
||||
|
||||
@Override
|
||||
public void onCommand(ISender sender, String commandLabel, String[] args) {
|
||||
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).parse() + " <username>", sender)) {
|
||||
return;
|
||||
}
|
||||
Verify.isTrue(args.length >= 1,
|
||||
() -> new IllegalArgumentException(Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(Arrays.toString(this.getArguments()))));
|
||||
|
||||
Database database = Database.getActive();
|
||||
String user = args[0];
|
||||
|
||||
@ -39,7 +40,8 @@ public class WebDeleteCommand extends CommandNode {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!Condition.isTrue(database.check().doesWebUserExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
|
||||
if (!database.check().doesWebUserExists(user)) {
|
||||
sender.sendMessage("§c[Plan] User Doesn't exist.");
|
||||
return;
|
||||
}
|
||||
database.remove().webUser(user);
|
||||
|
@ -16,8 +16,7 @@ public enum Actions {
|
||||
FIRST_SESSION(1),
|
||||
FIRST_LOGOUT(2),
|
||||
NEW_NICKNAME(3),
|
||||
KILLED(-2), // Not stored in ActionsTable.
|
||||
;
|
||||
KILLED(-2); // Not stored in ActionsTable.
|
||||
|
||||
private final int id;
|
||||
|
||||
|
@ -11,7 +11,6 @@ import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.comparators.ActionComparator;
|
||||
import com.djrapitops.plan.utilities.comparators.GeoInfoComparator;
|
||||
|
||||
@ -177,7 +176,7 @@ public class PlayerProfile {
|
||||
}
|
||||
|
||||
public long getTotalPlaytime() {
|
||||
return getPlaytime(-1, MiscUtils.getTime() + 1L);
|
||||
return getPlaytime(-1, System.currentTimeMillis() + 1L);
|
||||
}
|
||||
|
||||
public long getPlaytime(long after, long before) {
|
||||
@ -189,7 +188,7 @@ public class PlayerProfile {
|
||||
}
|
||||
|
||||
public long getLongestSession() {
|
||||
return getLongestSession(-1, MiscUtils.getTime() + 1L);
|
||||
return getLongestSession(-1, System.currentTimeMillis() + 1L);
|
||||
}
|
||||
|
||||
public long getLongestSession(int after, long before) {
|
||||
@ -201,7 +200,7 @@ public class PlayerProfile {
|
||||
}
|
||||
|
||||
public long getSessionMedian() {
|
||||
return getSessionMedian(-1, MiscUtils.getTime() + 1L);
|
||||
return getSessionMedian(-1, System.currentTimeMillis() + 1L);
|
||||
}
|
||||
|
||||
public long getSessionMedian(int after, long before) {
|
||||
@ -215,7 +214,7 @@ public class PlayerProfile {
|
||||
// Special Getters
|
||||
|
||||
public long getSessionAverage() {
|
||||
return getSessionAverage(-1, MiscUtils.getTime() + 1L);
|
||||
return getSessionAverage(-1, System.currentTimeMillis() + 1L);
|
||||
}
|
||||
|
||||
public long getSessionAverage(int after, long before) {
|
||||
@ -241,7 +240,7 @@ public class PlayerProfile {
|
||||
|
||||
public GeoInfo getMostRecentGeoInfo() {
|
||||
if (geoInformation.isEmpty()) {
|
||||
return new GeoInfo("-", "Not Known", MiscUtils.getTime(), "");
|
||||
return new GeoInfo("-", "Not Known", System.currentTimeMillis(), "");
|
||||
}
|
||||
geoInformation.sort(new GeoInfoComparator());
|
||||
return geoInformation.get(0);
|
||||
|
@ -93,7 +93,7 @@ public class AnalysisData extends RawData {
|
||||
}
|
||||
|
||||
public void analyze(ServerProfile profile) {
|
||||
long now = MiscUtils.getTime();
|
||||
long now = System.currentTimeMillis();
|
||||
refreshDate = now;
|
||||
long dayAgo = now - TimeAmount.DAY.ms();
|
||||
long weekAgo = now - TimeAmount.WEEK.ms();
|
||||
@ -225,14 +225,19 @@ public class AnalysisData extends RawData {
|
||||
long newW = value("newW");
|
||||
long newM = value("newM");
|
||||
|
||||
long fourDaysAgo = now - TimeAmount.DAY.ms() * 4L;
|
||||
long twoWeeksAgo = now - TimeAmount.WEEK.ms() * 2L;
|
||||
|
||||
List<PlayerProfile> playersStuckPerMonth = newMonth.stream()
|
||||
.filter(p -> p.playedBetween(monthAgo, twoWeeksAgo) && p.playedBetween(twoWeeksAgo, now))
|
||||
.filter(p -> {
|
||||
long backLimit = Math.max(monthAgo, p.getRegistered());
|
||||
long half = backLimit + ((now - backLimit) / 2L);
|
||||
return p.playedBetween(backLimit, half) && p.playedBetween(half, now);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
List<PlayerProfile> playersStuckPerWeek = newWeek.stream()
|
||||
.filter(p -> p.playedBetween(weekAgo, fourDaysAgo) && p.playedBetween(fourDaysAgo, now))
|
||||
.filter(p -> {
|
||||
long backLimit = Math.max(weekAgo, p.getRegistered());
|
||||
long half = backLimit + ((now - backLimit) / 2L);
|
||||
return p.playedBetween(backLimit, half) && p.playedBetween(half, now);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
int stuckPerM = playersStuckPerMonth.size();
|
||||
@ -240,32 +245,58 @@ public class AnalysisData extends RawData {
|
||||
got("stuckPerM", stuckPerM);
|
||||
got("stuckPerW", stuckPerW);
|
||||
|
||||
stickyMonthData = newMonth.stream().map(StickyData::new).distinct().collect(Collectors.toSet());
|
||||
|
||||
addValue("playersStuckMonth", stuckPerM);
|
||||
addValue("playersStuckWeek", stuckPerW);
|
||||
addValue("playersStuckPercMonth", newM != 0 ? FormatUtils.cutDecimals(MathUtils.averageDouble(stuckPerM, newM) * 100.0) + "%" : "-");
|
||||
addValue("playersStuckPercWeek", newW != 0 ? FormatUtils.cutDecimals(MathUtils.averageDouble(stuckPerW, newW) * 100.0) + "%" : "-");
|
||||
|
||||
stuckPerDay(newDay, newMonth, newD, playersStuckPerMonth, playersStuckPerWeek);
|
||||
stuckPerDay(newDay, newD, monthAgo);
|
||||
}
|
||||
|
||||
private void stuckPerDay(List<PlayerProfile> newDay, List<PlayerProfile> newMonth, long newD, List<PlayerProfile> playersStuckPerMonth, List<PlayerProfile> playersStuckPerWeek) {
|
||||
private void stuckPerDay(List<PlayerProfile> newDay, long newD, long monthAgo) {
|
||||
if (newD != 0) {
|
||||
// New Players
|
||||
stickyMonthData = newMonth.stream().map(StickyData::new).distinct().collect(Collectors.toSet());
|
||||
Set<StickyData> stickyW = playersStuckPerMonth.stream().map(StickyData::new).distinct().collect(Collectors.toSet());
|
||||
// New Players who stayed
|
||||
Set<StickyData> stickyStuckM = newMonth.stream().map(StickyData::new).distinct().collect(Collectors.toSet());
|
||||
Set<StickyData> stickyStuckW = playersStuckPerWeek.stream().map(StickyData::new).distinct().collect(Collectors.toSet());
|
||||
List<PlayerProfile> stuckAfterMonth = new ArrayList<>();
|
||||
List<PlayerProfile> notStuckAfterMonth = new ArrayList<>();
|
||||
|
||||
for (PlayerProfile player : players) {
|
||||
long registered = player.getRegistered();
|
||||
|
||||
// Discard uncertain data
|
||||
if (registered > monthAgo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
long monthAfterRegister = registered + TimeAmount.MONTH.ms();
|
||||
long half = registered + (TimeAmount.MONTH.ms() / 2L);
|
||||
if (player.playedBetween(registered, half) && player.playedBetween(half, monthAfterRegister)) {
|
||||
stuckAfterMonth.add(player);
|
||||
} else {
|
||||
notStuckAfterMonth.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (stuckAfterMonth.isEmpty() || notStuckAfterMonth.isEmpty()) {
|
||||
addValue("playersStuckDay", 0);
|
||||
addValue("playersStuckPercDay", "Not enough data");
|
||||
return;
|
||||
}
|
||||
|
||||
List<StickyData> stuck = stuckAfterMonth.stream().map(StickyData::new).collect(Collectors.toList());
|
||||
List<StickyData> nonStuck = notStuckAfterMonth.stream().map(StickyData::new).collect(Collectors.toList());
|
||||
|
||||
StickyData avgStuck = AnalysisUtils.average(stuck);
|
||||
StickyData avgNonStuck = AnalysisUtils.average(nonStuck);
|
||||
|
||||
int stuckPerD = 0;
|
||||
for (PlayerProfile playerProfile : newDay) {
|
||||
double probability = AnalysisUtils.calculateProbabilityOfStaying(
|
||||
stickyMonthData, stickyW, stickyStuckM, stickyStuckW, playerProfile
|
||||
);
|
||||
if (probability >= 0.5) {
|
||||
for (PlayerProfile player : newDay) {
|
||||
StickyData stickyData = new StickyData(player);
|
||||
if (stickyData.distance(avgStuck) < stickyData.distance(avgNonStuck)) {
|
||||
stuckPerD++;
|
||||
}
|
||||
}
|
||||
|
||||
addValue("playersStuckDay", stuckPerD);
|
||||
addValue("playersStuckPercDay", FormatUtils.cutDecimals(MathUtils.averageDouble(stuckPerD, newD) * 100.0) + "%");
|
||||
} else {
|
||||
|
@ -126,7 +126,7 @@ public class HealthNotes {
|
||||
}
|
||||
|
||||
private void newPlayerNote() {
|
||||
double avgOnlineOnRegister = MathUtils.averageInt(analysisData.getStickyMonthData().stream().map(StickyData::getOnlineOnJoin));
|
||||
double avgOnlineOnRegister = MathUtils.averageDouble(analysisData.getStickyMonthData().stream().map(StickyData::getOnlineOnJoin));
|
||||
if (avgOnlineOnRegister >= 1) {
|
||||
notes.add("<p>" + Html.GREEN_THUMB.parse() + " New Players have players to play with when they join ("
|
||||
+ FormatUtils.cutDecimals(avgOnlineOnRegister) + " on average)</p>");
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.djrapitops.plan.data.container;
|
||||
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -106,7 +105,7 @@ public class Session {
|
||||
*/
|
||||
public long getLength() {
|
||||
if (sessionEnd == -1) {
|
||||
return MiscUtils.getTime() - sessionStart;
|
||||
return System.currentTimeMillis() - sessionStart;
|
||||
}
|
||||
return sessionEnd - sessionStart;
|
||||
}
|
||||
@ -173,7 +172,7 @@ public class Session {
|
||||
* Used to get the ID of the session in the Database.
|
||||
*
|
||||
* @return ID if present.
|
||||
* @throws NullPointerException if Session was not fetched from DB. Condition using {@code isFetchedFromDB}
|
||||
* @throws NullPointerException if Session was not fetched from DB. Check {@code isFetchedFromDB} first.
|
||||
*/
|
||||
public int getSessionID() {
|
||||
return sessionID != null ? sessionID : -1;
|
||||
|
@ -13,22 +13,28 @@ import java.util.List;
|
||||
|
||||
public class StickyData {
|
||||
private final double activityIndex;
|
||||
private Integer messagesSent;
|
||||
private Integer onlineOnJoin;
|
||||
private Double messagesSent;
|
||||
private Double onlineOnJoin;
|
||||
|
||||
public StickyData(PlayerProfile player) {
|
||||
activityIndex = player.getActivityIndex(player.getRegistered() + TimeAmount.DAY.ms()).getValue();
|
||||
loadActionVariables(player.getActions());
|
||||
}
|
||||
|
||||
public StickyData(double activityIndex, Double messagesSent, Double onlineOnJoin) {
|
||||
this.activityIndex = activityIndex;
|
||||
this.messagesSent = messagesSent;
|
||||
this.onlineOnJoin = onlineOnJoin;
|
||||
}
|
||||
|
||||
private void loadActionVariables(List<Action> actions) {
|
||||
for (Action action : actions) {
|
||||
try {
|
||||
if (messagesSent == null && action.getDoneAction() == Actions.FIRST_LOGOUT) {
|
||||
messagesSent = loadSentMessages(action);
|
||||
messagesSent = (double) loadSentMessages(action);
|
||||
}
|
||||
if (onlineOnJoin == null && action.getDoneAction() == Actions.FIRST_SESSION) {
|
||||
onlineOnJoin = loadOnlineOnJoin(action);
|
||||
onlineOnJoin = (double) loadOnlineOnJoin(action);
|
||||
}
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
/* continue */
|
||||
@ -39,10 +45,10 @@ public class StickyData {
|
||||
|
||||
private void setDefaultValuesIfNull() {
|
||||
if (messagesSent == null) {
|
||||
messagesSent = 0;
|
||||
messagesSent = 0.0;
|
||||
}
|
||||
if (onlineOnJoin == null) {
|
||||
onlineOnJoin = 0;
|
||||
onlineOnJoin = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +94,15 @@ public class StickyData {
|
||||
return Objects.hashCode(activityIndex, messagesSent, onlineOnJoin);
|
||||
}
|
||||
|
||||
public int getOnlineOnJoin() {
|
||||
public double getOnlineOnJoin() {
|
||||
return onlineOnJoin;
|
||||
}
|
||||
|
||||
public double getActivityIndex() {
|
||||
return activityIndex;
|
||||
}
|
||||
|
||||
public Double getMessagesSent() {
|
||||
return messagesSent;
|
||||
}
|
||||
}
|
@ -30,13 +30,13 @@ import java.util.UUID;
|
||||
*/
|
||||
public final class AnalysisContainer extends InspectContainer {
|
||||
|
||||
private TreeMap<String, Map<UUID, ? extends Serializable>> playerTableValues;
|
||||
private Map<String, Map<UUID, ? extends Serializable>> playerTableValues;
|
||||
|
||||
public AnalysisContainer() {
|
||||
playerTableValues = new TreeMap<>();
|
||||
}
|
||||
|
||||
public TreeMap<String, Map<UUID, ? extends Serializable>> getPlayerTableValues() {
|
||||
public Map<String, Map<UUID, ? extends Serializable>> getPlayerTableValues() {
|
||||
return playerTableValues;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ import java.util.List;
|
||||
*/
|
||||
public class TableContainer {
|
||||
|
||||
private final String[] header;
|
||||
protected final String[] header;
|
||||
private List<Serializable[]> values;
|
||||
|
||||
private boolean jqueryDatatable;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.djrapitops.plan.data.time;
|
||||
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -28,7 +26,7 @@ public class WorldTimes {
|
||||
worldTimes = new HashMap<>();
|
||||
currentWorld = startingWorld;
|
||||
currentGamemode = startingGM;
|
||||
addWorld(startingWorld, startingGM, MiscUtils.getTime());
|
||||
addWorld(startingWorld, startingGM, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,8 +30,7 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
public class BukkitSystem extends PlanSystem implements ServerSystem {
|
||||
|
||||
public BukkitSystem(Plan plugin) {
|
||||
|
||||
testSystem = this;
|
||||
setTestSystem(this);
|
||||
|
||||
Log.setErrorManager(new PlanErrorManager());
|
||||
|
||||
|
@ -29,7 +29,7 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
public class BungeeSystem extends PlanSystem {
|
||||
|
||||
public BungeeSystem(PlanBungee plugin) {
|
||||
testSystem = this;
|
||||
setTestSystem(this);
|
||||
|
||||
Log.setErrorManager(new PlanErrorManager());
|
||||
|
||||
|
@ -196,4 +196,8 @@ public abstract class PlanSystem implements SubSystem {
|
||||
public Processing getProcessing() {
|
||||
return processing;
|
||||
}
|
||||
|
||||
static void setTestSystem(PlanSystem testSystem) {
|
||||
PlanSystem.testSystem = testSystem;
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ public class SpongeSystem extends PlanSystem implements ServerSystem {
|
||||
private boolean firstInstall = false;
|
||||
|
||||
public SpongeSystem(PlanSponge plugin) {
|
||||
testSystem = this;
|
||||
setTestSystem(this);
|
||||
|
||||
Log.setErrorManager(new PlanErrorManager());
|
||||
|
||||
|
@ -6,7 +6,6 @@ import com.djrapitops.plan.system.file.FileSystem;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.maxmind.geoip2.DatabaseReader;
|
||||
import com.maxmind.geoip2.exception.GeoIp2Exception;
|
||||
import com.maxmind.geoip2.model.CountryResponse;
|
||||
@ -28,8 +27,6 @@ import java.util.zip.GZIPInputStream;
|
||||
* This class contains the geolocation cache.
|
||||
* <p>
|
||||
* It caches all IPs with their matching country.
|
||||
* <p>
|
||||
* This cache uses the Google Guava {@link Cache}.
|
||||
*
|
||||
* @author Fuzzlemann
|
||||
* @since 3.5.5
|
||||
|
@ -4,7 +4,6 @@ import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
@ -30,7 +29,7 @@ public class SessionCache {
|
||||
}
|
||||
|
||||
public static SessionCache getInstance() {
|
||||
DataCache dataCache = CacheSystem.getInstance().getDataCache();
|
||||
SessionCache dataCache = CacheSystem.getInstance().getDataCache();
|
||||
Verify.nullCheck(dataCache, () -> new IllegalStateException("Data Cache was not initialized."));
|
||||
return dataCache;
|
||||
}
|
||||
@ -71,7 +70,7 @@ public class SessionCache {
|
||||
|
||||
public static void refreshActiveSessionsState() {
|
||||
for (Session session : activeSessions.values()) {
|
||||
session.getWorldTimes().updateState(MiscUtils.getTime());
|
||||
session.getWorldTimes().updateState(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +98,7 @@ public class SessionCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition if a session is player's first session on the server.
|
||||
* Check if a session is player's first session on the server.
|
||||
*
|
||||
* @param uuid UUID of the player
|
||||
* @return true / false
|
||||
|
@ -3,10 +3,12 @@ package com.djrapitops.plan.system.database.databases.operation;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface BackupOperations {
|
||||
|
||||
void backup(Database toDatabase) throws DBException;
|
||||
void backup(Database toDatabase) throws SQLException;
|
||||
|
||||
void restore(Database fromDatabase) throws DBException;
|
||||
void restore(Database fromDatabase) throws DBException, SQLException;
|
||||
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class MySQLDB extends SQLDB {
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
if (dataSource != null && dataSource instanceof BasicDataSource) {
|
||||
if (dataSource instanceof BasicDataSource) {
|
||||
((BasicDataSource) dataSource).close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
@ -139,7 +139,7 @@ public abstract class SQLDB extends Database {
|
||||
|
||||
if (newDatabase) {
|
||||
Log.info("New Database created.");
|
||||
versionTable.setVersion(17);
|
||||
versionTable.setVersion(18);
|
||||
}
|
||||
|
||||
int version = versionTable.getVersion();
|
||||
@ -187,6 +187,10 @@ public abstract class SQLDB extends Database {
|
||||
geoInfoTable.alterTableV17();
|
||||
versionTable.setVersion(17);
|
||||
}
|
||||
if (version < 18) {
|
||||
geoInfoTable.alterTableV18();
|
||||
// version set in the runnable in above method
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DBInitException("Failed to set-up Database", e);
|
||||
}
|
||||
@ -256,6 +260,7 @@ public abstract class SQLDB extends Database {
|
||||
private void clean() throws SQLException {
|
||||
tpsTable.clean();
|
||||
transferTable.clean();
|
||||
geoInfoTable.clean();
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long keepActiveAfter = now - TimeAmount.DAY.ms() * Settings.KEEP_INACTIVE_PLAYERS_DAYS.getNumber();
|
||||
@ -271,7 +276,10 @@ public abstract class SQLDB extends Database {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
Log.info("Removed data of " + inactivePlayers.size() + " players.");
|
||||
int removed = inactivePlayers.size();
|
||||
if (removed > 0) {
|
||||
Log.info("Removed data of " + removed + " players.");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Connection getConnection() throws SQLException;
|
||||
@ -373,7 +381,7 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
|
||||
public boolean isUsingMySQL() {
|
||||
return this instanceof MySQLDB;
|
||||
return usingMySQL;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,6 +6,7 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.service.sql.SqlService;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -44,4 +45,21 @@ public class SpongeMySQLDB extends MySQLDB {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
try {
|
||||
return super.getConnection();
|
||||
} catch (SQLException e) {
|
||||
if (e.getMessage().contains("has been closed")) {
|
||||
try {
|
||||
setupDataSource();
|
||||
} catch (DBInitException setupException) {
|
||||
throw new IllegalStateException("Failed to set up a new datasource after connection failure.", setupException);
|
||||
}
|
||||
return super.getConnection();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,9 @@ package com.djrapitops.plan.system.database.databases.sql.operation;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.database.databases.operation.BackupOperations;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.move.BatchOperationTable;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class SQLBackupOps extends SQLOps implements BackupOperations {
|
||||
|
||||
@ -11,12 +14,16 @@ public class SQLBackupOps extends SQLOps implements BackupOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backup(Database toDatabase) {
|
||||
// TODO
|
||||
public void backup(Database toDatabase) throws SQLException {
|
||||
BatchOperationTable toDB = new BatchOperationTable((SQLDB) toDatabase);
|
||||
BatchOperationTable fromDB = new BatchOperationTable(db);
|
||||
|
||||
toDB.removeAllData();
|
||||
fromDB.copyEverything(toDB);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore(Database fromDatabase) {
|
||||
// TODO
|
||||
public void restore(Database fromDatabase) throws SQLException {
|
||||
fromDatabase.backup().backup(db);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import com.djrapitops.plan.data.container.*;
|
||||
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.sql.SQLException;
|
||||
@ -32,7 +31,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
profile.setAllTimePeak(peak.getDate());
|
||||
profile.setAllTimePeakPlayers(peak.getPlayers());
|
||||
});
|
||||
Optional<TPS> lastPeak = tpsTable.getPeakPlayerCount(serverUUID, MiscUtils.getTime() - (TimeAmount.DAY.ms() * 2L));
|
||||
Optional<TPS> lastPeak = tpsTable.getPeakPlayerCount(serverUUID, System.currentTimeMillis() - (TimeAmount.DAY.ms() * 2L));
|
||||
lastPeak.ifPresent(peak -> {
|
||||
profile.setLastPeakDate(peak.getDate());
|
||||
profile.setLastPeakPlayers(peak.getPlayers());
|
||||
|
@ -10,7 +10,9 @@ import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Select;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.move.Version18TransferTable;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.comparators.GeoInfoComparator;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
@ -74,8 +76,10 @@ public class GeoInfoTable extends UserIDTable {
|
||||
|
||||
public void alterTableV17() {
|
||||
addColumns(Col.IP_HASH.get() + " varchar(200) DEFAULT ''");
|
||||
}
|
||||
|
||||
RunnableFactory.createNew("DB Version 16->17", new AbsRunnable() {
|
||||
public void alterTableV18() {
|
||||
RunnableFactory.createNew("DB Version 17->18", new AbsRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -91,6 +95,9 @@ public class GeoInfoTable extends UserIDTable {
|
||||
for (List<GeoInfo> geoInfos : allGeoInfo.values()) {
|
||||
for (GeoInfo geoInfo : geoInfos) {
|
||||
try {
|
||||
if (geoInfo.getIp().endsWith(".xx.xx")) {
|
||||
continue;
|
||||
}
|
||||
GeoInfo updatedInfo = new GeoInfo(
|
||||
geoInfo.getIp(),
|
||||
geoInfo.getGeolocation(),
|
||||
@ -99,6 +106,7 @@ public class GeoInfoTable extends UserIDTable {
|
||||
statement.setString(1, updatedInfo.getIp());
|
||||
statement.setString(2, updatedInfo.getIpHash());
|
||||
statement.setString(3, geoInfo.getIp());
|
||||
statement.addBatch();
|
||||
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
|
||||
if (Settings.DEV_MODE.isTrue()) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
@ -108,11 +116,17 @@ public class GeoInfoTable extends UserIDTable {
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
new Version18TransferTable(db).alterTableV18();
|
||||
db.setVersion(18);
|
||||
} catch (SQLException | DBInitException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
|
||||
}
|
||||
|
||||
public List<GeoInfo> getGeoInfo(UUID uuid) throws SQLException {
|
||||
@ -162,8 +176,9 @@ public class GeoInfoTable extends UserIDTable {
|
||||
List<GeoInfo> geoInfo = getGeoInfo(uuid);
|
||||
if (geoInfo.contains(info)) {
|
||||
updateGeoInfo(uuid, info);
|
||||
} else {
|
||||
insertGeoInfo(uuid, info);
|
||||
}
|
||||
insertGeoInfo(uuid, info);
|
||||
}
|
||||
|
||||
private void insertGeoInfo(UUID uuid, GeoInfo info) throws SQLException {
|
||||
@ -235,27 +250,18 @@ public class GeoInfoTable extends UserIDTable {
|
||||
}
|
||||
|
||||
public List<String> getNetworkGeolocations() throws SQLException {
|
||||
String subQuery = "SELECT " +
|
||||
Col.USER_ID + ", " +
|
||||
"MAX(" + Col.LAST_USED + ") as max" +
|
||||
" FROM " + tableName +
|
||||
" GROUP BY " + Col.USER_ID;
|
||||
String sql = "SELECT " +
|
||||
"f." + Col.GEOLOCATION +
|
||||
" FROM (" + subQuery + ") as x" +
|
||||
" INNER JOIN " + tableName + " AS f ON f." + Col.USER_ID + "=x." + Col.USER_ID +
|
||||
" AND f." + Col.LAST_USED + "=x.max";
|
||||
List<String> geolocations = new ArrayList<>();
|
||||
|
||||
return query(new QueryAllStatement<List<String>>(sql) {
|
||||
@Override
|
||||
public List<String> processResults(ResultSet set) throws SQLException {
|
||||
List<String> geolocations = new ArrayList<>();
|
||||
while (set.next()) {
|
||||
geolocations.add(set.getString(Col.GEOLOCATION.get()));
|
||||
}
|
||||
return geolocations;
|
||||
Map<UUID, List<GeoInfo>> geoInfo = getAllGeoInfo();
|
||||
for (List<GeoInfo> userGeoInfos : geoInfo.values()) {
|
||||
if (userGeoInfos.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
});
|
||||
userGeoInfos.sort(new GeoInfoComparator());
|
||||
geolocations.add(userGeoInfos.get(0).getGeolocation());
|
||||
}
|
||||
|
||||
return geolocations;
|
||||
}
|
||||
|
||||
public void insertAllGeoInfo(Map<UUID, List<GeoInfo>> allIPsAndGeolocations) throws SQLException {
|
||||
|
@ -11,7 +11,6 @@ import com.djrapitops.plan.system.database.databases.sql.statements.Select;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
@ -619,7 +618,7 @@ public class SessionsTable extends UserIDTable {
|
||||
return query(new QueryStatement<Map<UUID, Map<UUID, List<Session>>>>(sql, 20000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, MiscUtils.getTime() - TimeAmount.MONTH.ms());
|
||||
statement.setLong(1, System.currentTimeMillis() - TimeAmount.MONTH.ms());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -722,19 +721,32 @@ public class SessionsTable extends UserIDTable {
|
||||
* @param savedSessions Sessions of Player in a Server in the db.
|
||||
*/
|
||||
private void matchSessions(List<Session> sessions, List<Session> savedSessions) {
|
||||
Map<Long, Session> sessionsByStart = sessions.stream().collect(Collectors.toMap(Session::getSessionStart, Function.identity()));
|
||||
Map<Long, Session> savedSessionsByStart = savedSessions.stream().collect(Collectors.toMap(Session::getSessionStart, Function.identity()));
|
||||
for (Map.Entry<Long, Session> sessionEntry : sessionsByStart.entrySet()) {
|
||||
Map<Long, List<Session>> sessionsByStart = turnToMapByStart(sessions);
|
||||
Map<Long, List<Session>> savedSessionsByStart = turnToMapByStart(savedSessions);
|
||||
|
||||
for (Map.Entry<Long, List<Session>> sessionEntry : sessionsByStart.entrySet()) {
|
||||
long start = sessionEntry.getKey();
|
||||
Session savedSession = savedSessionsByStart.get(start);
|
||||
if (savedSession == null) {
|
||||
if (!savedSessionsByStart.containsKey(start)) {
|
||||
throw new IllegalStateException("Some of the sessions being matched were not saved.");
|
||||
}
|
||||
Session session = sessionEntry.getValue();
|
||||
session.setSessionID(savedSession.getSessionID());
|
||||
Session savedSession = savedSessionsByStart.get(start).get(0);
|
||||
sessionEntry.getValue().forEach(
|
||||
session -> session.setSessionID(savedSession.getSessionID())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Long, List<Session>> turnToMapByStart(List<Session> sessions) {
|
||||
Map<Long, List<Session>> sessionsByStart = new HashMap<>();
|
||||
for (Session session : sessions) {
|
||||
long start = session.getSessionStart();
|
||||
List<Session> sorted = sessionsByStart.getOrDefault(start, new ArrayList<>());
|
||||
sorted.add(session);
|
||||
sessionsByStart.put(start, sorted);
|
||||
}
|
||||
return sessionsByStart;
|
||||
}
|
||||
|
||||
public void alterTableV15() {
|
||||
addColumns(Col.AFK_TIME + " bigint NOT NULL DEFAULT 0");
|
||||
}
|
||||
@ -748,7 +760,7 @@ public class SessionsTable extends UserIDTable {
|
||||
return query(new QueryAllStatement<Map<Integer, Integer>>(sql, 10000) {
|
||||
@Override
|
||||
public Map<Integer, Integer> processResults(ResultSet set) throws SQLException {
|
||||
HashMap<Integer, Integer> idServerIdMap = new HashMap<>();
|
||||
Map<Integer, Integer> idServerIdMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
idServerIdMap.put(set.getInt(Col.ID.get()), set.getInt(Col.SERVER_ID.get()));
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
@ -133,7 +132,7 @@ public class TPSTable extends Table {
|
||||
statement.setInt(1, pValue);
|
||||
// More than 2 Months ago.
|
||||
long fiveWeeks = TimeAmount.MONTH.ms() * 2L;
|
||||
statement.setLong(2, MiscUtils.getTime() - fiveWeeks);
|
||||
statement.setLong(2, System.currentTimeMillis() - fiveWeeks);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -84,7 +83,7 @@ public class TransferTable extends Table {
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, MiscUtils.getTime());
|
||||
statement.setLong(1, System.currentTimeMillis());
|
||||
statement.setString(2, "onlineStatus");
|
||||
}
|
||||
});
|
||||
@ -133,7 +132,7 @@ public class TransferTable extends Table {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, ServerInfo.getServerUUID().toString());
|
||||
statement.setLong(2, MiscUtils.getTime() + TimeAmount.HOUR.ms());
|
||||
statement.setLong(2, System.currentTimeMillis() + TimeAmount.HOUR.ms());
|
||||
statement.setString(3, "configSettings");
|
||||
statement.setString(4, null);
|
||||
statement.setString(5, encodedSettingString);
|
||||
@ -146,7 +145,7 @@ public class TransferTable extends Table {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, "configSettings");
|
||||
statement.setLong(2, MiscUtils.getTime());
|
||||
statement.setLong(2, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,16 +170,21 @@ public class UserInfoTable extends UserIDTable {
|
||||
}
|
||||
|
||||
public List<UserInfo> getServerUserInfo(UUID serverUUID) throws SQLException {
|
||||
Optional<Integer> serverID = serverTable.getServerID(serverUUID);
|
||||
if (!serverID.isPresent()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Map<UUID, String> playerNames = usersTable.getPlayerNames();
|
||||
Map<Integer, UUID> uuidsByID = usersTable.getUUIDsByID();
|
||||
|
||||
String sql = "SELECT * FROM " + tableName +
|
||||
" WHERE " + Col.SERVER_ID + "=" + serverTable.statementSelectServerID;
|
||||
" WHERE " + Col.SERVER_ID + "=?";
|
||||
|
||||
return query(new QueryStatement<List<UserInfo>>(sql, 20000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
statement.setInt(1, serverID.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -361,8 +366,34 @@ public class UserInfoTable extends UserIDTable {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO improve performance of this method.
|
||||
public Set<UUID> getSavedUUIDs(UUID serverUUID) throws SQLException {
|
||||
return getSavedUUIDs().get(serverUUID);
|
||||
String usersIDColumn = usersTable + "." + UsersTable.Col.ID;
|
||||
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID + " as uuid";
|
||||
String serverIDColumn = serverTable + "." + ServerTable.Col.SERVER_ID;
|
||||
String serverUUIDColumn = serverTable + "." + ServerTable.Col.SERVER_UUID + " as s_uuid";
|
||||
String sql = "SELECT " +
|
||||
usersUUIDColumn + ", " +
|
||||
serverUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" INNER JOIN " + usersTable + " on " + usersIDColumn + "=" + Col.USER_ID +
|
||||
" INNER JOIN " + serverTable + " on " + serverIDColumn + "=" + Col.SERVER_ID +
|
||||
" WHERE s_uuid=?";
|
||||
|
||||
return query(new QueryStatement<Set<UUID>>(sql, 50000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> processResults(ResultSet set) throws SQLException {
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
uuids.add(uuid);
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -310,7 +310,7 @@ public class WorldTable extends Table {
|
||||
return query(new QueryAllStatement<Map<Integer, List<Integer>>>(sql, 100) {
|
||||
@Override
|
||||
public Map<Integer, List<Integer>> processResults(ResultSet set) throws SQLException {
|
||||
HashMap<Integer, List<Integer>> map = new HashMap<>();
|
||||
Map<Integer, List<Integer>> map = new HashMap<>();
|
||||
while (set.next()) {
|
||||
|
||||
int serverID = set.getInt(Col.SERVER_ID.get());
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.djrapitops.plan.system.database.databases.sql.tables.move;
|
||||
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.Table;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Abstract table used for transferring a whole table to a new table.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TransferTable extends Table {
|
||||
|
||||
public TransferTable(SQLDB db) {
|
||||
super("", db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTable() {
|
||||
throw new IllegalStateException("Method not supposed to be used on this table.");
|
||||
}
|
||||
|
||||
protected void renameTable(String from, String to) throws SQLException {
|
||||
String sql = usingMySQL ?
|
||||
"RENAME TABLE " + from + " TO " + to :
|
||||
"ALTER TABLE " + from + " RENAME TO " + to;
|
||||
execute(sql);
|
||||
}
|
||||
|
||||
protected void dropTable(String name) throws SQLException {
|
||||
String sql = "DROP TABLE " + name;
|
||||
execute(sql);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.djrapitops.plan.system.database.databases.sql.tables.move;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* DB Schema v17 -> 18 table.
|
||||
* <p>
|
||||
* Required due to a bug where duplicate rows were inserted.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class Version18TransferTable extends TransferTable {
|
||||
|
||||
public Version18TransferTable(SQLDB db) throws SQLException {
|
||||
super(db);
|
||||
}
|
||||
|
||||
public void alterTableV18() throws SQLException, DBInitException {
|
||||
String tempTableName = "plan_ips_temp";
|
||||
String ipTableName = "plan_ips";
|
||||
try {
|
||||
renameTable(ipTableName, tempTableName);
|
||||
} catch (SQLException e) {
|
||||
// Temp table already exists
|
||||
if (!e.getMessage().contains("plan_ips_temp")) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
db.getGeoInfoTable().createTable();
|
||||
execute("INSERT INTO plan_ips (" +
|
||||
"user_id, ip, ip_hash, geolocation, last_used" +
|
||||
") SELECT user_id, ip, ip_hash, geolocation, MAX(last_used) FROM plan_ips_temp GROUP BY ip_hash, user_id");
|
||||
dropTable(tempTableName);
|
||||
}
|
||||
}
|
@ -20,12 +20,12 @@ import java.util.Optional;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class Version8TransferTable extends Table {
|
||||
public class Version8TransferTable extends TransferTable {
|
||||
|
||||
private final int serverID;
|
||||
|
||||
public Version8TransferTable(SQLDB db) throws SQLException {
|
||||
super("", db);
|
||||
super(db);
|
||||
Optional<Integer> serverID = db.getServerTable().getServerID(ServerInfo.getServerUUID());
|
||||
if (!serverID.isPresent()) {
|
||||
throw new IllegalStateException("Server UUID was not registered, try rebooting the plugin.");
|
||||
@ -33,23 +33,6 @@ public class Version8TransferTable extends Table {
|
||||
this.serverID = serverID.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTable() {
|
||||
throw new IllegalStateException("Method not supposed to be used on this table.");
|
||||
}
|
||||
|
||||
private void renameTable(String from, String to) throws SQLException {
|
||||
String sql = usingMySQL ?
|
||||
"RENAME TABLE " + from + " TO " + to :
|
||||
"ALTER TABLE " + from + " RENAME TO " + to;
|
||||
execute(sql);
|
||||
}
|
||||
|
||||
private void dropTable(String name) throws SQLException {
|
||||
String sql = "DROP TABLE " + name;
|
||||
execute(sql);
|
||||
}
|
||||
|
||||
public void alterTablesToV10() throws SQLException, DBInitException {
|
||||
Benchmark.start("Schema copy from 8 to 10");
|
||||
copyCommandUsage();
|
||||
|
@ -62,11 +62,12 @@ public class FileSystem implements SubSystem {
|
||||
|
||||
@Override
|
||||
public void enable() throws EnableException {
|
||||
dataFolder.mkdirs();
|
||||
Verify.isTrue((dataFolder.exists() && dataFolder.isDirectory()) || dataFolder.mkdirs(),
|
||||
() -> new EnableException("Could not create data folder at " + dataFolder.getAbsolutePath()));
|
||||
try {
|
||||
if (configFile.exists()) {
|
||||
configFile.createNewFile();
|
||||
}
|
||||
Verify.isTrue((configFile.exists() && configFile.isFile()) || configFile.createNewFile(),
|
||||
() -> new EnableException("Could not create config file at " + configFile.getAbsolutePath()));
|
||||
|
||||
RunnableFactory.createNew(new LogsFolderCleanTask(Log.getLogsFolder()))
|
||||
.runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 30L);
|
||||
} catch (IOException e) {
|
||||
|
@ -10,7 +10,6 @@ import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.request.*;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
@ -32,10 +31,10 @@ public class BungeeConnectionSystem extends ConnectionSystem {
|
||||
}
|
||||
|
||||
private void refreshServerMap() {
|
||||
if (latestServerMapRefresh < MiscUtils.getTime() - TimeAmount.SECOND.ms() * 15L) {
|
||||
if (latestServerMapRefresh < System.currentTimeMillis() - TimeAmount.SECOND.ms() * 15L) {
|
||||
try {
|
||||
bukkitServers = Database.getActive().fetch().getBukkitServers();
|
||||
latestServerMapRefresh = MiscUtils.getTime();
|
||||
latestServerMapRefresh = System.currentTimeMillis();
|
||||
} catch (DBException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ package com.djrapitops.plan.system.info.connection;
|
||||
|
||||
import com.djrapitops.plan.system.info.request.InfoRequest;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -49,7 +48,7 @@ public class ConnectionLog {
|
||||
private static void logConnection(String address, String infoRequestName, int responseCode) {
|
||||
Map<String, Map<String, Entry>> log = getInstance().log;
|
||||
Map<String, Entry> requestMap = log.getOrDefault(address, new HashMap<>());
|
||||
requestMap.put(infoRequestName, new Entry(responseCode, MiscUtils.getTime()));
|
||||
requestMap.put(infoRequestName, new Entry(responseCode, System.currentTimeMillis()));
|
||||
log.put(address, requestMap);
|
||||
}
|
||||
|
||||
@ -87,7 +86,7 @@ public class ConnectionLog {
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(Entry o) {
|
||||
return -Long.compare(this.timeSent, o.timeSent);
|
||||
return Long.compare(o.timeSent, this.timeSent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ public class ConnectionOut {
|
||||
}
|
||||
|
||||
private SSLSocketFactory getRelaxedSocketFactory() throws NoSuchAlgorithmException, KeyManagementException {
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
SSLContext sc = SSLContext.getInstance("TLSv1.2");
|
||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
return sc.getSocketFactory();
|
||||
}
|
||||
|
@ -4,7 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.system.info.connection;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
import com.djrapitops.plan.api.exceptions.connection.NotFoundException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.info.request.InfoRequest;
|
||||
import com.djrapitops.plan.system.webserver.Request;
|
||||
import com.djrapitops.plan.system.webserver.pages.PageHandler;
|
||||
@ -54,22 +55,6 @@ public class InfoRequestPageHandler extends PageHandler {
|
||||
}
|
||||
|
||||
private int getResponseCodeFor(WebException e) {
|
||||
if (e instanceof BadRequestException) {
|
||||
return 400;
|
||||
} else if (e instanceof ForbiddenException) {
|
||||
return 403;
|
||||
} else if (e instanceof NotFoundException) {
|
||||
return 404;
|
||||
} else if (e instanceof UnauthorizedServerException) {
|
||||
return 412;
|
||||
} else if (e instanceof InternalErrorException) {
|
||||
return 500;
|
||||
} else if (e instanceof GatewayException) {
|
||||
return 504;
|
||||
} else if (e instanceof ConnectionFailException) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return e.getResponseCode().getCode();
|
||||
}
|
||||
}
|
@ -16,7 +16,6 @@ import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
@ -40,13 +39,13 @@ public class ServerConnectionSystem extends ConnectionSystem {
|
||||
|
||||
private void refreshServerMap() {
|
||||
Processing.submitNonCritical(() -> {
|
||||
if (latestServerMapRefresh < MiscUtils.getTime() - TimeAmount.SECOND.ms() * 15L) {
|
||||
if (latestServerMapRefresh < System.currentTimeMillis() - TimeAmount.SECOND.ms() * 15L) {
|
||||
try {
|
||||
Database database = Database.getActive();
|
||||
Optional<Server> bungeeInformation = database.fetch().getBungeeInformation();
|
||||
bungeeInformation.ifPresent(server -> mainServer = server);
|
||||
bukkitServers = database.fetch().getBukkitServers();
|
||||
latestServerMapRefresh = MiscUtils.getTime();
|
||||
latestServerMapRefresh = System.currentTimeMillis();
|
||||
} catch (DBException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
package com.djrapitops.plan.system.info.connection;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
import com.djrapitops.plan.utilities.java.ThrowingVoidFunction;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -19,9 +20,9 @@ import java.util.Map;
|
||||
*/
|
||||
public class WebExceptionLogger {
|
||||
|
||||
public static void logIfOccurs(Class c, ExceptionLoggingAction action) {
|
||||
public static void logIfOccurs(Class c, ThrowingVoidFunction<WebException> function) {
|
||||
try {
|
||||
action.performAction();
|
||||
function.apply();
|
||||
} catch (ConnectionFailException e) {
|
||||
if (shouldLog(e)) {
|
||||
Log.warn(e.getMessage());
|
||||
@ -62,10 +63,4 @@ public class WebExceptionLogger {
|
||||
return null;
|
||||
}
|
||||
|
||||
public interface ExceptionLoggingAction {
|
||||
|
||||
void performAction() throws WebException;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ import org.bukkit.Server;
|
||||
import org.spongepowered.api.Game;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Class responsible for holding server variable values that do not change
|
||||
@ -21,10 +22,10 @@ public class ServerProperties {
|
||||
private final int port;
|
||||
private final String version;
|
||||
private final String implVersion;
|
||||
private final IPWrapper ip;
|
||||
private final Supplier<String> ip;
|
||||
private final int maxPlayers;
|
||||
|
||||
private final OnlinePlayersWrapper onlinePlayers;
|
||||
private final Supplier<Integer> onlinePlayers;
|
||||
|
||||
public ServerProperties(Server server) {
|
||||
id = server.getServerId();
|
||||
@ -76,7 +77,7 @@ public class ServerProperties {
|
||||
* @return the ip.
|
||||
*/
|
||||
public String getIp() {
|
||||
return ip.getIP();
|
||||
return ip.get();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -104,14 +105,6 @@ public class ServerProperties {
|
||||
}
|
||||
|
||||
public int getOnlinePlayers() {
|
||||
return onlinePlayers.getOnlinePlayers();
|
||||
}
|
||||
|
||||
private interface OnlinePlayersWrapper {
|
||||
int getOnlinePlayers();
|
||||
}
|
||||
|
||||
private interface IPWrapper {
|
||||
String getIP();
|
||||
return onlinePlayers.get();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.djrapitops.plan.system.listeners.bukkit;
|
||||
|
||||
import com.djrapitops.plan.system.afk.AFKTracker;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -29,7 +28,7 @@ public class AFKListener implements Listener {
|
||||
private void event(PlayerEvent event) {
|
||||
try {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
AFK_TRACKER.performedAction(uuid, time);
|
||||
} catch (Exception e) {
|
||||
|
@ -4,7 +4,6 @@ import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.processing.processors.player.KillProcessor;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Format;
|
||||
import org.bukkit.Material;
|
||||
@ -32,7 +31,7 @@ public class DeathEventListener implements Listener {
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onDeath(EntityDeathEvent event) {
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
LivingEntity dead = event.getEntity();
|
||||
|
||||
if (dead instanceof Player) {
|
||||
@ -59,10 +58,10 @@ public class DeathEventListener implements Listener {
|
||||
KillProcessor processor = null;
|
||||
if (killerEntity instanceof Player) {
|
||||
processor = handlePlayerKill(time, dead, (Player) killerEntity);
|
||||
} else if (killerEntity instanceof Wolf) {
|
||||
processor = handleWolfKill(time, dead, (Wolf) killerEntity);
|
||||
} else if (killerEntity instanceof Arrow) {
|
||||
processor = handleArrowKill(time, dead, (Arrow) killerEntity);
|
||||
} else if (killerEntity instanceof Tameable) {
|
||||
processor = handlePetKill(time, dead, (Tameable) killerEntity);
|
||||
} else if (killerEntity instanceof Projectile) {
|
||||
processor = handleProjectileKill(time, dead, (Projectile) killerEntity);
|
||||
}
|
||||
if (processor != null) {
|
||||
Processing.submit(processor);
|
||||
@ -84,28 +83,32 @@ public class DeathEventListener implements Listener {
|
||||
return new KillProcessor(killer.getUniqueId(), time, dead, normalizeMaterialName(itemInHand));
|
||||
}
|
||||
|
||||
private KillProcessor handleWolfKill(long time, LivingEntity dead, Wolf wolf) {
|
||||
if (!wolf.isTamed()) {
|
||||
private KillProcessor handlePetKill(long time, LivingEntity dead, Tameable tameable) {
|
||||
if (!tameable.isTamed()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AnimalTamer owner = wolf.getOwner();
|
||||
AnimalTamer owner = tameable.getOwner();
|
||||
if (!(owner instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new KillProcessor(owner.getUniqueId(), time, dead, "Wolf");
|
||||
return new KillProcessor(owner.getUniqueId(), time, dead,
|
||||
new Format(tameable.getType().name()).capitalize().toString()
|
||||
);
|
||||
}
|
||||
|
||||
private KillProcessor handleArrowKill(long time, LivingEntity dead, Arrow arrow) {
|
||||
ProjectileSource source = arrow.getShooter();
|
||||
private KillProcessor handleProjectileKill(long time, LivingEntity dead, Projectile projectile) {
|
||||
ProjectileSource source = projectile.getShooter();
|
||||
if (!(source instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Player player = (Player) source;
|
||||
|
||||
return new KillProcessor(player.getUniqueId(), time, dead, "Bow");
|
||||
return new KillProcessor(player.getUniqueId(), time, dead,
|
||||
new Format(projectile.getType().name()).capitalize().toString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,6 @@ package com.djrapitops.plan.system.listeners.bukkit;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -41,7 +40,7 @@ public class GamemodeChangeListener implements Listener {
|
||||
private void actOnEvent(PlayerGameModeChangeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
String gameMode = event.getNewGameMode().name();
|
||||
String worldName = player.getWorld().getName();
|
||||
|
||||
|
@ -7,7 +7,6 @@ import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdatePr
|
||||
import com.djrapitops.plan.system.processing.processors.info.PlayerPageUpdateProcessor;
|
||||
import com.djrapitops.plan.system.processing.processors.player.*;
|
||||
import com.djrapitops.plan.system.tasks.TaskSystem;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.systems.NotificationCenter;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -83,7 +82,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
NotificationCenter.checkNotifications(player);
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
AFKListener.AFK_TRACKER.performedAction(uuid, time);
|
||||
|
||||
@ -119,7 +118,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
}
|
||||
|
||||
private void actOnQuitEvent(PlayerQuitEvent event) {
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.djrapitops.plan.system.listeners.bukkit;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -26,7 +25,7 @@ public class WorldChangeListener implements Listener {
|
||||
}
|
||||
|
||||
private void actOnEvent(PlayerChangedWorldEvent event) {
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
@ -6,7 +6,7 @@ package com.djrapitops.plan.system.listeners.bungee;
|
||||
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.processing.processors.player.BungeePlayerRegisterProcessor;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.system.processing.processors.player.IPUpdateProcessor;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
@ -28,9 +28,12 @@ public class PlayerOnlineListener implements Listener {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
String name = player.getName();
|
||||
long now = MiscUtils.getTime();
|
||||
String ip = player.getAddress().getAddress().getHostAddress();
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Processing.submit(new BungeePlayerRegisterProcessor(uuid, name, now));
|
||||
Processing.submit(new BungeePlayerRegisterProcessor(uuid, name, now,
|
||||
new IPUpdateProcessor(uuid, ip, now))
|
||||
);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.djrapitops.plan.system.listeners.sponge;
|
||||
|
||||
import com.djrapitops.plan.system.afk.AFKTracker;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
@ -31,7 +30,7 @@ public class SpongeAFKListener {
|
||||
private void event(TargetPlayerEvent event) {
|
||||
try {
|
||||
UUID uuid = event.getTargetEntity().getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
AFK_TRACKER.performedAction(uuid, time);
|
||||
} catch (Exception e) {
|
||||
@ -42,21 +41,21 @@ public class SpongeAFKListener {
|
||||
@Listener(order = Order.POST)
|
||||
public void onMove(MoveEntityEvent event, @First Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
AFK_TRACKER.performedAction(uuid, time);
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
AFK_TRACKER.performedAction(uuid, time);
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onPlayerCommand(SendCommandEvent event, @First Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
AFK_TRACKER.performedAction(uuid, time);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.processing.processors.player.SpongeKillProcessor;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Format;
|
||||
import org.spongepowered.api.data.key.Keys;
|
||||
@ -13,7 +12,7 @@ import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.entity.living.Living;
|
||||
import org.spongepowered.api.entity.living.animal.Wolf;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.entity.projectile.arrow.Arrow;
|
||||
import org.spongepowered.api.entity.projectile.Projectile;
|
||||
import org.spongepowered.api.entity.projectile.source.ProjectileSource;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource;
|
||||
@ -34,7 +33,7 @@ public class SpongeDeathListener {
|
||||
|
||||
@Listener
|
||||
public void onEntityDeath(DestructEntityEvent.Death event) {
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
Living dead = event.getTargetEntity();
|
||||
|
||||
if (dead instanceof Player) {
|
||||
@ -60,8 +59,8 @@ public class SpongeDeathListener {
|
||||
processor = handlePlayerKill(time, dead, (Player) killerEntity);
|
||||
} else if (killerEntity instanceof Wolf) {
|
||||
processor = handleWolfKill(time, dead, (Wolf) killerEntity);
|
||||
} else if (killerEntity instanceof Arrow) {
|
||||
processor = handleArrowKill(time, dead, (Arrow) killerEntity);
|
||||
} else if (killerEntity instanceof Projectile) {
|
||||
processor = handleProjectileKill(time, dead, (Projectile) killerEntity);
|
||||
}
|
||||
if (processor != null) {
|
||||
Processing.submit(processor);
|
||||
@ -96,15 +95,17 @@ public class SpongeDeathListener {
|
||||
).orElse(null);
|
||||
}
|
||||
|
||||
private SpongeKillProcessor handleArrowKill(long time, Living dead, Arrow arrow) {
|
||||
ProjectileSource source = arrow.getShooter();
|
||||
private SpongeKillProcessor handleProjectileKill(long time, Living dead, Projectile projectile) {
|
||||
ProjectileSource source = projectile.getShooter();
|
||||
if (!(source instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Player player = (Player) source;
|
||||
|
||||
return new SpongeKillProcessor(player.getUniqueId(), time, getUUID(dead), "Bow");
|
||||
return new SpongeKillProcessor(player.getUniqueId(), time, getUUID(dead),
|
||||
new Format(projectile.getType().getName()).capitalize().toString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,6 @@ package com.djrapitops.plan.system.listeners.sponge;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
@ -36,7 +35,7 @@ public class SpongeGMChangeListener {
|
||||
private void actOnGMChangeEvent(ChangeGameModeEvent.TargetPlayer event) {
|
||||
Player player = event.getTargetEntity();
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
String gameMode = event.getGameMode().getName().toUpperCase();
|
||||
String worldName = player.getWorld().getName();
|
||||
|
@ -7,7 +7,6 @@ import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdatePr
|
||||
import com.djrapitops.plan.system.processing.processors.info.PlayerPageUpdateProcessor;
|
||||
import com.djrapitops.plan.system.processing.processors.player.*;
|
||||
import com.djrapitops.plan.system.tasks.TaskSystem;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.systems.NotificationCenter;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.spongepowered.api.Sponge;
|
||||
@ -82,7 +81,7 @@ public class SpongePlayerListener {
|
||||
NotificationCenter.checkNotifications(player);
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
SpongeAFKListener.AFK_TRACKER.performedAction(uuid, time);
|
||||
|
||||
@ -122,7 +121,7 @@ public class SpongePlayerListener {
|
||||
}
|
||||
|
||||
private void actOnQuitEvent(ClientConnectionEvent.Disconnect event) {
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
Player player = event.getTargetEntity();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.djrapitops.plan.system.listeners.sponge;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.spongepowered.api.data.key.Keys;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
@ -37,7 +36,7 @@ public class SpongeWorldChangeListener {
|
||||
}
|
||||
|
||||
private void actOnEvent(MoveEntityEvent.Teleport event, Player player) {
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
|
@ -9,10 +9,7 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class Processing implements SubSystem {
|
||||
|
||||
@ -22,6 +19,9 @@ public class Processing implements SubSystem {
|
||||
public Processing() {
|
||||
nonCriticalExecutor = Executors.newFixedThreadPool(6);
|
||||
criticalExecutor = Executors.newFixedThreadPool(2);
|
||||
saveInstance(nonCriticalExecutor);
|
||||
saveInstance(criticalExecutor);
|
||||
saveInstance(this);
|
||||
}
|
||||
|
||||
public static void submit(Runnable runnable) {
|
||||
@ -38,27 +38,27 @@ public class Processing implements SubSystem {
|
||||
|
||||
public static void submitNonCritical(Runnable runnable) {
|
||||
saveInstance(runnable);
|
||||
getInstance().nonCriticalExecutor.submit(runnable);
|
||||
CompletableFuture.supplyAsync(() -> runnable, getInstance().nonCriticalExecutor)
|
||||
.thenAccept(Runnable::run)
|
||||
.handle(Processing::exceptionHandler);
|
||||
}
|
||||
|
||||
public static void submitCritical(Runnable runnable) {
|
||||
saveInstance(runnable);
|
||||
getInstance().criticalExecutor.submit(runnable);
|
||||
CompletableFuture.supplyAsync(() -> runnable, getInstance().criticalExecutor)
|
||||
.thenAccept(Runnable::run)
|
||||
.handle(Processing::exceptionHandler);
|
||||
}
|
||||
|
||||
public static void submitNonCritical(Runnable... runnables) {
|
||||
ExecutorService nonCriticalExecutor = getInstance().nonCriticalExecutor;
|
||||
for (Runnable runnable : runnables) {
|
||||
saveInstance(runnable);
|
||||
nonCriticalExecutor.submit(runnable);
|
||||
submitNonCritical(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
public static void submitCritical(Runnable... runnables) {
|
||||
ExecutorService criticalExecutor = getInstance().criticalExecutor;
|
||||
for (Runnable runnable : runnables) {
|
||||
saveInstance(runnable);
|
||||
criticalExecutor.submit(runnable);
|
||||
submitCritical(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,12 +72,35 @@ public class Processing implements SubSystem {
|
||||
|
||||
public static <T> Future<T> submitNonCritical(Callable<T> task) {
|
||||
saveInstance(task);
|
||||
return getInstance().nonCriticalExecutor.submit(task);
|
||||
return CompletableFuture.supplyAsync(() -> task, getInstance().nonCriticalExecutor)
|
||||
.thenApply(tCallable -> {
|
||||
try {
|
||||
return tCallable.call();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
})
|
||||
.handle(Processing::exceptionHandler);
|
||||
}
|
||||
|
||||
private static <T> T exceptionHandler(T t, Throwable throwable) {
|
||||
if (throwable != null) {
|
||||
Log.toLog(Processing.class, throwable.getCause());
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public static <T> Future<T> submitCritical(Callable<T> task) {
|
||||
saveInstance(task);
|
||||
return getInstance().criticalExecutor.submit(task);
|
||||
return CompletableFuture.supplyAsync(() -> task, getInstance().criticalExecutor)
|
||||
.thenApply(tCallable -> {
|
||||
try {
|
||||
return tCallable.call();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
})
|
||||
.handle(Processing::exceptionHandler);
|
||||
}
|
||||
|
||||
public static Processing getInstance() {
|
||||
|
@ -17,7 +17,6 @@ import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.importing.ServerImportData;
|
||||
import com.djrapitops.plan.system.processing.importing.UserImportData;
|
||||
import com.djrapitops.plan.system.processing.importing.UserImportRefiner;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
@ -225,7 +224,7 @@ public abstract class Importer {
|
||||
}
|
||||
|
||||
private List<GeoInfo> convertGeoInfo(UserImportData userImportData) {
|
||||
long date = MiscUtils.getTime();
|
||||
long date = System.currentTimeMillis();
|
||||
|
||||
return userImportData.getIps().parallelStream()
|
||||
.map(ip -> {
|
||||
|
@ -7,6 +7,7 @@ package com.djrapitops.plan.system.processing.processors.player;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.processing.CriticalRunnable;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -21,11 +22,13 @@ public class BungeePlayerRegisterProcessor implements CriticalRunnable {
|
||||
private final UUID uuid;
|
||||
private final String name;
|
||||
private final long registered;
|
||||
private final Runnable[] afterProcess;
|
||||
|
||||
public BungeePlayerRegisterProcessor(UUID uuid, String name, long registered) {
|
||||
public BungeePlayerRegisterProcessor(UUID uuid, String name, long registered, Runnable... afterProcess) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.registered = registered;
|
||||
this.afterProcess = afterProcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,6 +41,11 @@ public class BungeePlayerRegisterProcessor implements CriticalRunnable {
|
||||
database.save().registerNewUser(uuid, registered, name);
|
||||
} catch (DBException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
} finally {
|
||||
for (Runnable process : afterProcess) {
|
||||
Processing.submit(process);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -38,7 +38,8 @@ public class IPUpdateProcessor implements CriticalRunnable {
|
||||
if (Settings.DATA_GEOLOCATIONS.isTrue()) {
|
||||
String country = GeolocationCache.getCountry(ip);
|
||||
try {
|
||||
Database.getActive().save().geoInfo(uuid, new GeoInfo(ip, country, time));
|
||||
GeoInfo geoInfo = new GeoInfo(ip, country, time);
|
||||
Database.getActive().save().geoInfo(uuid, geoInfo);
|
||||
} catch (DBException | UnsupportedEncodingException | NoSuchAlgorithmException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.CriticalRunnable;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
@ -67,7 +66,7 @@ public class NameProcessor implements CriticalRunnable {
|
||||
return;
|
||||
}
|
||||
|
||||
long time = MiscUtils.getTime();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
Processing.submitCritical(() -> {
|
||||
String info = HtmlUtils.removeXSS(displayName);
|
||||
|
@ -9,22 +9,22 @@ package com.djrapitops.plan.system.settings;
|
||||
public enum Permissions {
|
||||
|
||||
HELP("plan.?"),
|
||||
//
|
||||
|
||||
INSPECT("plan.inspect"),
|
||||
QUICK_INSPECT("plan.qinspect"),
|
||||
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"),
|
||||
MANAGE("plan.manage"),
|
||||
MANAGE_WEB("plan.webmanage"),
|
||||
//
|
||||
|
||||
IGNORE_COMMANDUSE("plan.ignore.commanduse");
|
||||
|
||||
private final String permission;
|
||||
|
@ -71,9 +71,9 @@ public enum Settings {
|
||||
WEBSERVER_CERTIFICATE_ALIAS("WebServer.Security.SSL-Certificate.Alias"),
|
||||
EXTERNAL_WEBSERVER_LINK("WebServer.ExternalWebServerAddress"),
|
||||
PLUGIN_BUYCRAFT_SECRET("Plugins.BuyCraft.Secret"),
|
||||
//
|
||||
|
||||
SERVER_NAME("Server.ServerName"),
|
||||
//
|
||||
|
||||
FORMAT_DATE_FULL("Customization.Formatting.Dates.Full"),
|
||||
FORMAT_DATE_NO_SECONDS("Customization.Formatting.Dates.NoSeconds"),
|
||||
FORMAT_DATE_CLOCK("Customization.Formatting.Dates.JustClock"),
|
||||
@ -89,11 +89,11 @@ public enum Settings {
|
||||
FORMAT_SECONDS("Customization.Formatting.TimeAmount.Seconds"),
|
||||
FORMAT_ZERO_SECONDS("Customization.Formatting.TimeAmount.Zero"),
|
||||
FORMAT_DECIMALS("Customization.Formatting.DecimalPoints"),
|
||||
//
|
||||
|
||||
COLOR_MAIN("Commands.Colors.Main"),
|
||||
COLOR_SEC("Commands.Colors.Secondary"),
|
||||
COLOR_TER("Commands.Colors.Highlight"),
|
||||
//
|
||||
|
||||
THEME_BASE("Theme.Base"),
|
||||
THEME_GRAPH_TPS_THRESHOLD_HIGH("Theme.Graphs.TPS.High-Threshold"),
|
||||
THEME_GRAPH_TPS_THRESHOLD_MED("Theme.Graphs.TPS.Medium-Threshold"),
|
||||
@ -103,7 +103,7 @@ public enum Settings {
|
||||
HIDE_TOWNS("Plugins.Towny.HideTowns"),
|
||||
// Config section
|
||||
WORLD_ALIASES("Customization.WorldAliases"),
|
||||
//
|
||||
|
||||
// Bungee
|
||||
BUNGEE_IP("Server.IP"),
|
||||
BUNGEE_NETWORK_NAME("Network.Name");
|
||||
|
@ -14,23 +14,23 @@ public enum Msg {
|
||||
ENABLE_WEBSERVER_INFO("Enable - WebServer Info"),
|
||||
ENABLE_BOOT_ANALYSIS_INFO("Enable - Boot Analysis 30s Notify"),
|
||||
ENABLE_BOOT_ANALYSIS_RUN_INFO("Enable - Boot Analysis Notify"),
|
||||
//
|
||||
|
||||
ENABLE_NOTIFY_EMPTY_IP("Enable Notify-Empty IP"),
|
||||
ENABLE_NOTIFY_NO_DATA_VIEW("Enable Notify - No data view"),
|
||||
ENABLE_NOTIFY_DISABLED_CHATLISTENER("Enable Notify - ChatListener"),
|
||||
ENABLE_NOTIFY_DISABLED_COMMANDLISTENER("Enable Notify - Disabled CommandListener"),
|
||||
ENABLE_NOTIFY_DISABLED_DEATHLISTENER("Enable Notify - Disabled DeathListener"),
|
||||
//
|
||||
|
||||
ENABLE_FAIL_WRONG_DB("Enable FAIL - Wrong Db Type"),
|
||||
ENABLE_FAIL_DB("Enable FAIL-Db"),
|
||||
ENABLE_DB_FAIL_DISABLE_INFO("Enable Db FAIL - Disable Info"),
|
||||
//
|
||||
|
||||
RUN_WARN_QUEUE_SIZE("WARN - Too Small Queue Size"),
|
||||
//
|
||||
|
||||
DISABLED("Disable"),
|
||||
DISABLE_CACHE_SAVE("Disable - Save"),
|
||||
DISABLE_WEBSERVER("Disable - WebServer"),
|
||||
//
|
||||
|
||||
ANALYSIS_START("Analysis - Start"),
|
||||
ANALYSIS_FETCH_UUID("Analysis - Fetch Phase Start"),
|
||||
ANALYSIS_FETCH("Analysis - Fetch Phase"),
|
||||
@ -40,7 +40,7 @@ public enum Msg {
|
||||
ANALYSIS_FAIL_NO_PLAYERS("Analysis FAIL - No Players"),
|
||||
ANALYSIS_FAIL_NO_DATA("Analysis FAIL - No Data"),
|
||||
ANALYSIS_FAIL_FETCH_EXCEPTION("Analysis FAIL - Fetch Exception"),
|
||||
//
|
||||
|
||||
MANAGE_INFO_CONFIG_REMINDER("Manage - Remind Config Change"),
|
||||
MANAGE_INFO_START("Manage - Start"),
|
||||
MANAGE_INFO_IMPORT("Manage - Import"),
|
||||
@ -50,7 +50,7 @@ public enum Msg {
|
||||
MANAGE_INFO_MOVE_SUCCESS("Manage - Move Success"),
|
||||
MANAGE_INFO_CLEAR_SUCCESS("Manage - Clear Success"),
|
||||
MANAGE_INFO_REMOVE_SUCCESS("Manage - Remove Success"),
|
||||
//
|
||||
|
||||
MANAGE_FAIL_INCORRECT_PLUGIN("Manage FAIL - Incorrect Plugin"),
|
||||
MANAGE_FAIL_PLUGIN_NOT_ENABLED("Manage FAIL - Unenabled Plugin"),
|
||||
MANAGE_FAIL_SAME_DB("Manage FAIL - Same DB"),
|
||||
@ -58,13 +58,13 @@ public enum Msg {
|
||||
MANAGE_FAIL_FAULTY_DB("Manage FAIL - Faulty DB Connection"),
|
||||
MANAGE_FAIL_NO_PLAYERS("Manage FAIL - Empty DB"),
|
||||
MANAGE_FAIL_FILE_NOT_FOUND("Manage FAIL - Backup File Not Found"),
|
||||
//
|
||||
|
||||
MANAGE_FAIL_CONFIRM("Manage FAIL - Confirm Action"),
|
||||
MANAGE_NOTIFY_REWRITE("Manage NOTIFY - Rewrite"),
|
||||
MANAGE_NOTIFY_OVERWRITE("Manage NOTIFY - Overwrite"),
|
||||
MANAGE_NOTIFY_PARTIAL_OVERWRITE("Manage NOTIFY - Partial Overwrite"),
|
||||
MANAGE_NOTIFY_REMOVE("Manage NOTIFY - Remove"),
|
||||
//
|
||||
|
||||
CMD_FAIL_REQ_ARGS("Cmd FAIL - Requires Arguments"),
|
||||
CMD_FAIL_REQ_ONE_ARG("Cmd FAIL - Require only one Argument"),
|
||||
CMD_FAIL_NO_PERMISSION("Cmd FAIL - No Permission"),
|
||||
@ -73,7 +73,7 @@ public enum Msg {
|
||||
CMD_FAIL_USERNAME_NOT_KNOWN("Cmd FAIL - Unknown Username"),
|
||||
CMD_FAIL_TIMEOUT("Cmd FAIL - Timeout"),
|
||||
CMD_FAIL_NO_DATA_VIEW("Cmd FAIL - No Data View"),
|
||||
//
|
||||
|
||||
CMD_INFO_ANALYSIS_TEMP_DISABLE("Analysis NOTIFY - Temporary Disable"),
|
||||
CMD_INFO_CLICK_ME("Cmd - Click Me"),
|
||||
CMD_INFO_LINK("Cmd - Link"),
|
||||
@ -82,7 +82,7 @@ public enum Msg {
|
||||
CMD_INFO_RELOAD_COMPLETE("Cmd - Reload Success"),
|
||||
CMD_INFO_FETCH_DATA("Cmd - Fetch Data"),
|
||||
CMD_INFO_SEARCHING("Cmd - Searching"),
|
||||
//
|
||||
|
||||
CMD_USG_ANALYZE("Cmd - Usage /plan analyze"),
|
||||
CMD_USG_QANALYZE("Cmd - Usage /plan qanalyze"),
|
||||
CMD_USG_HELP("Cmd - Usage /plan help"),
|
||||
@ -107,7 +107,7 @@ public enum Msg {
|
||||
CMD_USG_WEB_DELETE("Cmd - Usage /plan webuser delete"),
|
||||
CMD_USG_WEB_LEVEL("Cmd - Usage /plan webuser level"),
|
||||
CMD_USG_WEB_REGISTER("Cmd - Usage /plan webuser register"),
|
||||
//
|
||||
|
||||
CMD_HELP_ANALYZE("In Depth Help - /plan analyze ?"),
|
||||
CMD_HELP_QANALYZE("In Depth Help - /plan qanalyze ?"),
|
||||
CMD_HELP_PLAN("In Depth Help - /plan ?"),
|
||||
@ -123,15 +123,15 @@ public enum Msg {
|
||||
CMD_HELP_SEARCH("In Depth Help - /plan search ?"),
|
||||
CMD_HELP_WEB("In Depth Help - /plan webuser ?"),
|
||||
CMD_HELP_WEB_REGISTER("In Depth Help - /plan webuser register ?"),
|
||||
//
|
||||
|
||||
CMD_HEADER_ANALYZE("Cmd Header - Analysis"),
|
||||
CMD_HEADER_INSPECT("Cmd Header - Inspect"),
|
||||
CMD_HEADER_INFO("Cmd Header - Info"),
|
||||
CMD_HEADER_SEARCH("Cmd Header - Search"),
|
||||
//
|
||||
|
||||
CMD_CONSTANT_LIST_BALL(">Constant - List Ball"),
|
||||
CMD_CONSTANT_FOOTER(">Constant - CMD Footer"),
|
||||
//
|
||||
|
||||
HTML_NO_PLUGINS("Html - No Extra Plugins"),
|
||||
HTML_BANNED("Html - Banned"),
|
||||
HTML_OP("Html - OP"),
|
||||
|
@ -12,10 +12,10 @@ package com.djrapitops.plan.system.settings.theme;
|
||||
public enum ThemeVal {
|
||||
|
||||
THEME_DEFAULT("DefaultColor", "light-green"),
|
||||
//
|
||||
|
||||
FONT_STYLESHEET("Font.FontStyleSheet", "https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,cyrillic-ext"),
|
||||
FONT_FAMILY("Font.FontFamily", "\"Roboto\", sans-serif"),
|
||||
//
|
||||
|
||||
RED("Colors.red", "#E91E63"),
|
||||
PINK("Colors.pink", "#F44336"),
|
||||
PURPLE("Colors.purple", "#9C27B0"),
|
||||
@ -37,7 +37,7 @@ public enum ThemeVal {
|
||||
BLUE_GREY("Colors.blue-grey", "#607D8B"),
|
||||
BLACK("Colors.black", "#000000"),
|
||||
WHITE("Colors.Extra.White", "#fff"),
|
||||
//
|
||||
|
||||
GRAPH_PUNCHCARD("GraphColors.PunchCard", "#222"),
|
||||
GRAPH_PLAYERS_ONLINE("GraphColors.PlayersOnline", "#1E90FF"),
|
||||
GRAPH_TPS_HIGH("GraphColors.TPS.High", "#267F00"),
|
||||
@ -53,7 +53,7 @@ public enum ThemeVal {
|
||||
GRAPH_SERVER_PREF_PIE("GraphColors.ServerPreferencePie", "\"#0099C6\", \"#66AA00\", \"#316395\", \"#994499\", \"#22AA99\", \"#AAAA11\", \"#6633CC\", \"#E67300\", \"#329262\", \"#5574A6\""),
|
||||
WORLD_MAP_HIGH("GraphColors.WorldMap_High", "#267f00"),
|
||||
WORLD_MAP_LOW("GraphColors.WorldMap_Low", "#EEFFEE"),
|
||||
//
|
||||
|
||||
PARSED_SESSION_ACCORDION("ParsedElements.SessionAccordion", "teal"),
|
||||
PARSED_SERVER_ACCORDION("ParsedElements.ServerAccordion", "light-green");
|
||||
|
||||
|
@ -4,7 +4,6 @@ import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.processing.processors.TPSInsertProcessor;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
|
||||
@ -33,7 +32,7 @@ public abstract class TPSCountTimer<T extends PlanPlugin> extends AbsRunnable {
|
||||
public void run() {
|
||||
try {
|
||||
long nanoTime = System.nanoTime();
|
||||
long now = MiscUtils.getTime();
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
addNewTPSEntry(nanoTime, now);
|
||||
|
||||
|
@ -8,12 +8,10 @@ import com.djrapitops.plan.system.tasks.TPSCountTimer;
|
||||
import com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.world.Chunk;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class SpongeTPSCountTimer extends TPSCountTimer<PlanSponge> {
|
||||
|
||||
@ -62,7 +60,7 @@ public class SpongeTPSCountTimer extends TPSCountTimer<PlanSponge> {
|
||||
double tps = Sponge.getGame().getServer().getTicksPerSecond();
|
||||
int playersOnline = ServerInfo.getServerProperties().getOnlinePlayers();
|
||||
latestPlayersOnline = playersOnline;
|
||||
int loadedChunks = -1;
|
||||
int loadedChunks = -1; // getLoadedChunks();
|
||||
int entityCount = getEntityCount();
|
||||
|
||||
return TPSBuilder.get()
|
||||
@ -83,13 +81,9 @@ public class SpongeTPSCountTimer extends TPSCountTimer<PlanSponge> {
|
||||
*/
|
||||
private int getLoadedChunks() {
|
||||
// DISABLED
|
||||
|
||||
int loaded = 0;
|
||||
for (World world : Sponge.getGame().getServer().getWorlds()) {
|
||||
Iterator<Chunk> iterator = world.getLoadedChunks().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
loaded++;
|
||||
}
|
||||
loaded += world.getLoadedChunks().spliterator().estimateSize();
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
@ -99,7 +93,7 @@ public class SpongeTPSCountTimer extends TPSCountTimer<PlanSponge> {
|
||||
*
|
||||
* @return amount of entities
|
||||
*/
|
||||
protected int getEntityCount() {
|
||||
private int getEntityCount() {
|
||||
return Sponge.getGame().getServer().getWorlds().stream().mapToInt(world -> world.getEntities().size()).sum();
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class ShutdownUpdateHook extends Thread {
|
||||
downloadNewJar(available, newJar);
|
||||
registerOldJarForDeletion(pluginsFolder, newJar);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.toLog(ShutdownUpdateHook.class, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,6 +129,7 @@ public class ShutdownUpdateHook extends Thread {
|
||||
try {
|
||||
((URLClassLoader) classLoader).close();
|
||||
} catch (IOException e) {
|
||||
// Loggers may be unavailable.
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,6 @@ public class VersionInfo implements Comparable<VersionInfo> {
|
||||
|
||||
@Override
|
||||
public int compareTo(VersionInfo o) {
|
||||
return -this.version.compareTo(o.version);
|
||||
return o.version.compareTo(this.version);
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ public class PlayerPageHandler extends PageHandler {
|
||||
try {
|
||||
if (Database.getActive().check().isPlayerRegistered(uuid)) {
|
||||
Response response = ResponseCache.loadResponse(PageId.PLAYER.of(uuid));
|
||||
if (response == null || !(response instanceof InspectPageResponse)) {
|
||||
if (!(response instanceof InspectPageResponse)) {
|
||||
InfoSystem.getInstance().generateAndCachePlayerPage(uuid);
|
||||
response = ResponseCache.loadResponse(PageId.PLAYER.of(uuid));
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class InspectPage extends Page {
|
||||
}
|
||||
|
||||
public String parse(PlayerProfile profile, UUID serverUUID, Map<UUID, String> serverNames) throws IOException {
|
||||
long now = MiscUtils.getTime();
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
addValue("refresh", FormatUtils.formatTimeStampClock(now));
|
||||
addValue("version", MiscUtils.getPlanVersion());
|
||||
|
@ -42,7 +42,7 @@ public class NetworkPage extends Page {
|
||||
public String toHtml() throws ParseException {
|
||||
try {
|
||||
UUID serverUUID = ServerInfo.getServerUUID();
|
||||
long now = MiscUtils.getTime();
|
||||
long now = System.currentTimeMillis();
|
||||
Database database = Database.getActive();
|
||||
List<TPS> networkOnlineData = database.fetch().getNetworkOnlineData();
|
||||
List<String> geolocations = database.fetch().getNetworkGeolocations();
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.djrapitops.plan.system.webserver.response;
|
||||
|
||||
/**
|
||||
* Enum for HTTP response codes.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public enum ResponseCode {
|
||||
NONE(0),
|
||||
CONNECTION_REFUSED(-1),
|
||||
SUCCESS(200),
|
||||
BAD_REQUEST(400),
|
||||
UNAUTHORIZED(401),
|
||||
FORBIDDEN(403),
|
||||
NOT_FOUND(404),
|
||||
PRECONDITION_FAILED(412),
|
||||
INTERNAL_ERROR(500),
|
||||
GATEWAY_ERROR(504);
|
||||
|
||||
private final int code;
|
||||
|
||||
ResponseCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
@ -16,19 +16,19 @@ public enum PageId {
|
||||
SERVER("serverPage:"),
|
||||
PLAYER("playerPage:"),
|
||||
PLAYERS("playersPage"),
|
||||
//
|
||||
|
||||
ERROR("error:"),
|
||||
FORBIDDEN(ERROR.of("Forbidden")),
|
||||
NOT_FOUND(ERROR.of("Not Found")),
|
||||
TRUE("true"),
|
||||
FALSE("false"),
|
||||
//
|
||||
|
||||
JS("js:"),
|
||||
CSS("css:"),
|
||||
//
|
||||
|
||||
FAVICON_REDIRECT("Redirect:Favicon"),
|
||||
AUTH_PROMPT("PromptAuth"),
|
||||
//
|
||||
|
||||
PLAYER_PLUGINS_TAB("playerPluginsTab:"),
|
||||
NETWORK_CONTENT("networkContent");
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.djrapitops.plan.system.webserver.response.Response;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* This class contains the page cache.
|
||||
@ -29,23 +30,23 @@ public class ResponseCache {
|
||||
/**
|
||||
* Loads the response from the response cache.
|
||||
* <p>
|
||||
* If the {@link Response} isn't cached, {@link ResponseLoader#createResponse()} in the {@code loader}
|
||||
* If the {@link Response} isn't cached, {@link Supplier#get()} in the {@code loader}
|
||||
* is called to create the Response.
|
||||
* <p>
|
||||
* If the Response is created, it's automatically cached.
|
||||
*
|
||||
* @param identifier The identifier of the page
|
||||
* @param loader The {@link ResponseLoader} (How should it load the page if it's not cached)
|
||||
* @return The Response that was cached or created by the {@link ResponseLoader loader}
|
||||
* @param loader The The {@link Response} {@link Supplier} (How should it load the page if it's not cached)
|
||||
* @return The Response that was cached or created by the the {@link Response} {@link Supplier}
|
||||
*/
|
||||
public static Response loadResponse(String identifier, ResponseLoader loader) {
|
||||
public static Response loadResponse(String identifier, Supplier<Response> loader) {
|
||||
Response response = loadResponse(identifier);
|
||||
|
||||
if (response != null) {
|
||||
return response;
|
||||
}
|
||||
|
||||
response = loader.createResponse();
|
||||
response = loader.get();
|
||||
|
||||
cache.put(identifier, response);
|
||||
|
||||
@ -68,10 +69,10 @@ public class ResponseCache {
|
||||
* If the cache already inherits that {@code identifier}, it's renewed.
|
||||
*
|
||||
* @param identifier The identifier of the page
|
||||
* @param loader The {@link ResponseLoader} (How it should load the page)
|
||||
* @param loader The {@link Response} {@link Supplier} (How it should load the page)
|
||||
*/
|
||||
public static void cacheResponse(String identifier, ResponseLoader loader) {
|
||||
Response response = loader.createResponse();
|
||||
public static void cacheResponse(String identifier, Supplier<Response> loader) {
|
||||
Response response = loader.get();
|
||||
cache.put(identifier, response);
|
||||
}
|
||||
|
||||
@ -92,15 +93,4 @@ public class ResponseCache {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface is used for providing the method to load the page.
|
||||
*
|
||||
* @author Fuzzlemann
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public interface ResponseLoader {
|
||||
|
||||
Response createResponse();
|
||||
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user