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

Add /sf dump command with blockstorage initially #3738

Closed
wants to merge 6 commits into from

Conversation

Sefiraat
Copy link
Member

@Sefiraat Sefiraat commented Jan 6, 2023

Description

Adds a new command /sf dump . This command just collects the blocks held in BlockStorage into a single file denoting the item ID and the amount held in storage.

Recently many servers have had issues with BlockStorage and a simple fix (for some) has been to show them just how many of a certain block they have to allow them to triage and tackle the amount. This has been very positive for servers with ExoticGarden where they have had upwards of millions of several of plants which, when they purged them, released a not insignificant amount of RAM.

Until now I have just offered this command as a separate JAR to server owners having issues and worked through the resolution with them but I think it makes sense to have the command here, regardless of the few use-cases.

Proposed changes

Add a new command that dumps contents into a file.

image

image

image

image

Related Issues (if applicable)

Checklist

  • I have fully tested the proposed changes and promise that they will not break everything into chaos.
  • I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
  • I have made sure that the proposed changes do not break compatibility across the supported Minecraft versions (1.14.* - 1.19.*).
  • I followed the existing code standards and didn't mess up the formatting.
  • I did my best to add documentation to any public classes or methods I added.
  • I have added Nonnull and Nullable annotations to my methods to indicate their behaviour for null values
  • I added sufficient Unit Tests to cover my code.

@Sefiraat Sefiraat requested a review from a team as a code owner January 6, 2023 14:35
Copy link
Member

@WalshyDev WalshyDev left a comment

Choose a reason for hiding this comment

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

I kinda feel like this should be under a dump command so we can add more to it...

@Sefiraat Sefiraat requested a review from WalshyDev January 6, 2023 17:58
@Sefiraat
Copy link
Member Author

Sefiraat commented Jan 6, 2023

I'm not a fan of the tab completer, but I think that thing may need some work in a separate PR, imo.

Copy link
Contributor

@J3fftw1 J3fftw1 left a comment

Choose a reason for hiding this comment

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

The file isnt stored in Slimefun right but in the folder Slimefun\
Also wouldnt a dump folder be even better?

@Sefiraat
Copy link
Member Author

Sefiraat commented Jan 6, 2023

The file isnt stored in Slimefun right but in the folder Slimefun
Also wouldnt a dump folder be even better?

Ah yeah it does make sense to have a dumps folder, and I think I’ll datetimestamp the file as well.

@J3fftw1
Copy link
Contributor

J3fftw1 commented Jan 6, 2023

The file isnt stored in Slimefun right but in the folder Slimefun
Also wouldnt a dump folder be even better?

Ah yeah it does make sense to have a dumps folder, and I think I’ll datetimestamp the file as well.

If you are making changes anyways, mind adding the date to the top of the file aswell it helps to see how recent the files are when people send them in pastebins

@Sefiraat
Copy link
Member Author

Sefiraat commented Jan 6, 2023

YARGH

J3fftw1
J3fftw1 previously approved these changes Jan 6, 2023
Copy link
Contributor

@J3fftw1 J3fftw1 left a comment

Choose a reason for hiding this comment

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

LGTM, even though me approving doesnt matter

@Sefiraat Sefiraat requested a review from svr333 January 6, 2023 19:35
@Sefiraat
Copy link
Member Author

Sefiraat commented Jan 7, 2023

All done :)

@TheBusyBiscuit TheBusyBiscuit added the 🎈 Feature This Pull Request adds a new feature. label Jan 7, 2023
Copy link
Member

@TheBusyBiscuit TheBusyBiscuit left a comment

Choose a reason for hiding this comment

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

Looks pretty good, I like it much better as a general /sf dump command that we can expand upon!

*/
class DumpCommand extends SubCommand {

private static final String PATH = Paths.get(Slimefun.instance().getDataFolder().getAbsolutePath(), "dumps").toString();
Copy link
Member

Choose a reason for hiding this comment

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

No reason for this to be static as this should be a singleton class.


@ParametersAreNonnullByDefault
private void createDump(CommandSender sender, String filePrefix, Supplier<List<String>> dump) {
String dateTimeStamp = new SimpleDateFormat("'_'yyyyMMddHHmm'.txt'").format(new Date());
Copy link
Member

Choose a reason for hiding this comment

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

Store the SimpleDateFormat as a class member, no need to instantiate it everytime.

}
}

private List<String> dumpBlockStorage() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private List<String> dumpBlockStorage() {
private @Nonnull List<String> dumpBlockStorage() {

@@ -39,6 +39,10 @@ commands:
running: '&7Running debug mode with test: &6%test%'
disabled: '&7Disabled debug mode.'

dump:
description: 'Contains commands to dump data to files'
Copy link
Member

Choose a reason for hiding this comment

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

Might want to specify that it is a dev/debug tool

Suggested change
description: 'Contains commands to dump data to files'
description: 'Debugging tool to dump data to files'

@Sefiraat Sefiraat changed the title Add /sf blockstorage command Add /sf dump command with blockstorage initially Jan 7, 2023
}

try (BufferedWriter writer = new BufferedWriter(new FileWriter(fullPath))) {
writer.write("Dump created at: " + dateTimeStamp + "\n");
Copy link
Member

Choose a reason for hiding this comment

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

Kinda weird to have Dump created at: _20220101.txt. This should probably be a more pretty date anyway


@ParametersAreNonnullByDefault
private void createDump(CommandSender sender, String filePrefix, Supplier<List<String>> dump) {
String dateTimeStamp = new SimpleDateFormat("'_'yyyyMMddHHmm'.txt'").format(new Date());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
String dateTimeStamp = new SimpleDateFormat("'_'yyyyMMddHHmm'.txt'").format(new Date());
String dateTimeStamp = new SimpleDateFormat("'_'yyyy-MM-dd-HH:mm'.txt'").format(new Date());

Readability.

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import java.nio.file.Path;

Path doesn't seem to be needed.

@TheBusyBiscuit TheBusyBiscuit added the ⏰ Waiting for response We are waiting for a response. label Mar 25, 2023
@J3fftw1 J3fftw1 added the Stale Marks a PR as stale. label Jul 29, 2023
@J3fftw1
Copy link
Contributor

J3fftw1 commented Jul 29, 2023

Messaged @Sefiraat privately if he still wants to work on it.
Closing it later if no response

@J3fftw1 J3fftw1 closed this Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎈 Feature This Pull Request adds a new feature. Stale Marks a PR as stale. ⏰ Waiting for response We are waiting for a response.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants