java - 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;
}
}
解决方案
推荐阅读
- php - 如何在 python 中从 php 创建 str_shuffle
- go - 发送带有标题文本的二进制数据
- python - Psycopg2 INSERT 变量,字符串格式错误
- c# - 在 Web API 2 的自定义活页夹中使用默认 IModelBinder
- reflection - Kotlin 对对象实例的反射
- azure-cosmosdb - 中止 WaitAndRetryAsync 策略?
- python - 在解释器工作时确定下一个要执行的脚本
- angularjs - 使用计时器时角度图表不实时更新图表
- python - 散景:绘制频谱图
- python - matplotlib/hist2d 生成的绘图在屏幕和 pdf 文件上看起来不同