geforkt von Mirrors/FastAsyncWorldEdit
Port history commands
Dieser Commit ist enthalten in:
Ursprung
31486cd473
Commit
20da6227d4
@ -19,20 +19,23 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.command;
|
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.EditSession;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
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 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.
|
* Commands to undo, redo, and clear history.
|
||||||
*/
|
*/
|
||||||
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.class)
|
||||||
public class HistoryCommands {
|
public class HistoryCommands {
|
||||||
|
|
||||||
private final WorldEdit worldEdit;
|
private final WorldEdit worldEdit;
|
||||||
@ -48,28 +51,29 @@ public class HistoryCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/undo", "undo" },
|
name = "undo",
|
||||||
usage = "[times] [player]",
|
aliases = { "/undo" },
|
||||||
desc = "Undoes the last action",
|
desc = "Undoes the last action (from history)"
|
||||||
min = 0,
|
|
||||||
max = 2
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.history.undo")
|
@CommandPermissions("worldedit.history.undo")
|
||||||
public void undo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
public void undo(Player player, LocalSession session,
|
||||||
int times = Math.max(1, args.getInteger(0, 1));
|
@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) {
|
for (int i = 0; i < times; ++i) {
|
||||||
EditSession undone;
|
LocalSession undoSession = session;
|
||||||
if (args.argsLength() < 2) {
|
if (playerName != null) {
|
||||||
undone = session.undo(session.getBlockBag(player), player);
|
|
||||||
} else {
|
|
||||||
player.checkPermission("worldedit.history.undo.other");
|
player.checkPermission("worldedit.history.undo.other");
|
||||||
LocalSession sess = worldEdit.getSessionManager().findByName(args.getString(1));
|
LocalSession sess = worldEdit.getSessionManager().findByName(playerName);
|
||||||
if (sess == null) {
|
if (sess == null) {
|
||||||
player.printError("Unable to find session for " + args.getString(1));
|
player.printError("Unable to find session for " + playerName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
undone = sess.undo(session.getBlockBag(player), player);
|
undoSession = session;
|
||||||
}
|
}
|
||||||
|
EditSession undone = undoSession.undo(undoSession.getBlockBag(player), player);
|
||||||
if (undone != null) {
|
if (undone != null) {
|
||||||
player.print("Undo successful.");
|
player.print("Undo successful.");
|
||||||
worldEdit.flushBlockBag(player, undone);
|
worldEdit.flushBlockBag(player, undone);
|
||||||
@ -81,45 +85,43 @@ public class HistoryCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/redo", "redo" },
|
name = "redo",
|
||||||
usage = "[times] [player]",
|
aliases = { "redo" },
|
||||||
desc = "Redoes the last action (from history)",
|
desc = "Redoes the last action (from history)"
|
||||||
min = 0,
|
|
||||||
max = 2
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.history.redo")
|
@CommandPermissions("worldedit.history.redo")
|
||||||
public void redo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
public void redo(Player player, LocalSession session,
|
||||||
|
@Arg(desc = "Number of redoes to perform", def = "1")
|
||||||
int times = Math.max(1, args.getInteger(0, 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) {
|
for (int i = 0; i < times; ++i) {
|
||||||
EditSession redone;
|
LocalSession redoSession = session;
|
||||||
if (args.argsLength() < 2) {
|
if (playerName != null) {
|
||||||
redone = session.redo(session.getBlockBag(player), player);
|
|
||||||
} else {
|
|
||||||
player.checkPermission("worldedit.history.redo.other");
|
player.checkPermission("worldedit.history.redo.other");
|
||||||
LocalSession sess = worldEdit.getSessionManager().findByName(args.getString(1));
|
LocalSession sess = worldEdit.getSessionManager().findByName(playerName);
|
||||||
if (sess == null) {
|
if (sess == null) {
|
||||||
player.printError("Unable to find session for " + args.getString(1));
|
player.printError("Unable to find session for " + playerName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
redone = sess.redo(session.getBlockBag(player), player);
|
redoSession = session;
|
||||||
}
|
}
|
||||||
|
EditSession redone = redoSession.redo(redoSession.getBlockBag(player), player);
|
||||||
if (redone != null) {
|
if (redone != null) {
|
||||||
player.print("Redo successful.");
|
player.print("Redo successful.");
|
||||||
worldEdit.flushBlockBag(player, redone);
|
worldEdit.flushBlockBag(player, redone);
|
||||||
} else {
|
} else {
|
||||||
player.printError("Nothing left to redo.");
|
player.printError("Nothing left to redo.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/clearhistory", "clearhistory" },
|
name = "clearhistory",
|
||||||
usage = "",
|
aliases = { "/clearhistory" },
|
||||||
desc = "Clear your history",
|
desc = "Clear your history"
|
||||||
min = 0,
|
|
||||||
max = 0
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.history.clear")
|
@CommandPermissions("worldedit.history.clear")
|
||||||
public void clearHistory(Player player, LocalSession session) throws WorldEditException {
|
public void clearHistory(Player player, LocalSession session) throws WorldEditException {
|
||||||
|
@ -38,6 +38,8 @@ import com.sk89q.worldedit.command.GeneralCommands;
|
|||||||
import com.sk89q.worldedit.command.GeneralCommandsRegistration;
|
import com.sk89q.worldedit.command.GeneralCommandsRegistration;
|
||||||
import com.sk89q.worldedit.command.GenerationCommands;
|
import com.sk89q.worldedit.command.GenerationCommands;
|
||||||
import com.sk89q.worldedit.command.GenerationCommandsRegistration;
|
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.SchematicCommands;
|
||||||
import com.sk89q.worldedit.command.SchematicCommandsRegistration;
|
import com.sk89q.worldedit.command.SchematicCommandsRegistration;
|
||||||
import com.sk89q.worldedit.command.argument.Arguments;
|
import com.sk89q.worldedit.command.argument.Arguments;
|
||||||
@ -277,6 +279,11 @@ public final class PlatformCommandMananger {
|
|||||||
GenerationCommandsRegistration.builder(),
|
GenerationCommandsRegistration.builder(),
|
||||||
new GenerationCommands(worldEdit)
|
new GenerationCommands(worldEdit)
|
||||||
);
|
);
|
||||||
|
register(
|
||||||
|
commandManager,
|
||||||
|
HistoryCommandsRegistration.builder(),
|
||||||
|
new HistoryCommands(worldEdit)
|
||||||
|
);
|
||||||
|
|
||||||
// Unported commands are below. Delete once they're added to the main manager above.
|
// Unported commands are below. Delete once they're added to the main manager above.
|
||||||
/*
|
/*
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren