mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-30 07:37:34 +02:00
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:
parent
e38c3b55f4
commit
4206435d65
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user