Package wecui.event.listeners

Source Code of wecui.event.listeners.WorldEditCommandListener

package wecui.event.listeners;

import wecui.fevents.Listener;
import wecui.WorldEditCUI;
import wecui.event.ChatCommandEvent;
import wecui.event.command.CommandEventBase;
import wecui.event.command.CommandEventType;
import wecui.vendor.org.joor.Reflect;
import wecui.exception.ReflectException;

/**
* Parses outgoing commands, and checks if they match an existing command.
*
* @author lahwran
* @author yetanotherx
*
*/
public class WorldEditCommandListener implements Listener<ChatCommandEvent> {

    protected WorldEditCUI controller;

    public WorldEditCommandListener(WorldEditCUI controller) {
        this.controller = controller;
    }

    @Override
    public void onEvent(ChatCommandEvent event) {
        if (event.getArgs().length == 0) {
            return;
        }

        CommandEventType commEventType = CommandEventType.getTypeFromCommand(event.getArgs()[0]);

        if (commEventType != null) {
            try {
                CommandEventBase newEvent = Reflect.on(commEventType.getEventClass()).create(this.controller, event.getArgs()).get();
                newEvent.run();

                if (newEvent.isCancelled()) {
                    event.setCancelled(true);
                }

            } catch (ReflectException ex) {
            }

        }
    }
}
TOP

Related Classes of wecui.event.listeners.WorldEditCommandListener

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.