GabiJunkes / MultipleBedSpawn

A simple Minecraft plugin to allow players to choose which bed to respawn into.
GNU General Public License v3.0
9 stars 3 forks source link

Fixed /sharebed command completely #28

Closed DrunkRussianGun closed 8 months ago

DrunkRussianGun commented 8 months ago

Finally made /sharebed command to work properly (I thought #27 did, but testing showed it didn't). This pull request includes the following changes:

This time I tested the changes and I believe that I did that properly. At least works for me 🙂

GabiJunkes commented 8 months ago

Tested as well, all good. Just curious about serialVersionUID.

GabiJunkes commented 8 months ago

Also, can you bump the version to 1.9.2, in pom.xml.

DrunkRussianGun commented 8 months ago

Just curious about serialVersionUID.

This is related to built-in Java serialization which we use to store data about registered beds. That mechanism relies on serialVersionUID to check if stored data is compatible with the class which the data is deserialized into, and if calculated serialVersionUID doesn't match serialVersionUID stored along with the data, it throws InvalidClassException. Algorithm of serialVersionUID calculation is sensitive to what fields and methods a class has, and if we didn't set it explicitly, serialVersionUID of PlayerBedsData would change because I added a new constructor and a new method there. That would lead to InvalidClassException's in all servers which used version 1.9.1 of the plugin and decided to upgrade to 1.9.2, and those exceptions (which actually happened on my server where I tested early version of the changes), in turn, could lead to two scenarios depending on implementation details of Paper:

  1. Data about registered beds would be lost
  2. Or plugin would work for new players only until manual data migration (which we would have to make a separate tool for)

I haven't checked yet what happened to the data on my server, but neither of those scenarios is desirable, therefore we must set serialVersionUID explicitly for each class that is used for persistent data storage and has changes which may change its serialVersionUID.

You can also find another explanation here.

Also, can you bump the version to 1.9.2, in pom.xml.

Sure, done.