Bukkit  1.4.7-R1.0
 All Classes Namespaces Files Functions Variables Enumerator Pages
PlayerChatEvent.java
Go to the documentation of this file.
1 package org.bukkit.event.player;
2 
3 import java.util.Arrays;
4 import java.util.HashSet;
5 import java.util.Set;
6 
7 import org.apache.commons.lang.Validate;
8 import org.bukkit.Warning;
9 import org.bukkit.entity.Player;
10 import org.bukkit.event.Cancellable;
11 import org.bukkit.event.HandlerList;
12 
20 @Deprecated
21 @Warning(reason="Listening to this event forces chat to wait for the main thread, delaying chat messages.")
22 public class PlayerChatEvent extends PlayerEvent implements Cancellable {
23  private static final HandlerList handlers = new HandlerList();
24  private boolean cancel = false;
25  private String message;
26  private String format;
27  private final Set<Player> recipients;
28 
29  public PlayerChatEvent(final Player player, final String message) {
30  super(player);
31  this.message = message;
32  this.format = "<%1$s> %2$s";
33  this.recipients = new HashSet<Player>(Arrays.asList(player.getServer().getOnlinePlayers()));
34  }
35 
36  public PlayerChatEvent(final Player player, final String message, final String format, final Set<Player> recipients) {
37  super(player);
38  this.message = message;
39  this.format = format;
40  this.recipients = recipients;
41  }
42 
43  public boolean isCancelled() {
44  return cancel;
45  }
46 
47  public void setCancelled(boolean cancel) {
48  this.cancel = cancel;
49  }
50 
56  public String getMessage() {
57  return message;
58  }
59 
65  public void setMessage(String message) {
66  this.message = message;
67  }
68 
75  public void setPlayer(final Player player) {
76  Validate.notNull(player, "Player cannot be null");
77  this.player = player;
78  }
79 
85  public String getFormat() {
86  return format;
87  }
88 
94  public void setFormat(final String format) {
95  // Oh for a better way to do this!
96  try {
97  String.format(format, player, message);
98  } catch (RuntimeException ex) {
99  ex.fillInStackTrace();
100  throw ex;
101  }
102 
103  this.format = format;
104  }
105 
111  public Set<Player> getRecipients() {
112  return recipients;
113  }
114 
115  @Override
117  return handlers;
118  }
119 
120  public static HandlerList getHandlerList() {
121  return handlers;
122  }
123 }