Add Vehicle specific preventions

This commit is contained in:
Michel Roux 2012-05-05 13:59:25 +02:00
parent 72b26bcdb4
commit fc023cc670
6 changed files with 125 additions and 72 deletions

View File

@ -21,7 +21,6 @@ public abstract class SimplyPrevents implements Listener {
"Item", "Item",
"Monster", "Monster",
"Sneak", "Sneak",
"Vehicle",
"animals.Shear", "animals.Shear",
"animals.Tame", "animals.Tame",
"bucket.Lavabucket", "bucket.Lavabucket",
@ -53,7 +52,11 @@ public abstract class SimplyPrevents implements Listener {
"projectile.Potion", "projectile.Potion",
"projectile.Snowball", "projectile.Snowball",
"spam.CapsLock", "spam.CapsLock",
"spam.Flood" "spam.Flood",
"vehicle.Collision",
"vehicle.Destroy",
"vehicle.Enter",
"vehicle.Place"
}; };
public SimplyPrevents(SimplyPlugin plugin) { public SimplyPrevents(SimplyPlugin plugin) {

View File

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

View File

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

View File

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

View File

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

View File

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