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

com.jgcomptech.tools.events.PermissionEvent Maven / Gradle / Ivy

package com.jgcomptech.tools.events;

import com.jgcomptech.tools.permissions.Permission;

import java.util.List;

/**
 * A {@link Event} for use with user {@link Permission} objects.
 * @since 1.4.0
 */
public class PermissionEvent extends Event {
    private Permission permission;
    public Permission getPermission() { return permission; }
    /** Common supertype for all permission event types. */
    public static final EventType ANY = new EventType<>(Event.ANY, "PERMISSION");

    public static final EventType PERMISSION_ENABLED = ANY.createSubType("PERMISSION_ENABLED");

    public static final EventType PERMISSION_DISABLED = ANY.createSubType("PERMISSION_DISABLED");

    public static final EventType PERMISSIONS_APPLIED = ANY.createSubType("PERMISSIONS_APPLIED");

    public static final EventType PERMISSIONS_ALL_ENABLED =
            ANY.createSubType("PERMISSIONS_ALL_ENABLED");

    public static final EventType PERMISSIONS_ALL_DISABLED =
            ANY.createSubType("PERMISSIONS_ALL_DISABLED");

    /**
     * Construct a new {@code Event} with the specified event target, type and args.
     * @param target    the event target to associate with the event
     * @param eventType the event type
     * @param args      arguments to make available to the EventHandler
     */
    public PermissionEvent(final EventTarget target,
                           final EventType eventType,
                           final List args) {
        super(target, eventType, args);
    }

    @Override
    public EventType getEventType() {
        return (EventType) super.getEventType();
    }

    @Override
    public PermissionEvent copyFor(final Object newSource, final EventTarget newTarget) {
        return (PermissionEvent) super.copyFor(newSource, newTarget);
    }

    /**
     * Fires the event with the specified source and permission.
     *
     * @param source      the event source which sent the event
     * @param permission  the permission object to pass to the EventHandler
     */
    public void fireEvent(final Object source, final Permission permission) {
        this.permission = permission;
        setSource(source);
       super.fireEvent(source);
    }
}