Use of NBPAPI
About 722 wordsAbout 2 min
Warning
The package p1xel.nobuildplus.API.NBPAPI has been renamed to p1xel.nobuildplus.api.NBPAPI in the latest version.
Get the instance of NBPAPI
Create an new instance of NBPAPI in the main class of your plugin.
public class YourMainClass extends JavaPlugin {
private static NBPAPI nbpapi;
public static NBPAPI getNBPAPI();
@Override
public void onEnable() {
if (getServer.getPluginManager.getPlugin("NoBuildPlus") != null) {
nbpapi = new NBPAPI();
}
}
}NoBuildPlusAPI
NoBuildPlusAPI from source code
NoBuildPlusAPI.java
public interface NoBuildPlusAPI {
/**
* @return version of api
*/
String getVersion();
/**
* Register extra flags from your own plugin.
* Refresh the flag list after registration
* @param flag the class with implementing p1xel.nobuildplus.Flag
*/
void registerFlag(Flag flag);
/**
* Return the bool whether the player can do the action with flag.
* This method includes isWorldEnabled()
* @param world name of the world
* @param flag object Flags
* @return true if the player/mob/world can do the action.
**/
boolean canDo(String world, Flag flag);
/**
* Return the bool whether the plugin does protection with flag.
* This method includes isWorldEnabled()
* @param world name of the world
* @param flag object Flags
* @return true if NoBuildPlus executes the protection.
**/
boolean canExecute(String world, Flags flag);
/**
* Return the bool whether the plugin does protection with flag.
* This method includes isWorldEnabled()
* @param world name of the world
* @param flag enum value of implementing FlagInterface
* @return true if NoBuildPlus executes the protection.
**/
boolean canExecute(String world, Flag flag);
/**
* Return the bool whether the plugin does protection with flag.
* This method is including the area protection plugins checking.
* If the player is in the area they create, the protection would be cancelled.
* @param world name of the world
* @param flag enum value of implementing FlagInterface
* @param player the player
* @return true if NoBuildPlus executes the protection.
**/
boolean canExecute(String world, Flag flag, Player player);
/**
* Return the bool whether the plugin does protection with flag.
* This method is including the area protection plugins checking.
* If the location is in the area they create, the protection would be cancelled.
* @param world name of the world
* @param flag enum value of implementing FlagInterface
* @param location the location
* @return true if NoBuildPlus executes the protection.
**/
boolean canExecute(String world, Flag flag, Location location);
/**
* Return the bool whether the plugin does protection with flag.
* This method is including the area protection plugins checking.
* If the entity is in the area they create, the protection would be cancelled.
* @param world name of the world
* @param flag enum value of implementing FlagInterface
* @param entity the entity
* @return true if NoBuildPlus executes the protection.
**/
boolean canExecute(String world, Flag flag, Entity entity);
/**
* Return the bool whether the plugin does protection with flag.
* This method is including the area protection plugins checking.
* If the block is in the area they create, the protection would be cancelled.
* @param world name of the world
* @param flag enum value of implementing FlagInterface
* @param block the block
* @return true if NoBuildPlus executes the protection.
**/
boolean canExecute(String world, Flag flag, Block block);
/**
* You can get the flag, deny message and bypass permission
* through the ProtectedWorld, see usage at p1xel.nobuildplus.world.ProtectedWorld
* @param worldName name of the world
* @return instance of ProtectedWorld
**/
@Nullable
ProtectedWorld getWorld(String worldName);
/**
* @return the language that plugin selects
*/
String getLang();
/**
* Get whether the world is enabled for NoBuildPlus protection or not.
* canExecute() also include this code.
* @param world name of the world
* @return true if the world is protected by NoBuildPlus
**/
boolean isWorldEnabled(String world);
}Example
If you want to check whether the flag BREAK is enabled in worldName.
This method is only asking for the protection status of NoBuildPlus.
String world = "worldName";
NBPAPI api = new NBPAPI();
boolean canPlayerBreak = api.canDo(world, Flags.break);This method is not only asking the protection status, but also checking whether the location is in the area created by area protection plugin.
Location location = yourLocationHere;
// In this situation,
// If the server has installed area protection plugin such as Residence, Dominion and BlockRegen.
// This method would check whether the location is in the area created by those plugins or not.
// If it is, canExecute() would return false, which means that NoBuildPlus would not do protection to that location.
boolean isEnabled = api.canExecute(world, Flags.fire_spread, location);You can see all the flags of NoBuildPlus at p1xel.nobuildplus.Flags