Skip to content

Commit

Permalink
Fix Command Parser.
Browse files Browse the repository at this point in the history
Fix a few text issues.
  • Loading branch information
gravityfox committed Jan 2, 2016
1 parent eb24713 commit 8d5ecc1
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.Logger;

@Mod(modid = "foxcoreforge", name = "FoxCoreForge", version = FoxCoreMain.VERSION, acceptableRemoteVersions = "*")
@Mod(modid = "foxcorecui", name = "FoxCoreCUI", version = FoxCoreMain.VERSION, acceptableRemoteVersions = "*")
public class FoxCoreForgeMain {

@Mod.Instance("foxcoreforge")
@Mod.Instance("foxcorecui")
public static FoxCoreForgeMain instance;

@SidedProxy(modId = "foxcoreforge", clientSide = "net.foxdenstudio.sponge.foxcore.mod.ClientProxy", serverSide = "net.foxdenstudio.sponge.foxcore.mod.CommonProxy")
@SidedProxy(modId = "foxcorecui", clientSide = "net.foxdenstudio.sponge.foxcore.mod.ClientProxy", serverSide = "net.foxdenstudio.sponge.foxcore.mod.CommonProxy")
public static CommonProxy proxy;

public static Logger logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
if (result.isSuccess()) {
if (result.getMessage().isPresent()) {
if (!FCHelper.hasColor(result.getMessage().get())) {
source.sendMessage(result.getMessage().get().builder().color(TextColors.GREEN).build());
source.sendMessage(result.getMessage().get().toBuilder().color(TextColors.GREEN).build());
} else {
source.sendMessage(result.getMessage().get());
}
Expand All @@ -76,7 +76,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
} else {
if (result.getMessage().isPresent()) {
if (!FCHelper.hasColor(result.getMessage().get())) {
source.sendMessage(result.getMessage().get().builder().color(TextColors.RED).build());
source.sendMessage(result.getMessage().get().toBuilder().color(TextColors.RED).build());
} else {
source.sendMessage(result.getMessage().get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
if (result.isSuccess()) {
if (result.getMessage().isPresent()) {
if (!FCHelper.hasColor(result.getMessage().get())) {
source.sendMessage(result.getMessage().get().builder().color(TextColors.GREEN).build());
source.sendMessage(result.getMessage().get().toBuilder().color(TextColors.GREEN).build());
} else {
source.sendMessage(result.getMessage().get());
}
Expand All @@ -64,7 +64,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
} else {
if (result.getMessage().isPresent()) {
if (!FCHelper.hasColor(result.getMessage().get())) {
source.sendMessage(result.getMessage().get().builder().color(TextColors.RED).build());
source.sendMessage(result.getMessage().get().toBuilder().color(TextColors.RED).build());
} else {
source.sendMessage(result.getMessage().get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
if (result.isSuccess()) {
if (result.getMessage().isPresent()) {
if (!FCHelper.hasColor(result.getMessage().get())) {
source.sendMessage(result.getMessage().get().builder().color(TextColors.GREEN).build());
source.sendMessage(result.getMessage().get().toBuilder().color(TextColors.GREEN).build());
} else {
source.sendMessage(result.getMessage().get());
}
Expand All @@ -87,7 +87,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
} else {
if (result.getMessage().isPresent()) {
if (!FCHelper.hasColor(result.getMessage().get())) {
source.sendMessage(result.getMessage().get().builder().color(TextColors.RED).build());
source.sendMessage(result.getMessage().get().toBuilder().color(TextColors.RED).build());
} else {
source.sendMessage(result.getMessage().get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
import org.spongepowered.api.text.format.TextColors;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public class CommandTest implements CommandCallable {

/*
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (!testPermission(source)) {
source.sendMessage(Text.of(TextColors.RED, "You don't have permission to use this command!"));
Expand All @@ -56,10 +58,11 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
source.sendMessage(builder.build());
return CommandResult.empty();
}
*/

@Override
public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
AdvCmdParse.ParseResult parse = AdvCmdParse.builder().arguments(arguments).autoCloseQuotes(true).limit(3).parse2();
AdvCmdParse.ParseResult parse = AdvCmdParse.builder().arguments(arguments).autoCloseQuotes(true).limit(2).parse2();
Text.Builder builder = Text.builder();
builder.append(Text.of(TextColors.GOLD, "-----------------------------\n"));
builder.append(Text.of(TextColors.GOLD, "Args: \"", TextColors.RESET, arguments, TextColors.GOLD, "\"\n"));
Expand Down Expand Up @@ -91,7 +94,7 @@ public Text getUsage(CommandSource source) {
return Text.of("test [mystery args]...");
}

/*

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (!testPermission(source)) {
Expand All @@ -111,5 +114,5 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
}
source.sendMessage(builder.build());
return CommandResult.empty();
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public CommandResult process(CommandSource source, String inputArguments) throws
Text.of(TextColors.GOLD, optCommand.get().getPrimaryAlias()),
Text.of(TextColors.GOLD, "\" Help"),
Text.of(TextColors.GREEN, "----------\n"));
source.sendMessage(builder.append(helpText.orElse(Text.of("Usage: " + dispatcherPrefix + " ").builder().append(command.getUsage(source)).build())).build());
source.sendMessage(builder.append(helpText.orElse(Text.of("Usage: " + dispatcherPrefix + " ").toBuilder().append(command.getUsage(source)).build())).build());
return CommandResult.empty();
} else {
source.sendMessage(this.getHelp(source).get());
Expand All @@ -224,8 +224,8 @@ public CommandResult process(CommandSource source, String inputArguments) throws
} catch (CommandException e) {
Text text = e.getText();
if (text == null) text = Text.of("There was an error processing command: " + args[0]);
source.sendMessage(text.builder().color(TextColors.RED).build());
source.sendMessage(Text.of("Usage: " + dispatcherPrefix + " ").builder()
source.sendMessage(text.toBuilder().color(TextColors.RED).build());
source.sendMessage(Text.of("Usage: " + dispatcherPrefix + " ").toBuilder()
.append(command.getUsage(source)).color(TextColors.RED).build());
return CommandResult.empty();
}
Expand Down Expand Up @@ -283,7 +283,7 @@ public Optional<? extends Text> getHelp(CommandSource source) {
if (this.commands.isEmpty()) {
return Optional.empty();
}
Text.Builder build = Text.of(TextColors.GREEN, "Available commands:\n").builder();
Text.Builder build = Text.of(TextColors.GREEN, "Available commands:\n").toBuilder();
for (Iterator<CommandMapping> it = filterCommandMappings(source).iterator(); it.hasNext(); ) {

CommandMapping mapping = it.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@ public ParseResult parse() throws CommandException {
}
}

if (!finalString.isEmpty())

{
finalList.add(finalString);
}
// Converts final argument list to an array.
parseResult.args = finalList.toArray(new String[finalList.size()]);

Expand Down Expand Up @@ -286,7 +281,6 @@ public ParseResult parse2() throws CommandException {
// Matcher for identifying arguments and flags.
Matcher matcher = pattern.matcher(arguments);
boolean lastIsCurrent = !(arguments.length() == 0) && (inQuote || !arguments.substring(arguments.length() - 1).matches("[\"' ]"));
System.out.println(lastIsCurrent);

// Iterate through matches
while (matcher.find()) {
Expand Down Expand Up @@ -388,6 +382,7 @@ public ParseResult parse2() throws CommandException {
if (!lastIsCurrent && (parseResult.currentElement == null || parseResult.currentElement.type != CurrentElement.ElementType.COMMENT)) {
parseResult.currentElement = new CurrentElement(CurrentElement.ElementType.ARGUMENT, "", argsList.size(), "");
}
System.out.println(argsList);

// This part converts the argument list to the final argument array.
// A number of arguments are copied to a new list less than or equal to the limit.
Expand All @@ -404,6 +399,11 @@ public ParseResult parse2() throws CommandException {
}
}
}
if (!finalString.isEmpty()) {
finalList.add(finalString);
}

System.out.println(finalString);

if (parseResult.currentElement != null && parseResult.currentElement.type == CurrentElement.ElementType.ARGUMENT && parseResult.currentElement.index >= limit)
parseResult.currentElement = new CurrentElement(CurrentElement.ElementType.FINAL, finalString + (lastIsCurrent ? "" : " "), finalList.size() - 1, "");
Expand Down

0 comments on commit 8d5ecc1

Please sign in to comment.