Check if player has PvP Perms in Towny

Discussion in 'Plugin Development' started by Colby l, Feb 25, 2014.

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

    Colby l

    I've been looking through Towny for a way to check if a player can, or is in, a PvP area, and their API is terribly hard to sift through, and is very frustrating.

    I was curious if anyone has done this check, or knows where to look for towny, as I've come to a dead end. Below is a method I tried to check.

    Code:
    Code:java
    1. public boolean inPvPAreaTowny(Player p) {
    2.  
    3. String world = p.getWorld().toString();
    4. TownyWorld townyWorld;
    5. Block block = p.getLocation().getBlock();
    6. try {
    7. townyWorld = TownyUniverse.getDataSource().getWorld(block.getWorld().getName());
    8. int x = (int) Math.round(p.getLocation().getX());
    9. int y = (int) Math.round(p.getLocation().getY());
    10. TownBlock townBlock = new TownBlock(x, y, townyWorld);
    11. Town towny = new Town(townBlock.getWorld().toString());
    12.  
    13. if (towny.isPVP()) {
    14. return true;
    15.  
    16. } else {
    17. return false;
    18. }
    19. } catch (NotRegisteredException e) {
    20. TownyMessaging.sendErrorMsg(p, TownySettings.getLangString("msg_err_not_configured"));
    21. // TODO Auto-generated catch block
    22. Main.getInstance().log.severe(ChatColor.RED + "[RiseFly] Towny World " + world + " is not registered!");
    23. }
    24. return false;
    25.  
    26. }


    Second method:
    Code:java
    1. public boolean canPvPTowny(Player p) {
    2.  
    3. TownyPermission towny = new TownyPermission();
    4.  
    5. if (towny.pvp) {
    6.  
    7. return true;
    8. } else {
    9.  
    10. return false;
    11. }
    12. }


    Not sure how the above would get the Player's info, but that's part of the huge issue I've encountered with towny.

    Thanks for the help!
     
  2. Offline

    Alshain01

Thread Status:
Not open for further replies.

Share This Page