feat: 领地边框粒子特效 + 强制游戏模式仅管理员可用

1. 进入/离开领地时展示3秒边框粒子(青色渐变DUST_COLOR_TRANSITION + 四角END_ROD高亮)
2. /protect info执行时展示5秒领地边框粒子
3. GUI强制游戏模式开关改为仅服务器管理员可操作(领地主不可操作)
This commit is contained in:
2026-07-12 16:45:22 +08:00
parent 0ff79aa959
commit 5d994c0dad
4 changed files with 240 additions and 7 deletions
@@ -333,6 +333,9 @@ public class AreaCLIManager {
"/protect settp " + land.name));
p.sendMessage(clickableAction("🔄", "过户领地(需要所有者权限)",
"/protect transfeland " + land.name));
// ★ 新增:领地公告管理
p.sendMessage(clickableAction("📢", "领地公告(进出提示消息)",
"/protect cli announcement " + land.name + " 1"));
p.sendMessage(Component.empty()
.append(Component.text("§a[◀ 返回列表]")
@@ -1594,4 +1597,127 @@ public class AreaCLIManager {
p.sendMessage(Component.text("§a已添加增益效果: §f" + desc));
areaProtect.saveAreaToDb(land);
}
// ==================== 领地公告管理 ====================
/**
* 领地公告管理主页面
* @param subPage 1=主菜单, 2=编辑进入消息, 3=编辑离开消息
*/
public void showAnnouncementManagement(Player p, String landName, int subPage) {
AreaProtection.AreaConfig land = areaProtect.getLand(landName);
if (land == null) {
p.sendMessage(Component.text("§c领地不存在: " + landName));
return;
}
// 权限检查
boolean isOwner = p.getName().equalsIgnoreCase(land.owner);
boolean isAdmin = areaProtect.isAreaAdmin(p);
if (!isOwner && !isAdmin) {
p.sendMessage(Component.text("§c需要领地所有者或管理员权限"));
return;
}
// ========== 主菜单 ==========
if (subPage == 1) {
p.sendMessage(header("领地公告: " + landName));
p.sendMessage(Component.text("§7配置玩家进出领地时的提示消息"));
p.sendMessage(Component.text("§7§l───────────────────────────────"));
// 显示当前进入消息
String enterMsg = (land.enterMsg != null && !land.enterMsg.isEmpty()) ? land.enterMsg : "§7(未设置)";
p.sendMessage(Component.text("§a进入消息: §f" + enterMsg));
p.sendMessage(Component.empty()
.append(Component.text("§e[编辑进入消息] ")
.hoverEvent(HoverEvent.showText(Component.text("§e点击编辑进入领地时的提示消息")))
.clickEvent(ClickEvent.runCommand("/protect cli announcement " + landName + " 2")))
.append(Component.text("§7点击编辑")));
p.sendMessage(Component.text(""));
// 显示当前离开消息
String leaveMsg = (land.leaveMsg != null && !land.leaveMsg.isEmpty()) ? land.leaveMsg : "§7(未设置)";
p.sendMessage(Component.text("§a离开消息: §f" + leaveMsg));
p.sendMessage(Component.empty()
.append(Component.text("§e[编辑离开消息] ")
.hoverEvent(HoverEvent.showText(Component.text("§e点击编辑离开领地时的提示消息")))
.clickEvent(ClickEvent.runCommand("/protect cli announcement " + landName + " 3")))
.append(Component.text("§7点击编辑")));
p.sendMessage(Component.text("§7§l───────────────────────────────"));
p.sendMessage(Component.text("§7提示: 使用 §f&7§l颜色代码 §7格式化消息"));
p.sendMessage(Component.text("§7例如: §f&a欢迎来到 §6领地名"));
// 返回按钮
p.sendMessage(clickableAction("◀", "返回领地管理", "/protect cli manage " + landName));
p.sendMessage(Component.text("§7§l───────────────────────────────"));
}
// ========== 编辑进入消息 ==========
else if (subPage == 2) {
p.sendMessage(header("编辑进入消息: " + landName));
p.sendMessage(Component.text("§7当前进入消息: §f" + (land.enterMsg != null && !land.enterMsg.isEmpty() ? land.enterMsg : "(空)")));
p.sendMessage(Component.text("§7§l───────────────────────────────"));
p.sendMessage(Component.text("§e请在聊天栏输入新的进入消息:"));
p.sendMessage(Component.text("§7输入 §c清空 §7可清除消息"));
// 标记等待输入
pendingEffectInput.put(p.getUniqueId(), new String[]{"announcement_enter", landName, ""});
savePageInfo(p, "announcement", landName, 2);
}
// ========== 编辑离开消息 ==========
else if (subPage == 3) {
p.sendMessage(header("编辑离开消息: " + landName));
p.sendMessage(Component.text("§7当前离开消息: §f" + (land.leaveMsg != null && !land.leaveMsg.isEmpty() ? land.leaveMsg : "(空)")));
p.sendMessage(Component.text("§7§l───────────────────────────────"));
p.sendMessage(Component.text("§e请在聊天栏输入新的离开消息:"));
p.sendMessage(Component.text("§7输入 §c清空 §7可清除消息"));
// 标记等待输入
pendingEffectInput.put(p.getUniqueId(), new String[]{"announcement_leave", landName, ""});
savePageInfo(p, "announcement", landName, 3);
}
}
/**
* 处理公告消息输入(在ChatEvent中调用)
*/
public boolean handleAnnouncementInput(Player p, String message) {
String[] pending = pendingEffectInput.get(p.getUniqueId());
if (pending == null) return false;
String type = pending[0];
String landName = pending[1];
if (!type.startsWith("announcement_")) return false;
AreaProtection.AreaConfig land = areaProtect.getLand(landName);
if (land == null) {
p.sendMessage(Component.text("§c领地不存在: " + landName));
pendingEffectInput.remove(p.getUniqueId());
return true;
}
String field = type.equals("announcement_enter") ? "enter_msg" : "leave_msg";
String value = message.equals("清空") ? "" : message;
// 保存到内存
if (type.equals("announcement_enter")) {
land.enterMsg = value;
} else {
land.leaveMsg = value;
}
// 保存到DB
areaProtect.saveAreaToDb(land);
p.sendMessage(Component.text("§a已保存" + (type.equals("announcement_enter") ? "进入" : "离开") + "消息: §f" + (value.isEmpty() ? "(已清空)" : value)));
pendingEffectInput.remove(p.getUniqueId());
// 返回公告管理页面
showAnnouncementManagement(p, landName, 1);
return true;
}
}
+15 -2
View File
@@ -1200,7 +1200,12 @@ public class AreaGUIManager implements Listener {
// ★ GUI模式不发送聊天消息
openLandSettings(p, landName);
} else if (raw == 15) {
// 切换强制游戏模式
// 切换强制游戏模式 —— 仅服务器管理员可操作
if (!areaProtect.isAreaAdmin(p)) {
p.sendMessage("§c仅服务器管理员可操作强制游戏模式");
openLandSettings(p, landName);
return;
}
if (land.enforceGameMode == null || land.enforceGameMode.isEmpty()) {
land.enforceGameMode = "SURVIVAL";
} else if ("SURVIVAL".equals(land.enforceGameMode)) {
@@ -1491,12 +1496,20 @@ public class AreaGUIManager implements Listener {
"",
"§e点击切换"));
// 强制游戏模式(位置15)
// 强制游戏模式(位置15)—— 仅服务器管理员可操作
boolean isAdmin = areaProtect.isAreaAdmin(p);
if (isAdmin) {
String modeStr = land.enforceGameMode != null ? land.enforceGameMode : "无";
inv.setItem(15, createItem(Material.COMPASS, "§e§l强制游戏模式",
"§7当前模式: §f" + modeStr,
"",
"§e点击切换: 生存→创造→冒险→旁观→无"));
} else {
inv.setItem(15, createItem(Material.BARRIER, "§7§l强制游戏模式",
"§7当前模式: §f" + (land.enforceGameMode != null ? land.enforceGameMode : "无"),
"",
"§c仅服务器管理员可操作"));
}
// ★ 设置传送点(位置31)
inv.setItem(31, createItem(Material.ENDER_PEARL, "§a§l设置传送点",
@@ -3034,6 +3034,11 @@ public class AreaProtection implements Listener {
p.sendMessage(formatAreaMsg(oldAc.leaveMsg));
}
// ★ 离开领地时展示边框粒子(3秒)
if (oldAc != null) {
showBorderBrief(p, oldAc);
}
// 收标
List<PotionEffectType> marked =
playerMarkedEffects.remove(uid);
@@ -3147,6 +3152,8 @@ public class AreaProtection implements Listener {
p.sendMessage(
formatAreaMsg(newAc.enterMsg));
}
// ★ 进入领地时展示边框粒子(3秒)
showBorderBrief(p, newAc);
// ★ 公共建筑设施:访客自动获得传送、免疫伤害、攻击敌对生物权限
if (newAc.isPublicBuilding && !p.getName().equalsIgnoreCase(newAc.owner) && !isAreaAdmin(p)) {
p.sendMessage("§a§l[公共建筑] §f欢迎来到公共设施: §e" + newAc.name);
@@ -4210,6 +4217,10 @@ public class AreaProtection implements Listener {
&& !fromArea.leaveMsg.isEmpty()) {
p.sendMessage(formatAreaMsg(fromArea.leaveMsg));
}
// ★ 离开领地时展示边框粒子(3秒)
if (fromArea != null) {
showBorderBrief(p, fromArea);
}
}
// ===== 进入新区域 =====
@@ -4237,6 +4248,11 @@ public class AreaProtection implements Listener {
p.sendMessage(formatAreaMsg(toArea.enterMsg));
}
// ★ 进入领地时展示边框粒子(3秒)
if (toArea != null) {
showBorderBrief(p, toArea);
}
// 发放效果
if (toArea != null) {
/* plugin.getLogger().info(
@@ -4324,6 +4340,64 @@ public class AreaProtection implements Listener {
return areas.keySet();
}
// ==================== 领地边框粒子展示 ====================
/**
* 向玩家展示领地边框粒子特效(只展示给指定玩家)
* @param ac 领地配置
* @param durationTicks 持续tick数(20tick=1秒)
*/
public void showBorderParticles(Player p, AreaConfig ac, int durationTicks) {
if (ac == null) return;
World world = Bukkit.getWorld(ac.world);
if (world == null) return;
int minX = Math.min(ac.x1, ac.x2);
int maxX = Math.max(ac.x1, ac.x2);
int minZ = Math.min(ac.z1, ac.z2);
int maxZ = Math.max(ac.z1, ac.z2);
Particle.DustTransition dust = new Particle.DustTransition(org.bukkit.Color.fromRGB(0, 255, 255), org.bukkit.Color.fromRGB(255, 255, 0), 1.2f);
// 每20tick刷新一次粒子(共durationTicks/20次)
int rounds = Math.max(1, durationTicks / 20);
for (int i = 0; i < rounds; i++) {
final int round = i;
new org.bukkit.scheduler.BukkitRunnable() {
@Override
public void run() {
if (!p.isOnline()) { cancel(); return; }
// 在玩家Y层展示四条边
int playerY = p.getLocation().getBlockY();
int y = Math.max(ac.yMin, Math.min(playerY, ac.yMax));
// 四条边
for (int x = minX; x <= maxX; x += 2) {
p.spawnParticle(Particle.DUST_COLOR_TRANSITION, new Location(world, x + 0.5, y, minZ + 0.5), 1, dust);
p.spawnParticle(Particle.DUST_COLOR_TRANSITION, new Location(world, x + 0.5, y, maxZ + 0.5), 1, dust);
}
for (int z = minZ; z <= maxZ; z += 2) {
p.spawnParticle(Particle.DUST_COLOR_TRANSITION, new Location(world, minX + 0.5, y, z + 0.5), 1, dust);
p.spawnParticle(Particle.DUST_COLOR_TRANSITION, new Location(world, maxX + 0.5, y, z + 0.5), 1, dust);
}
// 四个角高亮
p.spawnParticle(Particle.END_ROD, new Location(world, minX + 0.5, y, minZ + 0.5), 3);
p.spawnParticle(Particle.END_ROD, new Location(world, maxX + 0.5, y, minZ + 0.5), 3);
p.spawnParticle(Particle.END_ROD, new Location(world, minX + 0.5, y, maxZ + 0.5), 3);
p.spawnParticle(Particle.END_ROD, new Location(world, maxX + 0.5, y, maxZ + 0.5), 3);
}
}.runTaskLater(plugin, round * 20L);
}
}
/**
* 短时间展示领地边框(进入/离开时,3秒)
*/
public void showBorderBrief(Player p, AreaConfig ac) {
showBorderParticles(p, ac, 60); // 3秒
}
/** 获取所有用户组名(tab补全用) */
public List<String> getUserGroupNames() {
List<String> names = new ArrayList<>();
@@ -5958,6 +6032,18 @@ public class AreaProtection implements Listener {
}
plugin.areaCLIManager.startEditGiveEffect(p, args[2], args[3], args[4]);
break;
case "announcement":
// ★ 领地公告管理
if (args.length < 3) {
p.sendMessage("§c用法: /protect cli announcement <领地名> [子页]");
break;
}
int annPage = 1;
if (args.length >= 4) {
try { annPage = Integer.parseInt(args[3]); } catch (Exception ignored) {}
}
plugin.areaCLIManager.showAnnouncementManagement(p, args[2], annPage);
break;
case "create":
// 跳转到创建命令
// 直接转发
@@ -7590,6 +7676,8 @@ public class AreaProtection implements Listener {
} else if (level == PermissionLevel.VISITOR) {
p.sendMessage("§7(你是此领地的访客)");
}
// ★ info时展示领地边框粒子(5秒)
showBorderParticles(p, ac, 100);
return true;
}
+6
View File
@@ -3035,6 +3035,12 @@ public class Main extends JavaPlugin
return;
}
// ★ 领地公告管理输入拦截(CLI输入进出消息)
if (areaCLIManager != null && areaCLIManager.handleAnnouncementInput(p, msg)) {
e.setCancelled(true);
return;
}
// ★ 过户领地输入拦截(CLI输入新所有者名)
if (areaProtection != null && areaProtection.handleTransferInput(p, msg)) {
e.setCancelled(true);