GM Permission not working

Discussion in 'Plugin Development' started by GodzillaFlame42, Aug 10, 2016.

Thread Status:
Not open for further replies.
  1. This gamemode permission is not working and i dont know how its not.

    Here is the code:
    Code:
    package gamemode;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class GM implements CommandExecutor {
    
        List<String> toggled = new ArrayList<String>();
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(label.equalsIgnoreCase("gm")) {
                if(!(sender instanceof Player)) {
                    Player player = (Player) sender;
                    if(player.hasPermission("Gamemode.Allow"))
                    sender.sendMessage(ChatColor.BLUE + "Game Mode" + ChatColor.DARK_GRAY + " >> " + ChatColor.GRAY + "You must be a player to use this command!");
                    return false;
       
                }
                Player player1 = (Player) sender;
                if(toggled.contains(player1.getName())) {
                    player1.sendMessage(ChatColor.BLUE + "Game Mode" + ChatColor.DARK_GRAY + " >> " + ChatColor.GRAY + player1.getName() + "'s Creative: " + ChatColor.RED + "False");
                    player1.setGameMode(GameMode.SURVIVAL);
                    toggled.remove(player1.getName());
                    return true;
                }
                player1.sendMessage(ChatColor.BLUE + "Game Mode" + ChatColor.DARK_GRAY + " >> " + ChatColor.GRAY + player1.getName() + "'s Creative: " + ChatColor.GREEN + "True");
                player1.setGameMode(GameMode.CREATIVE);
                toggled.add(player1.getName());
                return true;
            } else {
                Player player = (Player) sender;
                player.sendMessage(ChatColor.BLUE + "Permissions" + ChatColor.DARK_GRAY + " >> " + ChatColor.GRAY + "This requires Permissions Rank [" + ChatColor.BLUE + "ADMIN" + ChatColor.GRAY + "].");
            }
            return false;
      }
    }
     
  2. Offline

    N00BHUN73R

    @GodzillaFlame42
    Encapsulation!
    Just a note, Console always has permission to do any and everything. You are putting the permission part after you know it's console, should probably move it.
    You have to move it under the } from sender instanceof Player and make sure to use {} after you type the line out so all the code under that gets executed!

    EDIT:
    Also I've noticed from your previous posts, you do the same little mistakes.
    I would suggest learning some more java before jumping into bukkit because you've made the same mistakes with encapsulation and semi-colons. Just a suggestion.
     
    Zombie_Striker likes this.
  3. i still dont understand what i do to fix this. @N00BHUN73R
     
  4. Offline

    Zombie_Striker

    @GodzillaFlame42
    Learn Java before working on plugins. That will really help you understand how encapsulation works. If you need a tutorial for Java, you can find one at the following link.
    https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/
     
Thread Status:
Not open for further replies.

Share This Page