Fixed undo/redo not working from console/commandblock

65fbe09c35e9affa71d0ce7c20fa5ebd0f1c8365

Co-Authored-By: Matthew Miller <mnmiller1@me.com>
This commit is contained in:
N0tMyFaultOG 2020-11-13 22:25:47 +01:00
parent cb088ff3e5
commit a32b4a1345

View File

@ -28,6 +28,7 @@ import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.annotation.Confirm; import com.sk89q.worldedit.command.util.annotation.Confirm;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
@ -60,7 +61,7 @@ public class HistoryCommands {
desc = "Undoes the last action (from history)" desc = "Undoes the last action (from history)"
) )
@CommandPermissions({"worldedit.history.undo", "worldedit.history.undo.self"}) @CommandPermissions({"worldedit.history.undo", "worldedit.history.undo.self"})
public void undo(Player player, LocalSession session, public void undo(Actor actor, LocalSession session,
@Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of undoes to perform", def = "1") @Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of undoes to perform", def = "1")
int times, int times,
@Arg(name = "player", desc = "Undo this player's operations", def = "") @Arg(name = "player", desc = "Undo this player's operations", def = "")
@ -68,31 +69,32 @@ public class HistoryCommands {
times = Math.max(1, times); times = Math.max(1, times);
LocalSession undoSession = session; LocalSession undoSession = session;
if (session.hasFastMode()) { if (session.hasFastMode()) {
player.print(TranslatableComponent.of("fawe.worldedit.history.command.undo.disabled")); actor.print(TranslatableComponent.of("fawe.worldedit.history.command.undo.disabled"));
return; return;
} }
if (playerName != null) { if (playerName != null) {
player.checkPermission("worldedit.history.undo.other"); actor.checkPermission("worldedit.history.undo.other");
undoSession = worldEdit.getSessionManager().findByName(playerName); undoSession = worldEdit.getSessionManager().findByName(playerName);
if (undoSession == null) { if (undoSession == null) {
player.printError(TranslatableComponent.of("worldedit.session.cant-find-session", TextComponent.of(playerName))); actor.printError(TranslatableComponent.of("worldedit.session.cant-find-session", TextComponent.of(playerName)));
return; return;
} }
} }
int timesUndone = 0; int timesUndone = 0;
for (int i = 0; i < times; ++i) { for (int i = 0; i < times; ++i) {
EditSession undone = undoSession.undo(undoSession.getBlockBag(player), player); BlockBag blockBag = actor instanceof Player ? undoSession.getBlockBag((Player) actor) : null;
EditSession undone = undoSession.undo(blockBag, actor);
if (undone != null) { if (undone != null) {
timesUndone++; timesUndone++;
worldEdit.flushBlockBag(player, undone); worldEdit.flushBlockBag(actor, undone);
} else { } else {
break; break;
} }
} }
if (timesUndone > 0) { if (timesUndone > 0) {
player.printInfo(TranslatableComponent.of("worldedit.undo.undone", TextComponent.of(timesUndone))); actor.printInfo(TranslatableComponent.of("worldedit.undo.undone", TextComponent.of(timesUndone)));
} else { } else {
player.printError(TranslatableComponent.of("worldedit.undo.none")); actor.printError(TranslatableComponent.of("worldedit.undo.none"));
} }
} }
@ -102,7 +104,7 @@ public class HistoryCommands {
desc = "Redoes the last action (from history)" desc = "Redoes the last action (from history)"
) )
@CommandPermissions({"worldedit.history.redo", "worldedit.history.redo.self"}) @CommandPermissions({"worldedit.history.redo", "worldedit.history.redo.self"})
public void redo(Player player, LocalSession session, public void redo(Actor actor, LocalSession session,
@Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of redoes to perform", def = "1") @Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of redoes to perform", def = "1")
int times, int times,
@Arg(name = "player", desc = "Redo this player's operations", def = "") @Arg(name = "player", desc = "Redo this player's operations", def = "")
@ -110,27 +112,28 @@ public class HistoryCommands {
times = Math.max(1, times); times = Math.max(1, times);
LocalSession redoSession = session; LocalSession redoSession = session;
if (playerName != null) { if (playerName != null) {
player.checkPermission("worldedit.history.redo.other"); actor.checkPermission("worldedit.history.redo.other");
redoSession = worldEdit.getSessionManager().findByName(playerName); redoSession = worldEdit.getSessionManager().findByName(playerName);
if (redoSession == null) { if (redoSession == null) {
player.printError(TranslatableComponent.of("worldedit.session.cant-find-session", TextComponent.of(playerName))); actor.printError(TranslatableComponent.of("worldedit.session.cant-find-session", TextComponent.of(playerName)));
return; return;
} }
} }
int timesRedone = 0; int timesRedone = 0;
for (int i = 0; i < times; ++i) { for (int i = 0; i < times; ++i) {
EditSession redone = redoSession.redo(redoSession.getBlockBag(player), player); BlockBag blockBag = actor instanceof Player ? redoSession.getBlockBag((Player) actor) : null;
EditSession redone = redoSession.redo(blockBag, actor);
if (redone != null) { if (redone != null) {
timesRedone++; timesRedone++;
worldEdit.flushBlockBag(player, redone); worldEdit.flushBlockBag(actor, redone);
} else { } else {
break; break;
} }
} }
if (timesRedone > 0) { if (timesRedone > 0) {
player.printInfo(TranslatableComponent.of("worldedit.redo.redone", TextComponent.of(timesRedone))); actor.printInfo(TranslatableComponent.of("worldedit.redo.redone", TextComponent.of(timesRedone)));
} else { } else {
player.printError(TranslatableComponent.of("worldedit.redo.none")); actor.printError(TranslatableComponent.of("worldedit.redo.none"));
} }
} }