-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugins.java
94 lines (75 loc) · 2.8 KB
/
Plugins.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package net.sparkzz.servercontrol.command;
import com.google.common.base.Optional;
import net.sparkzz.servercontrol.util.Utility;
import org.spongepowered.api.Server;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.util.command.CommandCallable;
import org.spongepowered.api.util.command.CommandException;
import org.spongepowered.api.util.command.CommandResult;
import org.spongepowered.api.util.command.CommandSource;
import java.util.*;
/**
* @author Brendon
* @since April 30, 2015
*/
public class Plugins extends Utility implements CommandCallable {
private final Server server;
private final Optional<String> desc = Optional.of("View a list of installed plugins");
private final Optional<String> help = Optional.of("View a list of installed plugins");
private final String permission = "server.plugins";
public Plugins(Server server) {
this.server = server;
}
// TODO: getPlugins() returns mods as well, try to figure a way to split them
@Override
public Optional<CommandResult> process(CommandSource source, String arguments) throws CommandException {
if (!testPermission(source)) {
msg.deny(source, action.COMMAND);
return result.EMPTY.getResult();
}
if (!arguments.equals("")) {
source.sendMessage(getUsage(source));
return result.EMPTY.getResult();
}
source.sendMessage(Texts.of("Plugins: " + getPluginList()));
return result.SUCCESS.getResult();
}
private Text getPluginList() {
StringBuilder list = new StringBuilder();
Collection<PluginContainer> plugins = game.getPluginManager().getPlugins();
List<String> exclude = new ArrayList<String>(Arrays.asList("Minecraft", "Minecraft Coder Pack", "Forge Mod Loader", "Minecraft Forge", "Sponge"));
int i = plugins.size();
for (PluginContainer plugin : plugins) {
if (!exclude.contains(plugin.getName())) {
if (list.length() > 0) {
list.append(TextColors.WHITE);
list.append(", ");
}
list.append(TextColors.GREEN + plugin.getName());
} else i--;
}
return Texts.of(TextColors.DARK_GRAY + "(" + TextColors.LIGHT_PURPLE + i + TextColors.DARK_GRAY + "): " + list.toString());
}
@Override
public boolean testPermission(CommandSource source) {
return source.hasPermission(permission);
}
@Override
public Optional<Text> getShortDescription(CommandSource source) {
return Optional.of(Texts.of(desc));
}
@Override
public Optional<Text> getHelp(CommandSource source) {
return Optional.of(Texts.of(help));
}
@Override
public Text getUsage(CommandSource source) {
return Texts.of("/plugins");
}
public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
return Collections.emptyList();
}
}