Sort action prompt arrays

This commit is contained in:
PikaMug 2024-08-19 03:17:53 -04:00
parent 0ad1d161cc
commit 9ae2bc57da
3 changed files with 27 additions and 15 deletions

View File

@ -42,6 +42,8 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -842,14 +844,18 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
final StringBuilder mobs = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"); final StringBuilder mobs = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
final EntityType[] mobArr = EntityType.values(); final List<EntityType> mobArr = new LinkedList<>(Arrays.asList(EntityType.values()));
for (int i = 0; i < mobArr.length; i++) { final List<EntityType> toRemove = new LinkedList<>();
final EntityType type = mobArr[i]; for (final EntityType type : mobArr) {
if (!type.isAlive()) { if (!type.isAlive() || type.name().equals("PLAYER")) {
continue; toRemove.add(type);
} }
mobs.append(ChatColor.AQUA).append(BukkitMiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name())); }
if (i < (mobArr.length - 1)) { mobArr.removeAll(toRemove);
mobArr.sort(Comparator.comparing(EntityType::name));
for (int i = 0; i < mobArr.size(); i++) {
mobs.append(ChatColor.AQUA).append(BukkitMiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name()));
if (i < (mobArr.size() - 1)) {
mobs.append(ChatColor.GRAY).append(", "); mobs.append(ChatColor.GRAY).append(", ");
} }
} }

View File

@ -30,6 +30,8 @@ import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -340,10 +342,11 @@ public class ActionEffectPrompt extends ActionsEditorNumericPrompt {
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
final StringBuilder effects = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"); final StringBuilder effects = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
final Effect[] worldArr = Effect.values(); final List<Effect> effArr = new LinkedList<>(Arrays.asList(Effect.values()));
for (int i = 0; i < worldArr.length; i++) { effArr.sort(Comparator.comparing(Effect::name));
effects.append(ChatColor.AQUA).append(BukkitMiscUtil.snakeCaseToUpperCamelCase(worldArr[i].name())); for (int i = 0; i < effArr.size(); i++) {
if (i < (worldArr.length - 1)) { effects.append(ChatColor.AQUA).append(BukkitMiscUtil.snakeCaseToUpperCamelCase(effArr.get(i).name()));
if (i < (effArr.size() - 1)) {
effects.append(ChatColor.GRAY).append(", "); effects.append(ChatColor.GRAY).append(", ");
} }
} }

View File

@ -35,6 +35,7 @@ import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -637,10 +638,12 @@ public class ActionPlayerPrompt extends ActionsEditorNumericPrompt {
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
final StringBuilder potions = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"); final StringBuilder potions = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
final PotionEffectType[] potionArr = PotionEffectType.values(); final List<PotionEffectType> effArr = new LinkedList<>(Arrays.asList(PotionEffectType.values()));
for (int i = 0; i < potionArr.length; i++) { effArr.sort(Comparator.comparing(PotionEffectType::getName));
potions.append(ChatColor.AQUA).append(potionArr[i].getName()); for (int i = 0; i < effArr.size(); i++) {
if (i < (potionArr.length - 1)) { final String name = effArr.get(i).getName().replaceFirst("minecraft:", "").toUpperCase();
potions.append(ChatColor.AQUA).append(name);
if (i < (effArr.size() - 1)) {
potions.append(ChatColor.GRAY).append(", "); potions.append(ChatColor.GRAY).append(", ");
} }
} }