mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-07 17:28:03 +08:00
Fixing Sonar smells:
- Removed unused code in Reflection - Removed duplicated Strings in GMTimes - Added private constructor to TimeZoneUtility - Renamed local variable in RegisterDateMinimizationPatch - Replaced Function<String, Boolean> with Predicate in ExtensionRegister - Changed AFKListeners to use primitive boolean - Changed Config#get(Setting<Boolean>) uses to isTrue and isFalse - comment to NukkitListenerSystem
This commit is contained in:
parent
b3325bfc6e
commit
732c7858d0
@ -119,7 +119,7 @@ public class BukkitTaskSystem extends TaskSystem {
|
||||
private void registerPingCounter() {
|
||||
try {
|
||||
Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.get(DataGatheringSettings.PING)) {
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(pingCounter);
|
||||
long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS);
|
||||
registerTask(pingCounter).runTaskTimer(startDelay, 40L);
|
||||
|
@ -68,10 +68,7 @@ public class BukkitAFKListener implements Listener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
Boolean ignored = ignorePermissionInfo.get(uuid);
|
||||
if (ignored == null) {
|
||||
ignored = player.hasPermission(Permissions.IGNORE_AFK.getPermission());
|
||||
}
|
||||
boolean ignored = ignorePermissionInfo.computeIfAbsent(uuid, keyUUID -> player.hasPermission(Permissions.IGNORE_AFK.getPermission()));
|
||||
if (ignored) {
|
||||
AFK_TRACKER.hasIgnorePermission(uuid);
|
||||
ignorePermissionInfo.put(uuid, true);
|
||||
|
@ -187,7 +187,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
));
|
||||
|
||||
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
}
|
||||
@ -227,7 +227,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
sessionCache.endSession(playerUUID, time)
|
||||
.ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));
|
||||
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,9 @@ package com.djrapitops.plan.utilities.java;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* An utility class that simplifies reflection in Bukkit plugins.
|
||||
@ -46,9 +43,6 @@ public final class Reflection {
|
||||
// Deduce the net.minecraft.server.v* package
|
||||
private static final String OBC_PREFIX = getOBCPrefix();
|
||||
private static final String NMS_PREFIX = OBC_PREFIX.replace("org.bukkit.craftbukkit", "net.minecraft.server");
|
||||
private static final String VERSION = OBC_PREFIX.replace("org.bukkit.craftbukkit", "").replace(".", "");
|
||||
// Variable replacement
|
||||
private static final Pattern MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}");
|
||||
|
||||
private Reflection() {
|
||||
// Seal class
|
||||
@ -71,42 +65,6 @@ public final class Reflection {
|
||||
return getField(target, name, fieldType, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a field accessor for a specific field type and name.
|
||||
*
|
||||
* @param className - lookup name of the class, see {@link #getClass(String)}.
|
||||
* @param name - the name of the field, or NULL to ignore.
|
||||
* @param fieldType - a compatible field type.
|
||||
* @return The field accessor.
|
||||
*/
|
||||
public static <T> FieldAccessor<T> getField(String className, String name, Class<T> fieldType) {
|
||||
return getField(getClass(className), name, fieldType, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a field accessor for a specific field type and name.
|
||||
*
|
||||
* @param target - the target type.
|
||||
* @param fieldType - a compatible field type.
|
||||
* @param index - the number of compatible fields to skip.
|
||||
* @return The field accessor.
|
||||
*/
|
||||
public static <T> FieldAccessor<T> getField(Class<?> target, Class<T> fieldType, int index) {
|
||||
return getField(target, null, fieldType, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a field accessor for a specific field type and name.
|
||||
*
|
||||
* @param className - lookup name of the class, see {@link #getClass(String)}.
|
||||
* @param fieldType - a compatible field type.
|
||||
* @param index - the number of compatible fields to skip.
|
||||
* @return The field accessor.
|
||||
*/
|
||||
public static <T> FieldAccessor<T> getField(String className, Class<T> fieldType, int index) {
|
||||
return getField(getClass(className), fieldType, index);
|
||||
}
|
||||
|
||||
// Common method
|
||||
private static <T> FieldAccessor<T> getField(Class<?> target, String name, Class<T> fieldType, int index) {
|
||||
for (final Field field : target.getDeclaredFields()) {
|
||||
@ -152,19 +110,6 @@ public final class Reflection {
|
||||
throw new IllegalArgumentException("Cannot find field with type " + fieldType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for the first publicly and privately defined method of the given name and parameter count.
|
||||
*
|
||||
* @param className - lookup name of the class, see {@link #getClass(String)}.
|
||||
* @param methodName - the method name, or NULL to skip.
|
||||
* @param params - the expected parameters.
|
||||
* @return An object that invokes this specific method.
|
||||
* @throws IllegalStateException If we cannot find this method.
|
||||
*/
|
||||
public static MethodInvoker getMethod(String className, String methodName, Class<?>... params) {
|
||||
return getTypedMethod(getClass(className), methodName, null, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for the first publicly and privately defined method of the given name and parameter count.
|
||||
*
|
||||
@ -211,92 +156,6 @@ public final class Reflection {
|
||||
throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for the first publicly and privately defined constructor of the given name and parameter count.
|
||||
*
|
||||
* @param className - lookup name of the class, see {@link #getClass(String)}.
|
||||
* @param params - the expected parameters.
|
||||
* @return An object that invokes this constructor.
|
||||
* @throws IllegalStateException If we cannot find this method.
|
||||
*/
|
||||
public static ConstructorInvoker getConstructor(String className, Class<?>... params) {
|
||||
return getConstructor(getClass(className), params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for the first publicly and privately defined constructor of the given name and parameter count.
|
||||
*
|
||||
* @param clazz - a class to start with.
|
||||
* @param params - the expected parameters.
|
||||
* @return An object that invokes this constructor.
|
||||
* @throws IllegalStateException If we cannot find this method.
|
||||
*/
|
||||
public static ConstructorInvoker getConstructor(Class<?> clazz, Class<?>... params) {
|
||||
for (final Constructor<?> constructor : clazz.getDeclaredConstructors()) {
|
||||
if (Arrays.equals(constructor.getParameterTypes(), params)) {
|
||||
constructor.setAccessible(true);
|
||||
|
||||
return arguments -> {
|
||||
try {
|
||||
return constructor.newInstance(arguments);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Cannot invoke constructor " + constructor, e);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(params)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a class from its full name, without knowing its type on compile time.
|
||||
* <p>
|
||||
* This is useful when looking up fields by a NMS or OBC type.
|
||||
* <p>
|
||||
*
|
||||
* @param lookupName - the class name with variables.
|
||||
* @return The class.
|
||||
* @see Object#getClass()
|
||||
*/
|
||||
public static Class<Object> getUntypedClass(String lookupName) {
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
Class<Object> clazz = (Class) getClass(lookupName);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a class from its full name.
|
||||
* <p>
|
||||
* Strings enclosed with curly brackets - such as {TEXT} - will be replaced according to the following table:
|
||||
* </p>
|
||||
* <table border="1" summary="Variables and description">
|
||||
* <tr>
|
||||
* <th>Variable</th>
|
||||
* <th>Content</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{nms}</td>
|
||||
* <td>Actual package name of net.minecraft.server.VERSION</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{obc}</td>
|
||||
* <td>Actual package name of org.bukkit.craftbukkit.VERSION</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{version}</td>
|
||||
* <td>The current Minecraft package VERSION, if any.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* @param lookupName - the class name with variables.
|
||||
* @return The looked up class.
|
||||
* @throws IllegalArgumentException If a variable or class could not be found.
|
||||
*/
|
||||
public static Class<?> getClass(String lookupName) {
|
||||
return getCanonicalClass(expandVariables(lookupName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a class in the net.minecraft.server.VERSION.* package.
|
||||
*
|
||||
@ -331,57 +190,6 @@ public final class Reflection {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand variables such as "{nms}" and "{obc}" to their corresponding packages.
|
||||
*
|
||||
* @param name - the full name of the class.
|
||||
* @return The expanded string.
|
||||
*/
|
||||
private static String expandVariables(String name) {
|
||||
StringBuffer output = new StringBuffer();
|
||||
Matcher matcher = MATCH_VARIABLE.matcher(name);
|
||||
|
||||
while (matcher.find()) {
|
||||
String variable = matcher.group(1);
|
||||
String replacement;
|
||||
|
||||
// Expand all detected variables
|
||||
if ("nms".equalsIgnoreCase(variable)) {
|
||||
replacement = NMS_PREFIX;
|
||||
} else if ("obc".equalsIgnoreCase(variable)) {
|
||||
replacement = OBC_PREFIX;
|
||||
} else if ("version".equalsIgnoreCase(variable)) {
|
||||
replacement = VERSION;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown variable: " + variable);
|
||||
}
|
||||
|
||||
// Assume the expanded variables are all packages, and append a dot
|
||||
if (!replacement.isEmpty() && matcher.end() < name.length() && name.charAt(matcher.end()) != '.') {
|
||||
replacement += ".";
|
||||
}
|
||||
matcher.appendReplacement(output, Matcher.quoteReplacement(replacement));
|
||||
}
|
||||
|
||||
matcher.appendTail(output);
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* An interface for invoking a specific constructor.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ConstructorInvoker {
|
||||
|
||||
/**
|
||||
* Invoke a constructor for a specific class.
|
||||
*
|
||||
* @param arguments - the arguments to pass to the constructor.
|
||||
* @return The constructed object.
|
||||
*/
|
||||
Object invoke(Object... arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* An interface for invoking a specific method.
|
||||
*/
|
||||
|
@ -87,7 +87,7 @@ public class BungeeTaskSystem extends TaskSystem {
|
||||
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
|
||||
Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.get(DataGatheringSettings.PING)) {
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(pingCounter);
|
||||
long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS);
|
||||
registerTask(pingCounter).runTaskTimer(startDelay, 40L);
|
||||
|
@ -118,7 +118,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
|
||||
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
|
||||
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
|
||||
sessionCache.endSession(playerUUID, System.currentTimeMillis());
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
processing.submit(() -> {
|
||||
@ -194,7 +194,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
session.putRawData(SessionKeys.NAME, playerName);
|
||||
session.putRawData(SessionKeys.SERVER_NAME, "Proxy Server");
|
||||
sessionCache.cacheSession(playerUUID, session);
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ public class ManageExportCommand extends CommandNode {
|
||||
}
|
||||
|
||||
private void exportServerJSON(Sender sender) {
|
||||
if (!config.get(ExportSettings.SERVER_JSON)) {
|
||||
if (config.isFalse(ExportSettings.SERVER_JSON)) {
|
||||
sender.sendMessage("§c'" + ExportSettings.SERVER_JSON.getPath() + "': false");
|
||||
return;
|
||||
}
|
||||
@ -133,9 +133,9 @@ public class ManageExportCommand extends CommandNode {
|
||||
}
|
||||
|
||||
private void exportPlayers(Sender sender) {
|
||||
boolean exportPlayerJSON = config.get(ExportSettings.PLAYER_JSON);
|
||||
boolean exportPlayerHTML = config.get(ExportSettings.PLAYER_PAGES);
|
||||
boolean exportPlayersHtml = config.get(ExportSettings.PLAYERS_PAGE);
|
||||
boolean exportPlayerJSON = config.isTrue(ExportSettings.PLAYER_JSON);
|
||||
boolean exportPlayerHTML = config.isTrue(ExportSettings.PLAYER_PAGES);
|
||||
boolean exportPlayersHtml = config.isTrue(ExportSettings.PLAYERS_PAGE);
|
||||
if (!exportPlayerJSON && !exportPlayerHTML) {
|
||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL));
|
||||
sender.sendMessage("§c'" + ExportSettings.PLAYER_JSON.getPath() + "' & '" + ExportSettings.PLAYER_PAGES.getPath() + "': false");
|
||||
|
@ -78,7 +78,7 @@ public class ExportScheduler {
|
||||
}
|
||||
|
||||
private void scheduleServerPageExport() {
|
||||
if (!config.get(ExportSettings.SERVER_PAGE)) return;
|
||||
if (config.isFalse(ExportSettings.SERVER_PAGE)) return;
|
||||
|
||||
Collection<Server> servers = dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformationCollection());
|
||||
int serverCount = servers.size();
|
||||
|
@ -95,7 +95,7 @@ public class Exporter extends FileExporter {
|
||||
*/
|
||||
public boolean exportServerPage(Server server) throws ExportException {
|
||||
UUID serverUUID = server.getUuid();
|
||||
if (failedServers.contains(serverUUID) || !config.get(ExportSettings.SERVER_PAGE)) return false;
|
||||
if (failedServers.contains(serverUUID) || config.isFalse(ExportSettings.SERVER_PAGE)) return false;
|
||||
|
||||
try {
|
||||
Path toDirectory = getPageExportDirectory();
|
||||
@ -113,7 +113,7 @@ public class Exporter extends FileExporter {
|
||||
|
||||
public boolean exportServerJSON(Server server) throws ExportException {
|
||||
UUID serverUUID = server.getUuid();
|
||||
if (failedServers.contains(serverUUID) || !config.get(ExportSettings.SERVER_JSON)) return false;
|
||||
if (failedServers.contains(serverUUID) || config.isFalse(ExportSettings.SERVER_JSON)) return false;
|
||||
|
||||
try {
|
||||
Path toDirectory = getJSONExportDirectory().resolve(toFileName(server.getName()));
|
||||
@ -139,7 +139,7 @@ public class Exporter extends FileExporter {
|
||||
*/
|
||||
public boolean exportPlayerPage(UUID playerUUID, String playerName) throws ExportException {
|
||||
Path toDirectory = getPageExportDirectory();
|
||||
if (!config.get(ExportSettings.PLAYER_PAGES)) return false;
|
||||
if (config.isFalse(ExportSettings.PLAYER_PAGES)) return false;
|
||||
|
||||
try {
|
||||
playerPageExporter.export(toDirectory, playerUUID, playerName);
|
||||
@ -151,7 +151,7 @@ public class Exporter extends FileExporter {
|
||||
|
||||
public boolean exportPlayersPage() throws ExportException {
|
||||
Path toDirectory = getPageExportDirectory();
|
||||
if (!config.get(ExportSettings.PLAYERS_PAGE)) return false;
|
||||
if (config.isFalse(ExportSettings.PLAYERS_PAGE)) return false;
|
||||
|
||||
try {
|
||||
playersPageExporter.export(toDirectory);
|
||||
@ -171,7 +171,7 @@ public class Exporter extends FileExporter {
|
||||
*/
|
||||
public boolean exportPlayerJSON(UUID playerUUID, String playerName) throws ExportException {
|
||||
Path toDirectory = getJSONExportDirectory();
|
||||
if (!config.get(ExportSettings.PLAYER_JSON)) return false;
|
||||
if (config.isFalse(ExportSettings.PLAYER_JSON)) return false;
|
||||
|
||||
try {
|
||||
playerJSONExporter.export(toDirectory, playerUUID, playerName);
|
||||
|
@ -82,7 +82,7 @@ public class JSONFactory {
|
||||
public String serverPlayersTableJSON(UUID serverUUID) {
|
||||
Integer xMostRecentPlayers = config.get(DisplaySettings.PLAYERS_PER_SERVER_PAGE);
|
||||
Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
|
||||
Boolean openPlayerLinksInNewTab = config.get(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB);
|
||||
boolean openPlayerLinksInNewTab = config.isTrue(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB);
|
||||
|
||||
Database database = dbSystem.getDatabase();
|
||||
|
||||
@ -97,7 +97,7 @@ public class JSONFactory {
|
||||
public String networkPlayersTableJSON() {
|
||||
Integer xMostRecentPlayers = config.get(DisplaySettings.PLAYERS_PER_PLAYERS_PAGE);
|
||||
Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
|
||||
Boolean openPlayerLinksInNewTab = config.get(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB);
|
||||
boolean openPlayerLinksInNewTab = config.isTrue(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB);
|
||||
|
||||
Database database = dbSystem.getDatabase();
|
||||
|
||||
|
@ -147,7 +147,7 @@ public class WebServer implements SubSystem {
|
||||
new BasicThreadFactory.Builder()
|
||||
.namingPattern("Plan WebServer Thread-%d")
|
||||
.uncaughtExceptionHandler((thread, throwable) -> {
|
||||
if (config.get(PluginSettings.DEV_MODE)) {
|
||||
if (config.isTrue(PluginSettings.DEV_MODE)) {
|
||||
errorHandler.log(L.WARN, WebServer.class, throwable);
|
||||
}
|
||||
}).build()
|
||||
|
@ -59,10 +59,10 @@ public class GMTimes extends TimeKeeper {
|
||||
|
||||
public static String magicNumberToGMName(int magicNumber) {
|
||||
switch (magicNumber) {
|
||||
case 0: return "SURVIVAL";
|
||||
case 1: return "CREATIVE";
|
||||
case 2: return "ADVENTURE";
|
||||
case 3: return "SPECTATOR";
|
||||
case 0: return SURVIVAL;
|
||||
case 1: return CREATIVE;
|
||||
case 2: return ADVENTURE;
|
||||
case 3: return SPECTATOR;
|
||||
default: return "UNKOWN";
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ import java.util.TimeZone;
|
||||
*/
|
||||
public class TimeZoneUtility {
|
||||
|
||||
private TimeZoneUtility() {
|
||||
// Static utility class
|
||||
}
|
||||
|
||||
public static Optional<TimeZone> parseTimeZone(String value) {
|
||||
if ("server".equalsIgnoreCase(value)) return Optional.of(TimeZone.getDefault());
|
||||
|
||||
|
@ -84,14 +84,14 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
this.logger = logger;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
devMode = config.get(PluginSettings.DEV_MODE);
|
||||
devMode = config.isTrue(PluginSettings.DEV_MODE);
|
||||
|
||||
this.transactionExecutorServiceProvider = () -> {
|
||||
String nameFormat = "Plan " + getClass().getSimpleName() + "-transaction-thread-%d";
|
||||
return Executors.newSingleThreadExecutor(new BasicThreadFactory.Builder()
|
||||
.namingPattern(nameFormat)
|
||||
.uncaughtExceptionHandler((thread, throwable) -> {
|
||||
if (config.get(PluginSettings.DEV_MODE)) {
|
||||
if (devMode) {
|
||||
errorHandler.log(L.WARN, getClass(), throwable);
|
||||
}
|
||||
}).build());
|
||||
|
@ -31,21 +31,23 @@ import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
|
||||
*/
|
||||
public class DeleteIPsPatch extends Patch {
|
||||
|
||||
private final String oldTableName;
|
||||
private final String tempTableName;
|
||||
|
||||
public DeleteIPsPatch() {
|
||||
oldTableName = "plan_ips";
|
||||
tempTableName = "temp_ips";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
return !hasTable("plan_ips");
|
||||
return !hasTable(oldTableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyPatch() {
|
||||
if (hasTable(GeoInfoTable.TABLE_NAME) && hasLessDataInPlanIPs()) {
|
||||
dropTable("plan_ips");
|
||||
dropTable(oldTableName);
|
||||
return;
|
||||
}
|
||||
tempOldTable();
|
||||
@ -68,7 +70,7 @@ public class DeleteIPsPatch extends Patch {
|
||||
}
|
||||
|
||||
private boolean hasLessDataInPlanIPs() {
|
||||
Integer inIPs = query(new QueryAllStatement<Integer>(SELECT + "COUNT(1) as c" + FROM + "plan_ips") {
|
||||
Integer inIPs = query(new QueryAllStatement<Integer>(SELECT + "COUNT(1) as c" + FROM + oldTableName) {
|
||||
@Override
|
||||
public Integer processResults(ResultSet set) throws SQLException {
|
||||
return set.next() ? set.getInt("c") : 0;
|
||||
@ -85,7 +87,7 @@ public class DeleteIPsPatch extends Patch {
|
||||
|
||||
private void tempOldTable() {
|
||||
if (!hasTable(tempTableName)) {
|
||||
renameTable("plan_ips", tempTableName);
|
||||
renameTable(oldTableName, tempTableName);
|
||||
}
|
||||
}
|
||||
}
|
@ -53,13 +53,13 @@ public class RegisterDateMinimizationPatch extends Patch {
|
||||
return new QueryAllStatement<Map<UUID, Long>>(sql, 500) {
|
||||
@Override
|
||||
public Map<UUID, Long> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, Long> registerDates = new HashMap<>();
|
||||
Map<UUID, Long> dates = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID playerUUID = UUID.fromString(set.getString(1));
|
||||
long newRegisterDate = set.getLong("min_registered");
|
||||
registerDates.put(playerUUID, newRegisterDate);
|
||||
dates.put(playerUUID, newRegisterDate);
|
||||
}
|
||||
return registerDates;
|
||||
return dates;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -30,6 +30,7 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* In charge of registering built in {@link com.djrapitops.plan.extension.DataExtension} implementations.
|
||||
@ -39,13 +40,13 @@ import java.util.function.Function;
|
||||
@Singleton
|
||||
public class ExtensionRegister {
|
||||
|
||||
private final Function<String, Boolean> isExtensionEnabledInConfig;
|
||||
private final Predicate<String> isExtensionEnabledInConfig;
|
||||
private IllegalStateException registerException;
|
||||
private Set<String> disabledExtensions;
|
||||
private ExtensionService extensionService;
|
||||
|
||||
@Inject
|
||||
public ExtensionRegister(@Named("isExtensionEnabled") Function<String, Boolean> isExtensionEnabledInConfig) {
|
||||
public ExtensionRegister(@Named("isExtensionEnabled") Predicate<String> isExtensionEnabledInConfig) {
|
||||
/* Required for dagger injection */
|
||||
this.isExtensionEnabledInConfig = isExtensionEnabledInConfig;
|
||||
}
|
||||
@ -98,7 +99,7 @@ public class ExtensionRegister {
|
||||
String factoryName = factory.getSimpleName();
|
||||
String extensionName = factoryName.replace("ExtensionFactory", "");
|
||||
|
||||
if (!isExtensionEnabledInConfig.apply(extensionName)) {
|
||||
if (!isExtensionEnabledInConfig.test(extensionName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class NukkitTaskSystem extends TaskSystem {
|
||||
|
||||
private void registerPingCounter() {
|
||||
Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.get(DataGatheringSettings.PING)) {
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(pingCounter);
|
||||
long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS);
|
||||
registerTask(pingCounter).runTaskTimer(startDelay, 40L);
|
||||
|
@ -76,6 +76,6 @@ public class NukkitListenerSystem extends ListenerSystem {
|
||||
|
||||
@Override
|
||||
public void callEnableEvent(PlanPlugin plugin) {
|
||||
|
||||
// EnableEvent was not implemented for Nukkit. If you need it please send a PR.
|
||||
}
|
||||
}
|
||||
|
@ -68,10 +68,7 @@ public class NukkitAFKListener implements Listener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
Boolean ignored = ignorePermissionInfo.get(uuid);
|
||||
if (ignored == null) {
|
||||
ignored = player.hasPermission(Permissions.IGNORE_AFK.getPermission());
|
||||
}
|
||||
boolean ignored = ignorePermissionInfo.computeIfAbsent(uuid, keyUUID -> player.hasPermission(Permissions.IGNORE_AFK.getPermission()));
|
||||
if (ignored) {
|
||||
AFK_TRACKER.hasIgnorePermission(uuid);
|
||||
ignorePermissionInfo.put(uuid, true);
|
||||
|
@ -185,7 +185,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
));
|
||||
|
||||
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
}
|
||||
@ -225,7 +225,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
sessionCache.endSession(playerUUID, time)
|
||||
.ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));
|
||||
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class SpongeTaskSystem extends TaskSystem {
|
||||
|
||||
private void registerPingCounter() {
|
||||
Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.get(DataGatheringSettings.PING)) {
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(pingCounter);
|
||||
long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS);
|
||||
registerTask(pingCounter).runTaskTimer(startDelay, 40L);
|
||||
|
@ -190,7 +190,7 @@ public class PlayerOnlineListener {
|
||||
));
|
||||
|
||||
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
}
|
||||
@ -231,7 +231,7 @@ public class PlayerOnlineListener {
|
||||
sessionCache.endSession(playerUUID, time)
|
||||
.ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));
|
||||
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
}
|
||||
|
@ -89,10 +89,7 @@ public class SpongeAFKListener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
Boolean ignored = ignorePermissionInfo.get(uuid);
|
||||
if (ignored == null) {
|
||||
ignored = player.hasPermission(Permissions.IGNORE_AFK.getPermission());
|
||||
}
|
||||
boolean ignored = ignorePermissionInfo.computeIfAbsent(uuid, keyUUID -> player.hasPermission(Permissions.IGNORE_AFK.getPermission()));
|
||||
if (ignored) {
|
||||
AFK_TRACKER.hasIgnorePermission(uuid);
|
||||
ignorePermissionInfo.put(uuid, true);
|
||||
|
@ -86,7 +86,7 @@ public class VelocityTaskSystem extends TaskSystem {
|
||||
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
|
||||
Long pingDelay = config.get(TimeSettings.PING_SERVER_ENABLE_DELAY);
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.get(DataGatheringSettings.PING)) {
|
||||
if (pingDelay < TimeUnit.HOURS.toMillis(1L) && config.isTrue(DataGatheringSettings.PING)) {
|
||||
plugin.registerListener(pingCounter);
|
||||
long startDelay = TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS);
|
||||
registerTask(pingCounter).runTaskTimer(startDelay, 40L);
|
||||
|
@ -122,7 +122,7 @@ public class PlayerOnlineListener {
|
||||
|
||||
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
|
||||
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ public class PlayerOnlineListener {
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
|
||||
sessionCache.endSession(playerUUID, System.currentTimeMillis());
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ public class PlayerOnlineListener {
|
||||
session.putRawData(SessionKeys.SERVER_NAME, "Proxy Server");
|
||||
sessionCache.cacheSession(playerUUID, session);
|
||||
|
||||
if (config.get(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
|
||||
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user