mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
ChatManager now uses ChatRenderer properly
This commit is contained in:
parent
4b3c31f0e9
commit
5ba81de118
@ -1,15 +1,15 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import io.papermc.paper.chat.ChatRenderer;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.api.event.AdminChatEvent;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@ -24,6 +24,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -74,12 +75,6 @@ public class ChatManager extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
// Tag
|
||||
Component tag = fPlayer.getTag().append(Component.space());
|
||||
|
||||
// Nickname
|
||||
Component nickname = player.displayName();
|
||||
|
||||
// Splitter
|
||||
Component splitter = Component.text("»", NamedTextColor.DARK_GRAY);
|
||||
|
||||
@ -92,23 +87,6 @@ public class ChatManager extends FreedomService
|
||||
steamrolled = steamrolled.substring(0, 256);
|
||||
}
|
||||
|
||||
// Pinging
|
||||
Arrays.stream(steamrolled.split(" ")).filter(string -> string.startsWith("@")).forEach(possiblePlayer ->
|
||||
{
|
||||
Player potential = server.getPlayer(possiblePlayer.replace("@", ""));
|
||||
|
||||
// Ping only that particular player
|
||||
if (potential != null)
|
||||
{
|
||||
ping(player);
|
||||
}
|
||||
// Ping everyone (if the person pinging is an admin)
|
||||
else if (possiblePlayer.equalsIgnoreCase("@everyone") && plugin.al.isAdmin(player))
|
||||
{
|
||||
server.getOnlinePlayers().forEach(this::ping);
|
||||
}
|
||||
});
|
||||
|
||||
// Did this because sonarlint was complaining about doing the unboxing in the if statement.
|
||||
// Something about returning null because it was boxed... I'm not sure.
|
||||
boolean unboxed = ConfigEntry.FOURCHAN_ENABLED.getBoolean();
|
||||
@ -133,12 +111,31 @@ public class ChatManager extends FreedomService
|
||||
// This simply filters out shit like &k in a simple but stupid way.
|
||||
Component filtered = FUtil.miniMessage(FUtil.miniMessage(message.build()));
|
||||
|
||||
event.setCancelled(true);
|
||||
server.broadcast(FUtil.miniMessage("<tag><nickname> <splitter> <message>",
|
||||
Placeholder.component("tag", tag),
|
||||
Placeholder.component("nickname", nickname),
|
||||
// Pinging
|
||||
String steamrolledFiltered = FUtil.steamroll(filtered);
|
||||
Arrays.stream(steamrolledFiltered.split(" ")).filter(string -> string.startsWith("@")).forEach(possiblePlayer ->
|
||||
{
|
||||
Player potential = server.getPlayer(possiblePlayer.replace("@", ""));
|
||||
|
||||
// Ping only that particular player
|
||||
if (potential != null)
|
||||
{
|
||||
ping(potential);
|
||||
}
|
||||
// Ping everyone (if the person pinging is an admin)
|
||||
else if (possiblePlayer.equalsIgnoreCase("@everyone") && plugin.al.isAdmin(player))
|
||||
{
|
||||
server.getOnlinePlayers().forEach(this::ping);
|
||||
}
|
||||
});
|
||||
|
||||
event.message(filtered);
|
||||
|
||||
event.renderer((source, displayName, msg, viewer) -> FUtil.miniMessage("<tag><nickname> <splitter> <message>",
|
||||
Placeholder.component("tag", plugin.pl.getPlayer(source).getTag().append(Component.space())),
|
||||
Placeholder.component("nickname", displayName),
|
||||
Placeholder.component("splitter", splitter),
|
||||
Placeholder.component("message", filtered)));
|
||||
Placeholder.component("message", msg)));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
Loading…
Reference in New Issue
Block a user