(Solved) 1.7 Server sending chat message to all players

Kahless61

New Member
Jul 29, 2019
249
0
0
Searching for this turned up the simple code:

server.getConfigurationManager().sendChatMsg( stuff );

When I run my mod in eclipse with that code in the FMLServerStartingEvent handler, it works great. But when I compile and jar up my mod, and stick it into my FTB Modpack, the mod loads up and then errors out with "NoSuchMethodError" claiming that server does not have a getConfigurationManager() method.

I'm using Forge 1.7.10-10.13.2.1291.

So how do I send a chat to all players?
 

Kahless61

New Member
Jul 29, 2019
249
0
0
Code:
...
    @EventHandler
    public void serverStarting(FMLServerStartingEvent event) {
        MinecraftServer server = event.getServer();
        ServerConfigurationManager m = server.getConfigurationManager(); //line 36
        System.out.println( "Ready to send chat" );
        m.sendChatMsg( new ChatComponentText( "Hello World" ) );
    }
...

When run in Eclipse as Server:
Code:
[09:58:25] [Server thread/INFO] [STDOUT]: [com.feedthemetrics.Runner:serverStarting:37]: Ready to send chat
[09:58:25] [Server thread/INFO]: Hello World

When run in Eclipse as Client, it works very much the same - console logs "Ready to send chat" and then I see the message "Hello World" chatted out.

When I build it and jar it up and run in Feed The Beast, the following error appears without "Ready to send chat" appearing:
http://paste.feed-the-beast.com/view/06045771

Isolated to relevant lines:

Code:
[10:04:40] [Server thread/ERROR] [FML]: Caught exception from feedthemetrics
java.lang.NoSuchMethodError: net.minecraft.server.MinecraftServer.getConfigurationManager()Lnet/minecraft/server/management/ServerConfigurationManager;
   at com.feedthemetrics.Runner.serverStarting(Runner.java:36) ~[Runner.class:?]
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_75]


So what's wrong?
 

ljfa

New Member
Jul 29, 2019
2,761
-46
0
I'm not sure what's wrong there, but that's how I do it:
Code:
MinecraftServer.getServer().addChatMessage(new ChatComponentText(msg));
 
  • Like
Reactions: InfinityRaider

ljfa

New Member
Jul 29, 2019
2,761
-46
0
I can only imagine that your mod didn't get obfuscated or something went wrong there.
How did you build the jar, with gradle?
 

Kahless61

New Member
Jul 29, 2019
249
0
0
@ljfa
I suspect that's the issue as well, as the code you shared gives the same error, NoSuchMethod addChatMessage. I had noticed that function, but the documentation for it made it sound like it was intended for sending a message to a single player, rather than the entire server. Although since it doesn't have a target argument, guess it must send to everyone.

I built the jar with gradlew on linux:
Code:
./gradlew build
./gradlew jar
cp build/libs/feedthemetrics-3.0.jar ../../FTBCustomPack/minecraft/mods/

Here's the output:
Code:
****************************
 Powered By MCP:   
 http://mcp.ocean-labs.de/   
 Searge, ProfMobius, Fesh0r,
 R4wk, ZeuX, IngisKahn, bspkrs
 MCP Data version : unknown
****************************
:compileApiJava UP-TO-DATE
:processApiResources UP-TO-DATE
:apiClasses UP-TO-DATE
:sourceMainJava
:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
:processResources UP-TO-DATE
:classes
:jar
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:extractMcpData UP-TO-DATE
:getVersionJson
:extractUserDev UP-TO-DATE
:genSrgs SKIPPED
:reobf
:assemble
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Total time: 18.576 secs
****************************
 Powered By MCP:   
 http://mcp.ocean-labs.de/   
 Searge, ProfMobius, Fesh0r,
 R4wk, ZeuX, IngisKahn, bspkrs
 MCP Data version : unknown
****************************
:compileApiJava UP-TO-DATE
:processApiResources UP-TO-DATE
:apiClasses UP-TO-DATE
:sourceMainJava UP-TO-DATE
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar

BUILD SUCCESSFUL

Total time: 5.47 secs
 

ljfa

New Member
Jul 29, 2019
2,761
-46
0
You don't need to run "gradlew jar".
"gradlew build" will go ahead and make the jar for you. I think the jar created by "gradlew jar" is not obfuscated.
 

Kahless61

New Member
Jul 29, 2019
249
0
0
Aha! So the whole time I was overwriting the good jar with a non-obfuscated one.
Just tested by removing the "gradlew jar" step and it ran great!

Thanks a bunch, @ljfa