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.PlotArea; 025import com.plotsquared.core.plot.flag.implementations.EditSignFlag; 026import com.plotsquared.core.util.PlotFlagUtil; 027import org.bukkit.block.Sign; 028import org.bukkit.event.EventHandler; 029import org.bukkit.event.Listener; 030import org.bukkit.event.player.PlayerSignOpenEvent; 031 032/** 033 * For events since 1.20.1 034 * @since 7.2.1 035 */ 036public class PlayerEventListener1201 implements Listener { 037 038 @EventHandler(ignoreCancelled = true) 039 @SuppressWarnings({"removal", "UnstableApiUsage"}) // thanks Paper, thanks Spigot 040 public void onPlayerSignOpenEvent(PlayerSignOpenEvent event) { 041 Sign sign = event.getSign(); 042 Location location = BukkitUtil.adapt(sign.getLocation()); 043 PlotArea area = location.getPlotArea(); 044 if (area == null) { 045 return; 046 } 047 Plot plot = location.getOwnedPlot(); 048 if (plot == null) { 049 if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, EditSignFlag.class, false)) { 050 event.setCancelled(true); 051 } 052 return; 053 } 054 if (plot.isAdded(event.getPlayer().getUniqueId())) { 055 return; // allow for added players 056 } 057 if (!plot.getFlag(EditSignFlag.class)) { 058 plot.debug(event.getPlayer().getName() + " could not edit the sign because of edit-sign = false"); 059 event.setCancelled(true); 060 } 061 } 062 063}