Can't fix a bug: TTT Map Voting problem

Discussion in 'Plugin Development' started by KayPIE, Feb 7, 2020.

  1. Offline

    KayPIE

    Hey Guys,
    I need help with a problem that I can't solve. For the first time, I try to programme a TTT Plugin for MC 1.13.
    I got this error message a few times and the plugin don't want's to work. I added the error message and the three methods that may are the problem to this thread. I think the mistake is the following line in the "initVoting"-Method: "for(String current : getConfig().getConfigurationSection("Arenas").getKeys(false))".

    I really hope you can help me and thanks for that in advance!

    Best regards
    Kay

    Error message (open)

    [23:27:37 INFO]: [TTT] Enabling TTT v1.0.0
    [23:27:37 ERROR]: Error occurred while enabling TTT v1.0.0 (Is it up to date?)
    java.lang.NullPointerException: null
    at de.kaypie.ttt.main.TTT.initVoting(TTT.java:61) ~[?:?]
    at de.kaypie.ttt.main.TTT.register(TTT.java:43) ~[?:?]
    at de.kaypie.ttt.main.TTT.onEnable(TTT.java:38) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:265) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:347) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:410) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugin(CraftServer.java:436) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugins(CraftServer.java:350) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.reload(CraftServer.java:809) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.Bukkit.reload(Bukkit.java:604) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:28) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchCommand(CraftServer.java:704) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchServerCommand(CraftServer.java:689) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at net.minecraft.server.v1_13_R2.DedicatedServer.handleCommandQueue(DedicatedServer.java:459) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:418) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:831) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:729) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
    at java.lang.Thread.run(Thread.java:834) [?:?]


    Register method (open)

    private void register(PluginManager pluginManager) {
    initVoting();
    roleManager = new RoleManager(this);
    gameProtectionListener = new GameProtectionListener(this);

    getCommand("setup").setExecutor(new SetupCommand(this));
    getCommand("start").setExecutor(new StartCommand(this));
    getCommand("build").setExecutor(new BuildCommand(this));

    pluginManager.registerEvents(new PlayerLobbyConnectionListener(this), this);
    pluginManager.registerEvents(new VotingListener(this), this);
    pluginManager.registerEvents(new GameProgressListener(this), this);
    pluginManager.registerEvents(new GameProtectionListener(this), this);
    pluginManager.registerEvents(new ChatListener(this), this);
    pluginManager.registerEvents(new ChestListener(this), this);
    }


    OnEnable method (open)

    public void onEnable() {
    this.prefix = Variables.PREFIX;
    gameStateManager = new GameStateManager(this);
    players = new ArrayList<>();

    gameStateManager.setGameState(GameState.LOBBY_STATE);

    register(Bukkit.getPluginManager());
    Bukkit.getConsoleSender().sendMessage(prefix + "§aDas Plugin wurde aktiviert.");
    }


    initVoting method (open)

    private void initVoting() {
    ArrayList<Map> maps = new ArrayList<>();
    for(String current : getConfig().getConfigurationSection("Arenas").getKeys(false)) {
    Map map = new Map(this, current);
    if(map.playable()) {
    maps.add(map);
    } else {
    Bukkit.getConsoleSender().sendMessage(prefix + "§4Die Map §6" + map.getName() + " §cist noch nicht fertig eingerichtet.");
    }
    }
    if(maps.size() >= Voting.MAP_AMOUNT) {
    voting = new Voting(this, maps);
    } else {
    Bukkit.getConsoleSender().sendMessage(Variables.PREFIX + "§cFür das Voting müssen mindestens §6" + Voting.MAP_AMOUNT + " §cMaps eingerichtet sein.");
    voting = null;
    }
    }
     
  2. Offline

    bowlerguy66

    @KayPIE When you try to get the configuration section from the config you're getting a null value either because the section doesn't exist in the config or there is a problem with loading your config file. I avoid this problem by adding a (configfile).contains("SectionName") before trying to access said configuration section.
     

Share This Page