Help with command

Discussion in 'Plugin Development' started by TheCupOfTea, Mar 7, 2018.

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

    TheCupOfTea

    Can you help me with /gamemode command?
    When i coded it with /gamemode 0 it works but when I tried to make /gamemode 1 it dosn't work
    Code:
    package me.arbata;
    
    package me.arbata;
    
    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 GAMEMODE implements CommandExecutor {
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
            if (cmd.getName().equalsIgnoreCase("gamemode") && sender instanceof Player) {
    
                int lenght = args.length;
    
                if (lenght == 1) {
                    if (args[0].equals("0")) {
    
                        Player player = (Player) sender;
    
                        if (player.hasPermission("bess.cmds")) {
                            player.setGameMode(GameMode.SURVIVAL);
                            player.sendMessage(ChatColor.GOLD + "Žaidimo rėžimas buvo pasirinktas į " + ChatColor.RED
                                    + "išlikimo" + ChatColor.GOLD + "!");
                            TitleAPI.sendTitle(player, 20, 20, 20, ChatColor.RED + "Išlikimo",
                                    ChatColor.GOLD + "Žaidimo rėžimas buvo pasirinktas!");
    
                        } else {
                            player.sendMessage(ChatColor.RED + "Jūs neturite teisės!");
                            TitleAPI.sendTitle(player, 20, 20, 20, "", ChatColor.RED + "Tu neturi teisės!");
    
                        }
    
                        return true;
                    }
                }
            } else if (cmd.getName().equalsIgnoreCase("gamemode") && sender instanceof Player) {
    
                int lenght = args.length;
    
                if (lenght == 1) {
                    if (args[0].equals("1")) {
    
                        Player player = (Player) sender;
    
                        if (player.hasPermission("bess.cmds")) {
                            player.setGameMode(GameMode.CREATIVE);
                            player.sendMessage(ChatColor.GOLD + "Žaidimo rėžimas buvo pasirinktas į " + ChatColor.RED
                                    + "kūrybinį" + ChatColor.GOLD + "!");
                            TitleAPI.sendTitle(player, 20, 20, 20, ChatColor.RED + "Kūrybinis",
                                    ChatColor.GOLD + "Žaidimo rėžimas buvo pasirinktas!");
    
                        } else {
                            player.sendMessage(ChatColor.RED + "Jūs neturite teisės!");
                            TitleAPI.sendTitle(player, 20, 20, 20, "", ChatColor.RED + "Tu neturi teisės!");
    
                        }
    
                        return true;
                    }
                }
            }
            return false;
        }
    
    }
     
    Last edited: Mar 7, 2018
  2. Offline

    timtower Administrator Administrator Moderator

    @TheCupOfTea Please format your code, I have no idea where the blocks end or start.
     
  3. Offline

    TheCupOfTea

    I changed the language
     
  4. Offline

    timtower Administrator Administrator Moderator

    Language was fine, it is the formatting, the indentation, the place between the { and }
    In eclipse: ctrl+shift+f
     
  5. Offline

    TheCupOfTea

    now it is good?
     
  6. Offline

    timtower Administrator Administrator Moderator

    Yes.
    You check twice for gamemode and player, but in an else if.
    Put this:
    if (args[0].equals("1")) {
    check as an else if for
    if (args[0].equals("0")) {
     
  7. Offline

    TheCupOfTea

    FIXED IT THANK YOU SO MUCH!
     
    Last edited: Mar 7, 2018
  8. Offline

    AdamDev

    @TheCupOfTea
    Could you please change your thread to solved for other people to know that it is solved.
     
Thread Status:
Not open for further replies.

Share This Page