Fix reactions showing up in Discord bridge & colour codes showing up in bridge

This commit is contained in:
Allink 2023-07-25 00:28:58 +01:00
parent 6e140ace7d
commit 08115470b0
No known key found for this signature in database
4 changed files with 59 additions and 34 deletions

View File

@ -46,8 +46,13 @@ public class ChatManager extends FreedomService
private void handleChatEvent(AsyncPlayerChatEvent event)
{
final Player player = event.getPlayer();
String message = event.getMessage().trim();
String originalMessage = event.getMessage();
if (plugin.mu.onPlayerChat(player) || plugin.sh.handlePlayerChat(player, originalMessage))
{
event.setCancelled(true);
return;
}
String message = originalMessage.trim();
// Format colors and strip &k
message = FUtil.colorize(message);
message = message.replaceAll(ChatColor.MAGIC.toString(), "&k");
@ -82,6 +87,8 @@ public class ChatManager extends FreedomService
return;
}
plugin.dc.onPlayerChat(player, ChatColor.stripColor(message));
// Check for 4chan trigger
if (ConfigEntry.FOURCHAN_ENABLED.getBoolean())
{

View File

@ -3,7 +3,6 @@ package me.totalfreedom.totalfreedommod;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FSync;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.ChatColor;
@ -11,7 +10,6 @@ import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class Muter extends FreedomService
@ -26,26 +24,23 @@ public class Muter extends FreedomService
{
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event)
public boolean onPlayerChat(Player player)
{
Player player = event.getPlayer();
FPlayer fPlayer = plugin.pl.getPlayerSync(player);
if (!fPlayer.isMuted())
{
return;
return false;
}
if (plugin.al.isAdminSync(player))
{
fPlayer.setMuted(false);
return;
return false;
}
player.sendMessage(Component.text("You are muted.", NamedTextColor.RED));
event.setCancelled(true);
return true;
}
@EventHandler(priority = EventPriority.LOW)

View File

@ -514,16 +514,28 @@ public class Discord extends FreedomService
}
}
@EventHandler(ignoreCancelled = true)
public void onAsyncPlayerChat(AsyncPlayerChatEvent event)
public void onPlayerChat(Player player, String message)
{
Player player = event.getPlayer();
String message = event.getMessage();
if (!ConfigEntry.ADMIN_ONLY_MODE.getBoolean() && !server.hasWhitelist()
&& !plugin.pl.getPlayer(player).isMuted() && bot != null)
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
{
messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message));
return;
}
if (server.hasWhitelist())
{
return;
}
if (plugin.pl.getPlayer(player).isMuted())
{
return;
}
if (bot == null)
{
return;
}
messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message));
}
}

View File

@ -21,7 +21,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
@ -412,23 +411,35 @@ public class Shop extends FreedomService
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
public boolean handlePlayerChat(Player player, String message)
{
String message = event.getMessage();
Player player = event.getPlayer();
if (ConfigEntry.SHOP_ENABLED.getBoolean() && ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean()
&& !plugin.sh.reactionString.isEmpty() && message.equals(plugin.sh.reactionString))
if (!ConfigEntry.SHOP_ENABLED.getBoolean())
{
event.setCancelled(true);
PlayerData data = plugin.pl.getData(player);
data.setCoins(data.getCoins() + plugin.sh.coinsPerReactionWin);
plugin.pl.save(data);
plugin.sh.endReaction(player.getName());
player.sendMessage(ChatColor.GREEN + "You have been given " + ChatColor.GOLD
+ plugin.sh.coinsPerReactionWin + ChatColor.GREEN + " coins!");
return false;
}
if (!ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean())
{
return false;
}
if (plugin.sh.reactionString.isEmpty())
{
return false;
}
if (!message.equals(plugin.sh.reactionString))
{
return false;
}
PlayerData data = plugin.pl.getData(player);
data.setCoins(data.getCoins() + plugin.sh.coinsPerReactionWin);
plugin.pl.save(data);
plugin.sh.endReaction(player.getName());
player.sendMessage(ChatColor.GREEN + "You have been given " + ChatColor.GOLD
+ plugin.sh.coinsPerReactionWin + ChatColor.GREEN + " coins!");
return true;
}
public ShopItem getShopItem(int slot)