Java Code Examples for org.bukkit.event.player.AsyncPlayerChatEvent#getMessage()
The following examples show how to use
org.bukkit.event.player.AsyncPlayerChatEvent#getMessage() .
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: NickNamerPlugin.java From NickNamer with MIT License | 6 votes |
@EventHandler(priority = EventPriority.NORMAL) public void on(final AsyncPlayerChatEvent event) { if (ChatReplacementEvent.getHandlerList().getRegisteredListeners().length > 0) { final String message = event.getMessage(); Set<String> nickedPlayerNames = NickNamerAPI.getNickedPlayerNames(); String replacedMessage = NickNamerAPI.replaceNames(message, nickedPlayerNames, new NameReplacer() { @Override public String replace(String original) { Player player = Bukkit.getPlayer(original); if (player != null) { boolean async = !getServer().isPrimaryThread(); NameReplacementEvent replacementEvent = new ChatReplacementEvent(player, event.getRecipients(), message, original, original, async); Bukkit.getPluginManager().callEvent(replacementEvent); if (replacementEvent.isCancelled()) { return original; } return replacementEvent.getReplacement(); } return original; } }, true); event.setMessage(replacedMessage); } }
Example 2
Source File: MentionListener.java From NyaaUtils with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void AsyncChatEvent(AsyncPlayerChatEvent e) { if (!plugin.cfg.mention_enable) return; Runnable r = () -> { // In case if we got an asynchronous event if (e.getMessage().contains("@")) { Player sender = e.getPlayer(); String raw = e.getMessage(); String rep = raw.replace("@ ", "@"); Set<Player> playersNotified = Bukkit.getOnlinePlayers().parallelStream() .filter(p -> rep.contains("@" + p.getName())) .collect(Collectors.toSet()); notify(sender, raw, playersNotified, plugin); } }; if (e.isAsynchronous()) { Bukkit.getScheduler().runTask(plugin, r); } else { r.run(); } }
Example 3
Source File: VariableObjective.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onChat(AsyncPlayerChatEvent event) { String playerID = PlayerConverter.getID(event.getPlayer()); if (!containsPlayer(playerID)) { return; } if (event.getMessage().matches("[a-zA-Z]*: .*")) { event.setCancelled(true); String message = event.getMessage(); int index = message.indexOf(':'); String key = message.substring(0, index).trim(); String value = message.substring(index + 1).trim(); ((VariableData) dataMap.get(playerID)).add(key, value); event.getPlayer().sendMessage("§2§l\u2713"); } }
Example 4
Source File: IndicatorListener.java From HoloAPI with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onAsyncPlayerChat(AsyncPlayerChatEvent event) { if (!event.isCancelled()) { final Player p = event.getPlayer(); if (!HoloAPI.getVanishProvider().isVanished(p)) { final String msg = event.getMessage(); if (event.isAsynchronous()) { HoloAPI.getCore().getServer().getScheduler().scheduleSyncDelayedTask(HoloAPI.getCore(), new BukkitRunnable() { @Override public void run() { showChatHologram(p, msg); } }); } else { this.showChatHologram(p, msg); } } } }
Example 5
Source File: CommandEventHandler.java From GriefDefender with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerChatInput(AsyncPlayerChatEvent event) { final Player player = event.getPlayer(); final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); // check for command input if (playerData.isWaitingForInput()) { playerData.commandInput = event.getMessage(); playerData.commandConsumer.accept(player); event.setCancelled(true); } }
Example 6
Source File: ChatDispatcher.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onChat(AsyncPlayerChatEvent event) { if (CHAT_EVENT_CACHE.getIfPresent(event) == null) { event.setCancelled(true); } else { CHAT_EVENT_CACHE.invalidate(event); return; } final MatchPlayer player = manager.getPlayer(event.getPlayer()); if (player != null) { final String message = event.getMessage(); if (message.startsWith(GLOBAL_SYMBOL)) { sendGlobal(player.getMatch(), player, message.substring(1)); } else if (message.startsWith(DM_SYMBOL)) { final String target = message.substring(1, message.indexOf(" ")); final MatchPlayer receiver = getApproximatePlayer(player.getMatch(), target, player.getBukkit()); if (receiver == null) { player.sendWarning( TranslatableComponent.of("chat.message.unknownTarget", TextComponent.of(target))); } else { sendDirect( player.getMatch(), player, receiver.getBukkit(), message.replace(target, "").substring(1)); } } else if (message.startsWith(ADMIN_CHAT_SYMBOL) && player.getBukkit().hasPermission(Permissions.ADMINCHAT)) { sendAdmin(player.getMatch(), player, event.getMessage().substring(1)); } else { sendDefault(player.getMatch(), player, event.getMessage()); } } }
Example 7
Source File: ChatListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
@EventHandler public void signPlaced(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); UUID uuid = event.getPlayer().getUniqueId(); if (chatList.containsKey(uuid)) { if (Math.abs((System.currentTimeMillis() - chatList.get(uuid))) < 20000) { ChatListener.chatList.remove(uuid); event.setCancelled(true); String[] settings = toChange.get(uuid).split(":"); GameMap gMap = GameMap.getMap(settings[0]); String setting = settings[1]; String variable = event.getMessage(); if (gMap != null && setting.equals("display")) { gMap.setDisplayName(variable); player.sendMessage(new Messaging.MessageFormatter().setVariable("mapname", gMap.getName()).setVariable("displayname", variable).format("maps.name")); new BukkitRunnable() { @Override public void run() { gMap.update(); } }.runTask(SkyWarsReloaded.get()); SkyWarsReloaded.getIC().show(player, gMap.getArenaKey()); } else if (gMap != null && setting.equalsIgnoreCase("creator")) { gMap.setCreator(variable); player.sendMessage(new Messaging.MessageFormatter().setVariable("mapname", gMap.getName()).setVariable("creator", variable).format("maps.creator")); new BukkitRunnable() { @Override public void run() { gMap.update(); } }.runTask(SkyWarsReloaded.get()); SkyWarsReloaded.getIC().show(player, gMap.getArenaKey()); } ChatListener.toChange.remove(uuid); } else { ChatListener.chatList.remove(uuid); ChatListener.toChange.remove(uuid); } } }
Example 8
Source File: PlayerChat.java From FunnyGuilds with Apache License 2.0 | 5 votes |
@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 9
Source File: AsyncPlayerChat.java From StaffPlus with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); String message = event.getMessage(); if(shouldCancel(player, message)) { event.setCancelled(true); return; } List<User> mentioned = getMentioned(message); if(!mentioned.isEmpty()) { for(User user : mentioned) { alertCoordinator.onMention(user, player.getName()); } } if(options.chatBlacklistEnabled && options.chatEnabled) { BlacklistFactory blacklistFactory = new BlacklistFactory(message); if(blacklistFactory.runCheck().hasChanged()&& !permission.has(player, options.permissionBlacklist)) { event.setMessage(blacklistFactory.getResult()); if(options.chatBlacklistHoverable) { Set<Player> staffPlayers = new HashSet<Player>(); for(Player p : Bukkit.getOnlinePlayers()) { if(permission.has(p, options.permissionBlacklist)) { event.getRecipients().remove(p); staffPlayers.add(p); } } versionProtocol.sendHoverableJsonMessage(staffPlayers, messages.blacklistChatFormat.replace("%player%", player.getName()).replace("%message%", blacklistFactory.getResult()), message); } } } }
Example 10
Source File: ChatEventListener.java From ChatItem with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) //We need to have lowest priority in order to get to the event before DeluxeChat or other plugins do public void onChat(final AsyncPlayerChatEvent e) { if(e.getMessage().indexOf(SEPARATOR)!=-1){ //If the BELL character is found, we have to remove it String msg = e.getMessage().replace(Character.toString(SEPARATOR), ""); e.setMessage(msg); } boolean found = false; for (String rep : c.PLACEHOLDERS) if (e.getMessage().contains(rep)) { found = true; break; } if (!found) { return; } Player p = e.getPlayer(); if (!p.hasPermission("chatitem.use")) { if(!c.LET_MESSAGE_THROUGH) { e.setCancelled(true); } if(!c.NO_PERMISSION_MESSAGE.isEmpty() && c.SHOW_NO_PERM_NORMAL){ p.sendMessage(c.NO_PERMISSION_MESSAGE); } return; } if (p.getItemInHand().getType().equals(Material.AIR)) { if (c.DENY_IF_NO_ITEM) { e.setCancelled(true); if (!c.DENY_MESSAGE.isEmpty()) e.getPlayer().sendMessage(c.DENY_MESSAGE); return; } if(c.HAND_DISABLED) { return; } } if(c.COOLDOWN > 0 && !p.hasPermission("chatitem.ignore-cooldown")){ if(COOLDOWNS.containsKey(p.getName())){ long start = COOLDOWNS.get(p.getName()); long current = System.currentTimeMillis()/1000; long elapsed = current - start; if(elapsed >= c.COOLDOWN){ COOLDOWNS.remove(p.getName()); }else{ if(!c.LET_MESSAGE_THROUGH) { e.setCancelled(true); } if(!c.COOLDOWN_MESSAGE.isEmpty()){ long left = (start + c.COOLDOWN) - current; p.sendMessage(c.COOLDOWN_MESSAGE.replace(LEFT, calculateTime(left))); } return; } } } String s = e.getMessage(); for(String placeholder : c.PLACEHOLDERS){ s = s.replace(placeholder, c.PLACEHOLDERS.get(0)); } int occurrences = countOccurrences(c.PLACEHOLDERS.get(0), s); if(occurrences>c.LIMIT){ e.setCancelled(true); if(c.LIMIT_MESSAGE.isEmpty()){ return; } e.getPlayer().sendMessage(c.LIMIT_MESSAGE); return; } String oldmsg = e.getMessage(); StringBuilder sb = new StringBuilder(oldmsg); sb.append(SEPARATOR).append(e.getPlayer().getName()); e.setMessage(sb.toString()); Bukkit.getConsoleSender().sendMessage(String.format(e.getFormat(), e.getPlayer().getDisplayName(), oldmsg)); if(!p.hasPermission("chatitem.ignore-cooldown")) { COOLDOWNS.put(p.getName(), System.currentTimeMillis() / 1000); } }