Jump to content

ServerChatEvent doesn't work on my server


rexlz

Recommended Posts

I've started modding with forge recently, and I want to create a mod to play a custom sound upon player chatting on my server.

 

I used ServerChatEvent as the event to trigger the sound, however that event doesn't really fire when I chat on my server as a client(no sound heard, no debug info). Other events like ItemCraftedEvent fires normally on my server.

I also tried my mod in singleplayer, ServerChatEvent works properly there(when I chat I could hear the sound correctly).

 

So, what could be the problem?

Edited by rexlz
Link to comment
Share on other sites

I’m not 100% sure if this is better or what you want, but I think it would be a better route to do this with a plugin, and players can run a command if they want to hear the sound when chatting. If you do this, I would suggest checking out SpigotMC.org.

 

Hope this helps!

Edited by IAmAFrenchFry
Link to comment
Share on other sites

3 hours ago, IAmAFrenchFry said:

I’m not 100% sure if this is better or what you want, but I think it would be a better route to do this with a plugin, and players can run a command if they want to hear the sound when chatting. If you do this, I would suggest checking out SpigotMC.org.

 

Hope this helps!

Thanks man, I'll consider that. But I'd still like to figure out a way to do it in a forge mod, as I'm also learning to mod. In fact it's not only the sound won't play, but the event itself not fires when I connect to my server as a client, where I'd try adding some other functions later on. The event does fire and function normally when I play singleplayer.

Link to comment
Share on other sites

On 2/24/2020 at 4:18 PM, diesieben07 said:

ServerChatEvent is a server-side event. Did you install the mod on the server?

Show your code.

Yeah...I'm trying to understand the concept of two sides in Minecraft. As I see it, ServerChatEvent should fire when a player chat on server.

The code below is event loader.

public class EventLoader {    
    public EventLoader()
    {
        MinecraftForge.EVENT_BUS.register(this);
    }
	
    ResourceLocation location = new ResourceLocation("mytestmod", "mytestmod.test");
    SoundEvent se = new SoundEvent(location);

    @SubscribeEvent
    public void onPlayerChat(ServerChatEvent event)
    {
        event.getPlayer().sendMessage(new TextComponentString("fired!"));
        System.out.println("fired!");
        event.getPlayer().world.playSound(null, event.getPlayer().getPosition(),se, SoundCategory.PLAYERS, 1.0F, 1.0F);
    }
}

 

And I initiate it in the main class.

public void preInit(FMLPreInitializationEvent event)
{
    new EventLoader();
}

 

The result when I test it on my remote server was nothing happen.

Edited by rexlz
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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