Permission - Think I'm being a noob!

Discussion in 'Plugin Development' started by thedjtrollin, Jan 7, 2014.

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

    thedjtrollin

    Sorry to bump but this is still going on I even tried another way to do it
    Code:java
    1. package me.razulle;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Vitalitycommands extends JavaPlugin implements Listener {
    11. public void onDisable() {
    12. // TODO: Disable.
    13. }
    14.  
    15. public void onEnable() {
    16. getServer().getPluginManager().registerEvents(this, this);
    17. //TODO: Finish Enable
    18. }
    19.  
    20. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    21. Player player = (Player) sender;
    22. if (cmd.getName().equalsIgnoreCase("heal")) {
    23. if (!sender.hasPermission("vitality.heal")) {
    24. player.sendMessage("noPerms");
    25. }
    26. player.sendMessage("Perms)");
    27. //ToDo: Add Heal Code
    28. }
    29. return false;
    30.  
    31. }
    32. }
    33.  


    [​IMG]
     
  2. Offline

    random_username

    thedjtrollin
    When you check for the permission, you check it in the same statement as the command. It will say the no permission message if the command is not equal to close and the user does not have permission. How about:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    2. if(sender instanceof Player){
    3. Player player = (Player) sender;
    4. if(cmd.getName().equalsIgnoreCase("close")){
    5. if(player.hasPermission("some.permission")){
    6. //code here
    7. }else{
    8. //code here
    9. }
    10. }
    11. }
    12. return false;
    13. }

    Hope this helps :) Btw, sorry if I made a typo in the code, didn't write it in an IDE :p
     
  3. Offline

    thedjtrollin

    random_username

    I tried that it I am getting the same thing

    *New Code*
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. if(sender instanceof Player){
    3. Player player = (Player) sender;
    4. if(cmd.getName().equalsIgnoreCase("close")){
    5. if(player.hasPermission("Vitality.shutdown")){
    6. kickShutdown();
    7. }else{
    8. player.sendMessage(ChatColor.GOLD + "Vitality >" + ChatColor.RED + "How about no?");
    9. }
    10. }
    11. }
    12. return false;
    13. }
    14.  
    15.  


    This problem still has not been resolved.

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

    CubieX

    Don't forget to "return true" if the player used a valid command.

    If you "return false", the usage will be shown.
     
    thedjtrollin likes this.
  5. Offline

    thedjtrollin

    Sorry to bump but this is still going on I even tried another way to do it
    Code:java
    1. package me.razulle;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Vitalitycommands extends JavaPlugin implements Listener {
    11. public void onDisable() {
    12. // TODO: Disable.
    13. }
    14.  
    15. public void onEnable() {
    16. getServer().getPluginManager().registerEvents(this, this);
    17. //TODO: Finish Enable
    18. }
    19.  
    20. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    21. Player player = (Player) sender;
    22. if (cmd.getName().equalsIgnoreCase("heal")) {
    23. if (!sender.hasPermission("vitality.heal")) {
    24. player.sendMessage("noPerms");
    25. }
    26. player.sendMessage("Perms)");
    27. //ToDo: Add Heal Code
    28. }
    29. return false;
    30.  
    31. }
    32. }
    33.  


    [​IMG]
     
Thread Status:
Not open for further replies.

Share This Page