Easier addon getter by their name (#939)

* Easier addon getter by their name

A small improvement to get a certain addon from its name.
This allows getting addon main class without the necessity to cast if afterwards (as the cast is done in `getAddonByName()` method).

* Use cast on CompositeCommand#getAddons()

This will allow getting correct addon class without casting in code.
Casting will be done in CompositeCommand#getAddons() method.
This commit is contained in:
BONNe 2019-09-14 22:12:18 +03:00 committed by Florian CUNY
parent e38c3b55f4
commit 4206435d65
2 changed files with 6 additions and 4 deletions

View File

@ -673,8 +673,9 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
/**
* @return the addon
*/
public Addon getAddon() {
return addon;
@SuppressWarnings("unchecked")
public <T extends Addon> T getAddon() {
return (T) addon;
}
/**

View File

@ -250,8 +250,9 @@ public class AddonsManager {
* @return Optional addon object
*/
@NonNull
public Optional<Addon> getAddonByName(@NonNull String name){
return addons.stream().filter(a -> a.getDescription().getName().equalsIgnoreCase(name)).findFirst();
@SuppressWarnings("unchecked")
public <T extends Addon> Optional<T> getAddonByName(@NonNull String name){
return addons.stream().filter(a -> a.getDescription().getName().equalsIgnoreCase(name)).map(a -> (T) a).findFirst();
}
@NonNull