From 547bbbadd21c78607dab76e90b4ac83a353d6471 Mon Sep 17 00:00:00 2001 From: Shevchik Date: Fri, 7 Mar 2014 21:41:59 +0400 Subject: [PATCH] Actually call events now --- src/com/cnaude/chairs/core/Chairs.java | 4 +++ .../chairs/listeners/TrySitEventListener.java | 12 +++++-- .../listeners/TryUnsitEventListener.java | 35 +++++++++++++------ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/com/cnaude/chairs/core/Chairs.java b/src/com/cnaude/chairs/core/Chairs.java index 5f40c4f..a3cbd0f 100644 --- a/src/com/cnaude/chairs/core/Chairs.java +++ b/src/com/cnaude/chairs/core/Chairs.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; @@ -15,6 +16,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import com.cnaude.chairs.api.ChairsAPI; +import com.cnaude.chairs.api.PlayerChairUnsitEvent; import com.cnaude.chairs.commands.ChairsCommand; import com.cnaude.chairs.commands.ChairsIgnoreList; import com.cnaude.chairs.listeners.NANLoginListener; @@ -91,6 +93,8 @@ public class Chairs extends JavaPlugin { public void onDisable() { for (Player player : getServer().getOnlinePlayers()) { if (psitdata.isSitting(player)) { + PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, false); + Bukkit.getPluginManager().callEvent(playerunsitevent); psitdata.unsitPlayerNow(player); } } diff --git a/src/com/cnaude/chairs/listeners/TrySitEventListener.java b/src/com/cnaude/chairs/listeners/TrySitEventListener.java index 1eabd6b..5439f3c 100644 --- a/src/com/cnaude/chairs/listeners/TrySitEventListener.java +++ b/src/com/cnaude/chairs/listeners/TrySitEventListener.java @@ -1,5 +1,6 @@ package com.cnaude.chairs.listeners; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -16,6 +17,7 @@ import org.bukkit.material.Stairs; import org.bukkit.material.Step; import org.bukkit.material.WoodenStep; +import com.cnaude.chairs.api.PlayerChairSitEvent; import com.cnaude.chairs.commands.ChairsIgnoreList; import com.cnaude.chairs.core.ChairBlock; import com.cnaude.chairs.core.Chairs; @@ -37,9 +39,13 @@ public class TrySitEventListener implements Listener { Player player = event.getPlayer(); Block block = event.getClickedBlock(); if (sitAllowed(player, block)) { - event.setCancelled(true); - Location sitLocation = getSitLocation(block, player.getLocation().getYaw()); - plugin.getPlayerSitData().sitPlayer(player, block, sitLocation); + PlayerChairSitEvent playersitevent = new PlayerChairSitEvent(player); + Bukkit.getPluginManager().callEvent(playersitevent); + if (!playersitevent.isCancelled()) { + event.setCancelled(true); + Location sitLocation = getSitLocation(block, player.getLocation().getYaw()); + plugin.getPlayerSitData().sitPlayer(player, block, sitLocation); + } } } } diff --git a/src/com/cnaude/chairs/listeners/TryUnsitEventListener.java b/src/com/cnaude/chairs/listeners/TryUnsitEventListener.java index fb9f3b3..1db5a8d 100644 --- a/src/com/cnaude/chairs/listeners/TryUnsitEventListener.java +++ b/src/com/cnaude/chairs/listeners/TryUnsitEventListener.java @@ -1,5 +1,6 @@ package com.cnaude.chairs.listeners; +import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -11,6 +12,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleExitEvent; +import com.cnaude.chairs.api.PlayerChairUnsitEvent; import com.cnaude.chairs.core.Chairs; public class TryUnsitEventListener implements Listener { @@ -20,15 +22,8 @@ public class TryUnsitEventListener implements Listener { public TryUnsitEventListener(Chairs plugin) { this.plugin = plugin; } - - @EventHandler(priority=EventPriority.LOWEST) - public void onPlayerQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); - if (plugin.getPlayerSitData().isSitting(player)) { - plugin.getPlayerSitData().unsitPlayerNow(player); - } - } - + + //spigot... @EventHandler(priority=EventPriority.LOWEST) public void onPlayerTeleport(PlayerTeleportEvent event) { final Player player = event.getPlayer(); @@ -37,10 +32,22 @@ public class TryUnsitEventListener implements Listener { } } + @EventHandler(priority=EventPriority.LOWEST) + public void onPlayerQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + if (plugin.getPlayerSitData().isSitting(player)) { + PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, false); + Bukkit.getPluginManager().callEvent(playerunsitevent); + plugin.getPlayerSitData().unsitPlayerNow(player); + } + } + @EventHandler(priority=EventPriority.LOWEST) public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); if (plugin.getPlayerSitData().isSitting(player)) { + PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, false); + Bukkit.getPluginManager().callEvent(playerunsitevent); plugin.getPlayerSitData().unsitPlayerNow(player); } } @@ -50,7 +57,13 @@ public class TryUnsitEventListener implements Listener { if (e.getVehicle().getPassenger() instanceof Player) { final Player player = (Player) e.getVehicle().getPassenger(); if (plugin.getPlayerSitData().isSitting(player)) { - plugin.getPlayerSitData().unsitPlayerNormal(player); + PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, true); + Bukkit.getPluginManager().callEvent(playerunsitevent); + if (!playerunsitevent.isCancelled()) { + plugin.getPlayerSitData().unsitPlayerNormal(player); + } else { + e.setCancelled(true); + } } } } @@ -60,6 +73,8 @@ public class TryUnsitEventListener implements Listener { Block b = event.getBlock(); if (plugin.getPlayerSitData().isBlockOccupied(b)) { Player player = plugin.getPlayerSitData().getPlayerOnChair(b); + PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, false); + Bukkit.getPluginManager().callEvent(playerunsitevent); plugin.getPlayerSitData().unsitPlayerForce(player); } }