Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to send a FancyMessage to multiple players #10

Closed
TheE opened this issue Mar 24, 2014 · 1 comment
Closed

Add a way to send a FancyMessage to multiple players #10

TheE opened this issue Mar 24, 2014 · 1 comment

Comments

@TheE
Copy link

TheE commented Mar 24, 2014

As of writing, the only way to send a FancyMessage to multiple players is to to call send(player) over and over again with calls toJSONString() each time. This might produce an overhead that can easily be removed by providing a send-method that takes an Iterable of players that calls toJSONString() once and sends this result to everybody:

public void send(Iterable<Players> players){
  String json = toJSONString();
  for (Player player : players) {
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(ChatSerializer.a(json)));
  }
}
@mkremins
Copy link
Owner

Incorporating this would definitely be a good idea. Just one tiny little nitpick – repeatedly calling toJSONString() on the same FancyMessage object doesn't actually yield much overhead as long as you don't modify the object in between calls, since the object internally caches the JSON string on the first such call. Subsequent calls then return the cached string, as long as the object hasn't been made "dirty" by modifications in the meantime.

Oddly enough, I developed the caching functionality to address the problem of performance when sending to multiple players – but never once thought to do the convenient thing and just include a method like the one you've described above :|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants