Actually call events now

This commit is contained in:
Shevchik 2014-03-07 21:41:59 +04:00
parent 56f4ddb87e
commit 547bbbadd2
3 changed files with 38 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -15,6 +16,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.cnaude.chairs.api.ChairsAPI; import com.cnaude.chairs.api.ChairsAPI;
import com.cnaude.chairs.api.PlayerChairUnsitEvent;
import com.cnaude.chairs.commands.ChairsCommand; import com.cnaude.chairs.commands.ChairsCommand;
import com.cnaude.chairs.commands.ChairsIgnoreList; import com.cnaude.chairs.commands.ChairsIgnoreList;
import com.cnaude.chairs.listeners.NANLoginListener; import com.cnaude.chairs.listeners.NANLoginListener;
@ -91,6 +93,8 @@ public class Chairs extends JavaPlugin {
public void onDisable() { public void onDisable() {
for (Player player : getServer().getOnlinePlayers()) { for (Player player : getServer().getOnlinePlayers()) {
if (psitdata.isSitting(player)) { if (psitdata.isSitting(player)) {
PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, false);
Bukkit.getPluginManager().callEvent(playerunsitevent);
psitdata.unsitPlayerNow(player); psitdata.unsitPlayerNow(player);
} }
} }

View File

@ -1,5 +1,6 @@
package com.cnaude.chairs.listeners; package com.cnaude.chairs.listeners;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -16,6 +17,7 @@ import org.bukkit.material.Stairs;
import org.bukkit.material.Step; import org.bukkit.material.Step;
import org.bukkit.material.WoodenStep; import org.bukkit.material.WoodenStep;
import com.cnaude.chairs.api.PlayerChairSitEvent;
import com.cnaude.chairs.commands.ChairsIgnoreList; import com.cnaude.chairs.commands.ChairsIgnoreList;
import com.cnaude.chairs.core.ChairBlock; import com.cnaude.chairs.core.ChairBlock;
import com.cnaude.chairs.core.Chairs; import com.cnaude.chairs.core.Chairs;
@ -37,9 +39,13 @@ public class TrySitEventListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
if (sitAllowed(player, block)) { if (sitAllowed(player, block)) {
event.setCancelled(true); PlayerChairSitEvent playersitevent = new PlayerChairSitEvent(player);
Location sitLocation = getSitLocation(block, player.getLocation().getYaw()); Bukkit.getPluginManager().callEvent(playersitevent);
plugin.getPlayerSitData().sitPlayer(player, block, sitLocation); if (!playersitevent.isCancelled()) {
event.setCancelled(true);
Location sitLocation = getSitLocation(block, player.getLocation().getYaw());
plugin.getPlayerSitData().sitPlayer(player, block, sitLocation);
}
} }
} }
} }

View File

@ -1,5 +1,6 @@
package com.cnaude.chairs.listeners; package com.cnaude.chairs.listeners;
import org.bukkit.Bukkit;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; 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.player.PlayerTeleportEvent;
import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.event.vehicle.VehicleExitEvent;
import com.cnaude.chairs.api.PlayerChairUnsitEvent;
import com.cnaude.chairs.core.Chairs; import com.cnaude.chairs.core.Chairs;
public class TryUnsitEventListener implements Listener { public class TryUnsitEventListener implements Listener {
@ -21,14 +23,7 @@ public class TryUnsitEventListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler(priority=EventPriority.LOWEST) //spigot...
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
if (plugin.getPlayerSitData().isSitting(player)) {
plugin.getPlayerSitData().unsitPlayerNow(player);
}
}
@EventHandler(priority=EventPriority.LOWEST) @EventHandler(priority=EventPriority.LOWEST)
public void onPlayerTeleport(PlayerTeleportEvent event) { public void onPlayerTeleport(PlayerTeleportEvent event) {
final Player player = event.getPlayer(); 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) @EventHandler(priority=EventPriority.LOWEST)
public void onPlayerDeath(PlayerDeathEvent event) { public void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity(); Player player = event.getEntity();
if (plugin.getPlayerSitData().isSitting(player)) { if (plugin.getPlayerSitData().isSitting(player)) {
PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, false);
Bukkit.getPluginManager().callEvent(playerunsitevent);
plugin.getPlayerSitData().unsitPlayerNow(player); plugin.getPlayerSitData().unsitPlayerNow(player);
} }
} }
@ -50,7 +57,13 @@ public class TryUnsitEventListener implements Listener {
if (e.getVehicle().getPassenger() instanceof Player) { if (e.getVehicle().getPassenger() instanceof Player) {
final Player player = (Player) e.getVehicle().getPassenger(); final Player player = (Player) e.getVehicle().getPassenger();
if (plugin.getPlayerSitData().isSitting(player)) { 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(); Block b = event.getBlock();
if (plugin.getPlayerSitData().isBlockOccupied(b)) { if (plugin.getPlayerSitData().isBlockOccupied(b)) {
Player player = plugin.getPlayerSitData().getPlayerOnChair(b); Player player = plugin.getPlayerSitData().getPlayerOnChair(b);
PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, false);
Bukkit.getPluginManager().callEvent(playerunsitevent);
plugin.getPlayerSitData().unsitPlayerForce(player); plugin.getPlayerSitData().unsitPlayerForce(player);
} }
} }