Moves the delete public command to its own file
This commit is contained in:
parent
db3679014d
commit
db4f080ac8
@ -84,6 +84,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
|||||||
registerCommand("decrypt", new CommandDecrypt(this), null);
|
registerCommand("decrypt", new CommandDecrypt(this), null);
|
||||||
registerCommand("groupEncrypt", new CommandGroupEncrypt(this), null);
|
registerCommand("groupEncrypt", new CommandGroupEncrypt(this), null);
|
||||||
registerCommand("delete", new CommandDelete(this), null);
|
registerCommand("delete", new CommandDelete(this), null);
|
||||||
|
registerCommand("deletePublic", new CommandDeletePublic(this), null);
|
||||||
registerCommand("copy", new CommandCopy(this), null);
|
registerCommand("copy", new CommandCopy(this), null);
|
||||||
registerCommand("unSign", new CommandUnSign(this), null);
|
registerCommand("unSign", new CommandUnSign(this), null);
|
||||||
registerCommand("encrypt", new CommandEncrypt(this), null);
|
registerCommand("encrypt", new CommandEncrypt(this), null);
|
||||||
@ -516,37 +517,6 @@ public class BooksWithoutBorders extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("deletePublic")) {
|
|
||||||
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
if (!sender.hasPermission("bookswithoutborders.admin")) {
|
|
||||||
sendErrorMessage(sender, " You don't have permission to use this command!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//lists delete-able files
|
|
||||||
if (args.length == 1) {
|
|
||||||
loadList.put(sender.getName(), listFiles(sender, true, false));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//actual deletion
|
|
||||||
if (args.length == 2) {
|
|
||||||
if (!loadList.containsKey(sender.getName())) {
|
|
||||||
sendErrorMessage(sender, "You must first use /bwb deletePublic to create a list of delete-able files!");
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if (!loadList.get(sender.getName()).isEmpty()) {
|
|
||||||
deleteBook((sender), args[1], true);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
sendErrorMessage(sender, "No files available to delete!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sendErrorMessage(sender, "Command not recognized! Use " + commandColor + "/BwB" + errorColor + " for more info!");
|
sendErrorMessage(sender, "Command not recognized! Use " + commandColor + "/BwB" + errorColor + " for more info!");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -19,32 +19,43 @@ public class CommandDelete implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (!(sender instanceof Player player)) {
|
if (!(sender instanceof Player)) {
|
||||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return deleteBook(sender, args, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a book
|
||||||
|
* @param sender <p>The sender trying to delete the book</p>
|
||||||
|
* @param args <p>The arguments given</p>
|
||||||
|
* @param deletePublic <p>Whether to delete a public book</p>
|
||||||
|
* @return <p>True if the book was deleted successfully</p>
|
||||||
|
*/
|
||||||
|
boolean deleteBook(CommandSender sender, String[] args, boolean deletePublic) {
|
||||||
//List deletable files
|
//List deletable files
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
BooksWithoutBorders.loadList.put(player.getName(), booksWithoutBorders.listFiles(player, false, false));
|
BooksWithoutBorders.loadList.put(sender.getName(), booksWithoutBorders.listFiles(sender, deletePublic, false));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//Delete the file
|
//Delete the file
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
if (!BooksWithoutBorders.loadList.containsKey(player.getName())) {
|
if (!BooksWithoutBorders.loadList.containsKey(sender.getName())) {
|
||||||
BooksWithoutBorders.sendErrorMessage(player, "You must first use /bwb delete to create a list of delete-able files!");
|
BooksWithoutBorders.sendErrorMessage(sender, "You must first use /bwb delete to create a list of delete-able files!");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (!BooksWithoutBorders.loadList.get(player.getName()).isEmpty()) {
|
if (!BooksWithoutBorders.loadList.get(sender.getName()).isEmpty()) {
|
||||||
booksWithoutBorders.deleteBook(player, args[0], false);
|
booksWithoutBorders.deleteBook(sender, args[0], deletePublic);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
BooksWithoutBorders.sendErrorMessage(player, "No files available to delete!");
|
BooksWithoutBorders.sendErrorMessage(sender, "No files available to delete!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BooksWithoutBorders.sendErrorMessage(player, "Incorrect number of arguments for this command!");
|
BooksWithoutBorders.sendErrorMessage(sender, "Incorrect number of arguments for this command!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,22 @@
|
|||||||
package net.knarcraft.bookswithoutborders.command;
|
package net.knarcraft.bookswithoutborders.command;
|
||||||
|
|
||||||
|
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class CommandDeletePublic implements CommandExecutor {
|
/**
|
||||||
|
* Command executor for the "delete public" command
|
||||||
|
*/
|
||||||
|
public class CommandDeletePublic extends CommandDelete implements CommandExecutor {
|
||||||
|
|
||||||
|
public CommandDeletePublic(BooksWithoutBorders booksWithoutBorders) {
|
||||||
|
super(booksWithoutBorders);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
return false;
|
return deleteBook(sender, args, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command executor for the load command
|
||||||
|
*/
|
||||||
public class CommandLoad implements CommandExecutor {
|
public class CommandLoad implements CommandExecutor {
|
||||||
|
|
||||||
private final BooksWithoutBorders booksWithoutBorders;
|
private final BooksWithoutBorders booksWithoutBorders;
|
||||||
|
@ -5,6 +5,9 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command executor for the load public command
|
||||||
|
*/
|
||||||
public class CommandLoadPublic extends CommandLoad implements CommandExecutor {
|
public class CommandLoadPublic extends CommandLoad implements CommandExecutor {
|
||||||
|
|
||||||
public CommandLoadPublic(BooksWithoutBorders booksWithoutBorders) {
|
public CommandLoadPublic(BooksWithoutBorders booksWithoutBorders) {
|
||||||
|
@ -29,6 +29,10 @@ commands:
|
|||||||
description: Deletes a book saved by the executing user
|
description: Deletes a book saved by the executing user
|
||||||
usage: /<command> <file name or number>
|
usage: /<command> <file name or number>
|
||||||
permission: bookswithoutborders.delete
|
permission: bookswithoutborders.delete
|
||||||
|
deletepublic:
|
||||||
|
description: Deletes a public book
|
||||||
|
usage: /<command> <file name of number>
|
||||||
|
permission: bookswithoutborders.admin
|
||||||
copy:
|
copy:
|
||||||
description: Copies the held book
|
description: Copies the held book
|
||||||
usage: /<command> <copies>
|
usage: /<command> <copies>
|
||||||
|
Loading…
Reference in New Issue
Block a user