Modded Command in Minecraft 1.8.9 命令不存在于多人服务器中。

问题描述 投票:0回答:1

我正在为1.8.9开发一些minecraft mod.我试图创建的是命令,简单地发送消息给发送者。

下面是命令类和主类的代码。

命令类。

package happyandjust.happymod.commands;

import java.util.HashMap;
import java.util.List;

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;

public class Command extends CommandBase {

    private HashMap<String, String> collection = new HashMap<String, String>();

    @Override
    public String getCommandName() {
        return "collection";
    }

    @Override
    public String getCommandUsage(ICommandSender sender) {
        return "collection <enchant name>";
    }

    @Override
    public void processCommand(ICommandSender sender, String[] args) throws CommandException {

        collection.put("harvesting", "Wheat Collection Level 2");
        collection.put("cubism", "Pumpkin Collection Level 5");

        if (args.length < 1) {
            sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Usage: /collection [Enchant Name]"));
            return;
        }

        if (args.length == 1) {
            String enchant_name = args[0].toLowerCase();
            String collec = collection.get(enchant_name);
            if (collec == null) {
                sender.addChatMessage(new ChatComponentText(
                        EnumChatFormatting.RED + enchant_name.toUpperCase() + " is not valid Enchant Name"));
                return;
            }
            sender.addChatMessage(new ChatComponentText(
                    EnumChatFormatting.GREEN + enchant_name.toUpperCase() + " is at " + collection.get(enchant_name)));
        }

    }

    @Override
    public boolean canCommandSenderUseCommand(ICommandSender sender) {
        return true;

    }

}

主类:

package happyandjust.happymod.main;

import happyandjust.happymod.commands.Command;
import happyandjust.happymod.proxy.CommonProxy;
import happyandjust.happymod.util.Reference;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;

@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)

public class HappyMod {

    @Instance
    public static HappyMod instance;

    @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.COMMON_PROXY_CLASS)
    public static CommonProxy proxy;

    @EventHandler
    public static void preInit(FMLPostInitializationEvent e) {
    }

    @EventHandler
    public static void init(FMLInitializationEvent e) {
        ClientCommandHandler.instance.registerCommand(new Command());
    }

    @EventHandler
    public static void postInit(FMLPostInitializationEvent e) {

    }

}

但如果我去多人服务器,比如hypixel,它就会显示 "未知命令"

我不知道该怎么做

谁能帮我在多人服务器中使用这个命令?

java minecraft minecraft-forge
1个回答
0
投票

你需要覆盖 getRequiredPermissionLevel() 方法从 CommandBase 为了让它在多人游戏中工作。

@Override
public int getRequiredPermissionLevel() {
    return 0;
}
© www.soinside.com 2019 - 2024. All rights reserved.