Add back api and server module

This commit is contained in:
len
2021-06-02 19:55:55 +02:00
parent b814a5b01b
commit 5d8d7b5dff
22 changed files with 100 additions and 61 deletions
@@ -27,7 +27,43 @@ public class ChatHandler {
plugin = ChatPlugin.getInstance();
}
public void globalChat(Player player, String message) {
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
if(user == null) return;
if(!user.isGcOn()) {
player.sendMessage();// GC IS OFF INFORM THEM ABOUT THIS and cancel
return;
}
// Check if the player has global chat enabled, if not warn them
String senderName, prefix = "";
senderName = player.getDisplayName(); // TODO this can be a component
// can also be cached in the chatuser object?
prefix = plugin.getChatAPI().getPrefix(player.getUniqueId());
MiniMessage miniMessage = MiniMessage.get();
message = Utility.parseColors(message);
if(!player.hasPermission("chat.format"))
message = miniMessage.stripTokens(message);
if(message.contains("[i]"))
message = message.replace("[i]", "<[i]>");
List<Template> templates = new ArrayList<>(List.of(
Template.of("sender", senderName),
Template.of("prefix", prefix),
Template.of("message", message),
Template.of("server", Bukkit.getServerName())/*,
Template.of("[i]", itemComponent(sender.getInventory().getItemInMainHand()))*/));
Component component = miniMessage.parse(Config.GCFORMAT, templates);
//todo make a method for this, it'll be used more then onc
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("globalchat");
out.writeUTF(miniMessage.serialize(component));
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
}
}