Skip to content

Commit

Permalink
Merge pull request #4 from Wertik/dev
Browse files Browse the repository at this point in the history
1.4.0
  • Loading branch information
Wertik authored Aug 15, 2021
2 parents 83d53a1 + c0441f0 commit 8c01ac8
Show file tree
Hide file tree
Showing 19 changed files with 216 additions and 117 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. \
Expand All @@ -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:
Expand Down Expand Up @@ -99,12 +99,12 @@ But first, load the new settings in with a quick `/ct reload`.

Then just use the placeholder ``%conditionaltext_<setting>%`` 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%'
Expand All @@ -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_<setting>_(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_<setting>_(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)
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>space.devport.wertik.conditionaltext</groupId>
<artifactId>ConditionalTextPlaceholders</artifactId>
<version>1.3.8</version>
<version>1.4.0</version>

<name>ConditionalTextPlaceholders</name>

Expand Down Expand Up @@ -44,8 +44,8 @@
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>space.devport.utils</pattern>
<shadedPattern>${project.groupId}.utils</shadedPattern>
<pattern>space.devport.dock</pattern>
<shadedPattern>${project.groupId}.dock</shadedPattern>
</relocation>
</relocations>
</configuration>
Expand All @@ -68,7 +68,7 @@
</repository>
<repository>
<id>devport</id>
<url>https://nexus.pvpcraft.cz/repository/devport/</url>
<url>https://nexus.devport.space/repository/devport-public/</url>
</repository>
<repository>
<id>placeholderapi</id>
Expand All @@ -80,31 +80,31 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
<version>21.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>space.devport.utils</groupId>
<artifactId>devportutils</artifactId>
<groupId>space.devport.dock</groupId>
<artifactId>dock</artifactId>
<version>4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.9</version>
<version>2.10.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

Expand All @@ -15,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)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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.ListSubCommand;
import space.devport.wertik.conditionaltext.commands.subcommands.TrySubCommand;

public class ConditionalTextCommand extends MainCommand {
Expand All @@ -19,6 +20,7 @@ public ConditionalTextCommand(ConditionalTextPlugin plugin) {
return CommandResult.SUCCESS;
}));
withSubCommand(new TrySubCommand(plugin));
withSubCommand(new ListSubCommand(plugin));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Setting> 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<String, Setting> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,22 +33,27 @@ 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;
}
}

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;
}
}
Loading

0 comments on commit 8c01ac8

Please sign in to comment.