- /credits give/remove、/credits user give/remove 控台可用(无自己则提示用法) - /credits <玩家名> give/remove 控台默认有权限 - 普通玩家无权限执行 give/remove 时不提示权限不足,改为直接返回积分查询结果 - 最小化信息透露:用户无法区分是没权限还是没有该子参数 - 修复给他人加减分分支误用未定义变量 p 的编译错误
This commit is contained in:
@@ -1440,24 +1440,25 @@ public class CreditManager {
|
||||
String arg1Lower = args[1].toLowerCase();
|
||||
if (arg1Lower.equals("give") || arg1Lower.equals("remove")) {
|
||||
// /credits <玩家名> give/remove <数值> [备注] — 给他人加减分
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("§c仅玩家可用");
|
||||
// 控台和玩家都可执行,控台默认有权限
|
||||
boolean isAdmin;
|
||||
if (sender instanceof Player) {
|
||||
isAdmin = plugin.isAdmin((Player) sender);
|
||||
} else {
|
||||
isAdmin = true; // 控台默认有权限
|
||||
}
|
||||
if (!isAdmin) {
|
||||
sender.sendMessage("§c§l[信誉积分] §c权限不足");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
boolean isGive = arg1Lower.equals("give");
|
||||
// 给他人加减分需要管理员权限
|
||||
if (!plugin.isAdmin(p)) {
|
||||
p.sendMessage("§c§l[信誉积分] §c权限不足");
|
||||
return true;
|
||||
}
|
||||
String targetName = args[0];
|
||||
String amountStr = args[2];
|
||||
double amount;
|
||||
try {
|
||||
amount = Double.parseDouble(amountStr);
|
||||
} catch (NumberFormatException e) {
|
||||
p.sendMessage("§c§l[信誉积分] §c数值必须是数字: " + amountStr);
|
||||
sender.sendMessage("§c§l[信誉积分] §c数值必须是数字: " + amountStr);
|
||||
return true;
|
||||
}
|
||||
if (!isGive) amount = -Math.abs(amount); // remove → 负数
|
||||
@@ -1466,7 +1467,7 @@ public class CreditManager {
|
||||
// ★ 第58批-问题3修复:负分用户也能继续加减分——直接 addScore,不检查 score 是否 < 0
|
||||
double newScore = getScore(targetName) + amount;
|
||||
addScore(targetName, amount, reason);
|
||||
p.sendMessage("§d§l[信誉积分] §f对 " + targetName + " " + (isGive ? "加分" : "扣分") + "成功: §e"
|
||||
sender.sendMessage("§d§l[信誉积分] §f对 " + targetName + " " + (isGive ? "加分" : "扣分") + "成功: §e"
|
||||
+ (amount > 0 ? "+" : "") + formatScore(amount)
|
||||
+ " §7目标当前积分: §e" + formatScore(newScore));
|
||||
return true;
|
||||
@@ -1491,14 +1492,14 @@ public class CreditManager {
|
||||
|
||||
// ★ 第58批-问题4:/credits give/remove <数值> [备注] — 给自己加减分
|
||||
if (sub.equals("give") || sub.equals("remove")) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("§c仅玩家可用");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
boolean isGive = sub.equals("give");
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
// 非管理员 remove → 不提示权限不足,当作查询自己积分
|
||||
if (!isGive && !plugin.isAdmin(p)) {
|
||||
p.sendMessage("§c§l[信誉积分] §c权限不足");
|
||||
double s = getScore(p.getName());
|
||||
p.sendMessage("§d§l[信誉积分] §f" + p.getName() + " §7的当前积分: §e" + formatScore(s)
|
||||
+ " §7(初始: " + DEFAULT_INIT_SCORE + ")");
|
||||
return true;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
@@ -1523,6 +1524,11 @@ public class CreditManager {
|
||||
+ (amount > 0 ? "+" : "") + formatScore(amount)
|
||||
+ " §7当前积分: §e" + formatScore(newScore));
|
||||
return true;
|
||||
} else {
|
||||
// 控台没有"自己",提示用法(不提示权限不足)
|
||||
sender.sendMessage("§7用法: /credits <玩家名> give/remove <数值> [备注]");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
switch (sub) {
|
||||
@@ -1539,14 +1545,14 @@ public class CreditManager {
|
||||
|
||||
// ★ /credits user give/remove <数值> [备注] — 给自己加减分
|
||||
if (arg1.equals("give") || arg1.equals("remove")) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("§c仅玩家可用");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
boolean isGive = arg1.equals("give");
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
// 非管理员 remove → 不提示权限不足,当作查询自己积分
|
||||
if (!isGive && !plugin.isAdmin(p)) {
|
||||
p.sendMessage("§c§l[信誉积分] §c权限不足");
|
||||
double s = getScore(p.getName());
|
||||
p.sendMessage("§d§l[信誉积分] §f" + p.getName() + " §7的当前积分: §e" + formatScore(s)
|
||||
+ " §7(初始: " + DEFAULT_INIT_SCORE + ")");
|
||||
return true;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
@@ -1571,6 +1577,11 @@ public class CreditManager {
|
||||
+ (amount > 0 ? "+" : "") + formatScore(amount)
|
||||
+ " §7当前积分: §e" + formatScore(newScore));
|
||||
return true;
|
||||
} else {
|
||||
// 控台没有"自己",提示用法(不提示权限不足)
|
||||
sender.sendMessage("§7用法: /credits user <玩家名> [give/remove <数值> [备注]]");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// /credits user <玩家名> [give/remove <数值> [备注>] — 查积分或快捷加减分
|
||||
@@ -1579,8 +1590,17 @@ public class CreditManager {
|
||||
if (args.length >= 4) {
|
||||
String action = args[2].toLowerCase();
|
||||
if (action.equals("give") || action.equals("remove")) {
|
||||
if (!(sender instanceof Player && plugin.isAdmin(sender))) {
|
||||
sender.sendMessage("§c§l[信誉积分] §c权限不足");
|
||||
boolean isAdmin;
|
||||
if (sender instanceof Player) {
|
||||
isAdmin = plugin.isAdmin((Player) sender);
|
||||
} else {
|
||||
isAdmin = true; // 控台默认有权限
|
||||
}
|
||||
// 无权限 → 不提示权限不足,当作普通查询返回结果(最小化信息透露)
|
||||
if (!isAdmin) {
|
||||
double s = getScore(targetName);
|
||||
sender.sendMessage("§d§l[信誉积分] §f" + targetName + " §7的当前积分: §e" + formatScore(s)
|
||||
+ " §7(初始: " + DEFAULT_INIT_SCORE + ")");
|
||||
return true;
|
||||
}
|
||||
boolean isGive = action.equals("give");
|
||||
|
||||
Reference in New Issue
Block a user