crwdns130043:0crwdne130043:0

crwdns130045:0:javadoc:crwdnd130045:0:javadoc:crwdne130045:0

crwdns130047:0crwdne130047:0

crwdns130049:0:javadoc:crwdnd130049:0:javadoc:crwdnd130049:0:javadoc:crwdne130049:0

crwdns130051:0crwdne130051:0

crwdns130053:0:javadoc:crwdnd130053:0:javadoc:crwdnd130053:0:javadoc:crwdnd130053:0:javadoc:crwdne130053:0

crwdns130055:0:javadoc:crwdne130055:0

crwdns130057:0crwdne130057:0

crwdns130059:0:javadoc:crwdnd130059:0:javadoc:crwdne130059:0

crwdns130061:0crwdne130061:0

crwdns130063:0:javadoc:crwdnd130063:0:javadoc:crwdne130063:0

crwdns130065:0crwdne130065:0

crwdns130067:0:javadoc:crwdne130067:0

crwdns130069:0crwdne130069:0

crwdns130071:0:javadoc:crwdnd130071:0:javadoc:crwdnd130071:0:javadoc:crwdnd130071:0:javadoc:crwdne130071:0

crwdns130073:0crwdne130073:0

crwdns130075:0:javadoc:crwdnd130075:0:javadoc:crwdnd130075:0:javadoc:crwdne130075:0

crwdns130077:0crwdne130077:0

crwdns130079:0:javadoc:crwdne130079:0

crwdns130081:0crwdne130081:0

crwdns130083:0[Admin]crwdne130083:0

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;

import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.channel.MessageChannel;
import org.spongepowered.api.text.channel.MessageReceiver;
import org.spongepowered.api.text.format.TextColors;

public class AdminMessageChannel implements MessageChannel {

    @Override
    public Optional<Text> transformMessage(Object sender, MessageReceiver recipient,
                                                                Text original) {
        Text text = original;
        text = Text.of(TextColors.RED, "[Admin]", TextColors.RESET, text);
        return Optional.of(text);
    }

    @Override
    public Collection<MessageReceiver> getMembers() {
        return Collections.emptyList();
    }
}

crwdns130085:0:javadoc:crwdne130085:0

crwdns130087:0[Admin]crwdne130087:0

import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.network.ClientConnectionEvent;

private AdminMessageChannel adminChannel = new AdminMessageChannel();

@Listener
public void onClientConnectionJoin(ClientConnectionEvent.Join event) {
    Player player = event.getTargetEntity();
    if(player.hasPermission("myplugin.admin")) {
        MessageChannel originalChannel = event.getOriginalChannel();
        MessageChannel newChannel = MessageChannel.combined(originalChannel,
            adminChannel);
        player.setMessageChannel(newChannel);
    }
}

crwdns130089:0:javadoc:crwdne130089:0

Optional<Player> playerOptional = event.getCause().<Player>first(Player.class);

crwdns130091:0:doc:crwdne130091:0

Note

crwdns130093:0crwdne130093:0

crwdns130095:0crwdne130095:0

crwdns130097:0:javadoc:crwdne130097:0

import java.util.Set;
import java.util.WeakHashMap;

import org.spongepowered.api.text.channel.MutableMessageChannel;

public class MutableAdminMessageChannel implements MutableMessageChannel {

    private Set<MessageReceiver> members;

    public MutableAdminMessageChannel() {
        this(Collections.emptySet());
    }

    public MutableAdminMessageChannel(Collection<MessageReceiver> members) {
        this.members = Collections.newSetFromMap(new WeakHashMap<>());
        this.members.addAll(members);
    }

    @Override
    public Collection<MessageReceiver> getMembers() {
        return Collections.unmodifiableSet(this.members);
    }

    @Override
    public boolean addMember(MessageReceiver member) {
        return this.members.add(member);
    }

    @Override
    public boolean removeMember(MessageReceiver member) {
        return this.members.remove(member);
    }

    @Override
    public void clearMembers() {
        this.members.clear();
    }

    @Override
    public Optional<Text> transformMessage(Object sender, MessageReceiver recipient,
                                                                Text original) {
        Text text = original;
        if(this.members.contains(recipient)) {
            text = Text.of(TextColors.RED, "[Admin]", TextColors.RESET, text);
        }
        return Optional.of(text);
    }
}

crwdns130099:0[Admin]crwdne130099:0

crwdns130101:0crwdne130101:0

crwdns130103:0crwdne130103:0

crwdns130105:0:javadoc:crwdnd130105:0:javadoc:crwdne130105:0