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
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move to /sf dump, remove comment and make async
  • Loading branch information
Sefiraat committed Jan 6, 2023
commit 17f6089c6f339ed82b03e31906a54416333a55af
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String labe
// Returning null will make it fallback to the default arguments (all online players)
return null;
}
} else if (args[0].equalsIgnoreCase("dump")) {
// Only one option here for now, but preparing for further usages of /sf dump
List<String> suggestions = new LinkedList<>();
suggestions.add("blockstorage");
Sefiraat marked this conversation as resolved.
Show resolved Hide resolved

return createReturnList(suggestions, args[1]);
} else if (args.length == 4 && args[0].equalsIgnoreCase("give")) {
return createReturnList(Arrays.asList("1", "2", "4", "8", "16", "32", "64"), args[3]);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,56 @@ class BlockStorageCommand extends SubCommand {

@ParametersAreNonnullByDefault
BlockStorageCommand(Slimefun plugin, SlimefunCommand cmd) {
super(plugin, cmd, "blockstorage", false);
super(plugin, cmd, "dump", false);
}

@Override
protected String getDescription() {
return "commands.blockstorage.description";
return "commands.dump.description";
}

@Override
public void onExecute(CommandSender sender, String[] args) {
if (sender.hasPermission("slimefun.command.blockstorage") || sender instanceof ConsoleCommandSender) {
final Map<String, Integer> map = new LinkedHashMap<>();
for (World world : Bukkit.getWorlds()) {
for (Config value : BlockStorage.getRawStorage(world).values()) {
final String id = value.getString("id");
map.merge(id, 1, Integer::sum);
}
if (sender.hasPermission("slimefun.command.dump") || sender instanceof ConsoleCommandSender) {
String sub = args[1];
if (sub.equalsIgnoreCase("blockstorage")) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, task -> dumpBlockStorage(sender));
}
} else {
Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true);
}
}

private void dumpBlockStorage(CommandSender sender) {
final Map<String, Integer> map = new LinkedHashMap<>();
for (World world : Bukkit.getWorlds()) {
for (Config value : BlockStorage.getRawStorage(world).values()) {
final String id = value.getString("id");
map.merge(id, 1, Integer::sum);
}
}

final String path = Slimefun.instance().getDataFolder().getAbsolutePath();
final String path = Slimefun.instance().getDataFolder().getAbsolutePath();

try (BufferedWriter writer = new BufferedWriter(new FileWriter(path + "/BlockStorageSummary.txt"))) {
map.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEach(
entry -> {
final String message = entry.getKey() + " -> " + entry.getValue();
try {
writer.write(message + "\n");
} catch (IOException e) {
e.printStackTrace();
}
// sender.sendMessage(message);
try (BufferedWriter writer = new BufferedWriter(new FileWriter(path + "/blockstorage_dump.txt"))) {
map.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEach(
entry -> {
final String message = entry.getKey() + " -> " + entry.getValue();
try {
writer.write(message + "\n");
} catch (IOException e) {
e.printStackTrace();
}
);
Slimefun.getLocalization().sendMessage(
sender,
"commands.blockstorage.complete",
true,
msg -> msg.replace("%path%", path)
);
} catch (IOException e) {
e.printStackTrace();
}
} else {
Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true);
}
);
Slimefun.getLocalization().sendMessage(
sender,
"commands.dump.blockstorage.complete",
true,
msg -> msg.replace("%path%", path)
);
} catch (IOException e) {
e.printStackTrace();
}
}
}
7 changes: 4 additions & 3 deletions src/main/resources/languages/en/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ commands:
running: '&7Running debug mode with test: &6%test%'
disabled: '&7Disabled debug mode.'

blockstorage:
description: 'Collects and writes the contents of BlockStorage to a file'
complete: '&aAll blocks processed, file saved to: &6%path%'
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'

blockstorage:
complete: '&aAll blocks processed, file saved to: &6%path%'

placeholderapi:
profile-loading: 'Loading...'
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ permissions:
slimefun.command.debug:
description: Allows you to do /sf debug
default: op
slimefun.command.blockstorage:
description: Allows you to do /sf blockstorage
slimefun.command.dump:
description: Allows you to do /sf dump
default: op
slimefun.android.bypass:
description: Allows you to edit other Players Androids
Expand Down