crwdns119273:0crwdne119273:0

crwdns119275:0:javadoc:crwdnd119275:0:javadoc:crwdne119275:0

crwdns119277:0crwdne119277:0

crwdns119279:0:javadoc:crwdnd119279:0:javadoc:crwdnd119279:0:javadoc:crwdne119279:0

crwdns119281:0crwdne119281:0

crwdns119283:0:javadoc:crwdnd119283:0:javadoc:crwdnd119283:0:javadoc:crwdnd119283:0:javadoc:crwdne119283:0

crwdns119285:0:javadoc:crwdne119285:0

crwdns119287:0crwdne119287:0

crwdns119289:0:javadoc:crwdnd119289:0:javadoc:crwdne119289:0

crwdns119291:0crwdne119291:0

crwdns119293:0:javadoc:crwdnd119293:0:javadoc:crwdne119293:0

crwdns119295:0crwdne119295:0

crwdns119297:0:javadoc:crwdne119297:0

crwdns119299:0crwdne119299:0

crwdns119301:0:javadoc:crwdnd119301:0:javadoc:crwdnd119301:0:javadoc:crwdnd119301:0:javadoc:crwdne119301:0

crwdns119303:0crwdne119303:0

crwdns119305:0:javadoc:crwdnd119305:0:javadoc:crwdnd119305:0:javadoc:crwdne119305:0

crwdns119307:0crwdne119307:0

crwdns119309:0:javadoc:crwdne119309:0

crwdns119311:0crwdne119311:0

crwdns119313:0[Admin]crwdne119313: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.chat.ChatType;
import org.spongepowered.api.text.format.TextColors;

public class AdminMessageChannel implements MessageChannel {

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

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

crwdns119315:0:javadoc:crwdne119315:0

crwdns119317:0[Admin]crwdne119317:0

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

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);
    }
}

crwdns119319:0:javadoc:crwdne119319:0

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

crwdns119321:0:doc:crwdne119321:0

Note

crwdns119323:0crwdne119323:0

crwdns119325:0crwdne119325:0

crwdns119327:0:javadoc:crwdne119327:0

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

import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.channel.MessageReceiver;
import org.spongepowered.api.text.channel.MutableMessageChannel;
import org.spongepowered.api.text.chat.ChatType;
import org.spongepowered.api.text.format.TextColors;

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, ChatType type) {
        Text text = original;
        if(this.members.contains(recipient)) {
            text = Text.of(TextColors.RED, "[Admin]", TextColors.RESET, text);
        }
        return Optional.of(text);
    }
}

crwdns119329:0[Admin]crwdne119329:0

crwdns119331:0crwdne119331:0

crwdns119333:0crwdne119333:0

crwdns119335:0:javadoc:crwdnd119335:0:javadoc:crwdne119335:0