Pass LocalPlayers to the EditSession getters for easy external access

This commit is contained in:
Ammar Askar 2012-11-13 15:07:08 +05:00 committed by Wizjany
parent 94a549214d
commit 4b50e0e453
8 changed files with 42 additions and 17 deletions

View File

@ -14,6 +14,17 @@ public EditSession getEditSession(LocalWorld world, int maxBlocks) {
return new EditSession(world, maxBlocks);
}
/**
* Construct an edit session with a maximum number of blocks.
*
* @param world
* @param maxBlocks
* @param player
*/
public EditSession getEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) {
return this.getEditSession(world, maxBlocks);
}
/**
* Construct an edit session with a maximum number of blocks and a block bag.
*
@ -25,4 +36,16 @@ public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag bloc
return new EditSession(world, maxBlocks, blockBag);
}
/**
* Construct an edit session with a maximum number of blocks and a block bag.
*
* @param world
* @param maxBlocks
* @param blockBag
* @param player
*/
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
return this.getEditSession(world, maxBlocks, blockBag);
}
}

View File

@ -136,14 +136,15 @@ public void remember(EditSession editSession) {
* Performs an undo.
*
* @param newBlockBag
* @param player
* @return whether anything was undone
*/
public EditSession undo(BlockBag newBlockBag) {
public EditSession undo(BlockBag newBlockBag, LocalPlayer player) {
--historyPointer;
if (historyPointer >= 0) {
EditSession editSession = history.get(historyPointer);
EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(editSession.getWorld(), -1, newBlockBag);
.getEditSession(editSession.getWorld(), -1, newBlockBag, player);
newEditSession.enableQueue();
newEditSession.setFastMode(fastMode);
editSession.undo(newEditSession);
@ -158,13 +159,14 @@ public EditSession undo(BlockBag newBlockBag) {
* Performs a redo
*
* @param newBlockBag
* @param player
* @return whether anything was redone
*/
public EditSession redo(BlockBag newBlockBag) {
public EditSession redo(BlockBag newBlockBag, LocalPlayer player) {
if (historyPointer < history.size()) {
EditSession editSession = history.get(historyPointer);
EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(editSession.getWorld(), -1, newBlockBag);
.getEditSession(editSession.getWorld(), -1, newBlockBag, player);
newEditSession.enableQueue();
newEditSession.setFastMode(fastMode);
editSession.redo(newEditSession);
@ -700,7 +702,7 @@ public EditSession createEditSession(LocalPlayer player) {
// Create an edit session
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(player.isPlayer() ? player.getWorld() : null,
getBlockChangeLimit(), blockBag);
getBlockChangeLimit(), blockBag, player);
editSession.setFastMode(fastMode);
if (mask != null) {
mask.prepare(this, player, null);

View File

@ -239,7 +239,7 @@ public EditSession createEditSession(Player player) {
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession = controller.getEditSessionFactory()
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag);
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer);
editSession.enableQueue();
return editSession;

View File

@ -56,7 +56,7 @@ public void undo(CommandContext args, LocalSession session, LocalPlayer player,
for (int i = 0; i < times; ++i) {
EditSession undone;
if (args.argsLength() < 2) {
undone = session.undo(session.getBlockBag(player));
undone = session.undo(session.getBlockBag(player), player);
} else {
player.checkPermission("worldedit.history.undo.other");
LocalSession sess = we.getSession(args.getString(1));
@ -64,7 +64,7 @@ public void undo(CommandContext args, LocalSession session, LocalPlayer player,
player.printError("Unable to find session for " + args.getString(1));
break;
}
undone = sess.undo(session.getBlockBag(player));
undone = sess.undo(session.getBlockBag(player), player);
}
if (undone != null) {
@ -98,7 +98,7 @@ public void redo(CommandContext args, LocalSession session, LocalPlayer player,
for (int i = 0; i < times; ++i) {
EditSession redone;
if (args.argsLength() < 2) {
redone = session.redo(session.getBlockBag(player));
redone = session.redo(session.getBlockBag(player), player);
} else {
player.checkPermission("worldedit.history.redo.other");
LocalSession sess = we.getSession(args.getString(1));
@ -106,7 +106,7 @@ public void redo(CommandContext args, LocalSession session, LocalPlayer player,
player.printError("Unable to find session for " + args.getString(1));
break;
}
redone = sess.redo(session.getBlockBag(player));
redone = sess.redo(session.getBlockBag(player), player);
}
if (redone != null) {

View File

@ -62,7 +62,7 @@ public CraftScriptContext(WorldEdit controller,
public EditSession remember() {
EditSession editSession = controller.getEditSessionFactory()
.getEditSession(player.getWorld(),
session.getBlockChangeLimit(), session.getBlockBag(player));
session.getBlockChangeLimit(), session.getBlockBag(player), player);
editSession.enableQueue();
editSessions.add(editSession);
return editSession;

View File

@ -46,7 +46,7 @@ public boolean actPrimary(ServerInterface server, LocalConfiguration config,
BlockBag bag = session.getBlockBag(player);
LocalWorld world = clicked.getWorld();
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, bag);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, bag, player);
try {
editSession.setBlock(clicked, targetBlock);
@ -66,7 +66,7 @@ public boolean actSecondary(ServerInterface server,
LocalSession session, WorldVector clicked) {
LocalWorld world = clicked.getWorld();
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, player);
targetBlock = (editSession).getBlock(clicked);
BlockType type = BlockType.fromID(targetBlock.getType());

View File

@ -37,7 +37,7 @@ public boolean actPrimary(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {
LocalWorld world = clicked.getWorld();
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 0);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 0, player);
BaseBlock block = (editSession).rawGetBlock(clicked);
BlockType type = BlockType.fromID(block.getType());

View File

@ -215,7 +215,7 @@ public EditSession createEditSession(Player player) {
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag);
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer);
editSession.enableQueue();
return editSession;