mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2024-11-29 13:36:04 +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 com.google.common.base.Joiner;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.pircbotx.Channel;
|
import org.pircbotx.Channel;
|
||||||
import org.pircbotx.User;
|
import org.pircbotx.User;
|
||||||
@ -98,6 +101,7 @@ public class IRCMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String gc = (String) ircBot.commandMap.get(channelName).get(command).get("game_command");
|
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> extraCommands = ircBot.extraCommandMap.get(channelName).get(command);
|
||||||
List<String> gameCommands = new ArrayList<>();
|
List<String> gameCommands = new ArrayList<>();
|
||||||
gameCommands.add(gc);
|
gameCommands.add(gc);
|
||||||
@ -115,6 +119,7 @@ public class IRCMessageHandler {
|
|||||||
plugin.logDebug("Target: " + target);
|
plugin.logDebug("Target: " + target);
|
||||||
|
|
||||||
if (isValidMode(modes, user, channel) && checkPerm(perm, user.getNick())) {
|
if (isValidMode(modes, user, channel) && checkPerm(perm, user.getNick())) {
|
||||||
|
gc_loop:
|
||||||
for (String gameCommand : gameCommands) {
|
for (String gameCommand : gameCommands) {
|
||||||
switch (gameCommand) {
|
switch (gameCommand) {
|
||||||
case "@list":
|
case "@list":
|
||||||
@ -184,21 +189,40 @@ public class IRCMessageHandler {
|
|||||||
if (commandArgs == null) {
|
if (commandArgs == null) {
|
||||||
commandArgs = "";
|
commandArgs = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameCommand.contains("%ARGS%")) {
|
if (gameCommand.contains("%ARGS%")) {
|
||||||
gameCommand = gameCommand.replace("%ARGS%", commandArgs);
|
gameCommand = gameCommand.replace("%ARGS%", commandArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gameCommand.contains("%NAME%")) {
|
||||||
|
gameCommand = gameCommand.replace("%NAME%", user.getNick());
|
||||||
|
}
|
||||||
|
|
||||||
if (gameCommand.matches(".*%ARG\\d+%.*")) {
|
if (gameCommand.matches(".*%ARG\\d+%.*")) {
|
||||||
String commandArgsArray[] = commandArgs.split(" ");
|
String commandArgsArray[] = commandArgs.split(" ");
|
||||||
for (int i = 0; i < commandArgsArray.length; i++) {
|
for (int i = 0; i < commandArgsArray.length; i++) {
|
||||||
gameCommand = gameCommand.replace("%ARG" + (i + 1) + "%", commandArgsArray[i]);
|
gameCommand = gameCommand.replace("%ARG" + (i + 1) + "%", commandArgsArray[i]);
|
||||||
}
|
}
|
||||||
gameCommand = gameCommand.replaceAll("%ARG\\d+%", "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameCommand.contains("%NAME%")) {
|
Pattern pattern = Pattern.compile(".*%ARG(\\d+)\\+%.*");
|
||||||
gameCommand = gameCommand.replace("%NAME%", user.getNick());
|
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() + "\"");
|
plugin.logDebug("GM: \"" + gameCommand.trim() + "\"");
|
||||||
try {
|
try {
|
||||||
plugin.commandQueue.add(new IRCCommand(
|
plugin.commandQueue.add(new IRCCommand(
|
||||||
@ -208,6 +232,7 @@ public class IRCMessageHandler {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
plugin.logError(ex.getMessage());
|
plugin.logError(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -990,6 +990,7 @@ public final class PurpleBot {
|
|||||||
optionPair.put("private", config.getString(commandKey + "private", "false"));
|
optionPair.put("private", config.getString(commandKey + "private", "false"));
|
||||||
optionPair.put("ctcp", config.getString(commandKey + "ctcp", "false"));
|
optionPair.put("ctcp", config.getString(commandKey + "ctcp", "false"));
|
||||||
optionPair.put("game_command", config.getString(commandKey + "game_command", ""));
|
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"));
|
optionPair.put("sender", config.getString(commandKey + "sender", "CONSOLE"));
|
||||||
extraCommands.addAll(config.getStringList(commandKey + "extra_commands"));
|
extraCommands.addAll(config.getStringList(commandKey + "extra_commands"));
|
||||||
plugin.logDebug("extra_commands: " + extraCommands.toString());
|
plugin.logDebug("extra_commands: " + extraCommands.toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user