mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 05:05:18 +01:00
Added JavaDoc to AddonRequestBuilder
This commit is contained in:
parent
1fe37a4b49
commit
55d0920a9c
@ -9,57 +9,64 @@ import org.apache.commons.lang.Validate;
|
|||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API to enable plugins to request data from addons.
|
||||||
|
* Addons can expose data that they want to expose. To access it, call this class with the appropriate addon name, the label for the
|
||||||
|
* data that is requested and if required, a map of key-value pairs that will be given to the addon.
|
||||||
|
* @author HyKurtis
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class AddonRequestBuilder
|
public class AddonRequestBuilder
|
||||||
{
|
{
|
||||||
private String addonName;
|
private String addonName;
|
||||||
private String requestLabel;
|
private String requestLabel;
|
||||||
private Map<String, Object> metaData = new HashMap<>();
|
private Map<String, Object> metaData = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the addon you wish to request.
|
* Define the addon you wish to request.
|
||||||
*
|
*
|
||||||
* @param addonName addon name
|
* @param addonName addon name
|
||||||
*/
|
*/
|
||||||
public AddonRequestBuilder addon(String addonName) {
|
public AddonRequestBuilder addon(String addonName) {
|
||||||
this.addonName = addonName;
|
this.addonName = addonName;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define label for addon request.
|
* Define label for addon request.
|
||||||
*
|
*
|
||||||
* @param requestLabel request label
|
* @param requestLabel request label
|
||||||
*/
|
*/
|
||||||
public AddonRequestBuilder label(String requestLabel) {
|
public AddonRequestBuilder label(String requestLabel) {
|
||||||
this.requestLabel = requestLabel;
|
this.requestLabel = requestLabel;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add meta data to addon request.
|
* Add meta data to addon request.
|
||||||
*
|
*
|
||||||
* @param key key
|
* @param key key
|
||||||
* @param value value
|
* @param value value
|
||||||
*/
|
*/
|
||||||
public AddonRequestBuilder addMetaData(String key, Object value) {
|
public AddonRequestBuilder addMetaData(String key, Object value) {
|
||||||
metaData.put(key, value);
|
metaData.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send request to addon.
|
* Send request to addon.
|
||||||
*
|
*
|
||||||
* @return request response, null if no response.
|
* @return request response, null if no response.
|
||||||
*/
|
*/
|
||||||
public Object request() {
|
public Object request() {
|
||||||
Validate.notNull(addonName);
|
Validate.notNull(addonName);
|
||||||
Validate.notNull(requestLabel);
|
Validate.notNull(requestLabel);
|
||||||
|
|
||||||
Optional<Addon> addonOptional = BentoBox.getInstance().getAddonsManager().getAddonByName(addonName);
|
Optional<Addon> addonOptional = BentoBox.getInstance().getAddonsManager().getAddonByName(addonName);
|
||||||
if(addonOptional.isPresent()) {
|
if(addonOptional.isPresent()) {
|
||||||
Addon addon = addonOptional.get();
|
Addon addon = addonOptional.get();
|
||||||
return addon.request(requestLabel, metaData);
|
return addon.request(requestLabel, metaData);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user