Guest User

Untitled

a guest
Mar 9th, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. @EventHandler
  2.     public void playerChat(AsyncPlayerChatEvent chat) {
  3.         chat.setCancelled(true);
  4.  
  5.         Player player = chat.getPlayer();
  6.         User user = luckPerms.getPlayerAdapter(Player.class).getUser(player);
  7.  
  8.         String prefix = user.getCachedData().getMetaData().getPrefix();
  9.         String suffix = user.getCachedData().getMetaData().getSuffix();
  10.         String msg = chat.getMessage();
  11.         String message = CityCraftChat.plugin.getConfig().getString("LocalPrefix") + " " + prefix + player.getName() + suffix + " §7» " + CityCraftChat.plugin.getConfig().getString("LocalChatColor") + msg;
  12.  
  13.         int blockDistance = CityCraftChat.plugin.getConfig().getInt("LocalChatDistance");
  14.         int onlinePlayers = Bukkit.getOnlinePlayers().size();
  15.  
  16.         Location playerLocation = chat.getPlayer().getLocation();
  17.  
  18.         for (Player pl : chat.getRecipients()) {
  19.  
  20.             if (pl.getLocation().distance(playerLocation) <= blockDistance) {
  21.                 pl.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
  22.             }
  23.  
  24.             if (onlinePlayers == 1) {
  25.                 player.sendMessage("§8<§c!§8> §7Nobody is online to hear you. It's a lonely world.");
  26.             }
  27.  
  28.             }
  29.  
  30.         chat.getRecipients().clear();
  31.  
  32.             }
Advertisement
Add Comment
Please, Sign In to add comment