-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from iAlexT/master
Add support for longs
- Loading branch information
Showing
8 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...rc/main/java/me/fixeddev/commandflow/annotated/part/defaults/factory/LongPartFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package me.fixeddev.commandflow.annotated.part.defaults.factory; | ||
|
||
import me.fixeddev.commandflow.annotated.annotation.Range; | ||
import me.fixeddev.commandflow.annotated.part.PartFactory; | ||
import me.fixeddev.commandflow.part.CommandPart; | ||
import me.fixeddev.commandflow.part.defaults.FloatPart; | ||
import me.fixeddev.commandflow.part.defaults.LongPart; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.List; | ||
|
||
public class LongPartFactory implements PartFactory { | ||
|
||
@Override | ||
public CommandPart createPart(String name, List<? extends Annotation> modifiers) { | ||
Range range = getAnnotation(modifiers, Range.class); | ||
|
||
if (range != null) { | ||
return new LongPart(name, range.min(), range.max()); | ||
} | ||
|
||
return new FloatPart(name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Universal/src/main/java/me/fixeddev/commandflow/part/defaults/LongPart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package me.fixeddev.commandflow.part.defaults; | ||
|
||
import me.fixeddev.commandflow.CommandContext; | ||
import me.fixeddev.commandflow.exception.ArgumentParseException; | ||
import me.fixeddev.commandflow.part.CommandPart; | ||
import me.fixeddev.commandflow.stack.ArgumentStack; | ||
import net.kyori.text.TranslatableComponent; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static net.kyori.text.TextComponent.of; | ||
|
||
public class LongPart extends PrimitivePart { | ||
|
||
private final long max; | ||
private final long min; | ||
private final boolean ranged; | ||
|
||
/** | ||
* Creates a PrimitivePart instance with the given name. | ||
* @param name The name for this part. | ||
*/ | ||
private LongPart(String name, long min, long max, boolean ranged) { | ||
super(name); | ||
this.min = min; | ||
this.max = max; | ||
this.ranged = ranged; | ||
} | ||
|
||
public LongPart(String name, long min, long max) { | ||
this(name, min, max, true); | ||
} | ||
|
||
public LongPart(String name) { | ||
this(name, 0L, 0L, false); | ||
} | ||
|
||
@Override | ||
public List<Long> parseValue(CommandContext context, ArgumentStack stack, CommandPart caller) throws ArgumentParseException { | ||
long next = stack.nextLong(); | ||
|
||
if (ranged && (next > max || next < min)) { | ||
throw new ArgumentParseException( | ||
TranslatableComponent.of( | ||
"number.out-range", | ||
of(next), | ||
of(min), | ||
of(max) | ||
) | ||
); | ||
} | ||
|
||
return Collections.singletonList(next); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return long.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters