Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add new command-sent message template.
Add new %UUID% token for game messages.
  • Loading branch information
cnaude committed Jan 9, 2016
1 parent b15cc3d commit 43739d2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
Expand Up @@ -68,7 +68,7 @@ private void queueAndSend() {
plugin.logDebug("Dispatching command as ConsoleSender: " + ircCommand.getGameCommand());

plugin.getServer().dispatchCommand(ircCommand.getIRCConsoleCommandSender(), ircCommand.getGameCommand());
ircCommand.getIRCConsoleCommandSender().sendMessage("Command sent: " + ircCommand.getGameCommand());
ircCommand.getIRCConsoleCommandSender().sendMessage(plugin.tokenizer.ircCommandSentTokenizer(ircCommand.getGameCommand()));
} else {
plugin.logDebug("Dispatching command as IRCCommandSender: " + ircCommand.getGameCommand());
plugin.getServer().dispatchCommand(ircCommand.getIRCCommandSender(), ircCommand.getGameCommand());
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/cnaude/purpleirc/IRCCommandSender.java
Expand Up @@ -45,8 +45,10 @@ public class IRCCommandSender implements CommandSender {
*/
@Override
public void sendMessage(String message) {
plugin.logDebug("sendMessage: " + message);
addMessageToQueue(template.replace("%RESULT%", message));
if (!message.isEmpty()) {
plugin.logDebug("sendMessage: " + message);
addMessageToQueue(template.replace("%RESULT%", message));
}
}

/**
Expand All @@ -56,8 +58,10 @@ public void sendMessage(String message) {
@Override
public void sendMessage(String[] messages) {
for (String message : messages) {
plugin.logDebug("sendMessage[]: " + message);
addMessageToQueue(template.replace("%RESULT%", message));
if (!message.isEmpty()) {
plugin.logDebug("sendMessage[]: " + message);
addMessageToQueue(template.replace("%RESULT%", message));
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/cnaude/purpleirc/IRCConsoleCommandSender.java
Expand Up @@ -46,8 +46,10 @@ public class IRCConsoleCommandSender implements ConsoleCommandSender {
*/
@Override
public void sendMessage(String message) {
plugin.logDebug("sendMessage: " + message);
addMessageToQueue(message);
if (!message.isEmpty()) {
plugin.logDebug("sendMessage: " + message);
addMessageToQueue(message);
}
}

/**
Expand All @@ -57,8 +59,10 @@ public void sendMessage(String message) {
@Override
public void sendMessage(String[] messages) {
for (String message : messages) {
plugin.logDebug("sendMessage[]: " + message);
addMessageToQueue(message);
if (!message.isEmpty()) {
plugin.logDebug("sendMessage[]: " + message);
addMessageToQueue(message);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/cnaude/purpleirc/TemplateName.java
Expand Up @@ -162,5 +162,7 @@ public class TemplateName {
public final static String NTHE_END_AGAIN_CRYSTAL = "ntheendagain-crystal";

public final static String LOG_TAILER = "log-tailer";

public final static String COMMAND_SENT = "command-sent";

}
23 changes: 20 additions & 3 deletions src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java
Expand Up @@ -773,6 +773,7 @@ public String playerTokenizer(Player player, String message) {
String gSuffix = plugin.getGroupSuffix(player);
String group = plugin.getPlayerGroup(player);
String displayName = player.getDisplayName();
UUID uuid = player.getUniqueId();
String playerIP = "";
try {
playerIP = player.getAddress().getAddress().getHostAddress();
Expand Down Expand Up @@ -819,6 +820,7 @@ public String playerTokenizer(Player player, String message) {
}
plugin.logDebug("[P]Raw message: " + message);
return message.replace("%DISPLAYNAME%", displayName)
.replace("%UUID%", uuid.toString())
.replace("%JOBS%", job)
.replace("%JOBSSHORT%", jobShort)
.replace("%NAME%", pName)
Expand All @@ -835,6 +837,7 @@ public String playerTokenizer(Player player, String message) {
}

private String playerTokenizer(String playerName, String message) {
Player player = getPlayer(playerName);
plugin.logDebug("Tokenizing " + playerName);
String worldName = plugin.defaultPlayerWorld;

Expand All @@ -861,6 +864,7 @@ private String playerTokenizer(String playerName, String message) {
}

String displayName = plugin.getDisplayName(playerName);
String uuid = "";
plugin.logDebug("playerTokenizer: 7 ");
String worldAlias = "";
String worldColor = "";
Expand Down Expand Up @@ -892,17 +896,19 @@ private String playerTokenizer(String playerName, String message) {
group = plugin.defaultPlayerGroup;
}
plugin.logDebug("playerTokenizer: 14 ");
if (message.contains("%JOBS%") || message.contains("%JOBSSHORT%")) {
Player player = getPlayer(playerName);
if (player != null) {
if (player != null) {
uuid = player.getUniqueId().toString();
if (message.contains("%JOBS%") || message.contains("%JOBSSHORT%")) {
if (plugin.jobsHook != null) {
job = plugin.jobsHook.getPlayerJob(player, false);
jobShort = plugin.jobsHook.getPlayerJob(player, true);
}
}
}

plugin.logDebug("[S]Raw message: " + message);
return message.replace("%DISPLAYNAME%", displayName)
.replace("%UUID%", uuid)
.replace("%JOBS%", job)
.replace("%JOBSSHORT%", jobShort)
.replace("%NAME%", playerName)
Expand Down Expand Up @@ -993,6 +999,17 @@ public String msgChatResponseTokenizer(String target, String message, String tem
);
}

/**
*
* @param command
* @return
*/
public String ircCommandSentTokenizer(String command) {
return plugin.colorConverter.gameColorsToIrc(
plugin.getMessageTemplate(TemplateName.COMMAND_SENT)
.replace("%COMMAND%", command));
}

/**
*
* @param sender
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config.yml
Expand Up @@ -91,11 +91,13 @@ chat-ping-fix: false
# %ACTION%
# %MESSAGE%
# %PLUGIN%
message-format:
message-format:
# Message templates for game to IRC messages
console-chat: '[&dServer&r] %MESSAGE%'
# Cross server chatting via linked bots
cross-chat: '[&4%SERVER%&r] %MESSAGE%'
# Command sent notification. Blank this to disable this message.
command-sent: 'Command sent: %COMMAND%'
game-achievement: '[&2%WORLD%&r] %NAME% has just earned the achievement [%MESSAGE%]'
game-mode: '[&2%WORLD%&r] %NAME% has changed game mode: [%MESSAGE%]'
game-action: '[&2%WORLD%&r]***%NAME% %MESSAGE%'
Expand Down

0 comments on commit 43739d2

Please sign in to comment.