Skip to content

Commit c6bad3f

Browse files
committed
Implement Sign menus
1 parent ce385a9 commit c6bad3f

24 files changed

Lines changed: 312 additions & 370 deletions

Plugin/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@
9292
<scope>provided</scope>
9393
</dependency>
9494

95+
<dependency>
96+
<groupId>com.github.retrooper</groupId>
97+
<artifactId>packetevents-spigot</artifactId>
98+
<version>2.12.1</version>
99+
<scope>provided</scope>
100+
</dependency>
101+
95102
<dependency>
96103
<groupId>org.mongodb</groupId>
97104
<artifactId>mongodb-driver-sync</artifactId>

Plugin/src/main/java/dev/lrxh/neptune/Neptune.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.lrxh.neptune;
22

3+
import com.github.retrooper.packetevents.PacketEvents;
4+
import com.github.retrooper.packetevents.event.PacketListenerPriority;
35
import com.jonahseguin.drink.CommandService;
46
import com.jonahseguin.drink.Drink;
57
import com.jonahseguin.drink.annotation.Text;
@@ -20,7 +22,6 @@
2022
import dev.lrxh.neptune.feature.divisions.DivisionService;
2123
import dev.lrxh.neptune.feature.hotbar.HotbarService;
2224
import dev.lrxh.neptune.feature.hotbar.listener.ItemListener;
23-
import dev.lrxh.neptune.feature.itembrowser.ItemBrowserListener;
2425
import dev.lrxh.neptune.feature.itembrowser.ItemBrowserService;
2526
import dev.lrxh.neptune.feature.leaderboard.LeaderboardService;
2627
import dev.lrxh.neptune.feature.leaderboard.command.LeaderboardCommand;
@@ -64,6 +65,7 @@
6465
import dev.lrxh.neptune.utils.ServerUtils;
6566
import dev.lrxh.neptune.utils.menu.MenuListener;
6667
import dev.lrxh.neptune.utils.menu.MenuRunnable;
68+
import dev.lrxh.neptune.utils.sign.SignInputListener;
6769
import dev.lrxh.neptune.utils.tasks.TaskScheduler;
6870
import fr.mrmicky.fastboard.FastManager;
6971
import lombok.Getter;
@@ -173,9 +175,10 @@ private void registerListeners() {
173175
new ArenaEditorChatListener(),
174176
new KitEditorChatListener(),
175177
new KitEditorListener(),
176-
new CustomKitListener(),
177-
new ItemBrowserListener())
178+
new CustomKitListener())
178179
.forEach(listener -> getServer().getPluginManager().registerEvents(listener, this));
180+
181+
PacketEvents.getAPI().getEventManager().registerListener(new SignInputListener(), PacketListenerPriority.NORMAL);
179182
}
180183

181184
private void loadExtensions() {

Plugin/src/main/java/dev/lrxh/neptune/feature/customkit/CustomKitService.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ public class CustomKitService {
99
public static int MAX_KITS = 5;
1010

1111
private final Map<UUID, List<CustomKit>> kits = new ConcurrentHashMap<>();
12-
private final Map<UUID, Input> inputType = new ConcurrentHashMap<>();
13-
private final Map<UUID, CustomKit> inputKit = new ConcurrentHashMap<>();
14-
15-
public enum Input {CREATE, HEALTH}
1612

1713
public static CustomKitService get() {
1814
if (instance == null) instance = new CustomKitService();
@@ -56,22 +52,4 @@ public void load(UUID uuid, List<String> data) {
5652
}
5753
kits.put(uuid, list);
5854
}
59-
60-
public void await(UUID uuid, Input type, CustomKit kit) {
61-
inputType.put(uuid, type);
62-
if (kit != null) inputKit.put(uuid, kit);
63-
}
64-
65-
public Input inputType(UUID uuid) {
66-
return inputType.get(uuid);
67-
}
68-
69-
public CustomKit inputKit(UUID uuid) {
70-
return inputKit.get(uuid);
71-
}
72-
73-
public void clearInput(UUID uuid) {
74-
inputType.remove(uuid);
75-
inputKit.remove(uuid);
76-
}
7755
}
Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,14 @@
11
package dev.lrxh.neptune.feature.customkit.listener;
22

3-
import dev.lrxh.neptune.API;
4-
import dev.lrxh.neptune.configs.impl.MessagesLocale;
5-
import dev.lrxh.neptune.feature.customkit.CustomKit;
6-
import dev.lrxh.neptune.feature.customkit.CustomKitService;
7-
import dev.lrxh.neptune.feature.customkit.menu.CustomKitManageMenu;
83
import dev.lrxh.neptune.feature.customkit.queue.CustomKitQueueService;
9-
import dev.lrxh.neptune.profile.impl.Profile;
10-
import io.papermc.paper.event.player.AsyncChatEvent;
11-
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
12-
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
13-
import org.bukkit.entity.Player;
144
import org.bukkit.event.EventHandler;
155
import org.bukkit.event.Listener;
166
import org.bukkit.event.player.PlayerQuitEvent;
177

188
public class CustomKitListener implements Listener {
199

20-
@EventHandler
21-
public void onChat(AsyncChatEvent event) {
22-
Player player = event.getPlayer();
23-
CustomKitService service = CustomKitService.get();
24-
CustomKitService.Input input = service.inputType(player.getUniqueId());
25-
if (input == null) return;
26-
27-
event.setCancelled(true);
28-
String message = PlainTextComponentSerializer.plainText().serialize(event.message()).trim();
29-
CustomKit kit = service.inputKit(player.getUniqueId());
30-
service.clearInput(player.getUniqueId());
31-
32-
if (message.equalsIgnoreCase("cancel")) {
33-
MessagesLocale.CUSTOM_KIT_CANCELLED.send(player.getUniqueId());
34-
return;
35-
}
36-
37-
switch (input) {
38-
case CREATE -> {
39-
CustomKit created = service.create(player.getUniqueId(), message);
40-
if (created == null) {
41-
MessagesLocale.CUSTOM_KIT_CREATE_FAIL.send(player.getUniqueId());
42-
return;
43-
}
44-
Profile profile = API.getProfile(player);
45-
if (profile != null) Profile.save(profile);
46-
MessagesLocale.CUSTOM_KIT_CREATED.send(player.getUniqueId(),
47-
Placeholder.parsed("kit", created.getDisplayName()));
48-
new CustomKitManageMenu(created).open(player);
49-
}
50-
case HEALTH -> {
51-
if (kit == null) return;
52-
try {
53-
double health = Double.parseDouble(message);
54-
if (health < 1 || health > 40) {
55-
MessagesLocale.CUSTOM_KIT_HEALTH_RANGE.send(player.getUniqueId());
56-
return;
57-
}
58-
kit.setHealth(health);
59-
Profile profile = API.getProfile(player);
60-
if (profile != null) Profile.save(profile);
61-
MessagesLocale.CUSTOM_KIT_HEALTH_SET.send(player.getUniqueId(),
62-
Placeholder.unparsed("health", String.valueOf(health)));
63-
new CustomKitManageMenu(kit).open(player);
64-
} catch (NumberFormatException e) {
65-
MessagesLocale.CUSTOM_KIT_HEALTH_INVALID.send(player.getUniqueId());
66-
}
67-
}
68-
}
69-
}
70-
7110
@EventHandler
7211
public void onQuit(PlayerQuitEvent event) {
73-
CustomKitService.get().clearInput(event.getPlayer().getUniqueId());
7412
CustomKitQueueService.get().unhost(event.getPlayer().getUniqueId());
7513
}
7614
}

Plugin/src/main/java/dev/lrxh/neptune/feature/customkit/menu/CustomKitManageMenu.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import dev.lrxh.neptune.utils.menu.Filter;
1313
import dev.lrxh.neptune.utils.menu.Menu;
1414
import dev.lrxh.neptune.utils.menu.impl.ReturnButton;
15+
import dev.lrxh.neptune.utils.sign.SignInputMenu;
1516
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
1617
import org.bukkit.entity.Player;
1718
import org.bukkit.event.inventory.ClickType;
@@ -80,9 +81,24 @@ public ItemStack getItemStack(Player p) {
8081

8182
@Override
8283
public void onClick(ClickType type, Player p) {
83-
CustomKitService.get().await(p.getUniqueId(), CustomKitService.Input.HEALTH, kit);
8484
p.closeInventory();
85-
MessagesLocale.CUSTOM_KIT_HEALTH_PROMPT.send(p.getUniqueId());
85+
SignInputMenu.open(p, "", "Enter max health (1-40)", input -> {
86+
try {
87+
double health = Double.parseDouble(input);
88+
if (health < 1 || health > 40) {
89+
MessagesLocale.CUSTOM_KIT_HEALTH_RANGE.send(p.getUniqueId());
90+
return;
91+
}
92+
kit.setHealth(health);
93+
Profile profile = API.getProfile(p);
94+
if (profile != null) Profile.save(profile);
95+
MessagesLocale.CUSTOM_KIT_HEALTH_SET.send(p.getUniqueId(),
96+
Placeholder.unparsed("health", String.valueOf(health)));
97+
new CustomKitManageMenu(kit).open(p);
98+
} catch (NumberFormatException e) {
99+
MessagesLocale.CUSTOM_KIT_HEALTH_INVALID.send(p.getUniqueId());
100+
}
101+
});
86102
}
87103
});
88104

Plugin/src/main/java/dev/lrxh/neptune/feature/customkit/menu/CustomKitsMenu.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package dev.lrxh.neptune.feature.customkit.menu;
22

3+
import dev.lrxh.neptune.API;
34
import dev.lrxh.neptune.configs.impl.MenusLocale;
45
import dev.lrxh.neptune.configs.impl.MessagesLocale;
56
import dev.lrxh.neptune.feature.customkit.CustomKit;
67
import dev.lrxh.neptune.feature.customkit.CustomKitService;
78
import dev.lrxh.neptune.feature.customkit.queue.CustomKitQueueService;
9+
import dev.lrxh.neptune.profile.impl.Profile;
810
import dev.lrxh.neptune.utils.ItemBuilder;
911
import dev.lrxh.neptune.utils.menu.Button;
1012
import dev.lrxh.neptune.utils.menu.Filter;
1113
import dev.lrxh.neptune.utils.menu.Menu;
14+
import dev.lrxh.neptune.utils.sign.SignInputMenu;
1215
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
1316
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
1417
import org.bukkit.entity.Player;
@@ -82,9 +85,19 @@ public void onClick(ClickType type, Player p) {
8285
MessagesLocale.CUSTOM_KIT_MAX.send(p.getUniqueId());
8386
return;
8487
}
85-
CustomKitService.get().await(p.getUniqueId(), CustomKitService.Input.CREATE, null);
8688
p.closeInventory();
87-
MessagesLocale.CUSTOM_KIT_CREATE_PROMPT.send(p.getUniqueId());
89+
SignInputMenu.open(p, "", "Enter kit name", input -> {
90+
CustomKit created = CustomKitService.get().create(p.getUniqueId(), input);
91+
if (created == null) {
92+
MessagesLocale.CUSTOM_KIT_CREATE_FAIL.send(p.getUniqueId());
93+
return;
94+
}
95+
Profile profile = API.getProfile(p);
96+
if (profile != null) Profile.save(profile);
97+
MessagesLocale.CUSTOM_KIT_CREATED.send(p.getUniqueId(),
98+
Placeholder.parsed("kit", created.getDisplayName()));
99+
new CustomKitManageMenu(created).open(p);
100+
});
88101
}
89102
});
90103
}

Plugin/src/main/java/dev/lrxh/neptune/feature/itembrowser/ItemBrowserListener.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

Plugin/src/main/java/dev/lrxh/neptune/feature/itembrowser/ItemBrowserService.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.lrxh.neptune.feature.itembrowser;
22

33
import dev.lrxh.api.features.IItemBrowserService;
4+
import dev.lrxh.neptune.utils.sign.SignInputMenu;
45
import org.bukkit.Material;
56
import org.bukkit.Registry;
67
import org.bukkit.block.BlockType;
@@ -15,7 +16,6 @@ public class ItemBrowserService implements IItemBrowserService {
1516

1617
private final Map<String, List<Material>> sectionMaterials = new HashMap<>();
1718
private final Map<String, List<Material>> computed = new HashMap<>();
18-
private final Map<UUID, SearchSession> searchSessions = new HashMap<>();
1919

2020
public static ItemBrowserService get() {
2121
if (instance == null) {
@@ -90,12 +90,8 @@ public void openBrowser(Player player, String section, Consumer<Material> itemCo
9090

9191
public void requestSearch(Player player, String section, Consumer<Material> itemConsumer, Runnable returnConsumer) {
9292
player.closeInventory();
93-
player.sendMessage("§ePlease type your search in chat.");
94-
searchSessions.put(player.getUniqueId(), new SearchSession(section, itemConsumer, returnConsumer));
95-
}
96-
97-
public SearchSession removeSearchSession(UUID uuid) {
98-
return searchSessions.remove(uuid);
93+
SignInputMenu.open(player, "", "Enter search", input ->
94+
openBrowser(player, section, itemConsumer, input, returnConsumer));
9995
}
10096

10197
@Override
@@ -109,7 +105,4 @@ public void registerSection(String section, List<String> materialNames) {
109105
}
110106
sectionMaterials.put(section, materials);
111107
}
112-
113-
record SearchSession(String section, Consumer<Material> itemConsumer, Runnable returnConsumer) {
114-
}
115108
}

0 commit comments

Comments
 (0)