mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-04 07:28:26 +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;
|
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.commands.PlanCommand;
|
||||||
import com.djrapitops.plan.exceptions.EnableException;
|
import com.djrapitops.plan.exceptions.EnableException;
|
||||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||||
@ -55,7 +55,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
|||||||
system.enable();
|
system.enable();
|
||||||
|
|
||||||
registerMetrics();
|
registerMetrics();
|
||||||
registerPlaceholderAPIExtension();
|
registerPlaceholderAPIExtension(component.placeholders());
|
||||||
|
|
||||||
logger.debug("Verbose debug messages are enabled.");
|
logger.debug("Verbose debug messages are enabled.");
|
||||||
String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
|
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")) {
|
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||||
runnableFactory.create("Placeholders Registrar", new AbsRunnable() {
|
runnableFactory.create("Placeholders Registrar", new AbsRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
PlaceholderRegistrar.register(system, errorHandler);
|
placeholders.register();
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchMethodError failed) {
|
} catch (Exception | NoClassDefFoundError | NoSuchMethodError failed) {
|
||||||
logger.warn("Failed to register PlaceholderAPI placeholders: " + failed.toString());
|
logger.warn("Failed to register PlaceholderAPI placeholders: " + failed.toString());
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan;
|
package com.djrapitops.plan;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.addons.placeholderapi.BukkitPlaceholderRegistrar;
|
||||||
import com.djrapitops.plan.commands.PlanCommand;
|
import com.djrapitops.plan.commands.PlanCommand;
|
||||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
|
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import com.djrapitops.plan.modules.bukkit.BukkitPlanModule;
|
import com.djrapitops.plan.modules.bukkit.BukkitPlanModule;
|
||||||
import com.djrapitops.plan.modules.bukkit.BukkitServerPropertiesModule;
|
import com.djrapitops.plan.modules.bukkit.BukkitServerPropertiesModule;
|
||||||
@ -38,6 +40,7 @@ import javax.inject.Singleton;
|
|||||||
BukkitPlanModule.class,
|
BukkitPlanModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
|
PlaceholderModule.class,
|
||||||
|
|
||||||
BukkitServerPropertiesModule.class,
|
BukkitServerPropertiesModule.class,
|
||||||
BukkitSuperClassBindingModule.class
|
BukkitSuperClassBindingModule.class
|
||||||
@ -48,6 +51,8 @@ public interface PlanBukkitComponent {
|
|||||||
|
|
||||||
PlanSystem system();
|
PlanSystem system();
|
||||||
|
|
||||||
|
BukkitPlaceholderRegistrar placeholders();
|
||||||
|
|
||||||
ServerShutdownSave serverShutdownSave();
|
ServerShutdownSave serverShutdownSave();
|
||||||
|
|
||||||
@Component.Builder
|
@Component.Builder
|
||||||
|
@ -26,6 +26,8 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
|||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,26 +40,30 @@ import java.util.Collections;
|
|||||||
* {@link ServerKeys#TPS},{@link ServerKeys#NAME},
|
* {@link ServerKeys#TPS},{@link ServerKeys#NAME},
|
||||||
* {@link ServerKeys#SERVER_UUID}</li>
|
* {@link ServerKeys#SERVER_UUID}</li>
|
||||||
* <li>{@link OperatorPlaceholders}: {@link ServerKeys#OPERATORS}</li>
|
* <li>{@link OperatorPlaceholders}: {@link ServerKeys#OPERATORS}</li>
|
||||||
* <li>{@link WorldTimePlaceHolder}: {@link ServerKeys#WORLD_TIMES}</li>
|
* <li>{@link WorldTimePlaceHolders}: {@link ServerKeys#WORLD_TIMES}</li>
|
||||||
* <li>{@link SessionPlaceHolder}: {@link ServerKeys#SESSIONS},
|
* <li>{@link SessionPlaceHolders}: {@link ServerKeys#SESSIONS},
|
||||||
* {@link ServerKeys#PLAYERS},{@link ServerKeys#PING},{@link ServerKeys#ALL_TIME_PEAK_PLAYERS},
|
* {@link ServerKeys#PLAYERS},{@link ServerKeys#PING},{@link ServerKeys#ALL_TIME_PEAK_PLAYERS},
|
||||||
* {@link ServerKeys#RECENT_PEAK_PLAYERS}</li>
|
* {@link ServerKeys#RECENT_PEAK_PLAYERS}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author aidn5
|
* @author aidn5
|
||||||
*/
|
*/
|
||||||
public class BukkitPlanPlaceHolders extends PlaceholderExpansion {
|
@Singleton
|
||||||
|
public class BukkitPlaceholderRegistrar extends PlaceholderExpansion {
|
||||||
|
|
||||||
public final ErrorHandler errorHandler;
|
public final ErrorHandler errorHandler;
|
||||||
private final VersionChecker versionChecker;
|
private final VersionChecker versionChecker;
|
||||||
|
private final PlanPlaceholders placeholders;
|
||||||
|
|
||||||
public BukkitPlanPlaceHolders(
|
@Inject
|
||||||
|
public BukkitPlaceholderRegistrar(
|
||||||
|
PlanPlaceholders placeholders,
|
||||||
PlanSystem system,
|
PlanSystem system,
|
||||||
ErrorHandler errorHandler
|
ErrorHandler errorHandler
|
||||||
) {
|
) {
|
||||||
|
this.placeholders = placeholders;
|
||||||
this.versionChecker = system.getVersionChecker();
|
this.versionChecker = system.getVersionChecker();
|
||||||
this.errorHandler = errorHandler;
|
this.errorHandler = errorHandler;
|
||||||
|
|
||||||
PlanPlaceholders.init(system);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -94,7 +100,7 @@ public class BukkitPlanPlaceHolders extends PlaceholderExpansion {
|
|||||||
@Override
|
@Override
|
||||||
public String onPlaceholderRequest(Player p, String params) {
|
public String onPlaceholderRequest(Player p, String params) {
|
||||||
try {
|
try {
|
||||||
String value = PlanPlaceholders.onPlaceholderRequest(p.getUniqueId(), params, Collections.emptyList());
|
String value = placeholders.onPlaceholderRequest(p.getUniqueId(), params, Collections.emptyList());
|
||||||
|
|
||||||
if ("true".equals(value)) { //hack
|
if ("true".equals(value)) { //hack
|
||||||
value = PlaceholderAPIPlugin.booleanTrue();
|
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.commands.PlanProxyCommand;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
|
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||||
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import com.djrapitops.plan.modules.bungee.BungeeCommandModule;
|
import com.djrapitops.plan.modules.bungee.BungeeCommandModule;
|
||||||
@ -40,6 +41,7 @@ import javax.inject.Singleton;
|
|||||||
BungeeCommandModule.class,
|
BungeeCommandModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
|
PlaceholderModule.class,
|
||||||
|
|
||||||
ProxySuperClassBindingModule.class,
|
ProxySuperClassBindingModule.class,
|
||||||
BungeeSuperClassBindingModule.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.DBSystem;
|
||||||
import com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries;
|
import com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholders about operators.
|
* Placeholders about operators.
|
||||||
*
|
*
|
||||||
* @author aidn5, Rsl1122
|
* @author aidn5, Rsl1122
|
||||||
*/
|
*/
|
||||||
public class OperatorPlaceholders {
|
@Singleton
|
||||||
|
public class OperatorPlaceholders implements PlaceholderRegistry {
|
||||||
|
|
||||||
public static void register(DBSystem dbSystem, ServerInfo serverInfo) {
|
private final DBSystem dbSystem;
|
||||||
PlanPlaceholders.registerStatic("operators_total",
|
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()))
|
() -> 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;
|
package com.djrapitops.plan.placeholder;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanSystem;
|
|
||||||
import com.djrapitops.plan.delivery.domain.container.PlayerContainer;
|
import com.djrapitops.plan.delivery.domain.container.PlayerContainer;
|
||||||
import com.djrapitops.plan.delivery.domain.keys.PlayerKeys;
|
import com.djrapitops.plan.delivery.domain.keys.PlayerKeys;
|
||||||
import com.djrapitops.plan.delivery.formatting.Formatters;
|
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.DBSystem;
|
||||||
import com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries;
|
import com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -33,58 +34,64 @@ import java.util.function.BiFunction;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
public final class PlanPlaceholders {
|
public final class PlanPlaceholders {
|
||||||
|
|
||||||
private static final Map<String, BiFunction<PlayerContainer, List<String>, Serializable>> placeholders = new HashMap<>();
|
private final Map<String, PlayerPlaceholderLoader> playerPlaceholders;
|
||||||
private static final Map<String, Function<List<String>, Serializable>> staticPlaceholders = new HashMap<>();
|
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) {
|
@Inject
|
||||||
dbSystem = system.getDatabaseSystem();
|
public PlanPlaceholders(
|
||||||
|
PlanConfig config,
|
||||||
|
DBSystem dbSystem,
|
||||||
|
ServerInfo serverInfo,
|
||||||
|
Formatters formatters,
|
||||||
|
Set<PlaceholderRegistry> placeholderRegistries
|
||||||
|
) {
|
||||||
|
this.dbSystem = dbSystem;
|
||||||
|
|
||||||
PlanConfig config = system.getConfigSystem().getConfig();
|
this.playerPlaceholders = new HashMap<>();
|
||||||
ServerInfo serverInfo = system.getServerInfo();
|
this.staticPlaceholders = new HashMap<>();
|
||||||
Formatters formatters = system.getDeliveryUtilities().getFormatters();
|
this.rawHandlers = new HashMap<>();
|
||||||
|
|
||||||
ServerPlaceHolders.register(dbSystem, serverInfo, formatters);
|
for (PlaceholderRegistry registry : placeholderRegistries) {
|
||||||
OperatorPlaceholders.register(dbSystem, serverInfo);
|
registry.register(this);
|
||||||
WorldTimePlaceHolder.register(dbSystem, serverInfo, formatters);
|
}
|
||||||
SessionPlaceHolder.register(config, dbSystem, serverInfo, formatters);
|
|
||||||
PlayerPlaceHolder.register(dbSystem, serverInfo, formatters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerStatic(String name, Supplier<Serializable> loader) {
|
public void registerStatic(String name, Supplier<Serializable> loader) {
|
||||||
registerStatic(name, params -> loader.get());
|
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);
|
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));
|
register(name, (player, params) -> loader.apply(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register(String name, BiFunction<PlayerContainer, List<String>, Serializable> loader) {
|
public void register(String name, PlayerPlaceholderLoader loader) {
|
||||||
placeholders.put(name, 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);
|
rawHandlers.put(name, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, BiFunction<PlayerContainer, List<String>, Serializable>> getPlaceholders() {
|
public Map<String, PlayerPlaceholderLoader> getPlaceholders() {
|
||||||
return placeholders;
|
return playerPlaceholders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Function<List<String>, Serializable>> getStaticPlaceholders() {
|
public Map<String, StaticPlaceholderLoader> getStaticPlaceholders() {
|
||||||
return staticPlaceholders;
|
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;
|
PlayerContainer player;
|
||||||
|
|
||||||
if (uuid != null) {
|
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
|
* @return the value of the placeholder if found, or empty {@link String} if no
|
||||||
* value found but the placeholder is registered,
|
* value found but the placeholder is registered,
|
||||||
* otherwise {@code null}
|
* 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()) {
|
for (Entry<String, BiFunction<String, PlayerContainer, Serializable>> entry : rawHandlers.entrySet()) {
|
||||||
if (placeholder.startsWith(entry.getKey())) {
|
if (placeholder.startsWith(entry.getKey())) {
|
||||||
return Objects.toString(entry.getValue().apply(placeholder, player));
|
return Objects.toString(entry.getValue().apply(placeholder, player));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Function<List<String>, Serializable> staticLoader = staticPlaceholders.get(placeholder);
|
StaticPlaceholderLoader staticLoader = staticPlaceholders.get(placeholder);
|
||||||
|
|
||||||
if (staticLoader != null) {
|
if (staticLoader != null) {
|
||||||
return Objects.toString(staticLoader.apply(parameters));
|
return Objects.toString(staticLoader.apply(parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
BiFunction<PlayerContainer, List<String>, Serializable> loader = placeholders.get(placeholder);
|
PlayerPlaceholderLoader loader = playerPlaceholders.get(placeholder);
|
||||||
|
|
||||||
if (loader != null) {
|
if (loader != null) {
|
||||||
return Objects.toString(loader.apply(player, parameters));
|
return Objects.toString(loader.apply(player, parameters));
|
||||||
@ -131,4 +137,8 @@ public final class PlanPlaceholders {
|
|||||||
|
|
||||||
return null;
|
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.storage.database.queries.objects.ServerQueries;
|
||||||
import com.djrapitops.plan.utilities.Predicates;
|
import com.djrapitops.plan.utilities.Predicates;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import static com.djrapitops.plan.utilities.MiscUtils.*;
|
import static com.djrapitops.plan.utilities.MiscUtils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,156 +39,171 @@ import static com.djrapitops.plan.utilities.MiscUtils.*;
|
|||||||
*
|
*
|
||||||
* @author aidn5, Rsl1122
|
* @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,
|
DBSystem dbSystem,
|
||||||
ServerInfo serverInfo,
|
ServerInfo serverInfo,
|
||||||
Formatters formatters
|
Formatters formatters
|
||||||
|
) {
|
||||||
|
this.dbSystem = dbSystem;
|
||||||
|
this.serverInfo = serverInfo;
|
||||||
|
this.formatters = formatters;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(
|
||||||
|
PlanPlaceholders placeholders
|
||||||
) {
|
) {
|
||||||
Formatter<Double> decimals = formatters.decimals();
|
Formatter<Double> decimals = formatters.decimals();
|
||||||
Formatter<Long> year = formatters.yearLong();
|
Formatter<Long> year = formatters.yearLong();
|
||||||
Formatter<Long> time = formatters.timeAmount();
|
Formatter<Long> time = formatters.timeAmount();
|
||||||
|
|
||||||
PlanPlaceholders.register("player_banned",
|
placeholders.register("player_banned",
|
||||||
player -> player.getValue(PlayerKeys.BANNED)
|
player -> player.getValue(PlayerKeys.BANNED)
|
||||||
.orElse(Boolean.FALSE)
|
.orElse(Boolean.FALSE)
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_operator",
|
placeholders.register("player_operator",
|
||||||
player -> player.getValue(PlayerKeys.OPERATOR)
|
player -> player.getValue(PlayerKeys.OPERATOR)
|
||||||
.orElse(Boolean.FALSE)
|
.orElse(Boolean.FALSE)
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_sessions_count",
|
placeholders.register("player_sessions_count",
|
||||||
player -> SessionsMutator.forContainer(player)
|
player -> SessionsMutator.forContainer(player)
|
||||||
.count()
|
.count()
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_kick_count",
|
placeholders.register("player_kick_count",
|
||||||
player -> player.getValue(PlayerKeys.KICK_COUNT)
|
player -> player.getValue(PlayerKeys.KICK_COUNT)
|
||||||
.orElse(0)
|
.orElse(0)
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_death_count",
|
placeholders.register("player_death_count",
|
||||||
player -> player.getValue(PlayerKeys.DEATH_COUNT)
|
player -> player.getValue(PlayerKeys.DEATH_COUNT)
|
||||||
.orElse(0)
|
.orElse(0)
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_mob_kill_count",
|
placeholders.register("player_mob_kill_count",
|
||||||
player -> player.getValue(PlayerKeys.MOB_KILL_COUNT)
|
player -> player.getValue(PlayerKeys.MOB_KILL_COUNT)
|
||||||
.orElse(0)
|
.orElse(0)
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_player_kill_count",
|
placeholders.register("player_player_kill_count",
|
||||||
player -> player.getValue(PlayerKeys.PLAYER_KILL_COUNT)
|
player -> player.getValue(PlayerKeys.PLAYER_KILL_COUNT)
|
||||||
.orElse(0)
|
.orElse(0)
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_kill_death_ratio",
|
placeholders.register("player_kill_death_ratio",
|
||||||
player -> PlayerVersusMutator.forContainer(player).toKillDeathRatio());
|
player -> PlayerVersusMutator.forContainer(player).toKillDeathRatio());
|
||||||
|
|
||||||
PlanPlaceholders.register("player_ping_average_day",
|
placeholders.register("player_ping_average_day",
|
||||||
player -> decimals.apply(PingMutator.forContainer(player)
|
player -> decimals.apply(PingMutator.forContainer(player)
|
||||||
.filterBy(Predicates.within(dayAgo(), now()))
|
.filterBy(Predicates.within(dayAgo(), now()))
|
||||||
.average()) + " ms"
|
.average()) + " ms"
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_ping_average_week",
|
placeholders.register("player_ping_average_week",
|
||||||
player -> decimals.apply(PingMutator.forContainer(player)
|
player -> decimals.apply(PingMutator.forContainer(player)
|
||||||
.filterBy(Predicates.within(weekAgo(), now()))
|
.filterBy(Predicates.within(weekAgo(), now()))
|
||||||
.average()) + " ms"
|
.average()) + " ms"
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_ping_average_month",
|
placeholders.register("player_ping_average_month",
|
||||||
player -> decimals.apply(PingMutator.forContainer(player)
|
player -> decimals.apply(PingMutator.forContainer(player)
|
||||||
.filterBy(Predicates.within(monthAgo(), now()))
|
.filterBy(Predicates.within(monthAgo(), now()))
|
||||||
.average()) + " ms"
|
.average()) + " ms"
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_lastseen",
|
placeholders.register("player_lastseen",
|
||||||
player -> year.apply(player.getValue(PlayerKeys.LAST_SEEN)
|
player -> year.apply(player.getValue(PlayerKeys.LAST_SEEN)
|
||||||
.orElse((long) 0))
|
.orElse((long) 0))
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_registered",
|
placeholders.register("player_registered",
|
||||||
player -> year.apply(player.getValue(PlayerKeys.REGISTERED)
|
player -> year.apply(player.getValue(PlayerKeys.REGISTERED)
|
||||||
.orElse((long) 0))
|
.orElse((long) 0))
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_time_active",
|
placeholders.register("player_time_active",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.toActivePlaytime())
|
.toActivePlaytime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_time_afk",
|
placeholders.register("player_time_afk",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.toAfkTime())
|
.toAfkTime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_time_total",
|
placeholders.register("player_time_total",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.toPlaytime())
|
.toPlaytime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_time_day",
|
placeholders.register("player_time_day",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.filterSessionsBetween(dayAgo(), now())
|
.filterSessionsBetween(dayAgo(), now())
|
||||||
.toPlaytime())
|
.toPlaytime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_time_week",
|
placeholders.register("player_time_week",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.filterSessionsBetween(weekAgo(), now())
|
.filterSessionsBetween(weekAgo(), now())
|
||||||
.toPlaytime())
|
.toPlaytime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_time_month",
|
placeholders.register("player_time_month",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.filterSessionsBetween(monthAgo(), now())
|
.filterSessionsBetween(monthAgo(), now())
|
||||||
.toPlaytime())
|
.toPlaytime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_server_time_active",
|
placeholders.register("player_server_time_active",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||||
.toActivePlaytime())
|
.toActivePlaytime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_server_time_afk",
|
placeholders.register("player_server_time_afk",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||||
.toAfkTime())
|
.toAfkTime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_server_time_total",
|
placeholders.register("player_server_time_total",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||||
.toPlaytime())
|
.toPlaytime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_server_time_day",
|
placeholders.register("player_server_time_day",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.filterSessionsBetween(dayAgo(), now())
|
.filterSessionsBetween(dayAgo(), now())
|
||||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||||
.toPlaytime())
|
.toPlaytime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_server_time_week",
|
placeholders.register("player_server_time_week",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.filterSessionsBetween(weekAgo(), now())
|
.filterSessionsBetween(weekAgo(), now())
|
||||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||||
.toPlaytime())
|
.toPlaytime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_server_time_month",
|
placeholders.register("player_server_time_month",
|
||||||
player -> time.apply(SessionsMutator.forContainer(player)
|
player -> time.apply(SessionsMutator.forContainer(player)
|
||||||
.filterSessionsBetween(monthAgo(), now())
|
.filterSessionsBetween(monthAgo(), now())
|
||||||
.filterPlayedOnServer(serverInfo.getServerUUID())
|
.filterPlayedOnServer(serverInfo.getServerUUID())
|
||||||
.toPlaytime())
|
.toPlaytime())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlanPlaceholders.register("player_favorite_server",
|
placeholders.register("player_favorite_server",
|
||||||
player -> PerServerMutator.forContainer(player).favoriteServer()
|
player -> PerServerMutator.forContainer(player).favoriteServer()
|
||||||
.flatMap(serverUUID -> dbSystem.getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverUUID)))
|
.flatMap(serverUUID -> dbSystem.getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverUUID)))
|
||||||
.map(Server::getName)
|
.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.Database;
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
|
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static com.djrapitops.plan.utilities.MiscUtils.*;
|
import static com.djrapitops.plan.utilities.MiscUtils.*;
|
||||||
@ -32,12 +34,27 @@ import static com.djrapitops.plan.utilities.MiscUtils.*;
|
|||||||
*
|
*
|
||||||
* @author aidn5, Rsl1122
|
* @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,
|
DBSystem dbSystem,
|
||||||
ServerInfo serverInfo,
|
ServerInfo serverInfo,
|
||||||
Formatters formatters
|
Formatters formatters
|
||||||
|
) {
|
||||||
|
this.dbSystem = dbSystem;
|
||||||
|
this.serverInfo = serverInfo;
|
||||||
|
this.formatters = formatters;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(
|
||||||
|
PlanPlaceholders placeholders
|
||||||
) {
|
) {
|
||||||
Formatter<Double> decimals = formatters.decimals();
|
Formatter<Double> decimals = formatters.decimals();
|
||||||
Formatter<Double> percentage = formatters.percentage();
|
Formatter<Double> percentage = formatters.percentage();
|
||||||
@ -45,82 +62,82 @@ public class ServerPlaceHolders {
|
|||||||
Database database = dbSystem.getDatabase();
|
Database database = dbSystem.getDatabase();
|
||||||
UUID serverUUID = serverInfo.getServerUUID();
|
UUID serverUUID = serverInfo.getServerUUID();
|
||||||
|
|
||||||
PlanPlaceholders.registerStatic("server_tps_day",
|
placeholders.registerStatic("server_tps_day",
|
||||||
() -> decimals.apply(database.query(TPSQueries.averageTPS(dayAgo(), now(), serverUUID))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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");
|
() -> 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");
|
() -> 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");
|
() -> 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)));
|
() -> database.query(TPSQueries.averageChunks(dayAgo(), now(), serverUUID)));
|
||||||
|
|
||||||
PlanPlaceholders.registerStatic("server_chunks_week",
|
placeholders.registerStatic("server_chunks_week",
|
||||||
() -> database.query(TPSQueries.averageChunks(weekAgo(), now(), serverUUID)));
|
() -> database.query(TPSQueries.averageChunks(weekAgo(), now(), serverUUID)));
|
||||||
|
|
||||||
PlanPlaceholders.registerStatic("server_chunks_month",
|
placeholders.registerStatic("server_chunks_month",
|
||||||
() -> database.query(TPSQueries.averageChunks(monthAgo(), now(), serverUUID)));
|
() -> database.query(TPSQueries.averageChunks(monthAgo(), now(), serverUUID)));
|
||||||
|
|
||||||
PlanPlaceholders.registerStatic("server_entities_day",
|
placeholders.registerStatic("server_entities_day",
|
||||||
() -> database.query(TPSQueries.averageEntities(dayAgo(), now(), serverUUID)));
|
() -> database.query(TPSQueries.averageEntities(dayAgo(), now(), serverUUID)));
|
||||||
|
|
||||||
PlanPlaceholders.registerStatic("server_entities_week",
|
placeholders.registerStatic("server_entities_week",
|
||||||
() -> database.query(TPSQueries.averageEntities(weekAgo(), now(), serverUUID)));
|
() -> database.query(TPSQueries.averageEntities(weekAgo(), now(), serverUUID)));
|
||||||
|
|
||||||
PlanPlaceholders.registerStatic("server_entities_month",
|
placeholders.registerStatic("server_entities_month",
|
||||||
() -> database.query(TPSQueries.averageEntities(monthAgo(), now(), serverUUID)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> database.query(TPSQueries.averageFreeDisk(monthAgo(), now(), serverUUID)));
|
||||||
|
|
||||||
PlanPlaceholders.registerStatic("server_name",
|
placeholders.registerStatic("server_name",
|
||||||
() -> serverInfo.getServer().getName());
|
() -> serverInfo.getServer().getName());
|
||||||
|
|
||||||
PlanPlaceholders.registerStatic("server_uuid",
|
placeholders.registerStatic("server_uuid",
|
||||||
serverInfo::getServerUUID);
|
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.SessionQueries;
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
|
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@ -41,13 +43,30 @@ import static com.djrapitops.plan.utilities.MiscUtils.*;
|
|||||||
*
|
*
|
||||||
* @author aidn5, Rsl1122
|
* @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,
|
PlanConfig config,
|
||||||
DBSystem dbSystem,
|
DBSystem dbSystem,
|
||||||
ServerInfo serverInfo,
|
ServerInfo serverInfo,
|
||||||
Formatters formatters
|
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());
|
int tzOffsetMs = config.getTimeZone().getOffset(System.currentTimeMillis());
|
||||||
Formatter<Long> timeAmount = formatters.timeAmount();
|
Formatter<Long> timeAmount = formatters.timeAmount();
|
||||||
@ -56,146 +75,146 @@ public class SessionPlaceHolder {
|
|||||||
Database database = dbSystem.getDatabase();
|
Database database = dbSystem.getDatabase();
|
||||||
UUID serverUUID = serverInfo.getServerUUID();
|
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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> 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))));
|
() -> timeAmount.apply(database.query(SessionQueries.afkTime(monthAgo(), now(), serverUUID))));
|
||||||
|
|
||||||
Supplier<Serializable> uniquePlayers = () -> database.query(PlayerCountQueries.newPlayerCount(0L, now(), serverUUID));
|
Supplier<Serializable> uniquePlayers = () -> database.query(PlayerCountQueries.newPlayerCount(0L, now(), serverUUID));
|
||||||
PlanPlaceholders.registerStatic("sessions_unique_players_total", uniquePlayers);
|
placeholders.registerStatic("sessions_unique_players_total", uniquePlayers);
|
||||||
PlanPlaceholders.registerStatic("sessions_new_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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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));
|
() -> 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));
|
() -> 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));
|
() -> 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));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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)));
|
() -> 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");
|
() -> 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");
|
() -> 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");
|
() -> 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");
|
() -> 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));
|
() -> 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("-"));
|
() -> 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));
|
() -> 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("-"));
|
() -> 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.DBSystem;
|
||||||
import com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries;
|
import com.djrapitops.plan.storage.database.queries.objects.WorldTimesQueries;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholders about a world times.
|
* Placeholders about a world times.
|
||||||
*
|
*
|
||||||
* @author aidn5, Rsl1122
|
* @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,
|
DBSystem dbSystem,
|
||||||
ServerInfo serverInfo,
|
ServerInfo serverInfo,
|
||||||
Formatters formatters
|
Formatters formatters
|
||||||
|
) {
|
||||||
|
this.dbSystem = dbSystem;
|
||||||
|
this.serverInfo = serverInfo;
|
||||||
|
this.formatters = formatters;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(
|
||||||
|
PlanPlaceholders placeholders
|
||||||
) {
|
) {
|
||||||
Formatter<Long> timeAmount = formatters.timeAmount();
|
Formatter<Long> timeAmount = formatters.timeAmount();
|
||||||
|
|
||||||
PlanPlaceholders.registerRaw("worlds_playtime_total_", (input, p) -> {
|
placeholders.registerRaw("worlds_playtime_total_", (input, p) -> {
|
||||||
// get world total play time
|
// get world total play time
|
||||||
// e.g. "plan_worlds_playtime_total_%worldname%"
|
// e.g. "plan_worlds_playtime_total_%worldname%"
|
||||||
// where %worldname% is "world_nether"
|
// where %worldname% is "world_nether"
|
||||||
@ -48,7 +66,7 @@ public class WorldTimePlaceHolder {
|
|||||||
return timeAmount.apply(worldTimes.getWorldPlaytime(worldName));
|
return timeAmount.apply(worldTimes.getWorldPlaytime(worldName));
|
||||||
});
|
});
|
||||||
|
|
||||||
PlanPlaceholders.registerStatic("worlds_playtime_total", params -> {
|
placeholders.registerStatic("worlds_playtime_total", params -> {
|
||||||
if (params.isEmpty()) {
|
if (params.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
@ -20,6 +20,7 @@ import com.djrapitops.plan.PlanPlugin;
|
|||||||
import com.djrapitops.plan.PlanSystem;
|
import com.djrapitops.plan.PlanSystem;
|
||||||
import com.djrapitops.plan.commands.PlanCommand;
|
import com.djrapitops.plan.commands.PlanCommand;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
|
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import dagger.BindsInstance;
|
import dagger.BindsInstance;
|
||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
@ -36,6 +37,7 @@ import javax.inject.Singleton;
|
|||||||
PlanPluginModule.class,
|
PlanPluginModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
|
PlaceholderModule.class,
|
||||||
|
|
||||||
PluginServerPropertiesModule.class,
|
PluginServerPropertiesModule.class,
|
||||||
PluginSuperClassBindingModule.class
|
PluginSuperClassBindingModule.class
|
||||||
|
@ -49,5 +49,4 @@ public interface PlanPluginModule {
|
|||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
ServerInfo bindServerInfo(ServerServerInfo serverServerInfo);
|
ServerInfo bindServerInfo(ServerServerInfo serverServerInfo);
|
||||||
|
|
||||||
}
|
}
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan;
|
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.commands.PlanCommand;
|
||||||
import com.djrapitops.plan.exceptions.EnableException;
|
import com.djrapitops.plan.exceptions.EnableException;
|
||||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||||
@ -52,7 +52,7 @@ public class PlanNukkit extends NukkitPlugin implements PlanPlugin {
|
|||||||
locale = system.getLocaleSystem().getLocale();
|
locale = system.getLocaleSystem().getLocale();
|
||||||
system.enable();
|
system.enable();
|
||||||
|
|
||||||
registerPlaceholderAPI();
|
registerPlaceholderAPI(component.placeholders());
|
||||||
|
|
||||||
logger.debug("Verbose debug messages are enabled.");
|
logger.debug("Verbose debug messages are enabled.");
|
||||||
String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
|
String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
|
||||||
@ -119,13 +119,13 @@ public class PlanNukkit extends NukkitPlugin implements PlanPlugin {
|
|||||||
return system;
|
return system;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerPlaceholderAPI() {
|
private void registerPlaceholderAPI(NukkitPlaceholderRegistrar placeholders) {
|
||||||
if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
runnableFactory.create("Placeholders Registrar", new AbsRunnable() {
|
runnableFactory.create("Placeholders Registrar", new AbsRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
NKPlaceholderRegistrar.register(system, errorHandler);
|
placeholders.register();
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchMethodError failed) {
|
} catch (Exception | NoClassDefFoundError | NoSuchMethodError failed) {
|
||||||
logger.warn("Failed to register PlaceholderAPI placeholders: " + failed.toString());
|
logger.warn("Failed to register PlaceholderAPI placeholders: " + failed.toString());
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan;
|
package com.djrapitops.plan;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.addons.placeholderapi.NukkitPlaceholderRegistrar;
|
||||||
import com.djrapitops.plan.commands.PlanCommand;
|
import com.djrapitops.plan.commands.PlanCommand;
|
||||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
|
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import com.djrapitops.plan.modules.nukkit.NukkitPlanModule;
|
import com.djrapitops.plan.modules.nukkit.NukkitPlanModule;
|
||||||
import com.djrapitops.plan.modules.nukkit.NukkitServerPropertiesModule;
|
import com.djrapitops.plan.modules.nukkit.NukkitServerPropertiesModule;
|
||||||
@ -38,6 +40,7 @@ import javax.inject.Singleton;
|
|||||||
NukkitPlanModule.class,
|
NukkitPlanModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
|
PlaceholderModule.class,
|
||||||
|
|
||||||
NukkitServerPropertiesModule.class,
|
NukkitServerPropertiesModule.class,
|
||||||
NukkitSuperClassBindingModule.class
|
NukkitSuperClassBindingModule.class
|
||||||
@ -50,6 +53,8 @@ public interface PlanNukkitComponent {
|
|||||||
|
|
||||||
ServerShutdownSave serverShutdownSave();
|
ServerShutdownSave serverShutdownSave();
|
||||||
|
|
||||||
|
NukkitPlaceholderRegistrar placeholders();
|
||||||
|
|
||||||
@Component.Builder
|
@Component.Builder
|
||||||
interface 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.L;
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
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 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.system = system;
|
||||||
this.errorHandler = errorHandler;
|
this.errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register0() {
|
public void register() {
|
||||||
PlanPlaceholders.init(system);
|
|
||||||
|
|
||||||
PlaceholderAPI api = PlaceholderAPI.getInstance();
|
PlaceholderAPI api = PlaceholderAPI.getInstance();
|
||||||
PlanPlaceholders.getPlaceholders().forEach((name, loader) ->
|
placeholders.getPlaceholders().forEach((name, loader) ->
|
||||||
api.visitorSensitivePlaceholder(name, (player, params) -> {
|
api.visitorSensitivePlaceholder(name, (player, params) -> {
|
||||||
try {
|
try {
|
||||||
return loader.apply(getPlayer(player), new ArrayList<>(params.getAll().values()));
|
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 -> {
|
api.staticPlaceholder(name, params -> {
|
||||||
try {
|
try {
|
||||||
return loader.apply(new ArrayList<>(params.getAll().values()));
|
return loader.apply(new ArrayList<>(params.getAll().values()));
|
||||||
@ -70,13 +78,9 @@ public class NKPlaceholderRegistrar {
|
|||||||
private PlayerContainer getPlayer(Player player) {
|
private PlayerContainer getPlayer(Player player) {
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
PlayerContainer p = system.getDatabaseSystem().getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid));
|
PlayerContainer container = system.getDatabaseSystem().getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid));
|
||||||
SessionCache.getCachedSession(uuid).ifPresent(session -> p.putRawData(PlayerKeys.ACTIVE_SESSION, session));
|
SessionCache.getCachedSession(uuid).ifPresent(session -> container.putRawData(PlayerKeys.ACTIVE_SESSION, session));
|
||||||
|
|
||||||
return p;
|
return container;
|
||||||
}
|
|
||||||
|
|
||||||
public static void register(PlanSystem system, ErrorHandler errorHandler) {
|
|
||||||
new NKPlaceholderRegistrar(system, errorHandler).register0();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,6 +19,7 @@ package com.djrapitops.plan;
|
|||||||
import com.djrapitops.plan.commands.PlanCommand;
|
import com.djrapitops.plan.commands.PlanCommand;
|
||||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
|
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import com.djrapitops.plan.modules.sponge.SpongePlanModule;
|
import com.djrapitops.plan.modules.sponge.SpongePlanModule;
|
||||||
import com.djrapitops.plan.modules.sponge.SpongeServerPropertiesModule;
|
import com.djrapitops.plan.modules.sponge.SpongeServerPropertiesModule;
|
||||||
@ -38,6 +39,7 @@ import javax.inject.Singleton;
|
|||||||
SpongePlanModule.class,
|
SpongePlanModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
|
PlaceholderModule.class,
|
||||||
|
|
||||||
SpongeSuperClassBindingModule.class,
|
SpongeSuperClassBindingModule.class,
|
||||||
SpongeServerPropertiesModule.class
|
SpongeServerPropertiesModule.class
|
||||||
|
@ -18,6 +18,7 @@ package com.djrapitops.plan;
|
|||||||
|
|
||||||
import com.djrapitops.plan.commands.PlanProxyCommand;
|
import com.djrapitops.plan.commands.PlanProxyCommand;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
|
import com.djrapitops.plan.modules.PlaceholderModule;
|
||||||
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import com.djrapitops.plan.modules.velocity.VelocityCommandModule;
|
import com.djrapitops.plan.modules.velocity.VelocityCommandModule;
|
||||||
@ -40,6 +41,7 @@ import javax.inject.Singleton;
|
|||||||
VelocityCommandModule.class,
|
VelocityCommandModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
|
PlaceholderModule.class,
|
||||||
|
|
||||||
ProxySuperClassBindingModule.class,
|
ProxySuperClassBindingModule.class,
|
||||||
VelocitySuperClassBindingModule.class,
|
VelocitySuperClassBindingModule.class,
|
||||||
|
Loading…
Reference in New Issue
Block a user