Settingsmanager Config.

Discussion in 'Plugin Development' started by AlbkadDev, Feb 9, 2018.

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

    AlbkadDev

    So I am not getting this thing to work. It works when I apply it as a command. But not when I use it as an Event.

    Code:
        public void setFine(int amount, Player p) {
    
            if (fine.containsKey(p.getUniqueId())) {
                fine.put(p.getUniqueId(), fine.get(p.getUniqueId())+amount);
                getConfig().set("Fines." + p.getUniqueId().toString(), fine.get(p.getUniqueId()));
                saveConfig();
                return;
            }
    This code is in the settingsmanager with this code to set the config.

    Code:
        Main plugin;
    
      
        Plugin p;
        FileConfiguration config;
        File cfile;
      
        public void setup(Plugin p) {
            config = p.getConfig();
            config.options().copyDefaults(true);
            cfile = new File(p.getDataFolder(), "config.yml");
            saveConfig();
        }
      
        public FileConfiguration getConfig() {
            return config;
        }
      
        public void saveConfig() {
            try {
                config.save(cfile);
            }
            catch (IOException e) {
                Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save config.yml!");
            }
        }
    When I put this code into the eventhandler the event goes through but it doesnt set anything in the config. It gives me a nullpointererror at the line of the config setter in the first paragraph of code a bit up in here.


    Code:
    @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e) {
          
            for (String word : e.getMessage().split(" ")) {
              
                if (plugin.getConfig().getStringList("badwords").contains(word)) {
                    e.setCancelled(true);
                    e.getPlayer().sendMessage(ChatColor.DARK_RED + "You have just been fined 4$ for swearing in chat!");
                    f.setFine(4, e.getPlayer().getPlayer());
                    return;
                }
              
              
            }
          
        }
     
  2. Offline

    Machine Maker

    Are you running the setup() method in your onEnable()?
     
Thread Status:
Not open for further replies.

Share This Page