修复denyMove权限检查、成员管理操作修改、优化任务队列优先级、登录轮询改为事件驱动
This commit is contained in:
@@ -204,8 +204,8 @@ public class AreaGUIManager implements Listener {
|
|||||||
int slot = i - start;
|
int slot = i - start;
|
||||||
|
|
||||||
ItemStack memberItem = createItem(Material.PLAYER_HEAD, "§a§l" + member,
|
ItemStack memberItem = createItem(Material.PLAYER_HEAD, "§a§l" + member,
|
||||||
"§7左键: 移除成员",
|
"§7左键: 编辑权限",
|
||||||
"§7右键: 传送到玩家");
|
"§7右键: 移除成员");
|
||||||
SkullMeta skull = (SkullMeta) memberItem.getItemMeta();
|
SkullMeta skull = (SkullMeta) memberItem.getItemMeta();
|
||||||
if (skull != null) {
|
if (skull != null) {
|
||||||
skull.setOwningPlayer(Bukkit.getOfflinePlayer(member));
|
skull.setOwningPlayer(Bukkit.getOfflinePlayer(member));
|
||||||
@@ -517,20 +517,13 @@ public class AreaGUIManager implements Listener {
|
|||||||
if (raw >= 0 && raw < (end - start)) {
|
if (raw >= 0 && raw < (end - start)) {
|
||||||
String member = memberList.get(start + raw);
|
String member = memberList.get(start + raw);
|
||||||
if (event.isLeftClick()) {
|
if (event.isLeftClick()) {
|
||||||
// 移除成员
|
// 左键:编辑权限(打开访客权限页面)
|
||||||
|
openVisitorPerm(p, landName, 0);
|
||||||
|
} else if (event.isRightClick()) {
|
||||||
|
// 右键:移除成员
|
||||||
areaProtect.removeLandMember(landName, member);
|
areaProtect.removeLandMember(landName, member);
|
||||||
p.sendMessage("§a已移除成员: " + member);
|
p.sendMessage("§a已移除成员: " + member);
|
||||||
openMemberList(p, landName, page);
|
openMemberList(p, landName, page);
|
||||||
} else if (event.isRightClick()) {
|
|
||||||
// 传送到玩家
|
|
||||||
Player target = Bukkit.getPlayer(member);
|
|
||||||
if (target != null) {
|
|
||||||
p.closeInventory();
|
|
||||||
p.teleport(target.getLocation());
|
|
||||||
p.sendMessage("§a已传送到: " + member);
|
|
||||||
} else {
|
|
||||||
p.sendMessage("§c玩家不在线");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (raw == 45) {
|
} else if (raw == 45) {
|
||||||
openAddMember(p, landName);
|
openAddMember(p, landName);
|
||||||
|
|||||||
@@ -2332,6 +2332,12 @@ public class AreaProtection implements Listener {
|
|||||||
if (newArea != null) {
|
if (newArea != null) {
|
||||||
AreaConfig ac = areas.get(newArea);
|
AreaConfig ac = areas.get(newArea);
|
||||||
if (ac != null) {
|
if (ac != null) {
|
||||||
|
// ★ denyMove检查:无OWNER/ADMIN权限的玩家不能移动
|
||||||
|
if (ac.denyMove && !hasPermission(p, ac, PermissionLevel.OWNER)) {
|
||||||
|
event.setTo(event.getFrom());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// ★ 每次移动都清除指定效果
|
// ★ 每次移动都清除指定效果
|
||||||
clearBadEffects(p, ac);
|
clearBadEffects(p, ac);
|
||||||
|
|
||||||
@@ -2459,6 +2465,12 @@ public class AreaProtection implements Listener {
|
|||||||
|
|
||||||
AreaConfig newAc = areas.get(newArea);
|
AreaConfig newAc = areas.get(newArea);
|
||||||
if (newAc != null) {
|
if (newAc != null) {
|
||||||
|
// ★ denyMove检查:无OWNER/ADMIN权限的玩家不能进入
|
||||||
|
if (newAc.denyMove && !hasPermission(p, newAc, PermissionLevel.OWNER)) {
|
||||||
|
event.setTo(event.getFrom());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (newAc.enterMsg != null
|
if (newAc.enterMsg != null
|
||||||
&& !newAc.enterMsg.isEmpty()) {
|
&& !newAc.enterMsg.isEmpty()) {
|
||||||
p.sendMessage(
|
p.sendMessage(
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ public class WebManager {
|
|||||||
|
|
||||||
// ★ 数据库写入排队系统(防止并发SQLite操作导致database is locked)
|
// ★ 数据库写入排队系统(防止并发SQLite操作导致database is locked)
|
||||||
private static final int LOGIN_PRIORITY = 1; // 登录相关操作最高优先级
|
private static final int LOGIN_PRIORITY = 1; // 登录相关操作最高优先级
|
||||||
|
private static final int SHOP_PRIORITY = 5; // 商店操作第二优先级
|
||||||
private static final int NORMAL_PRIORITY = 10; // 普通同步操作低优先级
|
private static final int NORMAL_PRIORITY = 10; // 普通同步操作低优先级
|
||||||
private final PriorityBlockingQueue<DbTask> dbTaskQueue = new PriorityBlockingQueue<>();
|
private final PriorityBlockingQueue<DbTask> dbTaskQueue = new PriorityBlockingQueue<>();
|
||||||
private final AtomicInteger dbTaskIdGen = new AtomicInteger(0);
|
private final AtomicInteger dbTaskIdGen = new AtomicInteger(0);
|
||||||
@@ -183,6 +184,13 @@ public class WebManager {
|
|||||||
submitDbTask(NORMAL_PRIORITY, name, action);
|
submitDbTask(NORMAL_PRIORITY, name, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交商店相关数据库写入任务(第二优先级)
|
||||||
|
*/
|
||||||
|
private void submitShopDbTask(String name, Runnable action) {
|
||||||
|
submitDbTask(SHOP_PRIORITY, name, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提交指定优先级的数据库写入任务
|
* 提交指定优先级的数据库写入任务
|
||||||
*/
|
*/
|
||||||
@@ -468,6 +476,8 @@ public class WebManager {
|
|||||||
requestImmediateTransactionPull();
|
requestImmediateTransactionPull();
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(plugin);
|
}.runTaskAsynchronously(plugin);
|
||||||
|
// ★ 事件驱动:PHP回调时触发一次登录轮询
|
||||||
|
triggerLoginPoll();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果不是notify_sync,处理注册回调
|
// 如果不是notify_sync,处理注册回调
|
||||||
@@ -3076,6 +3086,9 @@ public class WebManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskLater(plugin, 100L);
|
}.runTaskLater(plugin, 100L);
|
||||||
|
|
||||||
|
// ★ 事件驱动:玩家加入时触发一次登录轮询
|
||||||
|
triggerLoginPoll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3221,10 +3234,22 @@ public class WebManager {
|
|||||||
public void startWebLoginPolling() {
|
public void startWebLoginPolling() {
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
|
|
||||||
new BukkitRunnable() {
|
// ★ 改为事件驱动模式:不再主动轮询
|
||||||
@Override
|
// 玩家加入时触发一次轮询,PHP回调时触发一次轮询
|
||||||
public void run() {
|
// 登录完成后如果没有玩家还在登录则静默
|
||||||
// 登录操作通过DB队列串行化,高优先级
|
plugin.getLogger().info("[Web通信] Web登录轮询已切换为事件驱动模式(玩家加入/PHP回调时触发)");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触发一次登录轮询(事件驱动)
|
||||||
|
* 由玩家加入服务器或PHP回调时调用
|
||||||
|
*/
|
||||||
|
public void triggerLoginPoll() {
|
||||||
|
if (!enabled) return;
|
||||||
|
|
||||||
|
// 检查是否有玩家正在登录
|
||||||
|
if (!hasPendingLogins()) return;
|
||||||
|
|
||||||
submitDbTask("登录轮询-pollWebLoginConfirmations", () -> {
|
submitDbTask("登录轮询-pollWebLoginConfirmations", () -> {
|
||||||
try {
|
try {
|
||||||
pollWebLoginConfirmations();
|
pollWebLoginConfirmations();
|
||||||
@@ -3248,9 +3273,13 @@ public class WebManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}.runTaskTimer(plugin, 100L, 100L); // 5秒一次(100 ticks)
|
|
||||||
|
|
||||||
plugin.getLogger().info("[Web通信] Web登录轮询已启动(每5秒,通过DB队列串行化,高优先级)");
|
/**
|
||||||
|
* 检查是否有待处理的登录请求
|
||||||
|
*/
|
||||||
|
private boolean hasPendingLogins() {
|
||||||
|
// 检查是否有玩家正在等待登录确认
|
||||||
|
return !tokenStore.isEmpty() || Bukkit.getOnlinePlayers().size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user