Jump to content

ICommand not recognizing when on server


Bets

Recommended Posts

It's pretty straight forward here.

When I play in a singleplayer world the command works, you can find it using TAB as-well. But when I play on multiplayer the command does not work at all, like it doesn't exist.

Do I need to configure it to work on a server too somehow? I am extending CommandBase in my class file.

Link to comment
Share on other sites

It sounds like you're only registering it on the client. You need to register your commands on both physical sides in FMLServerStartingEvent, which needs to be handled by a @Mod.EventHandler method in your @Mod class.

 

If you're doing this and it's still not working, post your code.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

1 hour ago, Choonster said:

It sounds like you're only registering it on the client. You need to register your commands on both physical sides in FMLServerStartingEvent, which needs to be handled by a @Mod.EventHandler method in your @Mod class.

 

If you're doing this and it's still not working, post your code.

 

 

Yeah this is what I was doing:

    @EventHandler
    public void serverLoad(FMLServerStartingEvent event) {
        event.registerServerCommand(new testCommand());
    }

 

Link to comment
Share on other sites

5 minutes ago, Choonster said:

Is this in your @Mod class? Are there any errors in the log?

 

Post the testCommand class.

 
 

If by @Mod class you mean the main class that has the mod name in it, then yes, it is.

 

This is the test command class:

public class testCommand extends CommandBase {
    @Override
    public String getCommandName() {
        return "test";
    }
    @Override
    public String getCommandUsage(ICommandSender sender) {
        return "/<command>";
    }
    
    @Override
    public int getRequiredPermissionLevel() {
        return 0;
    }
    
    @Override
    public boolean canCommandSenderUseCommand(ICommandSender sender) {
        return true;
    }
    @Override
    public void processCommand(ICommandSender sender, String[] args) throws CommandException {
        if (sender instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) sender;
            player.addChatComponentMessage(new ChatComponentText("Works!"));
        }
    }
}

 

Link to comment
Share on other sites

2 minutes ago, diesieben07 said:

And the names FMLServerStartingEvent and registerServerCommand did not make you suspicious then? O.o

For client-side commands you need to use ClientCommandHandler.

 

Changed it to this one:

    @EventHandler
    public void serverLoad(ClientCommandHandler event) {
        event.registerCommand(new testCommand());
    }

 

Now it doesn't work not in single and not on multiplayer.

I think I tried using this before and it just didn't work so I used the server one.

Link to comment
Share on other sites

21 minutes ago, Bets said:

Changed it to this one:


    @EventHandler
    public void serverLoad(ClientCommandHandler event) {
        event.registerCommand(new testCommand());
    }

 

Now it doesn't work not in single and not on multiplayer.

I think I tried using this before and it just didn't work so I used the server one.

 

ClientCommandHandler isn't an event, you can't subscribe to it. You need to call ClientCommandHandler#registerCommand from your client proxy in preInit.

 

There should be an error in the log telling you that the method is invalid.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

26 minutes ago, Choonster said:

 

ClientCommandHandler isn't an event, you can't subscribe to it. You need to call ClientCommandHandler#registerCommand from your client proxy in preInit.

 

There should be an error in the log telling you that the method is invalid.

 

I have this in my preinit

    @Mod.EventHandler
    public void preInit(FMLPreInitializationEvent e) {
        MinecraftForge.EVENT_BUS.register(new THING());
        
    }

How do I call  ntCommandHandler#registerCommand?

Link to comment
Share on other sites

How do you call any other method?

 

You get an instance of an object and press the . key and type the method name...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

On 2/13/2017 at 5:48 PM, Draco18s said:

How do you call any other method?

 

You get an instance of an object and press the . key and type the method name...

 

Yes I know, but where should I call it, inside my @Mod class? how do I do this? should it be inside my preinit? what should be before it?

Link to comment
Share on other sites

...yes...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

15 hours ago, Draco18s said:

...yes...

 

I'm a little lost right now...

I have a class that extends CommandBase, there I give it the command name, usage etc.

Do I need to call that class from my preinitevent (I need to perhaps register it?), right? How do I do that? just like I did for my "THING" class? or there is some other way to do so?

The command class is called testCommand, and as I said before extends CommandBase. So I should just add this line to my preinit?

MinecraftForge.EVENT_BUS.register(new testCommand());

 

Link to comment
Share on other sites

No. It's a command, not an event handler, and furthermore, it's a client-side command. You need to register it with the ClientCommandHandler instance in your pre-init event. 

 

You should really learn Java before trying to mod, it will make your life a lot easier. Right now you're making a lot of mistakes that you wouldn't be if you had a basic knowledge of Java.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.