2021-07-23 15:48:51 +00:00
|
|
|
package com.sk89q.worldedit.command.util.annotation;
|
2019-11-21 06:50:37 +00:00
|
|
|
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.configuration.Settings;
|
2019-11-21 06:50:37 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
|
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
|
|
|
import org.enginehub.piston.CommandParameters;
|
|
|
|
import org.enginehub.piston.exception.StopExecutionException;
|
|
|
|
import org.enginehub.piston.gen.CommandCallListener;
|
|
|
|
import org.enginehub.piston.inject.Key;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
2020-07-14 02:50:59 +00:00
|
|
|
import java.util.Optional;
|
2019-11-21 06:50:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs called commands to a logger.
|
|
|
|
*/
|
|
|
|
public class ConfirmHandler implements CommandCallListener {
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2019-11-21 06:50:37 +00:00
|
|
|
@Override
|
|
|
|
public void beforeCall(Method method, CommandParameters parameters) {
|
|
|
|
Confirm confirmAnnotation = method.getAnnotation(Confirm.class);
|
|
|
|
if (confirmAnnotation == null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-05 05:37:42 +00:00
|
|
|
Optional<Actor> actorOpt = parameters.injectedValue(Key.of(Actor.class));
|
|
|
|
|
2023-05-12 11:12:08 +00:00
|
|
|
if (actorOpt.isEmpty()) {
|
2020-02-05 05:37:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Actor actor = actorOpt.get();
|
2020-10-22 05:28:07 +00:00
|
|
|
// don't check confirmation if actor doesn't need to confirm
|
2021-12-22 19:58:23 +00:00
|
|
|
if (!Settings.settings().getLimit(actor).CONFIRM_LARGE) {
|
2020-10-22 05:28:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-11-21 06:50:37 +00:00
|
|
|
if (!confirmAnnotation.value().passes(actor, parameters, 1)) {
|
|
|
|
throw new StopExecutionException(TextComponent.empty());
|
|
|
|
}
|
|
|
|
}
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2019-11-21 06:50:37 +00:00
|
|
|
}
|