Solved & gets replaced with "null"

Discussion in 'Plugin Development' started by Markcrafter1, Dec 2, 2016.

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

    Markcrafter1

    Hey Community,

    I dont know what it is, but it's not working:

    Config:
    Code:
    YT:
    - MSG1
    - MSG2
    - MSG3
    - MSG4
    

    If I for example insert &4TEST and reload the server, it replaces the &4TEST with just "null".

    No errors etc.

    InGame Command to output into chat
    Code:
    package cmds;
    
    import java.io.File;
    import java.util.List;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    
    public class yt implements CommandExecutor{
    
        private File file = new File("plugins//SchillerBasic", "Nachrichten.yml");
        private FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
      
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
    
          
            List<String> youtube = cfg.getStringList("YT");
          
            for(String str : youtube){
                Player p = (Player) sender;
                p.sendMessage(str);
            }
            return true;
        }
      
      
    
    }
    

    Main:
    Code:
    package me.schillerbasic;
    
    import java.io.File;
    import java.io.IOException;
    import java.util.Arrays;
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import cmds.yt;
    
    import listener.Reload;
    
    public class Class extends JavaPlugin{
        
        String[] yt = {"MSG1", "MSG2", "MSG3", "MSG4"};
    
      
        private File ordner = new File("plugins//SchillerBasic");
        private File file = new File("plugins//SchillerBasic", "Nachrichten");
        private FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
        public static String prefix = "§6SchillerYT §7>> §3";
    
        private static Class plugin;
        public static int sc;
        
        public static Class getPlugin(){
           return plugin;
         }
        
        public void onDisable() {
        }
        
        public void onEnable(){
            registerFiles();
            setCFG();
          
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvents(new Reload(), this);
           getCommand("yt").setExecutor(new yt());
          
           try {
                cfg.save(file);
            } catch (IOException e) {
            }
          
        }
      
      
        public void setCFG(){
          
            cfg.options().copyDefaults(true);
            cfg.addDefault("YT", Arrays.asList(youtube));
          
          
          
            try {
                cfg.save(file);
            } catch (IOException e) {
              
            }
        }
      
        public void registerFiles(){
            if(!ordner.exists()){
                ordner.mkdir();
            }
          
          
            if(!file.exists()){
            try {
                file.createNewFile();
            } catch (IOException e) {
              
            }
          
    
        }
        }
    }
          
    



    Thanks,
    Mark
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Markcrafter1 You never set the plugin variable.
    And please follow naming conventions, never name a class class.
     
    DoggyCode™ likes this.
  3. Offline

    Markcrafter1

    First, thanks for your answer.

    1 What do u mean with "plugin varibale"?
    2 Did it in like 100 plugins, never went wrong... so who cares?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Markcrafter1
    1. private static Class plugin;
      You never set it
    2. Pretty much all other developers out here.
     
    MrGeneralQ and AL_1 like this.
  5. Offline

    Markcrafter1

    1. I set it?
    2. ok


    But u still haven't answered my question.
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    Markcrafter1

    http://prntscr.com/delgx7

    Its also in the code I sent u

    And my question was why my &4TEST gets replaced with "null" in the config.
     
  8. Offline

    timtower Administrator Administrator Moderator

    @Markcrafter1 That is a declaration, that isn't setting it.
    And put single quotes around the value.
     
  9. Offline

    SirGregg

    @Markcrafter1 You cannot just put &4TEST and expect the output to be the same as ChatColor.DARK_RED + "TEST". Use
    Code:
    ChatColor.translateAlternateColorCodes(arg1, String to translate);
    To automatically translate the given char (defined as arg1) to ChatColor.<Color Name>.
     
  10. Offline

    MrGeneralQ

    Another case of : start learning Java basics before coding Bukkit plugins. Same as don't start running before you can walk
     
    Last edited: Dec 3, 2016
  11. Offline

    Markcrafter1

    This was the only thing I wanted to know. Working fine now. Thanks.

    Thanks for your answer! That was missing too, but I found it out myself. Thanks anyway!


    Very useful comment to get rid of my problem. Thank you anyway

    --Solved
     
Thread Status:
Not open for further replies.

Share This Page