Java Code Examples for org.bukkit.event.player.AsyncPlayerChatEvent#setCancelled()
The following examples show how to use
org.bukkit.event.player.AsyncPlayerChatEvent#setCancelled() .
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: PlayerChat.java From FunnyGuilds with Apache License 2.0 | 6 votes |
private boolean sendMessageToGuildMembers(AsyncPlayerChatEvent event, String message, PluginConfiguration c, Player player, Guild guild) { String guildPrefix = c.chatPriv; int prefixLength = guildPrefix.length(); if (message.length() > prefixLength && message.substring(0, prefixLength).equals(guildPrefix)) { String resultMessage = c.chatPrivDesign; resultMessage = StringUtils.replace(resultMessage, "{PLAYER}", player.getName()); resultMessage = StringUtils.replace(resultMessage, "{TAG}", guild.getTag()); resultMessage = StringUtils.replace(resultMessage, "{POS}", StringUtils.replace(c.chatPosition, "{POS}", getPositionString(User.get(player), c))); String messageWithoutPrefix = event.getMessage().substring(prefixLength).trim(); resultMessage = StringUtils.replace(resultMessage, "{MESSAGE}", messageWithoutPrefix); this.spy(player, messageWithoutPrefix); this.sendMessageToGuild(guild, player, resultMessage); event.setCancelled(true); return true; } return false; }
Example 2
Source File: RecipeBuilder.java From ProRecipes with GNU General Public License v2.0 | 6 votes |
@EventHandler public void onTalk(AsyncPlayerChatEvent event){ if(event.getPlayer().hasMetadata("recipeBuilder")){ String step = event.getPlayer().getMetadata("recipeBuilder").get(0).asString(); if(step.equalsIgnoreCase("choosePermission")){ if(event.getMessage().equalsIgnoreCase("no")){ event.setCancelled(true); openChoice(event.getPlayer()); return; } event.getPlayer().setMetadata("recPermission", new FixedMetadataValue(ProRecipes.getPlugin(), ChatColor.stripColor(event.getMessage()))); event.setCancelled(true); openChoice(event.getPlayer()); } } }
Example 3
Source File: Catchers.java From TabooLib with MIT License | 6 votes |
@EventHandler public void chat(AsyncPlayerChatEvent e) { if (playerdata.containsKey(e.getPlayer().getName()) && contains(e.getPlayer())) { e.setCancelled(true); // 1.14 supported. TabooLib.getPlugin().runTask(() -> { Catcher catcher = playerdata.get(e.getPlayer().getName()).getFirst(); // 退出 if (e.getMessage().split(" ")[0].matches(catcher.quit())) { playerdata.get(e.getPlayer().getName()).removeFirst().cancel(); } // 默认 else { // 如果终止引导 if (!catcher.after(e.getMessage())) { playerdata.get(e.getPlayer().getName()).removeFirst(); } else { catcher.before(); } } }); } }
Example 4
Source File: ListenerChat.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority=EventPriority.LOW, ignoreCancelled=true) public void onChat(AsyncPlayerChatEvent e) { FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); if(!config.getBoolean("disable-chat")) return; Player player = e.getPlayer(); ICombatManager combatManager = this.plugin.getCombatManager(); if(!combatManager.isInCombat(player)) return; e.setCancelled(true); String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.no-chat"); this.plugin.sendMessage(player, message); }
Example 5
Source File: ConfirmTransferCommandListener.java From Statz with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onAsyncChat(final AsyncPlayerChatEvent event) { Player player = event.getPlayer(); if (TransferCommand.confirmTransferSQLite.contains(player.getName())) { // Player did not type yes. if (!event.getMessage().trim().equalsIgnoreCase("yes")) { player.sendMessage(ChatColor.RED + "To confirm, type " + ChatColor.GOLD + "yes" + ChatColor.RED + ". To deny, just wait 10 seconds."); event.setCancelled(true); return; } player.sendMessage( ChatColor.RED + "Confirmed " + ChatColor.GRAY + "/statz transfer" + ChatColor.RED + " command!"); TransferCommand.confirmTransfer(player); // Cancel type of 'yes' event.setCancelled(true); } else if (TransferCommand.confirmTransferMySQL.contains(player.getName())) { // Player did not type yes. if (!event.getMessage().trim().equalsIgnoreCase("yes")) { player.sendMessage(ChatColor.RED + "To confirm, type " + ChatColor.GOLD + "yes" + ChatColor.RED + ". To deny, just wait 10 seconds."); event.setCancelled(true); return; } player.sendMessage( ChatColor.RED + "Confirmed " + ChatColor.GRAY + "/statz transfer reverse" + ChatColor.RED + " command!"); TransferCommand.confirmReverseTransfer(player); // Cancel type of 'yes' event.setCancelled(true); } }
Example 6
Source File: ChatEvent.java From MCAuthenticator with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); User user = instance.getCache().get(player.getUniqueId()); if (user == null) { event.getRecipients().clear(); return; } if (user.authenticated()) { Iterator<Player> recipients = event.getRecipients().iterator(); while(recipients.hasNext()) { User u = instance.getCache().get(recipients.next().getUniqueId()); if(u != null && !u.authenticated()) recipients.remove(); } return; } if (instance.getC().getBungeePluginChannel() == null) { boolean authenticate = false; try { authenticate = user.authenticate(event.getMessage(), player); } catch (Exception e) { instance.getC().sendDirect(player, "&cThere was a fatal exception when trying to authenticate you!"); } if (authenticate) { instance.getC().send(player, instance.getC().message("authenticated")); } else { instance.getC().send(player, instance.getC().message("authFailed")); } } event.setCancelled(true); }
Example 7
Source File: PlayerChat.java From FunnyGuilds with Apache License 2.0 | 5 votes |
private boolean sendMessageToGuildAllies(AsyncPlayerChatEvent event, String message, PluginConfiguration c, Player player, Guild guild) { String allyPrefix = c.chatAlly; int prefixLength = allyPrefix.length(); if (message.length() > prefixLength && message.substring(0, prefixLength).equals(allyPrefix)) { String resultMessage = c.chatAllyDesign; resultMessage = StringUtils.replace(resultMessage, "{PLAYER}", player.getName()); resultMessage = StringUtils.replace(resultMessage, "{TAG}", guild.getTag()); resultMessage = StringUtils.replace(resultMessage, "{POS}", StringUtils.replace(c.chatPosition, "{POS}", getPositionString(User.get(player), c))); String subMessage = event.getMessage().substring(prefixLength).trim(); resultMessage = StringUtils.replace(resultMessage, "{MESSAGE}", subMessage); this.spy(player, subMessage); this.sendMessageToGuild(guild, player, resultMessage); for (Guild g : guild.getAllies()) { this.sendMessageToGuild(g, player, resultMessage); } event.setCancelled(true); return true; } return false; }
Example 8
Source File: ChatCommand.java From MarriageMaster with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onChat(AsyncPlayerChatEvent event) { final MarriagePlayer player = getMarriagePlugin().getPlayerData(event.getPlayer()); if(player.isPrivateChatDefault()) { event.setCancelled(true); doChat(player, event.getMessage()); } }
Example 9
Source File: ChatEvent.java From StackMob-3 with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerChat(AsyncPlayerChatEvent event){ Player player = event.getPlayer(); if(StackTools.hasValidMetadata(player, GlobalValues.WAITING_FOR_INPUT)){ if(!(player.getMetadata(GlobalValues.WAITING_FOR_INPUT).get(0).asBoolean())){ return; } event.setCancelled(true); sm.getStickTools().updateStack(player, event.getMessage()); } }
Example 10
Source File: DPlayerListener.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); if (isCitizensNPC(player)) { return; } GlobalPlayer dPlayer = dPlayers.get(player); if (dPlayer == null) { return; } if (!dPlayer.isInGroupChat()) { return; } if (dPlayer instanceof DEditPlayer) { event.setCancelled(true); ((DInstancePlayer) dPlayer).chat(event.getMessage()); return; } PlayerGroup group = plugin.getPlayerGroup(player); if (group == null) { return; } boolean game = event.getMessage().startsWith(ALL) && dPlayer instanceof DInstancePlayer; event.setCancelled(true); if (game) { ((DInstancePlayer) dPlayer).chat(event.getMessage().substring(ALL.length())); } else { group.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatGroup(), dPlayer) + event.getMessage()); } }
Example 11
Source File: SilentNightListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler (priority = EventPriority.HIGH) public void onPlayerChat(AsyncPlayerChatEvent e){ if (nightMode && !e.isCancelled()){ e.setCancelled(true); e.getPlayer().sendMessage(Lang.SCENARIO_SILENTNIGHT_ERROR); } }
Example 12
Source File: CMListener.java From ChatMenuAPI with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerChat(AsyncPlayerChatEvent e) { Player player = e.getPlayer(); BiFunction<Player, String, Boolean> listener = chatListeners.get(player); if(listener != null) { e.setCancelled(true); if(listener.apply(player, e.getMessage())) chatListeners.remove(player); } }
Example 13
Source File: MuteManager.java From Hawk with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onChat(AsyncPlayerChatEvent e) { MuteEntry entry = getMuteInfo(e.getPlayer().getUniqueId()); if (entry == null) return; if (entry.expireTime <= System.currentTimeMillis()) { pardon(e.getPlayer().getUniqueId()); return; } e.setCancelled(true); e.getPlayer().sendMessage(ChatColor.RED + "You have been muted."); }
Example 14
Source File: ChatListener.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onChat(AsyncPlayerChatEvent e) { if (e.isCancelled() && plugin.getConfig().getBoolean("shop.ignore-cancel-chat-event")) { Util.debugLog("Ignored a chat event (Canceled by another plugin.)"); return; } if (!plugin.getShopManager().getActions().containsKey(e.getPlayer().getUniqueId())) { return; } // Fix stupid chat plugin will add a weird space before or after the number we want. plugin.getShopManager().handleChat(e.getPlayer(), e.getMessage().trim()); e.setCancelled(true); }
Example 15
Source File: ButtonAction.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public static void onChat(AsyncPlayerChatEvent event) { REQUEST_INPUT ri = REQUEST_INPUT.playerToAction.remove(event.getPlayer()); if (ri == null) return; event.setCancelled(true); ri.runnable.run(event.getPlayer(), event.getMessage()); ri.afterRun(event.getPlayer()); }
Example 16
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 17
Source File: ExampleSwearListener.java From NeuralNetworkAPI with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onChat(AsyncPlayerChatEvent e) { if (currentNN != null) if (!(currentNN.getCurrentNeuralNetwork() instanceof SwearBot)) return; if(training) return; //If it is not training, and if the demo is set to swearbot, then do the following: StringBuilder chat = new StringBuilder(); chat.append(" "); for (char c : e.getMessage().toUpperCase().toCharArray()) { if (c != ' ' && c != '?' && c != '.' && c != ',' && c != '!') chat.append(c); } //Add two spaces before the chat message, remove all spaces and punctuation marks so 's?h.i t' is treated as 'shit' for (int i = 0; i < chat.toString().length(); i++) { String testingString = chat.toString().substring(i); //We are using a scanner approach. This will offset the string by 1 char until it is at the last letter. for (NeuralNetwork k : swearbots) { ((SwearBot) k.getCurrentNeuralNetwork()).word .changeWord(testingString); //Loop through all the swear types. Testt it for each NN. boolean detectsSwearWord = ((SwearBot) k .getCurrentNeuralNetwork()).tickAndThink()[0]; if (detectsSwearWord) { // The bot detects a similarity to a swear word. May be a swear. e.setCancelled(true); e.getPlayer() .sendMessage( "[SwearBot] Do not swear. Found similarities of \"" + ((SwearBot) k .getCurrentNeuralNetwork()).filterType + "\" in \"" + testingString + "\""); return; } } } }
Example 18
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 19
Source File: ListenerTrMenuInfo.java From TrMenu with MIT License | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onChat(AsyncPlayerChatEvent e) { e.setCancelled(react(e.getPlayer(), e.getMessage().startsWith("#") ? e.getMessage().substring(1) : null)); }
Example 20
Source File: PlayerTalkListener.java From IridiumSkyblock with GNU General Public License v2.0 | 4 votes |
@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); } }