dand0 Posted April 25, 2014 Posted April 25, 2014 How to register commands and where is the class, that register vanilla commands in ServerCommandManager, and I should register them in init or preinit? Quote
ZetaHunter Posted April 25, 2014 Posted April 25, 2014 You might find this usefull. Quote ~I was here~
DiabolusNeil Posted April 26, 2014 Posted April 26, 2014 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 } } Quote 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 Posted April 26, 2014 Posted April 26, 2014 I think it's still for 1.6.4, but Mekanism (an open-source mod on GitHub) has all the relevant methods to make this work. Quote
ZetaHunter Posted April 26, 2014 Posted April 26, 2014 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. Quote ~I was here~
Recommended Posts
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.