Improve info command

This commit is contained in:
Luck 2016-11-19 21:56:11 +00:00
parent 9a2cf82623
commit bb25632178
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
18 changed files with 156 additions and 101 deletions

View File

@ -427,6 +427,24 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
return contexts;
}
@Override
public LinkedHashMap<String, Object> getExtraInfo() {
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("Vault Enabled", vaultHook != null);
map.put("Vault Server", configuration.getVaultServer());
map.put("Bukkit Defaults count", defaultsProvider.size());
map.put("Bukkit Child Permissions count", childPermissionProvider.getPermissions().size());
map.put("World Cache size", worldCalculator.getWorldCache().size());
map.put("Vault Including Global", configuration.isVaultIncludingGlobal());
map.put("Vault Ignoring World", configuration.isVaultIgnoreWorld());
map.put("Vault Primary Group Overrides", configuration.isVaultPrimaryGroupOverrides());
map.put("Vault Debug", configuration.isVaultDebug());
map.put("OPs Enabled", configuration.isOpsEnabled());
map.put("Auto OP", configuration.isAutoOp());
map.put("Commands Allow OPs", configuration.isCommandsAllowOp());
return map;
}
@Override
public Object getPlugin(String name) {
return getServer().getPluginManager().getPlugin(name);

View File

@ -102,6 +102,10 @@ public class DefaultsProvider {
return b == null ? Tristate.UNDEFINED : Tristate.fromBoolean(b);
}
public int size() {
return op.size() + nonOp.size();
}
@AllArgsConstructor
private static class DummyPermissible implements Permissible {
private final Runnable onRefresh;

View File

@ -46,10 +46,7 @@ import me.lucko.luckperms.common.utils.DebugHandler;
import me.lucko.luckperms.common.utils.LocaleManager;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.Executor;
/**
@ -206,7 +203,6 @@ public interface LuckPermsPlugin {
return isOnline(external) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
}
/**
* Gets a player object linked to this User. The returned object must be the same type
* as the instance used in the platforms {@link ContextManager}
@ -270,6 +266,14 @@ public interface LuckPermsPlugin {
return Collections.emptyList();
}
/**
* Gets a map of extra information to be shown in the info command
* @return a map of options, or null
*/
default LinkedHashMap<String, Object> getExtraInfo() {
return null;
}
/**
* Gets a set of players ignoring logging output
* @return a {@link Set} of {@link UUID}s

View File

@ -69,7 +69,6 @@ public class CommandManager {
.add(new SyncCommand())
.add(new NetworkSyncCommand())
.add(new InfoCommand())
.add(new DebugCommand())
.add(new VerboseCommand())
.add(new ImportCommand())
.add(new ExportCommand())
@ -282,6 +281,10 @@ public class CommandManager {
break;
// Provide backwards compatibility
case "setprimarygroup":
args.remove(2);
args.add(2, "switchprimarygroup");
break;
case "listnodes":
args.remove(2);
args.add(2, "permission");

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.misc;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
public class DebugCommand extends SingleCommand {
public DebugCommand() {
super("Debug", "Print debugging output", "/%s debug", Permission.DEBUG, Predicates.alwaysFalse(), null);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
plugin.getLog().info(sender.getName() + " used the debug command.");
Message.DEBUG.send(sender,
plugin.getPlayerCount(),
plugin.getUserManager().getAll().size(),
plugin.getGroupManager().getAll().size(),
plugin.getTrackManager().getAll().size()
);
return CommandResult.SUCCESS;
}
}

View File

@ -26,12 +26,15 @@ import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.config.LPConfiguration;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static me.lucko.luckperms.common.commands.utils.Util.formatBoolean;
@ -49,16 +52,49 @@ public class InfoCommand extends SingleCommand {
plugin.getStorage().getName(),
c.getServer(),
c.getSyncTime(),
plugin.getPlayerCount(),
plugin.getUserManager().getAll().size(),
plugin.getGroupManager().getAll().size(),
plugin.getTrackManager().getAll().size(),
plugin.getStorage().getLog().join().getContent().size(),
plugin.getUuidCache().getSize(),
plugin.getLocaleManager().getSize(),
plugin.getPreProcessContexts(false).size(),
plugin.getContextManager().getCalculatorsSize(),
formatBoolean(c.isOnlineMode()),
formatBoolean(c.isRedisEnabled()),
formatBoolean(c.isIncludingGlobalPerms()),
formatBoolean(c.isIncludingGlobalWorldPerms()),
formatBoolean(c.isApplyingGlobalGroups()),
formatBoolean(c.isApplyingGlobalWorldGroups()),
formatBoolean(c.isOnlineMode()),
formatBoolean(c.isApplyingWildcards()),
formatBoolean(c.isApplyingRegex()),
formatBoolean(c.isApplyingShorthand())
);
LinkedHashMap<String, Object> platformInfo = plugin.getExtraInfo();
if (platformInfo == null || platformInfo.isEmpty()) {
return CommandResult.SUCCESS;
}
Message.EMPTY.send(sender, "&f- &bPlatform Info:");
for (Map.Entry<String, Object> e : platformInfo.entrySet()) {
Message.EMPTY.send(sender, "&f- &3" + e.getKey() + ": " + formatValue(e.getValue().toString()));
}
return CommandResult.SUCCESS;
}
private static String formatValue(String value) {
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
return Util.formatBoolean(Boolean.parseBoolean(value));
}
try {
int i = Integer.parseInt(value);
return "&a" + i;
} catch (NumberFormatException ignored) {}
return "&f" + value;
}
}

View File

@ -47,7 +47,7 @@ public class UserMainCommand extends MainCommand<User> {
.add(new CommandParent<>(true))
.add(new CommandMeta<>(true))
.add(new UserGetUUID())
.add(new UserSetPrimaryGroup())
.add(new UserSwitchPrimaryGroup())
.add(new UserPromote())
.add(new UserDemote())
.add(new HolderShowTracks<>(true))

View File

@ -38,10 +38,10 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.List;
public class UserSetPrimaryGroup extends SubCommand<User> {
public UserSetPrimaryGroup() {
super("setprimarygroup", "Sets the user's primary group", Permission.USER_SETPRIMARYGROUP, Predicates.not(1),
Arg.list(Arg.create("group", true, "the group to set as the primary group"))
public class UserSwitchPrimaryGroup extends SubCommand<User> {
public UserSwitchPrimaryGroup() {
super("switchprimarygroup", "Switches the user's primary group", Permission.USER_SWITCHPRIMARYGROUP, Predicates.not(1),
Arg.list(Arg.create("group", true, "the group to switch to"))
);
}

View File

@ -122,26 +122,30 @@ public enum Message {
"{PREFIX}&f- &3Platform: &f{1}" + "\n" +
"{PREFIX}&f- &3Storage Method: &f{2}" + "\n" +
"{PREFIX}&f- &3Server Name: &f{3}" + "\n" +
"{PREFIX}&f- &3Sync Interval: &f{4} minutes" + "\n" +
"{PREFIX}&f- &3Include Global: &f{5}" + "\n" +
"{PREFIX}&f- &3Include Global World: &f{6}" + "\n" +
"{PREFIX}&f- &3Apply Global Groups: &f{7}" + "\n" +
"{PREFIX}&f- &3Apply Global World Groups: &f{8}" + "\n" +
"{PREFIX}&f- &3Online Mode: &f{9}" + "\n" +
"{PREFIX}&f- &3Apply Wildcards: &f{10}" + "\n" +
"{PREFIX}&f- &3Apply Regex: &f{11}" + "\n" +
"{PREFIX}&f- &3Apply Shorthand: &f{12}",
"{PREFIX}&f- &3Sync Interval: &a{4} &fminutes" + "\n" +
"{PREFIX}&f- &bCounts:" + "\n" +
"{PREFIX}&f- &3Online Players: &a{5}" + "\n" +
"{PREFIX}&f- &3Loaded Users: &a{6}" + "\n" +
"{PREFIX}&f- &3Loaded Groups: &a{7}" + "\n" +
"{PREFIX}&f- &3Loaded Tracks: &a{8}" + "\n" +
"{PREFIX}&f- &3Log size: &a{9}" + "\n" +
"{PREFIX}&f- &3UUID Cache size: &a{10}" + "\n" +
"{PREFIX}&f- &3Translations loaded: &a{11}" + "\n" +
"{PREFIX}&f- &3Pre-process contexts: &a{12}" + "\n" +
"{PREFIX}&f- &3Context Calculators: &a{13}" + "\n" +
"{PREFIX}&f- &bConfiguration:" + "\n" +
"{PREFIX}&f- &3Online Mode: {14}" + "\n" +
"{PREFIX}&f- &3Redis Enabled: {15}" + "\n" +
"{PREFIX}&f- &bPermission Calculation:" + "\n" +
"{PREFIX}&f- &3Including Global: {16}" + "\n" +
"{PREFIX}&f- &3Including Global World: {17}" + "\n" +
"{PREFIX}&f- &3Applying Global Groups: {18}" + "\n" +
"{PREFIX}&f- &3Applying Global World Groups: {19}" + "\n" +
"{PREFIX}&f- &3Applying Wildcards: {20}" + "\n" +
"{PREFIX}&f- &3Applying Regex: {21}" + "\n" +
"{PREFIX}&f- &3Applying Shorthand: {22}",
false
),
DEBUG(
"{PREFIX}&d&l> &dDebug Info" + "\n" +
"{PREFIX}&f> &3Online Players: &f{0}" + "\n" +
"{PREFIX}&f> &3Loaded Users: &f{1}" + "\n" +
"{PREFIX}&f> &3Loaded Groups: &f{2}" + "\n" +
"{PREFIX}&f> &3Loaded Tracks: &f{3}",
false
),
CREATE_GROUP_ERROR("There was an error whilst creating the group.", true),
DELETE_GROUP_ERROR("There was an error whilst deleting the group.", true),
DELETE_GROUP_ERROR_DEFAULT("You cannot delete the default group.", true),

View File

@ -36,7 +36,6 @@ public enum Permission {
SYNC(set("sync"), Type.NONE),
INFO(set("info"), Type.NONE),
DEBUG(set("debug"), Type.NONE),
VERBOSE(set("verbose"), Type.NONE),
IMPORT(set("import"), Type.NONE),
@ -77,7 +76,7 @@ public enum Permission {
USER_META_REMOVETEMP_SUFFIX(set("meta.removetempsuffix", "removetempsuffix"), Type.USER),
USER_META_CLEAR(set("meta.clear", "clearmeta"), Type.USER),
USER_GETUUID(set("getuuid"), Type.USER),
USER_SETPRIMARYGROUP(set("setprimarygroup"), Type.USER),
USER_SWITCHPRIMARYGROUP(set("switchprimarygroup", "setprimarygroup"), Type.USER),
USER_SHOWTRACKS(set("showtracks"), Type.USER),
USER_PROMOTE(set("promote"), Type.USER),
USER_DEMOTE(set("demote"), Type.USER),

View File

@ -71,4 +71,8 @@ public class ContextManager<T> {
listeners.add(listener);
}
public int getCalculatorsSize() {
return calculators.size();
}
}

View File

@ -66,4 +66,8 @@ public class UuidCache {
cache.remove(external);
}
public int getSize() {
return onlineMode ? 0 : cache.size();
}
}

View File

@ -49,5 +49,9 @@ public class ExpireTemporaryTask implements Runnable {
}
}
}
if (groupChanges) {
plugin.getUpdateTaskBuffer().request();
}
}
}

View File

@ -43,7 +43,7 @@ import static me.lucko.luckperms.common.core.PermissionHolder.exportToLegacy;
@SuppressWarnings("ResultOfMethodCallIgnored")
public class JSONBacking extends FlatfileBacking {
public JSONBacking(LuckPermsPlugin plugin, File pluginDir) {
super(plugin, "Flatfile - JSON", pluginDir);
super(plugin, "JSON", pluginDir);
}
private boolean doWrite(File file, WriteOperation writeOperation) {

View File

@ -43,7 +43,7 @@ import static me.lucko.luckperms.common.core.PermissionHolder.exportToLegacy;
@SuppressWarnings({"unchecked", "ResultOfMethodCallIgnored"})
public class YAMLBacking extends FlatfileBacking {
public YAMLBacking(LuckPermsPlugin plugin, File pluginDir) {
super(plugin, "Flatfile - YAML", pluginDir);
super(plugin, "YAML", pluginDir);
}
private static Yaml getYaml() {

View File

@ -44,6 +44,10 @@ public class LocaleManager {
translations = ImmutableMap.copyOf((Map<String, String>) new Yaml().load(fileReader));
}
public int getSize() {
return translations == null ? 0 : translations.size();
}
public String getTranslation(Message key) {
if (translations == null) {
return null;

View File

@ -83,22 +83,28 @@ info: >
{PREFIX}&f- &3Platform: &f{1}\n
{PREFIX}&f- &3Storage Method: &f{2}\n
{PREFIX}&f- &3Server Name: &f{3}\n
{PREFIX}&f- &3Sync Interval: &f{4} minutes\n
{PREFIX}&f- &3Include Global: &f{5}\n
{PREFIX}&f- &3Include Global World: &f{6}\n
{PREFIX}&f- &3Apply Global Groups: &f{7}\n
{PREFIX}&f- &3Apply Global World Groups: &f{8}\n
{PREFIX}&f- &3Online Mode: &f{9}\n
{PREFIX}&f- &3Apply Wildcards: &f{10}\n
{PREFIX}&f- &3Apply Regex: &f{11}\n
{PREFIX}&f- &3Apply Shorthand: &f{12}
debug: >
{PREFIX}&d&l> &dDebug Info\n
{PREFIX}&f> &3Online Players: &f{0}\n
{PREFIX}&f> &3Loaded Users: &f{1}\n
{PREFIX}&f> &3Loaded Groups: &f{2}\n
{PREFIX}&f> &3Loaded Tracks: &f{3}
{PREFIX}&f- &3Sync Interval: &a{4} &fminutes\n
{PREFIX}&f- &bCounts:\n
{PREFIX}&f- &3Online Players: &a{5}\n
{PREFIX}&f- &3Loaded Users: &a{6}\n
{PREFIX}&f- &3Loaded Groups: &a{7}\n
{PREFIX}&f- &3Loaded Tracks: &a{8}\n
{PREFIX}&f- &3Log size: &a{9}\n
{PREFIX}&f- &3UUID Cache size: &a{10}\n
{PREFIX}&f- &3Translations loaded: &a{11}\n
{PREFIX}&f- &3Pre-process contexts: &a{12}\n
{PREFIX}&f- &3Context Calculators: &a{13}\n
{PREFIX}&f- &bConfiguration:\n
{PREFIX}&f- &3Online Mode: {14}\n
{PREFIX}&f- &3Redis Enabled: {15}\n
{PREFIX}&f- &bPermission Calculation:\n
{PREFIX}&f- &3Including Global: {16}\n
{PREFIX}&f- &3Including Global World: {17}\n
{PREFIX}&f- &3Applying Global Groups: {18}\n
{PREFIX}&f- &3Applying Global World Groups: {19}\n
{PREFIX}&f- &3Applying Wildcards: {20}\n
{PREFIX}&f- &3Applying Regex: {21}\n
{PREFIX}&f- &3Applying Shorthand: {22}"
create-group-error: "There was an error whilst creating the group."
delete-group-error: "There was an error whilst deleting the group."
delete-group-error-default: "You cannot delete the default group."

View File

@ -77,6 +77,7 @@ import org.spongepowered.api.scheduler.SynchronousExecutor;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.service.permission.SubjectCollection;
import org.spongepowered.api.text.Text;
import java.io.File;
@ -85,6 +86,7 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
@Getter
@Plugin(id = "luckperms",
@ -405,6 +407,20 @@ public class LPSpongePlugin implements LuckPermsPlugin {
return Collections.singletonList(new SpongeMainCommand(this));
}
@Override
public LinkedHashMap<String, Object> getExtraInfo() {
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("SubjectCollection count", service.getKnownSubjects().size());
map.put("Subject count",
service.getKnownSubjects().values().stream()
.map(SubjectCollection::getAllSubjects)
.flatMap(subjects -> StreamSupport.stream(subjects.spliterator(), false))
.count()
);
map.put("PermissionDescription count", service.getDescriptions().size());
return map;
}
private void registerPermission(PermissionService p, String node) {
Optional<PermissionDescription.Builder> builder = p.newDescriptionBuilder(this);
if (!builder.isPresent()) return;