Moves another file loading related function to the FileHelper class

This commit is contained in:
2021-09-02 20:46:37 +02:00
parent 1b8965ace3
commit c39fd7d7db
9 changed files with 62 additions and 40 deletions

View File

@@ -18,8 +18,6 @@ import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getS
*/
public class CommandDelete implements CommandExecutor {
private final BooksWithoutBorders booksWithoutBorders = BooksWithoutBorders.getInstance();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
@@ -41,7 +39,7 @@ public class CommandDelete implements CommandExecutor {
boolean deleteBook(CommandSender sender, String[] args, boolean deletePublic) {
//List deletable files
if (args.length == 0) {
BooksWithoutBorders.loadList.put(sender.getName(), booksWithoutBorders.listFiles(sender, deletePublic, false));
BooksWithoutBorders.loadList.put(sender.getName(), FileHelper.listFiles(sender, deletePublic, false));
return true;
}
//Delete the file

View File

@@ -1,6 +1,7 @@
package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.utility.FileHelper;
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -32,7 +33,7 @@ public class CommandGive implements CommandExecutor {
}
if (args.length == 0) {
BooksWithoutBorders.loadList.put(sender.getName(), booksWithoutBorders.listFiles(sender, givePublic, false));
BooksWithoutBorders.loadList.put(sender.getName(), FileHelper.listFiles(sender, givePublic, false));
return true;
}
@@ -55,7 +56,7 @@ public class CommandGive implements CommandExecutor {
//Load books available to the player
try {
Integer.parseInt(bookIdentifier);
BooksWithoutBorders.loadList.put(sender.getName(), booksWithoutBorders.listFiles(sender, givePublic, true));
BooksWithoutBorders.loadList.put(sender.getName(), FileHelper.listFiles(sender, givePublic, true));
} catch (NumberFormatException ignored) {
}

View File

@@ -1,6 +1,7 @@
package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.utility.FileHelper;
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -44,7 +45,7 @@ public class CommandLoad implements CommandExecutor {
//Show books available to the player
if (argumentCount == 0) {
BooksWithoutBorders.loadList.put(sender.getName(), booksWithoutBorders.listFiles(player, loadPublic, false));
BooksWithoutBorders.loadList.put(sender.getName(), FileHelper.listFiles(player, loadPublic, false));
return true;
}
@@ -66,7 +67,7 @@ public class CommandLoad implements CommandExecutor {
//Load books available to the player
try {
Integer.parseInt(bookIdentifier);
BooksWithoutBorders.loadList.put(player.getName(), booksWithoutBorders.listFiles(player, loadPublic, true));
BooksWithoutBorders.loadList.put(player.getName(), FileHelper.listFiles(player, loadPublic, true));
} catch (NumberFormatException ignored) {
}

View File

@@ -14,7 +14,6 @@ import org.bukkit.inventory.meta.BookMeta;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.titleAuthorSeparator;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder;

View File

@@ -1,6 +1,7 @@
package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.utility.FileHelper;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -8,7 +9,6 @@ import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -49,7 +49,7 @@ public class GiveTabCompleter implements TabCompleter {
if (argumentCount == 1) {
//Return list of books
return BooksWithoutBorders.loadList.put(sender.getName(), booksWithoutBorders.listFiles(sender, false, true));
return BooksWithoutBorders.loadList.put(sender.getName(), FileHelper.listFiles(sender, false, true));
} else if (argumentCount == 2) {
//Return online players
return playerNames;