feat(plugin): 添加玩家坐标反馈和边界限制功能

- 新增 GetLocationCommand 类,实现 /getloc 命令显示玩家坐标- 添加 X 和 Z 轴的边界限制,超出范围自动传送到 spawn 点
- 优化 Y 轴虚空限制,调整为 minY 变量
-为玩家提供友好的提示信息
This commit is contained in:
CNLuminous 2025-08-08 01:36:00 +08:00
parent c185d0d9a3
commit f27b176096
1 changed files with 51 additions and 1 deletions

View File

@ -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)
);
}
}
}
}