-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChatAdvice.java
52 lines (47 loc) · 1.88 KB
/
ChatAdvice.java
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
package nexus;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerChatEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ChatAdvice extends PluginBase implements Listener {
final Pattern chatRegExp = Pattern.compile("^(@.*?)\s((.|\r|\n)+)");
@Override
public void onEnable() {
this.getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onChat(PlayerChatEvent ev) {
String message = ev.getMessage();
Level level = ev.getPlayer().getLevel();
Matcher result = chatRegExp.matcher(message);
if (result.find()) {
switch (result.group(1)) {
case "@월드" :
ev.setCancelled();
for (Player players: level.getPlayers().values()) {
players.sendMessage(message.replaceFirst("@월드", ""));
}
break;
case "@전체" :
ev.setCancelled();
this.getServer().broadcastMessage(message.replaceFirst("@전체", ""));
break;
default : //@플레이어닉네임 메시지 일경우
ev.setCancelled();
String username = mresultgroup(1).replaceFirst("@", "");
for (Player players : ev.getPlayer().getServer().getOnlinePlayers().values()) {
if (players.getName().equals(username)) {
players.sendMessage(result.group(2));
}
}
break;
}
} else { //딱히 없을때 월드채팅으로 ㄱㄱ
ev.setCancelled();
for (Player players: level.getPlayers().values()) {
players.sendMessage(message);
}
}
}
}