From fc023cc670d20b6f44f0dd3bd7d39ec34e934c62 Mon Sep 17 00:00:00 2001 From: Xefir Date: Sat, 5 May 2012 13:59:25 +0200 Subject: [PATCH] Add Vehicle specific preventions --- .../bukkit/simplyperms/SimplyPrevents.java | 7 +- .../simplyperms/preventions/Vehicle.java | 70 ------------------- .../preventions/vehicle/Collision.java | 29 ++++++++ .../preventions/vehicle/Destroy.java | 26 +++++++ .../preventions/vehicle/Enter.java | 26 +++++++ .../preventions/vehicle/Place.java | 39 +++++++++++ 6 files changed, 125 insertions(+), 72 deletions(-) delete mode 100644 src/net/crystalyx/bukkit/simplyperms/preventions/Vehicle.java create mode 100644 src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Collision.java create mode 100644 src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Destroy.java create mode 100644 src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Enter.java create mode 100644 src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Place.java diff --git a/src/net/crystalyx/bukkit/simplyperms/SimplyPrevents.java b/src/net/crystalyx/bukkit/simplyperms/SimplyPrevents.java index b2e5de6..5166f5c 100755 --- a/src/net/crystalyx/bukkit/simplyperms/SimplyPrevents.java +++ b/src/net/crystalyx/bukkit/simplyperms/SimplyPrevents.java @@ -21,7 +21,6 @@ public abstract class SimplyPrevents implements Listener { "Item", "Monster", "Sneak", - "Vehicle", "animals.Shear", "animals.Tame", "bucket.Lavabucket", @@ -53,7 +52,11 @@ public abstract class SimplyPrevents implements Listener { "projectile.Potion", "projectile.Snowball", "spam.CapsLock", - "spam.Flood" + "spam.Flood", + "vehicle.Collision", + "vehicle.Destroy", + "vehicle.Enter", + "vehicle.Place" }; public SimplyPrevents(SimplyPlugin plugin) { diff --git a/src/net/crystalyx/bukkit/simplyperms/preventions/Vehicle.java b/src/net/crystalyx/bukkit/simplyperms/preventions/Vehicle.java deleted file mode 100644 index f48b5b3..0000000 --- a/src/net/crystalyx/bukkit/simplyperms/preventions/Vehicle.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.crystalyx.bukkit.simplyperms.preventions; - -import net.crystalyx.bukkit.simplyperms.SimplyPlugin; -import net.crystalyx.bukkit.simplyperms.SimplyPrevents; - -import org.bukkit.Material; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.vehicle.VehicleDestroyEvent; -import org.bukkit.event.vehicle.VehicleEnterEvent; -import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; - -public class Vehicle extends SimplyPrevents { - - public Vehicle(SimplyPlugin plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void vehicleEnter(VehicleEnterEvent event) { - Entity entered = event.getEntered(); - if (entered instanceof Player) { - prevent(event, (Player) entered, "vehicle"); - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void vehicleDestroy(VehicleDestroyEvent event) { - Entity attacker = event.getAttacker(); - if (attacker instanceof Player) { - prevent(event, (Player) attacker, "vehicle"); - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void vehicleCollision(VehicleEntityCollisionEvent event) { - Entity collider = event.getEntity(); - if (collider instanceof Player) { - if (prevent(event, (Player) collider, "vehicle")) { - event.setCollisionCancelled(true); - event.setPickupCancelled(true); - } - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void vehicle(PlayerInteractEvent event) { - if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { - Material clickedMaterial = event.getClickedBlock().getType(); - Player player = event.getPlayer(); - Material materialInHand = player.getItemInHand().getType(); - if (clickedMaterial == Material.RAILS - || clickedMaterial == Material.POWERED_RAIL - || clickedMaterial == Material.DETECTOR_RAIL) { - if (materialInHand == Material.MINECART - || materialInHand == Material.POWERED_MINECART - || materialInHand == Material.STORAGE_MINECART) { - prevent(event, player, "vehicle"); - } - } else if (materialInHand == Material.BOAT) { - prevent(event, player, "vehicle"); - } - } - } - -} diff --git a/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Collision.java b/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Collision.java new file mode 100644 index 0000000..cb55105 --- /dev/null +++ b/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Collision.java @@ -0,0 +1,29 @@ +package net.crystalyx.bukkit.simplyperms.preventions.vehicle; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +public class Collision extends SimplyPrevents { + + public Collision(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void vehicleCollision(VehicleEntityCollisionEvent event) { + Entity collider = event.getEntity(); + if (collider instanceof Player) { + if (prevent(event, (Player) collider, "vehicle.collision")) { + event.setCollisionCancelled(true); + event.setPickupCancelled(true); + } + } + } + +} diff --git a/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Destroy.java b/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Destroy.java new file mode 100644 index 0000000..7160ea9 --- /dev/null +++ b/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Destroy.java @@ -0,0 +1,26 @@ +package net.crystalyx.bukkit.simplyperms.preventions.vehicle; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.vehicle.VehicleDestroyEvent; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +public class Destroy extends SimplyPrevents { + + public Destroy(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void vehicleDestroy(VehicleDestroyEvent event) { + Entity attacker = event.getAttacker(); + if (attacker instanceof Player) { + prevent(event, (Player) attacker, "vehicle.destroy"); + } + } + +} diff --git a/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Enter.java b/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Enter.java new file mode 100644 index 0000000..f753526 --- /dev/null +++ b/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Enter.java @@ -0,0 +1,26 @@ +package net.crystalyx.bukkit.simplyperms.preventions.vehicle; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.vehicle.VehicleEnterEvent; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +public class Enter extends SimplyPrevents { + + public Enter(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void vehicleEnter(VehicleEnterEvent event) { + Entity entered = event.getEntered(); + if (entered instanceof Player) { + prevent(event, (Player) entered, "vehicle.enter"); + } + } + +} diff --git a/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Place.java b/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Place.java new file mode 100644 index 0000000..8f59a8e --- /dev/null +++ b/src/net/crystalyx/bukkit/simplyperms/preventions/vehicle/Place.java @@ -0,0 +1,39 @@ +package net.crystalyx.bukkit.simplyperms.preventions.vehicle; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +public class Place extends SimplyPrevents { + + public Place(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void vehiclePlace(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Material clickedMaterial = event.getClickedBlock().getType(); + Player player = event.getPlayer(); + Material materialInHand = player.getItemInHand().getType(); + if (clickedMaterial == Material.RAILS + || clickedMaterial == Material.POWERED_RAIL + || clickedMaterial == Material.DETECTOR_RAIL) { + if (materialInHand == Material.MINECART + || materialInHand == Material.POWERED_MINECART + || materialInHand == Material.STORAGE_MINECART) { + prevent(event, player, "vehicle.place"); + } + } else if (materialInHand == Material.BOAT) { + prevent(event, player, "vehicle.place"); + } + } + } + +}