Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 99 lines 2.6 kB view raw
1package org.bukkit.event.player; 2 3import org.bukkit.entity.Player; 4import org.bukkit.event.Cancellable; 5 6import java.util.Arrays; 7import java.util.HashSet; 8import java.util.Set; 9 10/** 11 * Holds information for player chat and commands 12 */ 13public class PlayerChatEvent extends PlayerEvent implements Cancellable { 14 private boolean cancel = false; 15 private String message; 16 private String format = "<%1$s> %2$s"; 17 private final Set<Player> recipients; 18 19 public PlayerChatEvent(final Player player, final String message) { 20 this(Type.PLAYER_CHAT, player, message); 21 } 22 23 protected PlayerChatEvent(final Type type, final Player player, final String message) { 24 super(type, player); 25 recipients = new HashSet<Player>(Arrays.asList(player.getServer().getOnlinePlayers())); 26 this.message = message; 27 } 28 29 public boolean isCancelled() { 30 return cancel; 31 } 32 33 public void setCancelled(boolean cancel) { 34 this.cancel = cancel; 35 } 36 37 /** 38 * Gets the message that the player is attempting to send 39 * 40 * @return Message the player is attempting to send 41 */ 42 public String getMessage() { 43 return message; 44 } 45 46 /** 47 * Sets the message that the player will send 48 * 49 * @param message New message that the player will send 50 */ 51 public void setMessage(String message) { 52 this.message = message; 53 } 54 55 /** 56 * Sets the player that this message will display as, or command will be 57 * executed as 58 * 59 * @param player New player which this event will execute as 60 */ 61 public void setPlayer(final Player player) { 62 this.player = player; 63 } 64 65 /** 66 * Gets the format to use to display this chat message 67 * 68 * @return String.Format compatible format string 69 */ 70 public String getFormat() { 71 return format; 72 } 73 74 /** 75 * Sets the format to use to display this chat message 76 * 77 * @param format String.Format compatible format string 78 */ 79 public void setFormat(final String format) { 80 // Oh for a better way to do this! 81 try { 82 String.format(format, player, message); 83 } catch (RuntimeException ex) { 84 ex.fillInStackTrace(); 85 throw ex; 86 } 87 88 this.format = format; 89 } 90 91 /** 92 * Gets a set of recipients that this chat message will be displayed to 93 * 94 * @return All Players who will see this chat message 95 */ 96 public Set<Player> getRecipients() { 97 return recipients; 98 } 99}