This repository has been archived by the owner on Jul 27, 2019. It is now read-only.
/
GamePlayerChatListener.java
105 lines (99 loc) · 4 KB
/
GamePlayerChatListener.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
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
101
102
103
104
105
/*
* Copyright (C) 2014 cnaude
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cnaude.purpleirc.GameListeners;
import com.cnaude.purpleirc.PurpleBot;
import com.cnaude.purpleirc.PurpleIRC;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
import org.pircbotx.Channel;
import org.pircbotx.User;
/**
*
* @author Chris Naude
*/
public class GamePlayerChatListener implements Listener {
private final PurpleIRC plugin;
/**
*
* @param plugin the PurpleIRC plugin
*/
public GamePlayerChatListener(PurpleIRC plugin) {
this.plugin = plugin;
}
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
String message = event.getMessage();
plugin.logDebug("ChatFormat [" + event.isCancelled() + "]: " + event.getFormat());
if (message.startsWith(PurpleIRC.TOWNYTAG)) {
event.setMessage(message.replace(PurpleIRC.TOWNYTAG, ""));
plugin.logDebug("Ignoring due to TownyChat tag");
return;
}
event.setMessage(message.replace(PurpleIRC.TOWNYTAG, ""));
if (event.isCancelled() && !plugin.isPluginEnabled("FactionChat") && !plugin.ignoreChatCancel) {
plugin.logDebug("Ignore chat message due to event cancellation: " + event.getMessage());
return;
}
if (plugin.adminPrivateChatHook != null) {
if (event.isCancelled() && plugin.adminPrivateChatHook.ac.toggledPlayers.contains(event.getPlayer().getName())) {
plugin.logDebug("Ignore AdminChat message due to event cancellation: " + event.getMessage());
return;
}
}
if (event.getPlayer().hasPermission("irc.message.gamechat")) {
plugin.logDebug("Player " + event.getPlayer().getName() + " has permission irc.message.gamechat");
for (PurpleBot ircBot : plugin.ircBots.values()) {
ircBot.gameChat(event);
}
} else {
plugin.logDebug("Player " + event.getPlayer().getName() + " does not have irc.message.gamechat permission.");
}
}
/**
*
* @param event
*/
@EventHandler
public void onPlayerChatTabCompleteEvent(PlayerChatTabCompleteEvent event) {
for (PurpleBot ircBot : plugin.ircBots.values()) {
for (Channel channel : ircBot.getChannels()) {
String channelName = channel.getName();
for (User user : channel.getUsers()) {
String nick = user.getNick();
if (event.getTabCompletions().contains(nick)) {
continue;
}
if (ircBot.tabIgnoreNicks.containsKey(channelName)) {
if (ircBot.tabIgnoreNicks.get(channelName).contains(nick)) {
continue;
}
}
if (nick.toLowerCase().startsWith(event.getLastToken().toLowerCase())) {
event.getTabCompletions().add(nick);
}
}
}
}
}
}