mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-01 14:07:54 +01:00
Removed static usage from placeholders
- Dagger used to reduce the amount of method parameters. Affects: - #1404
This commit is contained in:
parent
0066813c28
commit
4371595ccf
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.addons.placeholderapi.PlaceholderRegistrar;
|
||||
import com.djrapitops.plan.addons.placeholderapi.BukkitPlaceholderRegistrar;
|
||||
import com.djrapitops.plan.commands.PlanCommand;
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||
@ -55,7 +55,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
||||
system.enable();
|
||||
|
||||
registerMetrics();
|
||||
registerPlaceholderAPIExtension();
|
||||
registerPlaceholderAPIExtension(component.placeholders());
|
||||
|
||||
logger.debug("Verbose debug messages are enabled.");
|
||||
String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
|
||||
@ -82,13 +82,13 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerPlaceholderAPIExtension() {
|
||||
private void registerPlaceholderAPIExtension(BukkitPlaceholderRegistrar placeholders) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
runnableFactory.create("Placeholders Registrar", new AbsRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PlaceholderRegistrar.register(system, errorHandler);
|
||||
placeholders.register();
|
||||
} catch (Exception | NoClassDefFoundError | NoSuchMethodError failed) {
|
||||
logger.warn("Failed to register PlaceholderAPI placeholders: " + failed.toString());
|
||||
}
|
||||
|
@ -16,9 +16,11 @@
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.addons.placeholderapi.BukkitPlaceholderRegistrar;
|
||||
import com.djrapitops.plan.commands.PlanCommand;
|
||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import com.djrapitops.plan.modules.bukkit.BukkitPlanModule;
|
||||
import com.djrapitops.plan.modules.bukkit.BukkitServerPropertiesModule;
|
||||
@ -38,6 +40,7 @@ import javax.inject.Singleton;
|
||||
BukkitPlanModule.class,
|
||||
SystemObjectProvidingModule.class,
|
||||
APFModule.class,
|
||||
PlaceholderModule.class,
|
||||
|
||||
BukkitServerPropertiesModule.class,
|
||||
BukkitSuperClassBindingModule.class
|
||||
@ -48,6 +51,8 @@ public interface PlanBukkitComponent {
|
||||
|
||||
PlanSystem system();
|
||||
|
||||
BukkitPlaceholderRegistrar placeholders();
|
||||
|
||||
ServerShutdownSave serverShutdownSave();
|
||||
|
||||
@Component.Builder
|
||||
|
@ -26,6 +26,8 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
@ -38,26 +40,30 @@ import java.util.Collections;
|
||||
* {@link ServerKeys#TPS},{@link ServerKeys#NAME},
|
||||
* {@link ServerKeys#SERVER_UUID}</li>
|
||||
* <li>{@link OperatorPlaceholders}: {@link ServerKeys#OPERATORS}</li>
|
||||
* <li>{@link WorldTimePlaceHolder}: {@link ServerKeys#WORLD_TIMES}</li>
|
||||
* <li>{@link SessionPlaceHolder}: {@link ServerKeys#SESSIONS},
|
||||
* <li>{@link WorldTimePlaceHolders}: {@link ServerKeys#WORLD_TIMES}</li>
|
||||
* <li>{@link SessionPlaceHolders}: {@link ServerKeys#SESSIONS},
|
||||
* {@link ServerKeys#PLAYERS},{@link ServerKeys#PING},{@link ServerKeys#ALL_TIME_PEAK_PLAYERS},
|
||||
* {@link ServerKeys#RECENT_PEAK_PLAYERS}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author aidn5
|
||||
*/
|
||||
public class BukkitPlanPlaceHolders extends PlaceholderExpansion {
|
||||
@Singleton
|
||||
public class BukkitPlaceholderRegistrar extends PlaceholderExpansion {
|
||||
|
||||
public final ErrorHandler errorHandler;
|
||||
private final VersionChecker versionChecker;
|
||||
private final PlanPlaceholders placeholders;
|
||||
|
||||
public BukkitPlanPlaceHolders(
|
||||
@Inject
|
||||
public BukkitPlaceholderRegistrar(
|
||||
PlanPlaceholders placeholders,
|
||||
PlanSystem system,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.placeholders = placeholders;
|
||||
this.versionChecker = system.getVersionChecker();
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
PlanPlaceholders.init(system);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -94,7 +100,7 @@ public class BukkitPlanPlaceHolders extends PlaceholderExpansion {
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player p, String params) {
|
||||
try {
|
||||
String value = PlanPlaceholders.onPlaceholderRequest(p.getUniqueId(), params, Collections.emptyList());
|
||||
String value = placeholders.onPlaceholderRequest(p.getUniqueId(), params, Collections.emptyList());
|
||||
|
||||
if ("true".equals(value)) { //hack
|
||||
value = PlaceholderAPIPlugin.booleanTrue();
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.addons.placeholderapi;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
/**
|
||||
* Additional wrapper to register PlaceholderAPI placeholders.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlaceholderRegistrar {
|
||||
|
||||
private PlaceholderRegistrar() {
|
||||
}
|
||||
|
||||
public static void register(PlanSystem system, ErrorHandler errorHandler) {
|
||||
new BukkitPlanPlaceHolders(system, errorHandler).register();
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,7 @@ package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.commands.PlanProxyCommand;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import com.djrapitops.plan.modules.bungee.BungeeCommandModule;
|
||||
@ -40,6 +41,7 @@ import javax.inject.Singleton;
|
||||
BungeeCommandModule.class,
|
||||
SystemObjectProvidingModule.class,
|
||||
APFModule.class,
|
||||
PlaceholderModule.class,
|
||||
|
||||
ProxySuperClassBindingModule.class,
|
||||
BungeeSuperClassBindingModule.class,
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.djrapitops.plan.modules;
|
||||
|
||||
import com.djrapitops.plan.placeholder.*;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.multibindings.IntoSet;
|
||||
|
||||
@Module
|
||||
public interface PlaceholderModule {
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
PlaceholderRegistry bindOperatorPlaceholders(OperatorPlaceholders placeholders);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
PlaceholderRegistry bindPlayerPlaceHolders(PlayerPlaceHolders placeholders);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
PlaceholderRegistry bindServerPlaceHolders(ServerPlaceHolders placeholders);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
PlaceholderRegistry bindSessionPlaceHolders(SessionPlaceHolders placeholders);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
PlaceholderRegistry bindWorldTimePlaceHolders(WorldTimePlaceHolders placeholders);
|
||||
|
||||
}
|
@ -20,15 +20,31 @@ import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Placeholders about operators.
|
||||
*
|
||||
* @author aidn5, Rsl1122
|
||||
*/
|
||||
public class OperatorPlaceholders {
|
||||
@Singleton
|
||||
public class OperatorPlaceholders implements PlaceholderRegistry {
|
||||
|
||||
public static void register(DBSystem dbSystem, ServerInfo serverInfo) {
|
||||
PlanPlaceholders.registerStatic("operators_total",
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
|
||||
@Inject
|
||||
public OperatorPlaceholders(
|
||||
DBSystem dbSystem, ServerInfo serverInfo
|
||||
) {
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(PlanPlaceholders placeholders) {
|
||||
placeholders.registerStatic("operators_total",
|
||||
() -> dbSystem.getDatabase().query(PlayerCountQueries.operators(serverInfo.getServerUUID()))
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.djrapitops.plan.placeholder;
|
||||
|
||||
public interface PlaceholderRegistry {
|
||||
|
||||
void register(PlanPlaceholders placeholders);
|
||||
|
||||
}
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package com.djrapitops.plan.placeholder;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.domain.container.PlayerContainer;
|
||||
import com.djrapitops.plan.delivery.domain.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.delivery.formatting.Formatters;
|
||||
@ -26,6 +25,8 @@ import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
@ -33,58 +34,64 @@ import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Singleton
|
||||
public final class PlanPlaceholders {
|
||||
|
||||
private static final Map<String, BiFunction<PlayerContainer, List<String>, Serializable>> placeholders = new HashMap<>();
|
||||
private static final Map<String, Function<List<String>, Serializable>> staticPlaceholders = new HashMap<>();
|
||||
private final Map<String, PlayerPlaceholderLoader> playerPlaceholders;
|
||||
private final Map<String, StaticPlaceholderLoader> staticPlaceholders;
|
||||
|
||||
private static final Map<String, BiFunction<String, PlayerContainer, Serializable>> rawHandlers = new HashMap<>();
|
||||
private final Map<String, BiFunction<String, PlayerContainer, Serializable>> rawHandlers;
|
||||
|
||||
private static DBSystem dbSystem;
|
||||
private final DBSystem dbSystem;
|
||||
|
||||
public static void init(PlanSystem system) {
|
||||
dbSystem = system.getDatabaseSystem();
|
||||
@Inject
|
||||
public PlanPlaceholders(
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
Formatters formatters,
|
||||
Set<PlaceholderRegistry> placeholderRegistries
|
||||
) {
|
||||
this.dbSystem = dbSystem;
|
||||
|
||||
PlanConfig config = system.getConfigSystem().getConfig();
|
||||
ServerInfo serverInfo = system.getServerInfo();
|
||||
Formatters formatters = system.getDeliveryUtilities().getFormatters();
|
||||
this.playerPlaceholders = new HashMap<>();
|
||||
this.staticPlaceholders = new HashMap<>();
|
||||
this.rawHandlers = new HashMap<>();
|
||||
|
||||
ServerPlaceHolders.register(dbSystem, serverInfo, formatters);
|
||||
OperatorPlaceholders.register(dbSystem, serverInfo);
|
||||
WorldTimePlaceHolder.register(dbSystem, serverInfo, formatters);
|
||||
SessionPlaceHolder.register(config, dbSystem, serverInfo, formatters);
|
||||
PlayerPlaceHolder.register(dbSystem, serverInfo, formatters);
|
||||
for (PlaceholderRegistry registry : placeholderRegistries) {
|
||||
registry.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerStatic(String name, Supplier<Serializable> loader) {
|
||||
public void registerStatic(String name, Supplier<Serializable> loader) {
|
||||
registerStatic(name, params -> loader.get());
|
||||
}
|
||||
|
||||
public static void registerStatic(String name, Function<List<String>, Serializable> loader) {
|
||||
public void registerStatic(String name, StaticPlaceholderLoader loader) {
|
||||
staticPlaceholders.put(name, loader);
|
||||
}
|
||||
|
||||
public static void register(String name, Function<PlayerContainer, Serializable> loader) {
|
||||
public void register(String name, Function<PlayerContainer, Serializable> loader) {
|
||||
register(name, (player, params) -> loader.apply(player));
|
||||
}
|
||||
|
||||
public static void register(String name, BiFunction<PlayerContainer, List<String>, Serializable> loader) {
|
||||
placeholders.put(name, loader);
|
||||
public void register(String name, PlayerPlaceholderLoader loader) {
|
||||
playerPlaceholders.put(name, loader);
|
||||
}
|
||||
|
||||
public static void registerRaw(String name, BiFunction<String, PlayerContainer, Serializable> loader) {
|
||||
public void registerRaw(String name, BiFunction<String, PlayerContainer, Serializable> loader) {
|
||||
rawHandlers.put(name, loader);
|
||||
}
|
||||
|
||||
public static Map<String, BiFunction<PlayerContainer, List<String>, Serializable>> getPlaceholders() {
|
||||
return placeholders;
|
||||
public Map<String, PlayerPlaceholderLoader> getPlaceholders() {
|
||||
return playerPlaceholders;
|
||||
}
|
||||
|
||||
public static Map<String, Function<List<String>, Serializable>> getStaticPlaceholders() {
|
||||
public Map<String, StaticPlaceholderLoader> getStaticPlaceholders() {
|
||||
return staticPlaceholders;
|
||||
}
|
||||
|
||||
public static String onPlaceholderRequest(UUID uuid, String placeholder, List<String> parameters) {
|
||||
public String onPlaceholderRequest(UUID uuid, String placeholder, List<String> parameters) {
|
||||
PlayerContainer player;
|
||||
|
||||
if (uuid != null) {
|
||||
@ -106,23 +113,22 @@ public final class PlanPlaceholders {
|
||||
* @return the value of the placeholder if found, or empty {@link String} if no
|
||||
* value found but the placeholder is registered,
|
||||
* otherwise {@code null}
|
||||
* @throws Exception if any error occurs
|
||||
*/
|
||||
public static String onPlaceholderRequest(PlayerContainer player, String placeholder, List<String> parameters) {
|
||||
public String onPlaceholderRequest(PlayerContainer player, String placeholder, List<String> parameters) {
|
||||
for (Entry<String, BiFunction<String, PlayerContainer, Serializable>> entry : rawHandlers.entrySet()) {
|
||||
if (placeholder.startsWith(entry.getKey())) {
|
||||
return Objects.toString(entry.getValue().apply(placeholder, player));
|
||||
}
|
||||
}
|
||||
|
||||
Function<List<String>, Serializable> staticLoader = staticPlaceholders.get(placeholder);
|
||||
StaticPlaceholderLoader staticLoader = staticPlaceholders.get(placeholder);
|
||||
|
||||
if (staticLoader != null) {
|
||||
return Objects.toString(staticLoader.apply(parameters));
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
BiFunction<PlayerContainer, List<String>, Serializable> loader = placeholders.get(placeholder);
|
||||
PlayerPlaceholderLoader loader = playerPlaceholders.get(placeholder);
|
||||
|
||||
if (loader != null) {
|
||||
return Objects.toString(loader.apply(player, parameters));
|
||||
@ -131,4 +137,8 @@ public final class PlanPlaceholders {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public interface PlayerPlaceholderLoader extends BiFunction<PlayerContainer, List<String>, Serializable> {}
|
||||
|
||||
public interface StaticPlaceholderLoader extends Function<List<String>, Serializable> {}
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import com.djrapitops.plan.utilities.Predicates;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import static com.djrapitops.plan.utilities.MiscUtils.*;
|
||||
|
||||
/**
|
||||
@ -36,156 +39,171 @@ import static com.djrapitops.plan.utilities.MiscUtils.*;
|
||||
*
|
||||
* @author aidn5, Rsl1122
|
||||
*/
|
||||
public class PlayerPlaceHolder {
|
||||
@Singleton
|
||||
public class PlayerPlaceHolders implements PlaceholderRegistry {
|
||||
|
||||
public static void register(
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final Formatters formatters;
|
||||
|
||||
@Inject
|
||||
public PlayerPlaceHolders(
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
Formatters formatters
|
||||
) {
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.formatters = formatters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(
|
||||
PlanPlaceholders placeholders
|
||||
) {
|
||||
Formatter<Double> decimals = formatters.decimals();
|
||||
Formatter<Long> year = formatters.yearLong();
|
||||
Formatter<Long> time = formatters.timeAmount();
|
||||
|
||||
PlanPlaceholders.register("player_banned",
|
||||
placeholders.register("player_banned",
|
||||
player -> player.getValue(PlayerKeys.BANNED)
|
||||
.orElse(Boolean.FALSE)
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_operator",
|
||||
placeholders.register("player_operator",
|
||||
player -> player.getValue(PlayerKeys.OPERATOR)
|
||||
.orElse(Boolean.FALSE)
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_sessions_count",
|
||||
placeholders.register("player_sessions_count",
|
||||
player -> SessionsMutator.forContainer(player)
|
||||
.count()
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_kick_count",
|
||||
placeholders.register("player_kick_count",
|
||||
player -> player.getValue(PlayerKeys.KICK_COUNT)
|
||||
.orElse(0)
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_death_count",
|
||||
placeholders.register("player_death_count",
|
||||
player -> player.getValue(PlayerKeys.DEATH_COUNT)
|
||||
.orElse(0)
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_mob_kill_count",
|
||||
placeholders.register("player_mob_kill_count",
|
||||
player -> player.getValue(PlayerKeys.MOB_KILL_COUNT)
|
||||
.orElse(0)
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_player_kill_count",
|
||||
placeholders.register("player_player_kill_count",
|
||||
player -> player.getValue(PlayerKeys.PLAYER_KILL_COUNT)
|
||||
.orElse(0)
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_kill_death_ratio",
|
||||
placeholders.register("player_kill_death_ratio",
|
||||
player -> PlayerVersusMutator.forContainer(player).toKillDeathRatio());
|
||||
|
||||
PlanPlaceholders.register("player_ping_average_day",
|
||||
placeholders.register("player_ping_average_day",
|
||||
player -> decimals.apply(PingMutator.forContainer(player)
|
||||
.filterBy(Predicates.within(dayAgo(), now()))
|
||||
.average()) + " ms"
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_ping_average_week",
|
||||
placeholders.register("player_ping_average_week",
|
||||
player -> decimals.apply(PingMutator.forContainer(player)
|
||||
.filterBy(Predicates.within(weekAgo(), now()))
|
||||
.average()) + " ms"
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_ping_average_month",
|
||||
placeholders.register("player_ping_average_month",
|
||||
player -> decimals.apply(PingMutator.forContainer(player)
|
||||
.filterBy(Predicates.within(monthAgo(), now()))
|
||||
.average()) + " ms"
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_lastseen",
|
||||
placeholders.register("player_lastseen",
|
||||
player -> year.apply(player.getValue(PlayerKeys.LAST_SEEN)
|
||||
.orElse((long) 0))
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_registered",
|
||||
placeholders.register("player_registered",
|
||||
player -> year.apply(player.getValue(PlayerKeys.REGISTERED)
|
||||
.orElse((long) 0))
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_time_active",
|
||||
placeholders.register("player_time_active",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.toActivePlaytime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_time_afk",
|
||||
placeholders.register("player_time_afk",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.toAfkTime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_time_total",
|
||||
placeholders.register("player_time_total",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.toPlaytime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_time_day",
|
||||
placeholders.register("player_time_day",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.filterSessionsBetween(dayAgo(), now())
|
||||
.toPlaytime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_time_week",
|
||||
placeholders.register("player_time_week",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.filterSessionsBetween(weekAgo(), now())
|
||||
.toPlaytime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_time_month",
|
||||
placeholders.register("player_time_month",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.filterSessionsBetween(monthAgo(), now())
|
||||
.toPlaytime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_server_time_active",
|
||||
placeholders.register("player_server_time_active",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||
.toActivePlaytime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_server_time_afk",
|
||||
placeholders.register("player_server_time_afk",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||
.toAfkTime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_server_time_total",
|
||||
placeholders.register("player_server_time_total",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||
.toPlaytime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_server_time_day",
|
||||
placeholders.register("player_server_time_day",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.filterSessionsBetween(dayAgo(), now())
|
||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||
.toPlaytime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_server_time_week",
|
||||
placeholders.register("player_server_time_week",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.filterSessionsBetween(weekAgo(), now())
|
||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||
.toPlaytime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_server_time_month",
|
||||
placeholders.register("player_server_time_month",
|
||||
player -> time.apply(SessionsMutator.forContainer(player)
|
||||
.filterSessionsBetween(monthAgo(), now())
|
||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||
.toPlaytime())
|
||||
);
|
||||
|
||||
PlanPlaceholders.register("player_favorite_server",
|
||||
placeholders.register("player_favorite_server",
|
||||
player -> PerServerMutator.forContainer(player).favoriteServer()
|
||||
.flatMap(serverUUID -> dbSystem.getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverUUID)))
|
||||
.map(Server::getName)
|
@ -23,6 +23,8 @@ import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.djrapitops.plan.utilities.MiscUtils.*;
|
||||
@ -32,12 +34,27 @@ import static com.djrapitops.plan.utilities.MiscUtils.*;
|
||||
*
|
||||
* @author aidn5, Rsl1122
|
||||
*/
|
||||
public class ServerPlaceHolders {
|
||||
@Singleton
|
||||
public class ServerPlaceHolders implements PlaceholderRegistry {
|
||||
|
||||
public static void register(
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final Formatters formatters;
|
||||
|
||||
@Inject
|
||||
public ServerPlaceHolders(
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
Formatters formatters
|
||||
) {
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.formatters = formatters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(
|
||||
PlanPlaceholders placeholders
|
||||
) {
|
||||
Formatter<Double> decimals = formatters.decimals();
|
||||
Formatter<Double> percentage = formatters.percentage();
|
||||
@ -45,82 +62,82 @@ public class ServerPlaceHolders {
|
||||
Database database = dbSystem.getDatabase();
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
|
||||
PlanPlaceholders.registerStatic("server_tps_day",
|
||||
placeholders.registerStatic("server_tps_day",
|
||||
() -> decimals.apply(database.query(TPSQueries.averageTPS(dayAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_tps_week",
|
||||
placeholders.registerStatic("server_tps_week",
|
||||
() -> decimals.apply(database.query(TPSQueries.averageTPS(weekAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_tps_month",
|
||||
placeholders.registerStatic("server_tps_month",
|
||||
() -> decimals.apply(database.query(TPSQueries.averageTPS(monthAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_cpu_day",
|
||||
placeholders.registerStatic("server_cpu_day",
|
||||
() -> percentage.apply(database.query(TPSQueries.averageCPU(dayAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_cpu_week",
|
||||
placeholders.registerStatic("server_cpu_week",
|
||||
() -> percentage.apply(database.query(TPSQueries.averageCPU(weekAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_cpu_month",
|
||||
placeholders.registerStatic("server_cpu_month",
|
||||
() -> percentage.apply(database.query(TPSQueries.averageCPU(monthAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_ram_day",
|
||||
placeholders.registerStatic("server_ram_day",
|
||||
() -> database.query(TPSQueries.averageRAM(dayAgo(), now(), serverUUID)) + " MB");
|
||||
|
||||
PlanPlaceholders.registerStatic("server_ram_week",
|
||||
placeholders.registerStatic("server_ram_week",
|
||||
() -> database.query(TPSQueries.averageRAM(weekAgo(), now(), serverUUID)) + " MB");
|
||||
|
||||
PlanPlaceholders.registerStatic("server_ram_month",
|
||||
placeholders.registerStatic("server_ram_month",
|
||||
() -> database.query(TPSQueries.averageRAM(monthAgo(), now(), serverUUID)) + " MB");
|
||||
|
||||
PlanPlaceholders.registerStatic("server_chunks_day",
|
||||
placeholders.registerStatic("server_chunks_day",
|
||||
() -> database.query(TPSQueries.averageChunks(dayAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_chunks_week",
|
||||
placeholders.registerStatic("server_chunks_week",
|
||||
() -> database.query(TPSQueries.averageChunks(weekAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_chunks_month",
|
||||
placeholders.registerStatic("server_chunks_month",
|
||||
() -> database.query(TPSQueries.averageChunks(monthAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_entities_day",
|
||||
placeholders.registerStatic("server_entities_day",
|
||||
() -> database.query(TPSQueries.averageEntities(dayAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_entities_week",
|
||||
placeholders.registerStatic("server_entities_week",
|
||||
() -> database.query(TPSQueries.averageEntities(weekAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_entities_month",
|
||||
placeholders.registerStatic("server_entities_month",
|
||||
() -> database.query(TPSQueries.averageEntities(monthAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_max_free_disk_day",
|
||||
placeholders.registerStatic("server_max_free_disk_day",
|
||||
() -> database.query(TPSQueries.maxFreeDisk(dayAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_max_free_disk_week",
|
||||
placeholders.registerStatic("server_max_free_disk_week",
|
||||
() -> database.query(TPSQueries.maxFreeDisk(weekAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_max_free_disk_month",
|
||||
placeholders.registerStatic("server_max_free_disk_month",
|
||||
() -> database.query(TPSQueries.maxFreeDisk(monthAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_min_free_disk_day",
|
||||
placeholders.registerStatic("server_min_free_disk_day",
|
||||
() -> database.query(TPSQueries.minFreeDisk(dayAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_min_free_disk_week",
|
||||
placeholders.registerStatic("server_min_free_disk_week",
|
||||
() -> database.query(TPSQueries.minFreeDisk(weekAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_min_free_disk_month",
|
||||
placeholders.registerStatic("server_min_free_disk_month",
|
||||
() -> database.query(TPSQueries.minFreeDisk(monthAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_average_free_disk_day",
|
||||
placeholders.registerStatic("server_average_free_disk_day",
|
||||
() -> database.query(TPSQueries.averageFreeDisk(dayAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_average_free_disk_week",
|
||||
placeholders.registerStatic("server_average_free_disk_week",
|
||||
() -> database.query(TPSQueries.averageFreeDisk(weekAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_average_free_disk_month",
|
||||
placeholders.registerStatic("server_average_free_disk_month",
|
||||
() -> database.query(TPSQueries.averageFreeDisk(monthAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("server_name",
|
||||
placeholders.registerStatic("server_name",
|
||||
() -> serverInfo.getServer().getName());
|
||||
|
||||
PlanPlaceholders.registerStatic("server_uuid",
|
||||
placeholders.registerStatic("server_uuid",
|
||||
serverInfo::getServerUUID);
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ import com.djrapitops.plan.storage.database.queries.objects.PingQueries;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.SessionQueries;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
@ -41,13 +43,30 @@ import static com.djrapitops.plan.utilities.MiscUtils.*;
|
||||
*
|
||||
* @author aidn5, Rsl1122
|
||||
*/
|
||||
public class SessionPlaceHolder {
|
||||
@Singleton
|
||||
public class SessionPlaceHolders implements PlaceholderRegistry {
|
||||
|
||||
public static void register(
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final Formatters formatters;
|
||||
|
||||
@Inject
|
||||
public SessionPlaceHolders(
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
Formatters formatters
|
||||
) {
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.formatters = formatters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(
|
||||
PlanPlaceholders placeholders
|
||||
) {
|
||||
int tzOffsetMs = config.getTimeZone().getOffset(System.currentTimeMillis());
|
||||
Formatter<Long> timeAmount = formatters.timeAmount();
|
||||
@ -56,146 +75,146 @@ public class SessionPlaceHolder {
|
||||
Database database = dbSystem.getDatabase();
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_play_time_total",
|
||||
placeholders.registerStatic("sessions_play_time_total",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.playtime(0L, now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_play_time_day",
|
||||
placeholders.registerStatic("sessions_play_time_day",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.playtime(dayAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_play_time_week",
|
||||
placeholders.registerStatic("sessions_play_time_week",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.playtime(weekAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_play_time_month",
|
||||
placeholders.registerStatic("sessions_play_time_month",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.playtime(monthAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_active_time_total",
|
||||
placeholders.registerStatic("sessions_active_time_total",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.activePlaytime(0L, now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_active_time_day",
|
||||
placeholders.registerStatic("sessions_active_time_day",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.activePlaytime(dayAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_active_time_week",
|
||||
placeholders.registerStatic("sessions_active_time_week",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.activePlaytime(weekAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_active_time_month",
|
||||
placeholders.registerStatic("sessions_active_time_month",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.activePlaytime(monthAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_afk_time_total",
|
||||
placeholders.registerStatic("sessions_afk_time_total",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.afkTime(0L, now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_afk_time_day",
|
||||
placeholders.registerStatic("sessions_afk_time_day",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.afkTime(dayAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_afk_time_week",
|
||||
placeholders.registerStatic("sessions_afk_time_week",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.afkTime(weekAgo(), now(), serverUUID))));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_afk_time_month",
|
||||
placeholders.registerStatic("sessions_afk_time_month",
|
||||
() -> timeAmount.apply(database.query(SessionQueries.afkTime(monthAgo(), now(), serverUUID))));
|
||||
|
||||
Supplier<Serializable> uniquePlayers = () -> database.query(PlayerCountQueries.newPlayerCount(0L, now(), serverUUID));
|
||||
PlanPlaceholders.registerStatic("sessions_unique_players_total", uniquePlayers);
|
||||
PlanPlaceholders.registerStatic("sessions_new_players_total", uniquePlayers);
|
||||
placeholders.registerStatic("sessions_unique_players_total", uniquePlayers);
|
||||
placeholders.registerStatic("sessions_new_players_total", uniquePlayers);
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_unique_players_day",
|
||||
placeholders.registerStatic("sessions_unique_players_day",
|
||||
() -> database.query(PlayerCountQueries.uniquePlayerCount(dayAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_unique_players_week",
|
||||
placeholders.registerStatic("sessions_unique_players_week",
|
||||
() -> database.query(PlayerCountQueries.uniquePlayerCount(weekAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_unique_players_month",
|
||||
placeholders.registerStatic("sessions_unique_players_month",
|
||||
() -> database.query(PlayerCountQueries.uniquePlayerCount(monthAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_players_death_total",
|
||||
placeholders.registerStatic("sessions_players_death_total",
|
||||
() -> database.query(KillQueries.deathCount(0L, now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_players_death_day",
|
||||
placeholders.registerStatic("sessions_players_death_day",
|
||||
() -> database.query(KillQueries.deathCount(dayAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_players_death_week",
|
||||
placeholders.registerStatic("sessions_players_death_week",
|
||||
() -> database.query(KillQueries.deathCount(weekAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_players_death_month",
|
||||
placeholders.registerStatic("sessions_players_death_month",
|
||||
() -> database.query(KillQueries.deathCount(monthAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_players_kill_total",
|
||||
placeholders.registerStatic("sessions_players_kill_total",
|
||||
() -> database.query(KillQueries.playerKillCount(0L, now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_players_kill_day",
|
||||
placeholders.registerStatic("sessions_players_kill_day",
|
||||
() -> database.query(KillQueries.playerKillCount(dayAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_players_kill_week",
|
||||
placeholders.registerStatic("sessions_players_kill_week",
|
||||
() -> database.query(KillQueries.playerKillCount(weekAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_players_kill_month",
|
||||
placeholders.registerStatic("sessions_players_kill_month",
|
||||
() -> database.query(KillQueries.playerKillCount(monthAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_mob_kill_total",
|
||||
placeholders.registerStatic("sessions_mob_kill_total",
|
||||
() -> database.query(KillQueries.mobKillCount(0L, now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_mob_kill_day",
|
||||
placeholders.registerStatic("sessions_mob_kill_day",
|
||||
() -> database.query(KillQueries.mobKillCount(dayAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_mob_kill_week",
|
||||
placeholders.registerStatic("sessions_mob_kill_week",
|
||||
() -> database.query(KillQueries.mobKillCount(weekAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_mob_kill_month",
|
||||
placeholders.registerStatic("sessions_mob_kill_month",
|
||||
() -> database.query(KillQueries.mobKillCount(monthAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_average_session_length_total",
|
||||
placeholders.registerStatic("sessions_average_session_length_total",
|
||||
() -> getPlaytime(database, 0L, now(), serverUUID, timeAmount));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_average_session_length_day",
|
||||
placeholders.registerStatic("sessions_average_session_length_day",
|
||||
() -> getPlaytime(database, dayAgo(), now(), serverUUID, timeAmount));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_average_session_length_week",
|
||||
placeholders.registerStatic("sessions_average_session_length_week",
|
||||
() -> getPlaytime(database, weekAgo(), now(), serverUUID, timeAmount));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_average_session_length_month",
|
||||
placeholders.registerStatic("sessions_average_session_length_month",
|
||||
() -> getPlaytime(database, monthAgo(), now(), serverUUID, timeAmount));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_average_unique_players_total",
|
||||
placeholders.registerStatic("sessions_average_unique_players_total",
|
||||
() -> database.query(PlayerCountQueries.averageUniquePlayerCount(0L, now(), tzOffsetMs, serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_average_unique_players_day",
|
||||
placeholders.registerStatic("sessions_average_unique_players_day",
|
||||
() -> database.query(PlayerCountQueries.averageUniquePlayerCount(dayAgo(), now(), tzOffsetMs, serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_average_unique_players_week",
|
||||
placeholders.registerStatic("sessions_average_unique_players_week",
|
||||
() -> database.query(PlayerCountQueries.averageUniquePlayerCount(weekAgo(), now(), tzOffsetMs, serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_average_unique_players_month",
|
||||
placeholders.registerStatic("sessions_average_unique_players_month",
|
||||
() -> database.query(PlayerCountQueries.averageUniquePlayerCount(monthAgo(), now(), tzOffsetMs, serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_new_players_day",
|
||||
placeholders.registerStatic("sessions_new_players_day",
|
||||
() -> database.query(PlayerCountQueries.newPlayerCount(dayAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_new_players_week",
|
||||
placeholders.registerStatic("sessions_new_players_week",
|
||||
() -> database.query(PlayerCountQueries.newPlayerCount(weekAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_new_players_month",
|
||||
placeholders.registerStatic("sessions_new_players_month",
|
||||
() -> database.query(PlayerCountQueries.newPlayerCount(monthAgo(), now(), serverUUID)));
|
||||
|
||||
PlanPlaceholders.registerStatic("ping_total",
|
||||
placeholders.registerStatic("ping_total",
|
||||
() -> decimals.apply(database.query(PingQueries.averagePing(0L, now(), serverUUID))) + " ms");
|
||||
|
||||
PlanPlaceholders.registerStatic("ping_day",
|
||||
placeholders.registerStatic("ping_day",
|
||||
() -> decimals.apply(database.query(PingQueries.averagePing(dayAgo(), now(), serverUUID))) + " ms");
|
||||
|
||||
PlanPlaceholders.registerStatic("ping_week",
|
||||
placeholders.registerStatic("ping_week",
|
||||
() -> decimals.apply(database.query(PingQueries.averagePing(weekAgo(), now(), serverUUID))) + " ms");
|
||||
|
||||
PlanPlaceholders.registerStatic("ping_month",
|
||||
placeholders.registerStatic("ping_month",
|
||||
() -> decimals.apply(database.query(PingQueries.averagePing(monthAgo(), now(), serverUUID))) + " ms");
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_peak_count",
|
||||
placeholders.registerStatic("sessions_peak_count",
|
||||
() -> database.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID)).map(DateObj::getValue).orElse(0));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_peak_date",
|
||||
placeholders.registerStatic("sessions_peak_date",
|
||||
() -> database.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID)).map(year).orElse("-"));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_recent_peak_count",
|
||||
placeholders.registerStatic("sessions_recent_peak_count",
|
||||
() -> database.query(TPSQueries.fetchPeakPlayerCount(serverUUID, dayAgo() * 2L)).map(DateObj::getValue).orElse(0));
|
||||
|
||||
PlanPlaceholders.registerStatic("sessions_recent_peak_date",
|
||||
placeholders.registerStatic("sessions_recent_peak_date",
|
||||
() -> database.query(TPSQueries.fetchPeakPlayerCount(serverUUID, dayAgo() * 2L)).map(year).orElse("-"));
|
||||
}
|
||||
|
@ -23,21 +23,39 @@ import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Placeholders about a world times.
|
||||
*
|
||||
* @author aidn5, Rsl1122
|
||||
*/
|
||||
public class WorldTimePlaceHolder {
|
||||
@Singleton
|
||||
public class WorldTimePlaceHolders implements PlaceholderRegistry {
|
||||
|
||||
public static void register(
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final Formatters formatters;
|
||||
|
||||
@Inject
|
||||
public WorldTimePlaceHolders(
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
Formatters formatters
|
||||
) {
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.formatters = formatters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(
|
||||
PlanPlaceholders placeholders
|
||||
) {
|
||||
Formatter<Long> timeAmount = formatters.timeAmount();
|
||||
|
||||
PlanPlaceholders.registerRaw("worlds_playtime_total_", (input, p) -> {
|
||||
placeholders.registerRaw("worlds_playtime_total_", (input, p) -> {
|
||||
// get world total play time
|
||||
// e.g. "plan_worlds_playtime_total_%worldname%"
|
||||
// where %worldname% is "world_nether"
|
||||
@ -48,7 +66,7 @@ public class WorldTimePlaceHolder {
|
||||
return timeAmount.apply(worldTimes.getWorldPlaytime(worldName));
|
||||
});
|
||||
|
||||
PlanPlaceholders.registerStatic("worlds_playtime_total", params -> {
|
||||
placeholders.registerStatic("worlds_playtime_total", params -> {
|
||||
if (params.isEmpty()) {
|
||||
return null;
|
||||
}
|
@ -20,6 +20,7 @@ import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.commands.PlanCommand;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
@ -36,6 +37,7 @@ import javax.inject.Singleton;
|
||||
PlanPluginModule.class,
|
||||
SystemObjectProvidingModule.class,
|
||||
APFModule.class,
|
||||
PlaceholderModule.class,
|
||||
|
||||
PluginServerPropertiesModule.class,
|
||||
PluginSuperClassBindingModule.class
|
||||
|
@ -49,5 +49,4 @@ public interface PlanPluginModule {
|
||||
|
||||
@Binds
|
||||
ServerInfo bindServerInfo(ServerServerInfo serverServerInfo);
|
||||
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.addons.placeholderapi.NKPlaceholderRegistrar;
|
||||
import com.djrapitops.plan.addons.placeholderapi.NukkitPlaceholderRegistrar;
|
||||
import com.djrapitops.plan.commands.PlanCommand;
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||
@ -52,7 +52,7 @@ public class PlanNukkit extends NukkitPlugin implements PlanPlugin {
|
||||
locale = system.getLocaleSystem().getLocale();
|
||||
system.enable();
|
||||
|
||||
registerPlaceholderAPI();
|
||||
registerPlaceholderAPI(component.placeholders());
|
||||
|
||||
logger.debug("Verbose debug messages are enabled.");
|
||||
String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
|
||||
@ -119,13 +119,13 @@ public class PlanNukkit extends NukkitPlugin implements PlanPlugin {
|
||||
return system;
|
||||
}
|
||||
|
||||
private void registerPlaceholderAPI() {
|
||||
private void registerPlaceholderAPI(NukkitPlaceholderRegistrar placeholders) {
|
||||
if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
runnableFactory.create("Placeholders Registrar", new AbsRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
NKPlaceholderRegistrar.register(system, errorHandler);
|
||||
placeholders.register();
|
||||
} catch (Exception | NoClassDefFoundError | NoSuchMethodError failed) {
|
||||
logger.warn("Failed to register PlaceholderAPI placeholders: " + failed.toString());
|
||||
}
|
||||
|
@ -16,9 +16,11 @@
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.addons.placeholderapi.NukkitPlaceholderRegistrar;
|
||||
import com.djrapitops.plan.commands.PlanCommand;
|
||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import com.djrapitops.plan.modules.nukkit.NukkitPlanModule;
|
||||
import com.djrapitops.plan.modules.nukkit.NukkitServerPropertiesModule;
|
||||
@ -38,6 +40,7 @@ import javax.inject.Singleton;
|
||||
NukkitPlanModule.class,
|
||||
SystemObjectProvidingModule.class,
|
||||
APFModule.class,
|
||||
PlaceholderModule.class,
|
||||
|
||||
NukkitServerPropertiesModule.class,
|
||||
NukkitSuperClassBindingModule.class
|
||||
@ -50,6 +53,8 @@ public interface PlanNukkitComponent {
|
||||
|
||||
ServerShutdownSave serverShutdownSave();
|
||||
|
||||
NukkitPlaceholderRegistrar placeholders();
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
|
@ -27,24 +27,32 @@ import com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQue
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NKPlaceholderRegistrar {
|
||||
@Singleton
|
||||
public class NukkitPlaceholderRegistrar {
|
||||
|
||||
private final ErrorHandler errorHandler;
|
||||
private final PlanPlaceholders placeholders;
|
||||
private final PlanSystem system;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public NKPlaceholderRegistrar(PlanSystem system, ErrorHandler errorHandler) {
|
||||
@Inject
|
||||
public NukkitPlaceholderRegistrar(
|
||||
PlanPlaceholders placeholders,
|
||||
PlanSystem system,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.placeholders = placeholders;
|
||||
this.system = system;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
private void register0() {
|
||||
PlanPlaceholders.init(system);
|
||||
|
||||
public void register() {
|
||||
PlaceholderAPI api = PlaceholderAPI.getInstance();
|
||||
PlanPlaceholders.getPlaceholders().forEach((name, loader) ->
|
||||
placeholders.getPlaceholders().forEach((name, loader) ->
|
||||
api.visitorSensitivePlaceholder(name, (player, params) -> {
|
||||
try {
|
||||
return loader.apply(getPlayer(player), new ArrayList<>(params.getAll().values()));
|
||||
@ -55,7 +63,7 @@ public class NKPlaceholderRegistrar {
|
||||
}
|
||||
));
|
||||
|
||||
PlanPlaceholders.getStaticPlaceholders().forEach((name, loader) ->
|
||||
placeholders.getStaticPlaceholders().forEach((name, loader) ->
|
||||
api.staticPlaceholder(name, params -> {
|
||||
try {
|
||||
return loader.apply(new ArrayList<>(params.getAll().values()));
|
||||
@ -70,13 +78,9 @@ public class NKPlaceholderRegistrar {
|
||||
private PlayerContainer getPlayer(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
PlayerContainer p = system.getDatabaseSystem().getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid));
|
||||
SessionCache.getCachedSession(uuid).ifPresent(session -> p.putRawData(PlayerKeys.ACTIVE_SESSION, session));
|
||||
PlayerContainer container = system.getDatabaseSystem().getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid));
|
||||
SessionCache.getCachedSession(uuid).ifPresent(session -> container.putRawData(PlayerKeys.ACTIVE_SESSION, session));
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public static void register(PlanSystem system, ErrorHandler errorHandler) {
|
||||
new NKPlaceholderRegistrar(system, errorHandler).register0();
|
||||
return container;
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ package com.djrapitops.plan;
|
||||
import com.djrapitops.plan.commands.PlanCommand;
|
||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import com.djrapitops.plan.modules.sponge.SpongePlanModule;
|
||||
import com.djrapitops.plan.modules.sponge.SpongeServerPropertiesModule;
|
||||
@ -38,6 +39,7 @@ import javax.inject.Singleton;
|
||||
SpongePlanModule.class,
|
||||
SystemObjectProvidingModule.class,
|
||||
APFModule.class,
|
||||
PlaceholderModule.class,
|
||||
|
||||
SpongeSuperClassBindingModule.class,
|
||||
SpongeServerPropertiesModule.class
|
||||
|
@ -18,6 +18,7 @@ package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.commands.PlanProxyCommand;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||
import com.djrapitops.plan.modules.velocity.VelocityCommandModule;
|
||||
@ -40,6 +41,7 @@ import javax.inject.Singleton;
|
||||
VelocityCommandModule.class,
|
||||
SystemObjectProvidingModule.class,
|
||||
APFModule.class,
|
||||
PlaceholderModule.class,
|
||||
|
||||
ProxySuperClassBindingModule.class,
|
||||
VelocitySuperClassBindingModule.class,
|
||||
|
Loading…
Reference in New Issue
Block a user