Fix command logging.

No seriously, was the previous code even supposed to work?
Dieser Commit ist enthalten in:
Wizjany 2012-12-27 11:45:37 -05:00
Ursprung 6c189c4ff9
Commit 79802bd4b9
7 geänderte Dateien mit 67 neuen und 39 gelöschten Zeilen

Datei anzeigen

@ -90,6 +90,7 @@ public abstract class LocalConfiguration {
public int maxSuperPickaxeSize = 5;
public int maxBrushRadius = 6;
public boolean logCommands = false;
public String logFile = "";
public boolean registerHelp = true; // what is the point of this, it's not even used
public int wandItem = ItemID.WOOD_AXE;
public boolean superPickaxeDrop = true;

Datei anzeigen

@ -32,6 +32,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
@ -110,6 +112,7 @@ public class WorldEdit {
* Logger for debugging.
*/
public static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
public final Logger commandLogger = Logger.getLogger("Minecraft.WorldEdit.CommandLogger");
/**
* Holds the current instance of this class, for static access
@ -168,6 +171,19 @@ public class WorldEdit {
this.server = server;
this.config = config;
if (!config.logFile.equals("")) {
try {
FileHandler logFileHandler;
logFileHandler = new FileHandler(new File(config.getWorkingDirectory(),
config.logFile).getAbsolutePath(), true);
logFileHandler.setFormatter(new LogFormat());
commandLogger.addHandler(logFileHandler);
} catch (IOException e) {
logger.log(Level.WARNING, "Could not use command log file " + config.logFile + ": "
+ e.getMessage());
}
}
commands = new CommandsManager<LocalPlayer>() {
@Override
protected void checkPermission(LocalPlayer player, Method method) throws CommandException {
@ -235,7 +251,7 @@ public class WorldEdit {
break;
}
}
logger.info(msg);
commandLogger.info(msg);
}
super.invokeMethod(parent, args, player, method, instance, methodArgs, level);
}

Datei anzeigen

@ -25,18 +25,31 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.jar.JarFile;
import java.util.logging.Handler;
import java.util.zip.ZipEntry;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.wepif.PermissionsResolverManager;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.worldedit.*;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditOperation;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.bukkit.selections.*;
import com.sk89q.worldedit.regions.*;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
/**
* Plugin for Bukkit.
@ -71,6 +84,7 @@ public class WorldEditPlugin extends JavaPlugin {
/**
* Called on plugin enable.
*/
@Override
public void onEnable() {
final String pluginYmlVersion = getDescription().getVersion();
final String manifestVersion = WorldEdit.getVersion();
@ -110,6 +124,7 @@ public class WorldEditPlugin extends JavaPlugin {
/**
* Called on plugin disable.
*/
@Override
public void onDisable() {
for (Player player : getServer().getOnlinePlayers()) {
LocalPlayer lPlayer = wrapPlayer(player);
@ -118,6 +133,9 @@ public class WorldEditPlugin extends JavaPlugin {
}
}
controller.clearSessions();
for (Handler h : controller.commandLogger.getHandlers()) {
h.close();
}
config.unload();
server.unregisterCommands();
this.getServer().getScheduler().cancelTasks(this);

Datei anzeigen

@ -1,5 +1,7 @@
package com.sk89q.worldedit.commands;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -7,6 +9,7 @@ import java.util.Set;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.BiomeType;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
@ -124,6 +127,7 @@ public class BiomeCommands {
min = 1,
max = 1
)
@Logging(REGION)
@CommandPermissions("worldedit.biome.set")
public void setBiome(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {

Datei anzeigen

@ -151,6 +151,7 @@ public class RegionCommands {
min = 1,
max = 1
)
@Logging(REGION)
@CommandPermissions("worldedit.region.center")
public void center(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {

Datei anzeigen

@ -19,12 +19,16 @@
package com.sk89q.worldedit.commands;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.minecraft.util.commands.NestedCommand;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
@ -66,6 +70,7 @@ public class SnapshotUtilCommands {
min = 0,
max = 1
)
@Logging(REGION)
@CommandPermissions("worldedit.snapshots.restore")
public void restore(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {

Datei anzeigen

@ -19,18 +19,13 @@
package com.sk89q.worldedit.util;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LogFormat;
import com.sk89q.worldedit.snapshots.SnapshotRepository;
/**
@ -41,7 +36,6 @@ import com.sk89q.worldedit.snapshots.SnapshotRepository;
public class YAMLConfiguration extends LocalConfiguration {
protected final YAMLProcessor config;
protected final Logger logger;
private FileHandler logFileHandler;
public YAMLConfiguration(YAMLProcessor config, Logger logger) {
this.config = config;
@ -60,30 +54,45 @@ public class YAMLConfiguration extends LocalConfiguration {
profile = config.getBoolean("debug", profile);
wandItem = config.getInt("wand-item", wandItem);
defaultChangeLimit = Math.max(-1, config.getInt(
"limits.max-blocks-changed.default", defaultChangeLimit));
maxChangeLimit = Math.max(-1,
config.getInt("limits.max-blocks-changed.maximum", maxChangeLimit));
defaultMaxPolygonalPoints = Math.max(-1,
config.getInt("limits.max-polygonal-points.default", defaultMaxPolygonalPoints));
maxPolygonalPoints = Math.max(-1,
config.getInt("limits.max-polygonal-points.maximum", maxPolygonalPoints));
maxRadius = Math.max(-1, config.getInt("limits.max-radius", maxRadius));
maxBrushRadius = config.getInt("limits.max-brush-radius", maxBrushRadius);
maxSuperPickaxeSize = Math.max(1, config.getInt(
"limits.max-super-pickaxe-size", maxSuperPickaxeSize));
butcherDefaultRadius = Math.max(-1, config.getInt("limits.butcher-radius.default", butcherDefaultRadius));
butcherMaxRadius = Math.max(-1, config.getInt("limits.butcher-radius.maximum", butcherMaxRadius));
disallowedBlocks = new HashSet<Integer>(config.getIntList("limits.disallowed-blocks", null));
allowedDataCycleBlocks = new HashSet<Integer>(config.getIntList("limits.allowed-data-cycle-blocks", null));
allowExtraDataValues = config.getBoolean("limits.allow-extra-data-values", false);
registerHelp = config.getBoolean("register-help", true);
logCommands = config.getBoolean("logging.log-commands", logCommands);
logFile = config.getString("logging.file", logFile);
superPickaxeDrop = config.getBoolean("super-pickaxe.drop-items",
superPickaxeDrop);
superPickaxeManyDrop = config.getBoolean(
"super-pickaxe.many-drop-items", superPickaxeManyDrop);
noDoubleSlash = config.getBoolean("no-double-slash", noDoubleSlash);
useInventory = config.getBoolean("use-inventory.enable", useInventory);
useInventoryOverride = config.getBoolean("use-inventory.allow-override",
useInventoryOverride);
maxBrushRadius = config.getInt("limits.max-brush-radius", maxBrushRadius);
navigationWand = config.getInt("navigation-wand.item", navigationWand);
navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance);
@ -94,13 +103,6 @@ public class YAMLConfiguration extends LocalConfiguration {
saveDir = config.getString("saving.dir", saveDir);
allowSymlinks = config.getBoolean("files.allow-symbolic-links", false);
disallowedBlocks = new HashSet<Integer>(config.getIntList("limits.disallowed-blocks", null));
allowedDataCycleBlocks = new HashSet<Integer>(config.getIntList("limits.allowed-data-cycle-blocks", null));
allowExtraDataValues = config.getBoolean("limits.allow-extra-data-values", false);
LocalSession.MAX_HISTORY_SIZE = Math.max(0, config.getInt("history.size", 15));
LocalSession.EXPIRATION_GRACE = config.getInt("history.expiration", 10) * 60 * 1000;
@ -112,27 +114,8 @@ public class YAMLConfiguration extends LocalConfiguration {
String type = config.getString("shell-save-type", "").trim();
shellSaveType = type.equals("") ? null : type;
String logFile = config.getString("logging.file", "");
if (!logFile.equals("")) {
try {
logFileHandler = new FileHandler(new File(getWorkingDirectory(),
logFile).getAbsolutePath(), true);
logFileHandler.setFormatter(new LogFormat());
logger.addHandler(logFileHandler);
} catch (IOException e) {
logger.log(Level.WARNING, "Could not use log file " + logFile + ": "
+ e.getMessage());
}
} else {
for (Handler handler : logger.getHandlers()) {
logger.removeHandler(handler);
}
}
}
public void unload() {
if (logFileHandler != null) {
logFileHandler.close();
}
}
}