Discussion in 'Plugin Development' started by Shade, Jan 3, 2011.

Thread Status:
Not open for further replies.
  1. Offline


    One of my biggest beefs about hMod was how it handled onChat. None of the plugins could interact with each other. Bukkit looks like it'll solve it sort of.

    Right now, you've got an event object that all plugin now interact with. Awesome since now people can edit the player and message object that's passed into it. That's~ about it though.

    We have an output message and a player object that I'm assuming will be formated as such:
    <player.getName> message

    Oh joys. 90% of plugins that hook onChat want to skin the entire message or at least, not edit that part of the message. That won't do.

    Bukkit is rather simple right now, inDev and all, but here's my take on it.
    My first idea was to have a global format string defined in the config and plugins can register their arguments into it. Adding a new plugin could mess up that order, and you don't want every bit of information flowing in for each line. Edit: Or do you? Now that I reflect on it a bit most things could get by with this. Still, you'd want some inGame editing to the order of things.

    Next up comes the method where you insert the format string in the event directly for plugins to interact with. Problem here is that each plugin would have to deal with a relative path. This would then force the admin to order the plugins (or at least their importance) carefully.

    You also still have to incorporate those would want to make channels, or only let select people view what he/she said. Truthfully, channels without client side work makes it crap, but we'll have to make do. Anyways, even if we pass a list of players for the plugins to decide what get's sent to who, we could still end up with plugins fighting over messages (the focus of a players output). The only way to fix that is to move all channel related stuff into the server itself (ahhhh fuck). Loathing as that might be, it's how most games work normally (but MC was never designed for bigness).

    You could also just leave it and either one focus based plugin or have channels need prefixed command calls instead (/talk #bukkit Blah blah blah / .local chat powah!). This is probably simplest since most of the smaller server's don't need channels.

    The alternative is that we just make a collossal mess of one chat plugin that does everything.


    Now we come to the section where I post pointless code.

                // CraftBukkit start
    PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_CHATplayersserver.getOnlinePlayers());
    MessageFormat.format(event.getFormat(), event.getFormatArgs());
                for (
    Player receivingPlayer event.getReceivingPlayers())
    //s = (new StringBuilder()).append("<").append(event.getPlayer().getName()).append("> ").append(event.getMessage()).toString();
                // CraftBukkit stop

    //d.f.a(new Packet3Chat(s));
    public class PlayerChatEvent extends PlayerEvent implements Cancellable {
    boolean cancel false;
    String messageformatlogString;
        private List<

    PlayerChatEvent(final Type type, final Player player, final String message) {
    this.message message;
    PlayerChatEvent(final Type type, final Player player, final String messagePlayer[] receivingPlayers) {
    this.message message;
    this.setLogString("<" player.getName() + "> " message);
    this.format "<{0}> {1}";
    // Plugin

    // Could also return the ChatCall instance as well.
    public void onChat(ChatCall cc) {
    // Simple message string replacement.
    // Change the skin completely
    cc.setFormat("{0}: {1}");
    // Insert a value into the format eg: "[HP: 20] Player: blarg"
    boolean result cc.insertIntoFormat(
    "[HP: {"+cc.getNextFormatArgIndex()+"}] ");
        if (
    // Send to only allies (aka remove everyone else)
    for (int i cc.getRecievers().size(); >= 0i--) {
    Player player cc.getRecievers().get(i);
            if (!
    // Send to only allies (aka get online allies from plugin)
    PS: I doubt that code is runnable. Disreguard the ChatCall class thing. I sketched up that code before I found the chat call in craftbucket and it's related event.
  2. Offline


    Interesting problem. From a programing point of view, I love to see this get solved. I dare not attempt it myself though, not enough experience/knowlege yet.
  3. Offline

    Dinnerbone Bukkit Team Member

    We are considering letting plugins pass a formatstring to define how to display the message, but it might get a little messy.

    In addition, Players will have a .getDisplayName() and appropriate functions to define how a name should display in chat and various places.
Thread Status:
Not open for further replies.

Share This Page