Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

How to register commands and where is the class, that register vanilla commands in ServerCommandManager, and I should register them in init or preinit?

You should register them during FMLServerStartingEvent. Example:

 

public class MyMainModClass {

 

    // Additional code ...

 

    @EventHandler

    public void serverStarting(FMLServerStartingEvent event) {

        event.registerServerCommand(new MyCustomCommand()); // MyCustomCommand must inherit the CommandBase class

    }

}

if (user.hasKnowledgeOfJava) {

    if (user.question.hasCode) {

        return interpetHelpfulResponse(user.getQuestion());

    } else {

        return "Could you post your code please?";

    }

} else {

    return "Learn some freaking Java!";

}

MrArcane111, I followed this http://www.minecraftforge.net/wiki/Server_Command and it worked perfectly fine for me, and I am using 1.7.2.

 

I don't see what else to discuss here even, follow the tutorial, the end.

But since I am in good mood,  I will share my sample command code with you.

package com.zetaworx.proboblyawesome.handler;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;

public class CommandHandle implements ICommand
{
private List<String> aliases;
public CommandHandle()
{
	this.aliases = new ArrayList<String>();
	this.aliases.add("probobly");
	this.aliases.add("awesome");
	this.aliases.add("proboblyawesome");
}

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

@Override
public String getCommandUsage(ICommandSender icommandsender)
{
	return "pa <text/help>";
}

@Override
public List<String> getCommandAliases()
{
	return this.aliases;
}

@Override
public void processCommand(ICommandSender icommandsender, String[] astring)
{
	if(astring.length == 0)
	{
		icommandsender.addChatMessage(new ChatComponentText("Invalid Arguments. Usage: " + this.getCommandUsage(icommandsender)));
		return;
	}
	if (astring[0] == "help")
	{
		icommandsender.addChatMessage(new ChatComponentText("Usage: " + this.getCommandUsage(icommandsender)));
		return;
	} else {
	ChatComponentText msg = new ChatComponentText("Output: [");
	for (int i = 0;i < astring.length; ++i)
	{
		msg.appendText(" " + astring[i]);
	}
	msg.appendText(" ]");
	icommandsender.addChatMessage(msg);	
	}
}

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

@Override
public List<?> addTabCompletionOptions(ICommandSender icommandsender,
String[] astring)
{
return null;
}

@Override
public boolean isUsernameIndex(String[] astring, int i)
{
return false;
}

@Override
public int compareTo(Object o)
{
return 0;
}
}

 

and this in your mod file

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

 

my command is using ICommand interface which is what CommandBase is extending from, but for time being I didn't need CommandBase functions so I didn't use it.

 

Ps. my command also shows how to send user a chat message.

~I was here~

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.