Help with a couple of things?

Discussion in 'Plugin Development' started by PimpDuck, Sep 11, 2013.

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

    PimpDuck

    Okay, this is going to be kind of a big post because I need help with more than one thing and I have to explain my plugin. It would be great if someone could help.
    Okay,
    so first thing first. My plugin. I'm not really having an issue as much as I could say, I want to extend my plugin onto permission plugins but never hooked two plugins together so I don't even know where to start or how to do this... What my plugin does: My plugin is like a /near for donators that can be specified in the config on how many blocks they can see. See, at first, I made this only for one server and I named it "DCNear" but now, I want to extend it and make it its own plugin named "NearPlus". So yeah, how would I extends on to PEX or other permission plugins and let the admins add in their own ranks in the config and for the permissions, the permission names are something like "nearplus." + whatever the admins put in to the config. Are you catching my drift? :) You can see all the code for NearPlus here: https://github.com/PimpDuck/NearPlus

    So yeah, my question is how would I extend onto PEX or other permissions plugins and so the Admins could add in their own ranks, and the permissions would look something like "nearplus." + what the admins of the other servers put in the config.

    Thanks for reading,

    PimpDuck
     
  2. Offline

    tommycake50

    The problem with just importing a specific permissions plugin is that it will only work with that plugin.
    Rather, Use Vault I believe the Vault BukkitDev has an example implementation you can work from, Just take a bit of time to explore the API so you don't find yourself coming back to us for help.
     
  3. Offline

    PimpDuck

    tommycake50 Economy? I wanted to hook it into PEX or another permission plugin? I'm not trying to make it cost $ per command?
     
  4. Offline

    tommycake50

    Oh im sorry i meant to type Permissions but in my mind Vault = economy so xD im sorry, Vault does have an economy API though, thats what i meant.
     
  5. Offline

    PimpDuck

    Ohh okay. xD I was like "wat". Lol. So what do you mean by "Just use permissions"? Do you mean just use bukkits default permissions?

    tommycake50 ^

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

    jayfella

    Code:java
    1.  
    2. private boolean initializeVault()
    3. {
    4. boolean vaultPresent = (plugin.getServer().getPluginManager().getPlugin("Vault") != null);
    5.  
    6. if (vaultPresent)
    7. {
    8. plugin.getLogger().info("Vault detected and enabled.");
    9. return true;
    10. }
    11. else
    12. {
    13. plugin.getLogger().info("Vault NOT PRESENT.");
    14. plugin.getLogger().warning("Disabling plugin.");
    15.  
    16. plugin.getPluginLoader().disablePlugin(plugin);
    17.  
    18. return false;
    19. }
    20. }
    21.  
    22. private Permission initializePermissions()
    23. {
    24. RegisteredServiceProvider<Permission> rsp = plugin.getServer().getServicesManager().getRegistration(Permission.class);
    25. Permission bPermission = (Permission)rsp.getProvider();
    26.  
    27. if (bPermission != null)
    28. {
    29. plugin.getLogger().log(Level.INFO, "Using Permissions: {0}", bPermission.getName());
    30. }
    31. else
    32. {
    33. plugin.getLogger().warning("No compatible permissions plugin detected [Vault].");
    34. plugin.getLogger().warning("Disabling plugin.");
    35. plugin.getPluginLoader().disablePlugin(plugin);
    36.  
    37. return null;
    38. }
    39.  
    40. return bPermission;
    41. }
    42.  


    useage:
    Code:java
    1.  
    2. boolean vaultPresent = initializeVault();
    3.  
    4. if (vaultPresent)
    5. Permission permissions = initializePermissions();
    6.  
    7. .....
    8.  
     
    PimpDuck and tommycake50 like this.
  7. Offline

    tommycake50

    I don't think i did say that.
    I said use Vault :confused:.
     
  8. Offline

    jayfella

  9. Offline

    PimpDuck

    tommycake50 Ohhhh! Okay, sorry :p So I can hook vault to my plugin and use that to allow other server owners to add their own ranks into my plugin?

    jayfella Thanks :p I'll try this.

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

    tommycake50

    Yes, Jayfella's suggestion was very useful.
     
  11. Offline

    PimpDuck

    tommycake50 jayfella so my Main class would look like
    Code:java
    1. package me.PimpDuck.NearPlus;
    2.  
    3. import java.util.HashMap;
    4. import java.util.logging.Level;
    5. import java.util.logging.Logger;
    6.  
    7. import net.milkbowl.vault.permission.Permission;
    8.  
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.RegisteredServiceProvider;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13.  
    14. public class NearPlus extends JavaPlugin{
    15.  
    16. private CommandClass CommandClass = new CommandClass(this);
    17.  
    18. Logger log = Logger.getLogger("Minecraft");
    19.  
    20.  
    21. public static FileManager configurationFile;
    22. public static HashMap<String, Long> delayedPlayers;
    23. private static int delay;
    24.  
    25. @Override
    26. public void onEnable(){
    27. log.info("[NearPlus] has been enabled!");
    28. log.info("Copyright 2013 PimpDuck All rights reserved.");
    29. saveDefaultConfig();
    30. configurationFile = new FileManager(this, "config.yml");
    31. delayedPlayers = new HashMap<String, Long>();
    32. delay = getConfig().getInt("DCNear.Options.Cooldown");
    33. getCommand("near").setExecutor(this.CommandClass);
    34. }
    35. @Override
    36. public void onDisable(){
    37. log.info("[NearPlus] has been disabled!");
    38. }
    39.  
    40. public static void addDelayedPlayer(Player player) {
    41. delayedPlayers.put(player.getName(), System.currentTimeMillis());
    42. }
    43.  
    44. public static void removeDelayedPlayer(Player player) {
    45. delayedPlayers.remove(player.getName());
    46. }
    47.  
    48. public static boolean playerDelayed(Player player) {
    49. return delayedPlayers.containsKey(player.getName());
    50. }
    51.  
    52. public static Long getPlayerDelay(Player player) {
    53. return (Long)delayedPlayers.get(player.getName());
    54. }
    55.  
    56. public static int getDelay(int multiplier) {
    57. return delay * multiplier;
    58. }
    59.  
    60. public static int getRemainingTime(Player player) {
    61. return (int)(getDelay(1) - (System.currentTimeMillis() - getPlayerDelay(player).longValue()) / 1000L / 60);
    62. }
    63.  
    64. private boolean initializeVault()
    65. {
    66. boolean vaultPresent = (getServer().getPluginManager().getPlugin("Vault") != null);
    67.  
    68. if (vaultPresent)
    69. {
    70. this.getLogger().info("Vault detected and enabled.");
    71. return true;
    72. }
    73. else
    74. {
    75. this.getLogger().info("Vault NOT PRESENT.");
    76. this.getLogger().warning("Disabling plugin.");
    77.  
    78. this.getPluginLoader().disablePlugin(this);
    79.  
    80. return false;
    81. }
    82. }
    83.  
    84. private Permission initializePermissions()
    85. {
    86. RegisteredServiceProvider<Permission> rsp = this.getServer().getServicesManager().getRegistration(Permission.class);
    87. Permission bPermission = (Permission)rsp.getProvider();
    88.  
    89. if (bPermission != null)
    90. {
    91. this.getLogger().log(Level.INFO, "Using Permissions: {0}", bPermission.getName());
    92. }
    93. else
    94. {
    95. this.getLogger().warning("No compatible permissions plugin detected [Vault].");
    96. this.getLogger().warning("Disabling plugin.");
    97. this.getPluginLoader().disablePlugin(this);
    98.  
    99. return null;
    100. }
    101.  
    102. return bPermission;
    103. }
    104.  
    105. }
     
  12. Offline

    Tehmaker

    Wouldn't it just be easier to run a console command?
     
  13. Offline

    PimpDuck

    Tehmaker I don't understand?
     
  14. Offline

    Tehmaker

    Bukkit.dispatchCommand(ConsoleCommandSender, "*Insert command here without the /*"));
     
Thread Status:
Not open for further replies.

Share This Page