fix: 1.出售限速记录时机提前到扣货发钱之前 2.用户组删除/添加成员分别处理 3.sellAllOf也加限速

This commit is contained in:
2026-07-03 18:11:03 +08:00
parent 53a7430184
commit abaf54470c
3 changed files with 80 additions and 15 deletions
+25 -9
View File
@@ -1595,6 +1595,14 @@ public class ShopManager implements Listener {
int total = item.getEffectiveSellPrice() * amount;
// ===== 记录IP段销售额(必须在扣货发钱之前)=====
if (playerIp != null) {
String ipSeg = getIpSegment(playerIp);
if (ipSeg != null) {
addToIpSegmentSales(ipSeg, total);
}
}
p.getInventory().removeItem(
getShopStack(item, amount));
plugin.getBonds().addBonds(
@@ -1607,15 +1615,6 @@ public class ShopManager implements Listener {
+ item.getDisplayName()
+ " x" + amount
+ " §a+" + total + "枚债券");
// ===== 记录IP段销售额 =====
if (playerIp != null) {
String ipSeg = getIpSegment(playerIp);
if (ipSeg != null) {
addToIpSegmentSales(ipSeg, total);
}
}
return true;
}
@@ -2540,6 +2539,14 @@ public class ShopManager implements Listener {
// ===== 批量出售某商品全部数量 =====
private void sellAllOf(Player p, ShopItem item) {
if (item == null) return;
// ★ 先做IP限速检查(在扫描背包之前,避免不必要的消耗)
String sellIp = getPlayerIp(p);
if (sellIp != null) {
String ipSeg = getIpSegment(sellIp);
if (ipSeg != null && isSellRateLimited(ipSeg)) {
return; // 静默拦截
}
}
// ★ 补上禁止出售检查
if (item.getEffectiveSellPrice() <= 0) {
p.sendMessage("§c该商品不可出售");
@@ -2570,6 +2577,15 @@ public class ShopManager implements Listener {
}
}
int money = item.getEffectiveSellPrice() * total;
// ===== 记录IP段销售额 =====
if (sellIp != null) {
String ipSeg = getIpSegment(sellIp);
if (ipSeg != null) {
addToIpSegmentSales(ipSeg, money);
}
}
plugin.getBonds().addBonds(
p.getName(), money, "shop_sell",
item.getId(), "商店系统",
@@ -240,6 +240,29 @@ public class UserGroupManager {
}
}
/**
* Java本地直接删除用户组成员(用于PHP删除操作同步)
* 删除后推送到PHP确认
*/
public boolean removePlayerLocal(String player, String groupName) {
try {
PreparedStatement ps = db.prepareStatement(
"DELETE FROM user_group_member WHERE player_name=? AND LOWER(group_name)=LOWER(?)");
ps.setString(1, player);
ps.setString(2, groupName);
int rows = ps.executeUpdate();
ps.close();
if (rows > 0) {
// 推送删除到PHP确认
pushMemberToPHP(player, groupName, "remove");
}
return rows > 0;
} catch (SQLException e) {
plugin.getLogger().warning("[UserGroup] removePlayerLocal failed: " + e.getMessage());
return false;
}
}
/**
* 清除指定用户组的所有成员(本地操作,不推PHP)
* 用于PHP→Java同步时先清后写
+31 -5
View File
@@ -3818,14 +3818,40 @@ public class WebManager {
break;
}
case "group_change": {
// ★ PHP端用户组变更 → 从PHP拉取最新用户组+成员到Java本地
// ★ PHP端用户组变更 → 根据action分别处理
String action = String.valueOf(changeData.getOrDefault("action", ""));
String groupName = String.valueOf(changeData.getOrDefault("group_name", ""));
// 直接从PHP拉取完整用户组数据(比仅reload本地更可靠)
pullUserGroupsFromPHP();
// ★ 同时拉取成员数据
String player = String.valueOf(changeData.getOrDefault("player", ""));
if ("add_member".equals(action) && !player.isEmpty()) {
// 添加成员:从PHP拉取该组成员
pullGroupMembersFromPHP(groupName);
plugin.getLogger().info("[Web通信] PHP端用户组变更(" + action + ": " + groupName + "),已从PHP同步");
plugin.getLogger().info("[Web通信] PHP端添加用户组成员(" + player + " → " + groupName + "),已从PHP同步");
} else if ("remove_member".equals(action) && !player.isEmpty()) {
// 删除成员:直接从Java本地删除,并通知PHP确认
UserGroupManager ugm = plugin.getUserGroup();
if (ugm != null) {
boolean removed = ugm.removePlayerLocal(player, groupName);
if (removed) {
plugin.getLogger().info("[Web通信] PHP端删除用户组成员(" + player + " ← " + groupName + "),Java本地已删除");
} else {
plugin.getLogger().warning("[Web通信] PHP端删除用户组成员(" + player + " ← " + groupName + "),Java本地未找到该成员");
}
}
} else if ("delete".equals(action)) {
// 删除整个用户组:从PHP拉取(removeGroupsNotIn已处理)
pullUserGroupsFromPHP();
plugin.getLogger().info("[Web通信] PHP端删除用户组(" + groupName + "),已同步");
} else if ("update".equals(action)) {
// 更新用户组配置:从PHP拉取
pullUserGroupsFromPHP();
plugin.getLogger().info("[Web通信] PHP端更新用户组(" + groupName + "),已同步");
} else {
// 未知action,兜底全拉
pullUserGroupsFromPHP();
pullGroupMembersFromPHP(groupName);
plugin.getLogger().info("[Web通信] PHP端用户组变更(未知action=" + action + ": " + groupName + ")");
}
applied = true;
break;
}