Fix up compile errors

This commit is contained in:
zontreck 2024-03-15 00:23:50 -07:00
parent f4b6f84167
commit 47e6a466f2
3 changed files with 70 additions and 18 deletions

View file

@ -1,5 +1,7 @@
package dev.zontreck.ariaslib.args; package dev.zontreck.ariaslib.args;
import dev.zontreck.ariaslib.exceptions.WrongArgumentTypeException;
public abstract class Argument<T> implements Cloneable public abstract class Argument<T> implements Cloneable
{ {
public boolean hasValue = false; public boolean hasValue = false;
@ -33,27 +35,70 @@ public abstract class Argument<T> implements Cloneable
throw new IllegalArgumentException("No value"); throw new IllegalArgumentException("No value");
} }
/**
* Directly cast to the Argument type Long
* @return
* @throws WrongArgumentTypeException Throws when type does not match
*/
public LongArgument getAsLong() throws WrongArgumentTypeException {
if(this instanceof LongArgument)
{
return (LongArgument) this;
}
throw new WrongArgumentTypeException();
}
/**
* Directly cast to the Argument type String
* @return
* @throws WrongArgumentTypeException Throws when type does not match
*/
public StringArgument getAsString() throws WrongArgumentTypeException {
if(this instanceof StringArgument)
{
return (StringArgument) this;
}
throw new WrongArgumentTypeException();
}
/**
* Directly cast to the Argument type Integer
* @return
* @throws WrongArgumentTypeException Throws when type does not match
*/
public IntegerArgument getAsInteger() throws WrongArgumentTypeException
{
if(this instanceof IntegerArgument)
{
return (IntegerArgument) this;
}
throw new WrongArgumentTypeException();
}
@Override @Override
public Argument<T> clone() { public Argument<T> clone() {
Argument<T> arg = null; Argument<T> arg = null;
switch (getType()) try{
if(getType() == ArgumentType.LONG)
{ {
case LONG -> { arg = (Argument<T>) new LongArgument(name, getAsLong().getValue());
arg = (Argument<T>) new LongArgument(name, (long)getValue()); } else if(getType() == ArgumentType.STRING)
break; {
} arg = (Argument<T>) new StringArgument(name, getAsString().getValue());
case STRING -> { } else if(getType() == ArgumentType.BOOLEAN) {
arg = (Argument<T>) new StringArgument(name, (String)getValue());
break;
}
case BOOLEAN -> {
arg = (Argument<T>) new BooleanArgument(name); arg = (Argument<T>) new BooleanArgument(name);
break; } else if(getType() == ArgumentType.INTEGER){
} arg = (Argument<T>) new IntegerArgument(name, getAsInteger().getValue());
case INTEGER -> {
arg = (Argument<T>) new IntegerArgument(name, (int)getValue());
break;
} }
}catch (WrongArgumentTypeException ex)
{
ex.printStackTrace();
} }
return arg; return arg;

View file

@ -0,0 +1,7 @@
package dev.zontreck.ariaslib.exceptions;
public class WrongArgumentTypeException extends Exception
{
}

View file

@ -25,8 +25,8 @@ public class ProgressBar
/** /**
* Build a progress bar * Build a progress bar
* <br/><br/> * <br><br>
* your text here [=========> ] 40% your text here * your text here [========= ] 40% your text here
* @param percent The percentage * @param percent The percentage
* @param beforeText * @param beforeText
* @param afterText * @param afterText