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