Skip to content

Commit

Permalink
Fixed detection of equal texture values being incorrect due to differ…
Browse files Browse the repository at this point in the history
…ent timestamps
  • Loading branch information
OmerBenGera committed Dec 25, 2022
1 parent c6a61f0 commit 48f440c
Showing 1 changed file with 16 additions and 5 deletions.
Expand Up @@ -164,11 +164,14 @@ public void setTextureValue(@Nonnull String textureValue) {

Log.debug(Debug.SET_TEXTURE_VALUE, getName(), textureValue);

if (Objects.equals(this.textureValue, textureValue))
return;

// We first update the texture value, even if they are equal.
this.textureValue = textureValue;

// We now compare them but remove the timestamp when comparing.
if (Objects.equals(removeTextureValueTimeStamp(this.textureValue), removeTextureValueTimeStamp(textureValue)))
return;

// We only save the value if it's actually different.
PlayersDatabaseBridge.saveTextureValue(this);
}

Expand Down Expand Up @@ -836,8 +839,8 @@ public void merge(SuperiorPlayer otherPlayer) {
// Convert data for missions
plugin.getMissions().convertPlayerData(otherPlayer, this);

PlayersDatabaseBridge.updatePlayer(this);
PlayersDatabaseBridge.deletePlayer(otherPlayer);
// Replace player in DB.
PlayersDatabaseBridge.replacePlayer(otherPlayer, this);
}

@Override
Expand Down Expand Up @@ -952,4 +955,12 @@ public String toString() {
"}";
}

private static String removeTextureValueTimeStamp(@Nullable String textureValue) {
// The texture value string is a json containing a timestamp value.
// However, when we compare texture values, we want to emit the timestamp value.
// This value is found at index 35->41 (6 chars in length).
Preconditions.checkState(textureValue == null || textureValue.length() > 42);
return textureValue == null ? null : textureValue.substring(0, 35) + textureValue.substring(42);
}

}

0 comments on commit 48f440c

Please sign in to comment.