How do i add permissions to a plugin? ( PermissionsEx Support)

Discussion in 'Plugin Development' started by javoris767, Oct 18, 2011.

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

    javoris767

    I pasted it just luke that and theirs a problem with

    Code:
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
     
  2. What is the problem?
     
  3. Offline

    thehutch

    thts because of the variables in your onCommand method your using :p
    your using Command command but in your code its Command cmd
     
  4. No, cmd is another String.
    Code:java
    1. String cmd = command.getName();
     
  5. Offline

    thehutch

    Well that in itself is pretty pointless that line :p just pout replace command with cmd :p

    Oh found your error :p no return value :O

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  6. Oh, yea. Dont know why Eclipse didn't give me an error for that.
     
    thehutch likes this.
  7. Offline

    javoris767

    so basically the return false; should be added?
     
  8. Make it return true;
     
  9. Offline

    javoris767

    command wont work ingame
     
  10. Offline

    thehutch

    in what way, the actual command wont work in what its purpose is or your getting a message saying unknown command or an error in the console?
     
  11. You really dont want to get help, huh?
    Saying it doesn't work wont help us at all.
     
  12. Offline

    javoris767

    lol i mean console error and like the cmd has an internal error has occurred while performing this command
     
  13. Then show us the error it gives you, goddamnit.
     
  14. Offline

    thehutch

    Chillax bro (I do not say that usually :p) but anyway yh we do need the console error otherwise we dont know whats going wrong.
     
  15. Offline

    javoris767

    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'javc
    ' in plugin Pr3datorCraft v1.5
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    3)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:3
    55)
            at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:757)
            at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:722)
    
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:715)
            at net.minecraft.server.Packet3Chat.a(Packet3Chat.java:33)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:92)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:108)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:471)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    Caused by: java.lang.Error: Unresolved compilation problem:
            This method must return a result of type boolean
    
            at me.javoris767.Pr3datorCraft.Pr3datorCraft.onCommand(Pr3datorCraft.jav
    a:27)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
            ... 12 more
    internal error has occurred while attempting to performing this command.
     
  16. Are you sure you added return true; ?
    If you did, you probally placed it wrong.
     
  17. Offline

    javoris767

    return true is close to the end
    Code:java
    1. package me.javoris767.Pr3datorCraft;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.GameMode;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Pr3datorCraft extends JavaPlugin {
    14. public static Pr3datorCraft plugin;
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16.  
    17. public void onEnable() {
    18. PluginDescriptionFile pdfFile = this.getDescription();
    19. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled.");
    20. }
    21.  
    22. public void onDisable() {
    23. PluginDescriptionFile pdfFile = this.getDescription();
    24. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled.");
    25. }
    26.  
    27. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    28. String cmd = command.getName();
    29. if (cmd.equalsIgnoreCase("JavC")) {
    30. if (!(sender instanceof Player)) {
    31. logger.info("You cant use that command from the console");
    32. return true;
    33. }
    34. Player player = (Player) sender;
    35. if (player.hasPermission("pr3d.creative") || player.isOp()) {
    36. player.setGameMode(GameMode.CREATIVE);
    37. player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "Set to creative mode");
    38. } else {
    39. player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "You dont have permissions for that command.");
    40. }
    41. } else if (cmd.equalsIgnoreCase("JavS")) {
    42. if (!(sender instanceof Player)) {
    43. logger.info("You cant use that command from the console");
    44. return true;
    45. }
    46. Player player = (Player) sender;
    47. if (player.hasPermission("pr3d.survival") || player.isOp()) {
    48. player.setGameMode(GameMode.SURVIVAL);
    49. player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "Set to survival mode");
    50. } else {
    51. player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "You dont have permissions for that command.");
    52. }
    53. }
    54. return true;
    55. }
    56. }
     
  18. Offline

    thehutch

    First fo all remove this:
    Code:
    public static Pr3datorCraft plugin;
    Next change your Logger declaration to this:
    Code:
    Logger logger = Logger.getLogger("Minecraft");
    Ok then copy and replace this with your onCOmmand method:
    Code:
    @Override
         public boolean onCommand(CommandSender cs, Command cmd, String aliases, String[] args) {
    
            if (cmd.getName().equalsIgnoreCase("JavC")) {
                if (!(cs instanceof Player)) {
                    cs.sendMessage("Invalid Player, Player required");
                    return false;
            }
                Player player = (Player)cs;
    
                if (player.hasPermission("pr3d.creative") || player.isOp()) {
                    player.setGameMode(GameMode.CREATIVE);
                    player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "Set to creative mode");
                } else {
    
                    player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "You dont have permissions for that command.");
                }
                } else if (cmd.getName().equalsIgnoreCase("JavS")) {
    
                     if (!(cs instanceof Player)) {
                     logger.info("You cant use that command from the console");
                     return true;
                     }
                     Player player = (Player)cs;
                     if (player.hasPermission("pr3d.survival") || player.isOp()) {
                     player.setGameMode(GameMode.SURVIVAL);
                     player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "Set to survival mode");
                     } else {
                     player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "You dont have permissions for that command.");
                     }
                                }
                                return true;
                               }
                            }
    I would also like to add that there is a "}" at the end of that which ends the class if your onCommand is not at the end remove the last "}" ok that might be your error
     
  19. Offline

    javoris767

    Did everything and its the same console and ingame error
     
  20. Offline

    thehutch

    are there any errors in your IDE and paste your code now
     
  21. Offline

    javoris767

    Code:java
    1. package me.javoris767.Pr3datorCraft;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.GameMode;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Pr3datorCraft extends JavaPlugin {
    14. Logger logger = Logger.getLogger("Minecraft");
    15. public void onEnable() {
    16. PluginDescriptionFile pdfFile = this.getDescription();
    17. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled.");
    18. }
    19.  
    20. public void onDisable() {
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled.");
    23. }
    24. @Override
    25. public boolean onCommand(CommandSender cs, Command cmd, String aliases, String[] args) {
    26.  
    27. if (cmd.getName().equalsIgnoreCase("JavC")) {
    28. if (!(cs instanceof Player)) {
    29. cs.sendMessage("Invalid Player, Player required");
    30. return false;
    31. }
    32. Player player = (Player)cs;
    33.  
    34. if (player.hasPermission("pr3d.creative") || player.isOp()) {
    35. player.setGameMode(GameMode.CREATIVE);
    36. player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "Set to creative mode");
    37. } else {
    38.  
    39. player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "You dont have permissions for that command.");
    40. }
    41. } else if (cmd.getName().equalsIgnoreCase("JavS")) {
    42.  
    43. if (!(cs instanceof Player)) {
    44. logger.info("You cant use that command from the console");
    45. return true;
    46. }
    47. Player player = (Player)cs;
    48. if (player.hasPermission("pr3d.survival") || player.isOp()) {
    49. player.setGameMode(GameMode.SURVIVAL);
    50. player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "Set to survival mode");
    51. } else {
    52. player.sendMessage("[Pr3dator Craft] " + ChatColor.RED + "You dont have permissions for that command.");
    53. }
    54. }
    55. return true;
    56. }
    57. }


    o and no code errors

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  22. Offline

    MrMag518

    Im pretty sure u need a return false;

    Like on end of my commands I always use:
    Code:
                    return true;
                }
            }
            return false;
        }
    }
    Like do something comepletly easy like this:
    Code:
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(cmd.getName().equalsIgnoreCase("kill")){
                Player player = (Player) sender;
                    player.setHealth(0);
                return true;
            }
            return false;
        }
    }
     
  23. Offline

    javoris767

    Works but permission nodes dont :|
     
  24. Offline

    javoris767

    Code:java
    1. package me.javoris767.Pr3datorCraft;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.GameMode;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Pr3datorCraft extends JavaPlugin {
    14. Logger logger = Logger.getLogger("Minecraft");
    15. public void onEnable() {
    16. PluginDescriptionFile pdfFile = this.getDescription();
    17. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled.");
    18. }
    19.  
    20. public void onDisable() {
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled.");
    23. }
    24. @Override
    25. public boolean onCommand(CommandSender cs, Command cmd, String aliases, String[] args) {
    26.  
    27. if (cmd.getName().equalsIgnoreCase("JavC")) {
    28. if (!(cs instanceof Player)) {
    29. cs.sendMessage("Invalid Player, Player required");
    30. return false;
    31. }
    32. Player player = (Player)cs;
    33.  
    34. if (player.hasPermission("pr3d.creative") || player.isOp()) {
    35. player.setGameMode(GameMode.CREATIVE);
    36. player.sendMessage(ChatColor.GREEN + "[Pr3dator Craft] " + ChatColor.DARK_RED + "Set to creative mode");
    37. } else {
    38.  
    39. player.sendMessage(ChatColor.DARK_GREEN + "[Pr3dator Craft] " + ChatColor.RED + "You dont have permissions for that command.");
    40. }
    41. } else if (cmd.getName().equalsIgnoreCase("JavS")) {
    42.  
    43. if (!(cs instanceof Player)) {
    44. logger.info("You cant use that command from the console");
    45. return true;
    46. }
    47. Player player = (Player)cs;
    48. if (player.hasPermission("pr3d.survival") || player.isOp()) {
    49. player.setGameMode(GameMode.SURVIVAL);
    50. player.sendMessage(ChatColor.DARK_GREEN + "[Pr3dator Craft] " + ChatColor.RED + "Set to survival mode");
    51. } else {
    52. player.sendMessage(ChatColor.GREEN + "[Pr3dator Craft] " + ChatColor.DARK_RED + "You dont have permissions for that command.");
    53. }
    54. }
    55. return true;
    56. }
    57. }


    Code:
    name: Pr3datorCraft
     main: me.javoris767.Pr3datorCraft.Pr3datorCraft
     version: 1.6
     description: >
                  Changes player's game mode.
     commands:
       JavC:
         description: Toggles game mode to creative.
       JavS:
         description: Toggles game mode to survival.
     permissions:
         pr3d.creative:
             description: Allows you to switch to creative mode.
             default: op
         pr3d.survival:
             description: Allows you to switch to survival mode.
             default: op
    
     
  25. Offline

    Blackside921

  26. Offline

    javoris767

    Could some check this cuz im trying to add PermissionsEx




    Code:java
    1. package me.javoris767.Pr3datorCraft;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.GameMode;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. import ru.tehkode.permissions.PermissionManager;
    15. import ru.tehkode.permissions.bukkit.PermissionsEx;
    16.  
    17. public class Pr3datorCraft extends JavaPlugin {
    18. Logger logger = Logger.getLogger("Minecraft");
    19. public void onEnable() {
    20. PluginDescriptionFile pdfFile = this.getDescription();
    21. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled.");
    22. }
    23.  
    24. public void onDisable() {
    25. PluginDescriptionFile pdfFile = this.getDescription();
    26. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled.");
    27. }
    28. @Override
    29. public boolean onCommand(CommandSender cs, Command cmd, String aliases, String[] args) {
    30.  
    31. if (cmd.getName().equalsIgnoreCase("javc")) {
    32. if (!(cs instanceof Player)) {
    33. cs.sendMessage("Invalid Player, Player required");
    34. return false;
    35. }
    36. Player player = (Player)cs;
    37. if(Bukkit.getServer().getPluginManager().isPluginEnabled("PermissionsEx")){
    38. PermissionManager permissions = PermissionsEx.getPermissionManager();
    39. if(permissions.has(player, "pr3d.creative") || player.isOp()) {
    40. if (player.hasPermission("pr3d.creative") || player.isOp()) {
    41. } else {
    42. }
    43. } else {
    44. Logger.getLogger("Minecraft").warning("PermissionsEx plugin are not found.");
    45. }
    46. player.setGameMode(GameMode.CREATIVE);
    47. player.sendMessage(ChatColor.GREEN + "[Pr3dator Craft] " + ChatColor.DARK_RED + "Set to creative mode");
    48. } else {
    49.  
    50. player.sendMessage(ChatColor.DARK_GREEN + "[Pr3dator Craft] " + ChatColor.RED + "You dont have permissions for that command.");
    51. }
    52. } else if (cmd.getName().equalsIgnoreCase("javs")) {
    53.  
    54. if (!(cs instanceof Player)) {
    55. logger.info("You cant use that command from the console");
    56. return true;
    57. }
    58. Player player = (Player)cs;
    59.  
    60. if(Bukkit.getServer().getPluginManager().isPluginEnabled("PermissionsEx")){
    61. PermissionManager permissions = PermissionsEx.getPermissionManager();
    62. if(permissions.has(player, "pr3d.survival") || player.isOp()) {
    63. if (player.hasPermission("pr3d.survival") || player.isOp()) {
    64. } else {
    65. }
    66. } else {
    67. Logger.getLogger("Minecraft").warning("PermissionsEx plugin are not found.");
    68. }
    69. player.setGameMode(GameMode.SURVIVAL);
    70. player.sendMessage(ChatColor.DARK_GREEN + "[Pr3dator Craft] " + ChatColor.RED + "Set to survival mode");
    71. } else {
    72. player.sendMessage(ChatColor.GREEN + "[Pr3dator Craft] " + ChatColor.DARK_RED + "You dont have permissions for that command.");
    73. }
    74. }
    75. return true;
    76. }
    77. }
     
  27. Offline

    Icelaunche

    player.sendMessage(ChatColor.DARK_RED + " You lack permissions to complete this action");
     
    tips48 likes this.
  28. Offline

    javoris767

    I just need someone to check this and/or correct it
     
  29. Offline

    coldandtired

    You shouldn't need to do anything special for PermissionsEx (or most permissions managers) now that it's built into Bukkit.

    Just if (player.hasPermission(....))
     
  30. Offline

    javoris767

    Ya but it doesnt work when i add the node
     
Thread Status:
Not open for further replies.

Share This Page