-1

I'm trying to run a private server for the game RuneScape. After some time a player of mine went to a minigame I have programmed in the server named pestcontrol. The player tried to join it but in order to be able to start it he needs 5 other players in order for it to work. So, he logged out. But then after that his account got nulled which caused other people to get nulled too. I have managed to fix that. But then he was invisible, I couldn't see his character ingame. So then i worked it out by declaring the following:

if (player == null)
return;

This did work and made him visible again. But then the error still occurs with this line of exception:

java.lang.NullPointerException
at net.kagani.game.player.controllers.pestcontrol.PestControlLobby.forceClose(PestControlLobby.java:52)
at net.kagani.game.player.ControlerManager.forceStop(ControlerManager.java:317)
at net.kagani.game.player.ControlerManager.login(ControlerManager.java:66)
at net.kagani.game.player.Player.sendInit(Player.java:1396)
at net.kagani.game.player.Player.run(Player.java:1233)
at net.kagani.game.player.Player.start(Player.java:886)
at net.kagani.executor.PlayerHandlerThread.initPlayer(PlayerHandlerThread.java:273)
at net.kagani.executor.PlayerHandlerThread.processLoginSession(PlayerHandlerThread.java:231)
at net.kagani.executor.PlayerHandlerThread.run(PlayerHandlerThread.java:65)

If someone could help me out with this ( redirect me to it ) cause i am willing to learn alot. This is the class itself:

package net.kagani.game.player.controllers.pestcontrol;

import net.kagani.Settings;
import net.kagani.game.WorldObject;
import net.kagani.game.minigames.pest.Lander;
import net.kagani.game.player.controllers.Controller;
import net.kagani.utils.Utils;

public final class PestControlLobby extends Controller {
    private Lander lander;

    @Override
    public void start() {
        this.lander = Lander.getLanders()[(Integer) getArguments()[0]];
    }

    @Override
    public void sendInterfaces() {
        if (player == null)
            return;
        int remainingTime = lander.getTimer().getMinutes();
        player.getPackets().sendIComponentText(407, 3,
                Utils.fixChatMessage(lander.toString()));
        player.getPackets().sendIComponentText(
                407,
                13,
                "Next Departure: " + remainingTime + " minutes "
                        + (!(remainingTime % 2 == 0) ? " 30 seconds" : ""));
        player.getPackets().sendIComponentText(407, 14,
                "Player's Ready: " + lander.getByStanders().size());
        player.getPackets().sendIComponentText(407, 16,
                "Commendations: " + player.getCommendation());
        player.getInterfaceManager().sendMinigameInterface(407);
    }

    @Override
    public void magicTeleported(int teleType) {
        player.getControlerManager().forceStop();
    }

    @Override
    public boolean sendDeath() {
        player.getControlerManager().forceStop();
        return true;
    }

    @Override
    public void forceClose() {

        player.getInterfaceManager().removeMinigameInterface();
        System.err.println("This is 1 error output that declares it here");
        lander.exit(player);
    }

    @Override
    public boolean logout() {
        lander.remove(player);
        return false;
    }

    @Override
    public boolean canSummonFamiliar() {
        player.getPackets()
                .sendGameMessage(
                        "You feel it's best to keep your Familiar away during this game.");
        return false;
    }

    @Override
    public boolean processObjectClick1(WorldObject object) {
        switch (object.getId()) {
            case 14314:
            case 25629:
            case 25630:
                player.getDialogueManager().startDialogue("LanderD");
                return true;
        }
        return true;
    }
}
kevinsa5
  • 3,301
  • 2
  • 25
  • 28

1 Answers1

-1

player.getInterfaceManager() has not been initialized, and hence you're getting a NullPointerException when trying to close the game with forceClose (see the second line of your stack trace).

I would suggest wrapping player.getInterfaceManager() in a null check for the time being and then working out why this was null when you assumed it would be accessible.

I would suggest reading more on how to read stack traces so things like this you can pick up straight away.

Col Taylor
  • 11
  • 3