From a93402e27bb7a9ae123c7fe349b5a8a51430184a Mon Sep 17 00:00:00 2001 From: zombachu Date: Fri, 17 Dec 2021 16:06:56 -0500 Subject: [PATCH] fix: Standardize projectile permissions (#3374) * fix: Standardize projectile permissions - Let all projectiles (not just splash potions) have a permissions check on throwing - Fixes snowballs, eggs, etc. being able to be thrown when not added to the plot, etc. - Fixes #2986 (splash potions only able being to be thrown when also added to the plot) - Remove the specialized code for egg hatching as now eggs are cancelled entirely - Remove the non-standard plots.projectile.unowned and plots.projectile.other permissions in favor of the standard admin ones * docs: Add back deprecated projectile permissions * docs: Update Core/src/main/java/com/plotsquared/core/permissions/Permission.java Co-authored-by: Alex Co-authored-by: Alex --- .../bukkit/listener/EntityEventListener.java | 4 +- .../bukkit/listener/PaperListener.java | 39 ++++++++++++++---- .../bukkit/listener/PlayerEventListener.java | 38 ------------------ .../listener/ProjectileEventListener.java | 40 +++++++++++++++---- .../core/permissions/Permission.java | 2 + 5 files changed, 67 insertions(+), 56 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java index 826aef2a2..d97b23d02 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java @@ -371,14 +371,14 @@ public class EntityEventListener implements Listener { if (shooter instanceof Player) { PlotPlayer pp = BukkitUtil.adapt((Player) shooter); if (plot == null) { - if (!Permissions.hasPermission(pp, Permission.PERMISSION_PROJECTILE_UNOWNED)) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) { entity.remove(); event.setCancelled(true); } return; } if (plot.isAdded(pp.getUUID()) || Permissions - .hasPermission(pp, Permission.PERMISSION_PROJECTILE_OTHER)) { + .hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { return; } entity.remove(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java index c53c25b80..069927326 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java @@ -39,11 +39,13 @@ import com.plotsquared.core.command.MainCommand; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.location.Location; +import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.world.PlotAreaManager; +import com.plotsquared.core.util.Permissions; import net.kyori.adventure.text.minimessage.Template; import org.bukkit.Chunk; import org.bukkit.block.Block; @@ -53,7 +55,6 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.Slime; -import org.bukkit.entity.ThrownPotion; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -321,9 +322,6 @@ public class PaperListener implements Listener { return; } Projectile entity = event.getProjectile(); - if (!(entity instanceof ThrownPotion)) { - return; - } ProjectileSource shooter = entity.getShooter(); if (!(shooter instanceof Player)) { return; @@ -332,11 +330,36 @@ public class PaperListener implements Listener { if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { return; } - PlotPlayer pp = BukkitUtil.adapt((Player) shooter); + PlotPlayer pp = BukkitUtil.adapt((Player) shooter); Plot plot = location.getOwnedPlot(); - if (plot != null && !plot.isAdded(pp.getUUID())) { - entity.remove(); - event.setCancelled(true); + + if (plot == null) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) { + pp.sendMessage( + TranslatableCaption.of("permission.no_permission_event"), + Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) + ); + entity.remove(); + event.setCancelled(true); + } + } else if (!plot.hasOwner()) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) { + pp.sendMessage( + TranslatableCaption.of("permission.no_permission_event"), + Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) + ); + entity.remove(); + event.setCancelled(true); + } + } else if (!plot.isAdded(pp.getUUID())) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { + pp.sendMessage( + TranslatableCaption.of("permission.no_permission_event"), + Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) + ); + entity.remove(); + event.setCancelled(true); + } } } 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 b5c3a4028..d0ce15164 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -127,7 +127,6 @@ import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerEggThrowEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; @@ -1595,43 +1594,6 @@ public class PlayerEventListener extends PlotListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerEggThrow(PlayerEggThrowEvent event) { - Location location = BukkitUtil.adapt(event.getEgg().getLocation()); - PlotArea area = location.getPlotArea(); - if (area == null) { - return; - } - Player player = event.getPlayer(); - BukkitPlayer plotPlayer = BukkitUtil.adapt(player); - Plot plot = area.getPlot(location); - if (plot == null) { - if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) { - plotPlayer.sendMessage( - TranslatableCaption.of("permission.no_permission_event"), - Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) - ); - event.setHatching(false); - } - } else if (!plot.hasOwner()) { - if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) { - plotPlayer.sendMessage( - TranslatableCaption.of("permission.no_permission_event"), - Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) - ); - event.setHatching(false); - } - } else if (!plot.isAdded(plotPlayer.getUUID())) { - if (!Permissions.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { - plotPlayer.sendMessage( - TranslatableCaption.of("permission.no_permission_event"), - Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) - ); - event.setHatching(false); - } - } - } - @EventHandler public void onItemDrop(PlayerDropItemEvent event) { Player player = event.getPlayer(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java index 9a28ab448..895a40b32 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java @@ -28,6 +28,7 @@ package com.plotsquared.bukkit.listener; import com.google.inject.Inject; import com.plotsquared.bukkit.util.BukkitEntityUtil; import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; @@ -36,6 +37,7 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotHandler; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.Permissions; +import net.kyori.adventure.text.minimessage.Template; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -96,9 +98,6 @@ public class ProjectileEventListener implements Listener { @EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) { Projectile entity = event.getEntity(); - if (!(entity instanceof ThrownPotion)) { - return; - } ProjectileSource shooter = entity.getShooter(); if (!(shooter instanceof Player)) { return; @@ -109,9 +108,34 @@ public class ProjectileEventListener implements Listener { } PlotPlayer pp = BukkitUtil.adapt((Player) shooter); Plot plot = location.getOwnedPlot(); - if (plot != null && !plot.isAdded(pp.getUUID())) { - entity.remove(); - event.setCancelled(true); + + if (plot == null) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) { + pp.sendMessage( + TranslatableCaption.of("permission.no_permission_event"), + Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) + ); + entity.remove(); + event.setCancelled(true); + } + } else if (!plot.hasOwner()) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) { + pp.sendMessage( + TranslatableCaption.of("permission.no_permission_event"), + Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) + ); + entity.remove(); + event.setCancelled(true); + } + } else if (!plot.isAdded(pp.getUUID())) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { + pp.sendMessage( + TranslatableCaption.of("permission.no_permission_event"), + Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) + ); + entity.remove(); + event.setCancelled(true); + } } } @@ -131,14 +155,14 @@ public class ProjectileEventListener implements Listener { if (shooter instanceof Player) { PlotPlayer pp = BukkitUtil.adapt((Player) shooter); if (plot == null) { - if (!Permissions.hasPermission(pp, Permission.PERMISSION_PROJECTILE_UNOWNED)) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) { entity.remove(); event.setCancelled(true); } return; } if (plot.isAdded(pp.getUUID()) || Permissions - .hasPermission(pp, Permission.PERMISSION_PROJECTILE_OTHER)) { + .hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { return; } entity.remove(); diff --git a/Core/src/main/java/com/plotsquared/core/permissions/Permission.java b/Core/src/main/java/com/plotsquared/core/permissions/Permission.java index ca07ac4ea..bec34ac8a 100644 --- a/Core/src/main/java/com/plotsquared/core/permissions/Permission.java +++ b/Core/src/main/java/com/plotsquared/core/permissions/Permission.java @@ -37,7 +37,9 @@ public enum Permission { PERMISSION_STAR("*"), PERMISSION_ADMIN("plots.admin"), PERMISSION_ADMIN_AREA_SUDO("plots.admin.area.sudo"), + @Deprecated(forRemoval = true, since = "6.3.0") PERMISSION_PROJECTILE_UNOWNED("plots.projectile.unowned"), + @Deprecated(forRemoval = true, since = "6.3.0") PERMISSION_PROJECTILE_OTHER("plots.projectile.other"), PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS("plots.admin.interact.blockedcommands"), PERMISSION_WORLDEDIT_BYPASS("plots.worldedit.bypass"),