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