首页 > 解决方案 > Spigot忽略命令的第一个参数

问题描述

我正在为我的 Minecraft 服务器创建一个/home命令,但我在让它工作时遇到了一些麻烦。对于普通玩家,他们可以输入/home来清除他们的库存,切换到冒险模式并进入 spawn(这很有效)。对于管理员来说,应该发生的事情是他们可以输入/home op进入管理基地,或者输入/home spawn进入 spawn。如果他们不提供参数,它将默认为管理员库。所有这些都有效,除了 home 命令中的任何参数都会将管理员带入管理员库,甚至/home spawn。我怀疑这个论点被完全忽略了,但我不知道如何解决它。

package com.epizy.alephnull.homecommand;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.Location;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import com.epizy.alephnull.homecommand.Main;

public class Home implements CommandExecutor {

    public Home(Main main)
    {
        main.getCommand("home").setExecutor(this);
    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if (!(sender instanceof Player))
        {
            sender.sendMessage("You must be a player to execute this command.");
            return true;
        }
        Player temp = (Player)sender;
        if (temp.isOp())
        {
            if (args.length == 0)
            {
                temp.teleport(new Location(Bukkit.getServer().getWorld("world"), 0, 218, 0));
                return true;
            }
            else if (args[0] == "op")
            {
                temp.teleport(new Location(Bukkit.getServer().getWorld("world"), 0, 218, 0));
                return true;
            }
            else if (args[0] == "spawn")
            {
                temp.teleport(new Location(Bukkit.getServer().getWorld("world"), 0, 250, 0));
                return true;
            }

        }
        else
        {

            temp.setGameMode(GameMode.ADVENTURE);
            temp.getInventory().clear();
            temp.updateInventory();
            temp.teleport(new Location(Bukkit.getServer().getWorld("world"), 0, 250, 0));
            return true;
        }
        return true;
    }

}

标签: javaminecraftbukkit

解决方案


推荐阅读