From 02a2a2133aec51adacc58b1db02b3aaed39afbd1 Mon Sep 17 00:00:00 2001 From: qwz Date: Wed, 4 Aug 2021 20:28:53 +0200 Subject: [PATCH 01/10] Update to dock 4.0.0-SNAPSHOT --- pom.xml | 10 +++++----- .../conditionaltext/ConditionalTextLanguage.java | 7 ++++--- .../wertik/conditionaltext/ConditionalTextPlugin.java | 10 +++++----- .../commands/ConditionalTextCommand.java | 4 ++-- .../commands/ConditionalTextSubCommand.java | 4 ++-- .../commands/subcommands/TrySubCommand.java | 4 ++-- .../wertik/conditionaltext/system/SettingManager.java | 5 ++--- .../wertik/conditionaltext/system/struct/Setting.java | 7 +++---- .../system/struct/operator/impl/OperatorWrapper.java | 3 +-- .../conditionaltext/system/utils/ParserUtil.java | 3 +-- .../conditionaltext/system/utils/PlaceholderUtil.java | 2 +- src/main/resources/plugin.yml | 1 + 12 files changed, 29 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index 61df639..a17789b 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ devport - https://nexus.pvpcraft.cz/repository/devport/ + https://nexus.devport.space/repository/devport-public/ placeholderapi @@ -86,18 +86,18 @@ org.jetbrains annotations - 20.1.0 + 21.0.1 compile org.projectlombok lombok - 1.18.16 + 1.18.20 provided - space.devport.utils - devportutils + space.devport.dock + dock 4.0.0-SNAPSHOT compile diff --git a/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextLanguage.java b/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextLanguage.java index 73fa006..acc273a 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextLanguage.java +++ b/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextLanguage.java @@ -1,11 +1,12 @@ package space.devport.wertik.conditionaltext; -import space.devport.utils.DevportPlugin; -import space.devport.utils.text.language.LanguageDefaults; + +import space.devport.dock.api.IDockedPlugin; +import space.devport.dock.text.language.LanguageDefaults; public class ConditionalTextLanguage extends LanguageDefaults { - public ConditionalTextLanguage(DevportPlugin plugin) { + public ConditionalTextLanguage(IDockedPlugin plugin) { super(plugin); } diff --git a/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextPlugin.java b/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextPlugin.java index 10846be..e2a07e3 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextPlugin.java +++ b/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextPlugin.java @@ -4,17 +4,17 @@ import lombok.extern.java.Log; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import space.devport.utils.DevportPlugin; -import space.devport.utils.UsageFlag; -import space.devport.utils.utility.DependencyUtil; -import space.devport.utils.utility.VersionUtil; +import space.devport.dock.DockedPlugin; +import space.devport.dock.UsageFlag; +import space.devport.dock.util.DependencyUtil; +import space.devport.dock.util.VersionUtil; import space.devport.wertik.conditionaltext.commands.ConditionalTextCommand; import space.devport.wertik.conditionaltext.system.SettingManager; import java.time.format.DateTimeFormatter; @Log -public class ConditionalTextPlugin extends DevportPlugin { +public class ConditionalTextPlugin extends DockedPlugin { @Getter private static ConditionalTextPlugin instance; diff --git a/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextCommand.java b/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextCommand.java index cf80d85..87c7a4f 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextCommand.java +++ b/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextCommand.java @@ -1,7 +1,7 @@ package space.devport.wertik.conditionaltext.commands; -import space.devport.utils.commands.MainCommand; -import space.devport.utils.commands.struct.CommandResult; +import space.devport.dock.commands.MainCommand; +import space.devport.dock.commands.struct.CommandResult; import space.devport.wertik.conditionaltext.ConditionalTextPlugin; import space.devport.wertik.conditionaltext.commands.subcommands.TrySubCommand; diff --git a/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextSubCommand.java b/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextSubCommand.java index 893f412..e6ab4b2 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextSubCommand.java +++ b/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextSubCommand.java @@ -2,8 +2,8 @@ import lombok.Getter; import org.jetbrains.annotations.Nullable; -import space.devport.utils.commands.SubCommand; -import space.devport.utils.commands.struct.ArgumentRange; +import space.devport.dock.commands.SubCommand; +import space.devport.dock.commands.struct.ArgumentRange; import space.devport.wertik.conditionaltext.ConditionalTextPlugin; public abstract class ConditionalTextSubCommand extends SubCommand { diff --git a/src/main/java/space/devport/wertik/conditionaltext/commands/subcommands/TrySubCommand.java b/src/main/java/space/devport/wertik/conditionaltext/commands/subcommands/TrySubCommand.java index 644dfd9..4f8ae0a 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/commands/subcommands/TrySubCommand.java +++ b/src/main/java/space/devport/wertik/conditionaltext/commands/subcommands/TrySubCommand.java @@ -6,8 +6,8 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import space.devport.utils.commands.struct.ArgumentRange; -import space.devport.utils.commands.struct.CommandResult; +import space.devport.dock.commands.struct.ArgumentRange; +import space.devport.dock.commands.struct.CommandResult; import space.devport.wertik.conditionaltext.ConditionalTextPlugin; import space.devport.wertik.conditionaltext.commands.ConditionalTextSubCommand; import space.devport.wertik.conditionaltext.system.struct.Setting; diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/SettingManager.java b/src/main/java/space/devport/wertik/conditionaltext/system/SettingManager.java index 627cbb7..bd9f0ce 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/SettingManager.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/SettingManager.java @@ -3,8 +3,7 @@ import lombok.Getter; import lombok.extern.java.Log; import org.jetbrains.annotations.Nullable; -import space.devport.utils.configuration.Configuration; -import space.devport.utils.logging.DebugLevel; +import space.devport.dock.configuration.Configuration; import space.devport.wertik.conditionaltext.ConditionalTextPlugin; import space.devport.wertik.conditionaltext.system.struct.Setting; @@ -38,7 +37,7 @@ public void load() { continue; loadedSettings.put(settingName, setting); - log.log(DebugLevel.DEBUG, String.format("Loaded setting %s", settingName)); + log.fine(String.format("Loaded setting %s", settingName)); } log.info(String.format("Loaded %d setting(s)...", loadedSettings.size())); diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java b/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java index 3ecdc97..9aa448e 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java @@ -6,9 +6,8 @@ import org.bukkit.OfflinePlayer; import org.bukkit.configuration.ConfigurationSection; import org.jetbrains.annotations.Nullable; -import space.devport.utils.configuration.Configuration; -import space.devport.utils.logging.DebugLevel; -import space.devport.utils.text.StringUtil; +import space.devport.dock.configuration.Configuration; +import space.devport.dock.util.StringUtil; import space.devport.wertik.conditionaltext.system.utils.PlaceholderUtil; import java.util.LinkedList; @@ -53,7 +52,7 @@ public static Setting load(Configuration config, String path) { } setting.addRule(rule); - log.log(DebugLevel.DEBUG, String.format("Loaded rule %s", rule.toString())); + log.fine(String.format("Loaded rule %s", rule)); } return setting; diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/impl/OperatorWrapper.java b/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/impl/OperatorWrapper.java index b275e53..29b58e0 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/impl/OperatorWrapper.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/impl/OperatorWrapper.java @@ -3,7 +3,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.java.Log; -import space.devport.utils.logging.DebugLevel; @Log @RequiredArgsConstructor @@ -16,7 +15,7 @@ public class OperatorWrapper { public boolean apply(Object input, Object required) { boolean bool = function.apply(input, required); - log.log(DebugLevel.DEBUG, String.format("'%s' (%s) %s '%s' (%s) -> %b", + log.fine(String.format("'%s' (%s) %s '%s' (%s) -> %b", input, input.getClass().getSimpleName(), sign, required, required.getClass().getSimpleName(), bool)); return bool; } diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/utils/ParserUtil.java b/src/main/java/space/devport/wertik/conditionaltext/system/utils/ParserUtil.java index 3a915a9..b6cc45f 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/utils/ParserUtil.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/utils/ParserUtil.java @@ -3,7 +3,6 @@ import lombok.experimental.UtilityClass; import lombok.extern.java.Log; import org.jetbrains.annotations.NotNull; -import space.devport.utils.logging.DebugLevel; import space.devport.wertik.conditionaltext.ConditionalTextPlugin; import java.time.LocalTime; @@ -41,7 +40,7 @@ public Object parseObject(String input) { if (out == null) out = input; - log.log(DebugLevel.DEBUG, String.format("Parsed: '%s' -> (%s)", input, out.getClass().getSimpleName())); + log.fine(String.format("Parsed: '%s' -> (%s)", input, out.getClass().getSimpleName())); return out; } } \ No newline at end of file diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/utils/PlaceholderUtil.java b/src/main/java/space/devport/wertik/conditionaltext/system/utils/PlaceholderUtil.java index 3f89be3..3749f14 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/utils/PlaceholderUtil.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/utils/PlaceholderUtil.java @@ -4,7 +4,7 @@ import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.Nullable; -import space.devport.utils.text.StringUtil; +import space.devport.dock.util.StringUtil; @UtilityClass public class PlaceholderUtil { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 88618ee..0fd77c6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,6 +3,7 @@ main: ${project.groupId}.ConditionalTextPlugin version: ${project.version} authors: [ Wertik1206 ] softdepend: [ PlaceholderAPI ] +api-version: 1.13 commands: conditionaltext: description: Main plugin command. From 0b426183c652797ca8e89d10d07b3320de7bc129 Mon Sep 17 00:00:00 2001 From: qwz Date: Wed, 4 Aug 2021 21:43:33 +0200 Subject: [PATCH 02/10] Clean around, add some comments so I don't have to think. --- pom.xml | 2 +- .../ConditionalTextExpansion.java | 6 ++- .../system/struct/Condition.java | 17 +++++-- .../system/struct/Setting.java | 34 +++++++++----- .../struct/operator/impl/OperatorWrapper.java | 5 +- .../system/utils/ParseUtil.java | 37 +++++++++++++++ .../system/utils/ParserUtil.java | 46 ------------------- .../system/utils/PlaceholderUtil.java | 15 ++++-- src/main/resources/config.yml | 9 +++- src/main/resources/plugin.yml | 2 +- 10 files changed, 98 insertions(+), 75 deletions(-) create mode 100644 src/main/java/space/devport/wertik/conditionaltext/system/utils/ParseUtil.java delete mode 100644 src/main/java/space/devport/wertik/conditionaltext/system/utils/ParserUtil.java diff --git a/pom.xml b/pom.xml index a17789b..45670ce 100644 --- a/pom.xml +++ b/pom.xml @@ -80,7 +80,7 @@ org.spigotmc spigot-api - 1.16.5-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT provided diff --git a/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextExpansion.java b/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextExpansion.java index 81b6540..315f94b 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextExpansion.java +++ b/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextExpansion.java @@ -40,14 +40,16 @@ public String onPlaceholderRequest(Player player, @NotNull String params) { if (Strings.isNullOrEmpty(params)) return "invalid-params"; + String[] args = params.split("_"); + Setting setting = plugin.getSettingManager().getSetting(params.split("_")[0]); if (setting == null) return "invalid-setting"; - String[] args = Arrays.copyOfRange(params.split("_"), 1, params.split("_").length); + String[] placeholderArguments = Arrays.copyOfRange(args, 1, args.length); - String output = setting.process(player, args); + String output = setting.process(player, placeholderArguments); return output == null ? plugin.getConfig().getString("empty-output", "no-match") : output; } diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/struct/Condition.java b/src/main/java/space/devport/wertik/conditionaltext/system/struct/Condition.java index 83108b9..affe432 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/struct/Condition.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/struct/Condition.java @@ -2,13 +2,15 @@ import com.google.common.base.Strings; import lombok.Getter; +import lombok.extern.java.Log; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.Nullable; import space.devport.wertik.conditionaltext.system.struct.operator.Operators; import space.devport.wertik.conditionaltext.system.struct.operator.impl.OperatorWrapper; -import space.devport.wertik.conditionaltext.system.utils.ParserUtil; +import space.devport.wertik.conditionaltext.system.utils.ParseUtil; import space.devport.wertik.conditionaltext.system.utils.PlaceholderUtil; +@Log public class Condition { @Getter @@ -37,16 +39,21 @@ public static Condition fromString(String input) { } } - return operator == null ? null : new Condition(ParserUtil.parseObject(input), operator); + return operator == null ? null : new Condition(ParseUtil.parseObject(input), operator); } public boolean check(Object value, @Nullable OfflinePlayer player) { Object required = this.required; - // Parse placeholders in String requirements + // Parse placeholders in String requirements. if (required instanceof String) - required = ParserUtil.parseObject(PlaceholderUtil.parsePlaceholders(player, (String) required)); + required = ParseUtil.parseObject(PlaceholderUtil.parsePlaceholders(player, (String) required)); - return operator.apply(value, required); + boolean out = operator.apply(value, required); + + log.fine(String.format("'%s' (%s) %s '%s' (%s) -> %b", + value, value.getClass().getSimpleName(), operator.getSign(), required, required.getClass().getSimpleName(), out)); + + return out; } } \ No newline at end of file diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java b/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java index 9aa448e..492dafc 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java @@ -62,41 +62,53 @@ public void addRule(Rule rule) { rules.add(rule); } + // Run rules for given Object value. + @Nullable + public String process(@Nullable OfflinePlayer player, Object value) { + for (Rule rule : rules) { + if (rule.check(value, player)) + return rule.getOutput(); + } + return null; + } + // Process the given value and output the formatted text based on rules. @Nullable public String process(@Nullable OfflinePlayer player, Object value, String... arguments) { + + // Actually process the value into an output String output = process(player, value); + // Parse arguments again (in case there were some in the output) output = parseArguments(output, arguments); + // Parse PAPI again and color the output. return StringUtil.color(output != null ? PlaceholderAPI.setPlaceholders(player, output) : null); } @Nullable public String process(@Nullable OfflinePlayer player, String valueString, String... arguments) { Object value = PlaceholderUtil.parsePlaceholderIntoObject(player, valueString); + + log.fine(String.format("Parsed: '%s' -> (%s)", placeholder, value.getClass().getSimpleName())); + return process(player, value, arguments); } // Process the Setting placeholder and output the formatted text based on rules. @Nullable public String process(@Nullable OfflinePlayer player, String... arguments) { + + // Replace $n String placeholder = parseArguments(this.placeholder, arguments); + + // Parse the placeholder into a comparable object. Object value = PlaceholderUtil.parsePlaceholderIntoObject(player, placeholder); - return process(player, value, arguments); - } - // Run rules for given Object value. - // Return the raw output. - @Nullable - public String process(@Nullable OfflinePlayer player, Object value) { - for (Rule rule : rules) { - if (rule.check(value, player)) - return rule.getOutput(); - } - return null; + return process(player, value, arguments); } + // Replace $n with arguments from the placeholder. private String parseArguments(String string, String[] arguments) { for (int n = 0; n < arguments.length; n++) { String argument = arguments[n]; diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/impl/OperatorWrapper.java b/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/impl/OperatorWrapper.java index 29b58e0..0a7390f 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/impl/OperatorWrapper.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/impl/OperatorWrapper.java @@ -14,9 +14,6 @@ public class OperatorWrapper { private final ObjectOperator function; public boolean apply(Object input, Object required) { - boolean bool = function.apply(input, required); - log.fine(String.format("'%s' (%s) %s '%s' (%s) -> %b", - input, input.getClass().getSimpleName(), sign, required, required.getClass().getSimpleName(), bool)); - return bool; + return function.apply(input, required); } } \ No newline at end of file diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/utils/ParseUtil.java b/src/main/java/space/devport/wertik/conditionaltext/system/utils/ParseUtil.java new file mode 100644 index 0000000..42c50de --- /dev/null +++ b/src/main/java/space/devport/wertik/conditionaltext/system/utils/ParseUtil.java @@ -0,0 +1,37 @@ +package space.devport.wertik.conditionaltext.system.utils; + +import lombok.experimental.UtilityClass; +import lombok.extern.java.Log; +import org.jetbrains.annotations.NotNull; +import space.devport.wertik.conditionaltext.ConditionalTextPlugin; + +import java.time.LocalTime; +import java.time.format.DateTimeParseException; + +@Log +@UtilityClass +public class ParseUtil { + + @NotNull + public Object parseObject(@NotNull String input) { + + try { + return Integer.parseInt(input); + } catch (NumberFormatException ignored) { + // Not an integer + } + + try { + return Double.parseDouble(input); + } catch (NumberFormatException ignored) { + // Not a double + } + try { + return LocalTime.parse(input, ConditionalTextPlugin.getInstance().getTimeFormatter()); + } catch (DateTimeParseException ignored) { + // Not a date + } + + return input; + } +} \ No newline at end of file diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/utils/ParserUtil.java b/src/main/java/space/devport/wertik/conditionaltext/system/utils/ParserUtil.java deleted file mode 100644 index b6cc45f..0000000 --- a/src/main/java/space/devport/wertik/conditionaltext/system/utils/ParserUtil.java +++ /dev/null @@ -1,46 +0,0 @@ -package space.devport.wertik.conditionaltext.system.utils; - -import lombok.experimental.UtilityClass; -import lombok.extern.java.Log; -import org.jetbrains.annotations.NotNull; -import space.devport.wertik.conditionaltext.ConditionalTextPlugin; - -import java.time.LocalTime; -import java.time.format.DateTimeParseException; - -@Log -@UtilityClass -public class ParserUtil { - - @NotNull - public Object parseObject(String input) { - - Object out = null; - - try { - out = Integer.parseInt(input); - } catch (NumberFormatException ignored) { - // Not an integer - } - - if (out == null) - try { - return Double.parseDouble(input); - } catch (NumberFormatException ignored) { - // Not a double - } - - if (out == null) - try { - return LocalTime.parse(input, ConditionalTextPlugin.getInstance().getTimeFormatter()); - } catch (DateTimeParseException ignored) { - // Not a date - } - - if (out == null) - out = input; - - log.fine(String.format("Parsed: '%s' -> (%s)", input, out.getClass().getSimpleName())); - return out; - } -} \ No newline at end of file diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/utils/PlaceholderUtil.java b/src/main/java/space/devport/wertik/conditionaltext/system/utils/PlaceholderUtil.java index 3749f14..b3ca353 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/utils/PlaceholderUtil.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/utils/PlaceholderUtil.java @@ -1,19 +1,26 @@ package space.devport.wertik.conditionaltext.system.utils; import lombok.experimental.UtilityClass; +import lombok.extern.java.Log; import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import space.devport.dock.util.StringUtil; +@Log @UtilityClass public class PlaceholderUtil { - public String parsePlaceholders(@Nullable OfflinePlayer player, String placeholder) { - return StringUtil.stripColor(PlaceholderAPI.setPlaceholders(player, placeholder)); + // Parse PlaceholderAPI placeholders. + @NotNull + public String parsePlaceholders(@Nullable OfflinePlayer player, @NotNull String placeholder) { + return StringUtil.stripColor(PlaceholderAPI.setPlaceholders(player, placeholder)); // Strip colors from the result } - public Object parsePlaceholderIntoObject(@Nullable OfflinePlayer player, String placeholder) { - return ParserUtil.parseObject(parsePlaceholders(player, placeholder)); + // Parse PlaceholderAPI placeholders and then into a comparable object. + @NotNull + public Object parsePlaceholderIntoObject(@Nullable OfflinePlayer player, @NotNull String placeholder) { + return ParseUtil.parseObject(parsePlaceholders(player, placeholder)); } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2e0e172..3c559a6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,7 +3,14 @@ # Version: ${project.version} plugin-prefix: '&eConditionalText &8| ' -debug-enabled: false + +## Plugin log level +# SEVERE - Errors +# WARNING - Warnings +# INFO - Normal user information +# FINE - Debug messages +# (...lower levels are not used) +log-level: INFO # Configure the placeholder identifier. # PAPI format: %_(params)% diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0fd77c6..282a307 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: ${project.name} main: ${project.groupId}.ConditionalTextPlugin version: ${project.version} -authors: [ Wertik1206 ] +authors: [ qwz ] softdepend: [ PlaceholderAPI ] api-version: 1.13 commands: From 93a52548d1b312b13e1e7551f1cab1f2750388a6 Mon Sep 17 00:00:00 2001 From: qwz Date: Wed, 4 Aug 2021 21:55:31 +0200 Subject: [PATCH 03/10] Add a list command. --- .../ConditionalTextLanguage.java | 5 ++ .../commands/ConditionalTextCommand.java | 2 + .../commands/subcommands/ListSubCommand.java | 56 +++++++++++++++++++ .../system/struct/Setting.java | 6 ++ 4 files changed, 69 insertions(+) create mode 100644 src/main/java/space/devport/wertik/conditionaltext/commands/subcommands/ListSubCommand.java diff --git a/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextLanguage.java b/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextLanguage.java index acc273a..8885ff9 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextLanguage.java +++ b/src/main/java/space/devport/wertik/conditionaltext/ConditionalTextLanguage.java @@ -16,5 +16,10 @@ public void setDefaults() { addDefault("Commands.Invalid-Target", "&cPlayer &f%param% &cis invalid."); addDefault("Commands.Try.Output", "&7Parsed, result: '&r%result%&7'"); + + addDefault("Commands.List.Empty", "&7No settings yet."); + + addDefault("Commands.List.Header", "&8&m &f Loaded Settings &8&m "); + addDefault("Commands.List.Format", "&8 - &f%name% &7( &f%rules% rule(s) &7)"); } } diff --git a/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextCommand.java b/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextCommand.java index 87c7a4f..876797c 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextCommand.java +++ b/src/main/java/space/devport/wertik/conditionaltext/commands/ConditionalTextCommand.java @@ -3,6 +3,7 @@ import space.devport.dock.commands.MainCommand; import space.devport.dock.commands.struct.CommandResult; import space.devport.wertik.conditionaltext.ConditionalTextPlugin; +import space.devport.wertik.conditionaltext.commands.subcommands.ListSubCommand; import space.devport.wertik.conditionaltext.commands.subcommands.TrySubCommand; public class ConditionalTextCommand extends MainCommand { @@ -19,6 +20,7 @@ public ConditionalTextCommand(ConditionalTextPlugin plugin) { return CommandResult.SUCCESS; })); withSubCommand(new TrySubCommand(plugin)); + withSubCommand(new ListSubCommand(plugin)); } @Override diff --git a/src/main/java/space/devport/wertik/conditionaltext/commands/subcommands/ListSubCommand.java b/src/main/java/space/devport/wertik/conditionaltext/commands/subcommands/ListSubCommand.java new file mode 100644 index 0000000..d2eb95f --- /dev/null +++ b/src/main/java/space/devport/wertik/conditionaltext/commands/subcommands/ListSubCommand.java @@ -0,0 +1,56 @@ +package space.devport.wertik.conditionaltext.commands.subcommands; + +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import space.devport.dock.commands.struct.ArgumentRange; +import space.devport.dock.commands.struct.CommandResult; +import space.devport.dock.text.message.Message; +import space.devport.wertik.conditionaltext.ConditionalTextPlugin; +import space.devport.wertik.conditionaltext.commands.ConditionalTextSubCommand; +import space.devport.wertik.conditionaltext.system.struct.Setting; + +import java.util.Map; + +public class ListSubCommand extends ConditionalTextSubCommand { + + public ListSubCommand(ConditionalTextPlugin plugin) { + super(plugin, "list"); + } + + @Override + protected @NotNull CommandResult perform(@NotNull CommandSender sender, @NotNull String label, String[] args) { + + Map settings = getPlugin().getSettingManager().getSettings(); + + if (settings.isEmpty()) { + language.sendPrefixed(sender, "Commands.List.Empty"); + return CommandResult.SUCCESS; + } + + Message header = language.get("Commands.List.Header"); + String format = language.get("Commands.List.Format").toString(); + + for (Map.Entry entry : settings.entrySet()) { + header.append(format.replace("%name%", entry.getKey()).replace("%rules%", String.valueOf(entry.getValue().getRules().size()))); + } + + header.send(sender); + return CommandResult.SUCCESS; + } + + @Override + public @Nullable String getDefaultUsage() { + return "/%label% list"; + } + + @Override + public @Nullable String getDefaultDescription() { + return "List loaded settings."; + } + + @Override + public @Nullable ArgumentRange getRange() { + return new ArgumentRange(0); + } +} diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java b/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java index 492dafc..84096db 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/struct/Setting.java @@ -10,6 +10,8 @@ import space.devport.dock.util.StringUtil; import space.devport.wertik.conditionaltext.system.utils.PlaceholderUtil; +import java.util.Collection; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -58,6 +60,10 @@ public static Setting load(Configuration config, String path) { return setting; } + public Collection getRules() { + return Collections.unmodifiableList(this.rules); + } + public void addRule(Rule rule) { rules.add(rule); } From bb0ac7cc00701b13ea71fa66665edec058c27e81 Mon Sep 17 00:00:00 2001 From: Mpcs Date: Thu, 5 Aug 2021 21:04:01 +0200 Subject: [PATCH 04/10] Add modulo operator --- .../system/struct/operator/Operators.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/Operators.java b/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/Operators.java index 0861b9d..2db8c80 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/Operators.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/struct/operator/Operators.java @@ -68,6 +68,15 @@ public class Operators { return false; }); + operatorFunctions.put("%", (input, required) -> { + + if (input instanceof Number && required instanceof Number) { + return ((Number) input).floatValue() % ((Number) required).floatValue() == 0; + } + + return false; + }); + operatorFunctions.put("==", Objects::equals); operatorFunctions.put("!==", (a, b) -> !Objects.equals(a, b)); From 4a57546f1958d8ec00f4522c143f896fa74a2821 Mon Sep 17 00:00:00 2001 From: Mpcs Date: Fri, 6 Aug 2021 22:26:23 +0200 Subject: [PATCH 05/10] condition parsing fix --- .../devport/wertik/conditionaltext/system/struct/Condition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/space/devport/wertik/conditionaltext/system/struct/Condition.java b/src/main/java/space/devport/wertik/conditionaltext/system/struct/Condition.java index affe432..d1a510a 100644 --- a/src/main/java/space/devport/wertik/conditionaltext/system/struct/Condition.java +++ b/src/main/java/space/devport/wertik/conditionaltext/system/struct/Condition.java @@ -33,7 +33,7 @@ public static Condition fromString(String input) { for (String sign : Operators.operatorFunctions.keySet()) { if (input.startsWith(sign)) { - input = input.replace(sign, ""); + input = input.replaceFirst(sign, ""); operator = new OperatorWrapper(sign, Operators.getFunction(sign)); break; } From 3464e43ea6fba3f143d4c2992881fc97723e745d Mon Sep 17 00:00:00 2001 From: qwz <33769406+Wertik@users.noreply.github.com> Date: Sat, 7 Aug 2021 14:30:16 +0200 Subject: [PATCH 06/10] Add modulo operator to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6730c85..3cb3f11 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Conditions should always have a valid operator on the left side and the limit nu Any type operators: `empty, !empty` (check if a placeholder returns empty value)\ Valid string operators: `=, !=`\ -Valid number operators: `=, !=, <, >, <=, >=`\ +Valid number operators: `=, !=, <, >, <=, >=, %`\ Valid time operators: `=, !=, <, >, <=, >=` When no condition is specified, it's automatically condidered true -- passing. \ From d3fe445257c328719a78606f2dbfa5a21b037f0d Mon Sep 17 00:00:00 2001 From: qwz <33769406+Wertik@users.noreply.github.com> Date: Sat, 7 Aug 2021 14:33:43 +0200 Subject: [PATCH 07/10] Update README.md --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3cb3f11..669e0c5 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ rules: - '&7On your way to a million huh.' ``` -Since 1.1.2 you can also use placeholders in conditions. +You can also use other placeholders in conditions. ``- '<%some_placeholder%;&7Some text.'`` With strings: @@ -99,12 +99,12 @@ But first, load the new settings in with a quick `/ct reload`. Then just use the placeholder ``%conditionaltext_%`` whereever you desire. (And where PlaceholderAPI is supported) -### Extra feature - custom arguments +### Arguments in placeholders It's a useful feature when you want to use one setting for more variations of the same placeholder, for example displaying the amount of keys on multiple crates. -It would be a pain to create a setting for each of the crate types. +It would be painful to create a setting for each of the crate types. -And that's why this is a thing: +That's when arguments come in handy: ```yaml custom-arg-setting: placeholder: '%specializedcrates_virtual_keys_$0%' @@ -116,11 +116,12 @@ custom-arg-setting: ``` *Example with [Specialized crates](https://www.spigotmc.org/resources/specialized-crates-1-8-1-16.9047/)* -To provide the `$0` argument, add another param to our placeholder: ``%conditionaltext__(args)%``\ -You can add as many of them as you want! Just make sure you're **counting from 0**, because that's the right and only way to count, and seperating each one with an underscore. +To provide the `$0` argument, add another param to the placeholder: ``%conditionaltext__(args)%``\ +You can add as many of them as you want. Just make sure you're **counting from 0** and seperating each one with an underscore. For the above example with a crate named Epic to display, you'd use ``%conditionaltext_custom-arg-setting_Epic%`` +Then with a different type of crate,.. let's say Mythic: ``%conditionaltext_custom-arg-setting_Mythic%`` ### Help -For help, join [this empty discord server](https://discord.gg/5Suw58j) +For help, join [this discord server](https://discord.gg/5Suw58j) From af4a5a81e44b545f6be79aeb4972c8501346b21a Mon Sep 17 00:00:00 2001 From: qwz Date: Sun, 8 Aug 2021 21:21:12 +0200 Subject: [PATCH 08/10] Relocate the right package. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 45670ce..91711c1 100644 --- a/pom.xml +++ b/pom.xml @@ -44,8 +44,8 @@ true - space.devport.utils - ${project.groupId}.utils + space.devport.dock + ${project.groupId}.dock From 440207237e4455e764c252e9267b00ceca7aa3f1 Mon Sep 17 00:00:00 2001 From: qwz Date: Tue, 10 Aug 2021 14:27:44 +0200 Subject: [PATCH 09/10] Update PAPI version, correct log level names. --- pom.xml | 2 +- src/main/resources/config.yml | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 91711c1..a9a6349 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ me.clip placeholderapi - 2.10.9 + 2.10.10 provided diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3c559a6..1bbfdd8 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -5,11 +5,10 @@ plugin-prefix: '&eConditionalText &8| ' ## Plugin log level -# SEVERE - Errors -# WARNING - Warnings +# ERROR - Errors +# WARN - Warnings # INFO - Normal user information # FINE - Debug messages -# (...lower levels are not used) log-level: INFO # Configure the placeholder identifier. From c0441f0f20e8331785794e20c30b38b4f1d8575c Mon Sep 17 00:00:00 2001 From: qwz Date: Sun, 15 Aug 2021 15:28:39 +0200 Subject: [PATCH 10/10] 1.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a9a6349..b599db2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ space.devport.wertik.conditionaltext ConditionalTextPlaceholders - 1.3.8 + 1.4.0 ConditionalTextPlaceholders