Plugin Help Need Help Loading Config.yml

Discussion in 'Plugin Help/Development/Requests' started by killerxxsethxx, Jul 2, 2015.

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

    killerxxsethxx

    Code
    package me.sethpvp.QuickLinks;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin{

    public void OnEnable(){
    getLogger().info("§8[§7QuickLinks§8]§aEnabled");
    getConfig().options().copyDefaults(true);
    saveConfig();
    }

    public void OnDisable(){
    getLogger().info("§8[§7QuickLinks§8]§cDisabled");
    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player p = (Player) sender;
    if(commandLabel.equalsIgnoreCase("Links")){
    p.sendMessage("§8-------------------------------------");
    p.sendMessage(getConfig().getString("Link_1"));
    p.sendMessage(getConfig().getString("Link_2"));
    p.sendMessage(getConfig().getString("Link_3"));
    p.sendMessage(getConfig().getString("Link_4"));
    p.sendMessage(getConfig().getString("Link_5"));
    p.sendMessage("§8-------------------------------------");
    }
    return false;
    }
    }
    Config.yml
    #Put the Links In Of Your Server.
    Link_1: 'test1'
    Link_2: 'test2'
    Link_3: 'test3'
    Link_4: 'test4'
    Link_5: 'test5'
    plugin.yml
    name: QuickLinks
    author: SethPvP
    version: 1.0
    main: me.sethpvp.QuickLinks.Main

    commands:
    Links:
    description: This Plugin Makes it Easy to put the Links of your server in the Config.yml. To see your links do /links
    help me please figure this out

    Plz help me out with is plugin

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

    Boomer

    what is wrong with it.. Be specific. Show error messages in full, etc?
     
  3. Offline

    killerxxsethxx

    The Config.yml Is not loading up at all i need help figure this out plz help!
     
  4. @killerxxsethxx Multiple issues here, I'm guessing you learnt off YouTube.

    1. You don't need an enable message, Bukkit does it for you.
    2. Use saveDefaultConfig();
    3. You don't need an onDisable if you aren't using it.
    4. Check before casting
    5. cmd.getName not commandLabel
    6. Use ChatColor not §
    7. You could make it better by just putting the links in a list and going through the list and sending that

    Please post your full server log in pastebin.com
     
  5. Offline

    Boomer

    also, its onEnable() .... you should have noticed the lack of your message in the log
     
  6. Offline

    killerxxsethxx

    @bwfcwalshy Im trying to make this plugin pubic becuz im have been making people plugin is like this for away but people want me to change it but like i want them to make it them self not me i want the config.yml to load becuz i want to make for players that want this plugin for /links many server dont have it and i have looked on the bukkit plugins and spigot plugins theres no plugin like this
     
  7. Offline

    Boomer

    Does that comment mean that you fixed the problems we pointed out? And do you have any further problems after fixing those?
     
  8. Offline

    killerxxsethxx

    Like theres no problem but the config.yml and the folder in the Plugins the folder does not show and the config.yml is not there

    @bwfcwalshy I dont no how do
    1. You don't need an enable message, Bukkit does it for you.
    2. Use saveDefaultConfig();
    3. You don't need an onDisable if you aren't using it.
    4. Check before casting
    5. cmd.getName not commandLabel
    6. Use ChatColor not §
    7. You could make it better by just putting the links in a list and going through the list and sending that
    Im still learning how to make plugins
     
    Last edited by a moderator: Jul 5, 2015
  9. Offline

    Boomer

    killer
    java is case sensitive
    wrong case for commands, or any expected things, does not work
    Take your plugin and run it on the server, and look at the server log
    Does it show the server loading the plugin okay, or does it show errors, or does it show nothing. Does it show the log message that your "OnEnable()" method has. You should see error, or no message that you specified there.

    Because case senstively th eplugin needs to be onEnable() to launch that code. No launching that code, no log message. Nothing else done with your code in those lines either. No config loaded.
    Fix that, then you're off and able to actually work from a working starting point to find problems to fix.

    His comment about "dont need log for startup message, bukkit does it" means just that - old old tutorials for plugins start up with adding a "look at my plugin starting to launch here is its name and version info" etc logger entry to the onEnable() because that was how they knew it loaded from the server. Bukkit changed that later and by default it adds "Loading plugin xyz version x" automatically, without need for a logger command now (which would just add a second such message unnecessarily . But in this case, you can use it to your advantage to see that your worded message never
    displays...

    onDisable -- unless you are performing cleanup of memory things and need to close open files, etc. just having a "i am disabling now" message is useless, as bukkit auto-adds that as well.

    Check-before-casting --> Dont cast sender with (Player) all the time - only do that if sender is an instanceof Player , otherwise, if the command is sent by a plugin, console, or command block it will trigger the code, and not be castable to a Player at all. It doesn't mean your code wont work - it is warning about bad practises that will cause errors at some time later when things happen not the way you expect them to happen.

    cmd.getName() not ...lable means, it is better to use cmd.getName() to check the command - lable was an old system.

    For best practices, use ChatColor not %wheatever symbol in the code means use ChatColor.RED ChatColor.YELLOW etc with your strings instead of %c and %d (where % is that symbol) -- its more readable, safer to use depending on how your java program will encode its saved files prevents odd side effects.
     
Thread Status:
Not open for further replies.

Share This Page