Skip to content

Commit

Permalink
使用权限节点进行权限检查 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevei5mc authored Jan 6, 2024
1 parent cca79fd commit 55ffafa
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public AddRouteSubCommand(String name) {

@Override
public boolean canUser(CommandSender sender) {
return sender.isPlayer() && sender.isOp();
return sender.isPlayer() && sender.hasPermission("RsNPC.admin.addroute");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CreateSubCommand(String name) {

@Override
public boolean canUser(CommandSender sender) {
return sender.isPlayer() && sender.isOp();
return sender.isPlayer() && sender.hasPermission("RsNPC.admin.create");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public DeleteSubCommand(String name) {

@Override
public boolean canUser(CommandSender sender) {
return sender.isOp();
return sender.hasPermission("RsNPC.admin.delete");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ReloadSubCommand(String name) {

@Override
public boolean canUser(CommandSender sender) {
return sender.isOp();
return sender.hasPermission("RsNPC.admin.reload");
}

@Override
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/smallaswater/npc/utils/FormHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ public static void sendMain(@NotNull Player player) {
simple.setContent(getRandomMessage() + "\n\n");
}

simple.addButton(new ResponseElementButton(language.translateString("gui.main.button.createNPCText")).onClicked(FormHelper::sendCreateNpc));
simple.addButton(new ResponseElementButton(language.translateString("gui.main.button.adminNPCText")).onClicked(FormHelper::sendAdminNpcSelect));
simple.addButton(new ResponseElementButton(language.translateString("gui.main.button.reloadText"))
.onClicked(cp -> Server.getInstance().dispatchCommand(cp, "rsnpc reload"))
);
if (player.hasPermission("RsNPC.admin.create")) {
simple.addButton(new ResponseElementButton(language.translateString("gui.main.button.createNPCText")).onClicked(FormHelper::sendCreateNpc));
if (player.hasPermission("RsNPC.admin.delete")) {
simple.addButton(new ResponseElementButton(language.translateString("gui.main.button.adminNPCText")).onClicked(FormHelper::sendAdminNpcSelect));
}
}
if (player.hasPermission("RsNPC.admin.reload")) {
simple.addButton(new ResponseElementButton(language.translateString("gui.main.button.reloadText"))
.onClicked(cp -> Server.getInstance().dispatchCommand(cp, "rsnpc reload"))
);
}

player.showFormWindow(simple);
}
Expand Down
14 changes: 13 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ softdepend:
permissions:
RsNPC.admin:
default: op
description: "RsNPC插件主命令"
description: "RsNPC 插件主命令"
RsNPC.admin.create:
default: op
description: "RsNPC 创建NPC命令"
RsNPC.admin.delete:
default: op
description: "RsNPC 删除NPC命令"
RsNPC.admin.reload:
default: op
description: "RsNPC 重载配置文件命令"
RsNPC.admin.addroute:
default: op
description: "RsNPC 添加NPC移动路径命令"

0 comments on commit 55ffafa

Please sign in to comment.