Actually call events now
This commit is contained in:
parent
56f4ddb87e
commit
547bbbadd2
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user