mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2024-11-26 03:55:55 +01:00
Add player list info to join/quit messages. #7
This commit is contained in:
parent
3c71797184
commit
6202673298
@ -180,10 +180,9 @@ public class IRCMessageHandler {
|
||||
case "@a":
|
||||
if (plugin.adminPrivateChatHook != null) {
|
||||
String newMessage = ircBot.filterMessage(
|
||||
plugin.tokenizer.ircChatToGameTokenizer(ircBot, user, channel, plugin.getMsgTemplate(
|
||||
ircBot.botNick, channelName, TemplateName.IRC_A_CHAT), commandArgs), channelName);
|
||||
plugin.tokenizer.ircChatToGameTokenizer(ircBot, user, channel, plugin.getMsgTemplate(ircBot.botNick, channelName, TemplateName.IRC_ADMIN_CHAT), commandArgs), channelName);
|
||||
plugin.adminPrivateChatHook.sendMessage(newMessage, user.getNick());
|
||||
String acResponse = plugin.tokenizer.msgChatResponseTokenizer(target, commandArgs, plugin.getMsgTemplate(TemplateName.IRC_A_RESPONSE));
|
||||
String acResponse = plugin.tokenizer.msgChatResponseTokenizer(target, commandArgs, plugin.getMsgTemplate(TemplateName.IRC_ADMIN_RESPONSE));
|
||||
if (!acResponse.isEmpty()) {
|
||||
sendMessage(ircBot, target, acResponse, ctcpResponse);
|
||||
}
|
||||
|
11
src/main/java/com/cnaude/purpleirc/PlayerList.java
Normal file
11
src/main/java/com/cnaude/purpleirc/PlayerList.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.cnaude.purpleirc;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author cnaude
|
||||
*/
|
||||
public class PlayerList {
|
||||
public int count;
|
||||
public int max;
|
||||
public String list;
|
||||
}
|
@ -1350,10 +1350,10 @@ public final class PurpleBot {
|
||||
return;
|
||||
}
|
||||
for (String channelName : botChannels) {
|
||||
if (isMessageEnabled(channelName, TemplateName.GAME_A_CHAT)) {
|
||||
if (isMessageEnabled(channelName, TemplateName.GAME_ADMIN_CHAT)) {
|
||||
asyncIRCMessage(channelName, plugin.tokenizer
|
||||
.gameChatToIRCTokenizer(name, plugin.
|
||||
getMsgTemplate(botNick, channelName, TemplateName.GAME_A_CHAT), message)
|
||||
getMsgTemplate(botNick, channelName, TemplateName.GAME_ADMIN_CHAT), message)
|
||||
.replace("%WORLD%", world)
|
||||
);
|
||||
}
|
||||
@ -1564,7 +1564,7 @@ public final class PurpleBot {
|
||||
if (isMessageEnabled(channelName, TemplateName.GAME_JOIN)
|
||||
&& isPlayerInValidWorld(player, channelName)) {
|
||||
asyncIRCMessage(channelName, plugin.tokenizer
|
||||
.gameChatToIRCTokenizer(player, plugin
|
||||
.gameChatToIRCTokenizer(this, channelName, player, plugin
|
||||
.getMsgTemplate(botNick, channelName, TemplateName.GAME_JOIN), message));
|
||||
}
|
||||
}
|
||||
@ -1588,7 +1588,7 @@ public final class PurpleBot {
|
||||
if (isMessageEnabled(channelName, TemplateName.GAME_QUIT)
|
||||
&& isPlayerInValidWorld(player, channelName)) {
|
||||
asyncIRCMessage(channelName, plugin.tokenizer
|
||||
.gameChatToIRCTokenizer(player, plugin
|
||||
.gameChatToIRCTokenizer(this, channelName, player, plugin
|
||||
.getMsgTemplate(botNick, channelName, TemplateName.GAME_QUIT), message));
|
||||
}
|
||||
}
|
||||
@ -1607,7 +1607,7 @@ public final class PurpleBot {
|
||||
if (isMessageEnabled(channelName, TemplateName.FAKE_JOIN)
|
||||
&& isPlayerInValidWorld(player, channelName)) {
|
||||
asyncIRCMessage(channelName, plugin.tokenizer
|
||||
.gameChatToIRCTokenizer(player, plugin
|
||||
.gameChatToIRCTokenizer(this, channelName, player, plugin
|
||||
.getMsgTemplate(botNick, channelName, TemplateName.FAKE_JOIN), message));
|
||||
}
|
||||
}
|
||||
@ -1626,7 +1626,7 @@ public final class PurpleBot {
|
||||
if (isMessageEnabled(channelName, TemplateName.FAKE_QUIT)
|
||||
&& isPlayerInValidWorld(player, channelName)) {
|
||||
asyncIRCMessage(channelName, plugin.tokenizer
|
||||
.gameChatToIRCTokenizer(player, plugin
|
||||
.gameChatToIRCTokenizer(this, channelName, player, plugin
|
||||
.getMsgTemplate(botNick, channelName, TemplateName.FAKE_QUIT), message));
|
||||
}
|
||||
}
|
||||
@ -2578,10 +2578,9 @@ public final class PurpleBot {
|
||||
Send messages to AdminPrivateChat if enabled
|
||||
*/
|
||||
if (plugin.adminPrivateChatHook != null) {
|
||||
if (isMessageEnabled(channelName, TemplateName.IRC_A_CHAT) || override) {
|
||||
if (isMessageEnabled(channelName, TemplateName.IRC_ADMIN_CHAT) || override) {
|
||||
String newMessage = filterMessage(
|
||||
plugin.tokenizer.ircChatToGameTokenizer(this, user, channel, plugin.getMsgTemplate(
|
||||
botNick, channelName, TemplateName.IRC_A_CHAT), message), channelName);
|
||||
plugin.tokenizer.ircChatToGameTokenizer(this, user, channel, plugin.getMsgTemplate(botNick, channelName, TemplateName.IRC_ADMIN_CHAT), message), channelName);
|
||||
if (!newMessage.isEmpty()) {
|
||||
plugin.adminPrivateChatHook.sendMessage(newMessage, user.getNick());
|
||||
messageSent = true;
|
||||
|
@ -825,6 +825,25 @@ public class PurpleIRC extends JavaPlugin {
|
||||
* @return
|
||||
*/
|
||||
public String getMCPlayers(PurpleBot ircBot, String channelName) {
|
||||
PlayerList pl = getMCPlayerList(ircBot, channelName);
|
||||
|
||||
String msg = listFormat
|
||||
.replace("%COUNT%", Integer.toString(pl.count))
|
||||
.replace("%MAX%", Integer.toString(pl.max))
|
||||
.replace("%PLAYERS%", pl.list);
|
||||
|
||||
return colorConverter.gameColorsToIrc(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ircBot
|
||||
* @param channelName
|
||||
* @return
|
||||
*/
|
||||
public PlayerList getMCPlayerList(PurpleBot ircBot, String channelName) {
|
||||
PlayerList pl = new PlayerList();
|
||||
|
||||
Map<String, String> playerList = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
if (ircBot.hideListWhenVanished.get(channelName)) {
|
||||
@ -848,15 +867,15 @@ public class PurpleIRC extends JavaPlugin {
|
||||
// sort without nick prefixes
|
||||
pList = Joiner.on(listSeparator).join(playerList.values());
|
||||
}
|
||||
|
||||
String msg = listFormat
|
||||
.replace("%COUNT%", Integer.toString(playerList.size()))
|
||||
.replace("%MAX%", Integer.toString(getServer().getMaxPlayers()))
|
||||
.replace("%PLAYERS%", pList);
|
||||
logDebug("L: " + msg);
|
||||
return colorConverter.gameColorsToIrc(msg);
|
||||
|
||||
pl.count = playerList.size();
|
||||
pl.max = getServer().getMaxPlayers();
|
||||
pl.list = pList;
|
||||
|
||||
return pl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getRemotePlayers(String commandArgs) {
|
||||
if (commandArgs != null) {
|
||||
String host;
|
||||
|
@ -130,9 +130,9 @@ public class TemplateName {
|
||||
|
||||
public final static String REDDIT_MESSAGES = "reddit-messages";
|
||||
|
||||
public final static String IRC_A_RESPONSE = "irc-a-response";
|
||||
public final static String GAME_A_CHAT = "game-a-chat";
|
||||
public final static String IRC_A_CHAT = "irc-a-chat";
|
||||
public final static String IRC_ADMIN_RESPONSE = "irc-a-response";
|
||||
public final static String GAME_ADMIN_CHAT = "game-a-chat";
|
||||
public final static String IRC_ADMIN_CHAT = "irc-a-chat";
|
||||
|
||||
public final static String FAKE_JOIN = "fake-join";
|
||||
public final static String FAKE_QUIT = "fake-quit";
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.cnaude.purpleirc.Utilities;
|
||||
|
||||
import com.cnaude.purpleirc.PlayerList;
|
||||
import com.cnaude.purpleirc.PurpleBot;
|
||||
import com.cnaude.purpleirc.PurpleIRC;
|
||||
import com.cnaude.purpleirc.TemplateName;
|
||||
@ -370,7 +371,6 @@ public class ChatTokenizer {
|
||||
*
|
||||
* @param player
|
||||
* @param template
|
||||
*
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
@ -384,6 +384,29 @@ public class ChatTokenizer {
|
||||
/**
|
||||
* Game chat to IRC
|
||||
*
|
||||
* @param ircBot
|
||||
* @param channelName
|
||||
* @param player
|
||||
* @param template
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
public String gameChatToIRCTokenizer(PurpleBot ircBot, String channelName, Player player, String template, String message) {
|
||||
if (message == null) {
|
||||
message = "";
|
||||
}
|
||||
PlayerList pl = plugin.getMCPlayerList(ircBot, channelName);
|
||||
return plugin.colorConverter.gameColorsToIrc(playerTokenizer(player, template)
|
||||
.replace("%MESSAGE%", message)
|
||||
.replace("%COUNT%", Integer.toString(pl.count))
|
||||
.replace("%MAX%", Integer.toString(pl.max))
|
||||
.replace("%PLAYERS%", pl.list)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynmap web chat to IRC
|
||||
*
|
||||
* @param source
|
||||
* @param name
|
||||
* @param template
|
||||
|
Loading…
Reference in New Issue
Block a user