Browse Source

Add chat prefix config option to Commands feature

pull/8/head
Anton Tarasenko 3 years ago
parent
commit
0d285cb440
  1. 4
      sources/Commands/Command.uc
  2. 32
      sources/Commands/Commands.uc
  3. 15
      sources/Commands/Commands_Feature.uc

4
sources/Commands/Command.uc

@ -357,6 +357,10 @@ public final function bool Execute(CallData callData, EPlayer callerPlayer)
ReportError(callData, callerPlayer);
return false;
}
callerPlayer.BorrowConsole()
.Write(P("Executing command `"))
.Write(commandData.name)
.Say(P("`"));
Executed(callData, callerPlayer);
if (commandData.requiresTarget)
{

32
sources/Commands/Commands.uc

@ -21,8 +21,9 @@ class Commands extends FeatureConfig
perobjectconfig
config(AcediaSystem);
var public config bool useChatInput;
var public config bool useMutateInput;
var public config bool useChatInput;
var public config bool useMutateInput;
var public config string chatCommandPrefix;
protected function AssociativeArray ToData()
{
@ -30,27 +31,38 @@ protected function AssociativeArray ToData()
data = __().collections.EmptyAssociativeArray();
data.SetBool(P("useChatInput"), useChatInput, true);
data.SetBool(P("useMutateInput"), useMutateInput, true);
data.SetItem( P("chatCommandPrefix"),
_.text.FromString(chatCommandPrefix), true);
return data;
}
protected function FromData(AssociativeArray source)
{
if (source != none)
{
useChatInput = source.GetBool(P("useChatInput"));
useMutateInput = source.GetBool(P("useMutateInput"));
local Text newChatPrefix;
if (source == none) {
return;
}
useChatInput = source.GetBool(P("useChatInput"));
useMutateInput = source.GetBool(P("useMutateInput"));
newChatPrefix = source.GetText(P("chatCommandPrefix"));
chatCommandPrefix = "!";
if (newChatPrefix != none) {
chatCommandPrefix = newChatPrefix.ToString();
}
_.memory.Free(newChatPrefix);
}
protected function DefaultIt()
{
useChatInput = true;
useMutateInput = true;
useChatInput = true;
useMutateInput = true;
chatCommandPrefix = "!";
}
defaultproperties
{
configName = "AcediaSystem"
useChatInput = true
useMutateInput = true
useChatInput = true
useMutateInput = true
chatCommandPrefix = "!"
}

15
sources/Commands/Commands_Feature.uc

@ -29,11 +29,16 @@ var private array<Text> commandDelimiters;
var private AssociativeArray registeredCommands;
// Setting this to `true` enables players to input commands right in the chat
// by prepending them with "!" character.
// by prepending them with `chatCommandPrefix`.
// Default is `true`.
var private /*config*/ bool useChatInput;
// Setting this to `true` enables players to input commands with "mutate"
// console command.
// Default is `true`.
var private /*config*/ bool useMutateInput;
// Chat messages, prepended by this prefix will be treated as commands.
// Default is "!". Empty values are also treated as "!".
var private /*config*/ Text chatCommandPrefix;
var LoggerAPI.Definition errCommandDuplicate;
@ -68,6 +73,8 @@ protected function OnDisabled()
registeredCommands = none;
}
commandDelimiters.length = 0;
_.memory.Free(chatCommandPrefix);
chatCommandPrefix = none;
}
protected function SwapConfig(FeatureConfig config)
@ -77,6 +84,8 @@ protected function SwapConfig(FeatureConfig config)
if (newConfig == none) {
return;
}
_.memory.Free(chatCommandPrefix);
chatCommandPrefix = _.text.FromString(newConfig.chatCommandPrefix);
if (useChatInput != newConfig.useChatInput)
{
useChatInput = newConfig.useChatInput;
@ -245,9 +254,9 @@ private function bool HandleCommands(
bool teamMessage)
{
local Parser parser;
// We are only interested in messages that start with "!"
// We are only interested in messages that start with `chatCommandPrefix`
parser = _.text.Parse(message);
if (!parser.Match(P("!")).Ok())
if (!parser.Match(chatCommandPrefix).Ok())
{
parser.FreeSelf();
return true;

Loading…
Cancel
Save