Skip to content

Commit

Permalink
feat(command): add execute module
Browse files Browse the repository at this point in the history
- Added execute module
- Fixed a bug causing EITHER action to omit displaying message on the very first perform callback
  • Loading branch information
iGoodie committed Jan 1, 2020
1 parent 53e6086 commit 9723dda
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.daemon=false

mod_id=twitchspawn
mod_group=net.programmer.igoodie
mod_version=0.4.14
mod_version=0.4.15

minecraft_version=1.12.2
forge_version=14.23.3.2655
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public TwitchSpawnCommand() {
registerModule(new ModuleRules());
registerModule(new ModuleSimulate());
registerModule(new ModuleTest());
registerModule(new ModuleExecute());
}

private void registerModule(CommandModule module) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.programmer.igoodie.twitchspawn.command.module;

import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.programmer.igoodie.twitchspawn.tslanguage.EventArguments;
import net.programmer.igoodie.twitchspawn.tslanguage.action.TSLAction;
import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser;
import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError;
import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLTokenizer;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class ModuleExecute extends CommandModule {

@Override
public String getName() {
return "execute";
}

@Override
public String getUsage() {
return super.getUsage() + " <tsl_action>";
}

@Override
public void execute(ICommandSender commandSender, String[] moduleArgs) throws CommandException {
try {
TSLAction tslAction = parseAction(moduleArgs);
EventArguments eventArguments = EventArguments.createRandom(commandSender.getName());
tslAction.process(eventArguments);

} catch (TSLSyntaxError e) {
throw new CommandException(e.getMessage());
}
}

private TSLAction parseAction(String[] moduleArgs) throws CommandException, TSLSyntaxError {
if (moduleArgs.length == 0)
throw new CommandException("Expected at least 1 TSL word!");

List<String> words = TSLTokenizer.intoWords(String.join(" ", moduleArgs));
String actionName = words.remove(0);

return TSLParser.parseAction(actionName, words);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public EitherAction(List<String> words) throws TSLSyntaxError {
throw new TSLSyntaxError("Expected at least 2 actions, found -> " + this.actions.size());

selectedAction = actions.randomItem();
message = selectedAction.message;
}

private void parseActions(List<String> words) throws TSLSyntaxError {
Expand Down

0 comments on commit 9723dda

Please sign in to comment.