Added List and Plugins commands

master
Etzelia 2018-09-14 00:08:13 -05:00
parent 941f0a40b6
commit a31a32edea
6 changed files with 125 additions and 8 deletions

View File

@ -168,6 +168,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -85,19 +85,24 @@ public class QoL extends JavaPlugin {
WorldInfoCommand worldInfoCommand = new WorldInfoCommand(this);
this.getCommand("worldinfo").setExecutor(worldInfoCommand);
if (getConfig().getStringList("list").size() > 0) {
ListCommand listCommand = new ListCommand(this);
this.getCommand("list").setExecutor(listCommand);
}
if (getConfig().getStringList("plugins").size() > 0) {
PluginsCommand pluginsCommand = new PluginsCommand(this);
this.getCommand("plugins").setExecutor(pluginsCommand);
}
// Scheduler
int schedule = config.getInt("schedule.frequency");
if (schedule > 0) {
Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), new Runnable() {
@Override
public void run() {
List<String> scheduled = config.getStringList("schedule.commands");
for (String command : scheduled) {
runTask(command);
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(QoL.getInstance(), () -> {
List<String> scheduled = config.getStringList("schedule.commands");
for (String command : scheduled) {
runTask(command);
}
}, 0, EtzTechUtil.minutesToTicks(schedule));
}

View File

@ -0,0 +1,55 @@
package xyz.etztech.qol.commands;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.etztech.qol.QoL;
import java.util.*;
public class ListCommand implements CommandExecutor {
QoL plugin;
public ListCommand(QoL plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
Map<String, List<String>> list = new HashMap<>();
List<String> groups = plugin.getConfig().getStringList("list");
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
for (String group : groups) {
if (player.hasPermission("qol.list." + group)) {
List<String> names = list.containsKey(group) ? list.get(group) : new ArrayList<String>();
names.add(player.getName());
list.put(group, names);
break;
}
}
}
StringBuilder message = new StringBuilder();
for (String key : list.keySet()) {
List<String> parts = Arrays.asList(key.split("_"));
parts.forEach(StringUtils::capitalize);
message.append(ChatColor.GOLD)
.append(StringUtils.join(parts, " "))
.append(": ")
.append(ChatColor.YELLOW)
.append(StringUtils.join(list.get(key), ", "))
.append("\n");
}
commandSender.sendMessage(message.toString());
return true;
}
}

View File

@ -0,0 +1,27 @@
package xyz.etztech.qol.commands;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import xyz.etztech.qol.QoL;
public class PluginsCommand implements CommandExecutor {
QoL plugin;
public PluginsCommand(QoL plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
commandSender.sendMessage(ChatColor.GOLD + "Plugins: " + ChatColor.YELLOW +
StringUtils.join(plugin.getConfig().getStringList("plugins"), ", "));
return true;
}
}

View File

@ -8,6 +8,22 @@ makeme:
# Can either be PermissionsEX or LuckPerms
engine: 'LuckPerms'
# Each item in the following list will be used to split players in /list
# Give the group the permission qol.list.<item>
# Group names will be generated by title-case and replacing underscores with spaces
# e.g. senior_staff -> Senior Staff (qol.list.senior_staff)
# Make sure the items are ordered from most to least important
# Leave blank to disable
list:
# - admin
# - mod
# - member
# A list of plugins to show, overriding the Vanilla /pl
# Leave blank to disable
plugins:
# - QoL
# A list of commands to send to Discord if anyone uses them
audit:
enabled: true

View File

@ -10,6 +10,12 @@ commands:
colors:
description: See all color/formatting codes
aliases: [color, c]
list:
description: See a list of players
aliases: [players, playerlist]
plugins:
description: See a list of plugins
aliases: [pl]
history:
description: Name History utility command
aliases: [names, name]