我在 Forge 1.12.1 中的自定义命令不起作用
My custom command in Forge 1.12.1 is not working
所以我制作了一个 class 来实现 ICommand 并将其注册到我的 ServerStarting 事件中。当我尝试在 Minecraft 中执行命令时,出现无权限错误。这是我实现的 ICommand class:
List aliases;
public CMinecraftStoryMod() {
aliases = new ArrayList();
aliases.add("msm");
}
@Override
public String getName() {
return "minecraftstorymod";
}
@Override
public String getUsage(ICommandSender sender) {
if (sender.getEntityWorld().isRemote) {
return "/minecraftstorymod";
} else {
return "/minecraftstorymod";
}
}
@Override
public List<String> getAliases() {
return aliases;
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (!MinecraftStoryMod.gameInProgress) {
MinecraftStoryMod.gameInProgress = true;
if (sender.getEntityWorld().isRemote) {
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Attempting to start game in a multiplayer world..."));
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Checking out the number of players in this world..."));
if (server.getPlayerList().getCurrentPlayerCount() > 0) {
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] There are " + server.getPlayerList().getCurrentPlayerCount() + " players in the server! Generating fun..."));
MinecraftStoryMod.gameHandler.startGame(server.getPlayerList());
} else {
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] The server has 0 players!"));
MinecraftStoryMod.gameInProgress = false;
return;
}
} else {
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Singleplayer mode for this mod is still under construction. We're sowwy :)"));
return;
}
} else {
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Another game is in progress! Wait for it ._."));
}
}
@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
return false;
}
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
return null;
}
@Override
public boolean isUsernameIndex(String[] args, int index) {
return false;
}
@Override
public int compareTo(ICommand o) {
return 0;
}
我知道我正确注册了命令,因为我可以在游戏中输入 /minecraftstorymod。我正在使用 Forge 1.12.1 14.22.0.2469
您总是从 checkPermission
方法 returning false
,这意味着没有人有权执行该命令。如果您希望任何人都能够执行命令,您总是可以 return true
或 return 根据发件人的不同值。
所以我制作了一个 class 来实现 ICommand 并将其注册到我的 ServerStarting 事件中。当我尝试在 Minecraft 中执行命令时,出现无权限错误。这是我实现的 ICommand class:
List aliases;
public CMinecraftStoryMod() {
aliases = new ArrayList();
aliases.add("msm");
}
@Override
public String getName() {
return "minecraftstorymod";
}
@Override
public String getUsage(ICommandSender sender) {
if (sender.getEntityWorld().isRemote) {
return "/minecraftstorymod";
} else {
return "/minecraftstorymod";
}
}
@Override
public List<String> getAliases() {
return aliases;
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (!MinecraftStoryMod.gameInProgress) {
MinecraftStoryMod.gameInProgress = true;
if (sender.getEntityWorld().isRemote) {
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Attempting to start game in a multiplayer world..."));
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Checking out the number of players in this world..."));
if (server.getPlayerList().getCurrentPlayerCount() > 0) {
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] There are " + server.getPlayerList().getCurrentPlayerCount() + " players in the server! Generating fun..."));
MinecraftStoryMod.gameHandler.startGame(server.getPlayerList());
} else {
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] The server has 0 players!"));
MinecraftStoryMod.gameInProgress = false;
return;
}
} else {
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Singleplayer mode for this mod is still under construction. We're sowwy :)"));
return;
}
} else {
sender.sendMessage(new TextComponentString("[CMinecraftStoryMod] Another game is in progress! Wait for it ._."));
}
}
@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
return false;
}
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
return null;
}
@Override
public boolean isUsernameIndex(String[] args, int index) {
return false;
}
@Override
public int compareTo(ICommand o) {
return 0;
}
我知道我正确注册了命令,因为我可以在游戏中输入 /minecraftstorymod。我正在使用 Forge 1.12.1 14.22.0.2469
您总是从 checkPermission
方法 returning false
,这意味着没有人有权执行该命令。如果您希望任何人都能够执行命令,您总是可以 return true
或 return 根据发件人的不同值。