Skip to content

Commit

Permalink
It begins...
Browse files Browse the repository at this point in the history
Start of the user command documentation.
  • Loading branch information
gravityfox committed Nov 21, 2015
1 parent 5521793 commit e3e5e0d
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 34 deletions.
16 changes: 8 additions & 8 deletions src/main/java/net/gravityfox/foxguard/FGStorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void writeFlagSets() {
for (IFlagSet flagSet : FGManager.getInstance().getFlagSetsListCopy()) {
statement.addBatch("INSERT INTO FLAGSETS(NAME, TYPE, PRIORITY) VALUES ('" +
flagSet.getName() + "', '" +
flagSet.getUniqueType() + "', " +
flagSet.getUniqueTypeString() + "', " +
flagSet.getPriority() + ");");
}
statement.executeBatch();
Expand All @@ -302,7 +302,7 @@ public void writeFlagSets() {
statement.addBatch("INSERT INTO FOXGUARD_META.METADATA(CATEGORY, NAME, TYPE, PRIORITY) VALUES (" +
"'flagset', '" +
flagSet.getName() + "', '" +
flagSet.getUniqueType() + "', " +
flagSet.getUniqueTypeString() + "', " +
flagSet.getPriority() + ");");
statement.executeBatch();
}
Expand All @@ -326,7 +326,7 @@ public void writeWorld(World world) {
for (IRegion region : FGManager.getInstance().getRegionsListCopy(world)) {
statement.addBatch("INSERT INTO REGIONS(NAME, TYPE) VALUES ('" +
region.getName() + "', '" +
region.getUniqueType() + "');");
region.getUniqueTypeString() + "');");
for (IFlagSet flagSet : region.getFlagSets()) {
statement.addBatch("INSERT INTO LINKAGES(REGION, FLAGSET) VALUES ('" +
region.getName() + "', '" +
Expand All @@ -353,7 +353,7 @@ public void writeWorld(World world) {
statement.addBatch("INSERT INTO FOXGUARD_META.METADATA(CATEGORY, NAME, TYPE, WORLD) VALUES (" +
"'region', '" +
region.getName() + "', '" +
region.getUniqueType() + "', '" +
region.getUniqueTypeString() + "', '" +
region.getWorld().getName() + "');");
statement.executeBatch();
}
Expand Down Expand Up @@ -394,7 +394,7 @@ public void updateRegion(IRegion region) {
statement.addBatch("INSERT INTO FOXGUARD_META.METADATA(CATEGORY, NAME, TYPE, WORLD) VALUES (" +
"'region', '" +
region.getName() + "', '" +
region.getUniqueType() + "', '" +
region.getUniqueTypeString() + "', '" +
region.getWorld().getName() + "');");
statement.executeBatch();
}
Expand Down Expand Up @@ -424,7 +424,7 @@ public void updateFlagSet(IFlagSet flagSet) {
statement.addBatch("INSERT INTO FOXGUARD_META.METADATA(CATEGORY, NAME, TYPE, PRIORITY) VALUES (" +
"'flagset', '" +
flagSet.getName() + "', '" +
flagSet.getUniqueType() + "', " +
flagSet.getUniqueTypeString() + "', " +
flagSet.getPriority() + ");");
statement.executeBatch();
}
Expand All @@ -450,7 +450,7 @@ public void updateLists() {
for (IRegion region : FGManager.getInstance().getRegionsListCopy(world)) {
statement.addBatch("INSERT INTO REGIONS(NAME, TYPE) VALUES ('" +
region.getName() + "', '" +
region.getUniqueType() + "');");
region.getUniqueTypeString() + "');");
for (IFlagSet flagSet : region.getFlagSets()) {
statement.addBatch("INSERT INTO LINKAGES(REGION, FLAGSET) VALUES ('" +
region.getName() + "', '" +
Expand All @@ -468,7 +468,7 @@ public void updateLists() {
for (IFlagSet flagSet : FGManager.getInstance().getFlagSetsListCopy()) {
statement.addBatch("INSERT INTO FLAGSETS(NAME, TYPE, PRIORITY) VALUES ('" +
flagSet.getName() + "', '" +
flagSet.getUniqueType() + "', " +
flagSet.getUniqueTypeString() + "', " +
flagSet.getPriority() + ");");
}
statement.executeBatch();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/gravityfox/foxguard/IFGObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public interface IFGObject {

void setName(String name);

String getType();
String getShortTypeName();

String getUniqueType();
String getLongTypeName();

String getUniqueTypeString();

Text getDetails(String arguments);

Expand Down
18 changes: 13 additions & 5 deletions src/main/java/net/gravityfox/foxguard/commands/CommandDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.spongepowered.api.util.command.CommandResult;
import org.spongepowered.api.util.command.CommandSource;
import org.spongepowered.api.util.command.args.ArgumentParseException;
import org.spongepowered.api.util.command.source.ConsoleSource;
import org.spongepowered.api.world.World;
import net.gravityfox.foxguard.FGManager;
import net.gravityfox.foxguard.FoxGuardMain;
Expand Down Expand Up @@ -89,23 +88,32 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
throw new CommandException(Texts.of("No region with name \"" + args[1 + flag] + "\"!"));
TextBuilder builder = Texts.builder();
builder.append(Texts.of(TextColors.GOLD, "-----------------------------------------------------\n"));
builder.append(Texts.of(TextColors.GREEN, "---General---\n"));
builder.append(Texts.of(TextColors.GOLD, "Name: "), Texts.of(TextColors.RESET, region.getName() + "\n"));
builder.append(Texts.of(TextColors.GOLD, "Type: "), Texts.of(TextColors.RESET, region.getLongTypeName() + "\n"));
builder.append(Texts.of(TextColors.GOLD, "World: "), Texts.of(TextColors.RESET, region.getWorld().getName() + "\n"));
builder.append(Texts.of(TextColors.GREEN, "---Details---\n"));
builder.append(region.getDetails(args.length < 3 + flag ? "" : args[2 + flag]));
builder.append(Texts.of(TextColors.GREEN, "\n---Linked FlagSets---"));
if (region.getFlagSets().size() == 0)
builder.append(Texts.of(TextStyles.ITALIC, "\nNo linked FlagSets!"));
region.getFlagSets().stream().forEach(flagSet -> builder.append(Texts.of(FGHelper.getColorForFlagSet(flagSet),
"\n" + flagSet.getType() + " : " + flagSet.getName())));
"\n" + flagSet.getShortTypeName() + " : " + flagSet.getName())));
player.sendMessage(builder.build());

} else if (FGHelper.contains(flagSetsAliases, args[0])) {
if (args.length < 2) throw new CommandException(Texts.of("Must specify a name!"));
TextBuilder builder = Texts.builder();
builder.append(Texts.of(TextColors.GOLD, "-----------------------------------------------------\n"));
builder.append(Texts.of(TextColors.GREEN, "---Details---\n"));

IFlagSet flagSet = FGManager.getInstance().getFlagSet(args[1]);
if (flagSet == null)
throw new CommandException(Texts.of("No region with name \"" + args[1] + "\"!"));
TextBuilder builder = Texts.builder();
builder.append(Texts.of(TextColors.GOLD, "-----------------------------------------------------\n"));
builder.append(Texts.of(TextColors.GREEN, "---General---\n"));
builder.append(Texts.of(TextColors.GOLD, "Name: "), Texts.of(TextColors.RESET, flagSet.getName() + "\n"));
builder.append(Texts.of(TextColors.GOLD, "Type: "), Texts.of(TextColors.RESET, flagSet.getLongTypeName() + "\n"));
builder.append(Texts.of(TextColors.GOLD, "Priority: "), Texts.of(TextColors.RESET, flagSet.getPriority() + "\n"));
builder.append(Texts.of(TextColors.GREEN, "---Details---\n"));
builder.append(flagSet.getDetails(args.length < 3 ? "" : args[2]));
player.sendMessage(builder.build());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
while (flagSetListIterator.hasNext()) {
IFlagSet flagSet = flagSetListIterator.next();
output.append(Texts.of(FGHelper.getColorForFlagSet(flagSet),
flagSet.getType() + " : " + flagSet.getName()));
flagSet.getShortTypeName() + " : " + flagSet.getName()));
if (flagSetListIterator.hasNext()) output.append(Texts.of("\n"));
}
source.sendMessage(output.build());
Expand All @@ -132,7 +132,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm


private String getRegionName(IRegion region, boolean dispWorld) {
return region.getType() + " : " + (dispWorld ? region.getWorld().getName() + " : " : "") + region.getName();
return region.getShortTypeName() + " : " + (dispWorld ? region.getWorld().getName() + " : " : "") + region.getName();
}

private boolean contains(String[] aliases, String input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
while (regionIterator.hasNext()) {
IRegion region = regionIterator.next();
output.append(Texts.of(FGHelper.getColorForRegion(region),
"\n " + (index++) + ": " + region.getType() + " : " + region.getWorld().getName() + " : " + region.getName()));
"\n " + (index++) + ": " + region.getShortTypeName() + " : " + region.getWorld().getName() + " : " + region.getName()));
}
output.append(Texts.of("\n"));
flag++;
Expand All @@ -77,7 +77,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
while (flagSetIterator.hasNext()) {
IFlagSet flagSet = flagSetIterator.next();
output.append(Texts.of(FGHelper.getColorForFlagSet(flagSet),
"\n " + (index++) + ": " + flagSet.getType() + " : " + flagSet.getName()));
"\n " + (index++) + ": " + flagSet.getShortTypeName() + " : " + flagSet.getName()));
}
output.append(Texts.of("\n"));
flag++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ public CommandResult process(CommandSource source, String inputArguments) throws
}
@SuppressWarnings("unchecked")
final Optional<Text> helpText = (Optional<Text>) command.getHelp(source);
source.sendMessage(helpText.orElse(Texts.of("Usage: " + usagePrefix + " ").builder().append(command.getUsage(source)).build()));
TextBuilder builder = Texts.builder();
if (helpText.isPresent()) builder.append(Texts.of(TextColors.GREEN, "----------"),
Texts.of(TextColors.GOLD, "Command \""),
Texts.of(TextColors.GOLD, optCommand.get().getPrimaryAlias()),
Texts.of(TextColors.GOLD, "\" Help"),
Texts.of(TextColors.GREEN, "----------\n"));
source.sendMessage(builder.append(helpText.orElse(Texts.of("Usage: " + usagePrefix + " ").builder().append(command.getUsage(source)).build())).build());
return CommandResult.empty();
} else {
source.sendMessage(this.getHelp(source).get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
FGCommandMainDispatcher.getInstance().getStateMap().get(source).selectedFlagSets.stream().forEach(flagSets::add);
for (String flagSetName : Arrays.copyOfRange(args, 1, args.length)) {
IFlagSet flagSet = FGManager.getInstance().getFlagSet(flagSetName);
if (flagSet != null) {
if (flagSet != null && !flagSets.contains(flagSet)) {
flagSets.add(flagSet);
} else {
failures++;
}
}
if (flagSets.size() < 1) throw new CommandException(Texts.of("You must specify at least one FlagSet!"));
if (args[0].startsWith("~")) {
int deltaPriority;
try {
Expand All @@ -85,7 +86,6 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
flagSet.setPriority(flagSet.getPriority() + deltaPriority);
successes++;
}

} else {
int priority;
try {
Expand Down Expand Up @@ -115,12 +115,15 @@ public boolean testPermission(CommandSource source) {

@Override
public Optional<? extends Text> getShortDescription(CommandSource source) {
return Optional.empty();
return Optional.of(Texts.of("Sets or changes the priority of one or more FlagSets."));
}

@Override
public Optional<? extends Text> getHelp(CommandSource source) {
return Optional.empty();
return Optional.of(Texts.of("This command will modify the priorities of all FlagSets currently in your state buffer.\n" +
"This command takes a minimum of one parameter, which is the priority that all FlagSets will be set to.\n" +
"Prefixing this value with a tilde (\" ~ \") instead increments or decrements the priority of each FlagSet by that value.\n" +
"Any arguments after the priority are understood to be additional FlagSet names not already in your state buffer."));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ public void setName(String name) {
}

@Override
public String getType() {
public String getShortTypeName() {
return "Global";
}

@Override
public String getUniqueType() {
public String getLongTypeName() {
return "Global";
}

@Override
public String getUniqueTypeString() {
return "global";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,17 @@ public Tristate isFlagAllowed(PassiveFlags flag, Event event) {
}

@Override
public String getType() {
public String getShortTypeName() {
return "Simple";
}

@Override
public String getUniqueType() {
public String getLongTypeName() {
return "Simple";
}

@Override
public String getUniqueTypeString() {
return "simple";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,17 @@ public boolean isInRegion(double x, double y, double z) {
}

@Override
public String getType() {
public String getShortTypeName() {
return "Cube";
}

@Override
public String getLongTypeName() {
return "Cuboid";
}

@Override
public String getUniqueType() {
public String getUniqueTypeString() {
return "cuboid";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ public void setName(String name) {
}

@Override
public String getType() {
public String getShortTypeName() {
return "Global";
}

@Override
public String getUniqueType() {
public String getLongTypeName() {
return "Global";
}

@Override
public String getUniqueTypeString() {
return "global";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,17 @@ public boolean isInRegion(double x, double y, double z) {
}

@Override
public String getType() {
public String getShortTypeName() {
return "Rect";
}

@Override
public String getUniqueType() {
public String getLongTypeName() {
return "Rectangular";
}

@Override
public String getUniqueTypeString() {
return "rectangular";
}

Expand Down

0 comments on commit e3e5e0d

Please sign in to comment.