mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
Fix some merge issues
This commit is contained in:
@ -19,9 +19,16 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class AbstractNonPlayerActor implements Actor {
|
||||
|
||||
@ -48,4 +55,61 @@ public abstract class AbstractNonPlayerActor implements Actor {
|
||||
@Override
|
||||
public void dispatchCUIEvent(CUIEvent event) {
|
||||
}
|
||||
|
||||
private final ConcurrentHashMap<String, Object> meta = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getRawMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
// Queue for async tasks
|
||||
private AtomicInteger runningCount = new AtomicInteger();
|
||||
private SimpleAsyncNotifyQueue asyncNotifyQueue = new SimpleAsyncNotifyQueue(
|
||||
(thread, throwable) -> {
|
||||
while (throwable.getCause() != null) {
|
||||
throwable = throwable.getCause();
|
||||
}
|
||||
if (throwable instanceof WorldEditException) {
|
||||
printError(throwable.getLocalizedMessage());
|
||||
} else {
|
||||
FaweException fe = FaweException.get(throwable);
|
||||
if (fe != null) {
|
||||
printError(fe.getMessage());
|
||||
} else {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Run a task either async, or on the current thread
|
||||
*
|
||||
* @param ifFree
|
||||
* @param checkFree Whether to first check if a task is running
|
||||
* @param async
|
||||
* @return false if the task was ran or queued
|
||||
*/
|
||||
@Override
|
||||
public boolean runAction(Runnable ifFree, boolean checkFree, boolean async) {
|
||||
if (checkFree) {
|
||||
if (runningCount.get() != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Runnable wrapped = () -> {
|
||||
try {
|
||||
runningCount.addAndGet(1);
|
||||
ifFree.run();
|
||||
} finally {
|
||||
runningCount.decrementAndGet();
|
||||
}
|
||||
};
|
||||
if (async) {
|
||||
asyncNotifyQueue.queue(wrapped);
|
||||
} else {
|
||||
TaskManager.IMP.taskNow(wrapped, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ public final class PlatformCommandManager {
|
||||
this.registration.register(
|
||||
commandManager,
|
||||
ClipboardCommandsRegistration.builder(),
|
||||
new ClipboardCommands(worldEdit)
|
||||
new ClipboardCommands()
|
||||
);
|
||||
this.registration.register(
|
||||
commandManager,
|
||||
@ -523,7 +523,7 @@ public final class PlatformCommandManager {
|
||||
this.registration.register(
|
||||
commandManager,
|
||||
RegionCommandsRegistration.builder(),
|
||||
new RegionCommands(worldEdit)
|
||||
new RegionCommands()
|
||||
);
|
||||
this.registration.register(
|
||||
commandManager,
|
||||
|
@ -415,7 +415,6 @@ public class PlatformManager {
|
||||
player.runAsyncIfFree(() -> reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING),
|
||||
getConfiguration(), player, session));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -429,7 +428,6 @@ public class PlatformManager {
|
||||
player.runAction(() -> reset((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING),
|
||||
getConfiguration(), player, session), false, true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,46 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.platform.binding;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.internal.annotation.Validate;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class AnnotatedBindings extends Bindings {
|
||||
|
||||
public AnnotatedBindings(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Validate()
|
||||
public String getText(String argument, Validate modifier) {
|
||||
return validate(argument, modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a string value using relevant modifiers.
|
||||
*
|
||||
* @param string the string
|
||||
* @param modifiers the list of modifiers to scan
|
||||
* @throws InputParseException on a validation error
|
||||
*/
|
||||
private static String validate(String string, Annotation... modifiers) {
|
||||
if (string != null) {
|
||||
for (Annotation modifier : modifiers) {
|
||||
if (modifier instanceof Validate) {
|
||||
Validate validate = (Validate) modifier;
|
||||
|
||||
if (!validate.value().isEmpty()) {
|
||||
if (!string.matches(validate.value())) {
|
||||
throw new InputParseException(
|
||||
String.format(
|
||||
"The given text doesn't match the right format (technically speaking, the 'format' is %s)",
|
||||
validate.value()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
@ -14,7 +14,6 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.internal.annotation.Direction;
|
||||
import com.sk89q.worldedit.internal.annotation.Validate;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
@ -10,10 +10,9 @@ import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.internal.annotation.Range;
|
||||
import com.sk89q.worldedit.internal.expression.EvaluationException;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector2;
|
||||
@ -38,19 +37,15 @@ public class PrimitiveBindings extends Bindings {
|
||||
@Binding
|
||||
public Expression getExpression(String argument) throws ExpressionException {
|
||||
try {
|
||||
return new Expression(Double.parseDouble(argument));
|
||||
} catch (NumberFormatException e1) {
|
||||
try {
|
||||
Expression expression = Expression.compile(argument);
|
||||
expression.optimize();
|
||||
return expression;
|
||||
} catch (EvaluationException e) {
|
||||
throw new InputParseException(String.format(
|
||||
"Expected '%s' to be a valid number (or a valid mathematical expression)", argument));
|
||||
} catch (ExpressionException e) {
|
||||
throw new InputParseException(String.format(
|
||||
"Expected '%s' to be a number or valid math expression (error: %s)", argument, e.getMessage()));
|
||||
}
|
||||
Expression expression = Expression.compile(argument);
|
||||
expression.optimize();
|
||||
return expression;
|
||||
} catch (EvaluationException e) {
|
||||
throw new InputParseException(String.format(
|
||||
"Expected '%s' to be a valid number (or a valid mathematical expression)", argument));
|
||||
} catch (ExpressionException e) {
|
||||
throw new InputParseException(String.format(
|
||||
"Expected '%s' to be a number or valid math expression (error: %s)", argument, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user