|
24 | 24 | import net.minecraft.commands.arguments.EntityArgument; |
25 | 25 | import net.minecraft.commands.arguments.GameProfileArgument; |
26 | 26 | import net.minecraft.nbt.StringTag; |
| 27 | +import net.minecraft.network.chat.ClickEvent; |
| 28 | +import net.minecraft.network.chat.ClickEvent.Action; |
27 | 29 | import net.minecraft.network.chat.Component; |
| 30 | +import net.minecraft.network.chat.HoverEvent; |
| 31 | +import net.minecraft.network.chat.Style; |
28 | 32 | import net.minecraft.server.level.ServerPlayer; |
29 | 33 |
|
30 | 34 | import java.io.IOException; |
@@ -176,11 +180,24 @@ private static int refreshReadme(CommandSourceStack source) { |
176 | 180 | return 1; |
177 | 181 | } |
178 | 182 |
|
| 183 | + private static Component makeRankNameClicky(Rank rank) { |
| 184 | + boolean isDef = rank.getCondition().isDefaultCondition(); |
| 185 | + return Component.literal(rank.getName()) |
| 186 | + .withStyle(isDef ? ChatFormatting.AQUA : ChatFormatting.YELLOW) |
| 187 | + .withStyle(Style.EMPTY |
| 188 | + .withClickEvent(new ClickEvent(Action.RUN_COMMAND, "/ftbranks show_rank " + rank.getId())) |
| 189 | + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, isDef ? |
| 190 | + Component.literal("Players must be explicitly added to this rank\nwith '/ftbranks add <player> " + rank.getId() + "'").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC) : |
| 191 | + Component.literal("Rank condition: " + rank.getCondition().asString()).withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC)) |
| 192 | + ) |
| 193 | + ); |
| 194 | + } |
| 195 | + |
179 | 196 | private static int listAllRanks(CommandSourceStack source) { |
180 | 197 | source.sendSuccess(() -> Component.literal("Ranks:"), false); |
181 | 198 |
|
182 | 199 | for (Rank rank : FTBRanksAPIImpl.manager.getAllRanks()) { |
183 | | - source.sendSuccess(() -> Component.literal("- " + rank.getName()).withStyle(rank.getCondition().isDefaultCondition() ? ChatFormatting.AQUA : ChatFormatting.YELLOW), false); |
| 200 | + source.sendSuccess(() -> Component.literal("- ").append(makeRankNameClicky(rank)), false); |
184 | 201 | } |
185 | 202 |
|
186 | 203 | return 1; |
@@ -234,7 +251,7 @@ private static int listRanksOf(CommandSourceStack source, ServerPlayer player) { |
234 | 251 |
|
235 | 252 | for (Rank rank : FTBRanksAPIImpl.manager.getAllRanks()) { |
236 | 253 | if (rank.isActive(player)) { |
237 | | - source.sendSuccess(() -> Component.literal("- " + rank.getName()).withStyle(rank.getCondition().isDefaultCondition() ? ChatFormatting.AQUA : ChatFormatting.YELLOW), false); |
| 254 | + source.sendSuccess(() -> Component.literal("- ").append(makeRankNameClicky(rank)), false); |
238 | 255 | } |
239 | 256 | } |
240 | 257 |
|
|
0 commit comments