From f27b1760960e7f4ab8a94bf7b48073893be97ff6 Mon Sep 17 00:00:00 2001 From: CNLuminous Date: Fri, 8 Aug 2025 01:36:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugin):=20=E6=B7=BB=E5=8A=A0=E7=8E=A9?= =?UTF-8?q?=E5=AE=B6=E5=9D=90=E6=A0=87=E5=8F=8D=E9=A6=88=E5=92=8C=E8=BE=B9?= =?UTF-8?q?=E7=95=8C=E9=99=90=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 GetLocationCommand 类,实现 /getloc 命令显示玩家坐标- 添加 X 和 Z 轴的边界限制,超出范围自动传送到 spawn 点 - 优化 Y 轴虚空限制,调整为 minY 变量 -为玩家提供友好的提示信息 --- .../java/com/blockfantasy/LimboBackSpawn.java | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/blockfantasy/LimboBackSpawn.java b/src/main/java/com/blockfantasy/LimboBackSpawn.java index c38115a..201a29e 100644 --- a/src/main/java/com/blockfantasy/LimboBackSpawn.java +++ b/src/main/java/com/blockfantasy/LimboBackSpawn.java @@ -1,6 +1,8 @@ package com.blockfantasy; import com.loohp.limbo.Limbo; +import com.loohp.limbo.commands.CommandExecutor; +import com.loohp.limbo.commands.CommandSender; import com.loohp.limbo.events.EventHandler; import com.loohp.limbo.events.Listener; import com.loohp.limbo.events.player.PlayerMoveEvent; @@ -11,21 +13,69 @@ import com.loohp.limbo.plugins.LimboPlugin; public class LimboBackSpawn extends LimboPlugin implements Listener { public static LimboBackSpawn instance; public static Location spawn; + + public static int maxX = 100; + public static int minY = -10; + public static int maxZ = 100; + @Override public void onEnable() { instance = this; spawn = instance.getServer().getServerProperties().getWorldSpawn(); Limbo.getInstance().getEventsManager().registerEvents(this,new LimboBackSpawnListener()); + Limbo.getInstance().getPluginManager().registerCommands(this,new GetLocationCommand()); } + public static class LimboBackSpawnListener implements Listener { @EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - if (event.getPlayer().getLocation().getY() < -10) { + double originX = player.getLocation().getX() - spawn.getX(); + double originZ = player.getLocation().getZ() - spawn.getZ(); + + if (originX > maxX || originX < -maxX){ + player.teleport(spawn); + player.sendMessage("§b[BlockFantasy]§c不要乱跑鸥~"); + } + if (originZ > maxZ || originZ < -maxZ){ + player.teleport(spawn); + player.sendMessage("§b[BlockFantasy]§c不要乱跑鸥~"); + + } + if (player.getLocation().getY() < minY) { player.teleport(spawn); player.sendMessage("§b[BlockFantasy]§c掉虚空了?我给你拽回来~"); } } } + + public static class GetLocationCommand implements CommandExecutor{ + @Override + public void execute(CommandSender sender, String[] args) { + if (args[0].equalsIgnoreCase("getloc")){ + if (!(sender instanceof Player player)) { + sender.sendMessage("§c只有玩家可以执行此命令"); + return; + } + if (!player.hasPermission("blockfantasy.getloc")){ + player.sendMessage("§c您没有权限执行此命令"); + return; + } + double originX = player.getLocation().getX() - spawn.getX(); + double originZ = player.getLocation().getZ() - spawn.getZ(); + + + Location location = player.getLocation(); + player.sendMessage("§b[BlockFantasy]§a您当前的坐标是: " + + "X: " + String.format("%.2f", location.getX()) + + ", Y: " + String.format("%.2f", location.getY()) + + ", Z: " + String.format("%.2f", location.getZ()) + + ", originX: " + String.format("%.2f", originX) + + ", originZ: " + String.format("%.2f", originZ) + + ); + } + } + } }