Skip to content

Add non-player WorldEdit logging support #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void wrapForLogging(EditSessionEvent event) {

Actor actor = event.getActor();
org.bukkit.World world = Bukkit.getWorld(event.getWorld().getName());
if (actor != null && actor.isPlayer() && world != null) {
if (actor != null && world != null) {
event.setExtent(new PrismWorldEditLogger(actor, event.getExtent(), world));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitBlockCommandSender;
import com.sk89q.worldedit.bukkit.BukkitCommandSender;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
Expand All @@ -18,19 +20,19 @@
import org.bukkit.block.data.BlockData;

public class PrismWorldEditLogger extends AbstractDelegateExtent {
private final Actor player;
private final Actor actor;
private final World world;

/**
* Constructor.
*
* @param player Actor
* @param actor Actor
* @param extent Extent
* @param world World
*/
public PrismWorldEditLogger(Actor player, Extent extent, World world) {
public PrismWorldEditLogger(Actor actor, Extent extent, World world) {
super(extent);
this.player = player;
this.actor = actor;
this.world = world;
}

Expand All @@ -41,8 +43,22 @@ public boolean setBlock(BlockVector3 pt, BlockStateHolder newBlock) throws World
Block oldBlock = loc.getBlock();
Material newMaterial = BukkitAdapter.adapt(newBlock.getBlockType());
BlockData newData = BukkitAdapter.adapt(newBlock);
RecordingQueue.addToQueue(ActionFactory.createBlockChange("world-edit", loc, oldBlock.getType(),
oldBlock.getBlockData(), newMaterial, newData, Bukkit.getPlayer(player.getUniqueId())));
if (actor.isPlayer()) {
RecordingQueue.addToQueue(ActionFactory.createBlockChange("world-edit", loc, oldBlock.getType(),
oldBlock.getBlockData(), newMaterial, newData, Bukkit.getPlayer(actor.getUniqueId())));
} else {
String nonPlayer;
if (actor instanceof BukkitCommandSender) {
nonPlayer = "Console";
} else if (actor instanceof BukkitBlockCommandSender) {
com.sk89q.worldedit.util.Location location = ((BukkitBlockCommandSender) actor).getBlockLocation();
nonPlayer = "Command Block(" + location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ() + ")";
} else {
nonPlayer = actor.getName();
}
RecordingQueue.addToQueue(ActionFactory.createBlockChange("world-edit", loc, oldBlock.getType(),
oldBlock.getBlockData(), newMaterial, newData, nonPlayer));
}
}
return super.setBlock(pt, newBlock);
}
Expand Down