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

The following examples show how to use org.spongepowered.api.text.channel.MessageChannel. 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: MeExecutor.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	String message = ctx.<String> getOne("message").get();
	Text finalMessage = Text.builder()
		.append(Text.of(TextColors.DARK_GRAY, "* ", TextColors.DARK_RED, src.getName(), TextColors.GREEN, " "))
		.append(TextSerializers.formattingCode('&').deserialize(message))
		.build();

	if (src instanceof Player && EssentialCmds.muteList.contains(((Player) src).getUniqueId()))
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You are muted!"));
		return;
	}

	MessageChannel.TO_ALL.send(finalMessage);
}
 
Example #2
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 #3
Source File: SayExecutor.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	String message = ctx.<String> getOne("message").get();
	Text finalMessage = Text.builder()
		.append(Text.of(TextColors.DARK_GRAY, "[", TextColors.DARK_RED, src.getName(), TextColors.DARK_GRAY, "]", TextColors.GREEN, " "))
		.append(TextSerializers.formattingCode('&').deserialize(message))
		.build();

	if (src instanceof Player && EssentialCmds.muteList.contains(((Player) src).getUniqueId()))
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You are muted!"));
		return;
	}

	MessageChannel.TO_ALL.send(finalMessage);
}
 
Example #4
Source File: NationadminDeleteExecutor.java    From Nations with MIT License 6 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (!ctx.<String>getOne("nation").isPresent())
	{
		src.sendMessage(Text.of(TextColors.YELLOW, "/na delete <nation>"));
		return CommandResult.success();
	}
	String nationName = ctx.<String>getOne("nation").get();
	Nation nation = DataHandler.getNation(nationName);
	if (nation == null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADNATIONNAME));
		return CommandResult.success();
	}
	DataHandler.removeNation(nation.getUUID());
	MessageChannel.TO_ALL.send(Text.of(TextColors.AQUA, LanguageHandler.INFO_NATIONFALL.replaceAll("\\{NATION\\}", nation.getName())));
	return CommandResult.success();
}
 
Example #5
Source File: DataHandler.java    From Nations with MIT License 6 votes vote down vote up
public static boolean canClaim(Location<World> loc, boolean ignoreMinDistance, UUID toExclude)
{
	for (Nation nation : nations.values())
	{
		if (!nation.getUUID().equals(toExclude) && nation.getRegion().distance(loc) < ConfigHandler.getNode("others", "minNationDistance").getInt())
		{
			if (ignoreMinDistance)
			{
				if (nation.getRegion().isInside(loc))
				{
					return false;
				}
			}
			else
			{
				MessageChannel.TO_CONSOLE.send(Text.of("too close: ", loc, " nation: ", nation.getName()));
				return false;
			}
		}
	}
	return true;
}
 
Example #6
Source File: BroadcastExecutor.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	String message = ctx.<String> getOne("message").get();
	Text msg = TextSerializers.formattingCode('&').deserialize(message);
	Text broadcast = Text.of(TextColors.DARK_GRAY, "[", TextColors.DARK_RED, "Broadcast", TextColors.DARK_GRAY, "]", TextColors.GREEN, " ");
	Text finalBroadcast = Text.builder().append(broadcast).append(msg).build();

	if ((message.contains("https://")) || (message.contains("http://")))
	{
		Text urlBroadcast = Text.builder().append(broadcast).append(Utils.getURL(message)).build();
		MessageChannel.TO_ALL.send(urlBroadcast);
	}
	else
	{
		MessageChannel.TO_ALL.send(finalBroadcast);
	}
}
 
Example #7
Source File: ChatListener.java    From Nations with MIT License 5 votes vote down vote up
@Listener(order = Order.LATE)
public void onPlayerChat(MessageChannelEvent.Chat e, @First Player p)
{
	Nation nation = DataHandler.getNationOfPlayer(p.getUniqueId());
	if (nation == null)
	{
		return;
	}
	MessageChannel chan = MessageChannel.TO_ALL;
	Optional<MessageChannel> channel = e.getChannel();
	if (channel.isPresent())
	{
		chan = channel.get();
	}
	
	MessageFormatter formater = e.getFormatter();
	
	if (chan.equals(MessageChannel.TO_ALL) && ConfigHandler.getNode("others", "enableNationTag").getBoolean(true))
	{
		e.setMessage(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "publicChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(p.getUniqueId()))), formater.getHeader().toText()), formater.getBody().toText());
	}
	else if (chan instanceof NationMessageChannel)
	{
		e.setMessage(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(p.getUniqueId()))), formater.getHeader().toText()), Text.of(TextColors.YELLOW, formater.getBody().toText()));
		DataHandler.getSpyChannel().send(p, Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationSpyChatTag").getString()), TextColors.RESET, e.getMessage()));
	}
}
 
Example #8
Source File: NationLeaveExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
		if (nation == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
			return CommandResult.success();
		}
		if (nation.isPresident(player.getUniqueId()))
		{
			if (nation.getNumCitizens() > 1)
			{
				src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NEEDRESIGN));
				return CommandResult.success();
			}
			nation.removeCitizen(player.getUniqueId());
			src.sendMessage(Text.of(TextColors.GREEN, LanguageHandler.SUCCESS_LEAVENATION));
			DataHandler.removeNation(nation.getUUID());
			MessageChannel.TO_ALL.send(Text.of(TextColors.AQUA, LanguageHandler.INFO_NATIONFALL.replaceAll("\\{NATION\\}", nation.getName())));
			return CommandResult.success();
		}
		nation.removeCitizen(player.getUniqueId());
		DataHandler.saveNation(nation.getUUID());
		src.sendMessage(Text.of(TextColors.GREEN, LanguageHandler.SUCCESS_LEAVENATION));
		for (UUID citizen : nation.getCitizens())
		{
			Sponge.getServer().getPlayer(citizen).ifPresent(
					p -> p.sendMessage(Text.of(TextColors.AQUA, LanguageHandler.INFO_LEAVENATION.replaceAll("\\{PLAYER\\}", player.getName()))));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example #9
Source File: NationChatExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
		if (nation == null)
		{
			player.setMessageChannel(MessageChannel.TO_ALL);
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
			return CommandResult.success();
		}
		NationMessageChannel channel = nation.getMessageChannel();

		if (!ctx.<String>getOne("msg").isPresent())
		{
			if (player.getMessageChannel().equals(channel)) {
				player.setMessageChannel(MessageChannel.TO_ALL);
				src.sendMessage(Text.of(TextColors.YELLOW, LanguageHandler.INFO_NATIONCHAT_OFF));
			} else {
				player.setMessageChannel(channel);
				src.sendMessage(Text.of(TextColors.YELLOW, LanguageHandler.INFO_NATIONCHATON_ON));
			}
		}
		else
		{
			Text header = TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(player.getUniqueId())));
			
			Text msg = Text.of(header, TextColors.RESET, player.getName(), TextColors.WHITE, ": ", TextColors.YELLOW, ctx.<String>getOne("msg").get());
			channel.send(player, msg);
			DataHandler.getSpyChannel().send(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationSpyChatTag").getString()), TextColors.RESET, msg));
		}

	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example #10
Source File: ZoneDeleteExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Nation nation = DataHandler.getNation(player.getLocation());
		if (nation == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NEEDSTANDNATION));
			return CommandResult.success();
		}
		Zone zone = nation.getZone(player.getLocation());
		if (zone == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADZONENAME));
			return CommandResult.success();
		}
		String zoneName = zone.getName();
		if (!nation.isStaff(player.getUniqueId()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONSTAFF));
			return CommandResult.success();
		}
		nation.removeZone(zone.getUUID());
		DataHandler.saveNation(nation.getUUID());
		src.sendMessage(Text.of(TextColors.GREEN, LanguageHandler.SUCCESS_DELZONE.replaceAll("\\{ZONE\\}", zoneName)));
		MessageChannel.TO_CONSOLE.send(Text.of(player.getName(), " > ", nation.getName(), ": ", LanguageHandler.SUCCESS_DELZONE.replaceAll("\\{ZONE\\}", zoneName)));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example #11
Source File: DataHandler.java    From Nations with MIT License 5 votes vote down vote up
public static void removeNation(UUID uuid)
{
	Nation oldNation = getNation(uuid);
	if (oldNation != null) {
		MessageChannel.TO_CONSOLE.send(Text.of("Removing Nation " + uuid + ": "));
		MessageChannel.TO_CONSOLE.send(Utils.formatNationDescription(oldNation, Utils.CLICKER_ADMIN));
	}
	nations.remove(uuid);

	ArrayList<UUID> toRemove = new ArrayList<>();
	for (Nation nation : lastNationWalkedOn.values())
	{
		if (nation != null && nation.getUUID().equals(uuid))
		{
			toRemove.add(nation.getUUID());
		}
	}
	for (UUID uuidToRemove : toRemove)
	{
		lastNationWalkedOn.remove(uuidToRemove);
	}

	calculateWorldChunks();

	inviteRequests.removeIf(req -> req.getNationUUID().equals(uuid));
	joinRequests.removeIf(req -> req.getNationUUID().equals(uuid));

	File file = new File(nationsDir, uuid.toString() + ".json");
	file.delete();
}
 
Example #12
Source File: Nation.java    From Nations with MIT License 5 votes vote down vote up
public void removeCitizen(UUID uuid)
{
	zones.values().stream()
			.filter(zone -> uuid.equals(zone.getOwner()))
			.forEach(zone -> zone.setOwner(null));
	ministers.remove(uuid);
	citizens.remove(uuid);
	Optional<Player> player = Sponge.getServer().getPlayer(uuid);
	if (player.isPresent())
	{
		channel.removeMember(player.get());
		player.get().setMessageChannel(MessageChannel.TO_ALL);
	}
}
 
Example #13
Source File: PlayerConnectionListener.java    From Nations with MIT License 5 votes vote down vote up
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event)
{
	if (event.getTargetEntity() instanceof Player)
	{
		Player player = event.getTargetEntity();
		Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
		if (nation != null)
			nation.getMessageChannel().addMember(player);
		player.setMessageChannel(MessageChannel.TO_ALL);
		if (player.hasPermission("nations.admin.spychat"))
			DataHandler.getSpyChannel().addMember(player);
	}
}
 
Example #14
Source File: PersonalmessageCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, PersonalmessagePermissions.UC_PERSONALMESSAGE_PERSONALMESSAGE_BASE);
    CommandSource t = args.<CommandSource>getOne("player").get();

    String message = args.<String>getOne("message").get();
    Text fmessage = Messages.getFormatted("personalmessage.command.personalmessage.format.receive", "%player%", sender, "%message%", message);

    //Event
    Cause cause = Cause.builder().append(UltimateCore.getContainer()).append(sender).append(t).build(EventContext.builder().build());
    MessageEvent.MessageFormatter formatter = new MessageEvent.MessageFormatter(fmessage);
    final CommandSource tf = t;
    MessageChannel channel = () -> Arrays.asList(tf);
    PersonalmessageEvent event = new PersonalmessageEvent(cause, sender, t, formatter, channel, message, fmessage);
    Sponge.getEventManager().post(event);
    if (!event.isMessageCancelled()) {
        Text received = event.getFormatter().toText();
        t.sendMessage(received);
        //Reply
        UUID uuid_s = sender instanceof Player ? ((Player) sender).getUniqueId() : UUID.fromString("00000000-0000-0000-0000-000000000000");
        UUID uuid_t = t instanceof Player ? ((Player) t).getUniqueId() : UUID.fromString("00000000-0000-0000-0000-000000000000");
        if (t instanceof Player) {
            UltimateUser user = UltimateCore.get().getUserService().getUser((Player) t);
            user.offer(PersonalmessageKeys.REPLY, uuid_s);
        }
        if (sender instanceof Player) {
            UltimateUser user2 = UltimateCore.get().getUserService().getUser((Player) sender);
            user2.offer(PersonalmessageKeys.REPLY, uuid_t);
        }
        //TODO better system for this message?
        Text send = Messages.getFormatted("personalmessage.command.personalmessage.format.send", "%player%", t, "%message%", message);
        sender.sendMessage(send);
        return CommandResult.success();
    } else {
        throw new ErrorMessageException(Messages.getFormatted(t, "personalmessage.command.personalmessage.cancelled"));
    }
}
 
Example #15
Source File: PersonalmessageEvent.java    From UltimateCore with MIT License 5 votes vote down vote up
public PersonalmessageEvent(Cause cause, CommandSource sender, CommandSource target, MessageFormatter formatter, MessageChannel channel, String text, Text message) {
    this.cause = cause;
    this.sender = sender;
    this.target = target;
    this.cancelled = false;
    this.formatter = formatter;
    this.channel = channel;
    this.orgchannel = channel;
    this.message = message;
    this.orgmessage = message;
    this.text = text;
}
 
Example #16
Source File: CacheService.java    From Web-API with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
public void onMessage(MessageChannelEvent event) {
    Optional<Player> player = event.getCause().first(Player.class);

    MessageChannel channel = event.getChannel().orElse(event.getOriginalChannel());
    CachedMessage msg = player.isPresent() ?
            new CachedChatMessage(player.get(), channel.getMembers(), event.getMessage()) :
            new CachedMessage(channel.getMembers(), event.getMessage());
    messages.add(msg);

    while (messages.size() > numChatMessages) {
        messages.poll();
    }
}
 
Example #17
Source File: ChatUILib.java    From ChatUI with MIT License 5 votes vote down vote up
@Listener(order = Order.PRE, beforeModifications = true)
@IsCancelled(Tristate.UNDEFINED)
public void onIncomingMessage(MessageChannelEvent.Chat event, @Root Player player) {
    if (getView(player).handleIncoming(event.getRawMessage())) {
        // No plugins should interpret this as chat
        event.setCancelled(true);
        event.setChannel(MessageChannel.TO_NONE);
    }
}
 
Example #18
Source File: KickExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	Server server = game.getServer();
	Player player = ctx.<Player> getOne("player").get();
	Optional<String> reason = ctx.<String> getOne("reason");

	if (server.getPlayer(player.getUniqueId()).isPresent())
	{
		Text finalKickMessage = Text.of(TextColors.GOLD, src.getName() + " kicked " + player.getName());

		if (reason.isPresent())
		{
			Text reas = TextSerializers.formattingCode('&').deserialize(reason.get());
			Text kickMessage = Text.of(TextColors.GOLD, src.getName() + " kicked " + player.getName() + " for ", TextColors.RED);
			finalKickMessage = Text.builder().append(kickMessage).append(reas).build();
			player.kick(reas);
		}
		else
		{
			player.kick();
		}

		MessageChannel.TO_ALL.send(finalKickMessage);
		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Player kicked."));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Player doesn't appear to be online!"));
	}

	return CommandResult.success();
}
 
Example #19
Source File: PlayerMoveListener.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Listener
public void onPlayerMove(MoveEntityEvent event)
{
	if (event.getTargetEntity() instanceof Player)
	{
		Player player = (Player) event.getTargetEntity();

		if (Utils.isTeleportCooldownEnabled() && EssentialCmds.teleportingPlayers.contains(player.getUniqueId()))
		{
			EssentialCmds.teleportingPlayers.remove(player.getUniqueId());
			player.sendMessage(Text.of(TextColors.RED, "Teleportation canceled due to movement."));
		}

		if (EssentialCmds.frozenPlayers.contains(player.getUniqueId()))
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot move while frozen."));
			event.setCancelled(true);
			return;
		}

		if (EssentialCmds.recentlyJoined.contains(player))
		{
			EssentialCmds.recentlyJoined.remove(player);

			if (EssentialCmds.afkList.containsKey(player.getUniqueId()))
			{
				EssentialCmds.afkList.remove(player.getUniqueId());
			}
		}
		else
		{
			if (EssentialCmds.afkList.containsKey(player.getUniqueId()))
			{
				AFK removeAFK = EssentialCmds.afkList.get(player.getUniqueId());

				if (removeAFK.getAFK())
				{
					if (Utils.shouldAnnounceAFK())
					{
						MessageChannel.TO_ALL.send(Text.of(TextColors.BLUE, player.getName(), TextColors.GOLD, " is no longer AFK."));
					}
				}

				EssentialCmds.afkList.remove(removeAFK);
			}

			AFK afk = new AFK(System.currentTimeMillis());
			EssentialCmds.afkList.put(player.getUniqueId(), afk);
		}

		if (!event.getFromTransform().getExtent().getUniqueId().equals(event.getToTransform().getExtent().getUniqueId()))
		{
			World oldWorld = event.getFromTransform().getExtent();
			World newWorld = event.getToTransform().getExtent();

			Utils.savePlayerInventory(player, oldWorld.getUniqueId());

			if (!Utils.doShareInventories(oldWorld.getName(), newWorld.getName()))
			{
				Utils.updatePlayerInventory(player, newWorld.getUniqueId());
			}

			player.offer(Keys.GAME_MODE, newWorld.getProperties().getGameMode());
		}
	}
}
 
Example #20
Source File: NationadminSetnameExecutor.java    From Nations with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (!ctx.<String> getOne("oldname").isPresent() || !ctx.<String> getOne("newname").isPresent())
	{
		src.sendMessage(Text.of(TextColors.YELLOW, "/na setname <oldname> <newname>"));
		return CommandResult.success();
	}
	String oldName = ctx.<String> getOne("oldname").get();
	String newName = ctx.<String> getOne("newname").get();
	Nation nation = DataHandler.getNation(oldName);
	if (nation == null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
		return CommandResult.success();
	}
	if (DataHandler.getNation(newName) != null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NAMETAKEN));
		return CommandResult.success();
	}
	if (DataHandler.getNationByTag(newName) != null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_TAGTAKEN));
		return CommandResult.success();
	}
	if (!newName.matches("[\\p{Alnum}\\p{IsIdeographic}\\p{IsLetter}\"_\"]*"))
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NAMEALPHA));
		return CommandResult.success();
	}
	if (newName.length() < ConfigHandler.getNode("others", "minNationNameLength").getInt()
			|| newName.length() > ConfigHandler.getNode("others", "maxNationNameLength").getInt())
	{
		src.sendMessage(Text.of(TextColors.RED,
				LanguageHandler.ERROR_NAMELENGTH
						.replaceAll("\\{MIN\\}",
								ConfigHandler.getNode("others", "minNationNameLength").getString())
						.replaceAll("\\{MAX\\}",
								ConfigHandler.getNode("others", "maxNationNameLength").getString())));
		return CommandResult.success();
	}
	nation.setName(newName);
	DataHandler.saveNation(nation.getUUID());
	MessageChannel.TO_ALL.send(Text.of(TextColors.RED,
			LanguageHandler.INFO_RENAME.replaceAll("\\{OLDNAME\\}", oldName).replaceAll("\\{NEWNAME\\}", nation.getName())));
	return CommandResult.success();
}
 
Example #21
Source File: ReplyCommand.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, PersonalmessagePermissions.UC_PERSONALMESSAGE_REPLY_BASE);

    Player p = (Player) sender;
    UltimateUser pu = UltimateCore.get().getUserService().getUser(p);
    Optional<UUID> tu = pu.get(PersonalmessageKeys.REPLY);
    if (!tu.isPresent()) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "personalmessage.command.reply.notarget"));
    }
    CommandSource t = Sponge.getServer().getPlayer(tu.get()).orElse(null);
    if (t == null) {
        if (tu.get() == UUID.fromString("00000000-0000-0000-0000-000000000000")) {
            t = Sponge.getServer().getConsole();
        } else {
            throw new ErrorMessageException(Messages.getFormatted(sender, "personalmessage.command.reply.notarget"));
        }
    }

    String message = args.<String>getOne("message").get();
    Text fmessage = Messages.getFormatted("personalmessage.command.personalmessage.format.receive", "%player%", sender, "%message%", message);

    //Event
    Cause cause = Cause.builder().append(UltimateCore.getContainer()).append(sender).append(t).build(EventContext.builder().build());
    MessageEvent.MessageFormatter formatter = new MessageEvent.MessageFormatter(fmessage);
    final CommandSource tf = t;
    MessageChannel channel = () -> Arrays.asList(tf);
    PersonalmessageEvent event = new PersonalmessageEvent(cause, sender, t, formatter, channel, message, fmessage);
    Sponge.getEventManager().post(event);
    if (!event.isMessageCancelled()) {
        Text received = event.getFormatter().toText();
        t.sendMessage(received);
        //Reply
        UUID uuid_s = ((Player) sender).getUniqueId();
        UUID uuid_t = t instanceof Player ? ((Player) t).getUniqueId() : UUID.fromString("00000000-0000-0000-0000-000000000000");
        if (t instanceof Player) {
            UltimateUser user = UltimateCore.get().getUserService().getUser((Player) t);
            user.offer(PersonalmessageKeys.REPLY, uuid_s);
        }
        UltimateUser user2 = UltimateCore.get().getUserService().getUser((Player) sender);
        user2.offer(PersonalmessageKeys.REPLY, uuid_t);
        //TODO better system for this message?
        Text send = Messages.getFormatted("personalmessage.command.personalmessage.format.send", "%player%", t, "%message%", message);
        sender.sendMessage(send);
        return CommandResult.success();
    } else {
        throw new ErrorMessageException(Messages.getFormatted(t, "personalmessage.command.personalmessage.cancelled"));
    }
}
 
Example #22
Source File: PersonalmessageEvent.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public MessageChannel getOriginalChannel() {
    return orgchannel;
}
 
Example #23
Source File: PersonalmessageEvent.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public Optional<MessageChannel> getChannel() {
    return Optional.ofNullable(channel);
}
 
Example #24
Source File: PersonalmessageEvent.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public void setChannel(@Nullable MessageChannel channel) {
    channel = channel;
}
 
Example #25
Source File: CommandSource.java    From Web-API with MIT License 4 votes vote down vote up
@Override
public void setMessageChannel(MessageChannel channel) { }
 
Example #26
Source File: CommandSource.java    From Web-API with MIT License 4 votes vote down vote up
@Override
public MessageChannel getMessageChannel() {
    if (hideInConsole)
        return MessageChannel.TO_NONE;
    return MessageChannel.TO_CONSOLE;
}
 
Example #27
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 #28
Source File: NationadminSettagExecutor.java    From Nations with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (!ctx.<String> getOne("nation").isPresent())
	{
		src.sendMessage(Text.of(TextColors.YELLOW, "/na settag <nation> [tag]"));
		return CommandResult.success();
	}
	String newTag = null;
	if (ctx.<String> getOne("tag").isPresent())
		newTag = ctx.<String> getOne("tag").get();
	Nation nation = DataHandler.getNation(ctx.<String> getOne("nation").get());
	if (nation == null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
		return CommandResult.success();
	}
	if (newTag != null && DataHandler.getNation(newTag) != null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NAMETAKEN));
		return CommandResult.success();
	}
	if (newTag != null && DataHandler.getNationByTag(newTag) != null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_TAGTAKEN));
		return CommandResult.success();
	}
	if (newTag != null && !newTag.matches("[\\p{Alnum}\\p{IsIdeographic}\\p{IsLetter}\"_\"]*"))
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_TAGALPHA));
		return CommandResult.success();
	}
	if (newTag != null && (newTag.length() < ConfigHandler.getNode("others", "minNationTagLength").getInt()
			|| newTag.length() > ConfigHandler.getNode("others", "maxNationTagLength").getInt()))
	{
		src.sendMessage(Text.of(TextColors.RED,
				LanguageHandler.ERROR_TAGLENGTH
						.replaceAll("\\{MIN\\}",
								ConfigHandler.getNode("others", "minNationTagLength").getString())
						.replaceAll("\\{MAX\\}",
								ConfigHandler.getNode("others", "maxNationTagLength").getString())));
		return CommandResult.success();
	}
	String oldTag = nation.getTag();
	nation.setTag(newTag);
	DataHandler.saveNation(nation.getUUID());
	MessageChannel.TO_ALL.send(Text.of(TextColors.RED,
			LanguageHandler.INFO_TAG.replaceAll("\\{NAME\\}", nation.getName()).replaceAll("\\{OLDTAG\\}", oldTag).replaceAll("\\{NEWTAG\\}", nation.getTag())));
	return CommandResult.success();
}
 
Example #29
Source File: NationSetnameExecutor.java    From Nations with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		if (!ctx.<String>getOne("name").isPresent())
		{
			src.sendMessage(Text.of(TextColors.YELLOW, "/n setname <name>"));
			return CommandResult.success();
		}
		Player player = (Player) src;
		Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
		if (nation == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
			return CommandResult.success();
		}
		if (!nation.isStaff(player.getUniqueId()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONSTAFF));
			return CommandResult.success();
		}
		String newName = ctx.<String>getOne("name").get();
		if (DataHandler.getNation(newName) != null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NAMETAKEN));
			return CommandResult.success();
		}
		if (DataHandler.getNationByTag(newName) != null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_TAGTAKEN));
			return CommandResult.success();
		}
		if (!newName.matches("[\\p{Alnum}\\p{IsIdeographic}\\p{IsLetter}\"_\"]*"))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NAMEALPHA));
			return CommandResult.success();
		}
		if (newName.length() < ConfigHandler.getNode("others", "minNationNameLength").getInt() || newName.length() > ConfigHandler.getNode("others", "maxNationNameLength").getInt())
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NAMELENGTH
					.replaceAll("\\{MIN\\}", ConfigHandler.getNode("others", "minNationNameLength").getString())
					.replaceAll("\\{MAX\\}", ConfigHandler.getNode("others", "maxNationNameLength").getString())));
			return CommandResult.success();
		}
		String oldName = nation.getName();
		nation.setName(newName);
		DataHandler.saveNation(nation.getUUID());
		MessageChannel.TO_ALL.send(Text.of(TextColors.AQUA, LanguageHandler.INFO_RENAME
				.replaceAll("\\{OLDNAME\\}", oldName)
				.replaceAll("\\{NEWNAME\\}", nation.getName())));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example #30
Source File: NationSettagExecutor.java    From Nations with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
		if (nation == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
			return CommandResult.success();
		}
		if (!nation.isStaff(player.getUniqueId()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONSTAFF));
			return CommandResult.success();
		}
		String newTag = null;
		if (ctx.<String>getOne("tag").isPresent())
			newTag = ctx.<String>getOne("tag").get();
		if (newTag != null && DataHandler.getNation(newTag) != null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NAMETAKEN));
			return CommandResult.success();
		}
		if (newTag != null && DataHandler.getNationByTag(newTag) != null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_TAGTAKEN));
			return CommandResult.success();
		}
		if (newTag != null && !newTag.matches("[\\p{Alnum}\\p{IsIdeographic}\\p{IsLetter}\"_\"]*"))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_TAGALPHA));
			return CommandResult.success();
		}
		if (newTag != null && (newTag.length() < ConfigHandler.getNode("others", "minNationTagLength").getInt() || newTag.length() > ConfigHandler.getNode("others", "maxNationTagLength").getInt()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_TAGLENGTH
					.replaceAll("\\{MIN\\}", ConfigHandler.getNode("others", "minNationTagLength").getString())
					.replaceAll("\\{MAX\\}", ConfigHandler.getNode("others", "maxNationTagLength").getString())));
			return CommandResult.success();
		}
		String oldName = nation.getTag();
		nation.setTag(newTag);
		DataHandler.saveNation(nation.getUUID());
		MessageChannel.TO_ALL.send(Text.of(TextColors.AQUA, LanguageHandler.INFO_TAG
				.replaceAll("\\{NAME\\}", nation.getName())
				.replaceAll("\\{OLDTAG\\}", oldName)
				.replaceAll("\\{NEWTAG\\}", nation.getTag())));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}