Factions API, canPlayerBuildAt

Discussion in 'Plugin Development' started by NathanWolf, Mar 5, 2014.

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

    NathanWolf

    Hello! I'm trying to integrate my plugin with Factions so it can respect build permissions within designated areas.

    I have searched and searched (and searched ) for this, but have come up with nothing. Lots of people seem to ask, and get answers that don't apear to work- there are no official docs that I can find, no API- and the developers' response amounts to "Just read the source, please".

    That said, I have read the source and see no discernible API :) The most common solution I see on these forums implies I should be using a static method of the "Board" class that, near as I can tell, does not exist.

    So what I have done is to hook into what appears to be a public static helper method of Factions' own Listener class. This method does *exactly* what I want- but I feel like this is a very hacky approach, since there's nothing ensuring that method won't change its signature, move to another class, get renamed, etc.

    Is there a better way? Would it be that hard to provide a couple of methods (like canPlayerBuildAt, isPVPEnabled, etc) on the base plugin class that accept normal Bukkit Location objects for simplicity, I wonder? (Not meant to be jab, there may really be a reason that it's not there?)

    If there is not a better way, then hopefully the below code will help somebody out. It uses reflection because it's important to me to be able to soft-depend on Factions (again, this is where a separate API is a really good thing!)

    Code:java
    1. // ... in my onEnable, I look for Factions
    2.  
    3. try {
    4. Class<?> psClass = Class.forName("com.massivecraft.mcore.ps.PS");
    5. factionsManager = Class.forName("com.massivecraft.factions.listeners.FactionsListenerMain");
    6. factionsCanBuildMethod = factionsManager.getMethod("canPlayerBuildAt", Player.class, psClass, Boolean.TYPE);
    7. psFactoryMethod = psClass.getMethod("valueOf", Location.class);
    8. if (factionsManager != null && factionsCanBuildMethod != null && psFactoryMethod != null) {
    9. getLogger().info("Factions found, build permissions will be respected.");
    10. } else {
    11. factionsManager = null;
    12. factionsCanBuildMethod = null;
    13. psFactoryMethod = null;
    14. }
    15. } catch (Throwable ex) {
    16. }
    17.  
    18. if (factionsManager == null) {
    19. getLogger().info("Factions not found, will not integrate.");
    20. }
    21.  
    22. // ...
    23. // Then if found, I will use it in my build check method.
    24. // ...
    25.  
    26. public boolean hasBuildPermission(Player player, Block block)
    27. {
    28. // Check the region manager, or Factions
    29. // TODO: We need to be able to do permission checks while a player is offline. This is currently exploitable. (!)
    30. boolean allowed = true;
    31.  
    32. // ... [SNIP'd out irrelevant WG check]
    33.  
    34. if (factionsEnabled && player != null && block != null && factionsManager != null && factionsCanBuildMethod != null && psFactoryMethod != null) {
    35. try {
    36. Object loc = psFactoryMethod.invoke(null, block.getLocation());
    37. allowed = allowed && loc != null && (Boolean)factionsCanBuildMethod.invoke(null, player, loc, false);
    38. } catch (Throwable ex) {
    39. ex.printStackTrace();
    40. allowed = false;
    41. }
    42. }
    43.  
    44. return allowed;
    45. }
    46.  


    Thanks in advance!

    Derp- not two minutes after posting this question, I found

    The Factions Developer Documentation, via their own issue tracker. I could not find this linked anywhere on the wiki or devbukkit page.

    That said, it's still a little confusing to me- what is a universe, and how do I know which one to ask for? Why is there not just a simple build check method? :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    SuperOmegaCow

    NathanWolf
    Ya maybe you should read before you post.
     
  3. Offline

    NathanWolf


    Wow, thanks. :\

    You'll notice I DID read and do a lot of googling and forum searching- should I really have to follow links on a 2-year old closed ticket in their bug tracker to find their developer API?

    My question still stands, their documentation doesn't tell me what I want to do. I need some mysterious Universe id, and they make no mention of how to actually do a build check.

    Anybody care to try and be helpful? This is a very common unanswered question on the forums.
     
Thread Status:
Not open for further replies.

Share This Page