updated cloud expansion list to be sorted via a configuration option of values [name, author, latest]. closes #363

This commit is contained in:
Sxtanna 2020-07-26 13:39:33 -04:00
parent a7a4b46821
commit 65f04ba70e
4 changed files with 52 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import com.google.common.collect.Sets;
import com.google.common.primitives.Ints;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.commands.PlaceholderCommand;
import me.clip.placeholderapi.configuration.ExpansionSort;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
import me.clip.placeholderapi.util.Format;
@ -22,7 +23,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -85,7 +85,7 @@ public final class CommandECloudExpansionList extends PlaceholderCommand
return;
}
expansions.sort(Comparator.comparing(CloudExpansion::getLastUpdate).reversed());
expansions.sort(plugin.getPlaceholderAPIConfig().getExpansionSort().orElse(ExpansionSort.LATEST));
if (!(sender instanceof Player) && params.size() < 2)
{

View File

@ -0,0 +1,31 @@
package me.clip.placeholderapi.configuration;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
import org.jetbrains.annotations.NotNull;
import java.util.Comparator;
public enum ExpansionSort implements Comparator<CloudExpansion>
{
NAME(Comparator.comparing(CloudExpansion::getName)),
AUTHOR(Comparator.comparing(CloudExpansion::getAuthor)),
LATEST(Comparator.comparing(CloudExpansion::getLastUpdate).reversed());
@NotNull
private final Comparator<CloudExpansion> comparator;
ExpansionSort(@NotNull final Comparator<CloudExpansion> comparator)
{
this.comparator = comparator;
}
@Override
public final int compare(final CloudExpansion expansion1, final CloudExpansion expansion2)
{
return comparator.compare(expansion1, expansion2);
}
}

View File

@ -23,6 +23,8 @@ package me.clip.placeholderapi.configuration;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
public final class PlaceholderAPIConfig
{
@ -64,6 +66,22 @@ public final class PlaceholderAPIConfig
}
public Optional<ExpansionSort> getExpansionSort()
{
final String option = plugin.getConfig().getString("cloud_sorting", ExpansionSort.LATEST.name());
try
{
//noinspection ConstantConditions (bad spigot annotation)
return Optional.of(ExpansionSort.valueOf(option.toUpperCase()));
}
catch (final IllegalArgumentException ignored)
{
return Optional.empty();
}
}
@NotNull
public String dateFormat()
{

View File

@ -10,6 +10,7 @@
# Download placeholders: /papi ecloud
check_updates: true
cloud_enabled: true
cloud_sorting: "name"
cloud_allow_unverified_expansions: false
boolean:
'true': 'yes'