mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2024-11-25 11:35:36 +01:00
Add support for %ARGX+% and game_command_usage.
This commit is contained in:
parent
09f88c37b9
commit
e3e6a9fc1b
@ -20,8 +20,11 @@ import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap;
|
||||
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.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.pircbotx.Channel;
|
||||
import org.pircbotx.User;
|
||||
@ -98,6 +101,7 @@ public class IRCMessageHandler {
|
||||
}
|
||||
|
||||
String gc = (String) ircBot.commandMap.get(channelName).get(command).get("game_command");
|
||||
String gcUsage = (String) ircBot.commandMap.get(channelName).get(command).get("game_command_usage");
|
||||
List<String> extraCommands = ircBot.extraCommandMap.get(channelName).get(command);
|
||||
List<String> gameCommands = new ArrayList<>();
|
||||
gameCommands.add(gc);
|
||||
@ -115,6 +119,7 @@ public class IRCMessageHandler {
|
||||
plugin.logDebug("Target: " + target);
|
||||
|
||||
if (isValidMode(modes, user, channel) && checkPerm(perm, user.getNick())) {
|
||||
gc_loop:
|
||||
for (String gameCommand : gameCommands) {
|
||||
switch (gameCommand) {
|
||||
case "@list":
|
||||
@ -184,21 +189,40 @@ public class IRCMessageHandler {
|
||||
if (commandArgs == null) {
|
||||
commandArgs = "";
|
||||
}
|
||||
|
||||
if (gameCommand.contains("%ARGS%")) {
|
||||
gameCommand = gameCommand.replace("%ARGS%", commandArgs);
|
||||
}
|
||||
|
||||
if (gameCommand.contains("%NAME%")) {
|
||||
gameCommand = gameCommand.replace("%NAME%", user.getNick());
|
||||
}
|
||||
|
||||
if (gameCommand.matches(".*%ARG\\d+%.*")) {
|
||||
String commandArgsArray[] = commandArgs.split(" ");
|
||||
for (int i = 0; i < commandArgsArray.length; i++) {
|
||||
gameCommand = gameCommand.replace("%ARG" + (i + 1) + "%", commandArgsArray[i]);
|
||||
}
|
||||
gameCommand = gameCommand.replaceAll("%ARG\\d+%", "");
|
||||
}
|
||||
|
||||
if (gameCommand.contains("%NAME%")) {
|
||||
gameCommand = gameCommand.replace("%NAME%", user.getNick());
|
||||
Pattern pattern = Pattern.compile(".*%ARG(\\d+)\\+%.*");
|
||||
Matcher matcher = pattern.matcher(gameCommand);
|
||||
if (matcher.matches()) {
|
||||
String commandArgsArray[] = commandArgs.split(" ");
|
||||
int startPos = Integer.valueOf(matcher.group(1));
|
||||
if (commandArgsArray.length >= startPos) {
|
||||
gameCommand = gameCommand.replace("%ARG" + startPos + "+%",
|
||||
Joiner.on(" ").join(Arrays.copyOfRange(commandArgsArray, startPos - 1, commandArgsArray.length)));
|
||||
}
|
||||
}
|
||||
|
||||
if (gameCommand.matches(".*%ARG\\d+%.*")
|
||||
|| gameCommand.matches(".*%ARG(\\d+)\\+%.*")
|
||||
|| gameCommand.contains("%ARGS%")) {
|
||||
plugin.logDebug("GM BAIL: \"" + gameCommand.trim() + "\"");
|
||||
ircBot.asyncIRCMessage(target, gcUsage);
|
||||
break gc_loop;
|
||||
} else {
|
||||
plugin.logDebug("GM: \"" + gameCommand.trim() + "\"");
|
||||
try {
|
||||
plugin.commandQueue.add(new IRCCommand(
|
||||
@ -208,6 +232,7 @@ public class IRCMessageHandler {
|
||||
} catch (Exception ex) {
|
||||
plugin.logError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -990,6 +990,7 @@ public final class PurpleBot {
|
||||
optionPair.put("private", config.getString(commandKey + "private", "false"));
|
||||
optionPair.put("ctcp", config.getString(commandKey + "ctcp", "false"));
|
||||
optionPair.put("game_command", config.getString(commandKey + "game_command", ""));
|
||||
optionPair.put("game_command_usage", config.getString(commandKey + "game_command_usage", ""));
|
||||
optionPair.put("sender", config.getString(commandKey + "sender", "CONSOLE"));
|
||||
extraCommands.addAll(config.getStringList(commandKey + "extra_commands"));
|
||||
plugin.logDebug("extra_commands: " + extraCommands.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user