From 91c622c4b71d9798aa0301846accb0bd76f53ef6 Mon Sep 17 00:00:00 2001 From: youpaishidifu <1@ypshidifu.cn> Date: Mon, 2 Nov 2026 00:12:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC66=E6=89=B9-=E4=BF=A1=E8=AA=89?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E5=91=BD=E4=BB=A4=E6=8E=A7=E5=8F=B0=E6=94=BE?= =?UTF-8?q?=E8=A1=8C+=E6=9C=80=E5=B0=8F=E5=8C=96=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=20-=20/credits=20give/remove=E3=80=81/credit?= =?UTF-8?q?s=20user=20give/remove=20=E6=8E=A7=E5=8F=B0=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=EF=BC=88=E6=97=A0=E8=87=AA=E5=B7=B1=E5=88=99=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E7=94=A8=E6=B3=95=EF=BC=89=20-=20/credits=20<=E7=8E=A9?= =?UTF-8?q?=E5=AE=B6=E5=90=8D>=20give/remove=20=E6=8E=A7=E5=8F=B0=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=9C=89=E6=9D=83=E9=99=90=20-=20=E6=99=AE=E9=80=9A?= =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E6=97=A0=E6=9D=83=E9=99=90=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=20give/remove=20=E6=97=B6=E4=B8=8D=E6=8F=90=E7=A4=BA=E6=9D=83?= =?UTF-8?q?=E9=99=90=E4=B8=8D=E8=B6=B3=EF=BC=8C=E6=94=B9=E4=B8=BA=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E8=BF=94=E5=9B=9E=E7=A7=AF=E5=88=86=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=20-=20=E6=9C=80=E5=B0=8F=E5=8C=96=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=80=8F=E9=9C=B2=EF=BC=9A=E7=94=A8=E6=88=B7=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=8C=BA=E5=88=86=E6=98=AF=E6=B2=A1=E6=9D=83=E9=99=90?= =?UTF-8?q?=E8=BF=98=E6=98=AF=E6=B2=A1=E6=9C=89=E8=AF=A5=E5=AD=90=E5=8F=82?= =?UTF-8?q?=E6=95=B0=20-=20=E4=BF=AE=E5=A4=8D=E7=BB=99=E4=BB=96=E4=BA=BA?= =?UTF-8?q?=E5=8A=A0=E5=87=8F=E5=88=86=E5=88=86=E6=94=AF=E8=AF=AF=E7=94=A8?= =?UTF-8?q?=E6=9C=AA=E5=AE=9A=E4=B9=89=E5=8F=98=E9=87=8F=20p=20=E7=9A=84?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Sdf1_login/CreditManager.java | 160 +++++++++++--------- 1 file changed, 90 insertions(+), 70 deletions(-) diff --git a/src/main/java/Sdf1_login/CreditManager.java b/src/main/java/Sdf1_login/CreditManager.java index 4105ed8..af8025a 100644 --- a/src/main/java/Sdf1_login/CreditManager.java +++ b/src/main/java/Sdf1_login/CreditManager.java @@ -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,38 +1492,43 @@ 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 (!isGive && !plugin.isAdmin(p)) { - p.sendMessage("§c§l[信誉积分] §c权限不足"); + if (sender instanceof Player) { + Player p = (Player) sender; + // 非管理员 remove → 不提示权限不足,当作查询自己积分 + if (!isGive && !plugin.isAdmin(p)) { + 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) { + p.sendMessage("§c用法: /credits " + (isGive ? "give" : "remove") + " <数值> [备注]"); + p.sendMessage("§7示例: /credits give 5 帮助新人 / credits remove 0.01 违规"); + return true; + } + String amountStr = args[1]; + double amount; + try { + amount = Double.parseDouble(amountStr); + } catch (NumberFormatException e) { + p.sendMessage("§c§l[信誉积分] §c数值必须是数字: " + amountStr); + return true; + } + if (!isGive) amount = -Math.abs(amount); // remove → 负数 + else amount = Math.abs(amount); // give → 正数 + String reason = args.length >= 3 ? String.join(" ", java.util.Arrays.copyOfRange(args, 2, args.length)) : (isGive ? "快捷加分" : "快捷扣分"); + double newScore = getScore(p.getName()) + amount; + addScore(p.getName(), amount, reason); + p.sendMessage("§d§l[信誉积分] §f" + (isGive ? "加分" : "扣分") + "成功: §e" + + (amount > 0 ? "+" : "") + formatScore(amount) + + " §7当前积分: §e" + formatScore(newScore)); + return true; + } else { + // 控台没有"自己",提示用法(不提示权限不足) + sender.sendMessage("§7用法: /credits <玩家名> give/remove <数值> [备注]"); return true; } - if (args.length < 2) { - p.sendMessage("§c用法: /credits " + (isGive ? "give" : "remove") + " <数值> [备注]"); - p.sendMessage("§7示例: /credits give 5 帮助新人 / credits remove 0.01 违规"); - return true; - } - String amountStr = args[1]; - double amount; - try { - amount = Double.parseDouble(amountStr); - } catch (NumberFormatException e) { - p.sendMessage("§c§l[信誉积分] §c数值必须是数字: " + amountStr); - return true; - } - if (!isGive) amount = -Math.abs(amount); // remove → 负数 - else amount = Math.abs(amount); // give → 正数 - String reason = args.length >= 3 ? String.join(" ", java.util.Arrays.copyOfRange(args, 2, args.length)) : (isGive ? "快捷加分" : "快捷扣分"); - double newScore = getScore(p.getName()) + amount; - addScore(p.getName(), amount, reason); - p.sendMessage("§d§l[信誉积分] §f" + (isGive ? "加分" : "扣分") + "成功: §e" - + (amount > 0 ? "+" : "") + formatScore(amount) - + " §7当前积分: §e" + formatScore(newScore)); - return true; } switch (sub) { @@ -1539,38 +1545,43 @@ 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 (!isGive && !plugin.isAdmin(p)) { - p.sendMessage("§c§l[信誉积分] §c权限不足"); + if (sender instanceof Player) { + Player p = (Player) sender; + // 非管理员 remove → 不提示权限不足,当作查询自己积分 + if (!isGive && !plugin.isAdmin(p)) { + 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) { + p.sendMessage("§c用法: /credits user " + (isGive ? "give" : "remove") + " <数值> [备注]"); + p.sendMessage("§7示例: /credits user give 5 帮助新人"); + return true; + } + String amountStr = args[2]; + double amount; + try { + amount = Double.parseDouble(amountStr); + } catch (NumberFormatException e) { + p.sendMessage("§c§l[信誉积分] §c数值必须是数字: " + amountStr); + return true; + } + if (!isGive) amount = -Math.abs(amount); + else amount = Math.abs(amount); + String reason = args.length >= 4 ? String.join(" ", java.util.Arrays.copyOfRange(args, 3, args.length)) : (isGive ? "快捷加分" : "快捷扣分"); + double newScore = getScore(p.getName()) + amount; + addScore(p.getName(), amount, reason); + p.sendMessage("§d§l[信誉积分] §f" + (isGive ? "加分" : "扣分") + "成功: §e" + + (amount > 0 ? "+" : "") + formatScore(amount) + + " §7当前积分: §e" + formatScore(newScore)); + return true; + } else { + // 控台没有"自己",提示用法(不提示权限不足) + sender.sendMessage("§7用法: /credits user <玩家名> [give/remove <数值> [备注]]"); return true; } - if (args.length < 3) { - p.sendMessage("§c用法: /credits user " + (isGive ? "give" : "remove") + " <数值> [备注]"); - p.sendMessage("§7示例: /credits user give 5 帮助新人"); - return true; - } - String amountStr = args[2]; - double amount; - try { - amount = Double.parseDouble(amountStr); - } catch (NumberFormatException e) { - p.sendMessage("§c§l[信誉积分] §c数值必须是数字: " + amountStr); - return true; - } - if (!isGive) amount = -Math.abs(amount); - else amount = Math.abs(amount); - String reason = args.length >= 4 ? String.join(" ", java.util.Arrays.copyOfRange(args, 3, args.length)) : (isGive ? "快捷加分" : "快捷扣分"); - double newScore = getScore(p.getName()) + amount; - addScore(p.getName(), amount, reason); - p.sendMessage("§d§l[信誉积分] §f" + (isGive ? "加分" : "扣分") + "成功: §e" - + (amount > 0 ? "+" : "") + formatScore(amount) - + " §7当前积分: §e" + formatScore(newScore)); - 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");