Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-08 04:20:06 +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.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@ -94,7 +95,7 @@ public class FastModeExtent extends ExtentDelegate {
|
||||
protected Operation commitBefore() {
|
||||
return new Operation() {
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
if (dirtyChunks.size() > 0) {
|
||||
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.Operation;
|
||||
import com.sk89q.worldedit.function.operation.OperationQueue;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
import com.sk89q.worldedit.util.collection.TupleArrayList;
|
||||
|
||||
import java.util.*;
|
||||
@ -122,7 +123,7 @@ public class MultiStageReorder extends ExtentDelegate implements ReorderingExten
|
||||
private class Stage3Committer implements Operation {
|
||||
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
Extent extent = getExtent();
|
||||
|
||||
final Set<BlockVector> blocks = new HashSet<BlockVector>();
|
||||
|
@ -52,7 +52,7 @@ public class BlockMapEntryPlacer implements Operation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<BlockVector, BaseBlock> entry = iterator.next();
|
||||
extent.setBlock(entry.getKey(), entry.getValue());
|
||||
|
@ -62,7 +62,7 @@ public class ChangeSetExecutor implements Operation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
while (iterator.hasNext()) {
|
||||
Change change = iterator.next();
|
||||
if (type == Type.UNDO) {
|
||||
|
@ -46,8 +46,8 @@ public class DelegateOperation implements Operation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
delegate = delegate.resume();
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
delegate = delegate.resume(run);
|
||||
return delegate != null ? this : original;
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ public class ForwardExtentCopy implements Operation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
if (lastVisitor != null) {
|
||||
affected += lastVisitor.getAffected();
|
||||
lastVisitor = null;
|
||||
|
@ -22,27 +22,30 @@ package com.sk89q.worldedit.function.operation;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
/**
|
||||
* An task that may be split into multiple steps to be run sequentially immediately
|
||||
* or at a varying or fixed interval. Operations should attempt to break apart tasks
|
||||
* into smaller tasks that can be completed in quicker successions.
|
||||
* An task that may be split into multiple steps to be run sequentially
|
||||
* immediately or at a varying or fixed interval. Operations should attempt
|
||||
* to break apart tasks into smaller tasks that can be completed in quicker
|
||||
* successions.
|
||||
*/
|
||||
public interface Operation {
|
||||
|
||||
/**
|
||||
* Complete the next step. If this method returns true, then the method may be
|
||||
* called again in the future, or possibly never. If this method returns false,
|
||||
* then this method should not be called again.
|
||||
* Complete the next step. If this method returns true, then the method may
|
||||
* be called again in the future, or possibly never. If this method
|
||||
* 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
|
||||
* @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
|
||||
* not be called at any point in the future. This method should not be called after
|
||||
* successful completion of the operation. This method must be called if
|
||||
* the operation is interrupted before completion.
|
||||
* Abort the current task. After the this method is called,
|
||||
* {@link #resume(RunContext)} should not be called at any point in the
|
||||
* future. This method should not be called after successful completion of
|
||||
* the operation. This method must be called if the operation is
|
||||
* interrupted before completion.
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
|
@ -76,13 +76,13 @@ public class OperationQueue implements Operation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
if (current == null && queue.size() > 0) {
|
||||
current = queue.poll();
|
||||
}
|
||||
|
||||
if (current != null) {
|
||||
current = current.resume();
|
||||
current = current.resume(run);
|
||||
|
||||
if (current == null) {
|
||||
current = queue.poll();
|
||||
|
@ -38,7 +38,7 @@ public final class Operations {
|
||||
*/
|
||||
public static void complete(Operation op) throws WorldEditException {
|
||||
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 {
|
||||
while (op != null) {
|
||||
try {
|
||||
op = op.resume();
|
||||
op = op.resume(new RunContext());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
throw e;
|
||||
} catch (WorldEditException e) {
|
||||
@ -71,7 +71,7 @@ public final class Operations {
|
||||
public static void completeBlindly(Operation op) {
|
||||
while (op != null) {
|
||||
try {
|
||||
op = op.resume();
|
||||
op = op.resume(new RunContext());
|
||||
} catch (WorldEditException 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.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -154,7 +155,7 @@ public abstract class BreadthFirstSearch implements Operation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
Vector position;
|
||||
|
||||
while ((position = queue.poll()) != null) {
|
||||
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.FlatRegionFunction;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
import com.sk89q.worldedit.regions.FlatRegion;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -60,7 +61,7 @@ public class FlatRegionVisitor implements Operation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
for (Vector2D pt : flatRegion.asFlatRegion()) {
|
||||
if (function.apply(pt)) {
|
||||
affected++;
|
||||
|
@ -26,6 +26,7 @@ import com.sk89q.worldedit.function.LayerFunction;
|
||||
import com.sk89q.worldedit.function.mask.Mask2D;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
import com.sk89q.worldedit.regions.FlatRegion;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
@ -88,7 +89,7 @@ public class LayerVisitor implements Operation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
for (Vector2D column : flatRegion.asFlatRegion()) {
|
||||
if (!mask.test(column)) {
|
||||
continue;
|
||||
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
@ -49,7 +50,7 @@ public class RegionVisitor implements Operation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation resume() throws WorldEditException {
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
for (Vector pt : region) {
|
||||
if (function.apply(pt)) {
|
||||
affected++;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren