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

studio.magemonkey.fabled.dynamic.trigger.ChatTrigger Maven / Gradle / Ivy

Go to download

A Minecraft Bukkit plugin aiming to provide an easy code API and skill editor for all server owners to create unique and fully custom classes and skills.

There is a newer version: 1.0.0-R1
Show newest version
package studio.magemonkey.fabled.dynamic.trigger;

import studio.magemonkey.fabled.api.CastData;
import studio.magemonkey.fabled.api.Settings;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.player.AsyncPlayerChatEvent;

/**
 * Fabled © 2024
 * studio.magemonkey.fabled.dynamic.trigger.BlockBreakTrigger
 */
public class ChatTrigger implements Trigger {

    /**
     * {@inheritDoc}
     */
    @Override
    public String getKey() {
        return "CHAT";
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Class getEvent() {
        return AsyncPlayerChatEvent.class;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean shouldTrigger(final AsyncPlayerChatEvent event, final int level, final Settings settings) {
        boolean cancelMessage = settings.getBool("cancel", false);
        boolean regex         = settings.getBool("regex", false);
        String  format        = settings.getString("format", "");
        if (regex) {
            if (!event.getMessage().matches(format)) {
                return false;
            }
        } else if (!event.getMessage().contains(format)) return false;

        event.setCancelled(cancelMessage);
        return true;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setValues(final AsyncPlayerChatEvent event, final CastData data) {
        data.put("api-message", event.getMessage());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public LivingEntity getCaster(final AsyncPlayerChatEvent event) {
        return event.getPlayer();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public LivingEntity getTarget(final AsyncPlayerChatEvent event, final Settings settings) {
        return event.getPlayer();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy