Can't get User's Group [HELP!]

Discussion in 'Plugin Development' started by RyanDev, Jul 21, 2014.

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

    RyanDev

    Hi there, i'm currently developing a private plugin for my own small server where by typing "/verse" it displays 3 messages back to the player of their info. Showing their Name + ServerName, The amount of players on the server, And their Group (from PEX)

    Though I can't seem to grasp the error I keep getting on the player.getGroupName(Player) it comes back with hover over error: "The method getGroupName(PermissionUser) is undefined for type Player"

    Can anyone help solve this? Thanks!

    NOTE: Before someone asks I do have PEX api build path as an external jar

    Code:java
    1. package me.ryanre;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.World;
    12.  
    13. import ru.tehkode.permissions.PermissionGroup;
    14. import ru.tehkode.permissions.PermissionUser;
    15. import ru.tehkode.permissions.bukkit.PermissionsEx;
    16.  
    17. public class VerseCM extends JavaPlugin {
    18.  
    19. public final Logger logger = Logger.getLogger("Minecraft");
    20.  
    21. @Override
    22. public void onEnable() {
    23. getLogger().info("plugin Enabled and running smooth!");
    24.  
    25. }
    26.  
    27. @Override
    28. public void onDisable() {
    29.  
    30. }
    31.  
    32. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    33.  
    34. if (cmd.getName().equalsIgnoreCase("verse") && sender instanceof Player){
    35.  
    36. Player player = (Player) sender;
    37.  
    38. PermissionUser Player = PermissionsEx.getUser(player);
    39.  
    40. if(player.hasPermission("versecm.verse"))
    41.  
    42. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GREEN + player.getName() + ChatColor.GRAY + " is currently active on server '" + ChatColor.DARK_AQUA + ChatColor.BOLD + "LOBBY" + ChatColor.GRAY + "'");
    43. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GRAY + "This server currently has " + ChatColor.GREEN + ChatColor.BOLD + Bukkit.getOnlinePlayers().length + ChatColor.GRAY + " players online!");
    44. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GRAY + "This player is rank " + ChatColor.DARK_AQUA + "[" + ChatColor.DARK_AQUA + player.getGroupName(Player) + ChatColor.DARK_AQUA + "]");
    45.  
    46. return true;
    47.  
    48. }else{
    49.  
    50. Player player = (Player) sender; player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.DARK_RED + "Nope. Looks like you don't have permission for this.");
    51.  
    52. return true;
    53.  
    54. }
    55.  
    56. }
    57.  
    58. }
    59.  
    60.  
     
  2. Offline

    hintss

    there is no way to get a player's group without hooking into the permissions plugin (use Vault for this)
     
  3. Offline

    RyanDev


    So would I add Vault as an external jar to the Build Path?
     
  4. Offline

    hintss

    yes, then use the example code from Vault to get the Permission object (making sure you import the vault one and not the bukkit one), then there should be something in that to get the player's group
     
  5. Offline

    RyanDev

    I've added in Vault but now can't seem to find/add the Permission object for it to work.

    Can someone help me solve this?


    Just seems to be an issue on Line 41 with the getPlayerGroups

    Code:java
    1. package me.ryanre;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. import ru.tehkode.permissions.PermissionUser;
    13. import ru.tehkode.permissions.bukkit.PermissionsEx;
    14.  
    15. public abstract class VerseCM extends JavaPlugin {
    16.  
    17. public final Logger logger = Logger.getLogger("Minecraft");
    18.  
    19. @Override
    20. public void onEnable() {
    21. getLogger().info("plugin Enabled and running smooth!");
    22.  
    23. }
    24.  
    25. @Override
    26. public void onDisable() {
    27.  
    28. }
    29.  
    30.  
    31. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    32.  
    33. if (cmd.getName().equalsIgnoreCase("verse") && sender instanceof Player){
    34.  
    35. Player player = (Player) sender;
    36.  
    37. if(player.hasPermission("versecm.verse"))
    38.  
    39. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GREEN + player.getName() + ChatColor.GRAY + " is currently active on server '" + ChatColor.DARK_AQUA + ChatColor.BOLD + "LOBBY" + ChatColor.GRAY + "'");
    40. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GRAY + "This server currently has " + ChatColor.GREEN + ChatColor.BOLD + Bukkit.getOnlinePlayers().length + ChatColor.GRAY + " players online!");
    41. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GRAY + "This player is rank " + ChatColor.DARK_AQUA + "[" + ChatColor.DARK_AQUA + player.getPlayerGroups(OfflinePlayer) + ChatColor.DARK_AQUA + "]");
    42.  
    43. return true;
    44.  
    45. }else{
    46.  
    47. Player player = (Player) sender; player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.DARK_RED + "Nope. Looks like you don't have permission for this.");
    48.  
    49. return true;
    50.  
    51. }
    52.  
    53. }
    54.  
    55. }
    56.  
     
  6. Offline

    hintss

    Do the stuff it says here down in the "Linking Vault" section. Just do the bits that pertain to permissions, you can ignore the chat and economy bits.
     
  7. Offline

    RyanDev

    I've done this but still need help getting line 79 to work (getting the name of the player's group)...

    Code:java
    1. package me.ryanre;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import net.milkbowl.vault.chat.Chat;
    6. import net.milkbowl.vault.economy.Economy;
    7. import net.milkbowl.vault.permission.Permission;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.plugin.RegisteredServiceProvider;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. import ru.tehkode.permissions.PermissionUser;
    18. import ru.tehkode.permissions.bukkit.PermissionsEx;
    19.  
    20. public abstract class VerseCM extends JavaPlugin {
    21.  
    22. public final Logger logger = Logger.getLogger("Minecraft");
    23.  
    24. @Override
    25. public void onEnable() {
    26. getLogger().info("plugin Enabled and running smooth!");
    27.  
    28. }
    29.  
    30. @Override
    31. public void onDisable() {
    32.  
    33. }
    34.  
    35. public static Permission permission = null;
    36. public static Economy economy = null;
    37. public static Chat chat = null;
    38.  
    39. private boolean setupPermissions()
    40. {
    41. RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
    42. if (permissionProvider != null) {
    43. permission = permissionProvider.getProvider();
    44. }
    45. return (permission != null);
    46. }
    47.  
    48. private boolean setupChat()
    49. {
    50. RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class);
    51. if (chatProvider != null) {
    52. chat = chatProvider.getProvider();
    53. }
    54.  
    55. return (chat != null);
    56. }
    57.  
    58. private boolean setupEconomy()
    59. {
    60. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    61. if (economyProvider != null) {
    62. economy = economyProvider.getProvider();
    63. }
    64.  
    65. return (economy != null);
    66. }
    67.  
    68.  
    69. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    70.  
    71. if (cmd.getName().equalsIgnoreCase("verse") && sender instanceof Player){
    72.  
    73. Player player = (Player) sender;
    74.  
    75. if(player.hasPermission("versecm.verse"))
    76.  
    77. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GREEN + player.getName() + ChatColor.GRAY + " is currently active on server '" + ChatColor.DARK_AQUA + ChatColor.BOLD + "LOBBY" + ChatColor.GRAY + "'");
    78. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GRAY + "This server currently has " + ChatColor.GREEN + ChatColor.BOLD + Bukkit.getOnlinePlayers().length + ChatColor.GRAY + " players online!");
    79. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GRAY + "This player is rank " + ChatColor.DARK_AQUA + "[" + ChatColor.DARK_AQUA + player.getPlayerGroups(OfflinePlayer) + ChatColor.DARK_AQUA + "]");
    80.  
    81. return true;
    82.  
    83. }else{
    84.  
    85. Player player = (Player) sender; player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.DARK_RED + "Nope. Looks like you don't have permission for this.");
    86.  
    87. return true;
    88.  
    89. }
    90.  
    91. }
    92.  
    93. }
    94.  
     
  8. Offline

    fireblast709

    RyanDev
    - Don't use the Minecraft logger
    - Player extends OfflinePlayer, so you could use that as the parameter
    - Since when does Player have the method getPlayerGroup()? Use the static methods in the Vault clasd
     
  9. RyanDev Also, this isn't urgent. Please don't do that, it's pretty rude. :)
     
  10. Offline

    RyanDev


    Hi fireblast709 , i'm quite new to bukkit plugin coding and i'm a little unsure how to carry out your second point.

    Here is my code currently, issue line 77 "Player cannot be resolved to a variable"

    Code:java
    1. package me.ryanre;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import net.milkbowl.vault.chat.Chat;
    6. import net.milkbowl.vault.economy.Economy;
    7. import net.milkbowl.vault.permission.Permission;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.plugin.RegisteredServiceProvider;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. import ru.tehkode.permissions.PermissionUser;
    18. import ru.tehkode.permissions.bukkit.PermissionsEx;
    19.  
    20. public abstract class VerseCM extends JavaPlugin {
    21.  
    22. @Override
    23. public void onEnable() {
    24. getLogger().info("plugin Enabled and running smooth!");
    25.  
    26. }
    27.  
    28. @Override
    29. public void onDisable() {
    30.  
    31. }
    32.  
    33. public static Permission permission = null;
    34. public static Economy economy = null;
    35. public static Chat chat = null;
    36.  
    37. private boolean setupPermissions()
    38. {
    39. RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
    40. if (permissionProvider != null) {
    41. permission = permissionProvider.getProvider();
    42. }
    43. return (permission != null);
    44. }
    45.  
    46. private boolean setupChat()
    47. {
    48. RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class);
    49. if (chatProvider != null) {
    50. chat = chatProvider.getProvider();
    51. }
    52.  
    53. return (chat != null);
    54. }
    55.  
    56. private boolean setupEconomy()
    57. {
    58. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    59. if (economyProvider != null) {
    60. economy = economyProvider.getProvider();
    61. }
    62.  
    63. return (economy != null);
    64. }
    65.  
    66.  
    67. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    68.  
    69. if (cmd.getName().equalsIgnoreCase("verse") && sender instanceof Player){
    70.  
    71. Player player = (Player) sender;
    72.  
    73. if(player.hasPermission("versecm.verse"))
    74.  
    75. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GREEN + player.getName() + ChatColor.GRAY + " is currently active on server '" + ChatColor.DARK_AQUA + ChatColor.BOLD + "LOBBY" + ChatColor.GRAY + "'");
    76. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GRAY + "This server currently has " + ChatColor.GREEN + ChatColor.BOLD + Bukkit.getOnlinePlayers().length + ChatColor.GRAY + " players online!");
    77. player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.GRAY + "This player is rank " + ChatColor.DARK_AQUA + "[" + ChatColor.DARK_AQUA + player.getGroup(Player) + ChatColor.DARK_AQUA + "]");
    78.  
    79. return true;
    80.  
    81. }else{
    82.  
    83. Player player = (Player) sender; player.sendMessage(ChatColor.YELLOW + "[VerseMC] " + ChatColor.DARK_RED + "Nope. Looks like you don't have permission for this.");
    84.  
    85. return true;
    86.  
    87. }
    88.  
    89. }
    90.  
    91. }
    92.  
    93.  
     
  11. Offline

    fireblast709

    RyanDev It's partially Java. With 'Player' and 'OfflinePlayer' I meant the classes. You can use your 'player' variable as the OfflinePlayer parameter
     
  12. Offline

    RyanDev


    I understand what you are saying but how would I use this to make it work?

    Sorry I'm quite nooby at java my appologies. I'm only just on the edge of understanding what you're suggesting.

    Could you show me how I could solve this? thanks :)
     
  13. Offline

    fireblast709

Thread Status:
Not open for further replies.

Share This Page