This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
BlacklistListCommand.java
73 lines (62 loc) · 3.44 KB
/
BlacklistListCommand.java
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
/*
* This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file
* at the root of this project for more details.
*/
package io.github.nucleuspowered.nucleus.modules.blacklist.commands;
import io.github.nucleuspowered.nucleus.Util;
import io.github.nucleuspowered.nucleus.configurate.datatypes.item.BlacklistNode;
import io.github.nucleuspowered.nucleus.dataservices.ItemDataService;
import io.github.nucleuspowered.nucleus.internal.annotations.Permissions;
import io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommand;
import io.github.nucleuspowered.nucleus.internal.annotations.RunAsync;
import io.github.nucleuspowered.nucleus.internal.command.AbstractCommand;
import io.github.nucleuspowered.nucleus.internal.messages.MessageProvider;
import io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.action.TextActions;
import org.spongepowered.api.text.format.TextColors;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@RunAsync
@Permissions(prefix = "blacklist", suggestedLevel = SuggestedLevel.ADMIN)
@RegisterCommand(value = {"list", "ls"}, subcommandOf = BlacklistCommand.class)
public class BlacklistListCommand extends AbstractCommand<CommandSource> {
@Override
public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception {
ItemDataService itemDataService = this.plugin.getItemDataService();
Map<String, BlacklistNode> itemsToNodes = itemDataService.getAllBlacklistedItems().entrySet().stream()
.collect(Collectors.toMap(x -> Util.getTranslatedStringFromItemId(x.getKey()).orElse(x.getKey()), Map.Entry::getValue));
if (itemsToNodes.isEmpty()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.blacklist.list.none"));
return CommandResult.empty();
}
MessageProvider mp = plugin.getMessageProvider();
Text header = mp.getTextMessageWithFormat("blacklist.title");
List<Text> lt = new ArrayList<>();
itemsToNodes.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)).forEach(e -> {
String types = String.join(", ", new ArrayList<String>() {{
if (e.getValue().isEnvironment()) {
add(mp.getMessageWithFormat("command.blacklist.list.environment"));
}
if (e.getValue().isInventory()) {
add(mp.getMessageWithFormat("command.blacklist.list.possess"));
}
if (e.getValue().isUse()) {
add(mp.getMessageWithFormat("command.blacklist.list.use"));
}
}});
lt.add(Text.builder(e.getKey()).color(TextColors.GREEN)
.onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("blacklist.hover", e.getKey())))
.append(Text.of(TextColors.YELLOW, " - " + types))
.build());
});
Util.getPaginationBuilder(src).title(Text.of(TextColors.YELLOW, header)).padding(Text.of(TextColors.GREEN, "-")).contents(lt).sendTo(src);
return CommandResult.success();
}
}