More cleanup on placeholder classes

This commit is contained in:
Risto Lahtela 2020-05-01 10:49:04 +03:00
parent 4371595ccf
commit 24af980d39
10 changed files with 41 additions and 41 deletions

View File

@ -17,8 +17,7 @@
package com.djrapitops.plan.addons.placeholderapi;
import com.djrapitops.plan.PlanSystem;
import com.djrapitops.plan.delivery.domain.keys.ServerKeys;
import com.djrapitops.plan.placeholder.*;
import com.djrapitops.plan.placeholder.PlanPlaceholders;
import com.djrapitops.plan.version.VersionChecker;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
@ -31,20 +30,7 @@ import javax.inject.Singleton;
import java.util.Collections;
/**
* Placeholder expansion used to provide data from Plan.
*
* <p>
* <b>Current used services for placeholders:</b>
* <ul>
* <li>{@link ServerPlaceHolders}:
* {@link ServerKeys#TPS},{@link ServerKeys#NAME},
* {@link ServerKeys#SERVER_UUID}</li>
* <li>{@link OperatorPlaceholders}: {@link ServerKeys#OPERATORS}</li>
* <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>
* Placeholder expansion used to provide data from Plan on Bukkit.
*
* @author aidn5
*/
@ -98,9 +84,9 @@ public class BukkitPlaceholderRegistrar extends PlaceholderExpansion {
}
@Override
public String onPlaceholderRequest(Player p, String params) {
public String onPlaceholderRequest(Player player, String params) {
try {
String value = placeholders.onPlaceholderRequest(p.getUniqueId(), params, Collections.emptyList());
String value = placeholders.onPlaceholderRequest(player.getUniqueId(), params, Collections.emptyList());
if ("true".equals(value)) { //hack
value = PlaceholderAPIPlugin.booleanTrue();
@ -111,8 +97,7 @@ public class BukkitPlaceholderRegistrar extends PlaceholderExpansion {
return value;
} catch (Exception e) {
errorHandler.log(L.WARN, getClass(), e);
return null;
}
return null;
}
}

View File

@ -5,27 +5,32 @@ import dagger.Binds;
import dagger.Module;
import dagger.multibindings.IntoSet;
/**
* Module for the Placeholder API related objects.
*
* @author Rsl1122
*/
@Module
public interface PlaceholderModule {
@Binds
@IntoSet
PlaceholderRegistry bindOperatorPlaceholders(OperatorPlaceholders placeholders);
Placeholders bindOperatorPlaceholders(OperatorPlaceholders placeholders);
@Binds
@IntoSet
PlaceholderRegistry bindPlayerPlaceHolders(PlayerPlaceHolders placeholders);
Placeholders bindPlayerPlaceHolders(PlayerPlaceHolders placeholders);
@Binds
@IntoSet
PlaceholderRegistry bindServerPlaceHolders(ServerPlaceHolders placeholders);
Placeholders bindServerPlaceHolders(ServerPlaceHolders placeholders);
@Binds
@IntoSet
PlaceholderRegistry bindSessionPlaceHolders(SessionPlaceHolders placeholders);
Placeholders bindSessionPlaceHolders(SessionPlaceHolders placeholders);
@Binds
@IntoSet
PlaceholderRegistry bindWorldTimePlaceHolders(WorldTimePlaceHolders placeholders);
Placeholders bindWorldTimePlaceHolders(WorldTimePlaceHolders placeholders);
}

View File

@ -29,7 +29,7 @@ import javax.inject.Singleton;
* @author aidn5, Rsl1122
*/
@Singleton
public class OperatorPlaceholders implements PlaceholderRegistry {
public class OperatorPlaceholders implements Placeholders {
private final DBSystem dbSystem;
private final ServerInfo serverInfo;

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.placeholder;
public interface PlaceholderRegistry {
public interface Placeholders {
void register(PlanPlaceholders placeholders);

View File

@ -34,6 +34,15 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* Registry for all placeholders.
*
* @see ServerPlaceHolders Placeholders about the current server
* @see OperatorPlaceholders Placeholders about operators of the current server
* @see PlayerPlaceHolders Placeholders about the current player on the whole network
* @see SessionPlaceHolders Placeholders about the player on the current server
* @see WorldTimePlaceHolders Placeholders about the world times of current player on the current server
*/
@Singleton
public final class PlanPlaceholders {
@ -50,7 +59,7 @@ public final class PlanPlaceholders {
DBSystem dbSystem,
ServerInfo serverInfo,
Formatters formatters,
Set<PlaceholderRegistry> placeholderRegistries
Set<Placeholders> placeholderRegistries
) {
this.dbSystem = dbSystem;
@ -58,7 +67,7 @@ public final class PlanPlaceholders {
this.staticPlaceholders = new HashMap<>();
this.rawHandlers = new HashMap<>();
for (PlaceholderRegistry registry : placeholderRegistries) {
for (Placeholders registry : placeholderRegistries) {
registry.register(this);
}
}
@ -122,17 +131,13 @@ public final class PlanPlaceholders {
}
StaticPlaceholderLoader staticLoader = staticPlaceholders.get(placeholder);
if (staticLoader != null) {
return Objects.toString(staticLoader.apply(parameters));
}
if (player != null) {
PlayerPlaceholderLoader loader = playerPlaceholders.get(placeholder);
if (loader != null) {
return Objects.toString(loader.apply(player, parameters));
}
PlayerPlaceholderLoader loader = playerPlaceholders.get(placeholder);
if (loader != null && player != null) {
return Objects.toString(loader.apply(player, parameters));
}
return null;

View File

@ -40,7 +40,7 @@ import static com.djrapitops.plan.utilities.MiscUtils.*;
* @author aidn5, Rsl1122
*/
@Singleton
public class PlayerPlaceHolders implements PlaceholderRegistry {
public class PlayerPlaceHolders implements Placeholders {
private final DBSystem dbSystem;
private final ServerInfo serverInfo;

View File

@ -35,7 +35,7 @@ import static com.djrapitops.plan.utilities.MiscUtils.*;
* @author aidn5, Rsl1122
*/
@Singleton
public class ServerPlaceHolders implements PlaceholderRegistry {
public class ServerPlaceHolders implements Placeholders {
private final DBSystem dbSystem;
private final ServerInfo serverInfo;

View File

@ -39,12 +39,12 @@ import java.util.function.Supplier;
import static com.djrapitops.plan.utilities.MiscUtils.*;
/**
* Placeholders about a sessions.
* Placeholders about sessions.
*
* @author aidn5, Rsl1122
*/
@Singleton
public class SessionPlaceHolders implements PlaceholderRegistry {
public class SessionPlaceHolders implements Placeholders {
private final PlanConfig config;
private final DBSystem dbSystem;

View File

@ -32,7 +32,7 @@ import javax.inject.Singleton;
* @author aidn5, Rsl1122
*/
@Singleton
public class WorldTimePlaceHolders implements PlaceholderRegistry {
public class WorldTimePlaceHolders implements Placeholders {
private final DBSystem dbSystem;
private final ServerInfo serverInfo;

View File

@ -32,6 +32,11 @@ import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.UUID;
/**
* Placeholder expansion used to provide data from Plan on Nukkit.
*
* @author developStorm
*/
@Singleton
public class NukkitPlaceholderRegistrar {