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

Port history commands

Dieser Commit ist enthalten in:
Kenzie Togami 2019-04-23 15:35:05 -07:00
Ursprung 31486cd473
Commit 20da6227d4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81
2 geänderte Dateien mit 49 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -19,20 +19,23 @@
package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.entity.Player;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Commands to undo, redo, and clear history.
*/
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.class)
public class HistoryCommands {
private final WorldEdit worldEdit;
@ -48,28 +51,29 @@ public class HistoryCommands {
}
@Command(
aliases = { "/undo", "undo" },
usage = "[times] [player]",
desc = "Undoes the last action",
min = 0,
max = 2
name = "undo",
aliases = { "/undo" },
desc = "Undoes the last action (from history)"
)
@CommandPermissions("worldedit.history.undo")
public void undo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
int times = Math.max(1, args.getInteger(0, 1));
public void undo(Player player, LocalSession session,
@Arg(desc = "Number of undoes to perform", def = "1")
int times,
@Arg(name = "player", desc = "Undo this player's operations", def = "")
String playerName) throws WorldEditException {
times = Math.max(1, times);
for (int i = 0; i < times; ++i) {
EditSession undone;
if (args.argsLength() < 2) {
undone = session.undo(session.getBlockBag(player), player);
} else {
LocalSession undoSession = session;
if (playerName != null) {
player.checkPermission("worldedit.history.undo.other");
LocalSession sess = worldEdit.getSessionManager().findByName(args.getString(1));
LocalSession sess = worldEdit.getSessionManager().findByName(playerName);
if (sess == null) {
player.printError("Unable to find session for " + args.getString(1));
player.printError("Unable to find session for " + playerName);
break;
}
undone = sess.undo(session.getBlockBag(player), player);
undoSession = session;
}
EditSession undone = undoSession.undo(undoSession.getBlockBag(player), player);
if (undone != null) {
player.print("Undo successful.");
worldEdit.flushBlockBag(player, undone);
@ -81,45 +85,43 @@ public class HistoryCommands {
}
@Command(
aliases = { "/redo", "redo" },
usage = "[times] [player]",
desc = "Redoes the last action (from history)",
min = 0,
max = 2
name = "redo",
aliases = { "redo" },
desc = "Redoes the last action (from history)"
)
@CommandPermissions("worldedit.history.redo")
public void redo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
int times = Math.max(1, args.getInteger(0, 1));
public void redo(Player player, LocalSession session,
@Arg(desc = "Number of redoes to perform", def = "1")
int times,
@Arg(name = "player", desc = "Redo this player's operations", def = "")
String playerName) throws WorldEditException {
times = Math.max(1, times);
for (int i = 0; i < times; ++i) {
EditSession redone;
if (args.argsLength() < 2) {
redone = session.redo(session.getBlockBag(player), player);
} else {
LocalSession redoSession = session;
if (playerName != null) {
player.checkPermission("worldedit.history.redo.other");
LocalSession sess = worldEdit.getSessionManager().findByName(args.getString(1));
LocalSession sess = worldEdit.getSessionManager().findByName(playerName);
if (sess == null) {
player.printError("Unable to find session for " + args.getString(1));
player.printError("Unable to find session for " + playerName);
break;
}
redone = sess.redo(session.getBlockBag(player), player);
redoSession = session;
}
EditSession redone = redoSession.redo(redoSession.getBlockBag(player), player);
if (redone != null) {
player.print("Redo successful.");
worldEdit.flushBlockBag(player, redone);
} else {
player.printError("Nothing left to redo.");
break;
}
}
}
@Command(
aliases = { "/clearhistory", "clearhistory" },
usage = "",
desc = "Clear your history",
min = 0,
max = 0
name = "clearhistory",
aliases = { "/clearhistory" },
desc = "Clear your history"
)
@CommandPermissions("worldedit.history.clear")
public void clearHistory(Player player, LocalSession session) throws WorldEditException {

Datei anzeigen

@ -38,6 +38,8 @@ import com.sk89q.worldedit.command.GeneralCommands;
import com.sk89q.worldedit.command.GeneralCommandsRegistration;
import com.sk89q.worldedit.command.GenerationCommands;
import com.sk89q.worldedit.command.GenerationCommandsRegistration;
import com.sk89q.worldedit.command.HistoryCommands;
import com.sk89q.worldedit.command.HistoryCommandsRegistration;
import com.sk89q.worldedit.command.SchematicCommands;
import com.sk89q.worldedit.command.SchematicCommandsRegistration;
import com.sk89q.worldedit.command.argument.Arguments;
@ -277,6 +279,11 @@ public final class PlatformCommandMananger {
GenerationCommandsRegistration.builder(),
new GenerationCommands(worldEdit)
);
register(
commandManager,
HistoryCommandsRegistration.builder(),
new HistoryCommands(worldEdit)
);
// Unported commands are below. Delete once they're added to the main manager above.
/*