Config problems

Discussion in 'Plugin Development' started by VortexGmer, Mar 20, 2015.

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

    VortexGmer

    Hi,
    I have some Config problems,
    I'm trying to get 3 ints from the config, on named Cooldown, One named Fly Time, and one named Broom Slot.
    When I make my plugin the config.yml is the same place as the plugin yml and has all the defaults there. Then when the plugin runs the config gets cleared except for the 3 lines before the first int. this is all my config related code.
    Code:
    //In my onenable
    getConfig().getDefaults();
            saveConfig();
    //In a Listener class
    
        int ft = plugin.getConfig().getInt("Fly Time");
        int cd = plugin.getConfig().getInt("Cooldown");
        int slot = plugin.getConfig().getInt("Broom Slot");
    
    Is there anything wrong I am doing? thanks in advance
     
  2. Offline

    Monkey_Swag

    If you're creating the config in your same place as your plugin.yml, you need to use JavaPlugin#saveDefaultConfig();
    Hope this helped :)
     
  3. Offline

    VortexGmer

    AAND Yay the config doesnt even generate now!
     
  4. Offline

    Monkey_Swag

  5. Offline

    VortexGmer

    here
    Code:
    package me.VortexGamer.lobbybroom;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class LobbyBroom extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static LobbyBroom plugin;
        public final MyPlayerListener pl = new MyPlayerListener();
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + ChatColor.RED
                    + " Has Been Disabled!");
        }
    
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version" + pdfFile.getVersion()
                    + " Has Been Enabled!");
            PluginManager pm = getServer().getPluginManager();
            getConfig().getDefaults();
            saveDefaultConfig();
            pm.registerEvents(this.pl, this);
            getServer()
            .getScheduler()
            .scheduleSyncRepeatingTask(this, new Runnable(){
                public void run() {
                    for(Player p: Bukkit.getOnlinePlayers()){
                        if(pl.flytime.containsKey(p.getName()) && pl.flytime.get(p.getName()) > 0){
                            int i = pl.flytime.get(p.getName());
                            i--;
                            pl.flytime.replace(p.getName(), i);
                        }else{
                            p.setAllowFlight(false);
                        }
                        if(pl.timer.containsKey(p.getName()) && pl.timer.get(p.getName()) > 0){
                            int i = pl.timer.get(p.getName());
                            i--;
                            pl.timer.replace(p.getName(), i);
                        }else{
                            p.setAllowFlight(false);
                        }
                    }
                }
            }, 20l, 20l);
        }
       
    
    }
    
    and here
    Code:
    package me.VortexGamer.lobbybroom;
    
    import java.util.HashMap;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class MyPlayerListener implements Listener{
        public static LobbyBroom plugin;
        public HashMap<String,Integer> timer = new HashMap<String,Integer>();
        public HashMap<String,Integer> flytime = new HashMap<String,Integer>();
        int ft = plugin.getConfig().getInt("Fly Time");
        int cd = plugin.getConfig().getInt("Cooldown");
        int slot = plugin.getConfig().getInt("Broom Slot");
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
            ItemStack wheat = new ItemStack(Material.WHEAT);
            ItemMeta im = wheat.getItemMeta();
            im.setDisplayName(ChatColor.GOLD + "Broom");
            wheat.setItemMeta(im);
            event.getPlayer().getInventory().setItem(slot,wheat);
            event.getPlayer().updateInventory();
            timer.put(event.getPlayer().getName(), 0);
        }
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent event){
            timer.remove(event.getPlayer().getName());
            flytime.remove(event.getPlayer().getName());
        }
        @EventHandler
        public void onInteract(PlayerInteractEvent event){
            ItemStack is = event.getPlayer().getItemInHand();
            Player p = event.getPlayer();
            if(event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.WHEAT){
                if(is.hasItemMeta()){
                    if(timer.get(p.getName()) != null && timer.get(p.getName()) == 0){
                        flytime.put(p.getName(), ft);
                        timer.replace(p.getName(), cd);
                        p.sendMessage(ChatColor.GOLD + "You can now fly!");
                        p.setAllowFlight(true);
                    }
                    else{
                        p.sendMessage(ChatColor.RED + "Wait " + timer.get(p.getName()) + " seconds to use the broom!");
                    }
                }
                else{
                    return;
                }
               
            } else {
                return;
            }
        }
    }
    
     
  6. Remove getConfig().getDefaults();
     
  7. Offline

    VortexGmer

    The config isnt generating anymore!
    @FisheyLP @Monkey_Swag
     
    Last edited: Mar 20, 2015
  8. Last edited: Mar 20, 2015
  9. Offline

    VortexGmer

  10. 1. Do you get any errors in the console?
    2. Where do you put the config.yml in your ide? (in the package, project itself or somewhere else?
     
  11. Offline

    VortexGmer

    No Errors in console, In same directory as plugin.yml
     
  12. ...And where is your plugin.yml /_.

    Try to delete the plugin folder in
    plugins/YourPluginName
    And reload the server
     
  13. Offline

    VortexGmer

    LobbyBrooms ->plugin.yml
    @FisheyLP
     
    Last edited: Mar 20, 2015
  14. Offline

    Monkey_Swag

  15. Offline

    VortexGmer

    Last edited by a moderator: Jun 13, 2016
  16. Offline

    Monkey_Swag

    @VortexGmer fix your code. You have so much stuff that you don't need.
    Remove lines 25-27, 17-21, and this:
    Code:
     public final Logger logger = Logger.getLogger("Minecraft");
        public static LobbyBroom plugin;
     
    FisheyLP likes this.
  17. @VortexGmer additional to what he said, read this: https://bukkit.org/threads/77899
     
  18. Offline

    VortexGmer

    Why? And this is not related to my config problem
     
  19. Offline

    nverdier

    @VortexGmer I'm going to list things you should fix with your code:
    1. Don't steal Minecraft's Logger.
    2. No need for the static instance of the class.
    3. No need to log onEnable/onDisable messages; Bukkit already does this for you.
    Just a start.
     
    CodePlaysMinecraft likes this.
  20. Offline

    VortexGmer

    Ok I did that... Now what?

    Up, Now I'm in Japan do timing will be weird
     
    Last edited by a moderator: Mar 26, 2015
Thread Status:
Not open for further replies.

Share This Page