crwdns149297:0crwdne149297:0

crwdns149299:0:javadoc:crwdnd149299:0:javadoc:crwdne149299:0

crwdns149301:0crwdne149301:0

crwdns149303:0:javadoc:crwdnd149303:0:javadoc:crwdnd149303:0:javadoc:crwdne149303:0

crwdns149305:0crwdne149305:0

crwdns149307:0:javadoc:crwdnd149307:0:javadoc:crwdnd149307:0:javadoc:crwdnd149307:0:javadoc:crwdne149307:0

crwdns149309:0:javadoc:crwdne149309:0

crwdns149311:0crwdne149311:0

crwdns149313:0:javadoc:crwdnd149313:0:javadoc:crwdne149313:0

crwdns149315:0crwdne149315:0

crwdns149317:0:javadoc:crwdnd149317:0:javadoc:crwdne149317:0

crwdns149319:0crwdne149319:0

crwdns149321:0:javadoc:crwdne149321:0

crwdns149323:0crwdne149323:0

crwdns149325:0:javadoc:crwdnd149325:0:javadoc:crwdnd149325:0:javadoc:crwdnd149325:0:javadoc:crwdne149325:0

crwdns149327:0crwdne149327:0

crwdns149329:0:javadoc:crwdnd149329:0:javadoc:crwdnd149329:0:javadoc:crwdne149329:0

crwdns149331:0crwdne149331:0

crwdns149333:0:javadoc:crwdne149333:0

crwdns149335:0crwdne149335:0

crwdns149337:0[Admin]crwdne149337: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();
    }
}

crwdns149339:0:javadoc:crwdne149339:0

crwdns149341:0[Admin]crwdne149341: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);
    }
}

crwdns149343:0:javadoc:crwdne149343:0

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

crwdns149345:0:doc:crwdne149345:0

Note

crwdns149347:0crwdne149347:0

crwdns149349:0crwdne149349:0

crwdns149351:0:javadoc:crwdne149351: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);
    }
}

crwdns149353:0[Admin]crwdne149353:0

crwdns149355:0crwdne149355:0

crwdns149357:0crwdne149357:0

crwdns149359:0:javadoc:crwdnd149359:0:javadoc:crwdne149359:0