Weird classname while saving FileConfiguration.save()

Discussion in 'Plugin Development' started by serhatkaya, Apr 7, 2022.

  1. Offline

    serhatkaya

    Hi All, I'm new at Java and Plugin Development,
    I'm facing a problem while saving the config.yml for first time, after plugin loads it doesn't save config.yml properly, after load if I run reload command on my server, config.yml fixes itself.

    Here is my first load config.yml

    Code:
    # Serhat KAYA
    
    cleaner: !!serhatkaya.candieUtils.types.CleanerSettings
      enabled: true
      messages:
        cleanSucceed: Cleaned successfully
        fiveToClean: The items on the ground will be removed in 10 seconds.
        tenToClean: The items on the ground will be removed in 10 seconds.
      offset: 60
    broadcaster: !!serhatkaya.candieUtils.types.BroadcasterSettings
      enabled: true
      messageColor: §f
      messages:
      - Candie broadcaster works.
      - This is default message of CandieBroadcaster
      - You can edit broadcasting messages in config.yml
      offset: 10
      prefix: §4[§bCandieBroadcaster§4]
    
    After running reload command

    Code:
    # Serhat KAYA
    
    cleaner:
      enabled: true
      messages:
        cleanSucceed: Cleaned successfully
        fiveToClean: The items on the ground will be removed in 10 seconds.
        tenToClean: The items on the ground will be removed in 10 seconds.
      offset: 60
    broadcaster:
      enabled: true
      messageColor: §f
      messages:
      - Candie broadcaster works.
      - This is default message of CandieBroadcaster
      - You can edit broadcasting messages in config.yml
      offset: 10
      prefix: §4[§bCandieBroadcaster§4]
    
    I have a class named Config and I'm calling it's load() function on plugin enable.

    load method:

    Code:
      
            config.options().setHeader(Arrays.asList(new String[] { "Serhat KAYA" }));
            config.addDefault("cleaner", new CleanerSettings(true, 60));
            config.addDefault("broadcaster", new BroadcasterSettings(true, 10));
            getConfig().options().copyDefaults(true);
            save();
    
            CLEANER_SETTINGS = config.getObject("cleaner", CleanerSettings.class);
            BROADCASTER_SETTINGS = config.getObject("broadcaster", BroadcasterSettings.class);
    
            BROADCASTER_SETTINGS.messages = config.getStringList("broadcaster.messages");
    
    save method :

    Code:
     public static void save() {
            if (config == null || configFile == null) {
                return;
            }
    
            try {
                config.save(configFile);
            } catch (IOException ex) {
                Log.severe("Could not save config.yml to " + configFile.getAbsolutePath());
            }
        }
    To explain it better, BroadcasterSettings class:

    Code:
    package serhatkaya.candieUtils.types;
    
    import java.util.Arrays;
    import java.util.List;
    
    public class BroadcasterSettings extends Feature {
        public String prefix = "§4[§bCandieBroadcaster§4]";
        public String messageColor = "§f";
        public List<String> messages = Arrays.asList(new String[] { "Candie broadcaster works.",
                "This is default message of CandieBroadcaster", "You can edit broadcasting messages in config.yml" });
    
        public BroadcasterSettings(boolean enabled, int offset) {
            super(enabled, offset);
    
        }
    }
    
    CleanerSettings class

    Code:
    package serhatkaya.candieUtils.types;
    
    public class CleanerSettings extends Feature {
        public CleanerMessages messages = new CleanerMessages();
    
        public CleanerSettings(boolean enabled, int offset) {
            super(enabled, offset);
        }
    }
    
    CleanerMessages class

    Code:
    package serhatkaya.candieUtils.types;
    
    public class CleanerMessages {
        public String tenToClean = "The items on the ground will be removed in 10 seconds.";
        public String fiveToClean = "The items on the ground will be removed in 10 seconds.";
        public String cleanSucceed = "Cleaned successfully";
    }
    
    Feature class
    Code:
    package serhatkaya.candieUtils.types;
    
    public class Feature {
        public boolean enabled;
        public int offset;
    
        public Feature(boolean enabled, int offset) {
            super();
            this.enabled = enabled;
            this.offset = offset;
        }
    }
    
    After reloading plugins everything works well, I just need to get rid of that weird class paths (cleaner: !!serhatkaya.candieUtils.types.CleanerSettings)
     
    Last edited: Apr 7, 2022
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    serhatkaya

    I edited the post. Thank you for reply.
     

Share This Page