Reworked Projectile permissions

This commit is contained in:
Fabrizio La Rosa 2020-08-01 20:06:31 +02:00
parent 37759f598c
commit 57994742a2
5 changed files with 15 additions and 55 deletions

View File

@ -1,7 +1,6 @@
package com.songoda.skyblock.listeners; package com.songoda.skyblock.listeners;
import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -20,16 +19,13 @@ public class Projectile implements Listener {
public void onProjectileLaunch(ProjectileLaunchEvent event) { public void onProjectileLaunch(ProjectileLaunchEvent event) {
org.bukkit.entity.Projectile projectile = event.getEntity(); org.bukkit.entity.Projectile projectile = event.getEntity();
ProjectileSource shooter = projectile.getShooter(); ProjectileSource shooter = projectile.getShooter();
if (!(shooter instanceof Player)) if (shooter instanceof Player) {
return;
Player player = (Player) shooter; Player player = (Player) shooter;
if (!plugin.getWorldManager().isIslandWorld(player.getWorld())) if (plugin.getWorldManager().isIslandWorld(player.getWorld())) {
return; plugin.getPermissionManager().processPermission(event, player, player.getLocation());
}
// Check permissions. }
plugin.getPermissionManager().processPermission(new ProjectileLaunchByPlayerEvent(event.getEntity()), player, player.getLocation());
} }
} }

View File

@ -5,7 +5,6 @@ import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.message.MessageManager;
import com.songoda.skyblock.permission.event.events.PlayerEnterPortalEvent; import com.songoda.skyblock.permission.event.events.PlayerEnterPortalEvent;
import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
@ -79,7 +78,7 @@ public abstract class ListeningPermission extends BasicPermission {
public void onTeleport(PlayerTeleportEvent event) {} public void onTeleport(PlayerTeleportEvent event) {}
public void onProjectileLaunch(ProjectileLaunchByPlayerEvent event) {} public void onProjectileLaunch(ProjectileLaunchEvent event) {}
public void onBlockIgnite(BlockIgniteEvent event) {} public void onBlockIgnite(BlockIgniteEvent event) {}

View File

@ -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;
}
}

View File

@ -7,9 +7,9 @@ import com.songoda.skyblock.permission.ListeningPermission;
import com.songoda.skyblock.permission.PermissionHandler; import com.songoda.skyblock.permission.PermissionHandler;
import com.songoda.skyblock.permission.PermissionPriority; import com.songoda.skyblock.permission.PermissionPriority;
import com.songoda.skyblock.permission.PermissionType; import com.songoda.skyblock.permission.PermissionType;
import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.ProjectileLaunchEvent;
public class FishingPermission extends ListeningPermission { public class FishingPermission extends ListeningPermission {
@ -23,12 +23,11 @@ public class FishingPermission extends ListeningPermission {
} }
@PermissionHandler(priority = PermissionPriority.LAST) @PermissionHandler(priority = PermissionPriority.LAST)
public void onProjectileLaunch(ProjectileLaunchByPlayerEvent event) { public void onProjectileLaunch(ProjectileLaunchEvent event) {
org.bukkit.entity.Projectile projectile = event.getEntity(); org.bukkit.entity.Projectile projectile = event.getEntity();
if (projectile instanceof FishHook && projectile.getShooter() instanceof Player) { if (projectile instanceof FishHook && projectile.getShooter() instanceof Player) {
Player shooter = (Player) projectile.getShooter(); Player shooter = (Player) projectile.getShooter();
cancelAndMessage(event, shooter, plugin, messageManager); cancelAndMessage(event, shooter, plugin, messageManager);
event.setStopped(true);
} }
} }
} }

View File

@ -7,9 +7,9 @@ import com.songoda.skyblock.permission.ListeningPermission;
import com.songoda.skyblock.permission.PermissionHandler; import com.songoda.skyblock.permission.PermissionHandler;
import com.songoda.skyblock.permission.PermissionPriority; import com.songoda.skyblock.permission.PermissionPriority;
import com.songoda.skyblock.permission.PermissionType; import com.songoda.skyblock.permission.PermissionType;
import com.songoda.skyblock.permission.event.events.ProjectileLaunchByPlayerEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
public class ProjectilePermission extends ListeningPermission { public class ProjectilePermission extends ListeningPermission {
@ -34,7 +34,9 @@ public class ProjectilePermission extends ListeningPermission {
} }
@PermissionHandler(priority = PermissionPriority.LAST) @PermissionHandler(priority = PermissionPriority.LAST)
public void onProjectileLaunch(ProjectileLaunchByPlayerEvent event) { public void onProjectileLaunch(ProjectileLaunchEvent event) {
event.setCancelled(true); if(event.getEntity().getShooter() instanceof Player) {
cancelAndMessage(event, (Player) event.getEntity().getShooter(), plugin, messageManager);
}
} }
} }