Class BanItemAPI

java.lang.Object
fr.andross.banitem.BanItemAPI

public final class BanItemAPI extends Object
BanItemAPI

IMPORTANT:

This api is loaded on next tick after server load, to allow other custom worlds plugins to load worlds. So this API is not available on server load, but will be on next available tick!

If you add/remove any action from a map (blacklist/whitelist), you have to reload the plugin listeners so it can handle correctly the actions, using BanListener.load(CommandSender) ()}

Version:
3.3
Author:
Andross
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addMetaItem(@NotNull String name, @NotNull org.bukkit.inventory.ItemStack item)
    Add an ItemStack as a meta item and save it in metaitems.yml.
    boolean
    addToBlacklist(@NotNull BannedItem item, @NotNull Map<BanAction,BanActionData> actions, @Nullable org.bukkit.World... worlds)
    Add a new banned item to blacklist and save the config file used.
    boolean
    addToBlacklist(@NotNull Collection<? extends BannedItem> items, @NotNull Map<BanAction,BanActionData> actions, @Nullable org.bukkit.World... worlds)
    Add the banned items to the blacklist and save the config file used.
    boolean
    addToWhitelist(@NotNull WhitelistedWorld whitelistedWorld, @NotNull BannedItem item, @NotNull Map<BanAction,BanActionData> actions)
    Add an item on the whitelist of a world and save in the used config.
    @NotNull Blacklist
    Blacklist handler which contains all blacklisted items.
    @Nullable BannedItem
    getCustomItem(@NotNull String customItemName)
    Get the configured custom item by its name.
    @NotNull CustomItems
    CustomItems handler which contains all custom items.
    @NotNull BanDatabase
    Get the BanItem database, containing blacklist, whitelist, custom items and meta items.
    static @NotNull BanItemAPI
    Get a static instance of the api.
    @Nullable BannedItem
    getMetaItem(@NotNull String metaItemName)
    Get the configured meta item by its name.
    @Nullable String
    getMetaItemName(@NotNull BannedItem item)
    Try to get the meta item name of the given item.
    @Nullable String
    getMetaItemName(@NotNull org.bukkit.inventory.ItemStack item)
    Try to get the meta item name of the given item.
    @NotNull Whitelist
    Whitelist handler which contains all whitelisted items.
    boolean
    isBanned(@NotNull org.bukkit.World world, @NotNull BannedItem item, @NotNull BanAction action, @Nullable BanData... data)
    This method is used to check if the item is banned, in both blacklist and whitelist, not involving a player.
    boolean
    isBanned(@NotNull org.bukkit.World world, @NotNull org.bukkit.Material material, @NotNull BanAction action, @Nullable BanData... data)
    This method is used to check if the item is banned, in both blacklist and whitelist, not involving a player.
    boolean
    isBanned(@NotNull org.bukkit.World world, @NotNull org.bukkit.inventory.ItemStack item, @NotNull BanAction action, @Nullable BanData... data)
    This method is used to check if the item is banned, in both blacklist and whitelist, not involving a player.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @NotNull BannedItem item, boolean sendMessage, @NotNull BanAction action, @Nullable BanData... data)
    Check if the BannedItem object is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @NotNull BannedItem item, @NotNull BanAction action, @Nullable BanData... data)
    Check if the BannedItem object is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.Material m, boolean sendMessage, @NotNull BanAction action, @Nullable BanData... data)
    Check if the material is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.Material m, @NotNull BanAction action, @Nullable BanData... data)
    Check if the material is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @Nullable org.bukkit.Location loc, @NotNull BannedItem item, boolean sendMessage, @NotNull BanAction action, @Nullable BanData... data)
    Check if the BannedItem object is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @Nullable org.bukkit.Location loc, @NotNull BannedItem item, @NotNull BanAction action, @Nullable BanData... data)
    Check if the BannedItem object is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @Nullable org.bukkit.Location loc, @NotNull org.bukkit.Material m, boolean sendMessage, @NotNull BanAction action, @Nullable BanData... data)
    Check if the material is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @Nullable org.bukkit.Location loc, @NotNull org.bukkit.Material m, @NotNull BanAction action, @Nullable BanData... data)
    Check if the material is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @Nullable org.bukkit.Location loc, @NotNull org.bukkit.inventory.ItemStack item, boolean sendMessage, @NotNull BanAction action, @Nullable BanData... data)
    Check if the ItemStack is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @Nullable org.bukkit.Location loc, @NotNull org.bukkit.inventory.ItemStack item, @NotNull BanAction action, @Nullable BanData... data)
    Check if the ItemStack is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.inventory.ItemStack item, boolean sendMessage, @NotNull BanAction action, @Nullable BanData... data)
    Check if the ItemStack is banned, in both blacklist and whitelist.
    boolean
    isBanned(@NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.inventory.ItemStack item, @NotNull BanAction action, @Nullable BanData... data)
    Check if the ItemStack is banned, in both blacklist and whitelist.
    boolean
    isBlacklisted(@NotNull org.bukkit.World world, @NotNull BannedItem item, @NotNull BanAction action, @Nullable BanData... data)
    Check if the item is blacklisted, not involving a player.
    boolean
    isBlacklisted(@NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.Location location, @NotNull BannedItem item, boolean sendMessage, @NotNull BanAction action, @Nullable BanData... data)
    Check if the item is blacklisted.
    boolean
    isWhitelisted(@NotNull org.bukkit.World world, @NotNull BannedItem item, @NotNull BanAction action, @Nullable BanData... data)
    Check if the item is whitelisted, not involving a player.
    boolean
    isWhitelisted(@NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.Location location, @NotNull BannedItem item, boolean sendMessage, @NotNull BanAction action, @Nullable BanData... data)
    Check if the item is whitelisted (allowed), sending a message or not to the player.
    void
    load(@NotNull org.bukkit.command.CommandSender sender, @Nullable File configFile)
    (re)Loading the plugin with this configuration file
    boolean
    removeFromBlacklist(@NotNull BannedItem item, @Nullable org.bukkit.World... worlds)
    Remove the banned item from blacklisted worlds and save the config file used.
    boolean
    removeFromBlacklist(@NotNull Collection<? extends BannedItem> items, @Nullable org.bukkit.World... worlds)
    Remove the banned items from blacklisted worlds and save the config file used.
    boolean
    removeFromWhitelist(@NotNull WhitelistedWorld whitelistedWorld, @NotNull BannedItem item)
    Remove the item from the whitelist and save in config.yml (comments in file may be removed).
    void
    removeMetaItem(@NotNull String name)
    Remove the meta ItemStack named name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getInstance

      @NotNull public static @NotNull BanItemAPI getInstance()
      Get a static instance of the api. You should use BanItem.getApi() instead.
      Returns:
      a static instance of the api
    • getDatabase

      @NotNull public @NotNull BanDatabase getDatabase()
      Get the BanItem database, containing blacklist, whitelist, custom items and meta items.
      Returns:
      the BanDatabase object
    • load

      public void load(@NotNull @NotNull org.bukkit.command.CommandSender sender, @Nullable @Nullable File configFile)
      (re)Loading the plugin with this configuration file
      Parameters:
      sender - command sender (send the message debug to)
      configFile - the file configuration to load. If null, using (and reloading) the default config
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull org.bukkit.Material m, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the material is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      m - the Material used
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable org.bukkit.Location loc, @NotNull @NotNull org.bukkit.Material m, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the material is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      loc - the effective Location of the action
      m - the Material used
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull org.bukkit.Material m, boolean sendMessage, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the material is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      m - the Material used
      sendMessage - if the banned message should be sent to the player
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable org.bukkit.Location loc, @NotNull @NotNull org.bukkit.Material m, boolean sendMessage, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the material is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      loc - the effective Location of the action
      m - the Material used
      sendMessage - if the banned message should be sent to the player
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the ItemStack is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      item - the ItemStack used
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable org.bukkit.Location loc, @NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the ItemStack is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      loc - the effective Location of the action
      item - the ItemStack used
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull org.bukkit.inventory.ItemStack item, boolean sendMessage, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the ItemStack is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      item - the ItemStack used
      sendMessage - if the banned message should be sent to the player
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable org.bukkit.Location loc, @NotNull @NotNull org.bukkit.inventory.ItemStack item, boolean sendMessage, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the ItemStack is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      loc - the effective Location of the action
      item - the ItemStack used
      sendMessage - if the banned message should be sent to the player
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull BannedItem item, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the BannedItem object is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      item - the BannedItem object
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable org.bukkit.Location loc, @NotNull @NotNull BannedItem item, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the BannedItem object is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      loc - the effective Location of the action
      item - the BannedItem object
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull BannedItem item, boolean sendMessage, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the BannedItem object is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      item - the BannedItem object
      sendMessage - if the banned message should be sent to the player
      action - the BanAction to check
      data - optional action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable org.bukkit.Location loc, @NotNull @NotNull BannedItem item, boolean sendMessage, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the BannedItem object is banned, in both blacklist and whitelist. This also consider the player bypass permissions.
      Parameters:
      player - the Player involved into this action
      loc - the effective Location of the action
      item - the BannedItem object
      sendMessage - if the banned message should be sent to the player
      action - the BanAction to check
      data - the optional ban action data, leave it blank if not needed for the action
      Returns:
      true if this item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.World world, @NotNull @NotNull org.bukkit.Material material, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      This method is used to check if the item is banned, in both blacklist and whitelist, not involving a player. This method is mainly used to check dispensers dispense and hoppers transfer.
      Parameters:
      world - bukkit world (World)
      material - the involved material
      action - the ban action to check
      data - the optional ban action data
      Returns:
      true if the item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.World world, @NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      This method is used to check if the item is banned, in both blacklist and whitelist, not involving a player. This method is mainly used to check dispensers dispense and hoppers transfer.
      Parameters:
      world - bukkit world (World)
      item - the involved ItemStack
      action - the ban action to check
      data - the optional ban action data
      Returns:
      true if the item is banned, otherwise false
    • isBanned

      public boolean isBanned(@NotNull @NotNull org.bukkit.World world, @NotNull @NotNull BannedItem item, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      This method is used to check if the item is banned, in both blacklist and whitelist, not involving a player. This method is mainly used to check dispensers dispense and hoppers transfer.
      Parameters:
      world - bukkit world (World)
      item - the involved item
      action - the ban action to check
      data - the optional ban action data
      Returns:
      true if the item is banned, otherwise false
    • isBlacklisted

      public boolean isBlacklisted(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull BannedItem item, boolean sendMessage, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the item is blacklisted. If sendMessage is on true, the ban message will be sent to the player.
      Parameters:
      player - the Player involved into this action
      location - the effective location where the action occurs
      item - the BannedItem involved into this action
      sendMessage - if the item is banned, send the ban message configured
      action - the BanAction action to check
      data - additional ban data
      Returns:
      true if this item is banned for those characteristics, otherwise false
    • isBlacklisted

      public boolean isBlacklisted(@NotNull @NotNull org.bukkit.World world, @NotNull @NotNull BannedItem item, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the item is blacklisted, not involving a player.
      Parameters:
      world - bukkit world (World)
      item - the involved item
      action - the ban action to check
      data - the optional ban action data
      Returns:
      true if the item is banned, otherwise false
    • isWhitelisted

      public boolean isWhitelisted(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull BannedItem item, boolean sendMessage, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the item is whitelisted (allowed), sending a message or not to the player.
      Parameters:
      player - the Player involved into this action
      location - the effective location where the action occurs
      item - the BannedItem involved into this action
      sendMessage - if the item is banned, send the ban message configured
      action - the BanAction action to check
      data - the optional ban action data
      Returns:
      true if this item is allowed, otherwise false
    • isWhitelisted

      public boolean isWhitelisted(@NotNull @NotNull org.bukkit.World world, @NotNull @NotNull BannedItem item, @NotNull @NotNull BanAction action, @Nullable @Nullable BanData... data)
      Check if the item is whitelisted, not involving a player.
      Parameters:
      world - bukkit world (World)
      item - the involved item
      action - the ban action to check
      data - the optional ban action data
      Returns:
      true if the item is allowed, otherwise false
    • getBlacklist

      @NotNull public @NotNull Blacklist getBlacklist()
      Blacklist handler which contains all blacklisted items.
      Returns:
      blacklist handler which contains all blacklisted items.
    • addToBlacklist

      public boolean addToBlacklist(@NotNull @NotNull BannedItem item, @NotNull @NotNull Map<BanAction,BanActionData> actions, @Nullable @Nullable org.bukkit.World... worlds)
      Add a new banned item to blacklist and save the config file used.
      Parameters:
      item - the item to ban
      actions - a map containing actions and their respective data
      worlds - worlds where the ban apply. If null, including all worlds
      Returns:
      true if the item is successfully added, otherwise false
    • addToBlacklist

      public boolean addToBlacklist(@NotNull @NotNull Collection<? extends BannedItem> items, @NotNull @NotNull Map<BanAction,BanActionData> actions, @Nullable @Nullable org.bukkit.World... worlds)
      Add the banned items to the blacklist and save the config file used.
      Parameters:
      items - the items to ban
      actions - a map containing actions and their respective data
      worlds - worlds where the ban apply. If null, including all worlds
      Returns:
      true if the item is successfully added, otherwise false
    • removeFromBlacklist

      public boolean removeFromBlacklist(@NotNull @NotNull BannedItem item, @Nullable @Nullable org.bukkit.World... worlds)
      Remove the banned item from blacklisted worlds and save the config file used.
      Parameters:
      item - the banned item to remove
      worlds - worlds where the banned item can be present, all worlds if null
      Returns:
      true if the item is successfully removed, otherwise false
    • removeFromBlacklist

      public boolean removeFromBlacklist(@NotNull @NotNull Collection<? extends BannedItem> items, @Nullable @Nullable org.bukkit.World... worlds)
      Remove the banned items from blacklisted worlds and save the config file used.
      Parameters:
      items - The banned items to remove
      worlds - Worlds where the banned item can be present, all worlds if null
      Returns:
      True if the item is successfully removed, otherwise false
    • getWhitelist

      @NotNull public @NotNull Whitelist getWhitelist()
      Whitelist handler which contains all whitelisted items.
      Returns:
      whitelist handler which contains all whitelisted items.
    • addToWhitelist

      public boolean addToWhitelist(@NotNull @NotNull WhitelistedWorld whitelistedWorld, @NotNull @NotNull BannedItem item, @NotNull @NotNull Map<BanAction,BanActionData> actions)
      Add an item on the whitelist of a world and save in the used config.
      Parameters:
      whitelistedWorld - the whitelisted world object, recoverable from Whitelist
      item - the item to add
      actions - map of ban actions and their respective data
      Returns:
      true if successfully added, otherwise false
    • removeFromWhitelist

      public boolean removeFromWhitelist(@NotNull @NotNull WhitelistedWorld whitelistedWorld, @NotNull @NotNull BannedItem item)
      Remove the item from the whitelist and save in config.yml (comments in file may be removed).
      Parameters:
      whitelistedWorld - the whitelisted world
      item - the item
      Returns:
      true if successfully removed, otherwise false
    • getCustomItems

      @NotNull public @NotNull CustomItems getCustomItems()
      CustomItems handler which contains all custom items.
      Returns:
      customItems handler which contains all custom items.
    • getCustomItem

      @Nullable public @Nullable BannedItem getCustomItem(@NotNull @NotNull String customItemName)
      Get the configured custom item by its name.
      Parameters:
      customItemName - the name of the custom item
      Returns:
      a BannedItem object of the custom item if exists, otherwise null
    • getMetaItem

      @Nullable public @Nullable BannedItem getMetaItem(@NotNull @NotNull String metaItemName)
      Get the configured meta item by its name.
      Parameters:
      metaItemName - the name of the meta item
      Returns:
      a BannedItem object of the meta item if exists, otherwise null
    • getMetaItemName

      @Nullable public @Nullable String getMetaItemName(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Try to get the meta item name of the given item.
      Parameters:
      item - the ItemStack
      Returns:
      the name of saved the meta item if exists, otherwise null
    • getMetaItemName

      @Nullable public @Nullable String getMetaItemName(@NotNull @NotNull BannedItem item)
      Try to get the meta item name of the given item.
      Parameters:
      item - the item
      Returns:
      the name of saved the meta item if exists, otherwise null
    • addMetaItem

      public void addMetaItem(@NotNull @NotNull String name, @NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Add an ItemStack as a meta item and save it in metaitems.yml.

      Will replace existing value

      Parameters:
      name - the name of the custom ItemStack
      item - the custom ItemStack
    • removeMetaItem

      public void removeMetaItem(@NotNull @NotNull String name)
      Remove the meta ItemStack named name.
      Parameters:
      name - the name of the custom ItemStack