Adds in-game command info, and fixes some permission bugs
This commit is contained in:
parent
e5dfc1ccf6
commit
337c4573e0
@ -51,6 +51,7 @@ arguments, such as no paid sign permission, you should use empty quotes ("").
|
||||
|
||||
| Command | Arguments | Permission | Description |
|
||||
| -------- | ------ | ------- | ------- |
|
||||
| /paidsigns | | paidsigns.info | Used to display in-game information about all other commands |
|
||||
| [/addpaidsign](#addpaidsign) | \<name> \<cost> \[permission] \[ignore case] \[ignore color] \[match any condition] | paidsigns.manage | Used to add a new paid sign |
|
||||
| [/addpaidsigncondition](#addpaidsigncondition) | \<name (of a paid sign)> \<line number> \<string to match> \[executeRegEx] \[ignoreCase] \[ignoreColor] | paidsigns.manage | Used to add a condition to a paid sign |
|
||||
| [/listpaidsigns](#listpaidsigns) | \[name (of a paid sign)] \[line number] | paidsigns.manage | Used to list registered paid signs or a registered paid sign's conditions |
|
||||
@ -61,6 +62,8 @@ arguments, such as no paid sign permission, you should use empty quotes ("").
|
||||
|
||||
## Command explanation
|
||||
|
||||
### /paidsigns
|
||||
|
||||
### /addpaidsign
|
||||
|
||||
This command adds a new paid sign that does nothing until a condition is added.
|
||||
|
@ -8,6 +8,7 @@ import net.knarcraft.paidsigns.command.EditCommand;
|
||||
import net.knarcraft.paidsigns.command.EditTabCompleter;
|
||||
import net.knarcraft.paidsigns.command.ListCommand;
|
||||
import net.knarcraft.paidsigns.command.ListTabCompleter;
|
||||
import net.knarcraft.paidsigns.command.PaidSignsTabCommand;
|
||||
import net.knarcraft.paidsigns.command.ReloadTabCommand;
|
||||
import net.knarcraft.paidsigns.command.RemoveConditionCommand;
|
||||
import net.knarcraft.paidsigns.command.RemoveConditionTabCompleter;
|
||||
@ -153,6 +154,8 @@ public final class PaidSigns extends JavaPlugin {
|
||||
* Registers the commands used by this plugin
|
||||
*/
|
||||
private void registerCommands() {
|
||||
TabExecutor paidSignsExecutor = new PaidSignsTabCommand();
|
||||
registerCommand("paidSigns", paidSignsExecutor, paidSignsExecutor);
|
||||
registerCommand("addPaidSign", new AddCommand(), new AddTabCompleter());
|
||||
registerCommand("listPaidSigns", new ListCommand(), new ListTabCompleter());
|
||||
registerCommand("addPaidSignCondition", new AddConditionCommand(), new AddConditionTabCompleter());
|
||||
|
@ -0,0 +1,81 @@
|
||||
package net.knarcraft.paidsigns.command;
|
||||
|
||||
import net.knarcraft.paidsigns.PaidSigns;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PaidSignsTabCommand implements TabExecutor {
|
||||
|
||||
private static final ChatColor successColor = ChatColor.GREEN;
|
||||
private static final ChatColor commandColor = ChatColor.YELLOW;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
sender.sendMessage(commandColor + "[] denote optional parameters");
|
||||
sender.sendMessage(commandColor + "<> denote required parameters");
|
||||
sender.sendMessage(commandColor + "{} denote required permission");
|
||||
sender.sendMessage(commandColor + "In some cases, commands with required parameters can be called with no parameters");
|
||||
if (sender instanceof Player) {
|
||||
showPlayerCommands(sender);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows all commands available to the sending player
|
||||
*
|
||||
* @param sender <p>The player which sent the command</p>
|
||||
*/
|
||||
private void showPlayerCommands(CommandSender sender) {
|
||||
sender.sendMessage(commandColor + "Commands:");
|
||||
|
||||
showCommandInfo("addPaidSign", sender);
|
||||
showCommandInfo("addPaidSignCondition", sender);
|
||||
showCommandInfo("listPaidSigns", sender);
|
||||
showCommandInfo("editPaidSign", sender);
|
||||
showCommandInfo("removePaidSignCondition", sender);
|
||||
showCommandInfo("removePaidSign", sender);
|
||||
showCommandInfo("reload", sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows information about the given command
|
||||
*
|
||||
* @param command <p>The command to get information about</p>
|
||||
* @param sender <p>The sender asking to see command info</p>
|
||||
*/
|
||||
private void showCommandInfo(String command, CommandSender sender) {
|
||||
PluginCommand pluginCommand = PaidSigns.getInstance().getCommand(command);
|
||||
if (pluginCommand != null) {
|
||||
String permission = pluginCommand.getPermission();
|
||||
if (permission == null || sender.hasPermission(permission)) {
|
||||
String commandInfo = "\n" + commandColor + pluginCommand.getUsage().replace("<command>",
|
||||
pluginCommand.getName()) + ": " + successColor + pluginCommand.getDescription();
|
||||
if (sender.hasPermission("paidsigns.admin")) {
|
||||
if (permission == null) {
|
||||
permission = "None";
|
||||
}
|
||||
commandInfo += commandColor + " {" + permission + "}";
|
||||
}
|
||||
sender.sendMessage(commandInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,10 @@ authors: [ EpicKnarvik97 ]
|
||||
description: Add costs for creating plugin signs
|
||||
website: https://git.knarcraft.net/EpicKnarvik97/PaidSigns
|
||||
commands:
|
||||
paidsigns:
|
||||
description: Displays information about paid signs commends
|
||||
usage: /<command>
|
||||
permission: paidsigns.info
|
||||
addpaidsign:
|
||||
aliases:
|
||||
- aps
|
||||
@ -49,17 +53,26 @@ commands:
|
||||
- r
|
||||
description: Reloads paid signs from disk
|
||||
usage: /<command>
|
||||
permision: paidsigns.reload
|
||||
permission: paidsigns.reload
|
||||
permissions:
|
||||
paidsigns.*:
|
||||
description: Alias to paidsigns.admin
|
||||
default: false
|
||||
children:
|
||||
paidsigns.admin: true
|
||||
paidsigns.admin:
|
||||
description: Grants all paid signs permissions
|
||||
default: op
|
||||
children:
|
||||
paidsigns.create: true
|
||||
paidsigns.info: true
|
||||
paidsigns.paymentexempt: true
|
||||
paidsigns.manage: true
|
||||
paidsigns.reload: true
|
||||
paidsigns.info:
|
||||
description: Grants the permission to see command info
|
||||
default: false
|
||||
paidsigns.manage:
|
||||
description: Grants the permission to add/remove a paid sign
|
||||
description: Grants the permission to add/remove/edit a paid sign
|
||||
default: false
|
||||
paidsigns.reload:
|
||||
description: Grants the permissions to reload the plugin
|
||||
|
Loading…
Reference in New Issue
Block a user