簡體   English   中英

Minecraft Forge Mod 命令不起作用?

[英]Minecraft Forge Mod command isnt working?

我為我的世界 1.8.9 編寫了一個鍛造模組,如果玩家輸入命令,並且當我在單人游戲中輸入命令時,它會每 20 秒發送一條消息,但如果我在多人游戲中輸入命令,它會說:“未知命令。鍵入“help”以獲得幫助。 下面是命令類的代碼:

package AutoAd;

import java.util.Timer;
import java.util.TimerTask;

import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

public class CommandAutoAD extends CommandBase{

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

    @Override
    public String getCommandUsage(ICommandSender sender) {
        return "/startAutoad";
    }

    @Override
    public void processCommand(final ICommandSender sender, String[] args) throws CommandException {
        if(sender instanceof EntityPlayer) {
            Thread t = new Thread() {
                public void run() {
                    EntityPlayer player = (EntityPlayer) sender;
                    for(int i = 0; i<=20; i++) {
                        MSG(player, "Beacons, Karten, Banner und mehr bei /p h 5ty1ne");
                        try {
                            Thread.sleep(20000);
                        } catch (InterruptedException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                        MSG(player, "Karten, Banner, stackweise Eisenblöcke, Emeraldblöcke und mehr bei /p h 5ty1ne");
                        try {
                            Thread.sleep(20000);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        MSG(player, "Shop bei /p h 5ty1ne");
                        try {
                            Thread.sleep(20000);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        MSG(player, "Günstig für deinen Shop einkaufen? /p h 5ty1ne");
                        try {
                            Thread.sleep(20000);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
            };
            t.start();
        }
        else {
            sender.addChatMessage(new ChatComponentText("In der Konsole nicht verfügbar."));
        }
    }

    public void MSG(EntityPlayer player, String message) {
        Minecraft.getMinecraft().thePlayer.sendChatMessage(message);
    }
}

這是主要的代碼:

package AutoAd;

import net.minecraft.command.ServerCommandManager;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.ModMetadata;
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.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import proxy.ServerProxy;

@Mod(modid = AutoAD.MODID)

public class AutoAD {


    public static final String MODID = "autoad";
    @SidedProxy(clientSide = "proxy.ClientProxy", serverSide = "proxy.ServerProxy")
    public static ServerProxy proxy;

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {

    }

    @EventHandler
    public void init(FMLInitializationEvent event) {

    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {

    }
    @EventHandler
    public void registerCommands(FMLServerStartingEvent event) {
        ServerCommandManager manager = (ServerCommandManager) event.getServer().getCommandManager();
        manager.registerCommand(new CommandAutoAD());
    }
}

我想你在你的 Minecraft 客戶端上安裝了這個 mod,但沒有安裝在你的服務器上。 您可以使用 Minecraft Forge gradle 啟動本地開發服務器,或者編譯成 JAR 並將此 JAR 拖放到 Minecraft Forge 服務器的/mods文件夾中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM