Potential crashes when using messages / path nodes
samolego opened this issue ยท 1 comments
Taterzens/common/src/main/java/org/samo_lego/taterzens/npc/TaterzenNPC.java
Lines 334 to 346 in c3a4402
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;
});
Probably related to #2 as well