From 9ae2bc57dafeece413c3a16d98ceca27b94b9c82 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Mon, 19 Aug 2024 03:17:53 -0400 Subject: [PATCH] Sort action prompt arrays --- .../convo/actions/main/ActionMainPrompt.java | 20 ++++++++++++------- .../actions/tasks/ActionEffectPrompt.java | 11 ++++++---- .../actions/tasks/ActionPlayerPrompt.java | 11 ++++++---- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/me/pikamug/quests/convo/actions/main/ActionMainPrompt.java b/core/src/main/java/me/pikamug/quests/convo/actions/main/ActionMainPrompt.java index 7c65ec695..aa1dd858b 100644 --- a/core/src/main/java/me/pikamug/quests/convo/actions/main/ActionMainPrompt.java +++ b/core/src/main/java/me/pikamug/quests/convo/actions/main/ActionMainPrompt.java @@ -42,6 +42,8 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; +import java.util.Comparator; import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -842,14 +844,18 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt { plugin.getServer().getPluginManager().callEvent(event); final StringBuilder mobs = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"); - final EntityType[] mobArr = EntityType.values(); - for (int i = 0; i < mobArr.length; i++) { - final EntityType type = mobArr[i]; - if (!type.isAlive()) { - continue; + final List mobArr = new LinkedList<>(Arrays.asList(EntityType.values())); + final List toRemove = new LinkedList<>(); + for (final EntityType type : mobArr) { + if (!type.isAlive() || type.name().equals("PLAYER")) { + 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(", "); } } diff --git a/core/src/main/java/me/pikamug/quests/convo/actions/tasks/ActionEffectPrompt.java b/core/src/main/java/me/pikamug/quests/convo/actions/tasks/ActionEffectPrompt.java index 71eb75a59..de14336c0 100644 --- a/core/src/main/java/me/pikamug/quests/convo/actions/tasks/ActionEffectPrompt.java +++ b/core/src/main/java/me/pikamug/quests/convo/actions/tasks/ActionEffectPrompt.java @@ -30,6 +30,8 @@ import org.bukkit.conversations.Prompt; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; +import java.util.Comparator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -340,10 +342,11 @@ public class ActionEffectPrompt extends ActionsEditorNumericPrompt { plugin.getServer().getPluginManager().callEvent(event); final StringBuilder effects = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"); - final Effect[] worldArr = Effect.values(); - for (int i = 0; i < worldArr.length; i++) { - effects.append(ChatColor.AQUA).append(BukkitMiscUtil.snakeCaseToUpperCamelCase(worldArr[i].name())); - if (i < (worldArr.length - 1)) { + final List effArr = new LinkedList<>(Arrays.asList(Effect.values())); + effArr.sort(Comparator.comparing(Effect::name)); + for (int i = 0; i < effArr.size(); i++) { + effects.append(ChatColor.AQUA).append(BukkitMiscUtil.snakeCaseToUpperCamelCase(effArr.get(i).name())); + if (i < (effArr.size() - 1)) { effects.append(ChatColor.GRAY).append(", "); } } diff --git a/core/src/main/java/me/pikamug/quests/convo/actions/tasks/ActionPlayerPrompt.java b/core/src/main/java/me/pikamug/quests/convo/actions/tasks/ActionPlayerPrompt.java index 4c57bd6be..0283020fd 100644 --- a/core/src/main/java/me/pikamug/quests/convo/actions/tasks/ActionPlayerPrompt.java +++ b/core/src/main/java/me/pikamug/quests/convo/actions/tasks/ActionPlayerPrompt.java @@ -35,6 +35,7 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import java.util.Arrays; +import java.util.Comparator; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -637,10 +638,12 @@ public class ActionPlayerPrompt extends ActionsEditorNumericPrompt { plugin.getServer().getPluginManager().callEvent(event); final StringBuilder potions = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"); - final PotionEffectType[] potionArr = PotionEffectType.values(); - for (int i = 0; i < potionArr.length; i++) { - potions.append(ChatColor.AQUA).append(potionArr[i].getName()); - if (i < (potionArr.length - 1)) { + final List effArr = new LinkedList<>(Arrays.asList(PotionEffectType.values())); + effArr.sort(Comparator.comparing(PotionEffectType::getName)); + for (int i = 0; i < effArr.size(); i++) { + 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(", "); } }