I made a server side mod for mc1.6.4 with forge and it works well. Im updating it to 1.7.2 and need to know how to add chat commands properly. In single player my old ways seemed to only need minor adjustment but when i export it and put it in a forge server for 1.7.2 it crashes. I have tried a couple of different ways i found and it doesnt seem to work. Does anyone have some example code? even if the code just displays "hello" in chat. that would get me going. I need it to work in multiplayer.
@EventHandler
public void serverLoad(FMLServerStartingEvent e) {
e.registerServerCommand(new CommandSpawn()); // this is line 50 as mentioned below in the log.
e.registerServerCommand(new CommandSpawnPoint());
e.registerServerCommand(new CommandSpawnSet());
e.registerServerCommand(new CommandSpawnQuery());
e.registerServerCommand(new CommandSpawnPlus());
e.registerServerCommand(new CommandSpawnMinus());
e.registerServerCommand(new CommandSpawns());
e.registerServerCommand(new CommandHome());
e.registerServerCommand(new CommandSetHome());
e.registerServerCommand(new CommandSpawnHelp());
e.registerServerCommand(new CommandBack());
}
it works on the SSP but crashes the SMP forge server with
18:44:53] [Server thread/INFO]: Preparing spawn area: 96%
[18:44:53] [Server thread/INFO]: Done (12.210s)! For help, type "help" or "?"
[18:44:53] [Server thread/ERROR] [FML]: Fatal errors were detected during the transition from SERVER_ABOUT_TO_START to SERVER_STARTING. Loading cannot continue
[18:44:53] [Server thread/ERROR] [FML]:
mcp{9.03} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available
FML{7.2.211.1121} [Forge Mod Loader] (forge-1.7.2-10.12.2.1121-universal.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available
Forge{10.12.2.1121} [Minecraft Forge] (forge-1.7.2-10.12.2.1121-universal.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available
SpawnCommands{1.4.1} [SpawnCommands] (SpawnCommands140 for 172 test e-method.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Errored
[18:44:53] [Server thread/ERROR] [FML]: The following problems were captured during this phase
[18:44:53] [Server thread/ERROR] [FML]: Caught exception from SpawnCommands
java.lang.AbstractMethodError
at net.minecraft.command.CommandHandler.func_71560_a(CommandHandler.java:128) ~[z.class:?]
at cpw.mods.fml.common.event.FMLServerStartingEvent.registerServerCommand(FMLServerStartingEvent.java:44) ~[FMLServerStartingEvent.class:?]
at aln.SpawnCommands.SpawnCommands.serverLoad(SpawnCommands.java:50) ~[SpawnCommands.class:?]
I also tried this method before the above:
@EventHandler
public void serverLoad(FMLServerStartingEvent e) { MinecraftServer server = MinecraftServer.getServer(); // single player only? // This is line 62 as shown below in the error.
ICommandManager command = server.getCommandManager();
ServerCommandManager manager = (ServerCommandManager) command;
manager.registerCommand(new CommandSpawn());
manager.registerCommand(new CommandSpawnPoint());
manager.registerCommand(new CommandSpawnSet());
manager.registerCommand(new CommandSpawnQuery());
manager.registerCommand(new CommandSpawnPlus());
manager.registerCommand(new CommandSpawnMinus());
manager.registerCommand(new CommandSpawns());
manager.registerCommand(new CommandHome());
manager.registerCommand(new CommandSetHome());
manager.registerCommand(new CommandSpawnHelp());
manager.registerCommand(new CommandBack());
}
But this one gives me the following crash problem:
18:55:15] [Server thread/INFO]: Preparing spawn area: 93%
[18:55:16] [Server thread/INFO]: Done (10.527s)! For help, type "help" or "?"
[18:55:16] [Server thread/ERROR] [FML]: Fatal errors were detected during the transition from SERVER_ABOUT_TO_START to SERVER_STARTING. Loading cannot continue
[18:55:16] [Server thread/ERROR] [FML]:
mcp{9.03} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available
FML{7.2.211.1121} [Forge Mod Loader] (forge-1.7.2-10.12.2.1121-universal.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available
Forge{10.12.2.1121} [Minecraft Forge] (forge-1.7.2-10.12.2.1121-universal.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available
SpawnCommands{1.4.1} [SpawnCommands] (SpawnCommands140 for 172 test method longer.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Errored
[18:55:16] [Server thread/ERROR] [FML]: The following problems were captured during this phase
[18:55:16] [Server thread/ERROR] [FML]: Caught exception from SpawnCommands
java.lang.NoSuchMethodError: net.minecraft.server.MinecraftServer.getServer()Lnet/minecraft/server/MinecraftServer;
at aln.SpawnCommands.SpawnCommands.serverLoad(SpawnCommands.java:62) ~[SpawnCommands.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_55]
Again i note that both above methods seem to work well in single player but not on a multiplayer server.
I also was wondering if I sould register my commands in FMLServerStartingEvent as i do now or perhaps in the FMLInitializationEvent?
My first attempt was the second example above. It works perfectly in single player but but not on a server so far. Did you mean my first attempt or my first example above?
Im not sure what you mean by "one created with the new ICommand(){}. Here is one of my commands:
public class CommandSpawnHelp implements ICommand {
@Override
public int compareTo(Object arg0) {
return 0;
}
@Override
public String getCommandName() {
return "spawnhelp";
}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
return "/spawnhelp - Displays quick help for this mod.";
}
@Override
public List getCommandAliases() {
return null;
}
@Override
public void processCommand(ICommandSender icommandsender, String[] params) {
if(icommandsender instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) icommandsender;
if ( player.worldObj.isRemote ) { return; }
SpawnCommands.ShowHelp(player);
}
}
@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;
}
}
is the above code what you meant? or what did you mean? by the new ICommand....?
Please note that the code errors out BEFORE it reaches the command registrations. It errors on the ...getServer() line. I have also tried MinecraftServer server = e.getServer(); (where 'e' is the event) with the exact same error.
My forge is forge-1.7.2-10.12.2.1121 which is the latest recommended one for Minecraft 1.7.2. There is the "Latest" not the recommended version 10.12.2.1147 that is available. Shoule i go with that version?
Thank you for the info. Im hoping for more explanation
This is my FIRST attempt to compile in 1.7.2. I have been working with 1.6.4 so far. So the solution was to compile the mod correctly and I did not have it correct. oops. The code above with MinecraftServer server = MinecraftServer.getServer(); works fine now. I had to compile with gradlew build and the build.gradle file setup properly. All good. Thanks all.
Examples anyone?
my published mods
it works on the SSP but crashes the SMP forge server with
I also tried this method before the above:
But this one gives me the following crash problem:
Again i note that both above methods seem to work well in single player but not on a multiplayer server.
I also was wondering if I sould register my commands in FMLServerStartingEvent as i do now or perhaps in the FMLInitializationEvent?
my published mods
Im not sure what you mean by "one created with the new ICommand(){}. Here is one of my commands:
import java.util.List;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
public class CommandSpawnHelp implements ICommand {
@Override
public int compareTo(Object arg0) {
return 0;
}
@Override
public String getCommandName() {
return "spawnhelp";
}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
return "/spawnhelp - Displays quick help for this mod.";
}
@Override
public List getCommandAliases() {
return null;
}
@Override
public void processCommand(ICommandSender icommandsender, String[] params) {
if(icommandsender instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) icommandsender;
if ( player.worldObj.isRemote ) { return; }
SpawnCommands.ShowHelp(player);
}
}
@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;
}
}
Please note that the code errors out BEFORE it reaches the command registrations. It errors on the ...getServer() line. I have also tried MinecraftServer server = e.getServer(); (where 'e' is the event) with the exact same error.
My forge is forge-1.7.2-10.12.2.1121 which is the latest recommended one for Minecraft 1.7.2. There is the "Latest" not the recommended version 10.12.2.1147 that is available. Shoule i go with that version?
Thank you for the info. Im hoping for more explanation
my published mods
MinecraftServer server = MinecraftServer.getServer();
would not work on a forge server for mc 1.7.2 ?
It errors out with this
NoSuchMethodError
I tried this too
ServerCommandManager manager = (ServerCommandManager) MinecraftServer.getServer().getCommandManager();
same error.
While testing inside eclipse it works well. but when I export it using eclipse then put it in a client or a server it fails with the error above.
my published mods
my published mods
This is my FIRST attempt to compile in 1.7.2. I have been working with 1.6.4 so far. So the solution was to compile the mod correctly and I did not have it correct. oops. The code above with MinecraftServer server = MinecraftServer.getServer(); works fine now. I had to compile with gradlew build and the build.gradle file setup properly. All good. Thanks all.
my published mods