#I m currently debugging

1 messages · Page 1 of 1 (latest)

near owl
#
    private void resetVariables() {
        killCount = 0;
        spawnedCount = 0;
        bossBar.setProgress(0);
        currentLevel++;
        mythicMob = null;

    }
quiet path
#

is resetVariables, meant to set the state

near owl
#

@quiet path I show what is does

#

resetVariables doesn't set the state

quiet path
#

by chance

#

is state final

near owl
#

negativo

#

It changes from waiting to resetting but then refuses to go back

quiet path
#

sysout something after you set the state

near owl
#

Adding that rn

#

Ummmm seems like resetVariables is never getting called?

quiet path
#

whats isEnabled

#

im gonna take a guess that that is always false

near owl
#

Always true

#

Haven't set it anywhere

#
    public boolean isEnabled() {
        return isEnabled;
    }
quiet path
#

are you setting it to start with

near owl
#

Constructor as true and haven't implementing disabling the game yet

#

intellij says no usages on set so

#

Adding some more sysout

#

I shall inform a infinite loop is happening somewhere

quiet path
#

that will be because its a runTaskTimer

#

it runs until the cancel gets called

near owl
#

But that's fine no?

#

I mean

#
                    case RESETTING:
                        Bukkit.getLogger().info("Trying to reset dungeon " + (dungeonGameID) + "...");
                        ChatManager.sendMessage(player, "The dungeon is resetting!");
                        currentLevel = 1;
                        state = State.WAITING;
                        resetVariables();
                        Bukkit.getLogger().info("Dungeon " + (dungeonGameID) + " has been reset!");

                        break;
#

None of that is ever getting called

quiet path
#

state never changes then

near owl
#

It does

#

From waiting to resetting

quiet path
#

force the state to be RESETTING, see if it runs

near owl
#

I made another runtask that's checking the state

#

It's waiting until I leave

#
    public void removePlayer(Player player) {
        DungeonPlayer dungeonPlayer = getDungeonPlayerByPlayer(player);

        if (dungeonPlayer == leader) {
            players.remove(dungeonPlayer);
            if (players.size() == 0) {
                state = State.RESETTING;
                        <-------------------- added sysout here. it works and only once
                return;
            }
            leader = players.get(0);
            messagePlayers("&4The leader has left the dungeon!");
            messagePlayers("&4The new leader is " + leader.getPlayer().getName() + "!");
        }
    }
#

Then goes to resetting

quiet path
#

add a sout on all occasions you set the state

near owl
#

I'm legit joining, doesn't change, and leaving changes in that method

quiet path
#

its either not getting set to waiting or its getting set the resetting constantly

near owl
#

Checking all resetting states

#

Wait even if

#

It was getting reset constaly

near owl
#

Not a single time

quiet path
#

the state in one case is waiting, so running waiting code, but by the time you sysout state its back to resetting

near owl
#

hmmm

#

What if I make that task a bit longer

#

and my getstate task 1tick

quiet path
#

might crash if you leave it running too long

near owl
#

For science

#

Kinda desperate at this point

#

@quiet path yeah no wtf

#

I made the one that prints it 1tick and the one that's in the actual game 30ticks

#

is tasktimerAsync?

quiet path
#

shouldnt be

near owl
#

what is happening

quiet path
#

ive got no idea, im gonna guess somehow its constantly running something

#

without full source code idk where or what would do that

near owl
#

I'll post this file here

#

Yeah no there's only 10 times the state gets set to resetting. and none of them are in a loop and none of them can repeat

#

The fact that it never even reaches the code for resetting anyways is crazy to me

#

yeah no wtf

quiet path
#

there is so much going on in that one class i cant even tell what half of it does or how it even works

near owl
#

Well you guys said to put the gamelogic in 1 place lol but either way

#

Unless im dumb. That first runnable task is repeating itself forever, correct?

quiet path
#

the activateDungeon one will run until isEnable is false

near owl
#

If that's the case then why isn't it even going to the resetting case for the switch

#

I'll send the start state to resetting and see what happens rq

quiet path
#

ive found one of the issues

near owl
#

OK

quiet path
#

on case ENDING and PAUSE on activate dungeon, it never breaks if player size doesnt equal 0

near owl
#

That would just make the loop run 1 more time

#
                        case ENDING:
                            ChatManager.sendMessage(player, "The dungeon is ending!");
                            if (players.size() == 0) {
                                state = State.RESETTING;
                                break; < -------------
                            }
                            getPlayers().forEach(dungeonPlayer -> {
                                dungeonPlayer.getPlayer().setGameMode(GameMode.SURVIVAL);
                                dungeonPlayer.getPlayer().teleport(Bukkit.getWorld("spawn").getSpawnLocation());
                                removePlayer(dungeonPlayer.getPlayer());
                                TitleManager.sendTitleWithPrefix(dungeonPlayer.getPlayer(), "Resetting, You have been teleported to spawn!");
                            });
                            getSpectators().forEach(dungeonSpectator -> {
                                dungeonSpectator.getPlayer().setGameMode(GameMode.SURVIVAL);
                                dungeonSpectator.getPlayer().teleport(Bukkit.getWorld("spawn").getSpawnLocation());
                                removeSpectator(dungeonSpectator.getPlayer());
                            });
                            break;    < -------------
#
                        case PAUSE:
                            if (players.size() == 0) {
                                state = State.RESETTING;
                                break;   < -------------
                            }
                            titlePlayers("&2&l/dm next &rto continue!", "Waiting for &2&lleader to resume the dungeon!");
                            break;   < -------------
quiet path
#

oh lmao

near owl
#

Bro

#

For a second

#

I thought I was having a mental collapse

quiet path
#

i can barely even tell where half of these methods are ending, others starts

near owl
#

So sort of like this

#

btw

#

80% isn't even getting called

#

Cause I'm just joining and leaving

#

Not even going through the logic

#
    public void addPlayer(DungeonGame gameHandler, Player player) {
        players.add(new DungeonPlayer(player));
        if (players.size() == 1) {
            gameHandler.setLeader(players.get(0));
        }
    }

gets called from command to add player

#
    public void removePlayer(Player player) {
        DungeonPlayer dungeonPlayer = getDungeonPlayerByPlayer(player);

        if (dungeonPlayer == leader) {
            players.remove(dungeonPlayer);
            if (players.size() == 0) {
                state = State.RESETTING;
                System.out.println("Leader left, no more players in dungeon, resetting dungeon");
                return;
            }
            leader = players.get(0);
            messagePlayers("&4The leader has left the dungeon!");
            messagePlayers("&4The new leader is " + leader.getPlayer().getName() + "!");

        }
    }
``` gets called from command to remove player
#

omg

#

I'm gonna kms

#

Well that's dumb of me

near owl
near owl
#

EDIT:
Is the correct way around this to initialize the main gamestate in a taskTimer from the constructor itself so that way the function containing the logic will be called over and over?

#
public void activateDungeon () {

                    switch (state) {
                        case WAITING:
                            messagePlayers("The dungeon is waiting for players!");
                            setWorldBorder();
                            break;
                        case STARTING:
                            break;
                        case IN_PROGRESS:

``` etc etc etc etc
#
        new BukkitRunnable() {
            @Override
            public void run() {
                //System.out.println("Dungeon " + (dungeonGameID) + " is " + state.toString() + "!");
                if (!isEnabled()) {
                    return;
                }
                activateDungeon();
            }
        }.runTaskTimer(plugin, 0, 10);

In the constructor

vital kayak
#

I think the timer just got out of scope, if its the only timer consider making it a member variable

near owl
#

Is what I did above bad practice tho?

vital kayak
#

but im not sure how gc wotks in java

near owl
#

Because before I had it like this

#
    public void activateDungeon(Player player) {
        new BukkitRunnable() {
            @Override
            public void run() {
                if (!isEnabled()) {
                    ChatManager.sendMessage(player, "This dungeon is not enabled!");
                    cancel();
                    return;
                }
                switch (state) {
                    case WAITING:
                        ChatManager.sendMessage(player, "The dungeon is waiting for players!");

                        setWorldBorder();
                        break;
                    case RESETTING:
                        ChatManager.sendMessage(player, "The dungeon is resetting!");
                        currentLevel = 1;
                        resetVariables();
                        state = State.WAITING;

                        break;

                }
            }
        }.runTaskTimer(plugin, 10, 10);
    }