Add verbose command

This commit is contained in:
Luck 2016-10-27 17:46:44 +01:00
parent 0a4d337a53
commit 7acc8bc7ed
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
11 changed files with 151 additions and 0 deletions

View File

@ -53,6 +53,7 @@ import me.lucko.luckperms.common.storage.StorageFactory;
import me.lucko.luckperms.common.tracks.TrackManager;
import me.lucko.luckperms.common.users.UserManager;
import me.lucko.luckperms.common.utils.BufferedRequest;
import me.lucko.luckperms.common.utils.DebugHandler;
import me.lucko.luckperms.common.utils.LocaleManager;
import me.lucko.luckperms.common.utils.LogFactory;
import org.bukkit.World;
@ -91,10 +92,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
private CalculatorFactory calculatorFactory;
private BufferedRequest<Void> updateTaskBuffer;
private boolean started = false;
private DebugHandler debugHandler;
@Override
public void onEnable() {
log = LogFactory.wrap(getLogger());
debugHandler = new DebugHandler();
getLog().info("Loading configuration...");
configuration = new BukkitConfig(this);

View File

@ -50,6 +50,7 @@ import me.lucko.luckperms.common.storage.StorageFactory;
import me.lucko.luckperms.common.tracks.TrackManager;
import me.lucko.luckperms.common.users.UserManager;
import me.lucko.luckperms.common.utils.BufferedRequest;
import me.lucko.luckperms.common.utils.DebugHandler;
import me.lucko.luckperms.common.utils.LocaleManager;
import me.lucko.luckperms.common.utils.LogFactory;
import net.md_5.bungee.api.config.ServerInfo;
@ -80,10 +81,12 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
private ContextManager<ProxiedPlayer> contextManager;
private CalculatorFactory calculatorFactory;
private BufferedRequest<Void> updateTaskBuffer;
private DebugHandler debugHandler;
@Override
public void onEnable() {
log = LogFactory.wrap(getLogger());
debugHandler = new DebugHandler();
getLog().info("Loading configuration...");
configuration = new BungeeConfig(this);

View File

@ -40,6 +40,7 @@ import me.lucko.luckperms.common.storage.Datastore;
import me.lucko.luckperms.common.tracks.TrackManager;
import me.lucko.luckperms.common.users.UserManager;
import me.lucko.luckperms.common.utils.BufferedRequest;
import me.lucko.luckperms.common.utils.DebugHandler;
import me.lucko.luckperms.common.utils.LocaleManager;
import java.io.File;
@ -70,6 +71,7 @@ public interface LuckPermsPlugin {
LocaleManager getLocaleManager();
ContextManager getContextManager();
CalculatorFactory getCalculatorFactory();
DebugHandler getDebugHandler();
/**
* @return the version of the plugin

View File

@ -58,6 +58,7 @@ public class PermissionCalculator {
permission = permission.toLowerCase();
Tristate t = cache.getUnchecked(permission);
plugin.getDebugHandler().printOutput(objectName, permission, t);
if (debug) {
plugin.getLog().info("Checking if " + objectName + " has permission: " + permission + " - (" + t.toString() + ")");
}

View File

@ -62,6 +62,7 @@ public class CommandManager {
.add(new NetworkSyncCommand())
.add(new InfoCommand())
.add(new DebugCommand())
.add(new VerboseCommand())
.add(new ImportCommand())
.add(new ExportCommand())
.add(new QueueCommand())

View File

@ -0,0 +1,67 @@
/*
* 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.Sender;
import me.lucko.luckperms.common.commands.SingleMainCommand;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import java.util.List;
public class VerboseCommand extends SingleMainCommand {
public VerboseCommand() {
super("Verbose", "/%s verbose <true|false> [query]", 1, Permission.VERBOSE);
}
@Override
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
if (args.isEmpty()) {
sendUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
if (!args.get(0).equalsIgnoreCase("true") && !args.get(0).equalsIgnoreCase("false")) {
sendUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
if (args.get(0).equalsIgnoreCase("false")) {
plugin.getDebugHandler().unregister(sender.getUuid());
Message.VERBOSE_OFF.send(sender);
return CommandResult.SUCCESS;
}
String query = args.size() == 1 ? "" : args.get(1);
plugin.getDebugHandler().register(sender, query);
if (!query.equals("")) {
Message.VERBOSE_ON_QUERY.send(sender, query);
} else {
Message.VERBOSE_ON.send(sender);
}
return CommandResult.SUCCESS;
}
}

View File

@ -84,6 +84,10 @@ public enum Message {
/*
* Commands
*/
VERBOSE_ON("&bVerbose checking output set to &aTRUE &bfor all permissions.", true),
VERBOSE_ON_QUERY("&bVerbose checking output set to &aTRUE &bfor permissions starting with &f\"{0}\"&b.", true),
VERBOSE_OFF("&bVerbose checking output set to &cFALSE&b.", true),
CREATE_SUCCESS("&b{0}&a was successfully created.", true),
DELETE_SUCCESS("&b{0}&a was successfully deleted.", true),
RENAME_SUCCESS("&b{0}&a was successfully renamed to &b{1}&a.", true),

View File

@ -37,6 +37,7 @@ 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),
CREATE_GROUP(set("creategroup"), Type.NONE),

View File

@ -0,0 +1,62 @@
/*
* 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.utils;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.constants.Message;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class DebugHandler {
private final Map<Reciever, String> listeners = new ConcurrentHashMap<>();
public void printOutput(String checked, String node, Tristate value) {
for (Map.Entry<Reciever, String> e : listeners.entrySet()) {
if (node.toLowerCase().startsWith(e.getValue().toLowerCase())) {
Message.LOG.send(e.getKey().getSender(), "&7Checking &a" + checked + "&7 for: &a" + node + " &f(&7" + value.toString() + "&f)");
}
}
}
public void register(Sender sender, String s) {
listeners.put(new Reciever(sender.getUuid(), sender), s);
}
public void unregister(UUID uuid) {
listeners.remove(new Reciever(uuid, null));
}
@Getter
@EqualsAndHashCode(of = "uuid")
@AllArgsConstructor
private static final class Reciever {
private final UUID uuid;
private final Sender sender;
}
}

View File

@ -45,6 +45,10 @@ use-uninherit-command: "Use the 'parent remove' command instead of specifying th
verbose-on: "&bVerbose checking output set to &aTRUE &bfor all permissions."
verbose-on_query: "&bVerbose checking output set to &aTRUE &bfor permissions starting with &f\"{0}\"&b."
verbose-off: "&bVerbose checking output set to &cFALSE&b."
create-success: "&b{0}&a was successfully created."
delete-success: "&b{0}&a was successfully deleted."
rename-success: "&b{0}&a was successfully renamed to &b{1}&a."

View File

@ -48,6 +48,7 @@ import me.lucko.luckperms.common.storage.StorageFactory;
import me.lucko.luckperms.common.tracks.TrackManager;
import me.lucko.luckperms.common.users.UserManager;
import me.lucko.luckperms.common.utils.BufferedRequest;
import me.lucko.luckperms.common.utils.DebugHandler;
import me.lucko.luckperms.common.utils.LocaleManager;
import me.lucko.luckperms.common.utils.LogFactory;
import me.lucko.luckperms.sponge.contexts.WorldCalculator;
@ -119,10 +120,12 @@ public class LPSpongePlugin implements LuckPermsPlugin {
private ContextManager<Subject> contextManager;
private CalculatorFactory calculatorFactory;
private BufferedRequest<Void> updateTaskBuffer;
private DebugHandler debugHandler;
@Listener
public void onEnable(GamePreInitializationEvent event) {
log = LogFactory.wrap(logger);
debugHandler = new DebugHandler();
getLog().info("Loading configuration...");
configuration = new SpongeConfig(this);