Java Code Examples for org.bukkit.event.player.AsyncPlayerChatEvent#getFormat()

The following examples show how to use org.bukkit.event.player.AsyncPlayerChatEvent#getFormat() . 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: EssentialsChatHandler.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onChatPlayer(AsyncPlayerChatEvent event) {
	String old = event.getFormat();
	if (old.toLowerCase(Locale.ENGLISH).contains("{parties_")) {
		// Bypass useless checks if this isn't an Parties placeholder
		boolean somethingChanged = false;
		PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
		PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyName());
		
		Matcher mat = PATTERN.matcher(old);
		while (mat.find()) {
			String base = mat.group(0);
			String identifier = mat.group(1);
			if (identifier != null) {
				identifier = identifier.toLowerCase(Locale.ENGLISH);
				PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder(identifier);
				if (placeholder != null) {
					String parsed = placeholder.formatPlaceholder(partyPlayer, party, identifier);
					if (parsed != null) {
						old = old.replace(base, plugin.getColorUtils().convertColors(parsed));
						somethingChanged = true;
					}
				}
			}
		}
		
		if(somethingChanged)
			event.setFormat(old);
	}
}
 
Example 2
Source File: ChatListener.java    From factions-top with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void replacePlaceholders(AsyncPlayerChatEvent event) {
    // Do nothing if placeholder should not be applied.
    if (!plugin.getSettings().isChatEnabled()) {
        return;
    }

    String placeholder = plugin.getSettings().getChatRankPlaceholder();

    if (!event.getFormat().contains(placeholder)) {
        return;
    }

    String factionId = plugin.getFactionsHook().getFaction(event.getPlayer());
    String format = event.getFormat();

    // Set rank not found if player is in an ignored faction.
    if (plugin.getSettings().getIgnoredFactionIds().contains(factionId)) {
        event.setFormat(format.replace(placeholder, plugin.getSettings().getChatRankNotFound()));
        return;
    }

    // Or if faction currently has no rank.
    FactionWorth worth = plugin.getWorthManager().getWorth(factionId);
    int rank = plugin.getWorthManager().getOrderedFactions().indexOf(worth) + 1;

    if (rank == 0) {
        event.setFormat(format.replace(placeholder, plugin.getSettings().getChatRankNotFound()));
        return;
    }

    // Update chat format with rank found placeholder.
    String rankFound = plugin.getSettings().getChatRankFound().replace(RANK_PLACEHOLDER, String.valueOf(rank));
    format = format.replace(placeholder, rankFound);
    event.setFormat(format);
}
 
Example 3
Source File: PlayerChat.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onChat(AsyncPlayerChatEvent event) {
    Player player = event.getPlayer();
    User user = User.get(player);
    PluginConfiguration c = FunnyGuilds.getInstance().getPluginConfiguration();
    
    if (user.hasGuild()) {
        Guild guild = user.getGuild();
        String message = event.getMessage();
        if (sendGuildMessage(event, message, c, player, guild)) {
            return;
        }
    }
    
    int points = user.getRank().getPoints();
    String format = event.getFormat();
    
    format = StringUtils.replace(format, "{RANK}", StringUtils.replace(c.chatRank, "{RANK}", String.valueOf(user.getRank().getPosition())));
    format = StringUtils.replace(format, "{POINTS}", c.chatPoints);
    format = StringUtils.replace(format, "{POINTS-FORMAT}", IntegerRange.inRange(points, c.pointsFormat, "POINTS"));
    format = StringUtils.replace(format, "{POINTS}", String.valueOf(points));
    
    if (user.hasGuild()) {
        format = StringUtils.replace(format, "{TAG}", StringUtils.replace(c.chatGuild, "{TAG}", user.getGuild().getTag()));
        format = StringUtils.replace(format, "{POS}", StringUtils.replace(c.chatPosition, "{POS}", getPositionString(user, c)));
    } else {
        format = StringUtils.replace(format, "{TAG}", "");
        format = StringUtils.replace(format, "{POS}", "");
    }
    
    event.setFormat(format);
}
 
Example 4
Source File: PlayerTalkListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerTalk(AsyncPlayerChatEvent event) {
    try {
        final Player player = event.getPlayer();
        final User user = User.getUser(player);

        if (user.warp != null) {
            if (user.warp.getPassword().equals(event.getMessage())) {
                Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> player.teleport(user.warp.getLocation()));
                player.sendMessage(Utils.color(IridiumSkyblock.getMessages().teleporting
                        .replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            } else {
                player.sendMessage(Utils.color(IridiumSkyblock.getMessages().wrongPassword
                        .replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                user.warp = null;
            }
            event.setCancelled(true);
        }

        final Island island = user.getIsland();

        String format = event.getFormat();
        if (format.contains(IridiumSkyblock.getConfiguration().chatRankPlaceholder)) {
            if (island == null) {
                format = format.replace(IridiumSkyblock.getConfiguration().chatRankPlaceholder, "");
            } else {
                format = format.replace(IridiumSkyblock.getConfiguration().chatRankPlaceholder, Utils.getIslandRank(island) + "");
            }
        }
        if (format.contains(IridiumSkyblock.getConfiguration().chatNAMEPlaceholder)) {
            if (island == null) {
                format = format.replace(IridiumSkyblock.getConfiguration().chatNAMEPlaceholder, "");
            } else {
                format = format.replace(IridiumSkyblock.getConfiguration().chatNAMEPlaceholder, island.getName());
            }
        }
        if (format.contains(IridiumSkyblock.getConfiguration().chatValuePlaceholder)) {
            if (island == null) {
                format = format.replace(IridiumSkyblock.getConfiguration().chatValuePlaceholder, "");
            } else {
                format = format.replace(IridiumSkyblock.getConfiguration().chatValuePlaceholder, island.getValue() + "");
            }
        }
        if (format.contains(IridiumSkyblock.getConfiguration().chatLevelPlaceholder)) {
            if (island == null) {
                format = format.replace(IridiumSkyblock.getConfiguration().chatLevelPlaceholder, "");
            } else {
                format = format.replace(IridiumSkyblock.getConfiguration().chatLevelPlaceholder, String.format("%.2f", island.getValue()));
            }
        }

        if (island != null && user.islandChat) {
            for (String member : island.getMembers()) {
                final Player islandPlayer = Bukkit.getPlayer(User.getUser(member).name);
                if (islandPlayer == null) continue;
                islandPlayer.sendMessage(Utils.color(IridiumSkyblock.getMessages().chatFormat)
                        .replace(IridiumSkyblock.getConfiguration().chatValuePlaceholder, island.getValue() + "")
                        .replace(IridiumSkyblock.getConfiguration().chatNAMEPlaceholder, island.getName())
                        .replace(IridiumSkyblock.getConfiguration().chatLevelPlaceholder, String.format("%.2f", island.getValue()))
                        .replace(IridiumSkyblock.getConfiguration().chatRankPlaceholder, Utils.getIslandRank(island) + "")
                        .replace("%player%", player.getName())
                        .replace("%message%", event.getMessage()));
            }
            event.setCancelled(true);
        }

        event.setFormat(Utils.color(format));
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 5
Source File: ChatPrefixSuffix.java    From MarriageMaster with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerChat(final AsyncPlayerChatEvent event)
{
	String format = event.getFormat();
	boolean changed = false;
	final MarriagePlayer player = plugin.getPlayerData(event.getPlayer());
	if(player.isMarried())
	{
		final Marriage marriage = player.getMarriageData();
		//noinspection ConstantConditions
		final MarriagePlayer partner = marriage.getPartner(player);
		//noinspection ConstantConditions
		String p = prefixFormatter.format(marriage, partner), s = suffixFormatter.format(marriage, partner);
		if(p.length() == 1) p = "";
		if(s.length() == 1) s = "";
		changed = !p.isEmpty() || !s.isEmpty();
		if(prefixOnLineBeginning)
		{
			format = p + format.replace("%1$s", "%1$s" + s);
		}
		else
		{
			format = format.replace("%1$s", p + "%1$s" + s);
		}
	}
	else
	{
		if(useStatusHeartPrefix)
		{
			if(prefixOnLineBeginning)
			{
				format = HEART_GRAY + format;
			}
			else
			{
				format = format.replace("%1$s", STATUS_HEART_NM);
			}
			changed = true;
		}
		if(useStatusHeartSuffix)
		{
			if(prefixOnLineBeginning)
			{
				format = HEART_GRAY + format;
			}
			else
			{
				format = format.replace("%1$s", "%1$s " + HEART_GRAY);
			}
			changed = true;
		}
	}
	if(changed) event.setFormat(format);
}