Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential crashes when using messages / path nodes #8

Closed
samolego opened this issue Apr 22, 2021 · 1 comment
Closed

Potential crashes when using messages / path nodes #8

samolego opened this issue Apr 22, 2021 · 1 comment

Comments

@samolego
Copy link
Owner

int msgPos = pl.getLastMsgPos();
if(this.npcData.messages.get(msgPos).getSecond() < pl.ticksSinceLastMessage()) {
entity.sendSystemMessage(
this.getName().copy().append(" -> you: ").append(this.npcData.messages.get(pl.getLastMsgPos()).getFirst()),
this.uuid
);
// Resetting message counter
pl.resetMessageTicks();
if(++msgPos >= this.npcData.messages.size())
msgPos = 0;
// Setting new message position
pl.setLastMsgPos(msgPos);

This part sets the next message index after message has been sent. If messages are cleared during the coolodown (while this.npcData.messages.get(msgPos).getSecond() < pl.ticksSinceLastMessage() is false), mod will crash with out of bounds exception.

Same can happen with path nodes.

Potential solution

this.world.getEntityCollisions(this, box, entity -> {
    if(entity instanceof ServerPlayerEntity && ((TaterzenEditor) entity).getEditorMode() != TaterzenEditor.Types.MESSAGES) {
        TaterzenPlayer pl = (TaterzenPlayer) entity;
        int msgPos = pl.getLastMsgPos();
+     if(msgPos > this.npcData.messages.size())
+        msgPos = 0;
        if(this.npcData.messages.get(msgPos).getSecond() < pl.ticksSinceLastMessage()) {
            entity.sendSystemMessage(
                    this.getName().copy().append(" -> you: ").append(this.npcData.messages.get(pl.getLastMsgPos()).getFirst()),
                    this.uuid
            );
            // Resetting message counter
            pl.resetMessageTicks();

-           if(++msgPos >= this.npcData.messages.size())
-               msgPos = 0;
            // Setting new message position
+          pl.setLastMsgPos(++msgPos);
-          pl.setLastMsgPos(msgPos);
        }
        return true;
    }
    return false;
});
@samolego
Copy link
Owner Author

Probably related to #2 as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant