From 2d4b6f20f2c286c392fa8b86be2e4ace61351935 Mon Sep 17 00:00:00 2001 From: garbagemule Date: Sat, 3 May 2014 22:32:24 +0200 Subject: [PATCH] Prevent mounted players from unmounting. --- resources/plugin.yml | 2 +- src/com/garbagemule/MobArena/ArenaListener.java | 16 ++++++++++++++++ .../MobArena/listeners/MAGlobalListener.java | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/resources/plugin.yml b/resources/plugin.yml index 02dfe8f..7a77b59 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,7 +1,7 @@ name: MobArena author: garbagemule main: com.garbagemule.MobArena.MobArena -version: 0.96.4.4 +version: 0.96.4.5 softdepend: [Multiverse-Core,Towny,Heroes,MagicSpells,Vault] commands: ma: diff --git a/src/com/garbagemule/MobArena/ArenaListener.java b/src/com/garbagemule/MobArena/ArenaListener.java index 5b1baa4..970adc0 100644 --- a/src/com/garbagemule/MobArena/ArenaListener.java +++ b/src/com/garbagemule/MobArena/ArenaListener.java @@ -51,6 +51,7 @@ import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -1176,4 +1177,19 @@ public class ArenaListener arena.playerLeave(p); } + + public void onVehicleExit(VehicleExitEvent event) { + LivingEntity entity = event.getExited(); + if (!(entity instanceof Player)) return; + + Player p = (Player) entity; + if (!arena.inArena(p)) return; + + Vehicle vehicle = event.getVehicle(); + if (!(vehicle instanceof Horse)) return; + + if (monsters.hasMount(vehicle)) { + event.setCancelled(true); + } + } } diff --git a/src/com/garbagemule/MobArena/listeners/MAGlobalListener.java b/src/com/garbagemule/MobArena/listeners/MAGlobalListener.java index 039f7a3..56029ac 100644 --- a/src/com/garbagemule/MobArena/listeners/MAGlobalListener.java +++ b/src/com/garbagemule/MobArena/listeners/MAGlobalListener.java @@ -8,6 +8,7 @@ import org.bukkit.event.block.*; import org.bukkit.event.entity.*; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.player.*; +import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldUnloadEvent; @@ -309,6 +310,13 @@ public class MAGlobalListener implements Listener arena.getEventListener().onPlayerPreLogin(event); } } + + @EventHandler(priority = EventPriority.NORMAL) + public void vehicleExit(VehicleExitEvent event) { + for (Arena arena : am.getArenas()) { + arena.getEventListener().onVehicleExit(event); + } + }