Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef922f6d3f | ||
|
|
026bc55ffb | ||
|
|
270fdbb18c | ||
|
|
fbf5967d17 | ||
|
|
4102be1201 | ||
|
|
f6bdb9cc65 | ||
|
|
c8282d1acf | ||
|
|
b056b537ef | ||
|
|
f69b458731 | ||
|
|
b035fa8940 | ||
|
|
25c087592d | ||
|
|
083cb39771 | ||
|
|
eb3e0f5c09 | ||
|
|
08f43ddafd |
@@ -1,13 +1,16 @@
|
||||
package com.willfp.eco.core.integrations.placeholder;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.willfp.eco.core.Eco;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.placeholder.AdditionalPlayer;
|
||||
import com.willfp.eco.core.placeholder.DynamicPlaceholder;
|
||||
import com.willfp.eco.core.placeholder.InjectablePlaceholder;
|
||||
import com.willfp.eco.core.placeholder.Placeholder;
|
||||
import com.willfp.eco.core.placeholder.PlaceholderInjectable;
|
||||
import com.willfp.eco.core.placeholder.PlayerDynamicPlaceholder;
|
||||
import com.willfp.eco.core.placeholder.PlayerPlaceholder;
|
||||
import com.willfp.eco.core.placeholder.PlayerStaticPlaceholder;
|
||||
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder;
|
||||
@@ -24,6 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -37,13 +41,20 @@ public final class PlaceholderManager {
|
||||
/**
|
||||
* All registered placeholders.
|
||||
*/
|
||||
private static final Map<EcoPlugin, Map<String, Placeholder>> REGISTERED_PLACEHOLDERS = new HashMap<>();
|
||||
private static final Map<EcoPlugin, Map<Pattern, Placeholder>> REGISTERED_PLACEHOLDERS = new HashMap<>();
|
||||
|
||||
/**
|
||||
* All registered placeholder integrations.
|
||||
*/
|
||||
private static final Set<PlaceholderIntegration> REGISTERED_INTEGRATIONS = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Placeholder Lookup Cache.
|
||||
*/
|
||||
private static final Cache<PlaceholderLookup, Optional<Placeholder>> PLACEHOLDER_LOOKUP_CACHE = Caffeine.newBuilder()
|
||||
.expireAfterWrite(1, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Placeholder Cache.
|
||||
*/
|
||||
@@ -51,10 +62,17 @@ public final class PlaceholderManager {
|
||||
.expireAfterWrite(50, TimeUnit.MILLISECONDS)
|
||||
.build(key -> key.entry.getValue(key.player));
|
||||
|
||||
/**
|
||||
* Dynamic Placeholder Cache.
|
||||
*/
|
||||
private static final LoadingCache<DynamicEntryWithPlayer, String> DYNAMIC_PLACEHOLDER_CACHE = Caffeine.newBuilder()
|
||||
.expireAfterWrite(50, TimeUnit.MILLISECONDS)
|
||||
.build(key -> key.entry.getValue(key.args, key.player));
|
||||
|
||||
/**
|
||||
* The default PlaceholderAPI pattern; brought in for compatibility.
|
||||
*/
|
||||
private static final Pattern PATTERN = Pattern.compile("[%]([^% ]+)[%]");
|
||||
private static final Pattern PATTERN = Pattern.compile("%([^% ]+)%");
|
||||
|
||||
/**
|
||||
* Empty injectable object.
|
||||
@@ -88,14 +106,17 @@ public final class PlaceholderManager {
|
||||
* @param placeholder The placeholder to register.
|
||||
*/
|
||||
public static void registerPlaceholder(@NotNull final Placeholder placeholder) {
|
||||
if (placeholder instanceof StaticPlaceholder) {
|
||||
if (placeholder instanceof StaticPlaceholder || placeholder instanceof PlayerStaticPlaceholder) {
|
||||
throw new IllegalArgumentException("Static placeholders cannot be registered!");
|
||||
}
|
||||
|
||||
EcoPlugin plugin = placeholder.getPlugin() == null ? Eco.get().getEcoPlugin() : placeholder.getPlugin();
|
||||
Map<String, Placeholder> pluginPlaceholders = REGISTERED_PLACEHOLDERS
|
||||
|
||||
Map<Pattern, Placeholder> pluginPlaceholders = REGISTERED_PLACEHOLDERS
|
||||
.getOrDefault(plugin, new HashMap<>());
|
||||
pluginPlaceholders.put(placeholder.getIdentifier(), placeholder);
|
||||
|
||||
pluginPlaceholders.put(placeholder.getPattern(), placeholder);
|
||||
|
||||
REGISTERED_PLACEHOLDERS.put(plugin, pluginPlaceholders);
|
||||
}
|
||||
|
||||
@@ -136,21 +157,47 @@ public final class PlaceholderManager {
|
||||
public static String getResult(@Nullable final Player player,
|
||||
@NotNull final String identifier,
|
||||
@Nullable final EcoPlugin plugin) {
|
||||
EcoPlugin owner = plugin == null ? Eco.get().getEcoPlugin() : plugin;
|
||||
Placeholder placeholder = REGISTERED_PLACEHOLDERS.getOrDefault(owner, new HashMap<>()).get(identifier.toLowerCase());
|
||||
// This is really janky, and it sucks, but it works so?
|
||||
// Compensating for regex being slow so that's why we get it.
|
||||
Placeholder placeholder = PLACEHOLDER_LOOKUP_CACHE.get(
|
||||
new PlaceholderLookup(identifier, plugin),
|
||||
(it) -> {
|
||||
EcoPlugin owner = plugin == null ? Eco.get().getEcoPlugin() : plugin;
|
||||
|
||||
if (placeholder == null && plugin != null) {
|
||||
Placeholder alternate = REGISTERED_PLACEHOLDERS.getOrDefault(Eco.get().getEcoPlugin(), new HashMap<>())
|
||||
.get(identifier.toLowerCase());
|
||||
if (alternate != null) {
|
||||
placeholder = alternate;
|
||||
}
|
||||
}
|
||||
// I hate the streams API.
|
||||
Optional<Placeholder> found = REGISTERED_PLACEHOLDERS
|
||||
.getOrDefault(owner, new HashMap<>())
|
||||
.entrySet()
|
||||
.stream().filter(entry -> entry.getKey().matcher(identifier).matches())
|
||||
.map(Map.Entry::getValue)
|
||||
.findFirst();
|
||||
|
||||
if (found.isEmpty() && plugin != null) {
|
||||
// Here we go again! Something about legacy support? I don't remember.
|
||||
// I won't touch it though, I'm scared of the placeholder system.
|
||||
found = REGISTERED_PLACEHOLDERS
|
||||
.getOrDefault(Eco.get().getEcoPlugin(), new HashMap<>())
|
||||
.entrySet()
|
||||
.stream().filter(entry -> entry.getKey().matcher(identifier).matches())
|
||||
.map(Map.Entry::getValue)
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
).orElse(null);
|
||||
|
||||
if (placeholder == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/*
|
||||
This code here is *really* not very good. It's mega externalized logic hacked
|
||||
together and made worse by the addition of dynamic placeholders. But it works,
|
||||
and it means I don't have to rewrite the whole placeholder system. So it's
|
||||
good enough for me.
|
||||
*/
|
||||
|
||||
if (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
||||
if (player == null) {
|
||||
return "";
|
||||
@@ -159,6 +206,14 @@ public final class PlaceholderManager {
|
||||
}
|
||||
} else if (placeholder instanceof PlayerlessPlaceholder playerlessPlaceholder) {
|
||||
return playerlessPlaceholder.getValue();
|
||||
} else if (placeholder instanceof PlayerDynamicPlaceholder playerDynamicPlaceholder) {
|
||||
if (player == null) {
|
||||
return "";
|
||||
} else {
|
||||
return DYNAMIC_PLACEHOLDER_CACHE.get(new DynamicEntryWithPlayer(playerDynamicPlaceholder, identifier, player));
|
||||
}
|
||||
} else if (placeholder instanceof DynamicPlaceholder dynamicPlaceholder) {
|
||||
return dynamicPlaceholder.getValue(identifier);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
@@ -245,8 +300,10 @@ public final class PlaceholderManager {
|
||||
for (PlaceholderIntegration integration : REGISTERED_INTEGRATIONS) {
|
||||
processed = integration.translate(processed, player);
|
||||
}
|
||||
|
||||
for (InjectablePlaceholder injection : context.getPlaceholderInjections()) {
|
||||
// Do I know this is a bad way of doing this? Yes.
|
||||
// I know it's deprecated, but it's fast.
|
||||
if (injection instanceof StaticPlaceholder placeholder) {
|
||||
processed = processed.replace("%" + placeholder.getIdentifier() + "%", placeholder.getValue());
|
||||
} else if (injection instanceof PlayerStaticPlaceholder placeholder && player != null) {
|
||||
@@ -280,11 +337,22 @@ public final class PlaceholderManager {
|
||||
return new ArrayList<>(found);
|
||||
}
|
||||
|
||||
private record PlaceholderLookup(@NotNull String identifier,
|
||||
@Nullable EcoPlugin plugin) {
|
||||
|
||||
}
|
||||
|
||||
private record EntryWithPlayer(@NotNull PlayerPlaceholder entry,
|
||||
@NotNull Player player) {
|
||||
|
||||
}
|
||||
|
||||
private record DynamicEntryWithPlayer(@NotNull PlayerDynamicPlaceholder entry,
|
||||
@NotNull String args,
|
||||
@NotNull Player player) {
|
||||
|
||||
}
|
||||
|
||||
private PlaceholderManager() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.willfp.eco.core.placeholder;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A placeholder that does not require a player and supports dynamic styles.
|
||||
*/
|
||||
public final class DynamicPlaceholder implements Placeholder {
|
||||
/**
|
||||
* The placeholder pattern.
|
||||
*/
|
||||
private final Pattern pattern;
|
||||
|
||||
/**
|
||||
* The function to retrieve the output of the placeholder.
|
||||
*/
|
||||
private final Function<String, String> function;
|
||||
|
||||
/**
|
||||
* The plugin for the placeholder.
|
||||
*/
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new dynamic placeholder.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param pattern The pattern.
|
||||
* @param function The function to retrieve the value.
|
||||
*/
|
||||
public DynamicPlaceholder(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final Pattern pattern,
|
||||
@NotNull final Function<String, String> function) {
|
||||
this.plugin = plugin;
|
||||
this.pattern = pattern;
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the placeholder.
|
||||
*
|
||||
* @param args The args.
|
||||
* @return The value.
|
||||
*/
|
||||
@NotNull
|
||||
public String getValue(@NotNull final String args) {
|
||||
return function.apply(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the placeholder.
|
||||
*
|
||||
* @return The placeholder.
|
||||
*/
|
||||
public DynamicPlaceholder register() {
|
||||
PlaceholderManager.registerPlaceholder(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull EcoPlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public @NotNull String getIdentifier() {
|
||||
return "dynamic";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Pattern getPattern() {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof DynamicPlaceholder that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(this.getPattern(), that.getPattern())
|
||||
&& Objects.equals(this.getPlugin(), that.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.getIdentifier(), this.getPlugin());
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,14 @@ package com.willfp.eco.core.placeholder;
|
||||
|
||||
import com.willfp.eco.core.Eco;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Placeholders that can be injected into {@link PlaceholderInjectable} objects.
|
||||
*/
|
||||
public sealed interface InjectablePlaceholder extends Placeholder permits PlayerStaticPlaceholder, StaticPlaceholder {
|
||||
@Override
|
||||
default EcoPlugin getPlugin() {
|
||||
default @NotNull EcoPlugin getPlugin() {
|
||||
return Eco.get().getEcoPlugin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
package com.willfp.eco.core.placeholder;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A placeholder represents a string that can hold a value.
|
||||
*/
|
||||
public sealed interface Placeholder permits PlayerPlaceholder, PlayerlessPlaceholder, InjectablePlaceholder {
|
||||
public sealed interface Placeholder permits PlayerPlaceholder, PlayerlessPlaceholder,
|
||||
DynamicPlaceholder, PlayerDynamicPlaceholder, InjectablePlaceholder {
|
||||
/**
|
||||
* Get the plugin that holds the placeholder.
|
||||
*
|
||||
* @return The plugin.
|
||||
*/
|
||||
@Nullable
|
||||
EcoPlugin getPlugin();
|
||||
|
||||
/**
|
||||
@@ -18,5 +24,16 @@ public sealed interface Placeholder permits PlayerPlaceholder, PlayerlessPlaceho
|
||||
*
|
||||
* @return The identifier.
|
||||
*/
|
||||
@NotNull
|
||||
String getIdentifier();
|
||||
|
||||
/**
|
||||
* Get the pattern for the placeholder.
|
||||
*
|
||||
* @return The pattern.
|
||||
*/
|
||||
@NotNull
|
||||
default Pattern getPattern() {
|
||||
return Pattern.compile(this.getIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.willfp.eco.core.placeholder;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A placeholder that does not require a player and supports dynamic styles.
|
||||
*/
|
||||
public final class PlayerDynamicPlaceholder implements Placeholder {
|
||||
/**
|
||||
* The placeholder pattern.
|
||||
*/
|
||||
private final Pattern pattern;
|
||||
|
||||
/**
|
||||
* The function to retrieve the output of the placeholder.
|
||||
*/
|
||||
private final BiFunction<String, Player, String> function;
|
||||
|
||||
/**
|
||||
* The plugin for the placeholder.
|
||||
*/
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new dynamic placeholder.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param pattern The pattern.
|
||||
* @param function The function to retrieve the value.
|
||||
*/
|
||||
public PlayerDynamicPlaceholder(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final Pattern pattern,
|
||||
@NotNull final BiFunction<String, Player, String> function) {
|
||||
this.plugin = plugin;
|
||||
this.pattern = pattern;
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the placeholder.
|
||||
*
|
||||
* @param args The args.
|
||||
* @param player The player.
|
||||
* @return The value.
|
||||
*/
|
||||
@NotNull
|
||||
public String getValue(@NotNull final String args,
|
||||
@NotNull final Player player) {
|
||||
return function.apply(args, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the placeholder.
|
||||
*
|
||||
* @return The placeholder.
|
||||
*/
|
||||
public PlayerDynamicPlaceholder register() {
|
||||
PlaceholderManager.registerPlaceholder(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull EcoPlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public @NotNull String getIdentifier() {
|
||||
return "dynamic";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Pattern getPattern() {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof PlayerDynamicPlaceholder that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(this.getPattern(), that.getPattern())
|
||||
&& Objects.equals(this.getPlugin(), that.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.getIdentifier(), this.getPlugin());
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A placeholder that requires a player.
|
||||
@@ -18,6 +19,11 @@ public final class PlayerPlaceholder implements Placeholder {
|
||||
*/
|
||||
private final String identifier;
|
||||
|
||||
/**
|
||||
* The placeholder pattern.
|
||||
*/
|
||||
private final Pattern pattern;
|
||||
|
||||
/**
|
||||
* The function to retrieve the output of the placeholder given a player.
|
||||
*/
|
||||
@@ -40,6 +46,7 @@ public final class PlayerPlaceholder implements Placeholder {
|
||||
@NotNull final Function<Player, String> function) {
|
||||
this.plugin = plugin;
|
||||
this.identifier = identifier;
|
||||
this.pattern = Pattern.compile(identifier);
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@@ -49,6 +56,7 @@ public final class PlayerPlaceholder implements Placeholder {
|
||||
* @param player The player.
|
||||
* @return The value.
|
||||
*/
|
||||
@NotNull
|
||||
public String getValue(@NotNull final Player player) {
|
||||
return function.apply(player);
|
||||
}
|
||||
@@ -64,15 +72,21 @@ public final class PlayerPlaceholder implements Placeholder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EcoPlugin getPlugin() {
|
||||
public @NotNull EcoPlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
public @NotNull String getIdentifier() {
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Pattern getPattern() {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable final Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A placeholder that cannot be registered, and exists purely in injection.
|
||||
@@ -16,6 +17,11 @@ public final class PlayerStaticPlaceholder implements InjectablePlaceholder {
|
||||
*/
|
||||
private final String identifier;
|
||||
|
||||
/**
|
||||
* The placeholder pattern.
|
||||
*/
|
||||
private final Pattern pattern;
|
||||
|
||||
/**
|
||||
* The function to retrieve the output of the placeholder.
|
||||
*/
|
||||
@@ -30,6 +36,7 @@ public final class PlayerStaticPlaceholder implements InjectablePlaceholder {
|
||||
public PlayerStaticPlaceholder(@NotNull final String identifier,
|
||||
@NotNull final Function<Player, String> function) {
|
||||
this.identifier = identifier;
|
||||
this.pattern = Pattern.compile(identifier);
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@@ -39,15 +46,22 @@ public final class PlayerStaticPlaceholder implements InjectablePlaceholder {
|
||||
* @param player The player.
|
||||
* @return The value.
|
||||
*/
|
||||
@NotNull
|
||||
public String getValue(@NotNull final Player player) {
|
||||
return function.apply(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
public @NotNull String getIdentifier() {
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Pattern getPattern() {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable final Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -7,16 +7,22 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A placeholder that does not require a player.
|
||||
*/
|
||||
public final class PlayerlessPlaceholder implements Placeholder {
|
||||
/**
|
||||
* The name of the placeholder.
|
||||
* The placeholder identifier.
|
||||
*/
|
||||
private final String identifier;
|
||||
|
||||
/**
|
||||
* The placeholder pattern.
|
||||
*/
|
||||
private final Pattern pattern;
|
||||
|
||||
/**
|
||||
* The function to retrieve the output of the placeholder.
|
||||
*/
|
||||
@@ -39,6 +45,7 @@ public final class PlayerlessPlaceholder implements Placeholder {
|
||||
@NotNull final Supplier<String> function) {
|
||||
this.plugin = plugin;
|
||||
this.identifier = identifier;
|
||||
this.pattern = Pattern.compile(identifier);
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@@ -62,15 +69,21 @@ public final class PlayerlessPlaceholder implements Placeholder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EcoPlugin getPlugin() {
|
||||
public @NotNull EcoPlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
public @NotNull String getIdentifier() {
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Pattern getPattern() {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable final Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A placeholder that cannot be registered, and exists purely in injection.
|
||||
@@ -15,6 +16,11 @@ public final class StaticPlaceholder implements InjectablePlaceholder {
|
||||
*/
|
||||
private final String identifier;
|
||||
|
||||
/**
|
||||
* The placeholder pattern.
|
||||
*/
|
||||
private final Pattern pattern;
|
||||
|
||||
/**
|
||||
* The function to retrieve the output of the placeholder.
|
||||
*/
|
||||
@@ -29,6 +35,7 @@ public final class StaticPlaceholder implements InjectablePlaceholder {
|
||||
public StaticPlaceholder(@NotNull final String identifier,
|
||||
@NotNull final Supplier<String> function) {
|
||||
this.identifier = identifier;
|
||||
this.pattern = Pattern.compile(identifier);
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@@ -37,15 +44,22 @@ public final class StaticPlaceholder implements InjectablePlaceholder {
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
@NotNull
|
||||
public String getValue() {
|
||||
return function.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
public @NotNull String getIdentifier() {
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Pattern getPattern() {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable final Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -9,7 +9,7 @@ class DelegatedBukkitCommand(
|
||||
private val delegate: EcoPluginCommand
|
||||
) : Command(delegate.name), TabCompleter, PluginIdentifiableCommand {
|
||||
override fun execute(sender: CommandSender, label: String, args: Array<out String>?): Boolean {
|
||||
return false
|
||||
return delegate.onCommand(sender, this, label, args)
|
||||
}
|
||||
|
||||
override fun onTabComplete(
|
||||
@@ -18,7 +18,7 @@ class DelegatedBukkitCommand(
|
||||
label: String,
|
||||
args: Array<out String>?
|
||||
): List<String> {
|
||||
return mutableListOf() // Mutable in case bukkit requires this (I haven't checked.)
|
||||
return delegate.onTabComplete(sender, this, label, args) ?: emptyList()
|
||||
}
|
||||
|
||||
override fun getPlugin() = delegate.plugin
|
||||
|
||||
@@ -33,6 +33,8 @@ class EcoPluginCommand(
|
||||
command.aliases = aliases
|
||||
}
|
||||
}
|
||||
|
||||
Eco.get().syncCommands()
|
||||
}
|
||||
|
||||
override fun unregister() {
|
||||
|
||||
@@ -50,8 +50,8 @@ abstract class HandledCommand(
|
||||
command: Command,
|
||||
label: String,
|
||||
args: Array<out String>?
|
||||
): MutableList<String>? {
|
||||
return handleTabComplete(sender, args?.toList() ?: listOf()).toMutableList()
|
||||
): List<String>? {
|
||||
return handleTabComplete(sender, args?.toList() ?: listOf())
|
||||
}
|
||||
|
||||
override fun getPlugin() = this.plugin
|
||||
|
||||
@@ -37,7 +37,7 @@ dependencies {
|
||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.202'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.10'
|
||||
compileOnly 'com.github.oraxen:oraxen:bd81ace154'
|
||||
compileOnly 'com.github.oraxen:oraxen:bea381fb82'
|
||||
compileOnly 'com.github.brcdev-minecraft:shopgui-api:3.0.0'
|
||||
compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.4.7'
|
||||
compileOnly 'com.arcaniax:HeadDatabase-API:1.3.0'
|
||||
|
||||
@@ -3,9 +3,7 @@ package com.willfp.eco.internal.spigot.integrations.antigrief
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefIntegration
|
||||
import me.angeschossen.lands.api.LandsIntegration
|
||||
import me.angeschossen.lands.api.flags.enums.FlagTarget
|
||||
import me.angeschossen.lands.api.flags.enums.RoleFlagCategory
|
||||
import me.angeschossen.lands.api.flags.type.RoleFlag
|
||||
import me.angeschossen.lands.api.flags.type.Flags
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.block.Block
|
||||
@@ -21,10 +19,7 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
||||
block: Block
|
||||
): Boolean {
|
||||
val area = landsIntegration.getArea(block.location) ?: return true
|
||||
return area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"BLOCK_BREAK"), block.type, false)
|
||||
return area.hasRoleFlag(player, Flags.BLOCK_BREAK, block.type, false)
|
||||
}
|
||||
|
||||
override fun canCreateExplosion(
|
||||
@@ -32,13 +27,8 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
||||
location: Location
|
||||
): Boolean {
|
||||
val area = landsIntegration.getArea(location) ?: return true
|
||||
return area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"ATTACK_PLAYER"), Material.AIR, false) && area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"ATTACK_ANIMAL"), Material.AIR, false)
|
||||
return area.hasRoleFlag(player, Flags.ATTACK_PLAYER, Material.AIR, false)
|
||||
&& area.hasRoleFlag(player, Flags.ATTACK_ANIMAL, Material.AIR, false)
|
||||
}
|
||||
|
||||
override fun canPlaceBlock(
|
||||
@@ -46,10 +36,7 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
||||
block: Block
|
||||
): Boolean {
|
||||
val area = landsIntegration.getArea(block.location) ?: return true
|
||||
return area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"BLOCK_PLACE"), Material.AIR, false)
|
||||
return area.hasRoleFlag(player, Flags.BLOCK_PLACE, Material.AIR, false)
|
||||
}
|
||||
|
||||
override fun canInjure(
|
||||
@@ -60,28 +47,16 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
||||
val area = landsIntegration.getArea(victim.location) ?: return true
|
||||
|
||||
return when(victim) {
|
||||
is Player -> area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"ATTACK_PLAYER"), Material.AIR, false)
|
||||
is Monster -> area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"ATTACK_MONSTER"), Material.AIR, false)
|
||||
is Animals -> area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"ATTACK_ANIMAL"), Material.AIR, false)
|
||||
is Player -> area.hasRoleFlag(player, Flags.ATTACK_PLAYER, Material.AIR, false)
|
||||
is Monster -> area.hasRoleFlag(player, Flags.ATTACK_MONSTER, Material.AIR, false)
|
||||
is Animals -> area.hasRoleFlag(player, Flags.ATTACK_ANIMAL, Material.AIR, false)
|
||||
else -> area.isTrusted(player.uniqueId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun canPickupItem(player: Player, location: Location): Boolean {
|
||||
val area = landsIntegration.getArea(location) ?: return true
|
||||
return area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"ITEM_PICKUP"), Material.AIR, false)
|
||||
return area.hasRoleFlag(player, Flags.ITEM_PICKUP, Material.AIR, false)
|
||||
}
|
||||
|
||||
override fun getPluginName(): String {
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.core.items.TestableItem
|
||||
import com.willfp.eco.core.items.provider.ItemProvider
|
||||
import com.willfp.eco.util.NamespacedKeyUtils
|
||||
import io.th0rgal.oraxen.items.OraxenItems
|
||||
import io.th0rgal.oraxen.api.OraxenItems
|
||||
|
||||
class CustomItemsOraxen : CustomItemsIntegration {
|
||||
override fun registerProvider() {
|
||||
|
||||
@@ -36,22 +36,22 @@ class ShopEconomyShopGUI : ShopIntegration {
|
||||
|
||||
object EconomyShopGUISellEventListeners : Listener {
|
||||
private val sellTypes = listOf(
|
||||
Transaction.Type.SELL_GUI_SCREEN,
|
||||
Transaction.Type.SELL_SCREEN,
|
||||
Transaction.Type.SELL_ALL_SCREEN,
|
||||
Transaction.Type.SELL_ALL_COMMAND,
|
||||
Transaction.Type.QUICK_SELL,
|
||||
Transaction.Type.AUTO_SELL_CHEST,
|
||||
"SELL_GUI_SCREEN",
|
||||
"SELL_SCREEN",
|
||||
"SELL_ALL_SCREEN",
|
||||
"SELL_ALL_COMMAND",
|
||||
"QUICK_SELL",
|
||||
"AUTO_SELL_CHEST",
|
||||
)
|
||||
|
||||
private val sellAllTypes = listOf(
|
||||
Transaction.Type.SELL_GUI_SCREEN,
|
||||
Transaction.Type.SELL_ALL_COMMAND,
|
||||
"SELL_GUI_SCREEN",
|
||||
"SELL_ALL_COMMAND",
|
||||
)
|
||||
|
||||
@EventHandler
|
||||
fun shopEventToEcoEvent(event: PreTransactionEvent) {
|
||||
if (event.transactionType !in sellTypes) {
|
||||
if (event.transactionType.name.uppercase() !in sellTypes) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class ShopEconomyShopGUI : ShopIntegration {
|
||||
return
|
||||
}
|
||||
|
||||
val prices = if (event.transactionType in sellAllTypes) {
|
||||
val prices = if (event.transactionType.name.uppercase() in sellAllTypes) {
|
||||
event.items!!
|
||||
} else {
|
||||
mapOf(event.shopItem to event.amount)
|
||||
|
||||
@@ -45,6 +45,7 @@ softdepend:
|
||||
- ExecutableItems
|
||||
- RPGHorses
|
||||
- EconomyShopGUI
|
||||
- EconomyShopGUI-Premium
|
||||
- zShop
|
||||
- DeluxeSellwands
|
||||
- Scyther
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version = 6.49.2
|
||||
version = 6.50.2
|
||||
plugin-name = eco
|
||||
kotlin.code.style = official
|
||||
Reference in New Issue
Block a user