This commit is contained in:
xzy XU917128zccx@163.com 2025-06-22 00:17:17 +08:00
parent fdf0e18773
commit 963a0e504e
2 changed files with 65 additions and 4 deletions

View File

@ -1,11 +1,18 @@
package com.ijh;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
public final class Ijhp_main extends JavaPlugin {
@Override
@ -19,12 +26,12 @@ public final class Ijhp_main extends JavaPlugin {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!sender.hasPermission("ijhplugin.mp")) {
sender.sendMessage("§暂无权限!");
sender.sendMessage("§插件缺少权限!");
return true;
}
if (args.length == 0) {
sender.sendMessage("§a§lIJHTest §7- §f插件版本 1.0");
sender.sendMessage("§6Usage: §f/mp <help|info|teleport>");
sender.sendMessage("§a§lMCSC-Test §7- §f插件版本 1.0");
sender.sendMessage("§6Usage: §f/mp <少羽眉目|teleport>");
return true;
}
@ -36,6 +43,7 @@ public final class Ijhp_main extends JavaPlugin {
sender.sendMessage("/mp help §f- 显示帮助信息");
sender.sendMessage("/mp info §f- 显示插件信息");
sender.sendMessage("/mp teleport §f- 传送");
sender.sendMessage("/mp lobby §f- 传送主城");
return true;
case "info":
@ -45,7 +53,7 @@ public final class Ijhp_main extends JavaPlugin {
case "teleport":
if (sender instanceof Player) {
Player pl = (Player) sender;
// 实现传送逻辑示例传送到出生点
// 传送
pl.teleport(pl.getWorld().getSpawnLocation());
pl.sendMessage("你已经被传送!");
} else {
@ -64,4 +72,53 @@ public final class Ijhp_main extends JavaPlugin {
System.out.println("Test off");
// Plugin shutdown logic
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (args.length == 1) {
return Arrays.asList("help", "info", "teleport");
}
// teleport子命令
if (args.length == 2 && "teleport".equalsIgnoreCase(args[0])) {
return Arrays.asList("spawn", "lobby");
}
return new ArrayList<>();
}
private void teleportToWorld(Player player, String worldAlias) {
// 获取实际世界名称
int worldAliases = 0;
String worldName = String.valueOf(worldAliases);
World targetWorld = Bukkit.getWorld(worldName);
if (targetWorld == null) {
player.sendMessage("§c世界 '" + worldName + "' 未找到或未加载!");
return;
}
// 获取玩家当前世界
World currentWorld = player.getWorld();
// 若已在目标世界
if (currentWorld.equals(targetWorld)) {
player.sendMessage("§a你已经在 " + worldAlias + " 世界!");
return;
}
// 获取目标出生点
Location spawnLocation = targetWorld.getSpawnLocation();
// 安全传送
spawnLocation = findSafeLocation(spawnLocation);
// 执行传送
player.teleport(spawnLocation);
player.sendMessage("§a已传送到 " + worldAlias + " 世界!");
}
private Location findSafeLocation(Location spawnLocation) {
return spawnLocation;
}
}

View File

@ -0,0 +1,4 @@
package com.ijh;
public class string {
}