Hooking up Group Manager

Discussion in 'Plugin Development' started by alex123099, Jun 16, 2012.

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

    alex123099

    So I've been trying to make a plugin where you can purchase items by using vote points.
    Now it all works, but a little problem, which I am unable to find a solution for.
    I can't find a way to add permissions to the buying user.
    I did add the plugin to libraries and all, cuz I am able to check his permissions.

    The plugin I'm using is EssentialsGroupManager.

    If someone could give me an example code of how to add permissions to a certain user by using bukkits Player class, it would be much appreciated.
     
  2. Offline

    ZeusAllMighty11

    Easiest way to go about this, would be to not implement a non-default plugins system. By default, CraftBukkit API and Bukkit API has...bPermissions built in? (not sure if it's bPermissions)

    Something similar though, if not exact.


    Easiest way to do it would be to take a command or part of your method, and add:
    PHP:
    && player.hasPermission("Your.PermissionNode")
     
  3. If you are simply checking if they have a permission node then use @ZeuesAllMighty11 's method or if you want to do more advanced things like changing, adding, removing groups etc then I recommend Vault

    I think you mean SuperPerms
     
    ZeusAllMighty11 likes this.
  4. Offline

    alex123099

    Checking if someone has a permission is not a problem, the problem is adding the permission.
    When I try to add it to someone it doesn't give any errors or exceptions, but when I check if the player has the permission after adding it, it returns false.
     
  5. Are you using the GroupManager or Vault API?
     
  6. Offline

    alex123099

    GroupManager
     
  7. Can you post the code you are using to Hook it and add a permission node? Please not I have never used groupmanager or its API so I may not be able to help you, but I will try my best.
     
  8. Offline

    alex123099

    Code:
    package me.alex.VotePoints;
     
    import java.util.ArrayList;
     
    import org.anjocaido.groupmanager.GroupManager;
    import org.anjocaido.groupmanager.data.DataUnit;
    import org.anjocaido.groupmanager.data.User;
    import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
    import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
    import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.Plugin;
     
    import com.massivecraft.factions.*;
     
    public class Shop extends DataUnit{
    private CommandSender sender;
    private int points;
    private AnjoPermissionsHandler handler;
    private OverloadedWorldHolder dataHolder = null;
    private WorldsHolder worldsHolder;
    private User auxUser;
    private Data shopItems;
    private ArrayList<String>items;
    private VotePoints vp;
    private Plugin plugin;
    private FPlayer f;
    private Faction fc;
    private String[] args;
     
    public Shop(CommandSender sender, int points,String[] args, AnjoPermissionsHandler handler, VotePoints vp, Plugin plugin){
    super(sender.getName());
    this.sender = sender;
    this.points = points;
    this.handler = handler;
    this.vp = vp;
    this.plugin = plugin;
    this.args = args;
    shopItems = new Data("VotePoints/shopItems.dat");
    items = new ArrayList<String>();
    items = shopItems.load();
    }
     
    public void welcomeMsg(){
    items = shopItems.load();
    sender.sendMessage("Welcome to "+ChatColor.GOLD+"[Ass]FreeBuild " + ChatColor.GREEN + "voting shop!");
    sender.sendMessage("Here you will be able to buy the stuff you've always wanted.");
    sender.sendMessage("===");
    if(items.size()>0){
    for(int i=0;i<items.size();i++)
    sender.sendMessage("["+i+"]"+ChatColor.LIGHT_PURPLE + items.get(i).split(":")[0] + ChatColor.WHITE + " for " + ChatColor.GREEN + items.get(i).split(":")[1] + " points. " + ChatColor.AQUA + items.get(i).split(":")[2]);
    sender.sendMessage("To buy an item, use " + ChatColor.RED + "/vp buy [item-id].");
    sender.sendMessage("===");
    sender.sendMessage(ChatColor.RED+"*The item-id is the number of the item.");
    } else
    sender.sendMessage("The shop is currently "+ChatColor.RED+"out of stock.");
    }
     
    public void addItem(String item, String price,String desc){
    items.add(item+":"+price+":"+desc);
    shopItems.save(items);
    }
     
    public void removeItem(String item){
     
    if(items.size()>0){
    for(int i=0;i<items.size();i++)
    if(items.get(i).contains(item))
    items.remove(i);
    } else
    sender.sendMessage("The shop is empty.");
    shopItems.save(items);
    }
    public void removeItem(int itemId){
    if(items.size()>0)
    items.remove(itemId);
    else
    sender.sendMessage("The shop is empty.");
    shopItems.save(items);
    }
     
    public void buy(int itemId){
    items = shopItems.load();
    if(items.size()>0){
    if(points >= Integer.parseInt(items.get(itemId).split(":")[1]))
    {
    String itemName = items.get(itemId).split(":")[0];
    if(itemName.substring(0, 2).equalsIgnoreCase("md")){
    worldsHolder = new WorldsHolder((GroupManager) plugin);
    dataHolder = worldsHolder.getWorldData((Player)sender);
    auxUser = dataHolder.getUser(sender.getName());
    if(itemName.equalsIgnoreCase("mdcreeper"))
    try{
    vp.getServer().getPluginManager().addPermission(new Permission("mobdisguise.mob.creeper"));
    }
    catch(Exception e){ sender.sendMessage("You already have that."); }
    else if(itemName.equalsIgnoreCase("mdskeleton"))
    auxUser.addPermission("mobdisguise.mob.skeleton");
    else if(itemName.equalsIgnoreCase("mdspider"))
    auxUser.addPermission("mobdisguise.mob.spider");
    else if(itemName.equalsIgnoreCase("mdgiant"))
    auxUser.addPermission("mobdisguise.mob.giant");
    else if(itemName.equalsIgnoreCase("mdzombie"))
    auxUser.addPermission("mobdisguise.mob.zombie");
    System.err.println(handler.has((Player)sender, "mobdisguise.mob.creeper"));
    /*plugin.getPluginLoader().disablePlugin(plugin);
    plugin.getPluginLoader().enablePlugin(plugin);*/
    }
    else if(itemName.equalsIgnoreCase("factionpower") || itemName.equalsIgnoreCase("fpower") || itemName.equalsIgnoreCase("fp"))
    {
    f = FPlayers.i.get((Player)sender);
    fc = f.getFaction();
    if(fc!=null)
    fc.setPermanentPower(fc.getPowerRounded()+Integer.parseInt(items.get(itemId).split(":")[1]));
    else
    sender.sendMessage("Get a faction first.");
    }
    else if(itemName.equalsIgnoreCase("factionname") && args.length>2)
    {
    f = FPlayers.i.get((Player)sender);
    fc = f.getFaction();
    if(fc!=null)
    fc.setTag(args[2]);
    }
    else{
    sender.sendMessage("The item is unpurchasable or the command is incorrect.");
    return;
    }
    vp.addPoints(-Integer.parseInt(items.get(itemId).split(":")[1]), sender.getName());
    sender.sendMessage("You have successfully bought " + ChatColor.GOLD + itemName);
    } else
    sender.sendMessage("You don't have enough vote points!");
    } else
    sender.sendMessage("Shop is empty.");
    }
     
    public void clearShop(){
    items.clear();
    shopItems.save(items);
    }
    }
    
    only the part that is under if itemName contains md
     
  9. Hmmmm try looking for a savePermissions and/or reloadPermissions (or something like that) function, I tried looking for an API Documentation but couldn't find one.
     
  10. Offline

    alex123099

  11. Offline

    Sleaker

    it's also possible that there's a bug in the permission check code right now for GM. I mentioned it to KHobbits as I've seen a few people reporting that players lose permission on rejoining the server with GM, you might want to check if this is the case for you also. The GM permission addition code should be fine, you can check how I do it in the Vault code if you are unsure about it too.
     
  12. Offline

    alex123099

    No the plugin works fine in the server, the checking if the player has a certain permission with this plugin is fine but adding is the problem.
    With your vault plugin, does it use the GM plugin?
     
  13. Yes Vault works with all Permissions systems!
     
  14. Offline

    alex123099

    So i can add it as a library and use the add permission funcion?
     
  15. Yep!
     
  16. Offline

    LexLaiden

    NOPE!
    You must also Hook the plugin.
     
  17. Offline

    Sleaker

    Wrong!
    Vault can handle adding permissions onto players in pretty much any of the permission systems. It has issues with some plugins that don't provide API. But as I've listed on the Vault page it currently supports: bPerms, bPerms2, DroxPerms, GM, P3, PBukkit, Privileges, SimplyPerms, SuperPerms (bukkit default), and zPermissions.

    alex123099
    In this case using the Vault API for adding permanent permissions does work with GM. It can add either world-specific permissions, or global permissions.
     
  18. Offline

    LexLaiden

    You missunderstand what i am saying. He needs to hook the plugin (Vault or whatever) not just include the library in his build path.
    I don't see that he is hooking.
     
  19. Offline

    Sleaker

    Oooh gotcha! hahaha. My bad!
     
  20. Offline

    alex123099

    import org.anjocaido.groupmanager.GroupManager;
    import org.anjocaido.groupmanager.data.DataUnit;
    import org.anjocaido.groupmanager.data.User;
    import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
    import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
    import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
    and so on..
    doesn't count as hooking up?

    @sleaker
    Do I have to have your plugin in the plugins fodler or just adding it to my plugins library is fine?
    And can you give me an example code of how to add permissions or just the classes I need to import and the class with the function to add the perm.
     
  21. Offline

    Sleaker

    alex123099 - you can hook directly into GM, or you can use Vault's permission service. Not both.
    The way you've started to import GM classes is how you might begin to hook into the GM API, but that's only to set it up so you can reference the classes. There's a lot more than just importing classes.

    if you're interested in the Vault API, again please look at the overview page, or the github page, they both have a simple setup process on how to get started along with a javadoc link on what methods you can do.
     
  22. Offline

    LexLaiden

    He is right. vault is the way to go AND you need to review the docs on how to hook Vault so you understand what your doing.
     
  23. Offline

    alex123099

    Do I have to have your plugin in the plugins fodler or just adding it to my plugins library is fine?
    And can you give me an example code of how to add permissions or just the classes I need to import and the class with the function to add the perm.
     
  24. Offline

    ZeusAllMighty11

    If it's in your plugin library, you still need the plugin installed on the server
     
Thread Status:
Not open for further replies.

Share This Page