-
Notifications
You must be signed in to change notification settings - Fork 555
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
Conversation
There was a problem hiding this 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...
...n/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BlockStorageCommand.java
Outdated
Show resolved
Hide resolved
...n/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BlockStorageCommand.java
Outdated
Show resolved
Hide resolved
I'm not a fan of the tab completer, but I think that thing may need some work in a separate PR, imo. |
There was a problem hiding this 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?
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 |
YARGH |
There was a problem hiding this 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
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DumpCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DumpCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DumpCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DumpCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/DumpCommand.java
Show resolved
Hide resolved
All done :) |
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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' |
There was a problem hiding this comment.
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
description: 'Contains commands to dump data to files' | |
description: 'Debugging tool to dump data to files' |
} | ||
|
||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fullPath))) { | ||
writer.write("Dump created at: " + dateTimeStamp + "\n"); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import java.nio.file.Path; |
Path doesn't seem to be needed.
Messaged @Sefiraat privately if he still wants to work on it. |
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.
Related Issues (if applicable)
Checklist
Nonnull
andNullable
annotations to my methods to indicate their behaviour for null values