Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b035fa8940 | ||
|
|
25c087592d | ||
|
|
083cb39771 | ||
|
|
eb3e0f5c09 | ||
|
|
08f43ddafd | ||
|
|
9d3efb5e83 | ||
|
|
8a5d1a604a | ||
|
|
ef67c6d6ae | ||
|
|
5b2654db15 | ||
|
|
eccd793317 | ||
|
|
1bc44755a0 | ||
|
|
ec606d9ebe | ||
|
|
c5556f15ab | ||
|
|
399cce21f5 | ||
|
|
b25feffdfa |
@@ -1,5 +1,7 @@
|
||||
package com.willfp.eco.core.command;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A notification exception is thrown when {@link org.bukkit.command.CommandSender}s don't
|
||||
* specify valid arguments in commands.
|
||||
@@ -18,7 +20,7 @@ public class NotificationException extends Exception {
|
||||
*
|
||||
* @param key The lang key of the notification.
|
||||
*/
|
||||
public NotificationException(String key) {
|
||||
public NotificationException(@NotNull final String key) {
|
||||
super(key);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -71,10 +71,6 @@ public final class Prices {
|
||||
ctx
|
||||
);
|
||||
|
||||
if (function.apply(context) <= 0) {
|
||||
return new PriceFree();
|
||||
}
|
||||
|
||||
// Default to economy
|
||||
if (priceName == null) {
|
||||
return new PriceEconomy(context, function);
|
||||
|
||||
@@ -31,7 +31,7 @@ dependencies {
|
||||
compileOnly('com.github.TownyAdvanced:Towny:0.97.2.6') {
|
||||
exclude group: 'com.zaxxer', module: 'HikariCP'
|
||||
}
|
||||
compileOnly 'com.github.angeschossen:LandsAPI:6.26.7'
|
||||
compileOnly 'com.github.angeschossen:LandsAPI:6.26.18'
|
||||
compileOnly 'com.github.angeschossen:PluginFrameworkAPI:1.0.0'
|
||||
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||
@@ -48,7 +48,7 @@ dependencies {
|
||||
compileOnly 'com.github.WhipDevelopment:CrashClaim:f9cd7d92eb'
|
||||
compileOnly 'com.wolfyscript.wolfyutilities:wolfyutilities:3.16.0.0'
|
||||
compileOnly 'com.github.decentsoftware-eu:decentholograms:2.1.2'
|
||||
compileOnly 'com.github.Gypopo:EconomyShopGUI-API:1.1.0'
|
||||
compileOnly 'com.github.Gypopo:EconomyShopGUI-API:1.4.6'
|
||||
compileOnly 'com.github.N0RSKA:ScytherAPI:55a'
|
||||
compileOnly 'com.ticxo.modelengine:api:R3.0.1'
|
||||
compileOnly 'me.TechsCode:UltraEconomyAPI:1.0.0'
|
||||
|
||||
@@ -316,6 +316,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
IntegrationLoader("zShop") { ShopManager.register(ShopZShop()) },
|
||||
IntegrationLoader("DeluxeSellwands") { ShopManager.register(ShopDeluxeSellwands()) },
|
||||
IntegrationLoader("EconomyShopGUI") { ShopManager.register(ShopEconomyShopGUI()) },
|
||||
IntegrationLoader("EconomyShopGUI-Premium") { ShopManager.register(ShopEconomyShopGUI()) },
|
||||
|
||||
// Hologram
|
||||
IntegrationLoader("HolographicDisplays") { HologramManager.register(HologramHolographicDisplays(this)) },
|
||||
|
||||
@@ -3,8 +3,11 @@ 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.Flags
|
||||
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 org.bukkit.Location
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.block.Block
|
||||
import org.bukkit.entity.Animals
|
||||
import org.bukkit.entity.LivingEntity
|
||||
@@ -18,7 +21,10 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
||||
block: Block
|
||||
): Boolean {
|
||||
val area = landsIntegration.getArea(block.location) ?: return true
|
||||
return area.hasFlag(player, Flags.BLOCK_BREAK, false)
|
||||
return area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"BLOCK_BREAK"), block.type, false)
|
||||
}
|
||||
|
||||
override fun canCreateExplosion(
|
||||
@@ -26,7 +32,13 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
||||
location: Location
|
||||
): Boolean {
|
||||
val area = landsIntegration.getArea(location) ?: return true
|
||||
return area.hasFlag(player, Flags.ATTACK_PLAYER, false) && area.hasFlag(player, Flags.ATTACK_ANIMAL, false)
|
||||
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)
|
||||
}
|
||||
|
||||
override fun canPlaceBlock(
|
||||
@@ -34,7 +46,10 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
||||
block: Block
|
||||
): Boolean {
|
||||
val area = landsIntegration.getArea(block.location) ?: return true
|
||||
return area.hasFlag(player, Flags.BLOCK_PLACE, false)
|
||||
return area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"BLOCK_PLACE"), Material.AIR, false)
|
||||
}
|
||||
|
||||
override fun canInjure(
|
||||
@@ -45,16 +60,28 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
||||
val area = landsIntegration.getArea(victim.location) ?: return true
|
||||
|
||||
return when(victim) {
|
||||
is Player -> area.hasFlag(player, Flags.ATTACK_PLAYER, false)
|
||||
is Monster -> area.hasFlag(player, Flags.ATTACK_MONSTER, false)
|
||||
is Animals -> area.hasFlag(player, Flags.ATTACK_MONSTER, false)
|
||||
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)
|
||||
else -> area.isTrusted(player.uniqueId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun canPickupItem(player: Player, location: Location): Boolean {
|
||||
val area = landsIntegration.getArea(location) ?: return true
|
||||
return area.hasFlag(player, Flags.ITEM_PICKUP, false)
|
||||
return area.hasRoleFlag(player, RoleFlag.of(landsIntegration,
|
||||
FlagTarget.PLAYER,
|
||||
RoleFlagCategory.ACTION,
|
||||
"ITEM_PICKUP"), Material.AIR, false)
|
||||
}
|
||||
|
||||
override fun getPluginName(): String {
|
||||
|
||||
@@ -4,8 +4,10 @@ import com.willfp.eco.core.integrations.shop.ShopIntegration
|
||||
import com.willfp.eco.core.integrations.shop.ShopSellEvent
|
||||
import com.willfp.eco.core.price.Price
|
||||
import com.willfp.eco.core.price.impl.PriceEconomy
|
||||
import com.willfp.eco.core.price.impl.PriceFree
|
||||
import me.gypopo.economyshopgui.api.EconomyShopGUIHook
|
||||
import me.gypopo.economyshopgui.api.events.PreTransactionEvent
|
||||
import me.gypopo.economyshopgui.util.Transaction
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.EventHandler
|
||||
@@ -18,27 +20,63 @@ class ShopEconomyShopGUI : ShopIntegration {
|
||||
}
|
||||
|
||||
override fun getUnitValue(itemStack: ItemStack, player: Player): Price {
|
||||
val shopItem = EconomyShopGUIHook.getShopItem(itemStack) ?: return PriceFree()
|
||||
|
||||
return PriceEconomy(
|
||||
EconomyShopGUIHook.getItemSellPrice(player, itemStack.clone().apply {
|
||||
EconomyShopGUIHook.getItemSellPrice(shopItem, itemStack.clone().apply {
|
||||
amount = 1
|
||||
})
|
||||
}, player)
|
||||
)
|
||||
}
|
||||
|
||||
override fun isSellable(itemStack: ItemStack, player: Player): Boolean {
|
||||
return EconomyShopGUIHook.getItemSellPrice(player, itemStack) > 0
|
||||
val shopItem = EconomyShopGUIHook.getShopItem(itemStack) ?: return false
|
||||
return EconomyShopGUIHook.getItemSellPrice(shopItem, itemStack, player) > 0
|
||||
}
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
private val sellAllTypes = listOf(
|
||||
Transaction.Type.SELL_GUI_SCREEN,
|
||||
Transaction.Type.SELL_ALL_COMMAND,
|
||||
)
|
||||
|
||||
@EventHandler
|
||||
fun shopEventToEcoEvent(event: PreTransactionEvent) {
|
||||
if (event.transactionType !in sellTypes) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
val ecoEvent = ShopSellEvent(event.player, PriceEconomy(event.price), event.itemStack)
|
||||
Bukkit.getPluginManager().callEvent(ecoEvent)
|
||||
event.price = ecoEvent.value.getValue(event.player) * ecoEvent.multiplier
|
||||
val prices = if (event.transactionType in sellAllTypes) {
|
||||
event.items!!
|
||||
} else {
|
||||
mapOf(event.shopItem to event.amount)
|
||||
}
|
||||
|
||||
var total = 0.0
|
||||
|
||||
for ((shopItem, amount) in prices) {
|
||||
val price = EconomyShopGUIHook.getItemSellPrice(shopItem, shopItem.itemToGive
|
||||
.apply { this.amount = amount }, event.player)
|
||||
val ecoEvent = ShopSellEvent(event.player, PriceEconomy(price), shopItem.itemToGive
|
||||
.apply { this.amount = amount })
|
||||
Bukkit.getPluginManager().callEvent(ecoEvent)
|
||||
total += ecoEvent.value.getValue(event.player) * ecoEvent.multiplier
|
||||
}
|
||||
|
||||
event.price = total
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version = 6.49.1
|
||||
version = 6.50.0
|
||||
plugin-name = eco
|
||||
kotlin.code.style = official
|
||||
Reference in New Issue
Block a user