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