Solved arg.lentgh > 6 Doesn't work (or im silly)

Discussion in 'Plugin Development' started by Meca_3D, Dec 17, 2021.

  1. Offline

    Meca_3D

    Hello i'm working on a plugin for a server and i'm coding a register system with Yaml (but it's not that the problem).
    I check if player hav a password lentgh equal at 6 but that Doesn't work .
    i'm french so srry for my english

    Code:
    package fr.meca3d.lineplug.commands;
    
    import java.io.File;
    import java.util.UUID;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    
    import fr.meca3d.lineplug.Main;
    
    public class CommandRegister implements CommandExecutor {
    
        private Main main;
       
        public CommandRegister(Main main) {
            this.main = main;
        }
       
       
        @Override
        public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) {
    
           
            if(sender instanceof Player) {
                Player player = (Player)sender;
                if(arg1.getName().equalsIgnoreCase("register")) {
                   
                    if(arg3.length < 6) {    <===== Here my problem
                        player.sendMessage("Le mot de passe doit faire minimum 6 de longueur !");
                    }
                    if(arg3.length >= 6) {   <===== and Here
                        player.sendMessage("okew !");
                   
                        File file = new File(main.getDataFolder(), "Lineplug/MDP.yml");
                        UUID uuid = player.getUniqueId();
                        YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file);
                   
                        configuration.set("player." + uuid.toString(), arg3);
                    }
                }
            }
           
            return false;
        }
    
    }
     
  2. Offline

    KarimAKL

    @Meca_3D You're checking the length of the arguments array, not the length of the string.
     

Share This Page