Problems with config file

Discussion in 'Plugin Development' started by xelatercero, Jan 25, 2016.

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

    xelatercero

    I have a config file when i type something inside and reload the server all the information desapear for example a class that uses the config file:

    Code:
    public class volar implements CommandExecutor {
        public volar(Main plugin){
          
        }
        public Permission playerPermission = new Permission("ultiplugin.volar");
        SettingsManager settings = SettingsManager.getInstance();
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("volar")){
                Player player = (Player) sender;
                if (settings.getConfig().getBoolean("Volar-permisos")==true){
                    if(player.hasPermission("ultiplugin.volar")){
                        player.setAllowFlight(true);
                        player.sendMessage(ChatColor.GREEN + "Has empezado a  volar");
                  
                    }else player.sendMessage(ChatColor.RED + "No tienes permisos para este comando");
              
                  
                }else if (settings.getConfig().getBoolean("Volar-permisos")==false){
                    player.setAllowFlight(true);
                    player.sendMessage(ChatColor.GREEN + "Has empezado a  volar");
                  
                }
              
              
              
              
            }
            else if (cmd.getName().equalsIgnoreCase("Novolar")){
                Player player = (Player) sender;
                if (settings.getConfig().getBoolean("Novolar-permisos")==true){
                    if(player.hasPermission("ultiplugin.volar")){
                        player.setAllowFlight(false);
                        player.sendMessage(ChatColor.GREEN + "Has dejado de volar");
                  
                }else player.sendMessage(ChatColor.RED + "No tienes permisos para este comando");
                }
                else if (settings.getConfig().getBoolean("Novolar-permisos")==false){
                    player.setAllowFlight(false);
                    player.sendMessage(ChatColor.GREEN + "Has dejado de volar");
                  
                  
                }
                  
                  
      
      
              
                  
              
              
              
            }
            return false;
        }
    
    }
    
    but whem i put Volar-permisos=true in the config file and reload the server all desapear


    @BobTheHamster9 the config fyle doesnt have anything its empty
     
    Last edited: Jan 25, 2016
  2. Offline

    BobTheHamster9

    Do you have an image of what the config looks like before and after?
     
  3. Offline

    JoaoBM

    @xelatercero Check if the sender is a Player before casting :)
    Do you want to create a command that resets the config file to the default?
     
  4. Offline

    Zombie_Striker

    Follow Java Naming Conventions: Classes should start with a n upper-case letter.
    DON'T BLIND CAST! Check if sender is actually an instance of Player before casting
    There is no reason for a main class to be a singleton. Pass the instance of the main class instead of being lazy and abusing static.

    There is no need to turn a boolean into a boolean. You can remove the "==true" and "==false" in these two if statements. If you wanted, you can remove the whole if statement in the else clause.
    What do you mean by this?
     
  5. Offline

    teej107

    I've seen that class around here a couple times and I think its just terrible.

    @xelatercero If you use something like this, your code will be much better off with less bugs. https://bukkit.org/threads/easily-manage-configuration-files.393455/
     
Thread Status:
Not open for further replies.

Share This Page