mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
refactor: Alter handling of errors in bindings (#1395)
* Alter handling of errors in bindings - Fixes #1384 * Arbitrarily use TextComponent#of for InputParseException
This commit is contained in:
parent
806ea14ad2
commit
6df16cfe96
@ -101,11 +101,15 @@ public class Bindings {
|
||||
|
||||
@Override
|
||||
public ConversionResult<Object> convert(String s, InjectedValueAccess access) {
|
||||
Object o = invoke(s, argsFunc, access, method);
|
||||
if (o == null) {
|
||||
return FailedConversion.from(new NullPointerException());
|
||||
try {
|
||||
Object o = invoke(s, argsFunc, access, method);
|
||||
if (o == null) {
|
||||
return FailedConversion.from(new NullPointerException());
|
||||
}
|
||||
return SuccessfulConversion.fromSingle(o);
|
||||
} catch (Throwable t) {
|
||||
return FailedConversion.from(t);
|
||||
}
|
||||
return SuccessfulConversion.fromSingle(o);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import org.enginehub.piston.exception.StopExecutionException;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -49,36 +50,76 @@ public class ConsumeBindings extends Bindings {
|
||||
@Binding
|
||||
@Confirm(Confirm.Processor.REGION)
|
||||
public int regionMultiple(Actor actor, InjectedValueAccess context, @Selection Region region, String argument) {
|
||||
int times = (int) Expression.compile(argument).evaluate();
|
||||
return Confirm.Processor.REGION.check(actor, context, times);
|
||||
try {
|
||||
int times = (int) Expression.compile(argument).evaluate();
|
||||
return Confirm.Processor.REGION.check(actor, context, times);
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof StopExecutionException) { // Maintain throw from Confirm#check
|
||||
throw t;
|
||||
} else {
|
||||
throw new InputParseException(TextComponent.of(t.getMessage()), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Binding
|
||||
@Confirm(Confirm.Processor.RADIUS)
|
||||
public Integer radiusInteger(Actor actor, InjectedValueAccess context, String argument) {
|
||||
int times = (int) Expression.compile(argument).evaluate();
|
||||
return Confirm.Processor.RADIUS.check(actor, context, times);
|
||||
try {
|
||||
int times = (int) Expression.compile(argument).evaluate();
|
||||
return Confirm.Processor.RADIUS.check(actor, context, times);
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof StopExecutionException) { // Maintain throw from Confirm#check
|
||||
throw t;
|
||||
} else {
|
||||
throw new InputParseException(TextComponent.of(t.getMessage()), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Binding
|
||||
@Confirm(Confirm.Processor.LIMIT)
|
||||
public Integer limitInteger(Actor actor, InjectedValueAccess context, String argument) {
|
||||
int times = (int) Expression.compile(argument).evaluate();
|
||||
return Confirm.Processor.LIMIT.check(actor, context, times);
|
||||
try {
|
||||
int times = (int) Expression.compile(argument).evaluate();
|
||||
return Confirm.Processor.LIMIT.check(actor, context, times);
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof StopExecutionException) { // Maintain throw from Confirm#check
|
||||
throw t;
|
||||
} else {
|
||||
throw new InputParseException(TextComponent.of(t.getMessage()), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Binding
|
||||
@Confirm(Confirm.Processor.RADIUS)
|
||||
public Double radiusDouble(Actor actor, InjectedValueAccess context, String argument) {
|
||||
double times = Expression.compile(argument).evaluate();
|
||||
return Confirm.Processor.RADIUS.check(actor, context, times);
|
||||
try {
|
||||
double times = Expression.compile(argument).evaluate();
|
||||
return Confirm.Processor.RADIUS.check(actor, context, times);
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof StopExecutionException) { // Maintain throw from Confirm#check
|
||||
throw t;
|
||||
} else {
|
||||
throw new InputParseException(TextComponent.of(t.getMessage()), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Binding
|
||||
@Confirm(Confirm.Processor.LIMIT)
|
||||
public Double limitDouble(Actor actor, InjectedValueAccess context, String argument) {
|
||||
double times = Expression.compile(argument).evaluate();
|
||||
return Confirm.Processor.LIMIT.check(actor, context, times);
|
||||
try {
|
||||
double times = Expression.compile(argument).evaluate();
|
||||
return Confirm.Processor.LIMIT.check(actor, context, times);
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof StopExecutionException) { // Maintain throw from Confirm#check
|
||||
throw t;
|
||||
} else {
|
||||
throw new InputParseException(TextComponent.of(t.getMessage()), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Binding
|
||||
|
Loading…
Reference in New Issue
Block a user