简体   繁体   中英

Minecraft Forge Mod command isnt working?

I programmed a forge mod for minecraft 1.8.9 which sends a message every 20 seconds if the player typed in the command and when I type in the command in singleplayer it is working, but if I type the command in in multiplayer it says: "Unknown command. Type "help" for help". Here is the code of the command class:

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);
    }
}

and here is the code of the main:

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());
    }
}

I imagine that you have this mod installed on your Minecraft Client but not on your server. You can start a local development server using the Minecraft Forge gradle, or by compiling into a JAR and dragging and dropping this JAR into the /mods folder of a Minecraft Forge server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM