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

Multipaper #2343

Merged
merged 26 commits into from
May 5, 2024
Merged

Multipaper #2343

merged 26 commits into from
May 5, 2024

Conversation

tastybento
Copy link
Member

@tastybento tastybento commented Apr 20, 2024

This PR brings Multipaper compatibility to BentoBox. This should not affect servers running non-Multi paper.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Period database saving is no longer required because the database is updated continuously.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the quarantine island code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Team invites are now stored in a database instead of memory so that they can be accessed by any server.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new data object to store invites.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do explicit saves because new data is saved when written to the Players object

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Players are not cached anymore. If player data is needed, it is read from the database.

* Replace the island we have with this one
* @param newIsland island
*/
public void updateIsland(@NonNull Island newIsland) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces the previous "save" method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Islands are still cached, but if there is a change made to an island value, then it is communicated to all other servers so that they can load the new Island from the database and refresh their cache.

Copy link
Member Author

@tastybento tastybento Apr 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Island Grid was storing Island objects in its 2D map. Now it stores island IDs. This is better because it means that the data doesn't have to be updated if a cache update to refresh an Island. Island locations never change, but other Island data can change.

if (zEntry.containsKey(island.getMinZ())) {
// There is an overlap or duplicate
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of old defensive code has been removed. If it's required, it can be added again, but I don't think it's needed.

boolean removed = grid.values().stream()
.anyMatch(innerMap -> innerMap.values().removeIf(innerValue -> innerValue.equals(id)));

grid.values().removeIf(TreeMap::isEmpty);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This previous code was broken and not fully removing islands from the 2D map.

@@ -489,7 +489,7 @@ private PanelItem createBundleButton(ItemTemplateRecord template, BlueprintBundl
long uses = plugin.getIslands().getIslands(world, user).stream()
.filter(is -> is.getMetaData("bundle")
.map(mdv -> bundle.getDisplayName().equalsIgnoreCase(mdv.asString())
&& !(reset && is.isPrimary())) // If this is a reset, then ignore the use of the island being reset
&& !(reset && is.isPrimary(user.getUniqueId()))) // If this is a reset, then ignore the use of the island being reset
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a bug where the primary island record was not user specific.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of changes in this class for obvious reasons.

island.setMaxMembers(rank, islandMax == worldDefault ? null : islandMax);
this.save(island);
Integer change = islandMax == worldDefault ? null : islandMax;
if (island.getMaxMembers().get(rank) != change) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only make a change if a change is needed.

public void save(Island island) {
handler.saveObjectAsync(island);
public static void updateIsland(Island island) {
if (handler.objectExists(island.getUniqueId())) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between updateIsland and the old save is that this only updates an existing Island. It won't create a new database entry. This prevents async updates from regenerating Island objects that had been deleted.

@@ -56,7 +58,7 @@
public class Island implements DataObject, MetaDataAble {

@Expose
private boolean primary;
private Set<UUID> primaries = new HashSet<>();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a bug where the primary island flag was not specific to users and instead was global.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of this class has changed to update the database if and only if a value actually changes, so there are multiple checks of current data to see if it is different to newly written data.

Copy link

sonarcloud bot commented Apr 20, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@tastybento tastybento merged commit b1fe76c into develop May 5, 2024
1 check failed
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

Successfully merging this pull request may close these issues.

1 participant