(Solved) 1.7 Server sending chat message to all players

Discussion in 'Mod Development' started by Kahless61, Mar 24, 2015.

  1. Kahless61

    Kahless61 New Member

    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?
     
  2. InfinityRaider

    InfinityRaider New Member

    Can you share your code and stacktrace?
     
    SatanicSanta likes this.
  3. Kahless61

    Kahless61 New Member

    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?
     
  4. ljfa

    ljfa New Member

    I'm not sure what's wrong there, but that's how I do it:
    Code:
    MinecraftServer.getServer().addChatMessage(new ChatComponentText(msg));
     
    InfinityRaider likes this.
  5. ljfa

    ljfa New Member

    I can only imagine that your mod didn't get obfuscated or something went wrong there.
    How did you build the jar, with gradle?
     
  6. Kahless61

    Kahless61 New Member

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

    ljfa New Member

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

    Kahless61 New Member

    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
     

Share This Page