0
FMLCommonHandler.instance().bus().register(new PlayerJoin());

That is the bus I used to register it.

@SubscribeEvent
public void onPlayerJoinServer(PlayerLoggedInEvent event) {
    event.player.addChatMessage(new ChatComponentText("test"));
    return;
}

That is my event. When I join a singleplayer world it sends me the "test" message but not when I join a multiplayer server. (Like Mineplex) Please let me know why this may be happening, thank you!

BillehBawb
  • 45
  • 1
  • 8

1 Answers1

1

That event is fired on the logical server side.

If your mod doesn't exist on the physical server (i.e. Mineplex hasn't installed it) Then it won't fire.

A little digging (the list I found is not current, but probably sufficient as events like this are never removed almost never renamed) and I found FMLNetworkEvent.ClientConnectedToServerEvent which is fired on the client when that client is about to connect to any server.

It is unlikely, however, to inform you that another player has connected to the same server (EntityJoinWorldEvent may work, though you would need to discriminate for instances of EntityPlayerMP).

  • With ClientConnectedToServerEvent there doesn't seem to be an event.getServer(). I need a way to get the playerEntities in the world/server that the client is connecting to. As for EntityJoinWorldEvent, It crashes the client because what the PlayerJoin class is doing basically opens a MySQL connection, checks if anybody on the server is in the database then does something if they are. If there are 50 players in the server I am joining it opens 50 connections all at once and crashes, I couldn't find a way to make it only run once when the player joins instead of for every entity that gets load. – BillehBawb Jul 11 '17 at 20:57
  • @BillehBawb Use `ClientConnectedToServerEvent` but you would need a different way to get the list of players connected (obviously you can't use `getServer()` because the client connected to a remote server *can't access the server process*). Look around for the UI that shows up when you press Tab, I've forgotten what it's called, but it's populated with the player list and would show you how to get access to the information you want. – Draco18s no longer trusts SE Jul 11 '17 at 21:00
  • @BillehBawb And now that I am home, take a look at `renderPlayerlist()` of `GuiPlayerTabOverlay` – Draco18s no longer trusts SE Jul 11 '17 at 21:47
  • Like `Minecraft.getMinecraft().ingameGUI.getTabList()`? If I do this there isn't a .getPlayers() or .playerEntities. Is this even what you were talking about? – BillehBawb Jul 11 '17 at 21:51
  • How about the bit that says, *`nethandlerplayclient.getPlayerInfoMap()`*? – Draco18s no longer trusts SE Jul 12 '17 at 01:51
  • This is the error I get when trying to join a singleplayer world with that code. https://hastebin.com/davaxiqama.md – BillehBawb Jul 12 '17 at 02:51
  • You're getting a null pointer. You need to [fix that](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it), it is very easy. – Draco18s no longer trusts SE Jul 12 '17 at 13:51
  • Yes, but that line is the line where I get the player info map. Therefore I am doing something wrong or that method wont work. – BillehBawb Jul 13 '17 at 00:45
  • Possibility 1: The event is too early. Possibility 2: you aren't retrieving it the right way (I haven't messed with it, soo..) – Draco18s no longer trusts SE Jul 13 '17 at 04:19
  • Well how do I not have the event be too early – BillehBawb Jul 13 '17 at 23:38
  • No no, not that the event is firing too early, but that the information you need hasn't been populated *by the time the event fires.* I.e. you would need to either delay your operation in some manner or use a different event. I don't have a good suggestion about anything more specific. – Draco18s no longer trusts SE Jul 14 '17 at 00:50