All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sk89q.worldedit.command.util.annotation.ConfirmHandler Maven / Gradle / Ivy

Go to download

Blazingly fast Minecraft world manipulation for artists, builders and everyone else.

There is a newer version: 2.9.2
Show newest version
package com.sk89q.worldedit.command.util.annotation;

import com.fastasyncworldedit.core.configuration.Settings;
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;
import java.util.Optional;

/**
 * Logs called commands to a logger.
 */
public class ConfirmHandler implements CommandCallListener {

    @Override
    public void beforeCall(Method method, CommandParameters parameters) {
        Confirm confirmAnnotation = method.getAnnotation(Confirm.class);
        if (confirmAnnotation == null) {
            return;
        }
        Optional actorOpt = parameters.injectedValue(Key.of(Actor.class));

        if (!actorOpt.isPresent()) {
            return;
        }
        Actor actor = actorOpt.get();
        // don't check confirmation if actor doesn't need to confirm
        if (!Settings.settings().getLimit(actor).CONFIRM_LARGE) {
            return;
        }
        if (!confirmAnnotation.value().passes(actor, parameters, 1)) {
            throw new StopExecutionException(TextComponent.empty());
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy