-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminPageRegistry.java
More file actions
171 lines (154 loc) · 4.76 KB
/
AdminPageRegistry.java
File metadata and controls
171 lines (154 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.hyperfactions.gui.admin;
import com.hyperfactions.gui.GuiManager;
import com.hyperfactions.gui.shared.NavEntry;
import com.hyperfactions.integration.PermissionManager;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.entity.entities.player.pages.InteractiveCustomUIPage;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Central registry for all HyperFactions Admin GUI pages.
* Follows the FactionPageRegistry pattern for admin-specific navigation.
*/
public final class AdminPageRegistry {
private static final AdminPageRegistry INSTANCE = new AdminPageRegistry();
private final Map<String, Entry> entries = new ConcurrentHashMap<>();
private final List<Entry> orderedEntries = new ArrayList<>();
private AdminPageRegistry() {
}
/** Returns the instance. */
public static AdminPageRegistry getInstance() {
return INSTANCE;
}
/**
* Represents a registered admin GUI page entry.
*
* @param id Unique page identifier (e.g., "dashboard", "zones")
* @param displayName UI display name (e.g., "Dashboard", "Zones")
* @param permission Required permission node (null for no permission required beyond admin)
* @param guiSupplier Function to create the page instance
* @param showsInNavBar Whether this page appears in the navigation bar
* @param order Display order in navigation (lower = first)
*/
public record Entry(
@NotNull String id,
@NotNull String displayName,
@Nullable String permission,
@NotNull PageSupplier guiSupplier,
boolean showsInNavBar,
int order
) implements NavEntry, Comparable<Entry> {
/** Compare To. */
@Override
public int compareTo(@NotNull Entry other) {
return Integer.compare(this.order, other.order);
}
}
/**
* Functional interface for creating admin page instances.
*/
@FunctionalInterface
public interface PageSupplier {
/**
* Creates a new page instance.
*
* @param player The player entity
* @param ref Entity reference
* @param store Entity store
* @param playerRef Player reference component
* @param guiManager The GUI manager
* @return The created page, or null if page cannot be created
*/
@Nullable InteractiveCustomUIPage<?> create(
Player player,
Ref<EntityStore> ref,
Store<EntityStore> store,
PlayerRef playerRef,
GuiManager guiManager
);
}
/**
* Registers a page entry.
*
* @param entry The entry to register
*/
public void registerEntry(@NotNull Entry entry) {
entries.put(entry.id(), entry);
orderedEntries.add(entry);
orderedEntries.sort(Entry::compareTo);
}
/**
* Gets an entry by ID.
*
* @param id The page ID
* @return The entry, or null if not found
*/
@Nullable
public Entry getEntry(@NotNull String id) {
return entries.get(id);
}
/**
* Gets all registered entries in display order.
*
* @return Unmodifiable list of entries
*/
@NotNull
public List<Entry> getEntries() {
return Collections.unmodifiableList(orderedEntries);
}
/**
* Gets entries that should appear in the navigation bar.
*
* @return List of nav bar entries in display order
*/
@NotNull
public List<Entry> getNavBarEntries() {
return orderedEntries.stream()
.filter(Entry::showsInNavBar)
.toList();
}
/**
* Gets entries accessible to a player (permission check).
*
* @param playerRef The player to check
* @return List of accessible entries
*/
@NotNull
public List<Entry> getAccessibleEntries(@NotNull PlayerRef playerRef) {
return orderedEntries.stream()
.filter(entry -> {
// Check permission
if (entry.permission() != null) {
return PermissionManager.get().hasPermission(playerRef.getUuid(), entry.permission());
}
return true;
})
.toList();
}
/**
* Gets nav bar entries accessible to a player.
*
* @param playerRef The player to check
* @return List of accessible nav bar entries
*/
@NotNull
public List<Entry> getAccessibleNavBarEntries(@NotNull PlayerRef playerRef) {
return getAccessibleEntries(playerRef).stream()
.filter(Entry::showsInNavBar)
.toList();
}
/**
* Clears all registered entries.
* Used for testing or reloading.
*/
public void clear() {
entries.clear();
orderedEntries.clear();
}
}