0
所以我做了一個實現了ICommand的類,並將其註冊到了我的ServerStarting事件中。當我嘗試在Minecraft中執行該命令時,我得到了一個沒有權限的錯誤。這裏是我的ICommand實現類:我在Forge 1.12.1中的自定義命令不起作用
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
有沒有辦法檢查玩家是操作還是有權限節點? –
對Ops和命令名使用ICommandSender.canUseCommand和權限級別4。你在說什麼權限系統? 「Minecraft」和「Forge」都沒有內置。 – Shadowfacts