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;
import dev.zontreck.ariaslib.exceptions.WrongArgumentTypeException;
public abstract class Argument<T> implements Cloneable
{
public boolean hasValue = false;
@ -33,27 +35,70 @@ public abstract class Argument<T> implements Cloneable
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
public Argument<T> clone() {
Argument<T> arg = null;
switch (getType())
try{
if(getType() == ArgumentType.LONG)
{
case LONG -> {
arg = (Argument<T>) new LongArgument(name, (long)getValue());
break;
}
case STRING -> {
arg = (Argument<T>) new StringArgument(name, (String)getValue());
break;
}
case BOOLEAN -> {
arg = (Argument<T>) new LongArgument(name, getAsLong().getValue());
} else if(getType() == ArgumentType.STRING)
{
arg = (Argument<T>) new StringArgument(name, getAsString().getValue());
} else if(getType() == ArgumentType.BOOLEAN) {
arg = (Argument<T>) new BooleanArgument(name);
break;
}
case INTEGER -> {
arg = (Argument<T>) new IntegerArgument(name, (int)getValue());
break;
} else if(getType() == ArgumentType.INTEGER){
arg = (Argument<T>) new IntegerArgument(name, getAsInteger().getValue());
}
}catch (WrongArgumentTypeException ex)
{
ex.printStackTrace();
}
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
* <br/><br/>
* your text here [=========> ] 40% your text here
* <br><br>
* your text here [========= ] 40% your text here
* @param percent The percentage
* @param beforeText
* @param afterText