我正在为 1.8.9 开发一些我的世界模组。 我试图创建的是简单地向发件人发送消息的命令。
这是命令类和主类的代码
命令类:
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 这样的多人游戏服务器。 它说“未知命令”
我不知道该怎么做
有人可以帮我在多人服务器中使用这个命令吗?
最佳答案
您需要覆盖 getRequiredPermissionLevel()
方法来自CommandBase
让它在多人游戏中运行。
@Override
public int getRequiredPermissionLevel() {
return 0;
}
关于java - Minecraft 1.8.9 中的 Modded 命令在多人游戏服务器中不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62243223/