Trying to make a config file for plugin and I fail every time :S

Discussion in 'Plugin Development' started by TechManDylan, Jul 18, 2012.

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

    TechManDylan

    Soo I have read and tryed several times at doing this, and every time I get sooo close but never quite get it if someone could help me get this working I would absolutely love them. I don't quite entirely understand Java but I'm trying :S anyways here is what I'm working with right now fairly simple only need a config for one option so nice first time thing lol.


    TheQuickeningMain

    Code:
    package me.TechManDylan.bukkit.TheQuickening;
     
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class TheQuickeningMain extends JavaPlugin {
        public void onEnable(){
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvents(new TheQuickeningListener(), this);
            pm.registerEvents(new TheQuickeningConfiguration(this), this);
        }
        public void onDisable(){
       
        }
    }
    
    TheQuickeningListener

    Code:
    package me.TechManDylan.bukkit.TheQuickening;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
     
    public class TheQuickeningListener implements Listener {
        @EventHandler(priority = EventPriority.NORMAL)
        public void getLvls(PlayerDeathEvent event) {
            Player p = event.getEntity();
            if (p.getKiller() instanceof Player) {
                int Plevel = p.getLevel() / 3;
                Math.floor(Plevel);
                if (Plevel < 1) {
                    // They don't get levels if it's under 1 :S
                } else {
                    int level = p.getKiller().getLevel() + Plevel;
                    p.getKiller().setLevel(level);
                    p.getKiller().sendMessage("You gained " + Plevel + " levels from killing "+ p.getDisplayName());
                    event.getEntity().getKiller().getWorld().strikeLightningEffect(p.getKiller().getLocation());
                    event.setDroppedExp(0);
                }
            }
        }
    }
    
    TheQuickeningConfiguration

    Code:
    package me.TechManDylan.bukkit.TheQuickening;
     
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.logging.Level;
     
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class TheQuickeningConfiguration implements Listener {
     
        TheQuickeningMain THC;
        public TheQuickeningConfiguration(TheQuickeningMain instance){
            this.THC = instance;
        }
     
        private FileConfiguration Config = null;
        private File ConfigFile = null;
     
        public void reloadConfig() {
            if (ConfigFile == null) {
                ConfigFile = new File(getDataFolder(), "config.yml");
            }
            Config = YamlConfiguration.loadConfiguration(ConfigFile);
     
            InputStream defConfigStream = this.getResource("config.yml");
            if (defConfigStream != null) {
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                Config.setDefaults(defConfig);
            }
        }
     
        public FileConfiguration getConfig() {
            if (Config == null) {
                this.reloadConfig();
            }
            return Config;
        }
     
        public void saveConfig() {
            if (Config == null || ConfigFile == null) {
                return;
            }
            try {
                getConfig().save(ConfigFile);
            } catch (IOException ex) {
                this.getLogger().log(Level.SEVERE, "Could not save config to " + ConfigFile, ex);
            }
        }
     
    }
    
    So tell me what kind of noob mistake I have made and then I will try to keep from doing it again :S
    and what I'm trying to do is get information into TheQuickeningListener to determine how many levels the player should get.
     
  2. Offline

    Icyene

    You should say WHAT isnt working as expected for people to be able to help you. Also, why are you registering events to configuration? That seems a bit pointless, but correct me if I'm wrong.
     
  3. Offline

    TechManDylan

    Oh :3 that might help well how I have it right now I get "The method is undefined for the type TheQuickeningConfiguration" from getDataFolder(), getResource, and getLogger which I know that measn it doesnt know what those methods are but I don't know how to fix it but aside from that after following the bukkit config tutorial I'm still unsure as to how this.getConfig() even works or how to use it in my Listener
     
  4. Offline

    Icyene

    getLogger requires class to extend javaplugin.... Just make your functions take a thequickeningmain a and use .getlogger on a.
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    You can access config.yml with the getConfig() on your instance of JavaPlugin, you do not need to write all this code. (copy and paste)
     
  6. Offline

    Dreeass

    Google 'Bukkit config.yml', on mobile atm., but there's all the info.
     
  7. Offline

    Sagacious_Zed Bukkit Docs

Thread Status:
Not open for further replies.

Share This Page