3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-05 11:00:05 +01:00

Added position/region logging.

Dieser Commit ist enthalten in:
TomyLobo 2011-08-08 14:40:02 +02:00
Ursprung 6f79df8398
Commit cc917b424c
7 geänderte Dateien mit 139 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,42 @@
//$Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.minecraft.util.commands;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Indicates how the affected blocks should be hinted at in the log.
*
* @author sk89q
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface Logging {
public enum LogMode {
POSITION, // Player position
REGION, // Region selection
PLACEMENT // Either the player position or pos1, depending on the placeAtPos1 flag
}
/**
* Log mode. Can be either POSITION, REGION or PLACEMENT.
*/
LogMode value();
}

Datei anzeigen

@ -22,10 +22,15 @@ package com.sk89q.worldedit;
import java.util.*;
import java.util.logging.Logger;
import java.io.*;
import java.lang.reflect.Method;
import javax.script.ScriptException;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
import com.sk89q.minecraft.util.commands.CommandUsageException;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.minecraft.util.commands.MissingNestedCommandException;
import com.sk89q.minecraft.util.commands.UnhandledCommandException;
import com.sk89q.minecraft.util.commands.WrappedCommandException;
@ -96,7 +101,7 @@ public class WorldEdit {
* @param server
* @param config
*/
public WorldEdit(ServerInterface server, LocalConfiguration config) {
public WorldEdit(ServerInterface server, final LocalConfiguration config) {
this.server = server;
this.config = config;
@ -105,6 +110,50 @@ public class WorldEdit {
public boolean hasPermission(LocalPlayer player, String perm) {
return player.hasPermission(perm);
}
@Override
public void invokeMethod(Method parent, String[] args,
LocalPlayer player, Method method, Object instance,
Object[] methodArgs, int level) throws CommandException {
if (config.logCommands) {
final Logging loggingAnnotation = method.getAnnotation(Logging.class);
final Logging.LogMode logMode;
if (loggingAnnotation == null)
logMode = null;
else
logMode = loggingAnnotation.value();
String msg = "WorldEdit: " + player.getName() + ": " + StringUtil.joinString(args, " ");
if (logMode != null) {
Vector position = player.getPosition();
final LocalSession session = getSession(player);
switch (logMode) {
case PLACEMENT:
try {
position = session.getPlacementPosition(player);
} catch (IncompleteRegionException e) {
break;
}
/* FALL-THROUGH */
case POSITION:
msg += " - Position: "+position;
break;
case REGION:
try {
msg += " - Region: "+session.getSelection(player.getWorld());
} catch (IncompleteRegionException e) {
break;
}
break;
}
}
logger.info(msg);
}
super.invokeMethod(parent, args, player, method, instance, methodArgs, level);
}
};
commands.register(ChunkCommands.class);
@ -1062,11 +1111,6 @@ public class WorldEdit {
long start = System.currentTimeMillis();
try {
if (config.logCommands) {
logger.info("WorldEdit: " + player.getName() + ": "
+ StringUtil.joinString(split, " "));
}
commands.execute(split, player, this, session, player, editSession);
} catch (CommandPermissionsException e) {
player.printError("You don't have permission to do this.");

Datei anzeigen

@ -24,6 +24,8 @@ 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 static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.data.LegacyChunkStore;
import com.sk89q.worldedit.data.McRegionChunkStore;
@ -88,6 +90,7 @@ public class ChunkCommands {
max = 0
)
@CommandPermissions({"worldedit.delchunks"})
@Logging(REGION)
public static void deleteChunks(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {

Datei anzeigen

@ -24,6 +24,8 @@ import java.io.IOException;
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 static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.data.DataException;
@ -69,6 +71,7 @@ public class ClipboardCommands {
max = 1
)
@CommandPermissions({"worldedit.clipboard.cut"})
@Logging(REGION)
public static void cut(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -103,6 +106,7 @@ public class ClipboardCommands {
max = 0
)
@CommandPermissions({"worldedit.clipboard.paste"})
@Logging(PLACEMENT)
public static void paste(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {

Datei anzeigen

@ -22,6 +22,8 @@ package com.sk89q.worldedit.commands;
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 static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.util.TreeGenerator;
@ -40,6 +42,7 @@ public class GenerationCommands {
max = 3
)
@CommandPermissions({"worldedit.generation.cylinder"})
@Logging(PLACEMENT)
public static void hcyl(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -61,6 +64,7 @@ public class GenerationCommands {
max = 3
)
@CommandPermissions({"worldedit.generation.cylinder"})
@Logging(PLACEMENT)
public static void cyl(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -82,6 +86,7 @@ public class GenerationCommands {
max = 3
)
@CommandPermissions({"worldedit.generation.sphere"})
@Logging(PLACEMENT)
public static void hsphere(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -111,6 +116,7 @@ public class GenerationCommands {
max = 3
)
@CommandPermissions({"worldedit.generation.sphere"})
@Logging(PLACEMENT)
public static void sphere(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -140,6 +146,7 @@ public class GenerationCommands {
max = 3
)
@CommandPermissions({"worldedit.generation.forest"})
@Logging(POSITION)
public static void forestGen(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -169,6 +176,7 @@ public class GenerationCommands {
max = 1
)
@CommandPermissions({"worldedit.generation.pumpkins"})
@Logging(POSITION)
public static void pumpkins(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -187,6 +195,7 @@ public class GenerationCommands {
max = 2
)
@CommandPermissions({"worldedit.generation.pyramid"})
@Logging(PLACEMENT)
public static void pyramid(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -209,6 +218,7 @@ public class GenerationCommands {
max = 2
)
@CommandPermissions({"worldedit.generation.pyramid"})
@Logging(PLACEMENT)
public static void hpyramid(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {

Datei anzeigen

@ -19,10 +19,13 @@
package com.sk89q.worldedit.commands;
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 static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.filtering.GaussianKernel;
@ -45,6 +48,7 @@ public class RegionCommands {
max = 1
)
@CommandPermissions({"worldedit.region.set"})
@Logging(REGION)
public static void set(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -71,6 +75,7 @@ public class RegionCommands {
max = 2
)
@CommandPermissions({"worldedit.region.replace"})
@Logging(REGION)
public static void replace(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -104,6 +109,7 @@ public class RegionCommands {
max = 1
)
@CommandPermissions({"worldedit.region.overlay"})
@Logging(REGION)
public static void overlay(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -129,6 +135,7 @@ public class RegionCommands {
max = 0
)
@CommandPermissions({"worldedit.region.naturalize"})
@Logging(REGION)
public static void naturalize(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -146,6 +153,7 @@ public class RegionCommands {
max = 1
)
@CommandPermissions({"worldedit.region.walls"})
@Logging(REGION)
public static void walls(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -164,6 +172,7 @@ public class RegionCommands {
max = 1
)
@CommandPermissions({"worldedit.region.faces"})
@Logging(REGION)
public static void faces(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -181,6 +190,7 @@ public class RegionCommands {
max = 1
)
@CommandPermissions({"worldedit.region.smooth"})
@Logging(REGION)
public static void smooth(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -206,6 +216,7 @@ public class RegionCommands {
max = 3
)
@CommandPermissions({"worldedit.region.move"})
@Logging(REGION) // TODO: Add view direction
public static void move(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -251,6 +262,7 @@ public class RegionCommands {
max = 2
)
@CommandPermissions({"worldedit.region.stack"})
@Logging(REGION) // TODO: Add view direction
public static void stack(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -286,6 +298,7 @@ public class RegionCommands {
max = 0
)
@CommandPermissions({"worldedit.regen"})
@Logging(REGION)
public static void regenerateChunk(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {

Datei anzeigen

@ -19,10 +19,13 @@
package com.sk89q.worldedit.commands;
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 static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.patterns.*;
@ -43,6 +46,7 @@ public class UtilityCommands {
max = 3
)
@CommandPermissions({"worldedit.fill"})
@Logging(PLACEMENT)
public static void fill(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -72,6 +76,7 @@ public class UtilityCommands {
max = 3
)
@CommandPermissions({"worldedit.fill.recursive"})
@Logging(PLACEMENT)
public static void fillr(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -101,6 +106,7 @@ public class UtilityCommands {
max = 1
)
@CommandPermissions({"worldedit.drain"})
@Logging(PLACEMENT)
public static void drain(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -120,6 +126,7 @@ public class UtilityCommands {
max = 1
)
@CommandPermissions({"worldedit.fixlava"})
@Logging(PLACEMENT)
public static void fixLava(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -139,6 +146,7 @@ public class UtilityCommands {
max = 1
)
@CommandPermissions({"worldedit.fixwater"})
@Logging(PLACEMENT)
public static void fixWater(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -158,6 +166,7 @@ public class UtilityCommands {
max = 2
)
@CommandPermissions({"worldedit.removeabove"})
@Logging(PLACEMENT)
public static void removeAbove(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -179,6 +188,7 @@ public class UtilityCommands {
max = 2
)
@CommandPermissions({"worldedit.removebelow"})
@Logging(PLACEMENT)
public static void removeBelow(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -200,6 +210,7 @@ public class UtilityCommands {
max = 2
)
@CommandPermissions({"worldedit.removenear"})
@Logging(PLACEMENT)
public static void removeNear(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -221,6 +232,7 @@ public class UtilityCommands {
max = 3
)
@CommandPermissions({"worldedit.replacenear"})
@Logging(PLACEMENT)
public static void replaceNear(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -253,6 +265,7 @@ public class UtilityCommands {
max = 1
)
@CommandPermissions({"worldedit.snow"})
@Logging(PLACEMENT)
public static void snow(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -271,6 +284,7 @@ public class UtilityCommands {
max = 1
)
@CommandPermissions({"worldedit.thaw"})
@Logging(PLACEMENT)
public static void thaw(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -289,6 +303,7 @@ public class UtilityCommands {
max = 1
)
@CommandPermissions({"worldedit.extinguish"})
@Logging(PLACEMENT)
public static void extinguish(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -314,6 +329,7 @@ public class UtilityCommands {
max = 1
)
@CommandPermissions({"worldedit.butcher"})
@Logging(PLACEMENT)
public static void butcher(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
@ -334,6 +350,7 @@ public class UtilityCommands {
max = 2
)
@CommandPermissions({"worldedit.remove"})
@Logging(PLACEMENT)
public static void remove(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {