Search in sources :

Example 1 with PlayerRespawnEvent

use of org.bukkit.event.player.PlayerRespawnEvent in project Essentials by drtshock.

the class EssentialsSpawn method onEnable.

@Override
public void onEnable() {
    final PluginManager pluginManager = getServer().getPluginManager();
    ess = (IEssentials) pluginManager.getPlugin("Essentials");
    if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
        LOGGER.log(Level.WARNING, tl("versionMismatchAll"));
    }
    if (!ess.isEnabled()) {
        this.setEnabled(false);
        return;
    }
    spawns = new SpawnStorage(ess);
    ess.addReloadListener(spawns);
    final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess, spawns);
    pluginManager.registerEvent(PlayerRespawnEvent.class, playerListener, ess.getSettings().getRespawnPriority(), new EventExecutor() {

        @Override
        public void execute(final Listener ll, final Event event) throws EventException {
            ((EssentialsSpawnPlayerListener) ll).onPlayerRespawn((PlayerRespawnEvent) event);
        }
    }, this);
    pluginManager.registerEvent(PlayerJoinEvent.class, playerListener, ess.getSettings().getRespawnPriority(), new EventExecutor() {

        @Override
        public void execute(final Listener ll, final Event event) throws EventException {
            ((EssentialsSpawnPlayerListener) ll).onPlayerJoin((PlayerJoinEvent) event);
        }
    }, this);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) EventExecutor(org.bukkit.plugin.EventExecutor) Listener(org.bukkit.event.Listener) EventException(org.bukkit.event.EventException) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Event(org.bukkit.event.Event) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent)

Example 2 with PlayerRespawnEvent

use of org.bukkit.event.player.PlayerRespawnEvent in project Essentials by drtshock.

the class Teleport method respawnNow.

protected void respawnNow(IUser teleportee, TeleportCause cause) throws Exception {
    final Player player = teleportee.getBase();
    Location bed = player.getBedSpawnLocation();
    if (bed != null) {
        now(teleportee, new LocationTarget(bed), cause);
    } else {
        if (ess.getSettings().isDebug()) {
            ess.getLogger().info("Could not find bed spawn, forcing respawn event.");
        }
        final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false);
        ess.getServer().getPluginManager().callEvent(pre);
        now(teleportee, new LocationTarget(pre.getRespawnLocation()), cause);
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) Location(org.bukkit.Location)

Aggregations

PlayerRespawnEvent (org.bukkit.event.player.PlayerRespawnEvent)2 Location (org.bukkit.Location)1 Player (org.bukkit.entity.Player)1 Event (org.bukkit.event.Event)1 EventException (org.bukkit.event.EventException)1 Listener (org.bukkit.event.Listener)1 PlayerJoinEvent (org.bukkit.event.player.PlayerJoinEvent)1 EventExecutor (org.bukkit.plugin.EventExecutor)1 PluginManager (org.bukkit.plugin.PluginManager)1