Skip to content

Commit 3b60892

Browse files
Add page change buttons to help command
1 parent 5c2343e commit 3b60892

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/main/java/parallelmc/parallelutils/commands/ParallelHelpCommand.java

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package parallelmc.parallelutils.commands;
22

3-
import org.bukkit.ChatColor;
3+
import net.md_5.bungee.api.ChatColor;
4+
import net.md_5.bungee.api.chat.ClickEvent;
5+
import net.md_5.bungee.api.chat.ComponentBuilder;
6+
import net.md_5.bungee.api.chat.TextComponent;
47
import org.bukkit.command.Command;
58
import org.bukkit.command.CommandSender;
69
import org.jetbrains.annotations.NotNull;
7-
import parallelmc.parallelutils.commands.ParallelCommand;
10+
import org.w3c.dom.Text;
811
import parallelmc.parallelutils.commands.permissions.ParallelPermission;
912

1013
import java.util.ArrayList;
1114
import java.util.List;
1215

16+
// TODO: Make this dynamic
1317
/**
1418
* A command to display usages of other commands
1519
* Usage: /pu help <page>
@@ -55,15 +59,43 @@ public boolean execute(@NotNull CommandSender sender, @NotNull Command command,
5559
end = HELP_MESSAGES.length;
5660
}
5761

58-
StringBuilder sb = new StringBuilder();
59-
sb.append(ChatColor.YELLOW).append("--------- ").append(ChatColor.WHITE).append("Help: Index (")
60-
.append(page).append("/").append(numPages).append(")")
61-
.append(ChatColor.YELLOW).append(" --------------------\n").append(ChatColor.RESET);
62+
// TODO: Is there a better way to do this? It's so messy
63+
ComponentBuilder componentBuilder = new ComponentBuilder();
64+
65+
TextComponent smallYellow = new TextComponent("--------- ");
66+
smallYellow.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
67+
68+
TextComponent largeYellow = new TextComponent(" --------------------\n");
69+
largeYellow.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
70+
71+
componentBuilder.append(smallYellow, ComponentBuilder.FormatRetention.NONE)
72+
.append("Help: Index (", ComponentBuilder.FormatRetention.NONE)
73+
.append("" + page).append("/").append("" + numPages).append(")")
74+
.append(largeYellow, ComponentBuilder.FormatRetention.NONE);
6275
for (int i=start; i<end; i++) {
63-
sb.append(ChatColor.GREEN).append(HELP_MESSAGES[i]).append("\n").append(ChatColor.RESET);
76+
TextComponent helpComponent = new TextComponent(HELP_MESSAGES[i]);
77+
helpComponent.setColor(net.md_5.bungee.api.ChatColor.GREEN);
78+
componentBuilder.append(helpComponent, ComponentBuilder.FormatRetention.NONE)
79+
.append("\n", ComponentBuilder.FormatRetention.NONE);
80+
}
81+
82+
if (page != 1) {
83+
TextComponent backComponent = new TextComponent("[Back] ");
84+
backComponent.setColor(net.md_5.bungee.api.ChatColor.AQUA);
85+
backComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/pu help " + (page-1)));
86+
componentBuilder.append(backComponent);
87+
}
88+
if (page != numPages) {
89+
TextComponent backComponent = new TextComponent(" [Forward]");
90+
backComponent.setColor(net.md_5.bungee.api.ChatColor.AQUA);
91+
backComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/pu help " + (page+1)));
92+
componentBuilder.append(backComponent);
93+
TextComponent resetLocColor = new TextComponent();
94+
resetLocColor.setColor(ChatColor.RESET);
95+
componentBuilder.append(resetLocColor, ComponentBuilder.FormatRetention.NONE);
6496
}
6597

66-
sender.sendMessage(sb.toString());
98+
sender.sendMessage(componentBuilder.create());
6799

68100
return true;
69101
}

src/main/java/parallelmc/parallelutils/modules/custommobs/commands/ParallelListSpawnersCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public boolean execute(@NotNull CommandSender sender, @NotNull Command command,
111111
componentBuilder.append(resetLocColor, ComponentBuilder.FormatRetention.NONE);
112112
}
113113

114-
sender.sendMessage(componentBuilder.create());
114+
sender.sendMessage(componentBuilder.create()); // TODO: Figure out how to do this without the deprecated method
115115

116116
return true;
117117
}

0 commit comments

Comments
 (0)