解决了在创建玩家特权时因为参数解析方式错误导致的潜在的ui对应命令错误问题

This commit is contained in:
zhangyuheng 2024-02-17 15:55:31 +08:00
parent a4c7797af8
commit 849e27b7d7
7 changed files with 36 additions and 13 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.4.5-beta</version>
<version>1.4.6-beta</version>
<packaging>jar</packaging>
<name>Dominion</name>

View File

@ -38,7 +38,7 @@ public class PlayerPrivilege {
}
Notification.info(sender, "成功创建玩家特权 " + args[1]);
if (args.length == 4) {
String[] newArgs = new String[3];
String[] newArgs = new String[2];
newArgs[0] = "privilege_list";
newArgs[1] = args[2];
DominionPrivilegeList.show(sender, newArgs);

View File

@ -26,14 +26,38 @@ public class Apis {
return page;
}
public static DominionDTO getDominion(Player player, String[] args) {
if (args.length == 2) {
/**
* 尝试从 arg[1] 获取领地名称
* 如果没有此参数则会尝试获取玩家当前所在位置
*
* @param player 玩家
* @param args 参数
* @return 领地信息
*/
public static DominionDTO getDominionNameArg_1(Player player, String[] args) {
if (args.length >= 2) {
return DominionDTO.select(args[1]);
} else {
return getPlayerCurrentDominion(player);
}
}
/**
* 尝试从 arg[2] 获取领地名称
* 如果没有此参数则会尝试获取玩家当前所在位置
*
* @param player 玩家
* @param args 参数
* @return 领地信息
*/
public static DominionDTO getDominionNameArg_2(Player player, String[] args) {
if (args.length >= 3) {
return DominionDTO.select(args[2]);
} else {
return getPlayerCurrentDominion(player);
}
}
public static boolean noAuthToManage(Player player, DominionDTO dominion) {
if (player.isOp()) return false;
if (!dominion.getOwner().equals(player.getUniqueId())) {

View File

@ -9,14 +9,14 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getDominion;
import static cn.lunadeer.dominion.tuis.Apis.getDominionNameArg_1;
import static cn.lunadeer.dominion.tuis.Apis.noAuthToManage;
public class DominionManage {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = getDominion(player, args);
DominionDTO dominion = getDominionNameArg_1(player, args);
if (dominion == null) {
Notification.error(sender, "你不在任何领地内,请指定领地名称 /dominion manage <领地名称>");
return;

View File

@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getDominion;
import static cn.lunadeer.dominion.tuis.Apis.getDominionNameArg_1;
import static cn.lunadeer.dominion.tuis.Apis.noAuthToManage;
public class DominionPrivilegeList {
@ -28,7 +28,7 @@ public class DominionPrivilegeList {
}
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = getDominion(player, args);
DominionDTO dominion = getDominionNameArg_1(player, args);
if (dominion == null) {
Notification.error(sender, "你不在任何领地内,请指定领地名称 /dominion privilege_list <领地名称>");
return;

View File

@ -11,13 +11,13 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getDominion;
import static cn.lunadeer.dominion.tuis.Apis.getDominionNameArg_1;
public class DominionSizeInfo {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = getDominion(player, args);
DominionDTO dominion = getDominionNameArg_1(player, args);
if (dominion == null) {
Notification.error(sender, "你不在任何领地内,请指定领地名称 /dominion info <领地名称>");
return;

View File

@ -11,15 +11,14 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getDominion;
import static cn.lunadeer.dominion.tuis.Apis.noAuthToManage;
import static cn.lunadeer.dominion.tuis.Apis.*;
public class PrivilegeInfo {
// /dominion privilege_info <玩家名称> [领地名称] [页码]
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = getDominion(player, args);
DominionDTO dominion = getDominionNameArg_2(player, args);
int page = 1;
if (args.length == 4) {
try {