2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
2018-06-01 22:39:52 +00:00
|
|
|
import com.google.common.base.Strings;
|
2020-12-25 19:46:43 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
2019-12-10 00:59:17 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
2020-06-30 07:25:38 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
2018-04-19 14:29:19 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FSync;
|
2018-06-02 20:08:35 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2020-06-30 07:25:38 +00:00
|
|
|
import net.md_5.bungee.api.ChatColor;
|
2020-07-01 03:38:29 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.SoundCategory;
|
2016-05-12 19:40:39 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
2020-07-01 03:38:29 +00:00
|
|
|
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
|
2015-11-15 23:32:04 +00:00
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class ChatManager extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
2015-11-15 23:32:04 +00:00
|
|
|
public void onPlayerChatFormat(AsyncPlayerChatEvent event)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
handleChatEvent(event);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
FLog.severe(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleChatEvent(AsyncPlayerChatEvent event)
|
|
|
|
{
|
|
|
|
final Player player = event.getPlayer();
|
|
|
|
String message = event.getMessage().trim();
|
2020-11-08 03:00:49 +00:00
|
|
|
|
2019-12-11 11:48:06 +00:00
|
|
|
// Format colors and strip &k
|
|
|
|
message = FUtil.colorize(message);
|
|
|
|
message = message.replaceAll(ChatColor.MAGIC.toString(), "&k");
|
2020-01-04 06:16:54 +00:00
|
|
|
|
2020-08-03 00:06:45 +00:00
|
|
|
if (ConfigEntry.SHOP_ENABLED.getBoolean() && ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean() && !plugin.sh.reactionString.isEmpty() && message.equals(plugin.sh.reactionString))
|
2020-04-08 08:34:08 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
2020-06-30 07:25:38 +00:00
|
|
|
PlayerData data = plugin.pl.getData(player);
|
2020-04-08 08:34:08 +00:00
|
|
|
data.setCoins(data.getCoins() + plugin.sh.coinsPerReactionWin);
|
2020-06-30 07:25:38 +00:00
|
|
|
plugin.pl.save(data);
|
2020-07-02 08:42:27 +00:00
|
|
|
plugin.sh.endReaction(player.getName());
|
2020-04-08 08:34:08 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + "You have been given " + ChatColor.GOLD + plugin.sh.coinsPerReactionWin + ChatColor.GREEN + " coins!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (!ConfigEntry.TOGGLE_CHAT.getBoolean() && !plugin.al.isAdmin(player))
|
2020-01-11 22:44:13 +00:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
2020-06-30 07:25:38 +00:00
|
|
|
playerMsg(player, "Chat is currently disabled.", org.bukkit.ChatColor.RED);
|
2020-01-11 22:44:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-30 07:41:01 +00:00
|
|
|
// Truncate messages that are too long - 256 characters is vanilla client max
|
|
|
|
if (message.length() > 256)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2017-06-30 07:41:01 +00:00
|
|
|
message = message.substring(0, 256);
|
2015-11-15 23:32:04 +00:00
|
|
|
FSync.playerMsg(player, "Message was shortened because it was too long to send.");
|
|
|
|
}
|
|
|
|
|
2016-03-07 20:32:05 +00:00
|
|
|
final FPlayer fPlayer = plugin.pl.getPlayerSync(player);
|
2020-01-04 02:42:23 +00:00
|
|
|
if (fPlayer.isLockedUp())
|
|
|
|
{
|
|
|
|
FSync.playerMsg(player, "You're locked up and cannot talk.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2020-04-08 02:20:01 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
// Check for adminchat
|
|
|
|
if (fPlayer.inAdminChat())
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
FSync.adminChatMessage(player, message);
|
2015-11-15 23:32:04 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-10 00:59:17 +00:00
|
|
|
// Check for 4chan trigger
|
2020-12-25 19:46:43 +00:00
|
|
|
boolean green = ChatColor.stripColor(message).toLowerCase().startsWith(">");
|
|
|
|
boolean orange = ChatColor.stripColor(message).toLowerCase().endsWith("<");
|
2019-12-10 00:59:17 +00:00
|
|
|
if (ConfigEntry.FOURCHAN_ENABLED.getBoolean())
|
|
|
|
{
|
|
|
|
if (green)
|
|
|
|
{
|
|
|
|
message = ChatColor.GREEN + message;
|
|
|
|
}
|
|
|
|
else if (orange)
|
|
|
|
{
|
|
|
|
message = ChatColor.GOLD + message;
|
|
|
|
}
|
|
|
|
}
|
2020-01-04 06:16:54 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
// Finally, set message
|
|
|
|
event.setMessage(message);
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
// Make format
|
2020-04-08 02:20:01 +00:00
|
|
|
String format = "%1$s §8\u00BB §f%2$s";
|
2016-05-12 19:40:39 +00:00
|
|
|
|
|
|
|
String tag = fPlayer.getTag();
|
|
|
|
if (tag != null && !tag.isEmpty())
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
format = tag.replace("%", "%%") + " " + format;
|
|
|
|
}
|
2020-11-08 03:00:49 +00:00
|
|
|
|
2019-08-22 21:48:30 +00:00
|
|
|
// Check for mentions
|
2020-12-25 19:46:43 +00:00
|
|
|
boolean mentionEveryone = ChatColor.stripColor(message).toLowerCase().contains("@everyone") && plugin.al.isAdmin(player);
|
2019-08-22 21:48:30 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2016-05-12 19:40:39 +00:00
|
|
|
|
|
|
|
// Set format
|
|
|
|
event.setFormat(format);
|
2019-11-28 09:08:36 +00:00
|
|
|
|
|
|
|
// Send to discord
|
2020-12-04 00:28:53 +00:00
|
|
|
if (!ConfigEntry.ADMIN_ONLY_MODE.getBoolean() && !Bukkit.hasWhitelist() && !plugin.pl.getPlayer(player).isMuted() && !plugin.tfg.inGuildChat(player))
|
2020-01-04 06:16:54 +00:00
|
|
|
{
|
2020-12-25 01:07:09 +00:00
|
|
|
plugin.dc.messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message));
|
2020-01-04 06:16:54 +00:00
|
|
|
}
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 22:42:46 +00:00
|
|
|
public ChatColor getColor(Displayable display)
|
2018-06-02 20:45:05 +00:00
|
|
|
{
|
2020-12-25 19:46:43 +00:00
|
|
|
return display.getColor();
|
2018-06-02 20:45:05 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 22:42:46 +00:00
|
|
|
public String getColoredTag(Displayable display)
|
2018-04-19 14:29:19 +00:00
|
|
|
{
|
|
|
|
ChatColor color = display.getColor();
|
2018-06-01 22:39:52 +00:00
|
|
|
return color + display.getAbbr();
|
2018-04-19 14:29:19 +00:00
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
public void adminChat(CommandSender sender, String message)
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2018-04-19 14:29:19 +00:00
|
|
|
Displayable display = plugin.rm.getDisplay(sender);
|
2020-12-04 00:28:53 +00:00
|
|
|
FLog.info("[ADMIN] " + sender.getName() + " " + display.getTag() + ": " + message, true);
|
2020-11-15 02:13:59 +00:00
|
|
|
plugin.dc.messageAdminChatChannel(sender.getName() + " \u00BB " + message);
|
2016-05-12 19:40:39 +00:00
|
|
|
|
2021-03-21 19:02:43 +00:00
|
|
|
server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)).forEach(player ->
|
|
|
|
{
|
2021-03-19 13:58:29 +00:00
|
|
|
Admin admin = plugin.al.getAdmin(player);
|
|
|
|
if (!Strings.isNullOrEmpty(admin.getAcFormat())) {
|
|
|
|
String format = admin.getAcFormat();
|
|
|
|
ChatColor color = getColor(display);
|
|
|
|
String msg = format.replace("%name%", sender.getName()).replace("%rank%", display.getAbbr()).replace("%rankcolor%", color.toString()).replace("%msg%", message);
|
|
|
|
player.sendMessage(FUtil.colorize(msg));
|
2021-03-21 19:02:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-19 13:58:29 +00:00
|
|
|
player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + sender.getName() + ChatColor.DARK_GRAY + " [" + getColoredTag(display) + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + ": " + ChatColor.GOLD + FUtil.colorize(message));
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
2021-03-19 13:58:29 +00:00
|
|
|
});
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 15:10:00 +00:00
|
|
|
public void reportAction(Player reporter, String reportedName, String report)
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
|
|
|
for (Player player : server.getOnlinePlayers())
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isAdmin(player))
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2022-05-26 15:10:00 +00:00
|
|
|
playerMsg(player, ChatColor.RED + "[REPORTS] " + ChatColor.GOLD + reporter.getName() + " has reported " + reportedName + " for " + report);
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
2022-05-26 15:10:00 +00:00
|
|
|
FLog.info("[REPORTS] " + reporter.getName() + " has reported " + reportedName + " for " + report);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
2020-07-17 02:24:59 +00:00
|
|
|
}
|