Full module source: 1 implementation
Every implementation below is the complete module file, verbatim. Expand a client to read its code.
NicotineMiscsrc/client/java/nicotine/mod/mods/misc/Tab.javaJava · 31 lines · 940 B
SettingsListedPlayersFriendPrefix
| 1 | package nicotine.mod.mods.misc;
|
| 2 |
|
| 3 | import nicotine.events.CollectPlayerEntriesEvent;
|
| 4 | import nicotine.mod.Mod;
|
| 5 | import nicotine.mod.ModCategory;
|
| 6 | import nicotine.mod.option.DropDownOption;
|
| 7 | import nicotine.util.EventBus;
|
| 8 |
|
| 9 | import java.util.Arrays;
|
| 10 |
|
| 11 | public class Tab extends Mod {
|
| 12 |
|
| 13 | public static final DropDownOption listedPlayers = new DropDownOption("ListedPlayers", new String[]{"All", "Friends", "Default"});
|
| 14 | public static final DropDownOption friendPrefix = new DropDownOption("FriendPrefix", new String[]{"[F]", "[+]", "[❤]", "None"});
|
| 15 |
|
| 16 | public Tab() {
|
| 17 | super(ModCategory.Misc, "Tab");
|
| 18 | this.addOptions(Arrays.asList(listedPlayers, friendPrefix));
|
| 19 | }
|
| 20 |
|
| 21 | @Override
|
| 22 | protected void init() {
|
| 23 | EventBus.register(CollectPlayerEntriesEvent.class, event -> {
|
| 24 | if (!this.enabled || listedPlayers.value.equals("Default"))
|
| 25 | return true;
|
| 26 |
|
| 27 | return false;
|
| 28 | });
|
| 29 | }
|
| 30 | }
|
| 31 |
|
Utilities (3)
EventBus.javaJava · 35 lines · 1.0 KB
| 1 | package nicotine.util;
|
| 2 |
|
| 3 | import java.util.ArrayList;
|
| 4 | import java.util.List;
|
| 5 | import java.util.Map;
|
| 6 | import java.util.concurrent.ConcurrentHashMap;
|
| 7 |
|
| 8 | public class EventBus {
|
| 9 | private static final Map<Class<?>, List<EventListener<?>>> listeners = new ConcurrentHashMap<>();
|
| 10 |
|
| 11 | public static <T> void register(Class<T> eventType, EventListener<T> listener) {
|
| 12 | listeners.computeIfAbsent(eventType, k -> new ArrayList<>()).add(listener);
|
| 13 | }
|
| 14 |
|
| 15 | public static <T> boolean post(T event) {
|
| 16 | List<EventListener<?>> eventListeners = listeners.get(event.getClass());
|
| 17 | if (eventListeners != null) {
|
| 18 | for (EventListener<?> listener : eventListeners) {
|
| 19 | @SuppressWarnings("unchecked")
|
| 20 | EventListener<T> typedListener = (EventListener<T>) listener;
|
| 21 | if (!typedListener.onEvent(event)) {
|
| 22 | return false;
|
| 23 | }
|
| 24 | }
|
| 25 | }
|
| 26 | return true;
|
| 27 | }
|
| 28 |
|
| 29 | @FunctionalInterface
|
| 30 | public interface EventListener<T> {
|
| 31 | boolean onEvent(T event);
|
| 32 | }
|
| 33 | }
|
| 34 |
|
| 35 |
|
DropDownOption.javaJava · 16 lines · 307 B
| 1 | package nicotine.mod.option;
|
| 2 |
|
| 3 | public class DropDownOption extends ModOption {
|
| 4 | public String[] modes;
|
| 5 | public String value;
|
| 6 |
|
| 7 | public DropDownOption(String name, String[] modes) {
|
| 8 | super(name);
|
| 9 |
|
| 10 | this.modes = modes;
|
| 11 | this.value = modes[0];
|
| 12 | }
|
| 13 |
|
| 14 | public void select() {};
|
| 15 | }
|
| 16 |
|
ModCategory.javaJava · 6 lines · 108 B
| 1 | package nicotine.mod;
|
| 2 |
|
| 3 | public enum ModCategory {
|
| 4 | Render, Player, Movement, Combat, Misc, HUD, General
|
| 5 | }
|
| 6 |
|