001 package org.bukkit.event.block;
002
003 import org.bukkit.block.Block;
004 import org.bukkit.entity.Player;
005 import org.bukkit.event.Cancellable;
006 import org.bukkit.event.HandlerList;
007
008 /**
009 * Called when a sign is changed by a player.
010 * <p>
011 * If a Sign Change event is cancelled, the sign will not be changed.
012 */
013 public class SignChangeEvent extends BlockEvent implements Cancellable {
014 private static final HandlerList handlers = new HandlerList();
015 private boolean cancel = false;
016 private final Player player;
017 private final String[] lines;
018
019 public SignChangeEvent(final Block theBlock, final Player thePlayer, final String[] theLines) {
020 super(theBlock);
021 this.player = thePlayer;
022 this.lines = theLines;
023 }
024
025 /**
026 * Gets the player changing the sign involved in this event.
027 *
028 * @return the Player involved in this event
029 */
030 public Player getPlayer() {
031 return player;
032 }
033
034 /**
035 * Gets all of the lines of text from the sign involved in this event.
036 *
037 * @return the String array for the sign's lines new text
038 */
039 public String[] getLines() {
040 return lines;
041 }
042
043 /**
044 * Gets a single line of text from the sign involved in this event.
045 *
046 * @param index index of the line to get
047 * @return the String containing the line of text associated with the
048 * provided index
049 * @throws IndexOutOfBoundsException thrown when the provided index is > 3
050 * or < 0
051 */
052 public String getLine(int index) throws IndexOutOfBoundsException {
053 return lines[index];
054 }
055
056 /**
057 * Sets a single line for the sign involved in this event
058 *
059 * @param index index of the line to set
060 * @param line text to set
061 * @throws IndexOutOfBoundsException thrown when the provided index is > 3
062 * or < 0
063 */
064 public void setLine(int index, String line) throws IndexOutOfBoundsException {
065 lines[index] = line;
066 }
067
068 public boolean isCancelled() {
069 return cancel;
070 }
071
072 public void setCancelled(boolean cancel) {
073 this.cancel = cancel;
074 }
075
076 @Override
077 public HandlerList getHandlers() {
078 return handlers;
079 }
080
081 public static HandlerList getHandlerList() {
082 return handlers;
083 }
084 }