Minor FAVS cleanup
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package com.thevoxelbox.voxelsniper.jsap;
|
||||
|
||||
import com.martiansoftware.jsap.JSAP;
|
||||
import com.martiansoftware.jsap.JSAPException;
|
||||
import com.martiansoftware.jsap.JSAPResult;
|
||||
import com.martiansoftware.jsap.Switch;
|
||||
import com.martiansoftware.util.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
@@ -7,21 +14,12 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.martiansoftware.jsap.JSAP;
|
||||
import com.martiansoftware.jsap.JSAPException;
|
||||
import com.martiansoftware.jsap.JSAPResult;
|
||||
import com.martiansoftware.jsap.Switch;
|
||||
import com.martiansoftware.util.StringUtils;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* JSAP parser with help generating code.
|
||||
*
|
||||
* @author MikeMatrix
|
||||
*/
|
||||
public class HelpJSAP extends JSAP
|
||||
{
|
||||
public class HelpJSAP extends JSAP {
|
||||
|
||||
private String name;
|
||||
private String explanation;
|
||||
@@ -32,20 +30,16 @@ public class HelpJSAP extends JSAP
|
||||
* @param explanation
|
||||
* @param screenWidth
|
||||
*/
|
||||
public HelpJSAP(final String name, final String explanation, final int screenWidth)
|
||||
{
|
||||
public HelpJSAP(final String name, final String explanation, final int screenWidth) {
|
||||
super();
|
||||
|
||||
this.name = name;
|
||||
this.explanation = explanation;
|
||||
this.screenWidth = screenWidth;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
this.registerParameter(new Switch("help", JSAP.NO_SHORTFLAG, "help", "Displays this help page."));
|
||||
}
|
||||
catch (final JSAPException e)
|
||||
{
|
||||
} catch (final JSAPException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,26 +48,19 @@ public class HelpJSAP extends JSAP
|
||||
* @param explanation
|
||||
* @param screenWidth
|
||||
* @param resourceName
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an I/O error occurs
|
||||
* @throws com.martiansoftware.jsap.JSAPException
|
||||
* if the configuration is not valid
|
||||
* @throws java.io.IOException if an I/O error occurs
|
||||
* @throws com.martiansoftware.jsap.JSAPException if the configuration is not valid
|
||||
*/
|
||||
public HelpJSAP(final String name, final String explanation, final int screenWidth, final String resourceName) throws IOException, JSAPException
|
||||
{
|
||||
public HelpJSAP(final String name, final String explanation, final int screenWidth, final String resourceName) throws IOException, JSAPException {
|
||||
super(resourceName);
|
||||
|
||||
this.name = name;
|
||||
this.explanation = explanation;
|
||||
this.screenWidth = screenWidth;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
this.registerParameter(new Switch("help", JSAP.NO_SHORTFLAG, "help", "Displays this help page."));
|
||||
}
|
||||
catch (final JSAPException e)
|
||||
{
|
||||
} catch (final JSAPException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,95 +69,74 @@ public class HelpJSAP extends JSAP
|
||||
* @param explanation
|
||||
* @param screenWidth
|
||||
* @param jsapXML
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an I/O error occurs
|
||||
* @throws com.martiansoftware.jsap.JSAPException
|
||||
* if the configuration is not valid
|
||||
* @throws java.io.IOException if an I/O error occurs
|
||||
* @throws com.martiansoftware.jsap.JSAPException if the configuration is not valid
|
||||
*/
|
||||
public HelpJSAP(final String name, final String explanation, final int screenWidth, final URL jsapXML) throws IOException, JSAPException
|
||||
{
|
||||
public HelpJSAP(final String name, final String explanation, final int screenWidth, final URL jsapXML) throws IOException, JSAPException {
|
||||
super(jsapXML);
|
||||
|
||||
this.name = name;
|
||||
this.explanation = explanation;
|
||||
this.screenWidth = screenWidth;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
this.registerParameter(new Switch("help", JSAP.NO_SHORTFLAG, "help", "Displays this help page."));
|
||||
}
|
||||
catch (final JSAPException e)
|
||||
{
|
||||
} catch (final JSAPException e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the explanation
|
||||
*/
|
||||
public final String getExplanation()
|
||||
{
|
||||
public final String getExplanation() {
|
||||
return this.explanation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param explanation
|
||||
* the explanation to set
|
||||
* @param explanation the explanation to set
|
||||
*/
|
||||
public final void setExplanation(final String explanation)
|
||||
{
|
||||
public final void setExplanation(final String explanation) {
|
||||
this.explanation = explanation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public final String getName()
|
||||
{
|
||||
public final String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
* @param name the name to set
|
||||
*/
|
||||
public final void setName(final String name)
|
||||
{
|
||||
public final void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the screenWidth
|
||||
*/
|
||||
public final int getScreenWidth()
|
||||
{
|
||||
public final int getScreenWidth() {
|
||||
return this.screenWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param screenWidth
|
||||
* the screenWidth to set
|
||||
* @param screenWidth the screenWidth to set
|
||||
*/
|
||||
public final void setScreenWidth(final int screenWidth)
|
||||
{
|
||||
public final void setScreenWidth(final int screenWidth) {
|
||||
this.screenWidth = screenWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jsapResult
|
||||
*
|
||||
* @return if something has been written on writer.
|
||||
*/
|
||||
public final List<String> writeHelpOrErrorMessageIfRequired(final JSAPResult jsapResult)
|
||||
{
|
||||
if (!(jsapResult.success()) || jsapResult.getBoolean("help"))
|
||||
{
|
||||
public final List<String> writeHelpOrErrorMessageIfRequired(final JSAPResult jsapResult) {
|
||||
if (!(jsapResult.success()) || jsapResult.getBoolean("help")) {
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
// To avoid spurious missing argument errors we never print errors if help is required.
|
||||
if (!jsapResult.getBoolean("help"))
|
||||
{
|
||||
for (final Iterator<?> err = jsapResult.getErrorMessageIterator(); err.hasNext(); )
|
||||
{
|
||||
if (!jsapResult.getBoolean("help")) {
|
||||
for (final Iterator<?> err = jsapResult.getErrorMessageIterator(); err.hasNext(); ) {
|
||||
returnValue.add(ChatColor.RED + "Error: " + ChatColor.DARK_RED + err.next());
|
||||
}
|
||||
|
||||
@@ -179,17 +145,14 @@ public class HelpJSAP extends JSAP
|
||||
returnValue.add(ChatColor.GOLD + "Usage:");
|
||||
|
||||
List<?> l = StringUtils.wrapToList(this.name + " " + this.getUsage(), this.screenWidth);
|
||||
for (final Object aL : l)
|
||||
{
|
||||
for (final Object aL : l) {
|
||||
returnValue.add(" " + aL.toString());
|
||||
}
|
||||
|
||||
if (this.explanation != null)
|
||||
{
|
||||
if (this.explanation != null) {
|
||||
returnValue.add("");
|
||||
l = StringUtils.wrapToList(this.explanation, this.screenWidth);
|
||||
for (final Object aL : l)
|
||||
{
|
||||
for (final Object aL : l) {
|
||||
final String next = (String) aL;
|
||||
returnValue.add(ChatColor.AQUA + next);
|
||||
}
|
||||
|
||||
@@ -10,22 +10,20 @@ import com.martiansoftware.jsap.StringParser;
|
||||
* @see com.martiansoftware.jsap.StringParser
|
||||
* @see Integer
|
||||
*/
|
||||
public class NullableIntegerStringParser extends StringParser
|
||||
{
|
||||
public class NullableIntegerStringParser extends StringParser {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final NullableIntegerStringParser INSTANCE = new NullableIntegerStringParser();
|
||||
private static final NullableIntegerStringParser INSTANCE = new NullableIntegerStringParser();
|
||||
|
||||
/**
|
||||
* Returns a {@link com.thevoxelbox.voxelsniper.jsap.NullableIntegerStringParser}.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* Convenient access to the only instance returned by this method is available through {@link com.martiansoftware.jsap.JSAP#INTEGER_PARSER}.
|
||||
*
|
||||
* @return a {@link com.thevoxelbox.voxelsniper.jsap.NullableIntegerStringParser}.
|
||||
*/
|
||||
public static NullableIntegerStringParser getParser()
|
||||
{
|
||||
public static NullableIntegerStringParser getParser() {
|
||||
return new NullableIntegerStringParser();
|
||||
}
|
||||
|
||||
@@ -34,8 +32,7 @@ public class NullableIntegerStringParser extends StringParser
|
||||
*
|
||||
* @deprecated Use {@link #getParser()} or, even better, {@link com.martiansoftware.jsap.JSAP#INTEGER_PARSER}.
|
||||
*/
|
||||
public NullableIntegerStringParser()
|
||||
{
|
||||
public NullableIntegerStringParser() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -43,31 +40,22 @@ public class NullableIntegerStringParser extends StringParser
|
||||
* Parses the specified argument into an Integer. This method delegates the parsing to <code>Integer.decode(arg)</code>. If <code>Integer.decode()</code>
|
||||
* throws a NumberFormatException, it is encapsulated into a ParseException and re-thrown.
|
||||
*
|
||||
* @param arg
|
||||
* the argument to parse
|
||||
*
|
||||
* @param arg the argument to parse
|
||||
* @return an Integer object with the value contained in the specified argument.
|
||||
*
|
||||
* @throws com.martiansoftware.jsap.ParseException
|
||||
* if <code>Integer.decode(arg)</code> throws a NumberFormatException.
|
||||
* @throws com.martiansoftware.jsap.ParseException if <code>Integer.decode(arg)</code> throws a NumberFormatException.
|
||||
* @see Integer
|
||||
* @see com.martiansoftware.jsap.StringParser#parse(String)
|
||||
*/
|
||||
@Override
|
||||
public final Object parse(final String arg) throws ParseException
|
||||
{
|
||||
if (arg == null)
|
||||
{
|
||||
public final Object parse(final String arg) throws ParseException {
|
||||
if (arg == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Integer result;
|
||||
try
|
||||
{
|
||||
try {
|
||||
result = Integer.decode(arg);
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw (new ParseException("Unable to convert '" + arg + "' to an Integer.", nfe));
|
||||
}
|
||||
return (result);
|
||||
|
||||
Reference in New Issue
Block a user