Search in sources :

Example 1 with CancelReport

use of com.sk89q.worldguard.bukkit.util.report.CancelReport in project WorldGuard by EngineHub.

the class BukkitDebugHandler method testEvent.

/**
 * Simulate an event and print its report.
 *
 * @param receiver The receiver of the messages
 * @param target The target
 * @param event The event
 * @param stacktraceMode Whether stack traces should be generated and posted
 * @param <T> The type of event
 */
private <T extends Event & CancelLogging> void testEvent(CommandSender receiver, Player target, T event, boolean stacktraceMode) throws CommandPermissionsException {
    boolean isConsole = receiver instanceof ConsoleCommandSender;
    if (!receiver.equals(target)) {
        if (!isConsole) {
            log.info(receiver.getName() + " is simulating an event on " + target.getName());
        }
        target.sendMessage(ChatColor.RED + "(Please ignore any messages that may immediately follow.)");
    }
    Bukkit.getPluginManager().callEvent(event);
    int start = new Exception().getStackTrace().length;
    CancelReport report = new CancelReport(event, event.getCancels(), start);
    report.setDetectingPlugin(!stacktraceMode);
    String result = report.toString();
    if (stacktraceMode) {
        receiver.sendMessage(ChatColor.GRAY + "The report was printed to console.");
        log.info("Event report for " + receiver.getName() + ":\n\n" + result);
        plugin.checkPermission(receiver, "worldguard.debug.pastebin");
        ActorCallbackPaste.pastebin(WorldGuard.getInstance().getSupervisor(), plugin.wrapCommandSender(receiver), result, "Event debugging report: %s.txt");
    } else {
        receiver.sendMessage(result.replaceAll("(?m)^", ChatColor.AQUA.toString()));
        if (result.length() >= 500 && !isConsole) {
            receiver.sendMessage(ChatColor.GRAY + "The report was also printed to console.");
            log.info("Event report for " + receiver.getName() + ":\n\n" + result);
        }
    }
}
Also used : CancelReport(com.sk89q.worldguard.bukkit.util.report.CancelReport) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) CommandException(com.sk89q.minecraft.util.commands.CommandException)

Aggregations

CommandException (com.sk89q.minecraft.util.commands.CommandException)1 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)1 CancelReport (com.sk89q.worldguard.bukkit.util.report.CancelReport)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1