Fixed a bunch of IntelliJ inspection issues and typos

This commit is contained in:
Risto Lahtela 2021-03-23 11:57:01 +02:00
parent bde57a0bdf
commit 2997e882a5
69 changed files with 410 additions and 540 deletions

View File

@ -65,7 +65,7 @@ public interface CapabilityService {
}
class ListHolder {
static volatile AtomicReference<List<Consumer<Boolean>>> enableListeners = new AtomicReference<>(
static final AtomicReference<List<Consumer<Boolean>>> enableListeners = new AtomicReference<>(
new CopyOnWriteArrayList<>()
);

View File

@ -50,7 +50,7 @@ public interface ResolverService {
void registerResolver(String pluginName, String start, Resolver resolver);
/**
* Register a new resolver with regex that maches start of target.
* Register a new resolver with regex that matches start of target.
* <p>
* NOTICE: It is recommended to avoid too generic regex like "/.*" to not override existing resolvers.
* <p>
@ -89,7 +89,7 @@ public interface ResolverService {
List<Resolver> getResolvers(String target);
class Holder {
static volatile AtomicReference<ResolverService> service = new AtomicReference<>();
static final AtomicReference<ResolverService> service = new AtomicReference<>();
private Holder() {
/* Static variable holder */

View File

@ -55,13 +55,13 @@ public interface ResourceService {
* @param pluginName Name of your plugin (for config purposes)
* @param fileName Name of the .html file being modified
* @param position Where to place the script tag on the page.
* @param jsSrcs Source URLs.
* @param jsSources Source URLs.
* @throws IllegalArgumentException If pluginName is empty or null
* @throws IllegalArgumentException If fileName is null, empty or does not end with .html
* @throws IllegalArgumentException If position null
* @throws IllegalArgumentException If jsSrcs is empty or null
* @throws IllegalArgumentException If jsSources is empty or null
*/
void addScriptsToResource(String pluginName, String fileName, Position position, String... jsSrcs);
void addScriptsToResource(String pluginName, String fileName, Position position, String... jsSources);
/**
* Add css to load in an existing html resource.
@ -71,13 +71,13 @@ public interface ResourceService {
* @param pluginName Name of your plugin (for config purposes)
* @param fileName Name of the .html file being modified
* @param position Where to place the link tag on the page.
* @param cssSrcs Source URLs.
* @param cssSources Source URLs.
* @throws IllegalArgumentException If pluginName is empty or null
* @throws IllegalArgumentException If fileName is null, empty or does not end with .html
* @throws IllegalArgumentException If position null
* @throws IllegalArgumentException If cssSrcs is empty or null
* @throws IllegalArgumentException If cssSources is empty or null
*/
void addStylesToResource(String pluginName, String fileName, Position position, String... cssSrcs);
void addStylesToResource(String pluginName, String fileName, Position position, String... cssSources);
enum Position {
/**
@ -103,7 +103,7 @@ public interface ResourceService {
}
class Holder {
static volatile AtomicReference<ResourceService> service = new AtomicReference<>();
static final AtomicReference<ResourceService> service = new AtomicReference<>();
private Holder() {
/* Static variable holder */

View File

@ -71,7 +71,7 @@ public interface ExtensionService {
void unregister(DataExtension extension);
class Holder {
static volatile AtomicReference<ExtensionService> service = new AtomicReference<>();
static final AtomicReference<ExtensionService> service = new AtomicReference<>();
private Holder() {
/* Static variable holder */

View File

@ -110,9 +110,9 @@ public final class Table {
building = new Table();
}
private Factory column(int indx, String columnName, Icon icon) {
building.columns[indx] = StringUtils.truncate(columnName, 50);
building.icons[indx] = icon != null ? Icon.called(icon.getName()).of(icon.getFamily()).build() : Icon.called("question").build();
private Factory column(int index, String columnName, Icon icon) {
building.columns[index] = StringUtils.truncate(columnName, 50);
building.icons[index] = icon != null ? Icon.called(icon.getName()).of(icon.getFamily()).build() : Icon.called("question").build();
return this;
}

View File

@ -113,7 +113,7 @@ public interface QueryService {
/**
* Get the UUID of this server.
*
* @return Optinal of the server UUID, empty if server did not start properly.
* @return Optional of the server UUID, empty if server did not start properly.
*/
Optional<UUID> getServerUUID();
@ -150,7 +150,7 @@ public interface QueryService {
}
class Holder {
static volatile AtomicReference<QueryService> service = new AtomicReference<>();
static final AtomicReference<QueryService> service = new AtomicReference<>();
private Holder() {
/* Static variable holder */

View File

@ -66,7 +66,7 @@ public interface SettingsService {
List<String> getStringList(String path, Supplier<List<String>> defaultValue);
class Holder {
static volatile AtomicReference<SettingsService> service = new AtomicReference<>();
static final AtomicReference<SettingsService> service = new AtomicReference<>();
private Holder() {
/* Static variable holder */

View File

@ -101,6 +101,7 @@ public class DeathEventListener implements Listener {
public String findWeapon(Entity dead) {
EntityDamageEvent entityDamageEvent = dead.getLastDamageCause();
if (entityDamageEvent == null) return "Unknown (No damage cause defined)";
Entity killer = ((EntityDamageByEntityEvent) entityDamageEvent).getDamager();
if (killer instanceof Player) return getItemInHand((Player) killer);
if (killer instanceof Tameable) return getPetType((Tameable) killer);

View File

@ -27,8 +27,6 @@ import org.bukkit.Bukkit;
import org.bukkit.Server;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
/**
* An utility class that simplifies reflection in Bukkit plugins.
@ -111,52 +109,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 clazz - a class to start with.
* @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(Class<?> clazz, String methodName, Class<?>... params) {
return getTypedMethod(clazz, methodName, null, params);
}
/**
* Search for the first publicly and privately defined method of the given name and parameter count.
*
* @param clazz - a class to start with.
* @param methodName - the method name, or NULL to skip.
* @param returnType - the expected return type, or NULL to ignore.
* @param params - the expected parameters.
* @return An object that invokes this specific method.
* @throws IllegalStateException If we cannot find this method.
*/
public static MethodInvoker getTypedMethod(Class<?> clazz, String methodName, Class<?> returnType, Class<?>... params) {
for (final Method method : clazz.getDeclaredMethods()) {
if ((methodName == null || method.getName().equals(methodName)) && (returnType == null) || method.getReturnType().equals(returnType) && Arrays.equals(method.getParameterTypes(), params)) {
method.setAccessible(true);
return (target, arguments) -> {
try {
return method.invoke(target, arguments);
} catch (Exception e) {
throw new IllegalStateException("Cannot invoke method " + method, e);
}
};
}
}
// Search in every superclass
if (clazz.getSuperclass() != null) {
return getMethod(clazz.getSuperclass(), methodName, params);
}
throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params)));
}
/**
* Retrieve a class in the net.minecraft.server.VERSION.* package.
*
@ -193,22 +145,6 @@ public final class Reflection {
}
}
/**
* An interface for invoking a specific method.
*/
@FunctionalInterface
public interface MethodInvoker {
/**
* Invoke a method on a specific target object.
*
* @param target - the target object, or NULL for a static method.
* @param arguments - the arguments to pass to the method.
* @return The return value, or NULL if is void.
*/
Object invoke(Object target, Object... arguments);
}
/**
* An interface for retrieving the field content.
*

View File

@ -29,7 +29,7 @@ import java.util.UUID;
public class BungeeCMDSender implements CMDSender {
CommandSender sender;
final CommandSender sender;
public BungeeCMDSender(CommandSender sender) {
this.sender = sender;

View File

@ -88,7 +88,7 @@ public class BungeeServerInfo extends ServerInfo {
String ip = serverProperties.getIp();
if ("0.0.0.0".equals(ip)) {
logger.error("IP setting still 0.0.0.0 - Configure Alternative_IP/IP that connects to the Proxy server.");
logger.info("Player Analytics partially enabled (Use /planbungee to reload config)");
logger.info("Player Analytics partially enabled (Use /planproxy reload to reload config)");
throw new EnableException("IP setting still 0.0.0.0 - Configure Alternative_IP/IP that connects to the Proxy server.");
}
}

View File

@ -69,14 +69,13 @@ public class DataSvc implements DataService {
}
@Override
public <A> Optional<A> pull(Class<A> type) {
Supplier present = this.suppliers.get(type);
if (present != null) return Optional.ofNullable((A) present.get());
public <T> Optional<T> pull(Class<T> type) {
Supplier<T> present = this.suppliers.get(type);
if (present != null) return Optional.ofNullable(present.get());
List<Mapper> mappers = this.mappersReverse.get(type);
for (Mapper mapper : mappers) {
Optional found = pull(mapper.typeA)
.map(data -> mapper.func.apply(data));
Optional<T> found = pull(mapper.typeA).map(mapper.func);
if (found.isPresent()) return found;
}
@ -89,7 +88,7 @@ public class DataSvc implements DataService {
List<Mapper> mappers = this.mappers.get(from.getClass());
for (Mapper mapper : mappers) {
if (mapper.typeB.equals(toType)) {
return toType.cast(mapper.func.apply(from));
return toType.cast(mapper.func);
}
}
// TODO Figure out type mapping resolution when it needs more than one mapping

View File

@ -53,6 +53,8 @@ public class PlanCommand {
private final ImportSystem importSystem;
private final ErrorLogger errorLogger;
private final String DB_ARG_OPTIONS = "MySQL/SQlite/H2";
@Inject
public PlanCommand(
@Named("mainCommandName") String commandName,
@ -340,7 +342,7 @@ public class PlanCommand {
return Subcommand.builder()
.aliases("backup")
.requirePermission(Permissions.DATA_BACKUP)
.optionalArgument("MySQL/SQlite/H2", locale.getString(HelpLang.DESC_ARG_DB_BACKUP))
.optionalArgument(DB_ARG_OPTIONS, locale.getString(HelpLang.DESC_ARG_DB_BACKUP))
.description(locale.getString(HelpLang.DB_BACKUP))
.inDepthDescription(locale.getString(DeepHelpLang.DB_BACKUP))
.onCommand(databaseCommands::onBackup)
@ -354,7 +356,7 @@ public class PlanCommand {
.aliases("restore")
.requirePermission(Permissions.DATA_RESTORE)
.requiredArgument(locale.getString(HelpLang.ARG_BACKUP_FILE), locale.getString(HelpLang.DESC_ARG_BACKUP_FILE))
.optionalArgument("MySQL/SQlite/H2", locale.getString(HelpLang.DESC_ARG_DB_RESTORE))
.optionalArgument(DB_ARG_OPTIONS, locale.getString(HelpLang.DESC_ARG_DB_RESTORE))
.description(locale.getString(HelpLang.DB_RESTORE))
.inDepthDescription(locale.getString(DeepHelpLang.DB_RESTORE))
.onCommand((sender, arguments) -> databaseCommands.onRestore(commandName, sender, arguments))
@ -378,8 +380,8 @@ public class PlanCommand {
return Subcommand.builder()
.aliases("move")
.requirePermission(Permissions.DATA_MOVE)
.requiredArgument("MySQL/SQlite/H2", locale.getString(HelpLang.DESC_ARG_DB_MOVE_FROM))
.requiredArgument("MySQL/SQlite/H2", locale.getString(HelpLang.DESC_ARG_DB_MOVE_TO))
.requiredArgument(DB_ARG_OPTIONS, locale.getString(HelpLang.DESC_ARG_DB_MOVE_FROM))
.requiredArgument(DB_ARG_OPTIONS, locale.getString(HelpLang.DESC_ARG_DB_MOVE_TO))
.description(locale.getString(HelpLang.DB_MOVE))
.inDepthDescription(locale.getString(DeepHelpLang.DB_MOVE))
.onCommand((sender, arguments) -> databaseCommands.onMove(commandName, sender, arguments))
@ -391,7 +393,7 @@ public class PlanCommand {
return Subcommand.builder()
.aliases("hotswap")
.requirePermission(Permissions.DATA_HOTSWAP)
.requiredArgument("MySQL/SQlite/H2", locale.getString(HelpLang.DESC_ARG_DB_HOTSWAP))
.requiredArgument(DB_ARG_OPTIONS, locale.getString(HelpLang.DESC_ARG_DB_HOTSWAP))
.description(locale.getString(HelpLang.DB_HOTSWAP))
.inDepthDescription(locale.getString(DeepHelpLang.DB_HOTSWAP))
.onCommand(databaseCommands::onHotswap)
@ -404,7 +406,7 @@ public class PlanCommand {
return Subcommand.builder()
.aliases("clear")
.requirePermission(Permissions.DATA_CLEAR)
.requiredArgument("MySQL/SQlite/H2", locale.getString(HelpLang.DESC_ARG_DB_REMOVE))
.requiredArgument(DB_ARG_OPTIONS, locale.getString(HelpLang.DESC_ARG_DB_REMOVE))
.description(locale.getString(HelpLang.DB_CLEAR))
.inDepthDescription(locale.getString(DeepHelpLang.DB_CLEAR))
.onCommand((sender, arguments) -> databaseCommands.onClear(commandName, sender, arguments))

View File

@ -37,10 +37,10 @@ public class DateHoldersMutator<T extends DateHolder> {
return map;
}
long sectionLenght = TimeUnit.MINUTES.toMillis(1L);
long sectionLength = TimeUnit.MINUTES.toMillis(1L);
for (T holder : dateHolders) {
long date = holder.getDate();
long startOfSection = date - (date % sectionLenght);
long startOfSection = date - (date % sectionLength);
List<T> list = map.computeIfAbsent(startOfSection, Lists::create);
list.add(holder);

View File

@ -94,7 +94,7 @@ public class PingMutator {
long start = session.getDate();
long end = session.getEnd();
if (end < start) continue;
// Calculate average ping for each session with a Ping submap
// Calculate average ping for each session with a section of the Ping map
SortedMap<Long, Ping> duringSession = pingOfServer.subMap(start, end);
for (Ping ping : duringSession.values()) {
pingCount += ping.getAverage();
@ -116,7 +116,7 @@ public class PingMutator {
public int max() {
int max = -1;
for (Ping ping : pings) {
Integer value = ping.getMax();
int value = ping.getMax();
if (value <= 0 || 4000 < value) {
continue;
}
@ -131,7 +131,7 @@ public class PingMutator {
public int min() {
int min = -1;
for (Ping ping : pings) {
Integer value = ping.getMin();
int value = ping.getMin();
if (value <= 0 || 4000 < value) {
continue;
}

View File

@ -34,6 +34,7 @@ import com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries;
import com.djrapitops.plan.storage.database.queries.objects.SessionQueries;
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
import com.djrapitops.plan.storage.database.queries.objects.UserInfoQueries;
import com.djrapitops.plan.utilities.analysis.Percentage;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -132,21 +133,21 @@ public class OnlineActivityOverviewJSONCreator implements ServerTabJSONCreator<M
int retained30d = db.query(PlayerCountQueries.retainedPlayerCount(monthAgo, now, serverUUID));
int retained7d = db.query(PlayerCountQueries.retainedPlayerCount(weekAgo, now, serverUUID));
double retentionPerc30d = new30d != 0 ? (double) retained30d / new30d : -1;
double retentionPerc7d = new7d != 0 ? (double) retained7d / new7d : -1;
double retentionPercentage30d = Percentage.calculate(retained30d, new30d, -1);
double retentionPercentage7d = Percentage.calculate(retained7d, new7d, -1);
numbers.put("new_players_retention_30d", retained30d);
numbers.put("new_players_retention_30d_perc", percentageFormatter.apply(retentionPerc30d));
numbers.put("new_players_retention_30d_perc", percentageFormatter.apply(retentionPercentage30d));
numbers.put("new_players_retention_7d", retained7d);
numbers.put("new_players_retention_7d_perc", percentageFormatter.apply(retentionPerc7d));
numbers.put("new_players_retention_7d_perc", percentageFormatter.apply(retentionPercentage7d));
int prediction1d = RetentionData.countRetentionPrediction(
db.query(ActivityIndexQueries.activityIndexForNewPlayers(dayAgo, now, serverUUID, playThreshold)),
db.query(ActivityIndexQueries.averageActivityIndexForRetainedPlayers(monthAgo, now, serverUUID, playThreshold)),
db.query(ActivityIndexQueries.averageActivityIndexForNonRetainedPlayers(monthAgo, now, serverUUID, playThreshold))
);
double retentionPerc1d = new1d != 0 ? (double) prediction1d / new1d : -1;
double retentionPercentage1d = Percentage.calculate(prediction1d, new1d, -1);
numbers.put("new_players_retention_24h", prediction1d);
numbers.put("new_players_retention_24h_perc", percentageFormatter.apply(retentionPerc1d));
numbers.put("new_players_retention_24h_perc", percentageFormatter.apply(retentionPercentage1d));
Long playtimeMonth = db.query(SessionQueries.playtime(monthAgo, now, serverUUID));
Long playtimeWeek = db.query(SessionQueries.playtime(weekAgo, now, serverUUID));

View File

@ -107,9 +107,9 @@ public class PerformanceJSONCreator implements ServerTabJSONCreator<Map<String,
numbers.put("tps_30d", format(tpsDataMonth.averageTPS()));
numbers.put("tps_7d", format(tpsDataWeek.averageTPS()));
numbers.put("tps_24h", format(tpsDataDay.averageTPS()));
numbers.put("cpu_30d", formatPerc(tpsDataMonth.averageCPU()));
numbers.put("cpu_7d", formatPerc(tpsDataWeek.averageCPU()));
numbers.put("cpu_24h", formatPerc(tpsDataDay.averageCPU()));
numbers.put("cpu_30d", formatPercentage(tpsDataMonth.averageCPU()));
numbers.put("cpu_7d", formatPercentage(tpsDataWeek.averageCPU()));
numbers.put("cpu_24h", formatPercentage(tpsDataDay.averageCPU()));
numbers.put("ram_30d", formatBytes(tpsDataMonth.averageRAM()));
numbers.put("ram_7d", formatBytes(tpsDataWeek.averageRAM()));
numbers.put("ram_24h", formatBytes(tpsDataDay.averageRAM()));
@ -138,7 +138,7 @@ public class PerformanceJSONCreator implements ServerTabJSONCreator<Map<String,
return value != -1 ? byteSize.apply(value) : locale.get(GenericLang.UNAVAILABLE).toString();
}
private String formatPerc(double value) {
private String formatPercentage(double value) {
return value != -1 ? percentage.apply(value / 100.0) : locale.get(GenericLang.UNAVAILABLE).toString();
}

View File

@ -26,6 +26,7 @@ import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.queries.analysis.ActivityIndexQueries;
import com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries;
import com.djrapitops.plan.storage.database.queries.objects.SessionQueries;
import com.djrapitops.plan.utilities.analysis.Percentage;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -96,11 +97,11 @@ public class PlayerBaseOverviewJSONCreator implements ServerTabJSONCreator<Map<S
Long avgAfkBefore = db.query(SessionQueries.averageAfkPerPlayer(twoMonthsAgo, monthAgo, serverUUID));
Long avgAfkAfter = db.query(SessionQueries.averageAfkPerPlayer(monthAgo, now, serverUUID));
double afkPercBefore = avgPlaytimeBefore != 0 ? (double) avgAfkBefore / avgPlaytimeBefore : 0;
double afkPercAfter = avgPlaytimeAfter != 0 ? (double) avgAfkAfter / avgPlaytimeAfter : 0;
trends.put("afk_then", percentage.apply(afkPercBefore));
trends.put("afk_now", percentage.apply(afkPercAfter));
trends.put("afk_trend", new Trend(afkPercBefore, afkPercAfter, Trend.REVERSED, percentage));
double afkPercentageBefore = Percentage.calculate(avgAfkBefore, avgPlaytimeBefore);
double afkPercentageAfter = Percentage.calculate(avgAfkAfter, avgPlaytimeAfter);
trends.put("afk_then", percentage.apply(afkPercentageBefore));
trends.put("afk_now", percentage.apply(afkPercentageAfter));
trends.put("afk_trend", new Trend(afkPercentageBefore, afkPercentageAfter, Trend.REVERSED, percentage));
Long avgRegularPlaytimeBefore = db.query(ActivityIndexQueries.averagePlaytimePerRegularPlayer(twoMonthsAgo, monthAgo, serverUUID, playThreshold));
Long avgRegularPlaytimeAfter = db.query(ActivityIndexQueries.averagePlaytimePerRegularPlayer(monthAgo, now, serverUUID, playThreshold));
@ -116,11 +117,11 @@ public class PlayerBaseOverviewJSONCreator implements ServerTabJSONCreator<Map<S
Long avgRegularAfkBefore = db.query(ActivityIndexQueries.averageAFKPerRegularPlayer(twoMonthsAgo, monthAgo, serverUUID, playThreshold));
Long avgRegularAfkAfter = db.query(ActivityIndexQueries.averageAFKPerRegularPlayer(monthAgo, now, serverUUID, playThreshold));
double afkRegularPercBefore = avgRegularPlaytimeBefore != 0 ? (double) avgRegularAfkBefore / avgRegularPlaytimeBefore : 0;
double afkRegularPercAfter = avgRegularPlaytimeAfter != 0 ? (double) avgRegularAfkAfter / avgRegularPlaytimeAfter : 0;
trends.put("regular_afk_avg_then", percentage.apply(afkRegularPercBefore));
trends.put("regular_afk_avg_now", percentage.apply(afkRegularPercAfter));
trends.put("regular_afk_avg_trend", new Trend(afkRegularPercBefore, afkRegularPercAfter, Trend.REVERSED, percentage));
double afkRegularPercentageBefore = Percentage.calculate(avgRegularAfkBefore, avgRegularPlaytimeBefore);
double afkRegularPercentageAfter = Percentage.calculate(avgRegularAfkAfter, avgRegularPlaytimeAfter);
trends.put("regular_afk_avg_then", percentage.apply(afkRegularPercentageBefore));
trends.put("regular_afk_avg_now", percentage.apply(afkRegularPercentageAfter));
trends.put("regular_afk_avg_trend", new Trend(afkRegularPercentageBefore, afkRegularPercentageAfter, Trend.REVERSED, percentage));
return trends;
}

View File

@ -44,7 +44,7 @@ import java.util.*;
public class PlayersTableJSONCreator {
private final List<TablePlayer> players;
private final List<ExtensionDescriptive> extensionDescriptives;
private final List<ExtensionDescription> extensionDescriptions;
private final Map<UUID, ExtensionTabData> extensionData;
private final Locale locale;
@ -67,9 +67,9 @@ public class PlayersTableJSONCreator {
this.extensionData = extensionData;
this.locale = locale;
extensionDescriptives = new ArrayList<>();
addExtensionDescriptives(extensionData);
extensionDescriptives.sort((one, two) -> String.CASE_INSENSITIVE_ORDER.compare(one.getName(), two.getName()));
extensionDescriptions = new ArrayList<>();
addExtensionDescriptions(extensionData);
extensionDescriptions.sort((one, two) -> String.CASE_INSENSITIVE_ORDER.compare(one.getName(), two.getName()));
// Settings
this.openPlayerPageInNewTab = openPlayerPageInNewTab;
@ -83,13 +83,13 @@ public class PlayersTableJSONCreator {
this.decimalFormatter = formatters.decimals();
}
private void addExtensionDescriptives(Map<UUID, ExtensionTabData> extensionData) {
Set<String> foundDescriptives = new HashSet<>();
private void addExtensionDescriptions(Map<UUID, ExtensionTabData> extensionData) {
Set<String> foundDescriptions = new HashSet<>();
for (ExtensionTabData tabData : extensionData.values()) {
for (ExtensionDescriptive descriptive : tabData.getDescriptives()) {
if (!foundDescriptives.contains(descriptive.getName())) {
extensionDescriptives.add(descriptive);
foundDescriptives.add(descriptive.getName());
for (ExtensionDescription description : tabData.getDescriptions()) {
if (!foundDescriptions.contains(description.getName())) {
extensionDescriptions.add(description);
foundDescriptions.add(description.getName());
}
}
}
@ -159,8 +159,8 @@ public class PlayersTableJSONCreator {
}
private void addExtensionData(Map<String, Object> dataJson, ExtensionTabData tabData) {
for (ExtensionDescriptive descriptive : extensionDescriptives) {
addValue(dataJson, tabData, descriptive.getName());
for (ExtensionDescription description : extensionDescriptions) {
addValue(dataJson, tabData, description.getName());
}
}
@ -219,7 +219,7 @@ public class PlayersTableJSONCreator {
}
private void addExtensionHeaders(List<Map<String, Object>> columnHeaders) {
for (ExtensionDescriptive provider : extensionDescriptives) {
for (ExtensionDescription provider : extensionDescriptions) {
String headerText = Icon.fromExtensionIcon(provider.getIcon().setColor(Color.NONE)).toHtml().replace('"', '\'') + ' ' + provider.getText();
columnHeaders.add(makeFColumnHeader(headerText, provider.getName()));
}

View File

@ -38,6 +38,7 @@ import com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries;
import com.djrapitops.plan.storage.database.queries.objects.KillQueries;
import com.djrapitops.plan.storage.database.queries.objects.SessionQueries;
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
import com.djrapitops.plan.utilities.analysis.Percentage;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -108,11 +109,11 @@ public class ServerOverviewJSONCreator implements ServerTabJSONCreator<Map<Strin
int new7d = db.query(PlayerCountQueries.newPlayerCount(weekAgo, now, serverUUID));
int retained7d = db.query(PlayerCountQueries.retainedPlayerCount(weekAgo, now, serverUUID));
double retentionPerc7d = new7d != 0 ? (double) retained7d / new7d : -1;
double retentionPercentage7d = Percentage.calculate(retained7d, new7d, -1);
sevenDays.put("new_players", new7d);
sevenDays.put("new_players_retention", retained7d);
sevenDays.put("new_players_retention_perc", percentage.apply(retentionPerc7d));
sevenDays.put("new_players_retention_perc", percentage.apply(retentionPercentage7d));
TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(weekAgo, now, serverUUID)));
double averageTPS = tpsMutator.averageTPS();
sevenDays.put("average_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(GenericLang.UNAVAILABLE).toString());

View File

@ -27,6 +27,7 @@ import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.queries.objects.SessionQueries;
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
import com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries;
import com.djrapitops.plan.utilities.analysis.Percentage;
import org.apache.commons.text.WordUtils;
import javax.inject.Inject;
@ -75,19 +76,19 @@ public class SessionsOverviewJSONCreator implements ServerTabJSONCreator<Map<Str
long uptime = TimeUnit.DAYS.toMillis(30L) - tpsMutator.serverDownTime();
long occupied = tpsMutator.serverOccupiedTime();
insights.put("server_occupied", timeAmount.apply(occupied));
insights.put("server_occupied_perc", uptime != 0 ? percentage.apply(1.0 * occupied / uptime) : "-");
insights.put("server_occupied_perc", percentage.apply(Percentage.calculate(occupied, uptime, -1)));
Long playtime = db.query(SessionQueries.playtime(monthAgo, now, serverUUID));
Long afkTime = db.query(SessionQueries.afkTime(monthAgo, now, serverUUID));
insights.put("total_playtime", timeAmount.apply(playtime));
insights.put("afk_time", timeAmount.apply(afkTime));
insights.put("afk_time_perc", playtime != 0 ? percentage.apply(1.0 * afkTime / playtime) : "-");
insights.put("afk_time_perc", percentage.apply(Percentage.calculate(afkTime, playtime, -1)));
GMTimes gmTimes = db.query(WorldTimesQueries.fetchGMTimes(monthAgo, now, serverUUID));
Optional<String> mostUsedGameMode = gmTimes.getMostUsedGameMode();
Long longestGMTime = mostUsedGameMode.map(gmTimes::getTime).orElse(-1L);
insights.put("most_active_gamemode", mostUsedGameMode.map(WordUtils::capitalizeFully).orElse("Not Known"));
insights.put("most_active_gamemode_perc", playtime != 0 ? percentage.apply(1.0 * longestGMTime / playtime) : "-");
insights.put("most_active_gamemode_perc", percentage.apply(Percentage.calculate(longestGMTime, playtime, -1)));
return insights;
}

View File

@ -60,7 +60,7 @@ import java.util.NavigableMap;
import java.util.concurrent.TimeUnit;
/**
* Perses Graph related Data JSON.
* Creates Graph related Data JSON.
*
* @author AuroraLS3
*/

View File

@ -64,8 +64,8 @@ public class PieGraphFactory {
return new ServerPreferencePie(serverNames, serverWorldTimes, locale.get(GenericLang.UNKNOWN).toString());
}
public Pie serverPreferencePie(Map<String, Long> serverPlaytimes) {
return new ServerPreferencePie(serverPlaytimes);
public Pie serverPreferencePie(Map<String, Long> playtimeByServerName) {
return new ServerPreferencePie(playtimeByServerName);
}
public Pie joinAddressPie(Map<String, Integer> joinAddresses) {
@ -77,7 +77,7 @@ public class PieGraphFactory {
Map<String, Long> playtimePerAlias = worldAliasSettings.getPlaytimePerAlias(worldTimes);
Map<String, GMTimes> gmTimesPerAlias = worldAliasSettings.getGMTimesPerAlias(worldTimes);
String[] colors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
boolean orderByPercentage = config.isTrue(DisplaySettings.ORDER_WORLD_PIE_BY_PERC);
boolean orderByPercentage = config.isTrue(DisplaySettings.ORDER_WORLD_PIE_BY_PERCENTAGE);
return new WorldPie(playtimePerAlias, gmTimesPerAlias, colors, orderByPercentage);
}
}

View File

@ -49,12 +49,12 @@ public class ServerPreferencePie extends Pie {
return slices;
}
private static List<PieSlice> turnToSlices(Map<String, Long> serverPlaytimes) {
private static List<PieSlice> turnToSlices(Map<String, Long> playtimeByServerName) {
List<PieSlice> slices = new ArrayList<>();
for (Map.Entry<String, Long> server : serverPlaytimes.entrySet()) {
String serverName = server.getKey();
long playtime = server.getValue();
for (Map.Entry<String, Long> playtimeOfServer : playtimeByServerName.entrySet()) {
String serverName = playtimeOfServer.getKey();
long playtime = playtimeOfServer.getValue();
slices.add(new PieSlice(serverName, playtime));
}

View File

@ -26,6 +26,7 @@ import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.queries.analysis.NetworkActivityIndexQueries;
import com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries;
import com.djrapitops.plan.storage.database.queries.objects.SessionQueries;
import com.djrapitops.plan.utilities.analysis.Percentage;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -76,51 +77,51 @@ public class NetworkPlayerBaseOverviewJSONCreator implements NetworkTabJSONCreat
Map<String, Object> trends = new HashMap<>();
Integer playersBefore = db.query(PlayerCountQueries.newPlayerCount(0L, monthAgo));
Integer playersAfter = db.query(PlayerCountQueries.newPlayerCount(0L, now));
int playersBefore = db.query(PlayerCountQueries.newPlayerCount(0L, monthAgo));
int playersAfter = db.query(PlayerCountQueries.newPlayerCount(0L, now));
trends.put("total_players_then", playersBefore);
trends.put("total_players_now", playersAfter);
trends.put("total_players_trend", new Trend(playersBefore, playersAfter, false));
Integer regularBefore = db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(monthAgo, playThreshold));
Integer regularAfter = db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(now, playThreshold));
int regularBefore = db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(monthAgo, playThreshold));
int regularAfter = db.query(NetworkActivityIndexQueries.fetchRegularPlayerCount(now, playThreshold));
trends.put("regular_players_then", regularBefore);
trends.put("regular_players_now", regularAfter);
trends.put("regular_players_trend", new Trend(regularBefore, regularAfter, false));
Long avgPlaytimeBefore = db.query(SessionQueries.averagePlaytimePerPlayer(twoMonthsAgo, monthAgo));
Long avgPlaytimeAfter = db.query(SessionQueries.averagePlaytimePerPlayer(monthAgo, now));
long avgPlaytimeBefore = db.query(SessionQueries.averagePlaytimePerPlayer(twoMonthsAgo, monthAgo));
long avgPlaytimeAfter = db.query(SessionQueries.averagePlaytimePerPlayer(monthAgo, now));
trends.put("playtime_avg_then", timeAmount.apply(avgPlaytimeBefore));
trends.put("playtime_avg_now", timeAmount.apply(avgPlaytimeAfter));
trends.put("playtime_avg_trend", new Trend(avgPlaytimeBefore, avgPlaytimeAfter, false, timeAmount));
Long avgAfkBefore = db.query(SessionQueries.averageAfkPerPlayer(twoMonthsAgo, monthAgo));
Long avgAfkAfter = db.query(SessionQueries.averageAfkPerPlayer(monthAgo, now));
double afkPercBefore = avgPlaytimeBefore != 0 ? (double) avgAfkBefore / avgPlaytimeBefore : 0;
double afkPercAfter = avgPlaytimeAfter != 0 ? (double) avgAfkAfter / avgPlaytimeAfter : 0;
trends.put("afk_then", percentage.apply(afkPercBefore));
trends.put("afk_now", percentage.apply(afkPercAfter));
trends.put("afk_trend", new Trend(afkPercBefore, afkPercAfter, Trend.REVERSED, percentage));
long avgAfkBefore = db.query(SessionQueries.averageAfkPerPlayer(twoMonthsAgo, monthAgo));
long avgAfkAfter = db.query(SessionQueries.averageAfkPerPlayer(monthAgo, now));
double afkPercentageBefore = Percentage.calculate(avgAfkBefore, avgPlaytimeBefore);
double afkPercentageAfter = Percentage.calculate(avgAfkAfter, avgPlaytimeAfter);
trends.put("afk_then", percentage.apply(afkPercentageBefore));
trends.put("afk_now", percentage.apply(afkPercentageAfter));
trends.put("afk_trend", new Trend(afkPercentageBefore, afkPercentageAfter, Trend.REVERSED, percentage));
Long avgRegularPlaytimeBefore = db.query(NetworkActivityIndexQueries.averagePlaytimePerRegularPlayer(twoMonthsAgo, monthAgo, playThreshold));
Long avgRegularPlaytimeAfter = db.query(NetworkActivityIndexQueries.averagePlaytimePerRegularPlayer(monthAgo, now, playThreshold));
long avgRegularPlaytimeBefore = db.query(NetworkActivityIndexQueries.averagePlaytimePerRegularPlayer(twoMonthsAgo, monthAgo, playThreshold));
long avgRegularPlaytimeAfter = db.query(NetworkActivityIndexQueries.averagePlaytimePerRegularPlayer(monthAgo, now, playThreshold));
trends.put("regular_playtime_avg_then", timeAmount.apply(avgRegularPlaytimeBefore));
trends.put("regular_playtime_avg_now", timeAmount.apply(avgRegularPlaytimeAfter));
trends.put("regular_playtime_avg_trend", new Trend(avgRegularPlaytimeBefore, avgRegularPlaytimeAfter, false, timeAmount));
Long avgRegularSessionLengthBefore = db.query(NetworkActivityIndexQueries.averageSessionLengthPerRegularPlayer(twoMonthsAgo, monthAgo, playThreshold));
Long avgRegularSessionLengthAfter = db.query(NetworkActivityIndexQueries.averageSessionLengthPerRegularPlayer(monthAgo, now, playThreshold));
long avgRegularSessionLengthBefore = db.query(NetworkActivityIndexQueries.averageSessionLengthPerRegularPlayer(twoMonthsAgo, monthAgo, playThreshold));
long avgRegularSessionLengthAfter = db.query(NetworkActivityIndexQueries.averageSessionLengthPerRegularPlayer(monthAgo, now, playThreshold));
trends.put("regular_session_avg_then", timeAmount.apply(avgRegularSessionLengthBefore));
trends.put("regular_session_avg_now", timeAmount.apply(avgRegularSessionLengthAfter));
trends.put("regular_session_avg_trend", new Trend(avgRegularSessionLengthBefore, avgRegularSessionLengthAfter, false, timeAmount));
Long avgRegularAfkBefore = db.query(NetworkActivityIndexQueries.averageAFKPerRegularPlayer(twoMonthsAgo, monthAgo, playThreshold));
Long avgRegularAfkAfter = db.query(NetworkActivityIndexQueries.averageAFKPerRegularPlayer(monthAgo, now, playThreshold));
double afkRegularPercBefore = avgRegularPlaytimeBefore != 0 ? (double) avgRegularAfkBefore / avgRegularPlaytimeBefore : 0;
double afkRegularPercAfter = avgRegularPlaytimeAfter != 0 ? (double) avgRegularAfkAfter / avgRegularPlaytimeAfter : 0;
trends.put("regular_afk_avg_then", percentage.apply(afkRegularPercBefore));
trends.put("regular_afk_avg_now", percentage.apply(afkRegularPercAfter));
trends.put("regular_afk_avg_trend", new Trend(afkRegularPercBefore, afkRegularPercAfter, Trend.REVERSED, percentage));
long avgRegularAfkBefore = db.query(NetworkActivityIndexQueries.averageAFKPerRegularPlayer(twoMonthsAgo, monthAgo, playThreshold));
long avgRegularAfkAfter = db.query(NetworkActivityIndexQueries.averageAFKPerRegularPlayer(monthAgo, now, playThreshold));
double afkRegularPercentageBefore = Percentage.calculate(avgRegularAfkBefore, avgRegularPlaytimeBefore);
double afkRegularPercentageAfter = Percentage.calculate(avgRegularAfkAfter, avgRegularPlaytimeAfter);
trends.put("regular_afk_avg_then", percentage.apply(afkRegularPercentageBefore));
trends.put("regular_afk_avg_now", percentage.apply(afkRegularPercentageAfter));
trends.put("regular_afk_avg_trend", new Trend(afkRegularPercentageBefore, afkRegularPercentageAfter, Trend.REVERSED, percentage));
return trends;
}

View File

@ -21,6 +21,7 @@ import com.djrapitops.plan.delivery.formatting.Formatters;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.queries.objects.SessionQueries;
import com.djrapitops.plan.utilities.analysis.Percentage;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -68,7 +69,7 @@ public class NetworkSessionsOverviewJSONCreator implements NetworkTabJSONCreator
Long afkTime = db.query(SessionQueries.afkTime(monthAgo, now));
insights.put("total_playtime", timeAmount.apply(playtime));
insights.put("afk_time", timeAmount.apply(afkTime));
insights.put("afk_time_perc", playtime != 0 ? percentage.apply(1.0 * afkTime / playtime) : "-");
insights.put("afk_time_perc", percentage.apply(Percentage.calculate(afkTime, playtime, -1)));
return insights;
}

View File

@ -193,24 +193,24 @@ public class PlayerPluginTab implements Comparable<PlayerPluginTab> {
private String buildValuesHtml(ExtensionTabData tabData) {
StringBuilder builder = new StringBuilder();
for (String key : tabData.getValueOrder()) {
tabData.getBoolean(key).ifPresent(data -> append(builder, data.getDescriptive(), data.getFormattedValue()));
tabData.getDouble(key).ifPresent(data -> append(builder, data.getDescriptive(), data.getFormattedValue(decimalFormatter)));
tabData.getPercentage(key).ifPresent(data -> append(builder, data.getDescriptive(), data.getFormattedValue(percentageFormatter)));
tabData.getNumber(key).ifPresent(data -> append(builder, data.getDescriptive(), data.getFormattedValue(numberFormatters.get(data.getFormatType()))));
tabData.getString(key).ifPresent(data -> append(builder, data.getDescriptive(), data.getFormattedValue()));
tabData.getBoolean(key).ifPresent(data -> append(builder, data.getDescription(), data.getFormattedValue()));
tabData.getDouble(key).ifPresent(data -> append(builder, data.getDescription(), data.getFormattedValue(decimalFormatter)));
tabData.getPercentage(key).ifPresent(data -> append(builder, data.getDescription(), data.getFormattedValue(percentageFormatter)));
tabData.getNumber(key).ifPresent(data -> append(builder, data.getDescription(), data.getFormattedValue(numberFormatters.get(data.getFormatType()))));
tabData.getString(key).ifPresent(data -> append(builder, data.getDescription(), data.getFormattedValue()));
}
return builder.toString();
}
private void append(StringBuilder builder, ExtensionDescriptive descriptive, String formattedValue) {
Optional<String> description = descriptive.getDescription();
if (description.isPresent()) {
builder.append("<p title=\"").append(description.get()).append("\">");
private void append(StringBuilder builder, ExtensionDescription description, String formattedValue) {
Optional<String> textDescription = description.getDescription();
if (textDescription.isPresent()) {
builder.append("<p title=\"").append(textDescription.get()).append("\">");
} else {
builder.append("<p>");
}
builder.append(Icon.fromExtensionIcon(descriptive.getIcon()))
.append(' ').append(descriptive.getText()).append("<span class=\"float-right\"><b>").append(formattedValue).append("</b></span></p>");
builder.append(Icon.fromExtensionIcon(description.getIcon()))
.append(' ').append(description.getText()).append("<span class=\"float-right\"><b>").append(formattedValue).append("</b></span></p>");
}
private String wrapInContainer(ExtensionInformation information, String tabsElement) {

View File

@ -215,24 +215,24 @@ public class ServerPluginTabs {
private String buildValuesHtml(ExtensionTabData tabData) {
StringBuilder builder = new StringBuilder();
for (String key : tabData.getValueOrder()) {
tabData.getBoolean(key).ifPresent(data -> append(builder, data.getDescriptive(), data.getFormattedValue()));
tabData.getDouble(key).ifPresent(data -> append(builder, data.getDescriptive(), data.getFormattedValue(decimalFormatter)));
tabData.getPercentage(key).ifPresent(data -> append(builder, data.getDescriptive(), data.getFormattedValue(percentageFormatter)));
tabData.getNumber(key).ifPresent(data -> append(builder, data.getDescriptive(), data.getFormattedValue(numberFormatters.get(data.getFormatType()))));
tabData.getString(key).ifPresent(data -> append(builder, data.getDescriptive(), data.getFormattedValue()));
tabData.getBoolean(key).ifPresent(data -> append(builder, data.getDescription(), data.getFormattedValue()));
tabData.getDouble(key).ifPresent(data -> append(builder, data.getDescription(), data.getFormattedValue(decimalFormatter)));
tabData.getPercentage(key).ifPresent(data -> append(builder, data.getDescription(), data.getFormattedValue(percentageFormatter)));
tabData.getNumber(key).ifPresent(data -> append(builder, data.getDescription(), data.getFormattedValue(numberFormatters.get(data.getFormatType()))));
tabData.getString(key).ifPresent(data -> append(builder, data.getDescription(), data.getFormattedValue()));
}
return builder.toString();
}
private void append(StringBuilder builder, ExtensionDescriptive descriptive, String formattedValue) {
Optional<String> description = descriptive.getDescription();
if (description.isPresent()) {
builder.append("<p title=\"").append(description.get()).append("\">");
private void append(StringBuilder builder, ExtensionDescription description, String formattedValue) {
Optional<String> textDescription = description.getDescription();
if (textDescription.isPresent()) {
builder.append("<p title=\"").append(textDescription.get()).append("\">");
} else {
builder.append("<p>");
}
builder.append(Icon.fromExtensionIcon(descriptive.getIcon()))
.append(' ').append(descriptive.getText()).append("<span class=\"float-right\"><b>").append(formattedValue).append("</b></span></p>");
builder.append(Icon.fromExtensionIcon(description.getIcon()))
.append(' ').append(description.getText()).append("<span class=\"float-right\"><b>").append(formattedValue).append("</b></span></p>");
}
private String wrapInContainer(ExtensionInformation information, String tabsElement) {

View File

@ -181,11 +181,11 @@ public class ResourceSvc implements ResourceService {
}
@Override
public void addScriptsToResource(String pluginName, String fileName, Position position, String... jsSrcs) {
checkParams(pluginName, fileName, position, jsSrcs);
public void addScriptsToResource(String pluginName, String fileName, Position position, String... jsSources) {
checkParams(pluginName, fileName, position, jsSources);
String snippet = new TextStringBuilder("<script src=\"")
.appendWithSeparators(jsSrcs, "\"></script><script src=\"")
.appendWithSeparators(jsSources, "\"></script><script src=\"")
.append("\"></script>").build();
snippets.add(new Snippet(pluginName, fileName, position, snippet));
if (!"Plan".equals(pluginName)) {
@ -193,7 +193,7 @@ public class ResourceSvc implements ResourceService {
}
}
public void checkParams(String pluginName, String fileName, Position position, String[] jsSrcs) {
public void checkParams(String pluginName, String fileName, Position position, String[] jsSources) {
if (pluginName == null || pluginName.isEmpty()) {
throw new IllegalArgumentException("'pluginName' can't be '" + pluginName + "'!");
}
@ -206,17 +206,17 @@ public class ResourceSvc implements ResourceService {
if (position == null) {
throw new IllegalArgumentException("'position' can't be null!");
}
if (jsSrcs == null || jsSrcs.length == 0) {
if (jsSources == null || jsSources.length == 0) {
throw new IllegalArgumentException("Can't add snippets to resource without snippets!");
}
}
@Override
public void addStylesToResource(String pluginName, String fileName, Position position, String... cssSrcs) {
checkParams(pluginName, fileName, position, cssSrcs);
public void addStylesToResource(String pluginName, String fileName, Position position, String... cssSources) {
checkParams(pluginName, fileName, position, cssSources);
String snippet = new TextStringBuilder("<link href=\"")
.appendWithSeparators(cssSrcs, "\" rel=\"stylesheet\"></link><link href=\"")
.appendWithSeparators(cssSources, "\" rel=\"stylesheet\"></link><link href=\"")
.append("\" rel=\"stylesheet\">").build();
snippets.add(new Snippet(pluginName, fileName, position, snippet));
if (!"Plan".equals(pluginName)) {

View File

@ -20,7 +20,7 @@ import com.djrapitops.plan.extension.FormatType;
import com.djrapitops.plan.extension.annotation.Conditional;
import com.djrapitops.plan.extension.icon.Color;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescriptive;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescription;
import org.apache.commons.lang3.StringUtils;
import java.util.Objects;
@ -31,7 +31,7 @@ import java.util.Optional;
*
* @author AuroraLS3
*/
public class ProviderInformation extends ExtensionDescriptive {
public class ProviderInformation extends ExtensionDescription {
private final String pluginName;
private final boolean showInPlayersTable;

View File

@ -49,13 +49,13 @@ public class DataProviders {
public <T> List<DataProvider<T>> getProvidersByTypes(MethodType methodType, Class<T> returnType) {
Map<Class<?>, List<DataProvider<?>>> byReturnType = byMethodType.getOrDefault(methodType, Collections.emptyMap());
List<DataProvider<?>> uncastProviders = byReturnType.get(returnType);
if (uncastProviders == null) {
List<DataProvider<?>> wildcardProvidersWithSpecificType = byReturnType.get(returnType);
if (wildcardProvidersWithSpecificType == null) {
return Collections.emptyList();
}
// Cast to T
List<DataProvider<T>> providers = new ArrayList<>();
for (DataProvider<?> dataProvider : uncastProviders) {
for (DataProvider<?> dataProvider : wildcardProvidersWithSpecificType) {
providers.add((DataProvider<T>) dataProvider);
}
return providers;

View File

@ -72,11 +72,11 @@ class BooleanProviderValueGatherer {
// Method parameters abstracted away so that same method can be used for all parameter types
// Same with Method result store transaction creation
Function<MethodWrapper<Boolean>, Callable<Boolean>> methodCaller = method -> () -> method.callMethod(extension, Parameters.player(serverUUID, playerUUID, playerName));
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTrancationCreator = (method, result) -> new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
BiFunction<MethodWrapper<Boolean>, Boolean, Transaction> storeTransactionCreator = (method, result) -> new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result);
do {
// Loop through all unsatisfied providers to see if more conditions are satisfied
satisfied = attemptToSatisfyMoreConditionsAndStoreResults(methodCaller, storeTrancationCreator, conditions, unsatisfiedProviders);
satisfied = attemptToSatisfyMoreConditionsAndStoreResults(methodCaller, storeTransactionCreator, conditions, unsatisfiedProviders);
// Remove now satisfied Providers so that they are not called again
unsatisfiedProviders.removeAll(satisfied);
// If no new conditions could be satisfied, stop looping.

View File

@ -24,10 +24,10 @@ package com.djrapitops.plan.extension.implementation.results;
public interface DescribedExtensionData {
/**
* Get Descriptive information about the data point.
* Get describing information about the data point.
*
* @return a {@link ExtensionDescriptive}.
* @return a {@link ExtensionDescription}.
*/
ExtensionDescriptive getDescriptive();
ExtensionDescription getDescription();
}

View File

@ -23,16 +23,16 @@ package com.djrapitops.plan.extension.implementation.results;
*/
public class ExtensionBooleanData implements DescribedExtensionData {
private final ExtensionDescriptive descriptive;
private final ExtensionDescription description;
private final boolean value;
public ExtensionBooleanData(ExtensionDescriptive descriptive, boolean value) {
this.descriptive = descriptive;
public ExtensionBooleanData(ExtensionDescription description, boolean value) {
this.description = description;
this.value = value;
}
public ExtensionDescriptive getDescriptive() {
return descriptive;
public ExtensionDescription getDescription() {
return description;
}
public String getFormattedValue() {

View File

@ -27,7 +27,7 @@ import java.util.Optional;
*
* @author AuroraLS3
*/
public class ExtensionDescriptive implements Comparable<ExtensionDescriptive> {
public class ExtensionDescription implements Comparable<ExtensionDescription> {
private final String name;
private final String text;
@ -35,7 +35,7 @@ public class ExtensionDescriptive implements Comparable<ExtensionDescriptive> {
private final Icon icon;
private final int priority;
public ExtensionDescriptive(String name, String text, String description, Icon icon, int priority) {
public ExtensionDescription(String name, String text, String description, Icon icon, int priority) {
this.name = name;
this.text = text;
this.description = description;
@ -64,15 +64,15 @@ public class ExtensionDescriptive implements Comparable<ExtensionDescriptive> {
}
@Override
public int compareTo(ExtensionDescriptive other) {
public int compareTo(ExtensionDescription other) {
return Integer.compare(other.priority, this.priority); // Higher is first
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ExtensionDescriptive)) return false;
ExtensionDescriptive that = (ExtensionDescriptive) o;
if (!(o instanceof ExtensionDescription)) return false;
ExtensionDescription that = (ExtensionDescription) o;
return priority == that.priority &&
name.equals(that.name) &&
text.equals(that.text) &&
@ -87,7 +87,7 @@ public class ExtensionDescriptive implements Comparable<ExtensionDescriptive> {
@Override
public String toString() {
return "ExtensionDescriptive{" +
return "ExtensionDescription{" +
"name='" + name + '\'' +
", text='" + text + '\'' +
", description='" + description + '\'' +

View File

@ -25,16 +25,16 @@ import com.djrapitops.plan.delivery.formatting.Formatter;
*/
public class ExtensionDoubleData implements DescribedExtensionData {
private final ExtensionDescriptive descriptive;
private final ExtensionDescription description;
private final double value;
public ExtensionDoubleData(ExtensionDescriptive descriptive, double value) {
this.descriptive = descriptive;
public ExtensionDoubleData(ExtensionDescription description, double value) {
this.description = description;
this.value = value;
}
public ExtensionDescriptive getDescriptive() {
return descriptive;
public ExtensionDescription getDescription() {
return description;
}
public String getFormattedValue(Formatter<Double> formatter) {

View File

@ -26,18 +26,18 @@ import com.djrapitops.plan.extension.FormatType;
*/
public class ExtensionNumberData implements DescribedExtensionData {
private final ExtensionDescriptive descriptive;
private final ExtensionDescription description;
private final FormatType formatType;
private final long value;
public ExtensionNumberData(ExtensionDescriptive descriptive, FormatType formatType, long value) {
this.descriptive = descriptive;
public ExtensionNumberData(ExtensionDescription description, FormatType formatType, long value) {
this.description = description;
this.formatType = formatType;
this.value = value;
}
public ExtensionDescriptive getDescriptive() {
return descriptive;
public ExtensionDescription getDescription() {
return description;
}
public FormatType getFormatType() {

View File

@ -25,18 +25,26 @@ import com.djrapitops.plan.delivery.rendering.html.Html;
*/
public class ExtensionStringData implements DescribedExtensionData {
private final ExtensionDescriptive descriptive;
private final ExtensionDescription description;
private final boolean playerName;
private String value;
public ExtensionStringData(ExtensionDescriptive descriptive, boolean playerName, String value) {
this.descriptive = descriptive;
public ExtensionStringData(ExtensionDescription description, boolean playerName, String value) {
this.description = description;
this.playerName = playerName;
this.value = value;
}
public ExtensionDescriptive getDescriptive() {
return descriptive;
public static ExtensionStringData regularString(ExtensionDescription description, String value) {
return new ExtensionStringData(description, false, value);
}
public static ExtensionStringData playerName(ExtensionDescription description, String value) {
return new ExtensionStringData(description, true, value);
}
public ExtensionDescription getDescription() {
return description;
}
public String getFormattedValue() {

View File

@ -38,7 +38,7 @@ public class ExtensionTabData implements Comparable<ExtensionTabData> {
private final Map<String, ExtensionStringData> stringData;
private final List<ExtensionTableData> tableData;
private final List<ExtensionDescriptive> descriptives;
private final List<ExtensionDescription> descriptions;
private List<String> order;
@ -54,7 +54,7 @@ public class ExtensionTabData implements Comparable<ExtensionTabData> {
stringData = new HashMap<>();
tableData = new ArrayList<>();
descriptives = new ArrayList<>();
descriptions = new ArrayList<>();
}
public TabInformation getTabInformation() {
@ -90,14 +90,14 @@ public class ExtensionTabData implements Comparable<ExtensionTabData> {
}
/**
* Get all Descriptives for this tabs data.
* Get all descriptions for data in this tab.
* <p>
* Only available after the Tab has been built.
*
* @return List of {@link ExtensionDescriptive}s.
* @return List of {@link ExtensionDescription}s.
*/
public List<ExtensionDescriptive> getDescriptives() {
return descriptives;
public List<ExtensionDescription> getDescriptions() {
return descriptions;
}
@Override
@ -132,18 +132,27 @@ public class ExtensionTabData implements Comparable<ExtensionTabData> {
}
private void createOrderingList() {
descriptives.addAll(Lists.map(booleanData.values(), DescribedExtensionData::getDescriptive));
descriptives.addAll(Lists.map(doubleData.values(), DescribedExtensionData::getDescriptive));
descriptives.addAll(Lists.map(percentageData.values(), DescribedExtensionData::getDescriptive));
descriptives.addAll(Lists.map(numberData.values(), DescribedExtensionData::getDescriptive));
descriptives.addAll(Lists.map(stringData.values(), DescribedExtensionData::getDescriptive));
descriptions.addAll(Lists.map(booleanData.values(), DescribedExtensionData::getDescription));
descriptions.addAll(Lists.map(doubleData.values(), DescribedExtensionData::getDescription));
descriptions.addAll(Lists.map(percentageData.values(), DescribedExtensionData::getDescription));
descriptions.addAll(Lists.map(numberData.values(), DescribedExtensionData::getDescription));
descriptions.addAll(Lists.map(stringData.values(), DescribedExtensionData::getDescription));
order = descriptives.stream().sorted()
.map(ExtensionDescriptive::getName)
order = descriptions.stream().sorted()
.map(ExtensionDescription::getName)
.distinct()// Method names are usually different, but in case someone had same method name with different parameters.
.collect(Collectors.toList());
}
@Override
public String toString() {
return "ExtensionTabData{" +
"tabInformation=" + tabInformation +
", tableData=" + tableData +
", descriptions=" + descriptions +
'}';
}
public static class Builder {
private final ExtensionTabData data;
@ -153,32 +162,32 @@ public class ExtensionTabData implements Comparable<ExtensionTabData> {
}
public Builder putBooleanData(ExtensionBooleanData extensionBooleanData) {
data.booleanData.put(extensionBooleanData.getDescriptive().getName(), extensionBooleanData);
data.booleanData.put(extensionBooleanData.getDescription().getName(), extensionBooleanData);
return this;
}
public Builder putDoubleData(ExtensionDoubleData extensionDoubleData) {
data.doubleData.put(extensionDoubleData.getDescriptive().getName(), extensionDoubleData);
data.doubleData.put(extensionDoubleData.getDescription().getName(), extensionDoubleData);
return this;
}
public Builder putPercentageData(ExtensionDoubleData extensionDoubleData) {
data.percentageData.put(extensionDoubleData.getDescriptive().getName(), extensionDoubleData);
data.percentageData.put(extensionDoubleData.getDescription().getName(), extensionDoubleData);
return this;
}
public Builder putNumberData(ExtensionNumberData extensionNumberData) {
data.numberData.put(extensionNumberData.getDescriptive().getName(), extensionNumberData);
data.numberData.put(extensionNumberData.getDescription().getName(), extensionNumberData);
return this;
}
public Builder putStringData(ExtensionStringData extensionStringData) {
data.stringData.put(extensionStringData.getDescriptive().getName(), extensionStringData);
data.stringData.put(extensionStringData.getDescription().getName(), extensionStringData);
return this;
}
public Builder putGroupData(ExtensionStringData extensionStringData) {
String name = extensionStringData.getDescriptive().getName();
String name = extensionStringData.getDescription().getName();
ExtensionStringData previous = data.stringData.get(name);
data.stringData.put(name, previous != null ? previous.concatenate(extensionStringData) : extensionStringData);
return this;
@ -195,13 +204,4 @@ public class ExtensionTabData implements Comparable<ExtensionTabData> {
return data;
}
}
@Override
public String toString() {
return "ExtensionTabData{" +
"tabInformation=" + tabInformation +
", tableData=" + tableData +
", descriptives=" + descriptives +
'}';
}
}

View File

@ -22,7 +22,7 @@ import com.djrapitops.plan.extension.icon.Family;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.TabInformation;
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescriptive;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescription;
import com.djrapitops.plan.extension.implementation.results.ExtensionDoubleData;
import com.djrapitops.plan.extension.implementation.results.ExtensionTabData;
import com.djrapitops.plan.identification.ServerUUID;
@ -127,8 +127,8 @@ public class ExtensionAggregateBooleansQuery implements Query<Map<Integer, Exten
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
ExtensionTabData.Builder extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
ExtensionDescription extensionDescription = extractDescription(set);
extractAndPutDataTo(extensionTab, extensionDescription, set);
}
return tabData;
}
@ -150,9 +150,9 @@ public class ExtensionAggregateBooleansQuery implements Query<Map<Integer, Exten
);
}
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescription description, ResultSet set) throws SQLException {
double percentageValue = percentage(set.getInt("positive"), set.getInt("total"));
extensionTab.putPercentageData(new ExtensionDoubleData(descriptive, percentageValue));
extensionTab.putPercentageData(new ExtensionDoubleData(description, percentageValue));
}
private double percentage(double first, double second) {
@ -162,7 +162,7 @@ public class ExtensionAggregateBooleansQuery implements Query<Map<Integer, Exten
return first / second;
}
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
private ExtensionDescription extractDescription(ResultSet set) throws SQLException {
String name = set.getString("provider_name") + "_aggregate";
String text = set.getString(ExtensionProviderTable.TEXT) + " / Players";
String description = set.getString(ExtensionProviderTable.DESCRIPTION);
@ -173,7 +173,7 @@ public class ExtensionAggregateBooleansQuery implements Query<Map<Integer, Exten
Color color = Color.getByName(set.getString("provider_icon_color")).orElse(Color.NONE);
Icon icon = new Icon(family, iconName, color);
return new ExtensionDescriptive(name, text, description, icon, priority);
return new ExtensionDescription(name, text, description, icon, priority);
}
private Icon extractTabIcon(ResultSet set) throws SQLException {

View File

@ -22,7 +22,7 @@ import com.djrapitops.plan.extension.icon.Family;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.TabInformation;
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescriptive;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescription;
import com.djrapitops.plan.extension.implementation.results.ExtensionDoubleData;
import com.djrapitops.plan.extension.implementation.results.ExtensionTabData;
import com.djrapitops.plan.identification.ServerUUID;
@ -125,8 +125,8 @@ public class ExtensionAggregateDoublesQuery implements Query<Map<Integer, Extens
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
ExtensionTabData.Builder extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
ExtensionDescription extensionDescription = extractDescription(set);
extractAndPutDataTo(extensionTab, extensionDescription, set);
}
return tabData;
}
@ -148,16 +148,16 @@ public class ExtensionAggregateDoublesQuery implements Query<Map<Integer, Extens
);
}
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
extensionTab.putDoubleData(new ExtensionDoubleData(modifiedDescriptive(descriptive, "_avg", "Average "), set.getDouble("average")));
extensionTab.putDoubleData(new ExtensionDoubleData(modifiedDescriptive(descriptive, "_total", "Total "), set.getDouble("total")));
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescription description, ResultSet set) throws SQLException {
extensionTab.putDoubleData(new ExtensionDoubleData(modifiedDescription(description, "_avg", "Average "), set.getDouble("average")));
extensionTab.putDoubleData(new ExtensionDoubleData(modifiedDescription(description, "_total", "Total "), set.getDouble("total")));
}
private ExtensionDescriptive modifiedDescriptive(ExtensionDescriptive descriptive, String appendToName, String appendToText) {
return new ExtensionDescriptive(descriptive.getName() + appendToName, appendToText + descriptive.getText(), descriptive.getDescription().orElse(null), descriptive.getIcon(), descriptive.getPriority());
private ExtensionDescription modifiedDescription(ExtensionDescription description, String appendToName, String appendToText) {
return new ExtensionDescription(description.getName() + appendToName, appendToText + description.getText(), description.getDescription().orElse(null), description.getIcon(), description.getPriority());
}
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
private ExtensionDescription extractDescription(ResultSet set) throws SQLException {
String name = set.getString("provider_name");
String text = set.getString(ExtensionProviderTable.TEXT);
String description = set.getString(ExtensionProviderTable.DESCRIPTION);
@ -168,7 +168,7 @@ public class ExtensionAggregateDoublesQuery implements Query<Map<Integer, Extens
Color color = Color.getByName(set.getString("provider_icon_color")).orElse(Color.NONE);
Icon icon = new Icon(family, iconName, color);
return new ExtensionDescriptive(name, text, description, icon, priority);
return new ExtensionDescription(name, text, description, icon, priority);
}
private Icon extractTabIcon(ResultSet set) throws SQLException {

View File

@ -23,7 +23,7 @@ import com.djrapitops.plan.extension.icon.Family;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.TabInformation;
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescriptive;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescription;
import com.djrapitops.plan.extension.implementation.results.ExtensionNumberData;
import com.djrapitops.plan.extension.implementation.results.ExtensionTabData;
import com.djrapitops.plan.identification.ServerUUID;
@ -131,8 +131,8 @@ public class ExtensionAggregateNumbersQuery implements Query<Map<Integer, Extens
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
ExtensionTabData.Builder extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
ExtensionDescription extensionDescription = extractDescription(set);
extractAndPutDataTo(extensionTab, extensionDescription, set);
}
return tabData;
}
@ -154,17 +154,17 @@ public class ExtensionAggregateNumbersQuery implements Query<Map<Integer, Extens
);
}
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescription description, ResultSet set) throws SQLException {
FormatType formatType = FormatType.getByName(set.getString(ExtensionProviderTable.FORMAT_TYPE)).orElse(FormatType.NONE);
extensionTab.putNumberData(new ExtensionNumberData(modifiedDescriptive(descriptive, "_avg", "Average "), formatType, (long) set.getDouble("average")));
extensionTab.putNumberData(new ExtensionNumberData(modifiedDescriptive(descriptive, "_total", "Total "), formatType, (long) set.getDouble("total")));
extensionTab.putNumberData(new ExtensionNumberData(modifiedDescription(description, "_avg", "Average "), formatType, (long) set.getDouble("average")));
extensionTab.putNumberData(new ExtensionNumberData(modifiedDescription(description, "_total", "Total "), formatType, (long) set.getDouble("total")));
}
private ExtensionDescriptive modifiedDescriptive(ExtensionDescriptive descriptive, String appendToName, String appendToText) {
return new ExtensionDescriptive(descriptive.getName() + appendToName, appendToText + descriptive.getText(), descriptive.getDescription().orElse(null), descriptive.getIcon(), descriptive.getPriority());
private ExtensionDescription modifiedDescription(ExtensionDescription description, String appendToName, String appendToText) {
return new ExtensionDescription(description.getName() + appendToName, appendToText + description.getText(), description.getDescription().orElse(null), description.getIcon(), description.getPriority());
}
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
private ExtensionDescription extractDescription(ResultSet set) throws SQLException {
String name = set.getString("provider_name");
String text = set.getString(ExtensionProviderTable.TEXT);
String description = set.getString(ExtensionProviderTable.DESCRIPTION);
@ -175,7 +175,7 @@ public class ExtensionAggregateNumbersQuery implements Query<Map<Integer, Extens
Color color = Color.getByName(set.getString("provider_icon_color")).orElse(Color.NONE);
Icon icon = new Icon(family, iconName, color);
return new ExtensionDescriptive(name, text, description, icon, priority);
return new ExtensionDescription(name, text, description, icon, priority);
}
private Icon extractTabIcon(ResultSet set) throws SQLException {

View File

@ -22,7 +22,7 @@ import com.djrapitops.plan.extension.icon.Family;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.TabInformation;
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescriptive;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescription;
import com.djrapitops.plan.extension.implementation.results.ExtensionDoubleData;
import com.djrapitops.plan.extension.implementation.results.ExtensionTabData;
import com.djrapitops.plan.identification.ServerUUID;
@ -116,8 +116,8 @@ public class ExtensionAggregatePercentagesQuery implements Query<Map<Integer, Ex
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
ExtensionTabData.Builder extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
ExtensionDescription extensionDescription = extractDescription(set);
extractAndPutDataTo(extensionTab, extensionDescription, set);
}
return tabData;
}
@ -139,15 +139,15 @@ public class ExtensionAggregatePercentagesQuery implements Query<Map<Integer, Ex
);
}
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
extensionTab.putPercentageData(new ExtensionDoubleData(modifiedDescriptive(descriptive, "_avg", "Average "), set.getDouble("average")));
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescription description, ResultSet set) throws SQLException {
extensionTab.putPercentageData(new ExtensionDoubleData(modifiedDescription(description, "_avg", "Average "), set.getDouble("average")));
}
private ExtensionDescriptive modifiedDescriptive(ExtensionDescriptive descriptive, String appendToName, String appendToText) {
return new ExtensionDescriptive(descriptive.getName() + appendToName, appendToText + descriptive.getText(), descriptive.getDescription().orElse(null), descriptive.getIcon(), descriptive.getPriority());
private ExtensionDescription modifiedDescription(ExtensionDescription description, String appendToName, String appendToText) {
return new ExtensionDescription(description.getName() + appendToName, appendToText + description.getText(), description.getDescription().orElse(null), description.getIcon(), description.getPriority());
}
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
private ExtensionDescription extractDescription(ResultSet set) throws SQLException {
String name = set.getString("provider_name");
String text = set.getString(ExtensionProviderTable.TEXT);
String description = set.getString(ExtensionProviderTable.DESCRIPTION);
@ -158,7 +158,7 @@ public class ExtensionAggregatePercentagesQuery implements Query<Map<Integer, Ex
Color color = Color.getByName(set.getString("provider_icon_color")).orElse(Color.NONE);
Icon icon = new Icon(family, iconName, color);
return new ExtensionDescriptive(name, text, description, icon, priority);
return new ExtensionDescription(name, text, description, icon, priority);
}
private Icon extractTabIcon(ResultSet set) throws SQLException {

View File

@ -159,8 +159,8 @@ public class ExtensionPlayerDataQuery implements Query<Map<ServerUUID, List<Exte
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
ExtensionTabData.Builder extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
ExtensionDescription extensionDescription = extractDescription(set);
extractAndPutDataTo(extensionTab, extensionDescription, set);
}
return tabData;
}
@ -182,40 +182,40 @@ public class ExtensionPlayerDataQuery implements Query<Map<ServerUUID, List<Exte
);
}
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescription description, ResultSet set) throws SQLException {
boolean booleanValue = set.getBoolean(ExtensionPlayerValueTable.BOOLEAN_VALUE);
if (!set.wasNull()) {
extensionTab.putBooleanData(new ExtensionBooleanData(descriptive, booleanValue));
extensionTab.putBooleanData(new ExtensionBooleanData(description, booleanValue));
return;
}
double doubleValue = set.getDouble(ExtensionPlayerValueTable.DOUBLE_VALUE);
if (!set.wasNull()) {
extensionTab.putDoubleData(new ExtensionDoubleData(descriptive, doubleValue));
extensionTab.putDoubleData(new ExtensionDoubleData(description, doubleValue));
return;
}
double percentageValue = set.getDouble(ExtensionPlayerValueTable.PERCENTAGE_VALUE);
if (!set.wasNull()) {
extensionTab.putPercentageData(new ExtensionDoubleData(descriptive, percentageValue));
extensionTab.putPercentageData(new ExtensionDoubleData(description, percentageValue));
return;
}
long numberValue = set.getLong(ExtensionPlayerValueTable.LONG_VALUE);
if (!set.wasNull()) {
FormatType formatType = FormatType.getByName(set.getString(ExtensionProviderTable.FORMAT_TYPE)).orElse(FormatType.NONE);
extensionTab.putNumberData(new ExtensionNumberData(descriptive, formatType, numberValue));
extensionTab.putNumberData(new ExtensionNumberData(description, formatType, numberValue));
return;
}
String stringValue = set.getString(ExtensionPlayerValueTable.STRING_VALUE);
if (stringValue != null) {
boolean isPlayerName = set.getBoolean("is_player_name");
extensionTab.putStringData(new ExtensionStringData(descriptive, isPlayerName, stringValue));
extensionTab.putStringData(new ExtensionStringData(description, isPlayerName, stringValue));
}
}
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
private ExtensionDescription extractDescription(ResultSet set) throws SQLException {
String name = set.getString("provider_name");
String text = set.getString(ExtensionProviderTable.TEXT);
String description = set.getString(ExtensionProviderTable.DESCRIPTION);
@ -226,7 +226,7 @@ public class ExtensionPlayerDataQuery implements Query<Map<ServerUUID, List<Exte
Color color = Color.getByName(set.getString("provider_icon_color")).orElse(Color.NONE);
Icon icon = new Icon(family, iconName, color);
return new ExtensionDescriptive(name, text, description, icon, priority);
return new ExtensionDescription(name, text, description, icon, priority);
}
private Icon extractTabIcon(ResultSet set) throws SQLException {

View File

@ -22,7 +22,7 @@ import com.djrapitops.plan.extension.icon.Family;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.TabInformation;
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescriptive;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescription;
import com.djrapitops.plan.extension.implementation.results.ExtensionStringData;
import com.djrapitops.plan.extension.implementation.results.ExtensionTabData;
import com.djrapitops.plan.storage.database.SQLDB;
@ -108,10 +108,10 @@ public class ExtensionPlayerGroupsQuery implements Query<Map<Integer, ExtensionD
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
ExtensionTabData.Builder extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
ExtensionDescription extensionDescription = extractDescription(set);
String groupName = set.getString(ExtensionGroupsTable.GROUP_NAME);
extensionTab.putGroupData(new ExtensionStringData(extensionDescriptive, false, groupName));
extensionTab.putGroupData(ExtensionStringData.regularString(extensionDescription, groupName));
}
return tabData;
}
@ -133,7 +133,7 @@ public class ExtensionPlayerGroupsQuery implements Query<Map<Integer, ExtensionD
);
}
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
private ExtensionDescription extractDescription(ResultSet set) throws SQLException {
String name = set.getString("provider_name");
String text = set.getString(ExtensionProviderTable.TEXT);
@ -142,7 +142,7 @@ public class ExtensionPlayerGroupsQuery implements Query<Map<Integer, ExtensionD
Color color = Color.getByName(set.getString("provider_icon_color")).orElse(Color.NONE);
Icon icon = new Icon(family, iconName, color);
return new ExtensionDescriptive(name, text, null, icon, 0);
return new ExtensionDescription(name, text, null, icon, 0);
}
private Icon extractTabIcon(ResultSet set) throws SQLException {

View File

@ -153,54 +153,53 @@ public class ExtensionQueryResultTableDataQuery implements Query<Map<UUID, Exten
UUID playerUUID = UUID.fromString(set.getString("uuid"));
ExtensionTabData.Builder data = dataByPlayer.getOrDefault(playerUUID, new ExtensionTabData.Builder(null));
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
extractAndPutDataTo(data, extensionDescriptive, set);
ExtensionDescription extensionDescription = extractDescription(set);
extractAndPutDataTo(data, extensionDescription, set);
dataByPlayer.put(playerUUID, data);
}
return dataByPlayer.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().build()));
}
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescription description, ResultSet set) throws SQLException {
String groupValue = set.getString("group_value");
if (groupValue != null) {
extensionTab.putGroupData(new ExtensionStringData(descriptive, false, groupValue));
extensionTab.putGroupData(ExtensionStringData.regularString(description, groupValue));
return;
}
boolean booleanValue = set.getBoolean(ExtensionServerValueTable.BOOLEAN_VALUE);
if (!set.wasNull()) {
extensionTab.putBooleanData(new ExtensionBooleanData(descriptive, booleanValue));
extensionTab.putBooleanData(new ExtensionBooleanData(description, booleanValue));
return;
}
double doubleValue = set.getDouble(ExtensionPlayerValueTable.DOUBLE_VALUE);
if (!set.wasNull()) {
extensionTab.putDoubleData(new ExtensionDoubleData(descriptive, doubleValue));
extensionTab.putDoubleData(new ExtensionDoubleData(description, doubleValue));
return;
}
double percentageValue = set.getDouble(ExtensionServerValueTable.PERCENTAGE_VALUE);
if (!set.wasNull()) {
extensionTab.putPercentageData(new ExtensionDoubleData(descriptive, percentageValue));
extensionTab.putPercentageData(new ExtensionDoubleData(description, percentageValue));
return;
}
long numberValue = set.getLong(ExtensionPlayerValueTable.LONG_VALUE);
if (!set.wasNull()) {
FormatType formatType = FormatType.getByName(set.getString(ExtensionProviderTable.FORMAT_TYPE)).orElse(FormatType.NONE);
extensionTab.putNumberData(new ExtensionNumberData(descriptive, formatType, numberValue));
extensionTab.putNumberData(new ExtensionNumberData(description, formatType, numberValue));
return;
}
String stringValue = set.getString(ExtensionPlayerValueTable.STRING_VALUE);
if (stringValue != null) {
boolean isPlayerName = false;
extensionTab.putStringData(new ExtensionStringData(descriptive, isPlayerName, stringValue));
extensionTab.putStringData(ExtensionStringData.regularString(description, stringValue));
}
}
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
private ExtensionDescription extractDescription(ResultSet set) throws SQLException {
String name = set.getString("provider_name");
String text = set.getString(ExtensionProviderTable.TEXT);
@ -208,6 +207,6 @@ public class ExtensionQueryResultTableDataQuery implements Query<Map<UUID, Exten
Family family = Family.getByName(set.getString("provider_icon_family")).orElse(Family.SOLID);
Icon icon = new Icon(family, iconName, Color.NONE);
return new ExtensionDescriptive(name, text, null, icon, 0);
return new ExtensionDescription(name, text, null, icon, 0);
}
}

View File

@ -162,8 +162,8 @@ public class ExtensionServerDataQuery implements Query<List<ExtensionData>> {
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
ExtensionTabData.Builder extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
ExtensionDescription extensionDescription = extractDescription(set);
extractAndPutDataTo(extensionTab, extensionDescription, set);
}
return tabData;
}
@ -185,40 +185,40 @@ public class ExtensionServerDataQuery implements Query<List<ExtensionData>> {
);
}
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescription description, ResultSet set) throws SQLException {
boolean booleanValue = set.getBoolean(ExtensionServerValueTable.BOOLEAN_VALUE);
if (!set.wasNull()) {
extensionTab.putBooleanData(new ExtensionBooleanData(descriptive, booleanValue));
extensionTab.putBooleanData(new ExtensionBooleanData(description, booleanValue));
return;
}
double doubleValue = set.getDouble(ExtensionServerValueTable.DOUBLE_VALUE);
if (!set.wasNull()) {
extensionTab.putDoubleData(new ExtensionDoubleData(descriptive, doubleValue));
extensionTab.putDoubleData(new ExtensionDoubleData(description, doubleValue));
return;
}
double percentageValue = set.getDouble(ExtensionServerValueTable.PERCENTAGE_VALUE);
if (!set.wasNull()) {
extensionTab.putPercentageData(new ExtensionDoubleData(descriptive, percentageValue));
extensionTab.putPercentageData(new ExtensionDoubleData(description, percentageValue));
return;
}
long numberValue = set.getLong(ExtensionServerValueTable.LONG_VALUE);
if (!set.wasNull()) {
FormatType formatType = FormatType.getByName(set.getString(ExtensionProviderTable.FORMAT_TYPE)).orElse(FormatType.NONE);
extensionTab.putNumberData(new ExtensionNumberData(descriptive, formatType, numberValue));
extensionTab.putNumberData(new ExtensionNumberData(description, formatType, numberValue));
return;
}
String stringValue = set.getString(ExtensionServerValueTable.STRING_VALUE);
if (stringValue != null) {
boolean isPlayerName = set.getBoolean("is_player_name");
extensionTab.putStringData(new ExtensionStringData(descriptive, isPlayerName, stringValue));
extensionTab.putStringData(new ExtensionStringData(description, isPlayerName, stringValue));
}
}
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
private ExtensionDescription extractDescription(ResultSet set) throws SQLException {
String name = set.getString("provider_name");
String text = set.getString(ExtensionProviderTable.TEXT);
String description = set.getString(ExtensionProviderTable.DESCRIPTION);
@ -229,7 +229,7 @@ public class ExtensionServerDataQuery implements Query<List<ExtensionData>> {
Color color = Color.getByName(set.getString("provider_icon_color")).orElse(Color.NONE);
Icon icon = new Icon(family, iconName, color);
return new ExtensionDescriptive(name, text, description, icon, priority);
return new ExtensionDescription(name, text, description, icon, priority);
}
private Icon extractTabIcon(ResultSet set) throws SQLException {

View File

@ -164,54 +164,53 @@ public class ExtensionServerTableDataQuery implements Query<Map<UUID, ExtensionT
UUID playerUUID = UUID.fromString(set.getString("uuid"));
ExtensionTabData.Builder data = dataByPlayer.getOrDefault(playerUUID, new ExtensionTabData.Builder(null));
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
extractAndPutDataTo(data, extensionDescriptive, set);
ExtensionDescription extensionDescription = extractDescription(set);
extractAndPutDataTo(data, extensionDescription, set);
dataByPlayer.put(playerUUID, data);
}
return dataByPlayer.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().build()));
}
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
private void extractAndPutDataTo(ExtensionTabData.Builder extensionTab, ExtensionDescription description, ResultSet set) throws SQLException {
String groupValue = set.getString("group_value");
if (groupValue != null) {
extensionTab.putGroupData(new ExtensionStringData(descriptive, false, groupValue));
extensionTab.putGroupData(ExtensionStringData.regularString(description, groupValue));
return;
}
boolean booleanValue = set.getBoolean(ExtensionServerValueTable.BOOLEAN_VALUE);
if (!set.wasNull()) {
extensionTab.putBooleanData(new ExtensionBooleanData(descriptive, booleanValue));
extensionTab.putBooleanData(new ExtensionBooleanData(description, booleanValue));
return;
}
double doubleValue = set.getDouble(ExtensionPlayerValueTable.DOUBLE_VALUE);
if (!set.wasNull()) {
extensionTab.putDoubleData(new ExtensionDoubleData(descriptive, doubleValue));
extensionTab.putDoubleData(new ExtensionDoubleData(description, doubleValue));
return;
}
double percentageValue = set.getDouble(ExtensionServerValueTable.PERCENTAGE_VALUE);
if (!set.wasNull()) {
extensionTab.putPercentageData(new ExtensionDoubleData(descriptive, percentageValue));
extensionTab.putPercentageData(new ExtensionDoubleData(description, percentageValue));
return;
}
long numberValue = set.getLong(ExtensionPlayerValueTable.LONG_VALUE);
if (!set.wasNull()) {
FormatType formatType = FormatType.getByName(set.getString(ExtensionProviderTable.FORMAT_TYPE)).orElse(FormatType.NONE);
extensionTab.putNumberData(new ExtensionNumberData(descriptive, formatType, numberValue));
extensionTab.putNumberData(new ExtensionNumberData(description, formatType, numberValue));
return;
}
String stringValue = set.getString(ExtensionPlayerValueTable.STRING_VALUE);
if (stringValue != null) {
boolean isPlayerName = false;
extensionTab.putStringData(new ExtensionStringData(descriptive, isPlayerName, stringValue));
extensionTab.putStringData(ExtensionStringData.regularString(description, stringValue));
}
}
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
private ExtensionDescription extractDescription(ResultSet set) throws SQLException {
String name = set.getString("provider_name");
String text = set.getString(ExtensionProviderTable.TEXT);
@ -219,6 +218,6 @@ public class ExtensionServerTableDataQuery implements Query<Map<UUID, ExtensionT
Family family = Family.getByName(set.getString("provider_icon_family")).orElse(Family.SOLID);
Icon icon = new Icon(family, iconName, Color.NONE);
return new ExtensionDescriptive(name, text, null, icon, 0);
return new ExtensionDescription(name, text, null, icon, 0);
}
}

View File

@ -43,13 +43,13 @@ public class TPSCalculator {
private final long maxBeforeZeroTPS;
private long lastPulse;
private final TimerAverage averager;
private final TimerAverage average;
public TPSCalculator() {
maxBeforeZeroTPS = SECOND_NS * 20L; // 20 ticks
lastPulse = -1;
averager = new TimerAverage();
average = new TimerAverage();
}
/**
@ -73,13 +73,13 @@ public class TPSCalculator {
// Add missed ticks, TPS has been low for a while, see the math in the class javadoc.
while (difference > maxBeforeZeroTPS) {
averager.add(time, 0.0);
average.add(time, 0.0);
difference -= maxBeforeZeroTPS;
}
double tps = maxBeforeZeroTPS * 1.0 / difference;
if (averager.add(time, tps)) {
return Optional.of(averager.getAverageAndReset(time));
if (average.add(time, tps)) {
return Optional.of(average.getAverageAndReset(time));
}
return Optional.empty();
}

View File

@ -31,7 +31,7 @@ public class DisplaySettings {
public static final Setting<String> THEME = new StringSetting("Display_options.Theme");
public static final Setting<Integer> SESSIONS_PER_PAGE = new IntegerSetting("Display_options.Sessions.Show_on_page");
public static final Setting<Boolean> ORDER_WORLD_PIE_BY_PERC = new BooleanSetting("Display_options.Sessions.Order_world_pies_by_percentage");
public static final Setting<Boolean> ORDER_WORLD_PIE_BY_PERCENTAGE = new BooleanSetting("Display_options.Sessions.Order_world_pies_by_percentage");
public static final Setting<Integer> PLAYERS_PER_SERVER_PAGE = new IntegerSetting("Display_options.Players_table.Show_on_server_page");
public static final Setting<Integer> PLAYERS_PER_PLAYERS_PAGE = new IntegerSetting("Display_options.Players_table.Show_on_players_page");
public static final Setting<Boolean> OPEN_PLAYER_LINKS_IN_NEW_TAB = new BooleanSetting("Display_options.Open_player_links_in_new_tab");

View File

@ -131,7 +131,7 @@ public class LargeStoreQueries {
}
/**
* Execute a big batch of server infromation insert statements.
* Execute a big batch of server information insert statements.
*
* @param servers Collection of Plan Servers.
* @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}

View File

@ -320,7 +320,7 @@ public class UserInfoQueries {
FROM + '(' + selectLowercaseJoinAddresses + ") q1" +
WHERE + "address IN (" +
new TextStringBuilder().appendWithSeparators(joinAddresses.stream().map(item -> '?').iterator(), ",") +
')'; // Don't append addresses directly, SQL incjection hazard
')'; // Don't append addresses directly, SQL injection hazard
return new QueryStatement<Set<UUID>>(sql) {
@Override

View File

@ -88,14 +88,14 @@ public class NetworkTablePlayersQuery implements Query<List<TablePlayer>> {
"u." + UsersTable.USER_NAME + ',' +
"u." + UsersTable.REGISTERED + ',' +
"ban." + UserInfoTable.USER_UUID + " as banned," +
"geoloc." + GeoInfoTable.GEOLOCATION + ',' +
"geo." + GeoInfoTable.GEOLOCATION + ',' +
"ses.last_seen," +
"ses.count," +
"ses.active_playtime," +
"act.activity_index" +
FROM + UsersTable.TABLE_NAME + " u" +
LEFT_JOIN + '(' + selectBanned + ") ban on ban." + UserInfoTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + selectLatestGeolocations + ") geoloc on geoloc." + GeoInfoTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + selectLatestGeolocations + ") geo on geo." + GeoInfoTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + selectSessionData + ") ses on ses." + SessionsTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + NetworkActivityIndexQueries.selectActivityIndexSQL() + ") act on u." + UsersTable.USER_UUID + "=act." + UserInfoTable.USER_UUID +
ORDER_BY + "ses.last_seen DESC LIMIT ?";

View File

@ -107,14 +107,14 @@ public class QueryTablePlayersQuery implements Query<List<TablePlayer>> {
"u." + UsersTable.USER_NAME + ',' +
"u." + UsersTable.REGISTERED + ',' +
"ban." + UserInfoTable.USER_UUID + " as banned," +
"geoloc." + GeoInfoTable.GEOLOCATION + ',' +
"geo." + GeoInfoTable.GEOLOCATION + ',' +
"ses.last_seen," +
"ses.count," +
"ses.active_playtime," +
"act.activity_index" +
FROM + UsersTable.TABLE_NAME + " u" +
LEFT_JOIN + '(' + selectBanned + ") ban on ban." + UserInfoTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + selectLatestGeolocations + ") geoloc on geoloc." + GeoInfoTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + selectLatestGeolocations + ") geo on geo." + GeoInfoTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + selectSessionData + ") ses on ses." + SessionsTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + NetworkActivityIndexQueries.selectActivityIndexSQL() + ") act on u." + SessionsTable.USER_UUID + "=act." + UserInfoTable.USER_UUID +
WHERE + "u." + UserInfoTable.USER_UUID +

View File

@ -96,14 +96,14 @@ public class ServerTablePlayersQuery implements Query<List<TablePlayer>> {
"u." + UsersTable.USER_NAME + ',' +
"u." + UsersTable.REGISTERED + ',' +
UserInfoTable.BANNED + ',' +
"geoloc." + GeoInfoTable.GEOLOCATION + ',' +
"geo." + GeoInfoTable.GEOLOCATION + ',' +
"ses.last_seen," +
"ses.count," +
"ses.active_playtime," +
"act.activity_index" +
FROM + UsersTable.TABLE_NAME + " u" +
INNER_JOIN + UserInfoTable.TABLE_NAME + " on u." + UsersTable.USER_UUID + "=" + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.USER_UUID +
LEFT_JOIN + '(' + selectLatestGeolocations + ") geoloc on geoloc." + GeoInfoTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + selectLatestGeolocations + ") geo on geo." + GeoInfoTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + selectSessionData + ") ses on ses." + SessionsTable.USER_UUID + "=u." + UsersTable.USER_UUID +
LEFT_JOIN + '(' + ActivityIndexQueries.selectActivityIndexSQL() + ") act on u." + SessionsTable.USER_UUID + "=act." + UserInfoTable.USER_UUID +
WHERE + UserInfoTable.SERVER_UUID + "=?" +

View File

@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
*/
public abstract class Transaction {
// SQLite version on 1.8.8 does not support savepoints, see createSavePoint() method
// SQLite version on 1.8.8 does not support save points, see createSavePoint() method
private static final AtomicBoolean SUPPORTS_SAVE_POINTS = new AtomicBoolean(true);
// Limit for Deadlock attempts.
private static final int ATTEMPT_LIMIT = 5;
@ -125,8 +125,8 @@ public abstract class Transaction {
private String rollbackTransaction() {
String rollbackStatusMsg = ", Transaction was rolled back.";
boolean hasNoSavepoints = !SUPPORTS_SAVE_POINTS.get();
if (hasNoSavepoints) {
boolean hasNoSavePoints = !SUPPORTS_SAVE_POINTS.get();
if (hasNoSavePoints) {
rollbackStatusMsg = ", additionally rollbacks are not supported on this server version.";
} else {
// Rollbacks are supported.

View File

@ -0,0 +1,28 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.utilities.analysis;
public class Percentage {
public static double calculate(double amount, long total) {
return calculate(amount, total, 0);
}
public static double calculate(double amount, long total, double whenZeroTotal) {
return total != 0 ? amount / total : whenZeroTotal;
}
}

View File

@ -94,7 +94,7 @@ public enum DefaultFontInfo {
AMPERSAND('&', 5),
ASTERISK('*', 5),
LEFT_PARENTHESIS('(', 4),
RIGHT_PERENTHESIS(')', 4),
RIGHT_PARENTHESIS(')', 4),
MINUS('-', 5),
UNDERSCORE('_', 5),
PLUS_SIGN('+', 5),

View File

@ -20,7 +20,7 @@ import java.util.Arrays;
import java.util.stream.Stream;
/**
* Utilities for manipulating different Throwables.
* Utilities for manipulating different Throwable stack traces.
*
* @author AuroraLS3
*/

View File

@ -912,171 +912,129 @@ div#navSrvContainer::-webkit-scrollbar-thumb {
}
.bg-red-outline {
outline-color: #F44336;
border-color: #F44336;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #F44336 solid 1px;
}
.bg-pink-outline {
outline-color: #E91E63;
border-color: #E91E63;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #E91E63 solid 1px;
}
.bg-purple-outline {
outline-color: #9C27B0;
border-color: #9C27B0;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #9C27B0 solid 1px;
}
.bg-deep-purple-outline {
outline-color: #673AB7;
border-color: #673AB7;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #673AB7 solid 1px;
}
.bg-indigo-outline {
outline-color: #3F51B5;
border-color: #3F51B5;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #3F51B5 solid 1px;
}
.bg-blue-outline {
outline-color: #2196F3;
border-color: #2196F3;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #2196F3 solid 1px;
}
.bg-light-blue-outline {
outline-color: #03A9F4;
border-color: #03A9F4;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #03A9F4 solid 1px;
}
.bg-cyan-outline {
outline-color: #00BCD4;
border-color: #00BCD4;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #00BCD4 solid 1px;
}
.bg-teal-outline {
outline-color: #009688;
border-color: #009688;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #009688 solid 1px;
}
.bg-green-outline {
outline-color: #4CAF50;
border-color: #4CAF50;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #4CAF50 solid 1px;
}
.bg-light-green-outline {
outline-color: #8BC34A;
border-color: #8BC34A;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #8BC34A solid 1px;
}
.bg-lime-outline {
outline-color: #CDDC39;
border-color: #CDDC39;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #CDDC39 solid 1px;
}
.bg-yellow-outline {
outline-color: #ffe821;
border-color: #ffe821;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #ffe821 solid 1px;
}
.bg-amber-outline {
outline-color: #FFC107;
border-color: #FFC107;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #FFC107 solid 1px;
}
.bg-orange-outline {
outline-color: #FF9800;
border-color: #FF9800;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #FF9800 solid 1px;
}
.bg-deep-orange-outline {
outline-color: #FF5722;
border-color: #FF5722;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #FF5722 solid 1px;
}
.bg-brown-outline {
outline-color: #795548;
border-color: #795548;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #795548 solid 1px;
}
.bg-grey-outline {
outline-color: #9E9E9E;
border-color: #9E9E9E;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #9E9E9E solid 1px;
}
.bg-blue-grey-outline {
outline-color: #607D8B;
border-color: #607D8B;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #607D8B solid 1px;
}
.bg-black-outline {
outline-color: #555555;
border-color: #555555;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #555555 solid 1px;
}
.bg-plan-outline {
outline-color: #368F17;
border-color: #368F17;
border-style: solid;
outline-style: solid;
outline-width: 1px;
outline: #368F17 solid 1px;
}
.col-red {

View File

@ -1,7 +1,9 @@
// https://gist.github.com/gkhays/e264009c0832c73d5345847e673a64ab
function drawSine(canvasId) {
// https://gist.github.com/gkhays/e264009c0832c73d5345847e673a64ab
let step;
function drawPoint(ctx, x, y) {
var radius = 2;
const radius = 2;
ctx.beginPath();
// Hold x constant at 4 so the point only moves up and down.
@ -13,27 +15,26 @@ function drawSine(canvasId) {
ctx.stroke();
}
function plotSine(ctx, xOffset, yOffset) {
var width = ctx.canvas.width;
var height = ctx.canvas.height;
function plotSine(ctx, xOffset) {
const width = ctx.canvas.width;
const height = ctx.canvas.height;
ctx.beginPath();
ctx.lineWidth = 2;
ctx.strokeStyle = "#fff";
// console.log("Drawing point...");
// Drawing point
let x = -2;
let y = 0;
const amplitude = 50;
const frequency = 50;
var x = -2;
var y = 0;
var amplitude = 50;
var frequency = 50;
// ctx.moveTo(x, y);
ctx.moveTo(x, 50);
while (x <= width) {
y = height / 2 + amplitude * Math.sin((x + xOffset) / frequency) * Math.cos((x + xOffset) / (frequency * 0.54515978463));
ctx.lineTo(x, y);
x += 5;
// console.log("x="+x+" y="+y);
}
ctx.stroke();
ctx.save();
@ -44,13 +45,13 @@ function drawSine(canvasId) {
}
function draw() {
var canvas = document.getElementById(canvasId);
var context = canvas.getContext("2d");
const canvas = document.getElementById(canvasId);
const context = canvas.getContext("2d");
context.clearRect(0, 0, 1000, 150);
context.save();
plotSine(context, step, 100);
plotSine(context, step);
context.restore();
step += 0.5;
@ -58,14 +59,15 @@ function drawSine(canvasId) {
}
function fix_dpi() {
var canvas = document.getElementById(canvasId);
let dpi = window.devicePixelRatio;//get canvas
let ctx = canvas.getContext('2d');
let style_width = +getComputedStyle(canvas).getPropertyValue("width").slice(0, -2);//scale the canvascanvas.setAttribute('height', style_height * dpi);
canvas.setAttribute('width', style_width * dpi);
const canvas = document.getElementById(canvasId);
let dpi = window.devicePixelRatio;
canvas.getContext('2d');
const style_width = getComputedStyle(canvas).getPropertyValue("width").slice(0, -2);
// Scale the canvas
canvas.setAttribute('width', `${style_width * dpi}`);
}
fix_dpi();
var step = -1;
step = -1;
window.requestAnimationFrame(draw);
}

View File

@ -231,6 +231,7 @@ function loadPlayerbaseOverviewValues(json, error) {
element.querySelector('#data_regular_to_inactive').innerHTML = data.regular_to_inactive + smallTrend(data.regular_to_inactive_trend);
}
// Lowercase due to locale translation: Server
function loadservers(json, error) {
if (error) {
displayError(document.getElementById('servers-tab'), error);
@ -266,10 +267,12 @@ function loadservers(json, error) {
onViewserver(0, servers)(); // Open first server.
}
// Lowercase due to locale translation: Server
function addserverToNav(server) {
return `<a class="collapse-item nav-button" href="server/${server.name}"><i class="fas fa-fw fa-server col-light-green"></i> ${server.name}</a>`;
}
// Lowercase due to locale translation: Network
function createnetworkserverBox(i, server) {
return `<div class="card shadow mb-4">
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
@ -292,6 +295,7 @@ function createnetworkserverBox(i, server) {
</div>`;
}
// Lowercase due to locale translation: Server
function onViewserver(i, servers) {
return function () {
setTimeout(function () {

View File

@ -146,6 +146,7 @@ function createConnectionsTableBody(connections) {
return table;
}
// Lowercase due to locale translation: Server
function loadserverAccordion(json, error) {
tab = $("#server-overview");
if (error) {
@ -194,6 +195,7 @@ function onOpenserver(i, servers) {
}
}
// Lowercase due to locale translation: Server
function createserverAccordionTitle(i, server) {
return '<tr id="server_h_' + i + '" aria-controls="server_t_' + i + '" aria-expanded="false" class="clickable collapsed bg-light-green-outline" data-target="#server_t_' + i + '" data-toggle="collapse"><td>'
+ server.server_name +
@ -205,6 +207,7 @@ function createserverAccordionTitle(i, server) {
+ '<td>' + server.last_seen + '</td></tr>'
}
// Lowercase due to locale translation: Server
function createserverAccordionBody(i, server) {
return `<tr class="collapse" data-parent="#tableSAccordion" id="server_t_` + i + `">` +

View File

@ -62,9 +62,9 @@ function refreshingJsonRequest(address, callback, tabID, skipOldData) {
*/
function jsonRequest(address, callback) {
setTimeout(function () {
var xhttp = new XMLHttpRequest();
xhttp.withCredentials = true;
xhttp.onreadystatechange = function () {
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.onreadystatechange = function () {
if (this.readyState === 4) {
try {
if (this.status === 200 || (this.status === 0 && this.responseText)) {
@ -85,11 +85,11 @@ function jsonRequest(address, callback) {
}
}
};
xhttp.timeout = 45000;
xhttp.ontimeout = function () {
xhr.timeout = 45000;
xhr.ontimeout = function () {
callback(null, "Timed out after 45 seconds. (" + address + ")")
};
xhttp.open("GET", address, true);
xhttp.send();
xhr.open("GET", address, true);
xhr.send();
}, 0);
}

View File

@ -6,7 +6,7 @@ What the endpoints return is not detailed to save time, as this document is writ
Parameters are given in the URL: `address/v1/<endpoint>?parameter=value&another=value`
If invalid parameters are given the server will return 400 Bad Request.
If invalid parameters are given, the server will return 400 Bad Request.
The body of the response is the error message
## Endpoints

View File

@ -1,71 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>CUSTOM-Javadoc</actionName>
<displayName>Javadoc</displayName>
<goals>
<goal>javadoc:javadoc</goal>
</goals>
</action>
<action>
<actionName>CUSTOM-checkstyle</actionName>
<displayName>Checkstyle</displayName>
<goals>
<goal>jxr:jxr</goal>
<goal>checkstyle:checkstyle</goal>
</goals>
</action>
<action>
<actionName>CUSTOM-pit</actionName>
<displayName>pit</displayName>
<goals>
<goal>org.pitest:pitest-maven:mutationCoverage</goal>
</goals>
</action>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath com.djrapitops.nmplayer.NMPlayer</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>debug</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath
com.djrapitops.nmplayer.NMPlayer
</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
</action>
<action>
<actionName>profile</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath com.djrapitops.nmplayer.NMPlayer</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
</actions>

View File

@ -29,7 +29,6 @@ import cn.nukkit.event.EventHandler;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerJoinEvent;
import cn.nukkit.event.player.PlayerQuitEvent;
import com.djrapitops.plan.PlanNukkit;
import com.djrapitops.plan.TaskSystem;
import com.djrapitops.plan.delivery.domain.DateObj;
import com.djrapitops.plan.identification.ServerInfo;
@ -61,7 +60,6 @@ public class NukkitPingCounter extends TaskSystem.Task implements Listener {
private final Map<UUID, List<DateObj<Integer>>> playerHistory;
private final Listeners listeners;
private final PlanNukkit plugin;
private final PlanConfig config;
private final DBSystem dbSystem;
private final ServerInfo serverInfo;
@ -70,14 +68,12 @@ public class NukkitPingCounter extends TaskSystem.Task implements Listener {
@Inject
public NukkitPingCounter(
Listeners listeners,
PlanNukkit plugin,
PlanConfig config,
DBSystem dbSystem,
ServerInfo serverInfo,
RunnableFactory runnableFactory
) {
this.listeners = listeners;
this.plugin = plugin;
this.config = config;
this.dbSystem = dbSystem;
this.serverInfo = serverInfo;

View File

@ -141,9 +141,9 @@ public class SpongeDeathListener {
}
private Optional<Player> getOwner(Wolf wolf) {
Optional<Optional<UUID>> isTameable = wolf.get(Keys.TAMED_OWNER);
if (!isTameable.isPresent()) return Optional.empty();
Optional<UUID> owner = isTameable.get();
Optional<Optional<UUID>> isTamed = wolf.get(Keys.TAMED_OWNER);
if (!isTamed.isPresent()) return Optional.empty();
Optional<UUID> owner = isTamed.get();
return owner.flatMap(Sponge.getGame().getServer()::getPlayer);
}

View File

@ -87,7 +87,7 @@ public class VelocityServerInfo extends ServerInfo {
String ip = serverProperties.getIp();
if ("0.0.0.0".equals(ip)) {
logger.error("IP setting still 0.0.0.0 - Configure Alternative_IP/IP that connects to the Proxy server.");
logger.info("Player Analytics partially enabled (Use /planbungee to reload config)");
logger.info("Player Analytics partially enabled (Use /planproxy reload to reload config)");
throw new EnableException("IP setting still 0.0.0.0 - Configure Alternative_IP/IP that connects to the Proxy server.");
}
}