Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-26 19:02:36 +01:00
Added RunContext parameter to Operation.resume().
Dieser Commit ist enthalten in:
Ursprung
9b564a460e
Commit
b78b086f2e
@ -25,6 +25,7 @@ import com.sk89q.worldedit.Vector;
|
|||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
import com.sk89q.worldedit.function.operation.Operation;
|
import com.sk89q.worldedit.function.operation.Operation;
|
||||||
|
import com.sk89q.worldedit.function.operation.RunContext;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -94,7 +95,7 @@ public class FastModeExtent extends ExtentDelegate {
|
|||||||
protected Operation commitBefore() {
|
protected Operation commitBefore() {
|
||||||
return new Operation() {
|
return new Operation() {
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
if (dirtyChunks.size() > 0) {
|
if (dirtyChunks.size() > 0) {
|
||||||
world.fixAfterFastMode(dirtyChunks);
|
world.fixAfterFastMode(dirtyChunks);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import com.sk89q.worldedit.extent.ExtentDelegate;
|
|||||||
import com.sk89q.worldedit.function.operation.BlockMapEntryPlacer;
|
import com.sk89q.worldedit.function.operation.BlockMapEntryPlacer;
|
||||||
import com.sk89q.worldedit.function.operation.Operation;
|
import com.sk89q.worldedit.function.operation.Operation;
|
||||||
import com.sk89q.worldedit.function.operation.OperationQueue;
|
import com.sk89q.worldedit.function.operation.OperationQueue;
|
||||||
|
import com.sk89q.worldedit.function.operation.RunContext;
|
||||||
import com.sk89q.worldedit.util.collection.TupleArrayList;
|
import com.sk89q.worldedit.util.collection.TupleArrayList;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -122,7 +123,7 @@ public class MultiStageReorder extends ExtentDelegate implements ReorderingExten
|
|||||||
private class Stage3Committer implements Operation {
|
private class Stage3Committer implements Operation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
Extent extent = getExtent();
|
Extent extent = getExtent();
|
||||||
|
|
||||||
final Set<BlockVector> blocks = new HashSet<BlockVector>();
|
final Set<BlockVector> blocks = new HashSet<BlockVector>();
|
||||||
|
@ -52,7 +52,7 @@ public class BlockMapEntryPlacer implements Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Map.Entry<BlockVector, BaseBlock> entry = iterator.next();
|
Map.Entry<BlockVector, BaseBlock> entry = iterator.next();
|
||||||
extent.setBlock(entry.getKey(), entry.getValue());
|
extent.setBlock(entry.getKey(), entry.getValue());
|
||||||
|
@ -62,7 +62,7 @@ public class ChangeSetExecutor implements Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Change change = iterator.next();
|
Change change = iterator.next();
|
||||||
if (type == Type.UNDO) {
|
if (type == Type.UNDO) {
|
||||||
|
@ -46,8 +46,8 @@ public class DelegateOperation implements Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
delegate = delegate.resume();
|
delegate = delegate.resume(run);
|
||||||
return delegate != null ? this : original;
|
return delegate != null ? this : original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ public class ForwardExtentCopy implements Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
if (lastVisitor != null) {
|
if (lastVisitor != null) {
|
||||||
affected += lastVisitor.getAffected();
|
affected += lastVisitor.getAffected();
|
||||||
lastVisitor = null;
|
lastVisitor = null;
|
||||||
|
@ -22,27 +22,30 @@ package com.sk89q.worldedit.function.operation;
|
|||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An task that may be split into multiple steps to be run sequentially immediately
|
* An task that may be split into multiple steps to be run sequentially
|
||||||
* or at a varying or fixed interval. Operations should attempt to break apart tasks
|
* immediately or at a varying or fixed interval. Operations should attempt
|
||||||
* into smaller tasks that can be completed in quicker successions.
|
* to break apart tasks into smaller tasks that can be completed in quicker
|
||||||
|
* successions.
|
||||||
*/
|
*/
|
||||||
public interface Operation {
|
public interface Operation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Complete the next step. If this method returns true, then the method may be
|
* Complete the next step. If this method returns true, then the method may
|
||||||
* called again in the future, or possibly never. If this method returns false,
|
* be called again in the future, or possibly never. If this method
|
||||||
* then this method should not be called again.
|
* returns false, then this method should not be called again.
|
||||||
*
|
*
|
||||||
|
* @param run describes information about the current run
|
||||||
* @return another operation to run that operation again, or null to stop
|
* @return another operation to run that operation again, or null to stop
|
||||||
* @throws WorldEditException an error
|
* @throws WorldEditException an error
|
||||||
*/
|
*/
|
||||||
Operation resume() throws WorldEditException;
|
Operation resume(RunContext run) throws WorldEditException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abort the current task. After the this method is called, {@link #resume()} should
|
* Abort the current task. After the this method is called,
|
||||||
* not be called at any point in the future. This method should not be called after
|
* {@link #resume(RunContext)} should not be called at any point in the
|
||||||
* successful completion of the operation. This method must be called if
|
* future. This method should not be called after successful completion of
|
||||||
* the operation is interrupted before completion.
|
* the operation. This method must be called if the operation is
|
||||||
|
* interrupted before completion.
|
||||||
*/
|
*/
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
||||||
|
@ -76,13 +76,13 @@ public class OperationQueue implements Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
if (current == null && queue.size() > 0) {
|
if (current == null && queue.size() > 0) {
|
||||||
current = queue.poll();
|
current = queue.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
current = current.resume();
|
current = current.resume(run);
|
||||||
|
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
current = queue.poll();
|
current = queue.poll();
|
||||||
|
@ -38,7 +38,7 @@ public final class Operations {
|
|||||||
*/
|
*/
|
||||||
public static void complete(Operation op) throws WorldEditException {
|
public static void complete(Operation op) throws WorldEditException {
|
||||||
while (op != null) {
|
while (op != null) {
|
||||||
op = op.resume();
|
op = op.resume(new RunContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public final class Operations {
|
|||||||
public static void completeLegacy(Operation op) throws MaxChangedBlocksException {
|
public static void completeLegacy(Operation op) throws MaxChangedBlocksException {
|
||||||
while (op != null) {
|
while (op != null) {
|
||||||
try {
|
try {
|
||||||
op = op.resume();
|
op = op.resume(new RunContext());
|
||||||
} catch (MaxChangedBlocksException e) {
|
} catch (MaxChangedBlocksException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (WorldEditException e) {
|
} catch (WorldEditException e) {
|
||||||
@ -71,7 +71,7 @@ public final class Operations {
|
|||||||
public static void completeBlindly(Operation op) {
|
public static void completeBlindly(Operation op) {
|
||||||
while (op != null) {
|
while (op != null) {
|
||||||
try {
|
try {
|
||||||
op = op.resume();
|
op = op.resume(new RunContext());
|
||||||
} catch (WorldEditException e) {
|
} catch (WorldEditException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
38
src/main/java/com/sk89q/worldedit/function/operation/RunContext.java
Normale Datei
38
src/main/java/com/sk89q/worldedit/function/operation/RunContext.java
Normale Datei
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.function.operation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the current run.
|
||||||
|
*/
|
||||||
|
public class RunContext {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether the current operation should still continue running.
|
||||||
|
* </p>
|
||||||
|
* This method can be called frequently.
|
||||||
|
*
|
||||||
|
* @return true if the operation should continue running
|
||||||
|
*/
|
||||||
|
public boolean shouldContinue() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -24,6 +24,7 @@ import com.sk89q.worldedit.Vector;
|
|||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.function.operation.Operation;
|
import com.sk89q.worldedit.function.operation.Operation;
|
||||||
import com.sk89q.worldedit.function.RegionFunction;
|
import com.sk89q.worldedit.function.RegionFunction;
|
||||||
|
import com.sk89q.worldedit.function.operation.RunContext;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -154,7 +155,7 @@ public abstract class BreadthFirstSearch implements Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
Vector position;
|
Vector position;
|
||||||
|
|
||||||
while ((position = queue.poll()) != null) {
|
while ((position = queue.poll()) != null) {
|
||||||
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.Vector2D;
|
|||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.function.FlatRegionFunction;
|
import com.sk89q.worldedit.function.FlatRegionFunction;
|
||||||
import com.sk89q.worldedit.function.operation.Operation;
|
import com.sk89q.worldedit.function.operation.Operation;
|
||||||
|
import com.sk89q.worldedit.function.operation.RunContext;
|
||||||
import com.sk89q.worldedit.regions.FlatRegion;
|
import com.sk89q.worldedit.regions.FlatRegion;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
@ -60,7 +61,7 @@ public class FlatRegionVisitor implements Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
for (Vector2D pt : flatRegion.asFlatRegion()) {
|
for (Vector2D pt : flatRegion.asFlatRegion()) {
|
||||||
if (function.apply(pt)) {
|
if (function.apply(pt)) {
|
||||||
affected++;
|
affected++;
|
||||||
|
@ -26,6 +26,7 @@ import com.sk89q.worldedit.function.LayerFunction;
|
|||||||
import com.sk89q.worldedit.function.mask.Mask2D;
|
import com.sk89q.worldedit.function.mask.Mask2D;
|
||||||
import com.sk89q.worldedit.function.mask.Masks;
|
import com.sk89q.worldedit.function.mask.Masks;
|
||||||
import com.sk89q.worldedit.function.operation.Operation;
|
import com.sk89q.worldedit.function.operation.Operation;
|
||||||
|
import com.sk89q.worldedit.function.operation.RunContext;
|
||||||
import com.sk89q.worldedit.regions.FlatRegion;
|
import com.sk89q.worldedit.regions.FlatRegion;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
@ -88,7 +89,7 @@ public class LayerVisitor implements Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
for (Vector2D column : flatRegion.asFlatRegion()) {
|
for (Vector2D column : flatRegion.asFlatRegion()) {
|
||||||
if (!mask.test(column)) {
|
if (!mask.test(column)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.Vector;
|
|||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.function.operation.Operation;
|
import com.sk89q.worldedit.function.operation.Operation;
|
||||||
import com.sk89q.worldedit.function.RegionFunction;
|
import com.sk89q.worldedit.function.RegionFunction;
|
||||||
|
import com.sk89q.worldedit.function.operation.RunContext;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +50,7 @@ public class RegionVisitor implements Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation resume() throws WorldEditException {
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
for (Vector pt : region) {
|
for (Vector pt : region) {
|
||||||
if (function.apply(pt)) {
|
if (function.apply(pt)) {
|
||||||
affected++;
|
affected++;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren