mirror of
				https://github.com/PlaceholderAPI/PlaceholderAPI
				synced 2025-10-30 18:03:43 +01:00 
			
		
		
		
	updated cloud expansion list to be sorted via a configuration option of values [name, author, latest]. closes #363
This commit is contained in:
		| @@ -7,6 +7,7 @@ import com.google.common.collect.Sets; | |||||||
| import com.google.common.primitives.Ints; | import com.google.common.primitives.Ints; | ||||||
| import me.clip.placeholderapi.PlaceholderAPIPlugin; | import me.clip.placeholderapi.PlaceholderAPIPlugin; | ||||||
| import me.clip.placeholderapi.commands.PlaceholderCommand; | import me.clip.placeholderapi.commands.PlaceholderCommand; | ||||||
|  | import me.clip.placeholderapi.configuration.ExpansionSort; | ||||||
| import me.clip.placeholderapi.expansion.PlaceholderExpansion; | import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||||||
| import me.clip.placeholderapi.expansion.cloud.CloudExpansion; | import me.clip.placeholderapi.expansion.cloud.CloudExpansion; | ||||||
| import me.clip.placeholderapi.util.Format; | import me.clip.placeholderapi.util.Format; | ||||||
| @@ -22,7 +23,6 @@ import java.text.SimpleDateFormat; | |||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Collection; | import java.util.Collection; | ||||||
| import java.util.Collections; | import java.util.Collections; | ||||||
| import java.util.Comparator; |  | ||||||
| import java.util.LinkedHashMap; | import java.util.LinkedHashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| @@ -85,7 +85,7 @@ public final class CommandECloudExpansionList extends PlaceholderCommand | |||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		expansions.sort(Comparator.comparing(CloudExpansion::getLastUpdate).reversed()); | 		expansions.sort(plugin.getPlaceholderAPIConfig().getExpansionSort().orElse(ExpansionSort.LATEST)); | ||||||
|  |  | ||||||
| 		if (!(sender instanceof Player) && params.size() < 2) | 		if (!(sender instanceof Player) && params.size() < 2) | ||||||
| 		{ | 		{ | ||||||
|   | |||||||
| @@ -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); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -23,6 +23,8 @@ package me.clip.placeholderapi.configuration; | |||||||
| import me.clip.placeholderapi.PlaceholderAPIPlugin; | import me.clip.placeholderapi.PlaceholderAPIPlugin; | ||||||
| import org.jetbrains.annotations.NotNull; | import org.jetbrains.annotations.NotNull; | ||||||
|  |  | ||||||
|  | import java.util.Optional; | ||||||
|  |  | ||||||
| public final class PlaceholderAPIConfig | 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 | 	@NotNull | ||||||
| 	public String dateFormat() | 	public String dateFormat() | ||||||
| 	{ | 	{ | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ | |||||||
| # Download placeholders: /papi ecloud | # Download placeholders: /papi ecloud | ||||||
| check_updates: true | check_updates: true | ||||||
| cloud_enabled: true | cloud_enabled: true | ||||||
|  | cloud_sorting: "name" | ||||||
| cloud_allow_unverified_expansions: false | cloud_allow_unverified_expansions: false | ||||||
| boolean: | boolean: | ||||||
|   'true': 'yes' |   'true': 'yes' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user