/* This file is part of PV-StarAPI for Bukkit, licensed under the MIT License (MIT).
 *
 * Copyright (c) JCThePants (www.jcwhatever.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */


package com.jcwhatever.bukkit.pvs.api.events.players;

import com.jcwhatever.bukkit.generic.utils.PreCon;
import com.jcwhatever.bukkit.pvs.api.arena.Arena;
import com.jcwhatever.bukkit.pvs.api.arena.ArenaPlayer;
import com.jcwhatever.bukkit.pvs.api.arena.options.AddPlayerReason;
import org.bukkit.Location;

import javax.annotation.Nullable;

/**
 * Called when player is added to an arena.
 */
public class PlayerAddedEvent extends AbstractPlayerEvent {

    private final AddPlayerReason _reason;
    private Location _initialSpawnLocation;
    private Location _spawnLocation;

    /**
     * Constructor.
     *
     * @param arena          The event arena.
     * @param player         The player being added.
     * @param reason         The reason the player is being added.
     * @param spawnLocation  The location the player will be teleported to, if any.
     */
    public PlayerAddedEvent(Arena arena, ArenaPlayer player, AddPlayerReason reason, @Nullable Location spawnLocation) {
        super(arena, player, false);

        PreCon.notNull(reason);

        _reason = reason;
        _initialSpawnLocation = spawnLocation;
        _spawnLocation = spawnLocation;
    }

    /**
     * Get the reason the player is being added.
     */
    public AddPlayerReason getReason() {
        return _reason;
    }

    /**
     * Get the spawn location set when the event was called.
     */
    @Nullable
    public Location getInitialSpawnLocation() {
        return _initialSpawnLocation;
    }

    /**
     * Get the current spawn location.
     * @return
     */
    @Nullable
    public Location getSpawnLocation() {
        return _spawnLocation;
    }

    /**
     * Set the players spawn location.
     *
     * @param location  The location to spawn the player. Null to prevent teleport.
     */
    public void setSpawnLocation(@Nullable Location location) {
        _spawnLocation = location;
    }

}

@@ -1791,16 +1791,45 @@
 ocation;
+%0A    private String _message;
 %0A%0A    /*
@@ -2199,16 +2199,44 @@
  reason,
+%0A                           
  @Nullab
@@ -2256,24 +2256,50 @@
 pawnLocation
+, @Nullable String message
 ) %7B%0A        
@@ -2466,32 +2466,60 @@
  spawnLocation;%0A
+        _message = message;%0A
     %7D%0A%0A    /**%0A 
@@ -3199,24 +3199,24 @@
 location) %7B%0A
-
         _spa
@@ -3245,10 +3245,417 @@
 %0A    %7D%0A%0A
+    /**%0A     * Get the message to display to players in the related player manager.%0A     */%0A    @Nullable%0A    public String getMessage() %7B%0A        return _message;%0A    %7D%0A%0A    /**%0A     * Set the message to display to players in the related player manager.%0A     *%0A     * @param message  The message to display.%0A     */%0A    public void setMessage(@Nullable String message) %7B%0A        _message = message;%0A    %7D%0A%0A
 %7D%0A

add message to PlayerAddedEvent