From 57994742a2fab7cc39bfd5abda620a7c5d7c462b Mon Sep 17 00:00:00 2001 From: Fabrizio La Rosa Date: Sat, 1 Aug 2020 20:06:31 +0200 Subject: [PATCH] Reworked Projectile permissions --- .../skyblock/listeners/Projectile.java | 18 ++++------ .../permission/ListeningPermission.java | 3 +- .../events/ProjectileLaunchByPlayerEvent.java | 36 ------------------- .../listening/FishingPermission.java | 5 ++- .../listening/ProjectilePermission.java | 8 +++-- 5 files changed, 15 insertions(+), 55 deletions(-) delete mode 100644 src/main/java/com/songoda/skyblock/permission/event/events/ProjectileLaunchByPlayerEvent.java diff --git a/src/main/java/com/songoda/skyblock/listeners/Projectile.java b/src/main/java/com/songoda/skyblock/listeners/Projectile.java index 8790fadd..5a49be0d 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Projectile.java +++ b/src/main/java/com/songoda/skyblock/listeners/Projectile.java @@ -1,7 +1,6 @@ package com.songoda.skyblock.listeners; import com.songoda.skyblock.SkyBlock; -import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -20,16 +19,13 @@ public class Projectile implements Listener { public void onProjectileLaunch(ProjectileLaunchEvent event) { org.bukkit.entity.Projectile projectile = event.getEntity(); ProjectileSource shooter = projectile.getShooter(); - if (!(shooter instanceof Player)) - return; - - Player player = (Player) shooter; - - if (!plugin.getWorldManager().isIslandWorld(player.getWorld())) - return; - - // Check permissions. - plugin.getPermissionManager().processPermission(new ProjectileLaunchByPlayerEvent(event.getEntity()), player, player.getLocation()); + if (shooter instanceof Player) { + Player player = (Player) shooter; + + if (plugin.getWorldManager().isIslandWorld(player.getWorld())) { + plugin.getPermissionManager().processPermission(event, player, player.getLocation()); + } + } } } diff --git a/src/main/java/com/songoda/skyblock/permission/ListeningPermission.java b/src/main/java/com/songoda/skyblock/permission/ListeningPermission.java index 656672d8..f07087e9 100644 --- a/src/main/java/com/songoda/skyblock/permission/ListeningPermission.java +++ b/src/main/java/com/songoda/skyblock/permission/ListeningPermission.java @@ -5,7 +5,6 @@ import com.songoda.core.compatibility.CompatibleSound; import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.permission.event.events.PlayerEnterPortalEvent; -import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.block.BlockBreakEvent; @@ -79,7 +78,7 @@ public abstract class ListeningPermission extends BasicPermission { public void onTeleport(PlayerTeleportEvent event) {} - public void onProjectileLaunch(ProjectileLaunchByPlayerEvent event) {} + public void onProjectileLaunch(ProjectileLaunchEvent event) {} public void onBlockIgnite(BlockIgniteEvent event) {} diff --git a/src/main/java/com/songoda/skyblock/permission/event/events/ProjectileLaunchByPlayerEvent.java b/src/main/java/com/songoda/skyblock/permission/event/events/ProjectileLaunchByPlayerEvent.java deleted file mode 100644 index b6912d63..00000000 --- a/src/main/java/com/songoda/skyblock/permission/event/events/ProjectileLaunchByPlayerEvent.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.songoda.skyblock.permission.event.events; - -import com.songoda.skyblock.permission.event.Stoppable; -import org.bukkit.entity.Entity; -import org.bukkit.event.Cancellable; -import org.bukkit.event.entity.ProjectileLaunchEvent; - -public class ProjectileLaunchByPlayerEvent extends ProjectileLaunchEvent implements Cancellable, Stoppable { - - private boolean isCancelled = false; - private boolean isStopped = false; - - public ProjectileLaunchByPlayerEvent(Entity what) { - super(what); - } - - @Override - public boolean isCancelled() { - return isCancelled; - } - - @Override - public void setCancelled(boolean cancelled) { - isCancelled = cancelled; - } - - @Override - public boolean isStopped() { - return isStopped; - } - - @Override - public void setStopped(boolean stopped) { - isStopped = stopped; - } -} diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/FishingPermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/FishingPermission.java index d76b5be8..44eaf835 100644 --- a/src/main/java/com/songoda/skyblock/permission/permissions/listening/FishingPermission.java +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/FishingPermission.java @@ -7,9 +7,9 @@ import com.songoda.skyblock.permission.ListeningPermission; import com.songoda.skyblock.permission.PermissionHandler; import com.songoda.skyblock.permission.PermissionPriority; import com.songoda.skyblock.permission.PermissionType; -import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent; import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; +import org.bukkit.event.entity.ProjectileLaunchEvent; public class FishingPermission extends ListeningPermission { @@ -23,12 +23,11 @@ public class FishingPermission extends ListeningPermission { } @PermissionHandler(priority = PermissionPriority.LAST) - public void onProjectileLaunch(ProjectileLaunchByPlayerEvent event) { + public void onProjectileLaunch(ProjectileLaunchEvent event) { org.bukkit.entity.Projectile projectile = event.getEntity(); if (projectile instanceof FishHook && projectile.getShooter() instanceof Player) { Player shooter = (Player) projectile.getShooter(); cancelAndMessage(event, shooter, plugin, messageManager); - event.setStopped(true); } } } diff --git a/src/main/java/com/songoda/skyblock/permission/permissions/listening/ProjectilePermission.java b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ProjectilePermission.java index 84545b19..8e31c466 100644 --- a/src/main/java/com/songoda/skyblock/permission/permissions/listening/ProjectilePermission.java +++ b/src/main/java/com/songoda/skyblock/permission/permissions/listening/ProjectilePermission.java @@ -7,9 +7,9 @@ import com.songoda.skyblock.permission.ListeningPermission; import com.songoda.skyblock.permission.PermissionHandler; import com.songoda.skyblock.permission.PermissionPriority; import com.songoda.skyblock.permission.PermissionType; -import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; +import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.player.PlayerInteractEvent; public class ProjectilePermission extends ListeningPermission { @@ -34,7 +34,9 @@ public class ProjectilePermission extends ListeningPermission { } @PermissionHandler(priority = PermissionPriority.LAST) - public void onProjectileLaunch(ProjectileLaunchByPlayerEvent event) { - event.setCancelled(true); + public void onProjectileLaunch(ProjectileLaunchEvent event) { + if(event.getEntity().getShooter() instanceof Player) { + cancelAndMessage(event, (Player) event.getEntity().getShooter(), plugin, messageManager); + } } }