mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2025-02-18 04:21:23 +01:00
Add /msg alias for /irc smsg
This commit is contained in:
parent
b67be94124
commit
6e04672421
@ -20,6 +20,7 @@ import com.cnaude.purpleirc.Commands.*;
|
||||
import com.google.common.base.Joiner;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.command.Command;
|
||||
@ -114,16 +115,33 @@ public class CommandHandlers implements CommandExecutor {
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (args.length >= 1) {
|
||||
String subCmd = args[0].toLowerCase();
|
||||
if (commands.containsKey(subCmd)) {
|
||||
if (!sender.hasPermission("irc." + subCmd)) {
|
||||
if (commandLabel.equalsIgnoreCase("irc")) {
|
||||
if (args.length >= 1) {
|
||||
String subCmd = args[0].toLowerCase();
|
||||
if (commands.containsKey(subCmd)) {
|
||||
if (!sender.hasPermission("irc." + subCmd)) {
|
||||
sender.sendMessage(plugin.noPermission);
|
||||
return true;
|
||||
}
|
||||
commands.get(subCmd).dispatch(sender, args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (commandLabel.equalsIgnoreCase("msg")) {
|
||||
if (args.length >= 1) {
|
||||
if (!sender.hasPermission("irc.smsg")) {
|
||||
sender.sendMessage(plugin.noPermission);
|
||||
return true;
|
||||
}
|
||||
commands.get(subCmd).dispatch(sender, args);
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("smsg");
|
||||
list.addAll(Arrays.asList(args));
|
||||
plugin.logDebug("MSG: " + list);
|
||||
commands.get("smsg").dispatch(sender, list.toArray(new String[list.size()]));
|
||||
return true;
|
||||
}
|
||||
} else if (commandLabel.equalsIgnoreCase("r")) {
|
||||
|
||||
}
|
||||
commands.get("help").dispatch(sender, args);
|
||||
return true;
|
||||
|
@ -70,6 +70,26 @@ public class SMsg implements IRCCommandInterface {
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = "";
|
||||
for (int i = msgIdx; i < args.length; i++) {
|
||||
msg = msg + " " + args[i];
|
||||
}
|
||||
msg = msg.trim();
|
||||
|
||||
if (plugin.getServer().getPlayer(target) instanceof Player) {
|
||||
Player player = plugin.getServer().getPlayer(target);
|
||||
String template = plugin.getMsgTemplate("MAIN", "", TemplateName.GAME_PCHAT);
|
||||
String targetMsg = plugin.tokenizer.gameChatTokenizer(player, template, msg);
|
||||
String responseTemplate = plugin.getMsgTemplate("MAIN", "", TemplateName.GAME_PCHAT_RESPONSE);
|
||||
if (!responseTemplate.isEmpty()) {
|
||||
String responseMsg = plugin.tokenizer.gameChatTokenizer(player, responseTemplate, msg);
|
||||
sender.sendMessage(responseMsg);
|
||||
}
|
||||
plugin.logDebug("Tokenized message: " + targetMsg);
|
||||
player.sendMessage(targetMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
for (PurpleBot ircBot : myBots) {
|
||||
String remoteBot = "";
|
||||
String remotePlayer = "";
|
||||
@ -91,17 +111,13 @@ public class SMsg implements IRCCommandInterface {
|
||||
}
|
||||
|
||||
if (remotePlayer.isEmpty()) {
|
||||
sender.sendMessage(ChatColor.RED + "Remote player "
|
||||
sender.sendMessage(ChatColor.RED + "Player "
|
||||
+ ChatColor.WHITE + target + ChatColor.RED + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ircBot.botLinkingEnabled) {
|
||||
String msg = "";
|
||||
final String template = plugin.getMsgTemplate(ircBot.botNick, "", TemplateName.GAME_PCHAT_RESPONSE);
|
||||
for (int i = msgIdx; i < args.length; i++) {
|
||||
msg = msg + " " + args[i];
|
||||
}
|
||||
if (sender instanceof Player) {
|
||||
ircBot.msgRemotePlayer((Player) sender, remoteBot, remotePlayer, msg.substring(1));
|
||||
} else {
|
||||
|
@ -79,7 +79,7 @@ public class NoticeListener extends ListenerAdapter {
|
||||
|
||||
plugin.logDebug("Are we linked to " + user.getNick() + "?");
|
||||
if (ircBot.botLinks.containsKey(nick)) {
|
||||
plugin.logDebug("Yes we are linked. Is thee code correct?");
|
||||
plugin.logDebug("Yes we are linked. Is the code correct?");
|
||||
if (ircBot.botLinks.get(nick).equals(code)) {
|
||||
plugin.logDebug("Yes the code is correct!");
|
||||
plugin.logDebug(" [COMMAND: " + command + "]");
|
||||
@ -101,7 +101,6 @@ public class NoticeListener extends ListenerAdapter {
|
||||
if (splitMsg.length == 5) {
|
||||
players = splitMsg[4];
|
||||
}
|
||||
|
||||
plugin.logDebug(" [CUR_COUNT:" + curCount + "]");
|
||||
plugin.logDebug(" [MAX_COUNT:" + maxCount + "]");
|
||||
plugin.logDebug(" [PLAYERS:" + players + "]");
|
||||
|
@ -245,10 +245,6 @@ public final class PurpleBot {
|
||||
this.linkRequests = new CaseInsensitiveMap<>();
|
||||
this.remotePlayers = new CaseInsensitiveMap<>();
|
||||
this.remoteServerInfo = new CaseInsensitiveMap<>();
|
||||
for (String s : botLinks.keySet()) {
|
||||
remotePlayers.put(s, new ArrayList<String>());
|
||||
remoteServerInfo.put(s, new CaseInsensitiveMap<String>());
|
||||
}
|
||||
config = new YamlConfiguration();
|
||||
goodBot = loadConfig();
|
||||
if (goodBot) {
|
||||
@ -735,6 +731,10 @@ public final class PurpleBot {
|
||||
plugin.logDebug("Bot-Link: " + t + " => " + botLinks.get(t));
|
||||
}
|
||||
}
|
||||
for (String s : botLinks.keySet()) {
|
||||
remotePlayers.put(s, new ArrayList<String>());
|
||||
remoteServerInfo.put(s, new CaseInsensitiveMap<String>());
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : config.getStringList("custom-prefixes")) {
|
||||
|
@ -218,6 +218,7 @@ public class PurpleIRC extends JavaPlugin {
|
||||
public static final String PURPLETAG = "UHVycGxlSVJDCg==";
|
||||
public static final String TOWNYTAG = "VG93bnlDaGF0Cg==";
|
||||
public static final String LINK_CMD = "PurpleIRC-Link:";
|
||||
public boolean overrideMsgCmd = false;
|
||||
|
||||
public PurpleIRC() {
|
||||
this.MAINCONFIG = "MAIN-CONFIG";
|
||||
@ -285,6 +286,9 @@ public class PurpleIRC extends JavaPlugin {
|
||||
ircTabCompleter = new PurpleTabCompleter(this);
|
||||
getCommand("irc").setExecutor(commandHandlers);
|
||||
getCommand("irc").setTabCompleter(ircTabCompleter);
|
||||
if (overrideMsgCmd) {
|
||||
getCommand("msg").setExecutor(commandHandlers);
|
||||
}
|
||||
regexGlobber = new RegexGlobber();
|
||||
tokenizer = new ChatTokenizer(this);
|
||||
loadBots();
|
||||
@ -565,6 +569,7 @@ public class PurpleIRC extends JavaPlugin {
|
||||
} catch (IOException | InvalidConfigurationException ex) {
|
||||
logError(ex.getMessage());
|
||||
}
|
||||
overrideMsgCmd = getConfig().getBoolean("override-msg-cmd", false);
|
||||
updateCheckerEnabled = getConfig().getBoolean("update-checker", true);
|
||||
updateCheckerMode = getConfig().getString("update-checker-mode", "stable");
|
||||
debugEnabled = getConfig().getBoolean("Debug");
|
||||
|
@ -328,6 +328,19 @@ public class ChatTokenizer {
|
||||
.replace("%NAME%", pName)
|
||||
.replace("%MESSAGE%", plugin.colorConverter.gameColorsToIrc(message)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Game chat to game (private messages)
|
||||
*
|
||||
* @param player
|
||||
* @param template
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
public String gameChatTokenizer(Player player, String template, String message) {
|
||||
return playerTokenizer(player, template)
|
||||
.replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Game chat to IRC
|
||||
|
@ -12,6 +12,8 @@ reconnect-fail-message-count: 10
|
||||
enable-ident-server: false
|
||||
# How often we check the channel user list
|
||||
channel-check-interval: 100
|
||||
# Alias /irc smsg to /msg
|
||||
override-msg-cmd: false
|
||||
# Chat messages support standard Bukkit color codes using '&#'. See http://minecraft.gamepedia.com/Formatting_codes
|
||||
# The following macro tokens are also supported.
|
||||
# %WORLD%
|
||||
|
@ -26,6 +26,9 @@ commands:
|
||||
irc:
|
||||
description: Various irc commands
|
||||
usage: /<command> help - List all irc commands available.
|
||||
msg:
|
||||
description: Shortcut for /irc smsg
|
||||
usage: /<command> [player] message
|
||||
permissions:
|
||||
'irc.reloadconfig':
|
||||
description: Gives player access to the /irc reloadconfig.
|
||||
|
Loading…
Reference in New Issue
Block a user