新增权限节点配置,允许通过权限节点控制玩家行为

This commit is contained in:
zhangyuheng 2024-07-12 17:39:31 +08:00
parent 3ffab50c9b
commit b52fce2479
9 changed files with 38 additions and 37 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>MiniPlayerTitle</artifactId>
<version>4.2.8</version>
<version>4.3.0</version>
<packaging>jar</packaging>
<name>MiniPlayerTitle</name>

View File

@ -13,16 +13,6 @@ import static cn.lunadeer.miniplayertitle.MiniPlayerTitle.usingPapi;
public class Apis {
public static boolean notOpOrConsole(CommandSender sender) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
Notification.warn(player, "你没有权限使用此命令");
return true;
}
}
return false;
}
public static void updateName(Player player, @Nullable TitleDTO title) {
MiniPlayerTitle.instance.setPlayerUsingTitle(player.getUniqueId(), title);

View File

@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
import java.time.LocalDateTime;
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
public class PlayerManage {
@ -20,7 +19,7 @@ public class PlayerManage {
* @param args String[]
*/
public static void addCoin(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
if (!sender.hasPermission("mplt.admin")) return;
try {
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
if (playerInfo == null) {
@ -46,7 +45,7 @@ public class PlayerManage {
* @param args String[]
*/
public static void setCoin(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
if (!sender.hasPermission("mplt.admin")) return;
try {
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
if (playerInfo == null) {
@ -72,7 +71,7 @@ public class PlayerManage {
* @param args String[]
*/
public static void grantTitle(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
if (!sender.hasPermission("mplt.admin")) return;
try {
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(args[1]);
if (playerInfo == null) {

View File

@ -11,7 +11,6 @@ import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
import static cn.lunadeer.miniplayertitle.commands.Apis.updateName;
public class TitleManage {
@ -23,7 +22,7 @@ public class TitleManage {
* @param args String[]
*/
public static void createTitle(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
if (!sender.hasPermission("mplt.admin")) return;
if (args.length < 2) {
Notification.warn(sender, "用法: /mplt create_title <称号名称> [称号描述]");
return;
@ -46,7 +45,7 @@ public class TitleManage {
*/
public static void deleteTitle(CommandSender sender, String[] args) {
try {
if (notOpOrConsole(sender)) return;
if (!sender.hasPermission("mplt.admin")) return;
if (args.length < 2) {
Notification.warn(sender, "用法: /mplt delete_title <称号ID>");
return;
@ -80,7 +79,7 @@ public class TitleManage {
*/
public static void editTitleName(CommandSender sender, String[] args) {
try {
if (notOpOrConsole(sender)) return;
if (!sender.hasPermission("mplt.admin")) return;
if (args.length != 3) {
Notification.warn(sender, "用法: /mplt set_title <称号ID> <称号名称>");
return;
@ -110,7 +109,7 @@ public class TitleManage {
*/
public static void editTitleDescription(CommandSender sender, String[] args) {
try {
if (notOpOrConsole(sender)) return;
if (!sender.hasPermission("mplt.admin")) return;
if (args.length != 3) {
Notification.warn(sender, "用法: /mplt set_desc <称号ID> <称号描述>");
return;
@ -143,6 +142,7 @@ public class TitleManage {
Notification.error(sender, "该命令只能由玩家执行");
return;
}
if (!sender.hasPermission("mplt.command")) return;
if (args.length < 2) {
Notification.warn(sender, "用法: /mplt use_title <背包ID> [页码]");
return;
@ -201,6 +201,7 @@ public class TitleManage {
Notification.error(sender, "该命令只能由玩家执行");
return;
}
if (!sender.hasPermission("mplt.custom")) return;
Player player = (Player) sender;
if (!MiniPlayerTitle.config.isEnableCustom()) {
Notification.error(sender, "自定义称号功能已关闭");

View File

@ -16,7 +16,6 @@ import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import static cn.lunadeer.miniplayertitle.commands.Apis.notOpOrConsole;
import static cn.lunadeer.miniplayertitle.tuis.Apis.getArgPage;
import static cn.lunadeer.miniplayertitle.tuis.Apis.getLastArgsPage;
@ -30,7 +29,7 @@ public class TitleShopSale {
* @param args String[]
*/
public static void setSale(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
if (!sender.hasPermission("mplt.admin")) return;
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[2]));
if (titleShop == null) {
Notification.error(sender, "获取详情时出现错误,详情请查看控制台日志");
@ -83,7 +82,7 @@ public class TitleShopSale {
* @param args String[]
*/
public static void createSale(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
if (!sender.hasPermission("mplt.admin")) return;
TitleDTO title = TitleDTO.get(Integer.parseInt(args[1]));
if (title == null) {
Notification.error(sender, "获取称号详情时出现错误,详情请查看控制台日志");
@ -108,7 +107,7 @@ public class TitleShopSale {
* @param args String[]
*/
public static void deleteSale(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
if (!sender.hasPermission("mplt.admin")) return;
TitleShopDTO titleShop = TitleShopDTO.get(Integer.valueOf(args[1]));
if (titleShop == null) {
Notification.error(sender, "获取详情时出现错误");
@ -138,6 +137,7 @@ public class TitleShopSale {
Notification.error(sender, "该命令只能由玩家执行");
return;
}
if (!sender.hasPermission("mplt.command")) return;
Player player = (Player) sender;
PlayerInfoDTO playerInfo = PlayerInfoDTO.get(player.getUniqueId());
if (playerInfo == null) {

View File

@ -32,7 +32,7 @@ public class AllTitles {
Line line = Line.create()
.append(title.getId().toString())
.append(title.getTitleColored());
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
line.append(Button.createRed("删除").setExecuteCommand("/mplt delete_title " + title.getId() + " " + page).build());
line.append(Button.createGreen("创建商品").setExecuteCommand("/mplt create_sale " + title.getId()).build());
}

View File

@ -58,7 +58,7 @@ public class Menu {
Line all = Line.create()
.append(Button.create("所有称号").setExecuteCommand("/mplt all_titles").build()).append("查看所有称号");
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
view.add(Line.create().append(""));
view.add(Line.create().append("---以下选项仅OP可见---"));
view.add(all);

View File

@ -46,11 +46,11 @@ public class SaleInfo {
Line price = Line.create().append("价格: ");
if (titleShop.getPrice() <= 0) {
price.append("免费");
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
price.append(Button.create("设置价格").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 100 " + page).build());
}
} else {
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
price.append(NumChanger.create(titleShop.getPrice(), "/mplt set_sale price " + titleShop.getId()).setPageNumber(page).build());
price.append(Button.create("设置为免费").setExecuteCommand("/mplt set_sale price " + titleShop.getId() + " 0 " + page).build());
} else {
@ -62,11 +62,11 @@ public class SaleInfo {
Line day = Line.create().append("购买天数: ");
if (titleShop.getDays() <= 0) {
day.append("永久");
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
day.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " 7 " + page).build());
}
} else {
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
day.append(NumChanger.create(titleShop.getDays(), "/mplt set_sale days " + titleShop.getId()).setPageNumber(page).build());
day.append(Button.create("转为永久").setExecuteCommand("/mplt set_sale days " + titleShop.getId() + " -1 " + page).build());
} else {
@ -78,12 +78,12 @@ public class SaleInfo {
Line amount = Line.create().append("剩余数量: ");
if (titleShop.getAmount() == -1) {
amount.append("无限");
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
amount.append(Button.create("转为限量").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " 0 " + page).build());
}
} else {
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
amount.append(NumChanger.create(titleShop.getAmount(), "/mplt set_sale amount " + titleShop.getId()).setPageNumber(page).build());
amount.append(Button.create("转为无限").setExecuteCommand("/mplt set_sale amount " + titleShop.getId() + " -1 " + page).build());
} else {
@ -95,11 +95,11 @@ public class SaleInfo {
Line end_at = Line.create().append("售卖结束时间: ");
if (titleShop.getSaleEndAt() == null) {
end_at.append("常驻");
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
end_at.append(Button.create("转为限时").setExecuteCommand("/mplt set_sale end_at " + titleShop.getId() + " " + now_year + ":" + now_month + ":" + now_day + " " + page).build());
}
} else {
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
end_at.append(Button.create("<<").setPreSufIx("", "").setHoverText("提前10天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 10 " + page).build()
.append(Button.create("-").setPreSufIx("", "").setHoverText("提前1天").setExecuteCommand("/mplt set_sale less_end_at " + titleShop.getId() + " 1 " + page).build())
.append(Component.text(titleShop.getSaleEndAt().getYear() + "" + titleShop.getSaleEndAt().getMonthValue() + "" + titleShop.getSaleEndAt().getDayOfMonth() + ""))
@ -120,7 +120,7 @@ public class SaleInfo {
} else {
operate.append(Button.createGreen("购买").setExecuteCommand("/mplt buy_sale " + titleShop.getId()).build());
}
if (player.isOp()) {
if (player.hasPermission("mplt.admin")) {
operate.append(Button.create("删除").setExecuteCommand("/mplt delete_sale " + args[1] + " b").build());
}
view.add(Line.create().append("---------------------"));

View File

@ -11,3 +11,14 @@ commands:
description: 称号插件命令
usage: /mplt <cmd>
aliases: [ mplt ]
permission: mplt.command
permissions:
mplt.command:
description: 普通命令
default: true
mplt.custom:
description: 是否可以自定义称号
default: true
mplt.admin:
description: 是否可以使用管理员命令
default: op