From 2ba2372bde0a25ae985bd7e808228af504883f4c Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 3 Mar 2026 21:56:17 -0500 Subject: [PATCH] Fix some Selection Handling for Abilities --- .../java/noppes/npcs/NoppesUtilServer.java | 8 ++-- .../gui/advanced/SubGuiAbilityLoad.java | 18 +++++--- .../gui/advanced/SubGuiAbilitySelect.java | 18 +++++--- .../gui/global/GuiNpcManageAbilities.java | 44 ++++++++++++++++--- 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 521c0cb02..53dbfb239 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -794,11 +794,10 @@ public class NoppesUtilServer { HashMap map = new HashMap(); AbilityController controller = AbilityController.Instance; if (controller != null) { - int index = 0; for (String name : controller.getAbilityNames()) { Ability ability = controller.getAbility(name); if (ability != null) { - map.put(ability.getName(), index++); + map.put(ability.getName(), ability.getAllowedBy().ordinal()); } } } @@ -809,11 +808,10 @@ public class NoppesUtilServer { HashMap map = new HashMap(); AbilityController controller = AbilityController.Instance; if (controller != null) { - int index = 0; for (String name : controller.getCustomAbilityNames()) { Ability ability = controller.getCustomAbility(name); - if (ability == null || !ability.getAllowedBy().allowsNpc()) continue; - map.put(name, index++); + if (ability == null) continue; + map.put(name, ability.getAllowedBy().ordinal()); } } sendScrollData(player, map, EnumScrollData.CUSTOM_ABILITIES); diff --git a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityLoad.java b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityLoad.java index dda5ee8e6..568f60883 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityLoad.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityLoad.java @@ -2,6 +2,7 @@ package noppes.npcs.client.gui.advanced; import kamkeel.npcs.controllers.AbilityController; import kamkeel.npcs.controllers.data.ability.Ability; +import kamkeel.npcs.controllers.data.ability.enums.UserType; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket; import kamkeel.npcs.network.packets.request.ability.CustomAbilityGetPacket; @@ -21,6 +22,7 @@ import noppes.npcs.constants.EnumScrollData; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Vector; /** @@ -98,14 +100,18 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL } private List getFilteredList() { - if (search.isEmpty()) { - return new ArrayList<>(rawData.keySet()); - } List list = new ArrayList<>(); - for (String name : rawData.keySet()) { - if (name.toLowerCase().contains(search.toLowerCase())) { - list.add(name); + for (Map.Entry entry : rawData.entrySet()) { + String name = entry.getKey(); + + // Only show NPC-valid abilities (NPC_ONLY or BOTH) + UserType ut = UserType.fromOrdinal(entry.getValue()); + if (!ut.allowsNpc()) continue; + + if (!search.isEmpty() && !name.toLowerCase().contains(search.toLowerCase())) { + continue; } + list.add(name); } return list; } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilitySelect.java b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilitySelect.java index 70faa9059..8cab092a2 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilitySelect.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilitySelect.java @@ -1,5 +1,6 @@ package noppes.npcs.client.gui.advanced; +import kamkeel.npcs.controllers.data.ability.enums.UserType; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket; import net.minecraft.client.gui.GuiButton; @@ -15,6 +16,7 @@ import noppes.npcs.constants.EnumScrollData; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Vector; /** @@ -93,14 +95,18 @@ public class SubGuiAbilitySelect extends SubGuiInterface implements ICustomScrol merged.putAll(builtInData); } - if (search.isEmpty()) { - return new ArrayList<>(merged.keySet()); - } List list = new ArrayList<>(); - for (String name : merged.keySet()) { - if (name.toLowerCase().contains(search.toLowerCase())) { - list.add(name); + for (Map.Entry entry : merged.entrySet()) { + String name = entry.getKey(); + + // Only show NPC-valid abilities (NPC_ONLY or BOTH) + UserType ut = UserType.fromOrdinal(entry.getValue()); + if (!ut.allowsNpc()) continue; + + if (!search.isEmpty() && !name.toLowerCase().contains(search.toLowerCase())) { + continue; } + list.add(name); } return list; } diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageAbilities.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageAbilities.java index cac2cccd5..5511eeb4f 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageAbilities.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageAbilities.java @@ -4,6 +4,7 @@ import kamkeel.npcs.controllers.AbilityController; import kamkeel.npcs.controllers.data.ability.Ability; import kamkeel.npcs.controllers.data.ability.AbilityVariant; import kamkeel.npcs.controllers.data.ability.data.ChainedAbility; +import kamkeel.npcs.controllers.data.ability.enums.UserType; import kamkeel.npcs.network.PacketClient; import java.util.UUID; @@ -48,6 +49,7 @@ import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Vector; /** @@ -72,6 +74,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface private static final int BTN_PREVIEW_PLAY = 91; private static final int BTN_PREVIEW_PAUSE = 92; private static final int BTN_PREVIEW_STOP = 93; + private static final int BTN_USER_TYPE_FILTER = 11; // ── TextField / Label IDs ───────────────────────────────────────────────── private static final int TF_SEARCH = 55; @@ -99,6 +102,11 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface private boolean showingChained = false; private boolean currentIsBuiltIn = false; + // ==================== USER TYPE FILTER ==================== + // 0 = Both, 1 = NPC Only, 2 = Player Only + private int userTypeFilter = 0; + private static final String[] USER_TYPE_FILTER_LABELS = {"gui.both", "gui.npcs", "gui.players"}; + // ==================== CHAINED DATA ==================== private HashMap chainedData = new HashMap<>(); private ChainedAbility selectedChain = null; @@ -176,6 +184,11 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface // Search bar addTextField(new GuiNpcTextField(TF_SEARCH, this, fontRendererObj, guiLeft + 220, guiTop + 192, 143, 20, search)); + // User type filter button (only for Custom and Built-in views) + if (!showingChained) { + addButton(new GuiNpcButton(BTN_USER_TYPE_FILTER, guiLeft + 368, guiTop + 192, 45, 20, USER_TYPE_FILTER_LABELS[userTypeFilter])); + } + // Check if we have something to preview if (showingChained) { if (selectedChain == null || selected == null || selectedChain.getEntries().isEmpty()) { @@ -213,14 +226,23 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface private List getSearchList() { HashMap data = getCurrentData(); - if (search.isEmpty()) { - return new ArrayList<>(data.keySet()); - } List list = new ArrayList<>(); - for (String name : data.keySet()) { - if (name.toLowerCase().contains(search.toLowerCase())) { - list.add(name); + for (Map.Entry entry : data.entrySet()) { + String name = entry.getKey(); + + // Apply search filter + if (!search.isEmpty() && !name.toLowerCase().contains(search.toLowerCase())) { + continue; } + + // Apply UserType filter (only for Custom and Built-in views) + if (!showingChained && userTypeFilter != 0) { + UserType ut = UserType.fromOrdinal(entry.getValue()); + if (userTypeFilter == 1 && !ut.allowsNpc()) continue; + if (userTypeFilter == 2 && !ut.allowsPlayer()) continue; + } + + list.add(name); } return list; } @@ -278,6 +300,16 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface int id = guibutton.id; + // User type filter: Both → NPC → Player → Both + if (id == BTN_USER_TYPE_FILTER) { + userTypeFilter = (userTypeFilter + 1) % 3; + if (scroll != null) { + scroll.setList(getSearchList()); + } + initGui(); + return; + } + // Toggle: Custom → Built-in → Chained → Custom if (id == BTN_TOGGLE_VIEW) { if (!showingBuiltIn && !showingChained) {