Development Assistance Can't get config information

Discussion in 'Plugin Help/Development/Requests' started by ArthurHoeke, Jan 11, 2015.

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

    ArthurHoeke

    Hello,
    Im trying to get a string out of my config, but I get a huge error. I don't know why...
    [​IMG]
    My code:

    Main for creating default config:
    Code:
    public void loadConfiguration(){
             //See "Creating you're defaults"
             plugin.getConfig().options().copyDefaults(true); // NOTE: You do not have to use "plugin." if the class extends the java plugin
             //Save the config whenever you manipulate it
             String JoinMessage = "Servers.JoinMessage";
             String Slot1 = "Servers.Slot1";
             String Slot2 = "Servers.Slot2";
             String Slot3 = "Servers.Slot3";
             String Slot4 = "Servers.Slot4";
             String Slot5 = "Servers.Slot5";
             String Slot6 = "Servers.Slot6";
             String Slot7 = "Servers.Slot7";
             String Slot8 = "Servers.Slot8";
                     plugin.getConfig().addDefault(Slot1, "&2>> &7SkyBlock");
                     plugin.getConfig().addDefault(Slot2, "&2>> &7KitPvP");
                     plugin.getConfig().addDefault(Slot3, "&2>> &7The Walls");
                     plugin.getConfig().addDefault(Slot4, "&2>> &7Capture The Flag");
                     plugin.getConfig().addDefault(Slot5, "&2>> &7PaintBall");
                     plugin.getConfig().addDefault(Slot6, "&2>> &7Factions");
                     plugin.getConfig().addDefault(Slot7, "&2>> &7SurvivalGames");
                     plugin.getConfig().addDefault(Slot8, "&2>> &7Spleef");
                     plugin.getConfig().addDefault(JoinMessage, "&7Scroll to see Servers");
                     plugin.getConfig().options().copyDefaults(true);
             plugin.saveConfig();
        }
    Other class:

    Code:
        @EventHandler
        public void OnJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            p.getInventory().setHeldItemSlot(0);
            Menu(p);
            Plugin plugin = (Plugin) this;
            p.sendMessage(plugin.getConfig().getString("Servers.JoinMessage" + " Test"));
        }
    Tried some more things, but still not working...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  2. Offline

    Plugers11

    Tutorial 35th line?

    Also
    Show us all classess pls..
     
  3. Offline

    ArthurHoeke

    That's this line of code: Plugin plugin = (Plugin) this;
    Code:
    package me.arthurhoeke.pindaserver;
    
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class Main extends JavaPlugin implements Listener{
         public FileConfiguration config;
        @Override
        public void onEnable() {
            PluginManager pm = Bukkit.getPluginManager();
            pm.registerEvents(new Tutorial(), this);
            loadConfiguration();
        }
        Plugin plugin = this;
        public void loadConfiguration(){
             //See "Creating you're defaults"
             plugin.getConfig().options().copyDefaults(true); // NOTE: You do not have to use "plugin." if the class extends the java plugin
             //Save the config whenever you manipulate it
             String JoinMessage = "Servers.JoinMessage";
             String Slot1 = "Servers.Slot1";
             String Slot2 = "Servers.Slot2";
             String Slot3 = "Servers.Slot3";
             String Slot4 = "Servers.Slot4";
             String Slot5 = "Servers.Slot5";
             String Slot6 = "Servers.Slot6";
             String Slot7 = "Servers.Slot7";
             String Slot8 = "Servers.Slot8";
                     plugin.getConfig().addDefault(Slot1, "&2>> &7SkyBlock");
                     plugin.getConfig().addDefault(Slot2, "&2>> &7KitPvP");
                     plugin.getConfig().addDefault(Slot3, "&2>> &7The Walls");
                     plugin.getConfig().addDefault(Slot4, "&2>> &7Capture The Flag");
                     plugin.getConfig().addDefault(Slot5, "&2>> &7PaintBall");
                     plugin.getConfig().addDefault(Slot6, "&2>> &7Factions");
                     plugin.getConfig().addDefault(Slot7, "&2>> &7SurvivalGames");
                     plugin.getConfig().addDefault(Slot8, "&2>> &7Spleef");
                     plugin.getConfig().addDefault(JoinMessage, "&7Scroll to see Servers");
                     plugin.getConfig().options().copyDefaults(true);
             plugin.saveConfig();
        }
    }
       
       
     
  4. Offline

    Plugers11

    WTF?

    Why u not simple use this.getConfig() ?????
     
  5. Offline

    mythbusterma

    @ArthurHoeke

    Or you scrap all of that, every last bit of code concerning your config and use the simple, beautiful, elegant, not stupid as hell:

    Code:
    JavaPlugin#saveDefaultConfig()
    Oh but can it really be that easy? Anyone who actually reads the documentation and doesn't watch stupid YouTube tutorials can vouch for it, it really is just that easy. Simply use this method and include a file named config.yml in the root directory of your jarfile, which Eclipse will do for you if you just put the file in the project directory and export it with the jarfile.

    Since nobody actually reads the documentation, and this is a very difficult concept to grasp, let me break it down for you:

    Code:
    @Override
    public void onEnable() {
        saveDefaultConfig();
    }
    I know this is a lot to take in at once, but I'm sure with practise you can master it.
     
  6. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
  7. Offline

    Ganga

    @mythbusterma
    I guess that has nothing to do with the config. I've got some same errors on entitydamagebyentity. And I also got no solution. :/
     
  8. Offline

    mythbusterma

    @Ganga

    Well his default config is still vomit inducing to look at, but it isn't causing the stack trace.


    @ArthurHoeke

    Your stack trace is caused by not know Java. Stop watching YouTube tutorials and actually learn the language if you want to program for it.

    You're performing an illegal class cast, and it's causing an exception.

    The Java™ Tutorials
     
  9. Offline

    ArthurHoeke

  10. Offline

    nverdier

Thread Status:
Not open for further replies.

Share This Page