Skip to content

Commit

Permalink
Remove data saving on server shutdown.
Browse files Browse the repository at this point in the history
Data is saved upon change.
  • Loading branch information
BONNe committed Feb 3, 2022
1 parent b4019a5 commit 0728556
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,6 @@ private void findLevel()
public void onDisable()
{
// Do some stuff...

if (this.hooked)
{
// Save database on disable.
this.getAddonManager().save();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private PanelItem createButton(Button button)
{
if (value != null) {
this.bundle.setFriendlyName(value);
this.manager.saveGeneratorBundle(this.bundle);
this.save();
}

this.build();
Expand Down Expand Up @@ -236,6 +236,7 @@ private PanelItem createButton(Button button)
// TODO: implement GUI for block selection
this.isIconSelected = !this.isIconSelected;
panel.getInventory().setItem(i, this.createButton(button).getItem());
this.save();

return true;
};
Expand All @@ -261,7 +262,7 @@ private PanelItem createButton(Button button)
{
if (value != null) {
this.bundle.setDescription(value);
this.manager.saveGeneratorBundle(this.bundle);
this.save();
}

this.build();
Expand Down Expand Up @@ -378,10 +379,11 @@ private PanelItem createButton(Action button)

// Add all selected generators to the current bundle
this.selectedGenerators.forEach(generator ->
this.bundle.getGeneratorTiers().add(generator.getUniqueId()));
this.bundle.getGeneratorTiers().add(generator.getUniqueId()));

// clear selected generator list.
this.selectedGenerators.clear();
this.save();
}

this.build();
Expand Down Expand Up @@ -413,6 +415,7 @@ private PanelItem createButton(Action button)

// clear selected generator list.
this.selectedGenerators.clear();
this.save();
this.build();
}

Expand Down Expand Up @@ -507,6 +510,15 @@ protected List<String> generateGeneratorDescription(GeneratorTierObject generato
}


/**
* This method saves generator bundle when change is detected.
*/
private void save()
{
this.addon.getAddonManager().saveGeneratorBundle(this.bundle);
}


/**
* This method is used to open UserPanel outside this class. It will be much easier to open panel with single method
* call then initializing new object.
Expand Down Expand Up @@ -550,7 +562,7 @@ public void onInventoryClick(User user, InventoryClickEvent event)
// set material and amount only. Other data should be removed.
BundleEditPanel.this.bundle.setGeneratorIcon(event.getCurrentItem().clone());
// save change
BundleEditPanel.this.manager.saveGeneratorBundle(BundleEditPanel.this.bundle);
BundleEditPanel.this.save();
// Deselect icon
BundleEditPanel.this.isIconSelected = false;

Expand Down

0 comments on commit 0728556

Please sign in to comment.