mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 08:28:12 +01:00
More cleanup on placeholder classes
This commit is contained in:
parent
4371595ccf
commit
24af980d39
@ -17,8 +17,7 @@
|
|||||||
package com.djrapitops.plan.addons.placeholderapi;
|
package com.djrapitops.plan.addons.placeholderapi;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanSystem;
|
import com.djrapitops.plan.PlanSystem;
|
||||||
import com.djrapitops.plan.delivery.domain.keys.ServerKeys;
|
import com.djrapitops.plan.placeholder.PlanPlaceholders;
|
||||||
import com.djrapitops.plan.placeholder.*;
|
|
||||||
import com.djrapitops.plan.version.VersionChecker;
|
import com.djrapitops.plan.version.VersionChecker;
|
||||||
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;
|
||||||
@ -31,20 +30,7 @@ import javax.inject.Singleton;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholder expansion used to provide data from Plan.
|
* Placeholder expansion used to provide data from Plan on Bukkit.
|
||||||
*
|
|
||||||
* <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>
|
|
||||||
*
|
*
|
||||||
* @author aidn5
|
* @author aidn5
|
||||||
*/
|
*/
|
||||||
@ -98,9 +84,9 @@ public class BukkitPlaceholderRegistrar extends PlaceholderExpansion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String onPlaceholderRequest(Player p, String params) {
|
public String onPlaceholderRequest(Player player, String params) {
|
||||||
try {
|
try {
|
||||||
String value = placeholders.onPlaceholderRequest(p.getUniqueId(), params, Collections.emptyList());
|
String value = placeholders.onPlaceholderRequest(player.getUniqueId(), params, Collections.emptyList());
|
||||||
|
|
||||||
if ("true".equals(value)) { //hack
|
if ("true".equals(value)) { //hack
|
||||||
value = PlaceholderAPIPlugin.booleanTrue();
|
value = PlaceholderAPIPlugin.booleanTrue();
|
||||||
@ -111,8 +97,7 @@ public class BukkitPlaceholderRegistrar extends PlaceholderExpansion {
|
|||||||
return value;
|
return value;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorHandler.log(L.WARN, getClass(), e);
|
errorHandler.log(L.WARN, getClass(), e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,27 +5,32 @@ import dagger.Binds;
|
|||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.multibindings.IntoSet;
|
import dagger.multibindings.IntoSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module for the Placeholder API related objects.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
@Module
|
@Module
|
||||||
public interface PlaceholderModule {
|
public interface PlaceholderModule {
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@IntoSet
|
@IntoSet
|
||||||
PlaceholderRegistry bindOperatorPlaceholders(OperatorPlaceholders placeholders);
|
Placeholders bindOperatorPlaceholders(OperatorPlaceholders placeholders);
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@IntoSet
|
@IntoSet
|
||||||
PlaceholderRegistry bindPlayerPlaceHolders(PlayerPlaceHolders placeholders);
|
Placeholders bindPlayerPlaceHolders(PlayerPlaceHolders placeholders);
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@IntoSet
|
@IntoSet
|
||||||
PlaceholderRegistry bindServerPlaceHolders(ServerPlaceHolders placeholders);
|
Placeholders bindServerPlaceHolders(ServerPlaceHolders placeholders);
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@IntoSet
|
@IntoSet
|
||||||
PlaceholderRegistry bindSessionPlaceHolders(SessionPlaceHolders placeholders);
|
Placeholders bindSessionPlaceHolders(SessionPlaceHolders placeholders);
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@IntoSet
|
@IntoSet
|
||||||
PlaceholderRegistry bindWorldTimePlaceHolders(WorldTimePlaceHolders placeholders);
|
Placeholders bindWorldTimePlaceHolders(WorldTimePlaceHolders placeholders);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import javax.inject.Singleton;
|
|||||||
* @author aidn5, Rsl1122
|
* @author aidn5, Rsl1122
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class OperatorPlaceholders implements PlaceholderRegistry {
|
public class OperatorPlaceholders implements Placeholders {
|
||||||
|
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
private final ServerInfo serverInfo;
|
private final ServerInfo serverInfo;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.djrapitops.plan.placeholder;
|
package com.djrapitops.plan.placeholder;
|
||||||
|
|
||||||
public interface PlaceholderRegistry {
|
public interface Placeholders {
|
||||||
|
|
||||||
void register(PlanPlaceholders placeholders);
|
void register(PlanPlaceholders placeholders);
|
||||||
|
|
@ -34,6 +34,15 @@ 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
@Singleton
|
||||||
public final class PlanPlaceholders {
|
public final class PlanPlaceholders {
|
||||||
|
|
||||||
@ -50,7 +59,7 @@ public final class PlanPlaceholders {
|
|||||||
DBSystem dbSystem,
|
DBSystem dbSystem,
|
||||||
ServerInfo serverInfo,
|
ServerInfo serverInfo,
|
||||||
Formatters formatters,
|
Formatters formatters,
|
||||||
Set<PlaceholderRegistry> placeholderRegistries
|
Set<Placeholders> placeholderRegistries
|
||||||
) {
|
) {
|
||||||
this.dbSystem = dbSystem;
|
this.dbSystem = dbSystem;
|
||||||
|
|
||||||
@ -58,7 +67,7 @@ public final class PlanPlaceholders {
|
|||||||
this.staticPlaceholders = new HashMap<>();
|
this.staticPlaceholders = new HashMap<>();
|
||||||
this.rawHandlers = new HashMap<>();
|
this.rawHandlers = new HashMap<>();
|
||||||
|
|
||||||
for (PlaceholderRegistry registry : placeholderRegistries) {
|
for (Placeholders registry : placeholderRegistries) {
|
||||||
registry.register(this);
|
registry.register(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,17 +131,13 @@ public final class PlanPlaceholders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StaticPlaceholderLoader 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) {
|
PlayerPlaceholderLoader loader = playerPlaceholders.get(placeholder);
|
||||||
PlayerPlaceholderLoader loader = playerPlaceholders.get(placeholder);
|
if (loader != null && player != null) {
|
||||||
|
return Objects.toString(loader.apply(player, parameters));
|
||||||
if (loader != null) {
|
|
||||||
return Objects.toString(loader.apply(player, parameters));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -40,7 +40,7 @@ import static com.djrapitops.plan.utilities.MiscUtils.*;
|
|||||||
* @author aidn5, Rsl1122
|
* @author aidn5, Rsl1122
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class PlayerPlaceHolders implements PlaceholderRegistry {
|
public class PlayerPlaceHolders implements Placeholders {
|
||||||
|
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
private final ServerInfo serverInfo;
|
private final ServerInfo serverInfo;
|
||||||
|
@ -35,7 +35,7 @@ import static com.djrapitops.plan.utilities.MiscUtils.*;
|
|||||||
* @author aidn5, Rsl1122
|
* @author aidn5, Rsl1122
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ServerPlaceHolders implements PlaceholderRegistry {
|
public class ServerPlaceHolders implements Placeholders {
|
||||||
|
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
private final ServerInfo serverInfo;
|
private final ServerInfo serverInfo;
|
||||||
|
@ -39,12 +39,12 @@ import java.util.function.Supplier;
|
|||||||
import static com.djrapitops.plan.utilities.MiscUtils.*;
|
import static com.djrapitops.plan.utilities.MiscUtils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholders about a sessions.
|
* Placeholders about sessions.
|
||||||
*
|
*
|
||||||
* @author aidn5, Rsl1122
|
* @author aidn5, Rsl1122
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class SessionPlaceHolders implements PlaceholderRegistry {
|
public class SessionPlaceHolders implements Placeholders {
|
||||||
|
|
||||||
private final PlanConfig config;
|
private final PlanConfig config;
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
|
@ -32,7 +32,7 @@ import javax.inject.Singleton;
|
|||||||
* @author aidn5, Rsl1122
|
* @author aidn5, Rsl1122
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class WorldTimePlaceHolders implements PlaceholderRegistry {
|
public class WorldTimePlaceHolders implements Placeholders {
|
||||||
|
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
private final ServerInfo serverInfo;
|
private final ServerInfo serverInfo;
|
||||||
|
@ -32,6 +32,11 @@ import javax.inject.Singleton;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Placeholder expansion used to provide data from Plan on Nukkit.
|
||||||
|
*
|
||||||
|
* @author developStorm
|
||||||
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class NukkitPlaceholderRegistrar {
|
public class NukkitPlaceholderRegistrar {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user