From ef88851ac9128a870b07fc27702cfa047d401f89 Mon Sep 17 00:00:00 2001 From: SirYwell Date: Fri, 11 Aug 2023 09:33:05 +0200 Subject: [PATCH] Move event to versioned class --- .../plotsquared/bukkit/BukkitPlatform.java | 4 ++ .../bukkit/listener/PlayerEventListener.java | 28 --------- .../listener/PlayerEventListener120.java | 62 +++++++++++++++++++ .../flag/implementations/EditSignFlag.java | 18 ++++++ 4 files changed, 84 insertions(+), 28 deletions(-) create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener120.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 38a4e682a..b6eb64c0d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -37,6 +37,7 @@ import com.plotsquared.bukkit.listener.EntityEventListener; import com.plotsquared.bukkit.listener.EntitySpawnListener; import com.plotsquared.bukkit.listener.PaperListener; import com.plotsquared.bukkit.listener.PlayerEventListener; +import com.plotsquared.bukkit.listener.PlayerEventListener120; import com.plotsquared.bukkit.listener.ProjectileEventListener; import com.plotsquared.bukkit.listener.ServerListener; import com.plotsquared.bukkit.listener.SingleWorldListener; @@ -358,6 +359,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl if (Settings.Enabled_Components.EVENTS) { getServer().getPluginManager().registerEvents(injector().getInstance(PlayerEventListener.class), this); + if ((serverVersion()[1] == 20 && serverVersion()[2] >= 1) || serverVersion()[1] > 20) { + getServer().getPluginManager().registerEvents(injector().getInstance(PlayerEventListener120.class), this); + } getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener.class), this); if (serverVersion()[1] >= 17) { getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener117.class), this); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index 33b4108f7..ab3fb5819 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -50,7 +50,6 @@ import com.plotsquared.core.plot.flag.implementations.DenyPortalsFlag; import com.plotsquared.core.plot.flag.implementations.DenyTeleportFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.DropProtectionFlag; -import com.plotsquared.core.plot.flag.implementations.EditSignFlag; import com.plotsquared.core.plot.flag.implementations.HangingBreakFlag; import com.plotsquared.core.plot.flag.implementations.HangingPlaceFlag; import com.plotsquared.core.plot.flag.implementations.HostileInteractFlag; @@ -88,7 +87,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; import org.bukkit.block.data.Waterlogged; import org.bukkit.command.PluginCommand; import org.bukkit.entity.ArmorStand; @@ -133,7 +131,6 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerSignOpenEvent; import org.bukkit.event.player.PlayerTakeLecternBookEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; @@ -1875,29 +1872,4 @@ public class PlayerEventListener implements Listener { event.setCancelled(true); } } - - @EventHandler(ignoreCancelled = true) - @SuppressWarnings({"removal", "UnstableApiUsage"}) // thanks Paper, thanks Spigot - public void onPlayerSignOpenEvent(PlayerSignOpenEvent event) { - Sign sign = event.getSign(); - Location location = BukkitUtil.adapt(sign.getLocation()); - PlotArea area = location.getPlotArea(); - if (area == null) { - return; - } - Plot plot = location.getOwnedPlot(); - if (plot == null) { - if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, EditSignFlag.class, false)) { - event.setCancelled(true); - } - return; - } - if (plot.isAdded(event.getPlayer().getUniqueId())) { - return; // allow for added players - } - if (!plot.getFlag(EditSignFlag.class)) { - plot.debug(event.getPlayer().getName() + " could not edit the sign because of edit-sign = false"); - event.setCancelled(true); - } - } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener120.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener120.java new file mode 100644 index 000000000..0cf9e7811 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener120.java @@ -0,0 +1,62 @@ +/* + * PlotSquared, a land and world management plugin for Minecraft. + * Copyright (C) IntellectualSites + * Copyright (C) IntellectualSites team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.bukkit.listener; + +import org.bukkit.block.Sign; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerSignOpenEvent; +import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.core.location.Location; +import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.flag.implementations.EditSignFlag; +import com.plotsquared.core.util.PlotFlagUtil; + +/** + * For events since 1.20.1 + */ +public class PlayerEventListener120 implements Listener { + + @EventHandler(ignoreCancelled = true) + @SuppressWarnings({"removal", "UnstableApiUsage"}) // thanks Paper, thanks Spigot + public void onPlayerSignOpenEvent(PlayerSignOpenEvent event) { + Sign sign = event.getSign(); + Location location = BukkitUtil.adapt(sign.getLocation()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = location.getOwnedPlot(); + if (plot == null) { + if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, EditSignFlag.class, false)) { + event.setCancelled(true); + } + return; + } + if (plot.isAdded(event.getPlayer().getUniqueId())) { + return; // allow for added players + } + if (!plot.getFlag(EditSignFlag.class)) { + plot.debug(event.getPlayer().getName() + " could not edit the sign because of edit-sign = false"); + event.setCancelled(true); + } + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EditSignFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EditSignFlag.java index 3464f753f..90db7fc46 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EditSignFlag.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EditSignFlag.java @@ -1,3 +1,21 @@ +/* + * PlotSquared, a land and world management plugin for Minecraft. + * Copyright (C) IntellectualSites + * Copyright (C) IntellectualSites team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.plotsquared.core.plot.flag.implementations; import com.plotsquared.core.configuration.caption.TranslatableCaption;