Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49687f9a91 | ||
|
|
5480c70f8c | ||
|
|
ef922f6d3f | ||
|
|
026bc55ffb | ||
|
|
270fdbb18c | ||
|
|
fbf5967d17 | ||
|
|
4102be1201 | ||
|
|
f6bdb9cc65 | ||
|
|
c8282d1acf | ||
|
|
b056b537ef | ||
|
|
f69b458731 | ||
|
|
b035fa8940 | ||
|
|
25c087592d | ||
|
|
083cb39771 | ||
|
|
eb3e0f5c09 | ||
|
|
08f43ddafd | ||
|
|
9d3efb5e83 | ||
|
|
8a5d1a604a | ||
|
|
ef67c6d6ae | ||
|
|
5b2654db15 | ||
|
|
eccd793317 | ||
|
|
1bc44755a0 | ||
|
|
ec606d9ebe | ||
|
|
c5556f15ab | ||
|
|
399cce21f5 | ||
|
|
b25feffdfa |
@@ -32,7 +32,6 @@ import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
|||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.command.CommandMap;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Mob;
|
import org.bukkit.entity.Mob;
|
||||||
@@ -547,19 +546,12 @@ public interface Eco {
|
|||||||
*/
|
*/
|
||||||
void syncCommands();
|
void syncCommands();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the command map.
|
|
||||||
*
|
|
||||||
* @return The command map.
|
|
||||||
*/
|
|
||||||
@NotNull CommandMap getCommandMap();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister a command.
|
* Unregister a command.
|
||||||
*
|
*
|
||||||
* @param command The command.
|
* @param command The command.
|
||||||
*/
|
*/
|
||||||
void unregisterCommand(@NotNull final PluginCommand command);
|
void unregisterCommand(@NotNull final PluginCommandBase command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the instance of eco; the bridge between the api frontend and the implementation backend.
|
* Get the instance of eco; the bridge between the api frontend and the implementation backend.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.willfp.eco.core.command;
|
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
|
* A notification exception is thrown when {@link org.bukkit.command.CommandSender}s don't
|
||||||
* specify valid arguments in commands.
|
* specify valid arguments in commands.
|
||||||
@@ -18,7 +20,7 @@ public class NotificationException extends Exception {
|
|||||||
*
|
*
|
||||||
* @param key The lang key of the notification.
|
* @param key The lang key of the notification.
|
||||||
*/
|
*/
|
||||||
public NotificationException(String key) {
|
public NotificationException(@NotNull final String key) {
|
||||||
super(key);
|
super(key);
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
package com.willfp.eco.core.integrations.placeholder;
|
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.Caffeine;
|
||||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||||
import com.willfp.eco.core.Eco;
|
import com.willfp.eco.core.Eco;
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
import com.willfp.eco.core.placeholder.AdditionalPlayer;
|
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.InjectablePlaceholder;
|
||||||
import com.willfp.eco.core.placeholder.Placeholder;
|
import com.willfp.eco.core.placeholder.Placeholder;
|
||||||
import com.willfp.eco.core.placeholder.PlaceholderInjectable;
|
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.PlayerPlaceholder;
|
||||||
import com.willfp.eco.core.placeholder.PlayerStaticPlaceholder;
|
import com.willfp.eco.core.placeholder.PlayerStaticPlaceholder;
|
||||||
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder;
|
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder;
|
||||||
@@ -24,6 +27,7 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -37,13 +41,20 @@ public final class PlaceholderManager {
|
|||||||
/**
|
/**
|
||||||
* All registered placeholders.
|
* 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.
|
* All registered placeholder integrations.
|
||||||
*/
|
*/
|
||||||
private static final Set<PlaceholderIntegration> REGISTERED_INTEGRATIONS = new HashSet<>();
|
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.
|
* Placeholder Cache.
|
||||||
*/
|
*/
|
||||||
@@ -51,10 +62,17 @@ public final class PlaceholderManager {
|
|||||||
.expireAfterWrite(50, TimeUnit.MILLISECONDS)
|
.expireAfterWrite(50, TimeUnit.MILLISECONDS)
|
||||||
.build(key -> key.entry.getValue(key.player));
|
.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.
|
* 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.
|
* Empty injectable object.
|
||||||
@@ -88,14 +106,17 @@ public final class PlaceholderManager {
|
|||||||
* @param placeholder The placeholder to register.
|
* @param placeholder The placeholder to register.
|
||||||
*/
|
*/
|
||||||
public static void registerPlaceholder(@NotNull final Placeholder placeholder) {
|
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!");
|
throw new IllegalArgumentException("Static placeholders cannot be registered!");
|
||||||
}
|
}
|
||||||
|
|
||||||
EcoPlugin plugin = placeholder.getPlugin() == null ? Eco.get().getEcoPlugin() : placeholder.getPlugin();
|
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<>());
|
.getOrDefault(plugin, new HashMap<>());
|
||||||
pluginPlaceholders.put(placeholder.getIdentifier(), placeholder);
|
|
||||||
|
pluginPlaceholders.put(placeholder.getPattern(), placeholder);
|
||||||
|
|
||||||
REGISTERED_PLACEHOLDERS.put(plugin, pluginPlaceholders);
|
REGISTERED_PLACEHOLDERS.put(plugin, pluginPlaceholders);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,21 +157,47 @@ public final class PlaceholderManager {
|
|||||||
public static String getResult(@Nullable final Player player,
|
public static String getResult(@Nullable final Player player,
|
||||||
@NotNull final String identifier,
|
@NotNull final String identifier,
|
||||||
@Nullable final EcoPlugin plugin) {
|
@Nullable final EcoPlugin plugin) {
|
||||||
EcoPlugin owner = plugin == null ? Eco.get().getEcoPlugin() : plugin;
|
// This is really janky, and it sucks, but it works so?
|
||||||
Placeholder placeholder = REGISTERED_PLACEHOLDERS.getOrDefault(owner, new HashMap<>()).get(identifier.toLowerCase());
|
// 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) {
|
// I hate the streams API.
|
||||||
Placeholder alternate = REGISTERED_PLACEHOLDERS.getOrDefault(Eco.get().getEcoPlugin(), new HashMap<>())
|
Optional<Placeholder> found = REGISTERED_PLACEHOLDERS
|
||||||
.get(identifier.toLowerCase());
|
.getOrDefault(owner, new HashMap<>())
|
||||||
if (alternate != null) {
|
.entrySet()
|
||||||
placeholder = alternate;
|
.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) {
|
if (placeholder == null) {
|
||||||
return "";
|
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 (placeholder instanceof PlayerPlaceholder playerPlaceholder) {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return "";
|
return "";
|
||||||
@@ -159,6 +206,14 @@ public final class PlaceholderManager {
|
|||||||
}
|
}
|
||||||
} else if (placeholder instanceof PlayerlessPlaceholder playerlessPlaceholder) {
|
} else if (placeholder instanceof PlayerlessPlaceholder playerlessPlaceholder) {
|
||||||
return playerlessPlaceholder.getValue();
|
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 {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -245,8 +300,10 @@ public final class PlaceholderManager {
|
|||||||
for (PlaceholderIntegration integration : REGISTERED_INTEGRATIONS) {
|
for (PlaceholderIntegration integration : REGISTERED_INTEGRATIONS) {
|
||||||
processed = integration.translate(processed, player);
|
processed = integration.translate(processed, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (InjectablePlaceholder injection : context.getPlaceholderInjections()) {
|
for (InjectablePlaceholder injection : context.getPlaceholderInjections()) {
|
||||||
// Do I know this is a bad way of doing this? Yes.
|
// 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) {
|
if (injection instanceof StaticPlaceholder placeholder) {
|
||||||
processed = processed.replace("%" + placeholder.getIdentifier() + "%", placeholder.getValue());
|
processed = processed.replace("%" + placeholder.getIdentifier() + "%", placeholder.getValue());
|
||||||
} else if (injection instanceof PlayerStaticPlaceholder placeholder && player != null) {
|
} else if (injection instanceof PlayerStaticPlaceholder placeholder && player != null) {
|
||||||
@@ -280,11 +337,22 @@ public final class PlaceholderManager {
|
|||||||
return new ArrayList<>(found);
|
return new ArrayList<>(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record PlaceholderLookup(@NotNull String identifier,
|
||||||
|
@Nullable EcoPlugin plugin) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private record EntryWithPlayer(@NotNull PlayerPlaceholder entry,
|
private record EntryWithPlayer(@NotNull PlayerPlaceholder entry,
|
||||||
@NotNull Player player) {
|
@NotNull Player player) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record DynamicEntryWithPlayer(@NotNull PlayerDynamicPlaceholder entry,
|
||||||
|
@NotNull String args,
|
||||||
|
@NotNull Player player) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private PlaceholderManager() {
|
private PlaceholderManager() {
|
||||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
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.Eco;
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholders that can be injected into {@link PlaceholderInjectable} objects.
|
* Placeholders that can be injected into {@link PlaceholderInjectable} objects.
|
||||||
*/
|
*/
|
||||||
public sealed interface InjectablePlaceholder extends Placeholder permits PlayerStaticPlaceholder, StaticPlaceholder {
|
public sealed interface InjectablePlaceholder extends Placeholder permits PlayerStaticPlaceholder, StaticPlaceholder {
|
||||||
@Override
|
@Override
|
||||||
default EcoPlugin getPlugin() {
|
default @NotNull EcoPlugin getPlugin() {
|
||||||
return Eco.get().getEcoPlugin();
|
return Eco.get().getEcoPlugin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
package com.willfp.eco.core.placeholder;
|
package com.willfp.eco.core.placeholder;
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
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.
|
* 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.
|
* Get the plugin that holds the placeholder.
|
||||||
*
|
*
|
||||||
* @return The plugin.
|
* @return The plugin.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
EcoPlugin getPlugin();
|
EcoPlugin getPlugin();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,5 +24,16 @@ public sealed interface Placeholder permits PlayerPlaceholder, PlayerlessPlaceho
|
|||||||
*
|
*
|
||||||
* @return The identifier.
|
* @return The identifier.
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
String getIdentifier();
|
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.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A placeholder that requires a player.
|
* A placeholder that requires a player.
|
||||||
@@ -18,6 +19,11 @@ public final class PlayerPlaceholder implements Placeholder {
|
|||||||
*/
|
*/
|
||||||
private final String identifier;
|
private final String identifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The placeholder pattern.
|
||||||
|
*/
|
||||||
|
private final Pattern pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The function to retrieve the output of the placeholder given a player.
|
* 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) {
|
@NotNull final Function<Player, String> function) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
|
this.pattern = Pattern.compile(identifier);
|
||||||
this.function = function;
|
this.function = function;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +56,7 @@ public final class PlayerPlaceholder implements Placeholder {
|
|||||||
* @param player The player.
|
* @param player The player.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public String getValue(@NotNull final Player player) {
|
public String getValue(@NotNull final Player player) {
|
||||||
return function.apply(player);
|
return function.apply(player);
|
||||||
}
|
}
|
||||||
@@ -64,15 +72,21 @@ public final class PlayerPlaceholder implements Placeholder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EcoPlugin getPlugin() {
|
public @NotNull EcoPlugin getPlugin() {
|
||||||
return this.plugin;
|
return this.plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdentifier() {
|
public @NotNull String getIdentifier() {
|
||||||
return this.identifier;
|
return this.identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Pattern getPattern() {
|
||||||
|
return this.pattern;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable final Object o) {
|
public boolean equals(@Nullable final Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A placeholder that cannot be registered, and exists purely in injection.
|
* 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;
|
private final String identifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The placeholder pattern.
|
||||||
|
*/
|
||||||
|
private final Pattern pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The function to retrieve the output of the placeholder.
|
* 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,
|
public PlayerStaticPlaceholder(@NotNull final String identifier,
|
||||||
@NotNull final Function<Player, String> function) {
|
@NotNull final Function<Player, String> function) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
|
this.pattern = Pattern.compile(identifier);
|
||||||
this.function = function;
|
this.function = function;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,15 +46,22 @@ public final class PlayerStaticPlaceholder implements InjectablePlaceholder {
|
|||||||
* @param player The player.
|
* @param player The player.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public String getValue(@NotNull final Player player) {
|
public String getValue(@NotNull final Player player) {
|
||||||
return function.apply(player);
|
return function.apply(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdentifier() {
|
public @NotNull String getIdentifier() {
|
||||||
return this.identifier;
|
return this.identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Pattern getPattern() {
|
||||||
|
return this.pattern;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable final Object o) {
|
public boolean equals(@Nullable final Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
|
|||||||
@@ -7,16 +7,22 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A placeholder that does not require a player.
|
* A placeholder that does not require a player.
|
||||||
*/
|
*/
|
||||||
public final class PlayerlessPlaceholder implements Placeholder {
|
public final class PlayerlessPlaceholder implements Placeholder {
|
||||||
/**
|
/**
|
||||||
* The name of the placeholder.
|
* The placeholder identifier.
|
||||||
*/
|
*/
|
||||||
private final String identifier;
|
private final String identifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The placeholder pattern.
|
||||||
|
*/
|
||||||
|
private final Pattern pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The function to retrieve the output of the placeholder.
|
* The function to retrieve the output of the placeholder.
|
||||||
*/
|
*/
|
||||||
@@ -39,6 +45,7 @@ public final class PlayerlessPlaceholder implements Placeholder {
|
|||||||
@NotNull final Supplier<String> function) {
|
@NotNull final Supplier<String> function) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
|
this.pattern = Pattern.compile(identifier);
|
||||||
this.function = function;
|
this.function = function;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,15 +69,21 @@ public final class PlayerlessPlaceholder implements Placeholder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EcoPlugin getPlugin() {
|
public @NotNull EcoPlugin getPlugin() {
|
||||||
return this.plugin;
|
return this.plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdentifier() {
|
public @NotNull String getIdentifier() {
|
||||||
return this.identifier;
|
return this.identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Pattern getPattern() {
|
||||||
|
return this.pattern;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable final Object o) {
|
public boolean equals(@Nullable final Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A placeholder that cannot be registered, and exists purely in injection.
|
* 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;
|
private final String identifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The placeholder pattern.
|
||||||
|
*/
|
||||||
|
private final Pattern pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The function to retrieve the output of the placeholder.
|
* 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,
|
public StaticPlaceholder(@NotNull final String identifier,
|
||||||
@NotNull final Supplier<String> function) {
|
@NotNull final Supplier<String> function) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
|
this.pattern = Pattern.compile(identifier);
|
||||||
this.function = function;
|
this.function = function;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,15 +44,22 @@ public final class StaticPlaceholder implements InjectablePlaceholder {
|
|||||||
*
|
*
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return function.get();
|
return function.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdentifier() {
|
public @NotNull String getIdentifier() {
|
||||||
return this.identifier;
|
return this.identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Pattern getPattern() {
|
||||||
|
return this.pattern;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable final Object o) {
|
public boolean equals(@Nullable final Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
|
|||||||
@@ -71,10 +71,6 @@ public final class Prices {
|
|||||||
ctx
|
ctx
|
||||||
);
|
);
|
||||||
|
|
||||||
if (function.apply(context) <= 0) {
|
|
||||||
return new PriceFree();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default to economy
|
// Default to economy
|
||||||
if (priceName == null) {
|
if (priceName == null) {
|
||||||
return new PriceEconomy(context, function);
|
return new PriceEconomy(context, function);
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ import org.bukkit.command.TabCompleter
|
|||||||
class DelegatedBukkitCommand(
|
class DelegatedBukkitCommand(
|
||||||
private val delegate: EcoPluginCommand
|
private val delegate: EcoPluginCommand
|
||||||
) : Command(delegate.name), TabCompleter, PluginIdentifiableCommand {
|
) : Command(delegate.name), TabCompleter, PluginIdentifiableCommand {
|
||||||
|
private var _aliases: List<String>? = null
|
||||||
|
private var _description: String? = null
|
||||||
|
|
||||||
override fun execute(sender: CommandSender, label: String, args: Array<out String>?): Boolean {
|
override fun execute(sender: CommandSender, label: String, args: Array<out String>?): Boolean {
|
||||||
return false
|
return delegate.onCommand(sender, this, label, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTabComplete(
|
override fun onTabComplete(
|
||||||
@@ -18,11 +21,21 @@ class DelegatedBukkitCommand(
|
|||||||
label: String,
|
label: String,
|
||||||
args: Array<out String>?
|
args: Array<out String>?
|
||||||
): List<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
|
override fun getPlugin() = delegate.plugin
|
||||||
override fun getPermission() = delegate.permission
|
override fun getPermission() = delegate.permission
|
||||||
override fun getDescription() = delegate.description ?: ""
|
override fun getDescription() = _description ?: delegate.description ?: ""
|
||||||
override fun getAliases(): List<String> = delegate.aliases
|
override fun getAliases(): List<String> = _aliases ?: delegate.aliases
|
||||||
|
|
||||||
|
override fun setDescription(description: String): Command {
|
||||||
|
this._description = description
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setAliases(aliases: List<String>): Command {
|
||||||
|
this._aliases = aliases
|
||||||
|
return this
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,27 +17,25 @@ class EcoPluginCommand(
|
|||||||
override fun register() {
|
override fun register() {
|
||||||
val command = Bukkit.getPluginCommand(name)
|
val command = Bukkit.getPluginCommand(name)
|
||||||
|
|
||||||
|
val knownDescription = command?.description ?: description ?: ""
|
||||||
|
val knownAliases = command?.aliases ?: aliases
|
||||||
|
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
unregister()
|
unregister()
|
||||||
|
|
||||||
commandMap.register(plugin.name.lowercase(), DelegatedBukkitCommand(this))
|
commandMap.register(plugin.name.lowercase(), DelegatedBukkitCommand(this))
|
||||||
} else {
|
} else {
|
||||||
command.setExecutor(this)
|
command.setExecutor(this)
|
||||||
|
command.tabCompleter = this
|
||||||
|
command.description = knownDescription
|
||||||
description?.let {
|
command.aliases = knownAliases
|
||||||
command.setDescription(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aliases.isNotEmpty()) {
|
|
||||||
command.aliases = aliases
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Eco.get().syncCommands()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unregister() {
|
override fun unregister() {
|
||||||
val found = commandMap.getCommand(name)
|
commandMap.getCommand(name)?.unregister(commandMap)
|
||||||
found?.unregister(commandMap)
|
Eco.get().unregisterCommand(this)
|
||||||
|
|
||||||
Eco.get().syncCommands()
|
Eco.get().syncCommands()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ abstract class HandledCommand(
|
|||||||
command: Command,
|
command: Command,
|
||||||
label: String,
|
label: String,
|
||||||
args: Array<out String>?
|
args: Array<out String>?
|
||||||
): MutableList<String>? {
|
): List<String>? {
|
||||||
return handleTabComplete(sender, args?.toList() ?: listOf()).toMutableList()
|
return handleTabComplete(sender, args?.toList() ?: listOf())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPlugin() = this.plugin
|
override fun getPlugin() = this.plugin
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.willfp.eco.internal.spigot.proxy.v1_17_R1
|
package com.willfp.eco.internal.spigot.proxy.v1_17_R1
|
||||||
|
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
import com.willfp.eco.core.command.PluginCommandBase
|
||||||
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
@@ -28,7 +28,7 @@ class BukkitCommands : BukkitCommandsProxy {
|
|||||||
(Bukkit.getServer() as CraftServer).syncCommands()
|
(Bukkit.getServer() as CraftServer).syncCommands()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unregisterCommand(command: PluginCommand) {
|
override fun unregisterCommand(command: PluginCommandBase) {
|
||||||
knownCommands.remove(command.name)
|
knownCommands.remove(command.name)
|
||||||
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
|
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.willfp.eco.internal.spigot.proxy.v1_18_R1
|
package com.willfp.eco.internal.spigot.proxy.v1_18_R1
|
||||||
|
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
import com.willfp.eco.core.command.PluginCommandBase
|
||||||
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
@@ -28,7 +28,7 @@ class BukkitCommands : BukkitCommandsProxy {
|
|||||||
(Bukkit.getServer() as CraftServer).syncCommands()
|
(Bukkit.getServer() as CraftServer).syncCommands()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unregisterCommand(command: PluginCommand) {
|
override fun unregisterCommand(command: PluginCommandBase) {
|
||||||
knownCommands.remove(command.name)
|
knownCommands.remove(command.name)
|
||||||
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
|
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.willfp.eco.internal.spigot.proxy.v1_18_R2
|
package com.willfp.eco.internal.spigot.proxy.v1_18_R2
|
||||||
|
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
import com.willfp.eco.core.command.PluginCommandBase
|
||||||
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
@@ -28,7 +28,7 @@ class BukkitCommands : BukkitCommandsProxy {
|
|||||||
(Bukkit.getServer() as CraftServer).syncCommands()
|
(Bukkit.getServer() as CraftServer).syncCommands()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unregisterCommand(command: PluginCommand) {
|
override fun unregisterCommand(command: PluginCommandBase) {
|
||||||
knownCommands.remove(command.name)
|
knownCommands.remove(command.name)
|
||||||
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
|
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||||
|
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
import com.willfp.eco.core.command.PluginCommandBase
|
||||||
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
@@ -28,7 +28,7 @@ class BukkitCommands : BukkitCommandsProxy {
|
|||||||
(Bukkit.getServer() as CraftServer).syncCommands()
|
(Bukkit.getServer() as CraftServer).syncCommands()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unregisterCommand(command: PluginCommand) {
|
override fun unregisterCommand(command: PluginCommandBase) {
|
||||||
knownCommands.remove(command.name)
|
knownCommands.remove(command.name)
|
||||||
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
|
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R2
|
package com.willfp.eco.internal.spigot.proxy.v1_19_R2
|
||||||
|
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
import com.willfp.eco.core.command.PluginCommandBase
|
||||||
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
@@ -28,7 +28,7 @@ class BukkitCommands : BukkitCommandsProxy {
|
|||||||
(Bukkit.getServer() as CraftServer).syncCommands()
|
(Bukkit.getServer() as CraftServer).syncCommands()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unregisterCommand(command: PluginCommand) {
|
override fun unregisterCommand(command: PluginCommandBase) {
|
||||||
knownCommands.remove(command.name)
|
knownCommands.remove(command.name)
|
||||||
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
|
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ dependencies {
|
|||||||
compileOnly('com.github.TownyAdvanced:Towny:0.97.2.6') {
|
compileOnly('com.github.TownyAdvanced:Towny:0.97.2.6') {
|
||||||
exclude group: 'com.zaxxer', module: 'HikariCP'
|
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 'com.github.angeschossen:PluginFrameworkAPI:1.0.0'
|
||||||
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
||||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||||
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.202'
|
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.202'
|
||||||
compileOnly 'me.clip:placeholderapi:2.10.10'
|
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.brcdev-minecraft:shopgui-api:3.0.0'
|
||||||
compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.4.7'
|
compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.4.7'
|
||||||
compileOnly 'com.arcaniax:HeadDatabase-API:1.3.0'
|
compileOnly 'com.arcaniax:HeadDatabase-API:1.3.0'
|
||||||
@@ -48,7 +48,7 @@ dependencies {
|
|||||||
compileOnly 'com.github.WhipDevelopment:CrashClaim:f9cd7d92eb'
|
compileOnly 'com.github.WhipDevelopment:CrashClaim:f9cd7d92eb'
|
||||||
compileOnly 'com.wolfyscript.wolfyutilities:wolfyutilities:3.16.0.0'
|
compileOnly 'com.wolfyscript.wolfyutilities:wolfyutilities:3.16.0.0'
|
||||||
compileOnly 'com.github.decentsoftware-eu:decentholograms:2.1.2'
|
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.github.N0RSKA:ScytherAPI:55a'
|
||||||
compileOnly 'com.ticxo.modelengine:api:R3.0.1'
|
compileOnly 'com.ticxo.modelengine:api:R3.0.1'
|
||||||
compileOnly 'me.TechsCode:UltraEconomyAPI:1.0.0'
|
compileOnly 'me.TechsCode:UltraEconomyAPI:1.0.0'
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.willfp.eco.core.EcoPlugin
|
|||||||
import com.willfp.eco.core.PluginLike
|
import com.willfp.eco.core.PluginLike
|
||||||
import com.willfp.eco.core.PluginProps
|
import com.willfp.eco.core.PluginProps
|
||||||
import com.willfp.eco.core.command.CommandBase
|
import com.willfp.eco.core.command.CommandBase
|
||||||
|
import com.willfp.eco.core.command.PluginCommandBase
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
import com.willfp.eco.core.command.impl.PluginCommand
|
||||||
import com.willfp.eco.core.config.ConfigType
|
import com.willfp.eco.core.config.ConfigType
|
||||||
import com.willfp.eco.core.config.interfaces.Config
|
import com.willfp.eco.core.config.interfaces.Config
|
||||||
@@ -317,9 +318,6 @@ class EcoImpl : EcoSpigotPlugin(), Eco {
|
|||||||
override fun syncCommands() =
|
override fun syncCommands() =
|
||||||
this.getProxy(BukkitCommandsProxy::class.java).syncCommands()
|
this.getProxy(BukkitCommandsProxy::class.java).syncCommands()
|
||||||
|
|
||||||
override fun getCommandMap(): CommandMap =
|
override fun unregisterCommand(command: PluginCommandBase) =
|
||||||
this.getProxy(BukkitCommandsProxy::class.java).getCommandMap()
|
|
||||||
|
|
||||||
override fun unregisterCommand(command: PluginCommand) =
|
|
||||||
this.getProxy(BukkitCommandsProxy::class.java).unregisterCommand(command)
|
this.getProxy(BukkitCommandsProxy::class.java).unregisterCommand(command)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,6 +316,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
|||||||
IntegrationLoader("zShop") { ShopManager.register(ShopZShop()) },
|
IntegrationLoader("zShop") { ShopManager.register(ShopZShop()) },
|
||||||
IntegrationLoader("DeluxeSellwands") { ShopManager.register(ShopDeluxeSellwands()) },
|
IntegrationLoader("DeluxeSellwands") { ShopManager.register(ShopDeluxeSellwands()) },
|
||||||
IntegrationLoader("EconomyShopGUI") { ShopManager.register(ShopEconomyShopGUI()) },
|
IntegrationLoader("EconomyShopGUI") { ShopManager.register(ShopEconomyShopGUI()) },
|
||||||
|
IntegrationLoader("EconomyShopGUI-Premium") { ShopManager.register(ShopEconomyShopGUI()) },
|
||||||
|
|
||||||
// Hologram
|
// Hologram
|
||||||
IntegrationLoader("HolographicDisplays") { HologramManager.register(HologramHolographicDisplays(this)) },
|
IntegrationLoader("HolographicDisplays") { HologramManager.register(HologramHolographicDisplays(this)) },
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package com.willfp.eco.internal.spigot.integrations.antigrief
|
|||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import com.willfp.eco.core.integrations.antigrief.AntigriefIntegration
|
import com.willfp.eco.core.integrations.antigrief.AntigriefIntegration
|
||||||
import me.angeschossen.lands.api.LandsIntegration
|
import me.angeschossen.lands.api.LandsIntegration
|
||||||
import me.angeschossen.lands.api.flags.Flags
|
import me.angeschossen.lands.api.flags.type.Flags
|
||||||
import org.bukkit.Location
|
import org.bukkit.Location
|
||||||
|
import org.bukkit.Material
|
||||||
import org.bukkit.block.Block
|
import org.bukkit.block.Block
|
||||||
import org.bukkit.entity.Animals
|
import org.bukkit.entity.Animals
|
||||||
import org.bukkit.entity.LivingEntity
|
import org.bukkit.entity.LivingEntity
|
||||||
@@ -18,7 +19,7 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
|||||||
block: Block
|
block: Block
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val area = landsIntegration.getArea(block.location) ?: return true
|
val area = landsIntegration.getArea(block.location) ?: return true
|
||||||
return area.hasFlag(player, Flags.BLOCK_BREAK, false)
|
return area.hasRoleFlag(player, Flags.BLOCK_BREAK, block.type, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canCreateExplosion(
|
override fun canCreateExplosion(
|
||||||
@@ -26,7 +27,8 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
|||||||
location: Location
|
location: Location
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val area = landsIntegration.getArea(location) ?: return true
|
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, Flags.ATTACK_PLAYER, Material.AIR, false)
|
||||||
|
&& area.hasRoleFlag(player, Flags.ATTACK_ANIMAL, Material.AIR, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canPlaceBlock(
|
override fun canPlaceBlock(
|
||||||
@@ -34,7 +36,7 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
|||||||
block: Block
|
block: Block
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val area = landsIntegration.getArea(block.location) ?: return true
|
val area = landsIntegration.getArea(block.location) ?: return true
|
||||||
return area.hasFlag(player, Flags.BLOCK_PLACE, false)
|
return area.hasRoleFlag(player, Flags.BLOCK_PLACE, Material.AIR, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canInjure(
|
override fun canInjure(
|
||||||
@@ -45,16 +47,16 @@ class AntigriefLands(private val plugin: EcoPlugin) : AntigriefIntegration {
|
|||||||
val area = landsIntegration.getArea(victim.location) ?: return true
|
val area = landsIntegration.getArea(victim.location) ?: return true
|
||||||
|
|
||||||
return when(victim) {
|
return when(victim) {
|
||||||
is Player -> area.hasFlag(player, Flags.ATTACK_PLAYER, false)
|
is Player -> area.hasRoleFlag(player, Flags.ATTACK_PLAYER, Material.AIR, false)
|
||||||
is Monster -> area.hasFlag(player, Flags.ATTACK_MONSTER, false)
|
is Monster -> area.hasRoleFlag(player, Flags.ATTACK_MONSTER, Material.AIR, false)
|
||||||
is Animals -> area.hasFlag(player, Flags.ATTACK_MONSTER, false)
|
is Animals -> area.hasRoleFlag(player, Flags.ATTACK_ANIMAL, Material.AIR, false)
|
||||||
else -> area.isTrusted(player.uniqueId)
|
else -> area.isTrusted(player.uniqueId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canPickupItem(player: Player, location: Location): Boolean {
|
override fun canPickupItem(player: Player, location: Location): Boolean {
|
||||||
val area = landsIntegration.getArea(location) ?: return true
|
val area = landsIntegration.getArea(location) ?: return true
|
||||||
return area.hasFlag(player, Flags.ITEM_PICKUP, false)
|
return area.hasRoleFlag(player, Flags.ITEM_PICKUP, Material.AIR, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPluginName(): String {
|
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.TestableItem
|
||||||
import com.willfp.eco.core.items.provider.ItemProvider
|
import com.willfp.eco.core.items.provider.ItemProvider
|
||||||
import com.willfp.eco.util.NamespacedKeyUtils
|
import com.willfp.eco.util.NamespacedKeyUtils
|
||||||
import io.th0rgal.oraxen.items.OraxenItems
|
import io.th0rgal.oraxen.api.OraxenItems
|
||||||
|
|
||||||
class CustomItemsOraxen : CustomItemsIntegration {
|
class CustomItemsOraxen : CustomItemsIntegration {
|
||||||
override fun registerProvider() {
|
override fun registerProvider() {
|
||||||
|
|||||||
@@ -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.integrations.shop.ShopSellEvent
|
||||||
import com.willfp.eco.core.price.Price
|
import com.willfp.eco.core.price.Price
|
||||||
import com.willfp.eco.core.price.impl.PriceEconomy
|
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.EconomyShopGUIHook
|
||||||
import me.gypopo.economyshopgui.api.events.PreTransactionEvent
|
import me.gypopo.economyshopgui.api.events.PreTransactionEvent
|
||||||
|
import me.gypopo.economyshopgui.util.Transaction
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
@@ -18,27 +20,63 @@ class ShopEconomyShopGUI : ShopIntegration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getUnitValue(itemStack: ItemStack, player: Player): Price {
|
override fun getUnitValue(itemStack: ItemStack, player: Player): Price {
|
||||||
|
val shopItem = EconomyShopGUIHook.getShopItem(itemStack) ?: return PriceFree()
|
||||||
|
|
||||||
return PriceEconomy(
|
return PriceEconomy(
|
||||||
EconomyShopGUIHook.getItemSellPrice(player, itemStack.clone().apply {
|
EconomyShopGUIHook.getItemSellPrice(shopItem, itemStack.clone().apply {
|
||||||
amount = 1
|
amount = 1
|
||||||
})
|
}, player)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isSellable(itemStack: ItemStack, player: Player): Boolean {
|
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 {
|
object EconomyShopGUISellEventListeners : Listener {
|
||||||
|
private val sellTypes = listOf(
|
||||||
|
"SELL_GUI_SCREEN",
|
||||||
|
"SELL_SCREEN",
|
||||||
|
"SELL_ALL_SCREEN",
|
||||||
|
"SELL_ALL_COMMAND",
|
||||||
|
"QUICK_SELL",
|
||||||
|
"AUTO_SELL_CHEST",
|
||||||
|
)
|
||||||
|
|
||||||
|
private val sellAllTypes = listOf(
|
||||||
|
"SELL_GUI_SCREEN",
|
||||||
|
"SELL_ALL_COMMAND",
|
||||||
|
)
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
fun shopEventToEcoEvent(event: PreTransactionEvent) {
|
fun shopEventToEcoEvent(event: PreTransactionEvent) {
|
||||||
|
if (event.transactionType.name.uppercase() !in sellTypes) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (event.isCancelled) {
|
if (event.isCancelled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val ecoEvent = ShopSellEvent(event.player, PriceEconomy(event.price), event.itemStack)
|
val prices = if (event.transactionType.name.uppercase() in sellAllTypes) {
|
||||||
Bukkit.getPluginManager().callEvent(ecoEvent)
|
event.items!!
|
||||||
event.price = ecoEvent.value.getValue(event.player) * ecoEvent.multiplier
|
} 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ softdepend:
|
|||||||
- ExecutableItems
|
- ExecutableItems
|
||||||
- RPGHorses
|
- RPGHorses
|
||||||
- EconomyShopGUI
|
- EconomyShopGUI
|
||||||
|
- EconomyShopGUI-Premium
|
||||||
- zShop
|
- zShop
|
||||||
- DeluxeSellwands
|
- DeluxeSellwands
|
||||||
- Scyther
|
- Scyther
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.willfp.eco.internal.spigot.proxy
|
package com.willfp.eco.internal.spigot.proxy
|
||||||
|
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
import com.willfp.eco.core.command.PluginCommandBase
|
||||||
import org.bukkit.command.CommandMap
|
import org.bukkit.command.CommandMap
|
||||||
|
|
||||||
interface BukkitCommandsProxy {
|
interface BukkitCommandsProxy {
|
||||||
@@ -8,5 +8,5 @@ interface BukkitCommandsProxy {
|
|||||||
|
|
||||||
fun syncCommands()
|
fun syncCommands()
|
||||||
|
|
||||||
fun unregisterCommand(command: PluginCommand)
|
fun unregisterCommand(command: PluginCommandBase)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version = 6.49.1
|
version = 6.50.3
|
||||||
plugin-name = eco
|
plugin-name = eco
|
||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
Reference in New Issue
Block a user