Rewrite and update report generation.

This commit is contained in:
sk89q 2014-12-31 01:18:23 -08:00
parent 0cb36b3b8b
commit 88169236cb
24 changed files with 861 additions and 512 deletions

View File

@ -29,6 +29,7 @@
import com.sk89q.worldguard.protection.managers.storage.DriverType;
import com.sk89q.worldguard.protection.managers.storage.RegionDriver;
import com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver;
import com.sk89q.worldguard.util.report.Unreported;
import com.sk89q.worldguard.util.sql.DataSourceConfig;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -75,12 +76,11 @@ public class ConfigurationManager {
"# - Lines starting with # are comments and so they are ignored.\r\n" +
"#\r\n";
private WorldGuardPlugin plugin;
private ConcurrentMap<String, WorldConfiguration> worlds;
private YAMLProcessor config;
@Deprecated
private Set<String> hasGodMode = new HashSet<String>();
private Set<String> hasAmphibious = new HashSet<String>();
@Unreported private WorldGuardPlugin plugin;
@Unreported private ConcurrentMap<String, WorldConfiguration> worlds;
@Unreported private YAMLProcessor config;
@Deprecated @Unreported private Set<String> hasGodMode = new HashSet<String>();
@Unreported private Set<String> hasAmphibious = new HashSet<String>();
private boolean hasCommandBookGodMode = false;
@ -96,13 +96,14 @@ public class ConfigurationManager {
public boolean blockInGameOp;
public boolean migrateRegionsToUuid;
public boolean keepUnresolvedNames;
public Map<String, String> hostKeys = new HashMap<String, String>();
@Unreported public Map<String, String> hostKeys = new HashMap<String, String>();
/**
* Region Storage Configuration method, and config values
*/
public RegionDriver selectedRegionStoreDriver;
public Map<DriverType, RegionDriver> regionStoreDriverMap;
@Unreported public RegionDriver selectedRegionStoreDriver;
@Unreported public Map<DriverType, RegionDriver> regionStoreDriverMap;
/**
* Construct the object.

View File

@ -32,6 +32,7 @@
import com.sk89q.worldguard.bukkit.util.TargetMatcherSet;
import com.sk89q.worldguard.chest.ChestProtection;
import com.sk89q.worldguard.chest.SignChestProtection;
import com.sk89q.worldguard.util.report.Unreported;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -40,12 +41,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -71,15 +67,15 @@ public class WorldConfiguration {
"# Remove the {} and add your own entries.\r\n" +
"#\r\n";
private WorldGuardPlugin plugin;
@Unreported private WorldGuardPlugin plugin;
private String worldName;
private YAMLProcessor parentConfig;
private YAMLProcessor config;
@Unreported private String worldName;
@Unreported private YAMLProcessor parentConfig;
@Unreported private YAMLProcessor config;
private File blacklistFile;
private Blacklist blacklist;
private ChestProtection chestProtection = new SignChestProtection();
@Unreported private Blacklist blacklist;
@Unreported private ChestProtection chestProtection = new SignChestProtection();
/* Configuration data start */
public boolean summaryOnStart;

View File

@ -19,14 +19,17 @@
package com.sk89q.worldguard.bukkit.commands;
import com.google.common.io.Files;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.util.LoggerToChatHandler;
import com.sk89q.worldguard.bukkit.util.ReportWriter;
import com.sk89q.worldguard.bukkit.util.report.*;
import com.sk89q.worldguard.util.paste.Pastebin;
import com.sk89q.worldguard.util.report.ReportList;
import com.sk89q.worldguard.util.report.SystemInfoReport;
import com.sk89q.worldguard.util.task.Task;
import com.sk89q.worldguard.util.task.TaskStateComparator;
import org.bukkit.Bukkit;
@ -38,6 +41,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
@ -103,14 +107,21 @@ public void reload(CommandContext args, CommandSender sender) throws CommandExce
@Command(aliases = {"report"}, desc = "Writes a report on WorldGuard", flags = "p", max = 0)
@CommandPermissions({"worldguard.report"})
public void report(CommandContext args, final CommandSender sender) throws CommandException {
File dest = new File(plugin.getDataFolder(), "report.txt");
ReportWriter report = new ReportWriter(plugin);
ReportList report = new ReportList("Report");
report.add(new SystemInfoReport());
report.add(new ServerReport());
report.add(new PluginReport());
report.add(new SchedulerReport());
report.add(new ServicesReport());
report.add(new WorldReport());
report.add(new PerformanceReport());
report.add(new ConfigReport(plugin));
String result = report.toString();
try {
report.write(dest);
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report written to "
+ dest.getAbsolutePath());
File dest = new File(plugin.getDataFolder(), "report.txt");
Files.write(result, dest, Charset.forName("UTF-8"));
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report written to " + dest.getAbsolutePath());
} catch (IOException e) {
throw new CommandException("Failed to write report: " + e.getMessage());
}
@ -120,7 +131,7 @@ public void report(CommandContext args, final CommandSender sender) throws Comma
sender.sendMessage(ChatColor.YELLOW + "Now uploading to Pastebin...");
Futures.addCallback(new Pastebin().paste(report.toString()), new FutureCallback<URL>() {
Futures.addCallback(new Pastebin().paste(result), new FutureCallback<URL>() {
@Override
public void onSuccess(URL url) {
sender.sendMessage(ChatColor.YELLOW + "WorldGuard report: " + url);

View File

@ -1,346 +0,0 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.util;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.sk89q.worldguard.bukkit.ConfigurationManager;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.Plugin;
import com.sk89q.worldguard.protection.GlobalRegionManager;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.util.LogListBlock;
public class ReportWriter {
private static final SimpleDateFormat dateFmt =
new SimpleDateFormat("yyyy-MM-dd kk:mm Z");
private Date date = new Date();
private StringBuilder output = new StringBuilder();
public ReportWriter(WorldGuardPlugin plugin) {
appendReportHeader(plugin);
appendServerInformation(plugin.getServer());
appendPluginInformation(plugin.getServer().getPluginManager().getPlugins());
appendWorldInformation(plugin.getServer().getWorlds());
appendGlobalConfiguration(plugin.getGlobalStateManager());
appendWorldConfigurations(plugin, plugin.getServer().getWorlds(),
plugin.getGlobalRegionManager(), plugin.getGlobalStateManager());
appendln("-------------");
appendln("END OF REPORT");
appendln();
}
protected static String repeat(String str, int n) {
if(str == null) {
return null;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(str);
}
return sb.toString();
}
protected void appendln(String text) {
output.append(text);
output.append("\r\n");
}
protected void appendln(String text, Object ... args) {
output.append(String.format(text, args));
output.append("\r\n");
}
protected void append(LogListBlock log) {
output.append(log.toString());
}
protected void appendln() {
output.append("\r\n");
}
protected void appendHeader(String text) {
String rule = repeat("-", text.length());
output.append(rule);
output.append("\r\n");
appendln(text);
output.append(rule);
output.append("\r\n");
appendln();
}
private void appendReportHeader(WorldGuardPlugin plugin) {
appendln("WorldGuard Configuration Report");
appendln("Generated " + dateFmt.format(date));
appendln();
appendln("Version: " + plugin.getDescription().getVersion());
appendln();
}
private void appendGlobalConfiguration(ConfigurationManager config) {
appendHeader("Global Configuration");
LogListBlock log = new LogListBlock();
LogListBlock configLog = log.putChild("Configuration");
Class<? extends ConfigurationManager> cls = config.getClass();
for (Field field : cls.getFields()) {
try {
String name = field.getName();
// store these elsewhere maybe?
if (name.equals("CONFIG_HEADER")
|| name.equals("hostKeys")
|| name.equals("sqlPassword")) {
continue;
}
Object val = field.get(config);
configLog.put(name, val);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException ignore) {
}
}
append(log);
appendln();
}
private void appendServerInformation(Server server) {
appendHeader("Server Information");
LogListBlock log = new LogListBlock();
Runtime runtime = Runtime.getRuntime();
log.put("Java", "%s %s (%s)",
System.getProperty("java.vendor"),
System.getProperty("java.version"),
System.getProperty("java.vendor.url"));
log.put("Operating system", "%s %s (%s)",
System.getProperty("os.name"),
System.getProperty("os.version"),
System.getProperty("os.arch"));
log.put("Available processors", runtime.availableProcessors());
log.put("Free memory", runtime.freeMemory() / 1024 / 1024 + " MB");
log.put("Max memory", runtime.maxMemory() / 1024 / 1024 + " MB");
log.put("Total memory", runtime.totalMemory() / 1024 / 1024 + " MB");
log.put("Server ID", server.getServerId());
log.put("Server name", server.getServerName());
log.put("Implementation", server.getVersion());
//log.put("Address", server.getIp(), server.getPort());
log.put("Player count", "%d/%d",
server.getOnlinePlayers().length, server.getMaxPlayers());
append(log);
appendln();
}
private void appendPluginInformation(Plugin[] plugins) {
appendHeader("Plugins (" + plugins.length + ")");
LogListBlock log = new LogListBlock();
for (Plugin plugin : plugins) {
log.put(plugin.getDescription().getName(), plugin.getDescription().getVersion());
}
append(log);
appendln();
/*appendHeader("Plugin Information");
log = new LogListBlock();
for (Plugin plugin : plugins) {
log.putChild(plugin.getDescription().getName())
.put("Data folder", plugin.getDataFolder())
.put("Website", plugin.getDescription().getWebsite())
.put("Entry point", plugin.getDescription().getMain());
}
append(log);
appendln();*/
}
private void appendWorldInformation(List<World> worlds) {
appendHeader("Worlds");
LogListBlock log = new LogListBlock();
int i = 0;
for (World world : worlds) {
int loadedChunkCount = world.getLoadedChunks().length;
LogListBlock worldLog = log.putChild(world.getName() + " (" + i + ")");
LogListBlock infoLog = worldLog.putChild("Information");
LogListBlock entitiesLog = worldLog.putChild("Entities");
infoLog.put("Seed", world.getSeed());
infoLog.put("Environment", world.getEnvironment().toString());
infoLog.put("Player count", world.getPlayers().size());
infoLog.put("Entity count", world.getEntities().size());
infoLog.put("Loaded chunk count", loadedChunkCount);
infoLog.put("Spawn location", world.getSpawnLocation());
infoLog.put("Raw time", world.getFullTime());
Map<Class<? extends Entity>, Integer> entityCounts =
new HashMap<Class<? extends Entity>, Integer>();
// Collect entities
for (Entity entity : world.getEntities()) {
Class<? extends Entity> cls = entity.getClass();
if (entityCounts.containsKey(cls)) {
entityCounts.put(cls, entityCounts.get(cls) + 1);
} else {
entityCounts.put(cls, 1);
}
}
// Print entities
for (Map.Entry<Class<? extends Entity>, Integer> entry
: entityCounts.entrySet()) {
entitiesLog.put(entry.getKey().getSimpleName(),
"%d [%f/chunk]",
entry.getValue(),
(float) (entry.getValue() / (double) loadedChunkCount));
}
i++;
}
append(log);
appendln();
}
private void appendWorldConfigurations(WorldGuardPlugin plugin, List<World> worlds,
GlobalRegionManager regionMgr, ConfigurationManager mgr) {
appendHeader("World Configurations");
LogListBlock log = new LogListBlock();
int i = 0;
for (World world : worlds) {
LogListBlock worldLog = log.putChild(world.getName() + " (" + i + ")");
LogListBlock infoLog = worldLog.putChild("Information");
LogListBlock configLog = worldLog.putChild("Configuration");
LogListBlock blacklistLog = worldLog.putChild("Blacklist");
LogListBlock regionsLog = worldLog.putChild("Region manager");
infoLog.put("Configuration file", (new File(plugin.getDataFolder(), "worlds/"
+ world.getName() + "/config.yml")).getAbsoluteFile());
infoLog.put("Blacklist file", (new File(plugin.getDataFolder(), "worlds/"
+ world.getName() + "/blacklist.txt")).getAbsoluteFile());
infoLog.put("Regions file", (new File(plugin.getDataFolder(), "worlds/"
+ world.getName() + "/regions.yml")).getAbsoluteFile());
WorldConfiguration config = mgr.get(world);
Class<? extends WorldConfiguration> cls = config.getClass();
for (Field field : cls.getFields()) {
try {
Object val = field.get(config);
configLog.put(field.getName(), String.valueOf(val));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException ignore) {
}
}
if (config.getBlacklist() == null) {
blacklistLog.put("State", "DISABLED");
} else {
blacklistLog.put("State", "Enabled");
blacklistLog.put("Number of items",
config.getBlacklist().getItemCount());
blacklistLog.put("Is whitelist",
config.getBlacklist().isWhitelist());
}
RegionManager worldRegions = regionMgr.get(world);
regionsLog.put("Type", worldRegions.getClass().getCanonicalName());
regionsLog.put("Number of regions", worldRegions.getRegions().size());
LogListBlock globalRegionLog = regionsLog.putChild("Global region");
ProtectedRegion globalRegion = worldRegions.matchRegion("__global__");
if (globalRegion == null) {
globalRegionLog.put("Status", "UNDEFINED");
} else {
for (Flag<?> flag : DefaultFlag.getFlags()) {
if (flag instanceof StateFlag) {
globalRegionLog.put(flag.getName(),
globalRegion.getFlag(flag));
}
}
}
}
append(log);
appendln();
}
public void write(File file) throws IOException {
FileWriter writer = null;
BufferedWriter out;
try {
writer = new FileWriter(file);
out = new BufferedWriter(writer);
out.write(output.toString());
out.close();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException ignore) {
}
}
}
}
@Override
public String toString() {
return output.toString();
}
}

View File

@ -0,0 +1,82 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.util.report;
import com.sk89q.worldguard.blacklist.Blacklist;
import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.util.report.DataReport;
import com.sk89q.worldguard.util.report.RegionReport;
import com.sk89q.worldguard.util.report.ShallowObjectReport;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.util.List;
public class ConfigReport extends DataReport {
public ConfigReport(WorldGuardPlugin plugin) {
super("WorldGuard Configuration");
List<World> worlds = Bukkit.getServer().getWorlds();
append("Configuration", new ShallowObjectReport("Configuration", plugin.getGlobalStateManager()));
for (World world : worlds) {
WorldConfiguration config = plugin.getGlobalStateManager().get(world);
DataReport report = new DataReport("World: " + world.getName());
report.append("UUID", world.getUID());
report.append("Configuration", new ShallowObjectReport("Configuration", config));
Blacklist blacklist = config.getBlacklist();
if (blacklist != null) {
DataReport section = new DataReport("Blacklist");
section.append("Rule Count", blacklist.getItemCount());
section.append("Whitelist Mode?", blacklist.isWhitelist());
report.append(section.getTitle(), section);
} else {
report.append("Blacklist", "<Disabled>");
}
RegionManager regions = plugin.getRegionContainer().get(world);
if (regions != null) {
DataReport section = new DataReport("Regions");
section.append("Region Count", regions.size());
ProtectedRegion global = regions.getRegion("__global__");
if (global != null) {
section.append("__global__", new RegionReport(global));
} else {
section.append("__global__", "<Undefined>");
}
report.append(section.getTitle(), section);
} else {
report.append("Regions", "<Disabled>");
}
append(report.getTitle(), report);
}
}
}

View File

@ -0,0 +1,75 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.util.report;
import com.google.common.collect.Maps;
import com.sk89q.worldguard.util.report.DataReport;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import java.util.List;
import java.util.Map;
public class PerformanceReport extends DataReport {
public PerformanceReport() {
super("Performance");
List<World> worlds = Bukkit.getServer().getWorlds();
append("World Count", worlds.size());
for (World world : worlds) {
int loadedChunkCount = world.getLoadedChunks().length;
DataReport report = new DataReport("World: " + world.getName());
report.append("Keep in Memory?", world.getKeepSpawnInMemory());
report.append("Entity Count", world.getEntities().size());
report.append("Chunk Count", loadedChunkCount);
Map<Class<? extends Entity>, Integer> entityCounts = Maps.newHashMap();
// Collect entities
for (Entity entity : world.getEntities()) {
Class<? extends Entity> cls = entity.getClass();
if (entityCounts.containsKey(cls)) {
entityCounts.put(cls, entityCounts.get(cls) + 1);
} else {
entityCounts.put(cls, 1);
}
}
// Print entities
DataReport entities = new DataReport("Entity Distribution");
for (Map.Entry<Class<? extends Entity>, Integer> entry : entityCounts.entrySet()) {
entities.append(entry.getKey().getSimpleName(), "%d [%f/chunk]",
entry.getValue(),
(float) (entry.getValue() / (double) loadedChunkCount));
}
report.append(entities.getTitle(), entities);
append(report.getTitle(), report);
}
}
}

View File

@ -0,0 +1,54 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.util.report;
import com.sk89q.worldguard.util.report.DataReport;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public class PluginReport extends DataReport {
public PluginReport() {
super("Plugins");
Plugin[] plugins = Bukkit.getServer().getPluginManager().getPlugins();
append("Plugin Count", plugins.length);
for (Plugin plugin : plugins) {
DataReport report = new DataReport("Plugin: " + plugin.getName());
report.append("Enabled?", plugin.isEnabled());
report.append("Full Name", plugin.getDescription().getFullName());
report.append("Version", plugin.getDescription().getVersion());
report.append("Website", plugin.getDescription().getWebsite());
report.append("Description", plugin.getDescription().getDescription());
report.append("Authors", plugin.getDescription().getAuthors());
report.append("Load Before", plugin.getDescription().getLoadBefore());
report.append("Dependencies", plugin.getDescription().getDepend());
report.append("Soft Dependencies", plugin.getDescription().getSoftDepend());
report.append("Folder", plugin.getDataFolder().getAbsoluteFile());
report.append("Entry Point", plugin.getDescription().getMain());
report.append("Class", plugin.getClass().getName());
report.append("Class Source", plugin.getClass().getProtectionDomain().getCodeSource().getLocation());
append(report.getTitle(), report);
}
}
}

View File

@ -0,0 +1,44 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.util.report;
import com.sk89q.worldguard.util.report.DataReport;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask;
import java.util.List;
public class SchedulerReport extends DataReport {
public SchedulerReport() {
super("Scheduler");
List<BukkitTask> tasks = Bukkit.getServer().getScheduler().getPendingTasks();
append("Pending Task Count", tasks.size());
for (BukkitTask task : tasks) {
DataReport report = new DataReport("Task: #" + task.getTaskId());
report.append("Owner", task.getOwner().getName());
report.append("Synchronous?", task.isSync());
append(report.getTitle(), report);
}
}
}

View File

@ -0,0 +1,65 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.util.report;
import com.sk89q.worldguard.util.report.DataReport;
import org.bukkit.Bukkit;
import org.bukkit.Server;
public class ServerReport extends DataReport {
public ServerReport() {
super("Server Information");
Server server = Bukkit.getServer();
append("Server ID", server.getServerId());
append("Server Name", server.getServerName());
append("Bukkit Version", server.getBukkitVersion());
append("Implementation", server.getVersion());
append("Player Count", "%d/%d", server.getOnlinePlayers().length, server.getMaxPlayers());
DataReport spawning = new DataReport("Spawning");
spawning.append("Ambient Spawn Limit", server.getAmbientSpawnLimit());
spawning.append("Animal Spawn Limit", server.getAnimalSpawnLimit());
spawning.append("Monster Spawn Limit", server.getMonsterSpawnLimit());
spawning.append("Ticks per Animal Spawn", server.getTicksPerAnimalSpawns());
spawning.append("Ticks per Monster Spawn", server.getTicksPerMonsterSpawns());
append(spawning.getTitle(), spawning);
DataReport config = new DataReport("Configuration");
config.append("Nether Enabled?", server.getAllowNether());
config.append("The End Enabled?", server.getAllowEnd());
config.append("Generate Structures?", server.getGenerateStructures());
config.append("Flight Allowed?", server.getAllowFlight());
config.append("Connection Throttle", server.getConnectionThrottle());
config.append("Idle Timeout", server.getIdleTimeout());
config.append("Shutdown Message", server.getShutdownMessage());
config.append("Default Game Mode", server.getDefaultGameMode());
config.append("Main World Type", server.getWorldType());
config.append("View Distance", server.getViewDistance());
append(config.getTitle(), config);
DataReport protection = new DataReport("Protection");
protection.append("Spawn Radius", server.getSpawnRadius());
append(protection.getTitle(), protection);
}
}

View File

@ -0,0 +1,46 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.util.report;
import com.sk89q.worldguard.util.report.DataReport;
import org.bukkit.Bukkit;
import org.bukkit.plugin.ServicesManager;
import org.bukkit.scheduler.BukkitTask;
import java.util.Collection;
import java.util.List;
public class ServicesReport extends DataReport {
public ServicesReport() {
super("Services");
ServicesManager manager = Bukkit.getServer().getServicesManager();
Collection<Class<?>> services = manager.getKnownServices();
for (Class<?> service : services) {
Object provider = manager.load(service);
if (provider != null) {
append(service.getName(), provider);
}
}
}
}

View File

@ -0,0 +1,76 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.util.report;
import com.sk89q.worldguard.util.report.DataReport;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator;
import java.util.List;
public class WorldReport extends DataReport {
public WorldReport() {
super("Worlds");
List<World> worlds = Bukkit.getServer().getWorlds();
append("World Count", worlds.size());
for (World world : worlds) {
DataReport report = new DataReport("World: " + world.getName());
report.append("UUID", world.getUID());
report.append("World Type", world.getWorldType());
report.append("Environment", world.getEnvironment());
ChunkGenerator generator = world.getGenerator();
report.append("Chunk Generator", generator != null ? generator.getClass().getName() : "<Default>");
DataReport spawning = new DataReport("Spawning");
spawning.append("Animals?", world.getAllowAnimals());
spawning.append("Monsters?", world.getAllowMonsters());
spawning.append("Ambient Spawn Limit", world.getAmbientSpawnLimit());
spawning.append("Animal Spawn Limit", world.getAnimalSpawnLimit());
spawning.append("Monster Spawn Limit", world.getMonsterSpawnLimit());
spawning.append("Water Creature Spawn Limit", world.getWaterAnimalSpawnLimit());
report.append(spawning.getTitle(), spawning);
DataReport config = new DataReport("Configuration");
config.append("Difficulty", world.getDifficulty());
config.append("Max Height", world.getMaxHeight());
config.append("Sea Level", world.getSeaLevel());
report.append(config.getTitle(), config);
DataReport state = new DataReport("State");
state.append("Spawn Location", world.getSpawnLocation());
state.append("Full Time", world.getFullTime());
state.append("Weather Duration", world.getWeatherDuration());
state.append("Thunder Duration", world.getThunderDuration());
report.append(state.getTitle(), state);
DataReport protection = new DataReport("Protection");
protection.append("PVP?", world.getPVP());
protection.append("Game Rules", world.getGameRules());
report.append(protection.getTitle(), protection);
append(report.getTitle(), report);
}
}
}

View File

@ -344,4 +344,12 @@ public void setDirty(boolean dirty) {
playerDomain.setDirty(dirty);
groupDomain.setDirty(dirty);
}
@Override
public String toString() {
return "{players=" + playerDomain +
", groups=" + groupDomain +
'}';
}
}

View File

@ -130,4 +130,11 @@ public void setDirty(boolean dirty) {
this.dirty = dirty;
}
@Override
public String toString() {
return "{" +
"names=" + groups +
'}';
}
}

View File

@ -185,4 +185,11 @@ public void setDirty(boolean dirty) {
this.dirty = dirty;
}
@Override
public String toString() {
return "{" +
"uuids=" + uniqueIds +
", names=" + names +
'}';
}
}

View File

@ -82,7 +82,7 @@ public RegionGroupFlag getRegionGroupFlag() {
@Override
public String toString() {
return getClass().getName() + "{" +
return getClass().getSimpleName() + "{" +
"name='" + name + '\'' +
'}';
}

View File

@ -1,130 +0,0 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.util;
import java.util.LinkedHashMap;
import java.util.Map;
public class LogListBlock {
private LinkedHashMap<String, Object> items = new LinkedHashMap<String, Object>();
private int maxKeyLength = 0;
private void updateKey(String key) {
if (key.length() > maxKeyLength) {
maxKeyLength = key.length();
}
}
public LogListBlock put(String key, String value) {
updateKey(key);
items.put(key, String.valueOf(value));
return this;
}
public LogListBlock put(String key, LogListBlock value) {
updateKey(key);
items.put(key, value);
return this;
}
public LogListBlock put(String key, Object value) {
put(key, String.valueOf(value));
return this;
}
public LogListBlock put(String key, String value, Object ... args) {
put(key, String.format(value, args));
return this;
}
public LogListBlock put(String key, int value) {
put(key, String.valueOf(value));
return this;
}
public LogListBlock put(String key, byte value) {
put(key, String.valueOf(value));
return this;
}
public LogListBlock put(String key, double value) {
put(key, String.valueOf(value));
return this;
}
public LogListBlock put(String key, float value) {
put(key, String.valueOf(value));
return this;
}
public LogListBlock put(String key, short value) {
put(key, String.valueOf(value));
return this;
}
public LogListBlock put(String key, long value) {
put(key, String.valueOf(value));
return this;
}
public LogListBlock put(String key, boolean value) {
put(key, String.valueOf(value));
return this;
}
public LogListBlock putChild(String key) {
updateKey(key);
LogListBlock block = new LogListBlock();
items.put(key, block);
return block;
}
private String padKey(String key, int len) {
return String.format("%-" + len + "s", key);
}
protected String getOutput(String prefix) {
StringBuilder out = new StringBuilder();
for (Map.Entry<String, Object> entry : items.entrySet()) {
Object val = entry.getValue();
if (val instanceof LogListBlock) {
out.append(prefix);
out.append(padKey(entry.getKey(), maxKeyLength));
out.append(":\r\n");
out.append(((LogListBlock) val).getOutput(prefix + " "));
} else {
out.append(prefix);
out.append(padKey(entry.getKey(), maxKeyLength));
out.append(": ");
out.append(val.toString());
out.append("\r\n");
}
}
return out.toString();
}
@Override
public String toString() {
return getOutput("");
}
}

View File

@ -30,6 +30,9 @@
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Reports on cancelled events.
*/
public class CancelReport implements Report {
private final Event event;

View File

@ -0,0 +1,177 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.util.report;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.*;
import static com.google.common.base.Preconditions.checkNotNull;
public class DataReport implements Report {
private final String title;
private final List<Line> lines = Lists.newArrayList();
public DataReport(String title) {
checkNotNull(title, "title");
this.title = title;
}
public void append(String key, String message) {
checkNotNull(key, "key");
lines.add(new Line(key, message));
}
public void append(String key, String message, Object... values) {
checkNotNull(message, "values");
checkNotNull(values, "values");
append(key, String.format(message, values));
}
public void append(String key, byte value) {
append(key, String.valueOf(value));
}
public void append(String key, short value) {
append(key, String.valueOf(value));
}
public void append(String key, int value) {
append(key, String.valueOf(value));
}
public void append(String key, long value) {
append(key, String.valueOf(value));
}
public void append(String key, float value) {
append(key, String.valueOf(value));
}
public void append(String key, double value) {
append(key, String.valueOf(value));
}
public void append(String key, boolean value) {
append(key, String.valueOf(value));
}
public void append(String key, char value) {
append(key, String.valueOf(value));
}
public void append(String key, Object value) {
append(key, getStringValue(value, Sets.newHashSet()));
}
private static String getStringValue(Object value, Set<Object> seen) {
if (seen.contains(value)) {
return "<Recursive>";
} else {
seen.add(value);
}
if (value instanceof Object[]) {
value = Arrays.asList(value);
}
if (value instanceof Collection<?>) {
StringBuilder builder = new StringBuilder();
boolean first = true;
for (Object entry : (Collection<?>) value) {
if (first) {
first = false;
} else {
builder.append("\n");
}
builder.append(getStringValue(entry, seen));
}
return builder.toString();
} else if (value instanceof Map<?, ?>) {
StringBuilder builder = new StringBuilder();
boolean first = true;
for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
if (first) {
first = false;
} else {
builder.append("\n");
}
String key = getStringValue(entry.getKey(), seen).replaceAll("[\r\n]", "");
if (key.length() > 60) {
key = key.substring(0, 60) + "...";
}
builder
.append(key)
.append(": ")
.append(getStringValue(entry.getValue(), seen));
}
return builder.toString();
} else {
return String.valueOf(value);
}
}
@Override
public String getTitle() {
return title;
}
@Override
public String toString() {
if (!lines.isEmpty()) {
StringBuilder builder = new StringBuilder();
boolean first = true;
for (Line line : lines) {
if (first) {
first = false;
} else {
builder.append("\n");
}
builder.append(line.key).append(": ");
if (line.value == null) {
builder.append("null");
} else if (line.value.contains("\n")) {
builder.append("\n");
builder.append(line.value.replaceAll("(?m)^", "\t"));
} else {
builder.append(line.value);
}
}
return builder.toString();
} else {
return "No data.";
}
}
private static class Line {
private final String key;
private final String value;
public Line(String key, String value) {
this.key = key;
this.value = value;
}
}
}

View File

@ -0,0 +1,39 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.util.report;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
/**
* Reports on a region.
*/
public class RegionReport extends DataReport {
public RegionReport(ProtectedRegion region) {
super("Region: " + region.getId());
append("Type", region.getType());
append("Priority", region.getPriority());
append("Owners", region.getOwners());
append("Members", region.getMembers());
append("Flags", region.getFlags());
}
}

View File

@ -178,9 +178,9 @@ public String toString() {
if (!reports.isEmpty()) {
StringBuilder builder = new StringBuilder();
for (Report report : reports) {
builder.append("================================")
builder.append("================================\n")
.append(report.getTitle())
.append("================================")
.append("\n================================")
.append("\n\n")
.append(report.toString())
.append("\n\n");

View File

@ -0,0 +1,58 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.util.report;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
public class ShallowObjectReport extends DataReport {
private static final Logger log = Logger.getLogger(ShallowObjectReport.class.getCanonicalName());
public ShallowObjectReport(String title, Object object) {
super(title);
checkNotNull(object, "object");
Class<?> type = object.getClass();
for (Field field : type.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers())) {
continue;
}
if (field.getAnnotation(Unreported.class) != null) {
continue;
}
field.setAccessible(true);
try {
Object value = field.get(object);
append(field.getName(), String.valueOf(value));
} catch (IllegalAccessException e) {
log.log(Level.WARNING, "Failed to get value of '" + field.getName() + "' on " + type);
}
}
}
}

View File

@ -41,10 +41,10 @@ public String toString() {
StringBuilder builder = new StringBuilder();
boolean first = true;
for (StackTraceElement element : stackTrace) {
if (!first) {
builder.append("\n");
} else {
if (first) {
first = false;
} else {
builder.append("\n");
}
builder.append(element.getClassName())
.append(".")

View File

@ -0,0 +1,43 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.util.report;
public class SystemInfoReport extends DataReport {
public SystemInfoReport() {
super("System Information");
Runtime runtime = Runtime.getRuntime();
append("Java", "%s %s (%s)",
System.getProperty("java.vendor"),
System.getProperty("java.version"),
System.getProperty("java.vendor.url"));
append("Operating System", "%s %s (%s)",
System.getProperty("os.name"),
System.getProperty("os.version"),
System.getProperty("os.arch"));
append("Available Processors", runtime.availableProcessors());
append("Free Memory", runtime.freeMemory() / 1024 / 1024 + " MB");
append("Max Memory", runtime.maxMemory() / 1024 / 1024 + " MB");
append("Total Memory", runtime.totalMemory() / 1024 / 1024 + " MB");
}
}

View File

@ -0,0 +1,33 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.util.report;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotates properties that should not be exposed in the report.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Unreported {
}