Admins can now use color chatting and formatting.

This commit is contained in:
Ivan 2019-08-22 17:48:30 -04:00
parent d6d42cc905
commit f2f3720de2

View File

@ -7,6 +7,7 @@ import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FSync; import me.totalfreedom.totalfreedommod.util.FSync;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.admin.Admin;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -14,6 +15,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg; import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
public class ChatManager extends FreedomService public class ChatManager extends FreedomService
{ {
@ -51,8 +54,21 @@ public class ChatManager extends FreedomService
final Player player = event.getPlayer(); final Player player = event.getPlayer();
String message = event.getMessage().trim(); String message = event.getMessage().trim();
// Strip color from messages if (plugin.al.isAdmin(player))
message = ChatColor.stripColor(message); {
// Format color
message = FUtil.colorize(message);
message = message.replaceAll(ChatColor.BOLD.toString(), "&l");
message = message.replaceAll(ChatColor.MAGIC.toString(), "&k");
message = message.replaceAll(ChatColor.ITALIC.toString(), "&o");
message = message.replaceAll(ChatColor.UNDERLINE.toString(), "&n");
message = message.replaceAll(ChatColor.STRIKETHROUGH.toString(), "&m");
}
else
{
// Strip color from messages
message = ChatColor.stripColor(message);
}
// Truncate messages that are too long - 256 characters is vanilla client max // Truncate messages that are too long - 256 characters is vanilla client max
if (message.length() > 256) if (message.length() > 256)
@ -101,6 +117,16 @@ public class ChatManager extends FreedomService
{ {
format = tag.replace("%", "%%") + " " + format; format = tag.replace("%", "%%") + " " + format;
} }
// Check for mentions
Boolean mentionEveryone = ChatColor.stripColor(message).toLowerCase().contains("@everyone") && plugin.al.isAdmin(player);
for (Player p : server.getOnlinePlayers())
{
if (ChatColor.stripColor(message).toLowerCase().contains("@" + p.getName().toLowerCase()) || mentionEveryone)
{
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, SoundCategory.MASTER, 1337F, 0.9F);
}
}
// Set format // Set format
event.setFormat(format); event.setFormat(format);