001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.bukkit.listener;
020
021import com.plotsquared.bukkit.util.BukkitUtil;
022import com.plotsquared.core.location.Location;
023import com.plotsquared.core.plot.Plot;
024import com.plotsquared.core.plot.flag.FlagContainer;
025import com.plotsquared.core.plot.flag.implementations.BeaconEffectsFlag;
026import org.bukkit.entity.Entity;
027import org.bukkit.event.EventHandler;
028import org.bukkit.event.Listener;
029import org.bukkit.event.entity.EntityPotionEffectEvent;
030import org.checkerframework.checker.nullness.qual.NonNull;
031
032/**
033 * Fallback listener for paper events on spigot
034 */
035public class SpigotListener implements Listener {
036
037    @EventHandler(ignoreCancelled = true)
038    public void onEffect(@NonNull EntityPotionEffectEvent event) {
039        if (event.getCause() != EntityPotionEffectEvent.Cause.BEACON) {
040            return;
041        }
042
043        Entity entity = event.getEntity();
044        Location location = BukkitUtil.adapt(entity.getLocation());
045        Plot plot = location.getPlot();
046        if (plot == null) {
047            return;
048        }
049
050        FlagContainer container = plot.getFlagContainer();
051        BeaconEffectsFlag effectsEnabled = container.getFlag(BeaconEffectsFlag.class);
052        if (effectsEnabled != null && !effectsEnabled.getValue()) {
053            event.setCancelled(true);
054        }
055    }
056
057}