Solved [Help me] Multiple home

Discussion in 'Plugin Development' started by Cheesepro, Nov 5, 2014.

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

    Cheesepro

    So I was adding home feature to my server plugin, but I have some difficulties in setting up permission for multiple homes. So here is what I have right now:
    Code:java
    1. else if(label.equalsIgnoreCase("sethome")){
    2. if (args.length == 0) {
    3. msg.w(p, "5", "Please specify a name!");
    4. return true;
    5. }
    6. settings.getData().set("homes." + id + "." + args[0] + ".world", p.getLocation().getWorld().getName());
    7. settings.getData().set("homes." + id + "." + args[0] + ".pitch", p.getLocation().getPitch());
    8. settings.getData().set("homes." + id + "." + args[0] + ".yaw", p.getLocation().getYaw());
    9. settings.getData().set("homes." + id + "." + args[0] + ".x", p.getLocation().getX());
    10. settings.getData().set("homes." + id + "." + args[0] + ".y", p.getLocation().getY());
    11. settings.getData().set("homes." + id + "." + args[0] + ".z", p.getLocation().getZ());
    12. settings.saveData();
    13. msg.m(p, "a", "Set home " + args[0] + "!");
    14. }


    I was wonder if I can add a if statement to check if the player has permission to access 3 homes from this permission (CheeseEss.home.3). I know how to check if the player has a permission or not by using the hasPermission() method but I dont know how to take the number out... If you know how to do that please help me :D Thanks
     
  2. Cheesepro You'd still just do hasPermission("CheeseEss.home.3")
     
  3. Offline

    Cheesepro

    AdamQpzm
    Thanks for helping, but what if i change the permission to (CheeseEss.home.4) and the code will be broken, and if I add a IF statement for the 4 then it will be hard coded... Still looking for other answers :D
     
  4. Cheesepro What exactly are you looking to do?
     
  5. Offline

    Cheesepro

    AdamQpzm
    Ok so what I wanted to do is, the server owners can set the home limit for those who has the permission (CheeseEss.home.howmanyhomes)

    *I know if I want to get Int from String, I could use:
    Code:java
    1. String numberOnly= str.replaceAll("[^0-9]", "");
     
  6. Cheesepro likes this.
  7. Offline

    Barinade

    p.hasPermission("CheeseEss.home." + (homeCount + 1))
     
  8. Offline

    Cheesepro

    Barinade
    Don't I have to declare what is the value of homeCount? If so, then the homeCount will not be what I configed in the permission plugin, but the value that I declared before.
     
  9. Offline

    Barinade

    Or you can just read how many homes the config already has stored?
     
  10. Offline

    Cheesepro

    Thank you guys so much for your help. specially Assist. So here is the code, if anyone is interested it :D
    Code:java
    1. if(label.equalsIgnoreCase("sethome")){
    2. if (args.length == 0) {
    3. msg.w(p, "5", "Please specify a name!");
    4. return true;
    5. }
    6. for (PermissionAttachmentInfo perm : p.getEffectivePermissions()) {
    7. if (perm.getPermission().startsWith("cheeseess.homemax.")) {
    8. String numberOnly= perm.getPermission().replaceAll("[^0-9]", "");
    9. int homeCount = 0;
    10. try {
    11. homeCount = Integer.parseInt(numberOnly);
    12. List homenum = new ArrayList();
    13. for(String homes : settings.getData().getConfigurationSection("homes." + id).getKeys(false)){
    14. homenum.add(homes);
    15. }
    16. int has = homenum.size()+1;
    17. if(has<=homeCount){
    18. settings.getData().set("homes." + id + "." + args[0] + ".world", p.getLocation().getWorld().getName());
    19. settings.getData().set("homes." + id + "." + args[0] + ".pitch", p.getLocation().getPitch());
    20. settings.getData().set("homes." + id + "." + args[0] + ".yaw", p.getLocation().getYaw());
    21. settings.getData().set("homes." + id + "." + args[0] + ".x", p.getLocation().getX());
    22. settings.getData().set("homes." + id + "." + args[0] + ".y", p.getLocation().getY());
    23. settings.getData().set("homes." + id + "." + args[0] + ".z", p.getLocation().getZ());
    24. settings.saveData();
    25. msg.m(p, "a", "Set home " + args[0] + "!");
    26. return true;
    27. }else{
    28. msg.w(p, "4", "Reached maximum home limit");
    29. return true;
    30. }
    31. } catch (NumberFormatException ex) {
    32. ConsoleSender.msgConsole("CheeseEss.home.int != CheeseEss.home.string");
    33. return true;
    34. }
    35. }
    36. }
    37.  
    38. }
     
  11. Offline

    Barinade

    Seems like a lot more work than what I suggested, lol
     
    Cheesepro likes this.
Thread Status:
Not open for further replies.

Share This Page