org.spongepowered.api.text.channel.MessageReceiver Java Examples

The following examples show how to use org.spongepowered.api.text.channel.MessageReceiver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChatMessageListener.java    From EagleFactions with MIT License 6 votes vote down vote up
private MessageChannel hideMessageForPlayersInFactionChat(final MessageChannel messageChannel)
{
    final Collection<MessageReceiver> chatMembers = messageChannel.getMembers();
    final Set<MessageReceiver> newReceivers = new HashSet<>(chatMembers);
    for(final MessageReceiver messageReceiver : chatMembers)
    {
        if(!(messageReceiver instanceof Player))
            continue;

        final Player receiver = (Player) messageReceiver;

        if(EagleFactionsPlugin.CHAT_LIST.containsKey(receiver.getUniqueId()) && EagleFactionsPlugin.CHAT_LIST.get(receiver.getUniqueId()) != ChatEnum.GLOBAL)
        {
            newReceivers.remove(receiver);
        }
    }
    return MessageChannel.fixed(newReceivers);
}
 
Example #2
Source File: VirtualChestPlugin.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void onReload(GameReloadEvent event)
{
    try
    {
        MessageReceiver src = event.getCause().first(CommandSource.class).orElse(Sponge.getServer().getConsole());
        src.sendMessage(this.translation.take("virtualchest.reload.start"));
        this.loadConfig();
        this.saveConfig();
        src.sendMessage(this.translation.take("virtualchest.reload.finish"));
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #3
Source File: TeleporthereCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, getPermission());
    Player p = (Player) sender;
    List<Entity> t = new ArrayList<>(args.getAll("entities"));

    Teleportation request = UltimateCore.get().getTeleportService().createTeleportation(sender, t, p::getTransform, teleportRequest -> {
        //Complete
        Messages.send(p, "teleport.command.teleporthere.success.self", "%player%", VariableUtil.getNamesEntity(t));
        for (Entity en : t) {
            if (en instanceof MessageReceiver) {
                Messages.send(((CommandSource) en), "teleport.command.teleporthere.success.others", "%player%", VariableUtil.getNameEntity(p));
            }
        }
    }, (teleportRequest, reason) -> {
    }, true, false);
    request.start();
    return CommandResult.successCount(t.size());
}
 
Example #4
Source File: ChatMessageListener.java    From EagleFactions with MIT License 5 votes vote down vote up
private List<MessageReceiver> getAdminReceivers()
{
    final List<MessageReceiver> admins = new ArrayList<>();
    for(final UUID adminUUID : super.getPlugin().getPlayerManager().getAdminModePlayers())
    {
        final Optional<Player> optionalAdminPlayer = Sponge.getServer().getPlayer(adminUUID);
        optionalAdminPlayer.ifPresent(admins::add);
    }
    return admins;
}
 
Example #5
Source File: CachedMessage.java    From Web-API with MIT License 5 votes vote down vote up
public CachedMessage(Collection<MessageReceiver> receivers, Text content) {
    super(null);

    this.timestamp = (new Date()).toInstant().toEpochMilli();
    if (receivers != null) {
        this.receivers.addAll(receivers.stream()
                .map(m -> cacheService.asCachedObject(m))
                .collect(Collectors.toList()));
    }
    this.content = content.toBuilder().build();
}
 
Example #6
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }

    GDTimings.PLAYER_CHAT_EVENT.startTimingIfSync();
    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    // check for command input
    if (playerData.isWaitingForInput()) {
        playerData.commandInput = event.getRawMessage().toPlain();
        playerData.commandConsumer.accept(player);
        event.setCancelled(true);
        return;
    }

    if (playerData.inTown && playerData.townChat) {
        final MessageChannel channel = event.getChannel().orElse(null);
        if (GriefDefenderPlugin.getInstance().nucleusApiProvider != null && channel != null) {
            if (GriefDefenderPlugin.getInstance().nucleusApiProvider.isChatChannel(channel)) {
                GDTimings.PLAYER_CHAT_EVENT.stopTimingIfSync();
                return;
            }
        }
        final GDClaim sourceClaim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
        if (sourceClaim.isInTown()) {
            playerData.inTown = true;
        } else {
            playerData.inTown = false;
        }
        final GDClaim sourceTown = sourceClaim.getTownClaim();
        final Component townTag = sourceTown.getTownData().getTownTag().orElse(null);

        Text header = event.getFormatter().getHeader().toText();
        Text body = event.getFormatter().getBody().toText();
        Text footer = event.getFormatter().getFooter().toText();
        Text townMessage = Text.of(TextColors.GREEN, body);
        if (townTag != null) {
            townMessage = Text.of(SpongeUtil.getSpongeText(townTag), townMessage);
        }
        event.setMessage(townMessage);
        Set<CommandSource> recipientsToRemove = new HashSet<>();
        Iterator<MessageReceiver> iterator = event.getChannel().get().getMembers().iterator();
        while (iterator.hasNext()) {
            MessageReceiver receiver = iterator.next();
            if (receiver instanceof Player) {
                Player recipient = (Player) receiver;
                if (GriefDefenderPlugin.getInstance().nucleusApiProvider != null) {
                    if (NucleusProvider.getPrivateMessagingService().isPresent() && NucleusProvider.getPrivateMessagingService().get().isSocialSpy(recipient)) {
                        // always allow social spy users
                        continue;
                    }
                }

                final GDPlayerData targetPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(recipient.getWorld(), recipient.getUniqueId());
                if (!targetPlayerData.inTown) {
                    recipientsToRemove.add(recipient);
                    continue;
                }

                final GDClaim targetClaim = this.dataStore.getClaimAtPlayer(targetPlayerData, recipient.getLocation());
                final GDClaim targetTown = targetClaim.getTownClaim();
                if (targetPlayerData.canIgnoreClaim(targetClaim)) {
                    continue;
                }
                if (sourceTown != null && (targetTown == null || !sourceTown.getUniqueId().equals(targetTown.getUniqueId()))) {
                    recipientsToRemove.add(recipient);
                }
            }
        }

        if (!recipientsToRemove.isEmpty()) {
            Set<MessageReceiver> newRecipients = Sets.newHashSet(event.getChannel().get().getMembers().iterator());
            newRecipients.removeAll(recipientsToRemove);
            event.setChannel(new FixedMessageChannel(newRecipients));
        }
    }

    GDTimings.PLAYER_CHAT_EVENT.stopTimingIfSync();
}
 
Example #7
Source File: NationMessageChannel.java    From Nations with MIT License 4 votes vote down vote up
public NationMessageChannel(Collection<MessageReceiver> members) {
    this.members = Collections.newSetFromMap(new WeakHashMap<>());
    this.members.addAll(members);
}
 
Example #8
Source File: NationMessageChannel.java    From Nations with MIT License 4 votes vote down vote up
@Override
public Collection<MessageReceiver> getMembers() {
    return Collections.unmodifiableSet(this.members);
}
 
Example #9
Source File: NationMessageChannel.java    From Nations with MIT License 4 votes vote down vote up
@Override
public boolean addMember(MessageReceiver member) {
    return this.members.add(member);
}
 
Example #10
Source File: NationMessageChannel.java    From Nations with MIT License 4 votes vote down vote up
@Override
public boolean removeMember(MessageReceiver member) {
    return this.members.remove(member);
}
 
Example #11
Source File: CachedChatMessage.java    From Web-API with MIT License 4 votes vote down vote up
public CachedChatMessage(Player sender, Collection<MessageReceiver> receivers, Text content) {
    super(receivers, content);

    this.sender = cacheService.getPlayer(sender);
}