Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class BuildSystemCommand extends PagedCommand implements CommandExecutor
private final BuildSystem plugin;

public BuildSystemCommand(BuildSystem plugin) {
super("buildsystem_permission", "buildsystem_title_with_page");
super("buildsystem_title_with_page", "buildsystem_permission");

this.plugin = plugin;
plugin.getCommand("buildsystem").setExecutor(this);
Expand All @@ -45,7 +45,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
plugin.getLogger().warning(Messages.getString("sender_not_player", null));
return true;
}

Player player = (Player) sender;
if (!player.hasPermission("buildsystem.help.buildsystem")) {
plugin.sendPermissionMessage(player);
return true;
}

if (args.length == 0) {
sendMessage(player, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public abstract class PagedCommand {

private static final int MAX_COMMANDS_PER_PAGE = 7;

private final String permission, title;
private final String title, permissionTemplate;

public PagedCommand(String permission, String title) {
this.permission = permission;
public PagedCommand(String title, String permissionTemplate) {
this.title = title;
this.permissionTemplate = permissionTemplate;
}

protected void sendMessage(Player player, int pageNum) {
Expand Down Expand Up @@ -85,7 +85,7 @@ protected TextComponent createComponent(Player player, String command, String co

commandComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest));
commandComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder(Messages.getString(this.permission, player, new AbstractMap.SimpleEntry<>("%permission%", permission))).create()
new ComponentBuilder(Messages.getString(this.permissionTemplate, player, new AbstractMap.SimpleEntry<>("%permission%", permission))).create()
));
commandComponent.addExtra(textComponent);
return commandComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
break;
}
case HELP: {
subCommand = new HelpSubCommand();
subCommand = new HelpSubCommand(plugin);
break;
}
case IMPORT_ALL: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public interface SubCommand {
Argument getArgument();

default boolean hasPermission(Player player) {
if (getArgument().getPermission() == null) {
return true;
}
return player.hasPermission(getArgument().getPermission());
String permission = getArgument().getPermission();
return permission == null || player.hasPermission(permission);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package de.eintosti.buildsystem.command.subcommand.worlds;

import com.google.common.collect.Lists;
import de.eintosti.buildsystem.BuildSystem;
import de.eintosti.buildsystem.Messages;
import de.eintosti.buildsystem.command.PagedCommand;
import de.eintosti.buildsystem.command.subcommand.Argument;
Expand All @@ -29,12 +30,20 @@

public class HelpSubCommand extends PagedCommand implements SubCommand {

public HelpSubCommand() {
super("worlds_help_permission", "worlds_help_title_with_page");
private final BuildSystem plugin;

public HelpSubCommand(BuildSystem plugin) {
super("worlds_help_title_with_page", "worlds_help_permission");
this.plugin = plugin;
}

@Override
public void execute(Player player, String[] args) {
if (!hasPermission(player)) {
plugin.sendPermissionMessage(player);
return;
}

if (args.length == 1) {
sendMessage(player, 1);
} else if (args.length == 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ public enum WorldsArgument implements Argument {
BUILDERS("builders", "buildsystem.builders"),
DELETE("delete", "buildsystem.delete"),
EDIT("edit", "buildsystem.edit"),
HELP("help", null),
HELP("help", "buildsystem.help.worlds"),
IMPORT("import", "buildsystem.import"),
IMPORT_ALL("importAll", "buildsystem.import.all"),
INFO("info", "buildsystem.info"),
ITEM("item", null),
ITEM("item", "buildsystem.navigator.item"),
REMOVE_BUILDER("removeBuilder", "buildsystem.removebuilder"),
RENAME("rename", "buildsystem.rename"),
SET_CREATOR("setCreator", "buildsystem.setcreator"),
Expand Down
8 changes: 7 additions & 1 deletion buildsystem-core/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ commands:
usage: /<command>

permissions:
buildsystem.help:
children:
- buildsystem.help.buildsystem
- buildsystem.help.worlds
default: true
description: Permission for help commands.
buildsystem.navigator:
description: Open the worlds navigator.
default: true
buildsystem.navigator.item:
description: Receive and use the naviagtor open.
description: Receive and use the navigator.
default: true
buildsystem.create:
children:
Expand Down
Loading