[Lib] ProtectionsLib - Check block protections

Discussion in 'Resources' started by Minnymin3, Apr 13, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Minnymin3

    What is it
    ProtectionsLib is a library that allows you to check for block protections for multiple plugins. It works by registering protections plugins when it starts up and then when you check if a player can build it cycles through all registered protections and sees if any of them object to the player building there.

    BukkitDev page: http://dev.bukkit.org/bukkit-plugins/protectionslib/
    Github page: https://github.com/minnymin3/ProtectionsLib

    How to use
    Using ProtectionsLib is designed to be as easy as possible. You start by fetching the plugin instance.
    Code:java
    1.  
    2. public class ExamplePlugin extends JavaPlugin {
    3.  
    4. ProtectionsLib lib = null;
    5.  
    6. @Override
    7. public void onEnable() {
    8. Plugin plugin = Bukkit.getPluginManager().getPlugin("ProtectionsLib");
    9. if (plugin != null && plugin instanceof ProtectionsLib) {
    10. lib = (ProtectionsLib) plugin;
    11. }
    12. }
    13. }
    14.  

    This gets the plugin and sets it to the lib variable. This variable will be accessable in your main class.

    Now lets say you have a command that sets the players target block to air.
    Code:java
    1.  
    2. public class ExamplePlugin extends JavaPlugin {
    3.  
    4. ProtectionsLib lib = null;
    5.  
    6. @Override
    7. public void onEnable() {
    8. Plugin plugin = Bukkit.getPluginManager().getPlugin("ProtectionsLib");
    9. if (plugin != null && plugin instanceof ProtectionsLib) {
    10. lib = (ProtectionsLib) plugin;
    11. }
    12. }
    13.  
    14. @Override
    15. public void onCommand(CommandSender sender, Command command, String label, String[] args) {
    16. if (sender instanceof Player) {
    17. Player player = (Player) sender;
    18. Block block = player.getTargetBlock(null, 100);
    19. if (lib.canBuild(player, block)) {
    20. block.setType(Material.AIR);
    21. }
    22. }
    23. }
    24. }
    25.  

    This command now checks if the sender is a player then it gets the players target block. With this target block it checks if the protections plugins supported by ProtectionsLib allow the player to build with the canBuild method. canBuild() returns true if the player can build at that block and false if any plugin objects.

    Currently, there are three checks you can do with ProtectionsLib.
    Code:java
    1.  
    2. canBuild(Player player, Block block);
    3. canBuild(Player player, Location loc);
    4. canPvp(Player player, Player target);
    5.  
     
  2. Offline

    Blah1

    What's the difference between this and checking if BlockBreakEvent is cancelled?

    Also, I was hoping this was like a mini WorldGaurd alternative from the title :p
     
  3. Offline

    Minnymin3

    Block break events cause other things to happen such as nocheat stopping the block break/place and many other checks that other plugins besides protection plugins do.
     
  4. Offline

    TigerHix

    Interesting! Though it will be even better if it's a single class lib :p
     
Thread Status:
Not open for further replies.

Share This Page