Error on server start

Hey,
I wrote my own plugin and everything was ok. Today I started my server and it gave me following error:

    [16:16:48] [Server thread/ERROR] [Sponge]: [Plugin Class: me.Hitzk0pf.CaveAccounts.Main][Handler: onServerInitialize]
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.spongepowered.mod.plugin.SpongeModPluginContainer.handleModStateEvent(SpongeModPluginContainer.java:126) [SpongeModPluginContainer.class:1.8-1499-2.1DEV-584+unknown-b584.git-unknown]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [minecraft_server.1.8.jar:?]
        at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [minecraft_server.1.8.jar:?]
        at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [minecraft_server.1.8.jar:?]
        at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [minecraft_server.1.8.jar:?]
        at com.google.common.eventbus.EventBus.post(EventBus.java:275) [minecraft_server.1.8.jar:?]
        at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212) [LoadController.class:?]
        at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190) [LoadController.class:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [minecraft_server.1.8.jar:?]
        at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [minecraft_server.1.8.jar:?]
        at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [minecraft_server.1.8.jar:?]
        at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [minecraft_server.1.8.jar:?]
        at com.google.common.eventbus.EventBus.post(EventBus.java:275) [minecraft_server.1.8.jar:?]
        at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119) [LoadController.class:?]
        at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:731) [Loader.class:?]
        at net.minecraftforge.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:97) [FMLServerHandler.class:?]
        at net.minecraftforge.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:360) [FMLCommonHandler.class:?]
        at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:210) [po.class:?]
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:438) [MinecraftServer.class:?]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
Caused by: java.lang.NoSuchMethodError: ninja.leaping.configurate.hocon.HoconConfigurationLoader$Builder.setFile(Ljava/io/File;)Lninja/leaping/configurate/hocon/HoconConfigurationLoader$Builder;
        at me.Hitzk0pf.CaveAccounts.obj.tools.ConfigurationManager.getFile(ConfigurationManager.java:22) ~[ConfigurationManager.class:?]
        at me.Hitzk0pf.CaveAccounts.Main.configurationDefaults(Main.java:128) ~[Main.class:?]
        at me.Hitzk0pf.CaveAccounts.Main.onServerInitialize(Main.java:67) ~[Main.class:?]
        ... 32 more

Strange thing is, that the plugin creates its folder and config file in /config folder, but when I want to use it in game (by command) sponge just responses “unkown command…”

Hope you can help me with my error.
Greets

Be sure to build against the version of SpongeAPI your server is running.
The exception is caused by java not finding the setFile method of the HoconConfigurationLoader.Builder, so it has likely changed.

1 Like

Do you mean this:
import me.Hitzk0pf.CaveAccounts.obj.tools.ConfigurationManager;
the location is right ?
When i’m wrong, what do I have to change ? (Sorry, I’m new when it comes to Java & Sponge…)

Try refreshing your dependencies, and make sure you are using the latest Sponge build.

I did… I downloaded the latest SpongeAPI. Is there a function in Intelliji, which refreshes all my dependencies ?
Greets :slight_smile:

I don’t use IntelliJ, but I found an answer on StackOverflow.

I just found a function (STRG + SHIFT + A) -> reimport which refreshes all my maven dependencies. Error is still there…

I think you want me to check for new builds of hocon, don’t you ??

It looks that hasn’t been updated for 13 days, could you post your source code?

Main class:

 package me.Hitzk0pf.CaveAccounts;

import java.io.File;
import java.io.IOException;

import me.Hitzk0pf.CaveAccounts.Commands.AccountCommand;
import me.Hitzk0pf.CaveAccounts.Commands.HomeCommand;
import me.Hitzk0pf.CaveAccounts.Commands.KontoCommand;
import me.Hitzk0pf.CaveAccounts.obj.tools.ConfigurationManager;
import me.Hitzk0pf.CaveAccounts.obj.tools.HomeManager;
import me.Hitzk0pf.CaveAccounts.obj.tools.UserManager;
import ninja.leaping.configurate.ConfigurationNode;

import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.event.Subscribe;
import org.spongepowered.api.event.state.InitializationEvent;
import org.spongepowered.api.event.state.ServerStartedEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.service.sql.SqlService;

import com.google.common.base.Optional;
import com.google.inject.Inject;

@Plugin(id = "CaveAccounts", name = "CaveAccounts", version = "0.0.1")
public class Main {

    @Inject
    private Logger logger;

    @Inject
    private Game game;
    private AccountCommand AccountCommand;
    private HomeCommand HomeCommand;
    private KontoCommand KontoCommand;

    private static String group = "";
    private static String hostname = "";
    private static String port = "";
    private static String database = "";
    private static String username = "";
    private static String password = "";
    private static String moneyName = "";
    private static UserManager userManager;
    private static HomeManager homeManager;

    public Game getGame(InitializationEvent event) {
        return event.getGame();
    }

    @Subscribe
    public void onInit(InitializationEvent event) {
        this.AccountCommand = new AccountCommand(logger, this.game);
        this.HomeCommand = new HomeCommand(logger, this.game);
        this.KontoCommand = new KontoCommand(logger, this.game);
    }

    public Game getGame() {
        return this.game;
    }

    @Subscribe
    public void onServerInitialize(InitializationEvent event) {
        logger.info("CaveAccounts by Hitzk0pf initializing!");

        createFiles();
        configurationDefaults();
        loadOptions();

        event.getGame().getEventManager().register(this, new PlayerJoin(logger));

        event.getGame().getCommandDispatcher().register(this, new AccountCommand(logger, getGame()), "account");
        event.getGame().getCommandDispatcher().register(this, new HomeCommand(logger, getGame()), "home");
        event.getGame().getCommandDispatcher().register(this, new KontoCommand(logger, getGame()), "konto");

        Optional<SqlService> sqlServiceOptional = event.getGame().getServiceManager().provide(SqlService.class);

        //logger.info("MySQL Storage Enabled...");
        userManager = new UserManager(hostname, port, database, username, password, logger, sqlServiceOptional.get());
        homeManager = new HomeManager(hostname, port, database, username, password, logger, sqlServiceOptional.get());
    }

    /*
    @Subscribe
    public void onServerStart(ServerStartedEvent event) {
        //logger.info("CaveAccounts by Hitzk0pf enabled: ");
    }
    */

    private void createFiles() {
        //Create EconomyLite folder if doesn't exist
        File folder = new File("config/CaveAccounts");
        try {
            if (!folder.exists()) {
                logger.info("Erstelle Ordner");
                if (folder.mkdir()) {
                    logger.info("Ordner wurde erstellt");
                } else {
                    logger.warn("Ordner konnte nicht erstellt werden");
                }

            }
        } catch (Exception e) {
            logger.warn("Ordner konnte nicht erstellt werden:");
            logger.warn(e.getMessage());
            logger.warn("ENDE DES ERRORS");
        }

        //Configuration file
        File conf = new File("config/CaveAccounts/config.conf");
        if (!conf.exists()) {
            logger.info("Config-Datei nicht gefunden...");
            try {
                conf.createNewFile();
                logger.info("Config-Datei wurde erstellt!");
            } catch (IOException e) {
                logger.error("Config-Datei konnte nicht erstellt werden.");
                e.printStackTrace();
            }
        }

    }

    private void configurationDefaults() {
        //Check if file contains configuration options
        ConfigurationManager manager = new ConfigurationManager(logger);

        ConfigurationNode root = manager.getFile();

        if (root != null) {
            //Check all MySQL child nodes
            if (!root.getNode("MySQL").getChildrenMap().containsKey("hostname")) {
                root.getNode("MySQL").getNode("hostname").setValue("localhost");
            }
            if (!root.getNode("MySQL").getChildrenMap().containsKey("port")) {
                root.getNode("MySQL").getNode("port").setValue("3306");
            }
            if (!root.getNode("MySQL").getChildrenMap().containsKey("database")) {
                root.getNode("MySQL").getNode("database").setValue("thecave");
            }
            if (!root.getNode("MySQL").getChildrenMap().containsKey("username")) {
                root.getNode("MySQL").getNode("username").setValue("root");
            }
            if (!root.getNode("MySQL").getChildrenMap().containsKey("password")) {
                root.getNode("MySQL").getNode("password").setValue("");
            }
            if (!root.getChildrenMap().containsKey("Promote-Group")) {
                root.getNode("Promote-Group").setValue("Spieler");
            }
            if (!root.getChildrenMap().containsKey("Currency-Name")) {
                root.getNode("Currency-Name").setValue("Pfund");
            }
            manager.saveFile(root);
        }
    }

    private void loadOptions() {
        logger.info("Loading configuration options into memory...");
        ConfigurationManager manager = new ConfigurationManager(logger);

        ConfigurationNode root = manager.getFile();

        if (root != null) {
            if (root.getChildrenMap().containsKey("MySQL")) {
                if (root.getNode("MySQL").getChildrenMap().containsKey("hostname")) {
                    hostname = root.getNode("MySQL").getNode("hostname").getString();
                }
                if (root.getNode("MySQL").getChildrenMap().containsKey("port")) {
                    port = root.getNode("MySQL").getNode("port").getString();
                }
                if (root.getNode("MySQL").getChildrenMap().containsKey("database")) {
                    database = root.getNode("MySQL").getNode("database").getString();
                }
                if (root.getNode("MySQL").getChildrenMap().containsKey("username")) {
                    username = root.getNode("MySQL").getNode("username").getString();
                }
                if (root.getNode("MySQL").getChildrenMap().containsKey("password")) {
                    password = root.getNode("MySQL").getNode("password").getString();
                }
            }
            if (root.getChildrenMap().containsKey("Promote-Group")) {
                group = root.getNode("Promote-Group").getString();
            }
            if (root.getChildrenMap().containsKey("Currency-Name")) {
                moneyName = root.getNode("Currency-Name").getString();
            }
        }
    }

    public static UserManager getUserManager() {
        return userManager;
    }

    public static HomeManager getHomeManager() {
        return homeManager;
    }

    public static String getGroup() {
        return group;
    }

    public static String getMoneyName() {
        return moneyName;
    }
}

Configuration Manager Class:

package me.Hitzk0pf.CaveAccounts.obj.tools;

import java.io.File;
import java.io.IOException;

import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader;

import org.slf4j.Logger;

public class ConfigurationManager {

private Logger logger;

public ConfigurationManager(Logger log){
	this.logger = log;
}

public ConfigurationNode getFile(){
	ConfigurationLoader<?> manager = HoconConfigurationLoader.builder().setFile(new File("config/CaveAccounts/config.conf")).build();
	ConfigurationNode root;	
	try {
		root = manager.load();
	} catch (IOException e) {
		logger.error("Config konnte nicht geladen werden!");
		logger.error(e.getMessage());
		return null;
	}
	return root;
}

public void saveFile(ConfigurationNode root){
	ConfigurationLoader<?> manager = HoconConfigurationLoader.builder().setFile(new File("config/CaveAccounts/config.conf")).build();
	
	try {
		manager.save(root);
	} catch (IOException e) {
		logger.error("Config konnte nicht gespeichert werden!");
		logger.error(e.getMessage());
	}
}
}

I hope this is enough, because the Error is on Server start, so the problem must be in one of both classes…

After you refresh your dependencies, do you rebuild the plugin? Make sure that running the latest version of your source code.

Yes I do / I did it soooo often…
Could it be, that Java / Forge causes the problem?
Greets

I believe he means you have to be running the latest Sponge build and make sure your API dependency is refreshed completely.