mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 09:15:38 +00:00
Admins can now use color chatting and formatting.
This commit is contained in:
parent
d6d42cc905
commit
f2f3720de2
@ -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();
|
||||||
|
|
||||||
|
if (plugin.al.isAdmin(player))
|
||||||
|
{
|
||||||
|
// 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
|
// Strip color from messages
|
||||||
message = ChatColor.stripColor(message);
|
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)
|
||||||
@ -102,6 +118,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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user