Help with 'Dynamic' Permissions

Discussion in 'Plugin Development' started by wadu436, Aug 1, 2013.

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

    wadu436

    Hello people.
    Does anyone knows how to achieve something like with th kits from essentials, like: essentials.kit.[kitname]
    how would i do this?
    xTrollxDudex
    Cirno
    Assist
     
  2. Offline

    Samthelord1

    wadu436 I don't understand what you mean? Do you mean making kits? If so, yeh that's easy.
     
  3. Offline

    Cirno

    if(Player.hasPermission("somepermissionnode.subpermissionnode.[nameofthing]")
     
  4. Offline

    wadu436

    But how do i getr the names of the classes they have. i dont know how the classes are gonna be called and i think the problem is getting all the class names from the confgi file.
    Heres the basic config ile:
    Code:
    groups:
      examplegroup: 10
     
  5. then use
    if(player.hasPermission("node.subnode."+dynamicString))
    ?
     
  6. Offline

    xTrollxDudex

    wadu436
    You need to see if the player has a permission "essentials.kit" + kitname in your code.
     
  7. Offline

    Cirno

    yourConfig.getString("groups.examplegroup")
     
  8. Offline

    wadu436

    how do i get the kitname out of my config (i tried with lists, arrays, mostly everything possible, but it didnt worked)

    i config can also be something like:
    groups:
    agroup: 5
    anothergroup: 50

    i want to know how to get the names of those other groups

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  9. so you want all in the config defined permissions which start with essentials.kit ?

    Edit: Then i would use something like this:

    Code:java
    1. ConfigurationSection section = getConfig().getConfigurationSection("essentials.kit");
    2. Set<String> keys = section.getKeys(false);
     
  10. Offline

    xTrollxDudex

  11. Offline

    wadu436

    It doesnt work can you check my code? xTrollxDudex
    Code:
    Code:java
    1. package be.wadu.morehearts;
    2.  
    3. import java.util.Set;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.configuration.ConfigurationSection;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerLoginEvent;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class MoreHearts extends JavaPlugin implements Listener {
    13. JavaPlugin plugin = this;
    14. Set<String> groups;
    15. String[] grouparray;
    16. double[] extraHealth;
    17. String[] perms;
    18. double maxHealth;
    19. ConfigurationSection section;
    20.  
    21. @Override
    22. public void onEnable() {
    23. saveDefaultConfig();
    24. section = getConfig().getConfigurationSection("groups");
    25. groups = section.getKeys(false);
    26. grouparray = new String[groups.size()];
    27. //groups = (String[]) getConfig().getList("groups").toArray(new String[getConfig().getList("groups").size()]); //Getting Dynamic Groups
    28. extraHealth = new double[groups.size()]; //Initializing Dynamic Health
    29. perms = new String[groups.size()]; //Initializing Permissions
    30. for (int i = 1; i <= groups.size(); i++) {
    31. extraHealth[i - 1] = getConfig().getDouble("groups." + grouparray[i - 1]);
    32. extraHealth[i - 1] = extraHealth[i - 1] * 2; //Getting Dynamic Health
    33. perms[i - 1] = "morehearts" + grouparray[i - 1]; //Getting Dynamic Permissions
    34. }
    35. }
    36.  
    37. @Override
    38. public void onDisable() {
    39. final Player[] p = Bukkit.getOnlinePlayers();
    40. for (int i = 1; i <= p.length; i++) {
    41. p[i - 1].setMaxHealth(20.0);
    42. }
    43. }
    44.  
    45. public void LoginListener(final PlayerLoginEvent event) {
    46. final Player p = event.getPlayer(); //Getting Player
    47. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    48. @Override
    49. public void run() {
    50. p.sendMessage("Logged in!");
    51. for (int i = 1; i <= perms.length; i++) {
    52. if (p.hasPermission(perms[i - 1])) {
    53. p.setMaxHealth(extraHealth[i - 1] + 20.0); //Setting Health
    54. }
    55. }
    56. }
    57. }, 20);
    58. }
    59. }
     
  12. grouparray[i - 1]

    you created the new array with the right size, but newer put in the values/permissionparts, so you would get a NullPointerException i think.
     
Thread Status:
Not open for further replies.

Share This Page