Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private boolean register(Method method, InjectedValueStore store, CommandManager

// If the method provides all parameters
if (provide) {
store.injectValue(key, access -> Optional.of(invoke(null, argsFunc, access, method)));
store.injectValue(key, access -> Optional.ofNullable(invoke(null, argsFunc, access, method)));
} else { // If the method consumes a String argument
manager.registerConverter(key, new ArgumentConverter<Object>() {
@Override
Expand Down Expand Up @@ -129,7 +129,7 @@ private Object invoke(
Function<InjectedValueAccess, Object> func = argsFunc[i];
if (func != null) {
Optional optional = (Optional) func.apply(access);
args[i] = optional.get();
args[i] = optional.orElse(null);
} else {
args[i] = arg;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.fastasyncworldedit.core.util.TextureUtil;
import com.fastasyncworldedit.core.util.image.ImageUtil;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.argument.Arguments;
Expand Down Expand Up @@ -91,7 +92,11 @@ public EditSession editSession(LocalSession localSession, Actor actor, InjectedV
@Selection
@Binding
public Region selection(LocalSession localSession) {
return localSession.getSelection();
try {
return localSession.getSelection();
} catch (IncompleteRegionException ignore) {
return null;
}
}

@Binding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ public void update(@Nonnull Actor actor, @Nonnull World world) {
MutablePair<World, Set<BlockVector2>> existing = cancelAndGet(actor);
try {
Region region = session.getSelection(world);
if (region == null) {
return;
}
if (existing == null) {
update.put(
actor.getUniqueId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void biomeInfo(
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@SynchronousSettingExpected // TODO improve using filter/chunk-based-placement
@Confirm(Confirm.Processor.REGION)
@Confirm(Confirm.Processor.NULLABLE_REGION)
@CommandPermissions("worldedit.biome.set")
public void setBiome(
Actor actor, World world, LocalSession session, EditSession editSession,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.internal.command.CommandArgParser;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.internal.util.Substring;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.apache.logging.log4j.Logger;
import org.enginehub.piston.exception.StopExecutionException;
import org.enginehub.piston.inject.InjectAnnotation;
import org.enginehub.piston.inject.InjectedValueAccess;
Expand Down Expand Up @@ -45,6 +47,21 @@
Processor value() default Processor.ALWAYS;

enum Processor {
NULLABLE_REGION {
@Override
public boolean passes(Actor actor, InjectedValueAccess context, double value) {
if (checkExisting(context)) {
return true;
}
Region region = context
.injectedValue(Key.of(Region.class, Selection.class))
.orElse(null);
if (region == null) {
return true;
}
return handleRegion(region, actor, context, value);
}
},
REGION {
@Override
public boolean passes(Actor actor, InjectedValueAccess context, double value) {
Expand All @@ -54,18 +71,7 @@ public boolean passes(Actor actor, InjectedValueAccess context, double value) {
Region region = context
.injectedValue(Key.of(Region.class, Selection.class))
.orElseThrow(IncompleteRegionException::new);
BlockVector3 pos1 = region.getMinimumPoint();
BlockVector3 pos2 = region.getMaximumPoint();
long area = (pos2.x() - pos1.x()) * (pos2.z() - pos1.z() + 1)
* (long) value;
long max = 2 << 18;
if (max != -1 && area > max) {
actor.print(Caption.of("fawe.cancel.reason.confirm.region",
pos1, pos2, getArgs(context), region.getHeight() * area
));
return confirm(actor, context);
}
return true;
return handleRegion(region, actor, context, value);
}
},
RADIUS {
Expand Down Expand Up @@ -111,6 +117,8 @@ public boolean passes(Actor actor, InjectedValueAccess context, double value) {
}
};

private static final Logger LOGGER = LogManagerCompat.getLogger();

public boolean passes(Actor actor, InjectedValueAccess context, double value) {
return true;
}
Expand Down Expand Up @@ -171,7 +179,7 @@ private static boolean confirm(Actor actor, InjectedValueAccess context) {
Map<Key<?>, Optional<?>> memory = (Map<Key<?>, Optional<?>>) Reflect.memory.get(memoizingValueAccess);
memory.put(Key.of(InterruptableCondition.class), Optional.of(wait));
} catch (IllegalAccessException e) {
e.printStackTrace();
LOGGER.error("Error confirming command", e);
}
// Waits till 15 seconds then returns false unless awakened
if (condition.await(15, TimeUnit.SECONDS)) {
Expand All @@ -192,10 +200,27 @@ boolean checkExisting(InjectedValueAccess context) {
// in which case this is the least of our worries...
return lock.isPresent();
}

private static boolean handleRegion(Region region, Actor actor, InjectedValueAccess context, double value) {
BlockVector3 pos1 = region.getMinimumPoint();
BlockVector3 pos2 = region.getMaximumPoint();
long area = (pos2.x() - pos1.x()) * (pos2.z() - pos1.z() + 1)
* (long) value;
long max = 2 << 18;
if (max != -1 && area > max) {
actor.print(Caption.of("fawe.cancel.reason.confirm.region",
pos1, pos2, getArgs(context), region.getHeight() * area
));
return confirm(actor, context);
}
return true;
}
}

class Reflect {

private static final Logger LOGGER = LogManagerCompat.getLogger();

static final Field memory;
static final Field injectedValues;

Expand All @@ -205,7 +230,7 @@ class Reflect {
memoryField = MemoizingValueAccess.class.getDeclaredField("memory");
memoryField.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
LOGGER.error("Could not find memory field", e);
memoryField = null;
}
memory = memoryField;
Expand All @@ -216,7 +241,7 @@ class Reflect {
injectedValuesField = c.getDeclaredField("injectedValues");
injectedValuesField.setAccessible(true);
} catch (NoSuchFieldException | ClassNotFoundException e) {
e.printStackTrace();
LOGGER.error("Could not find injectedValues field", e);
injectedValuesField = null;
}
injectedValues = injectedValuesField;
Expand Down
Loading