Finished party command, and sub commands

This commit is contained in:
2021-08-08 11:36:06 +02:00
parent 0932bf8d51
commit 2cb843b68c
18 changed files with 462 additions and 142 deletions
@@ -1,12 +1,12 @@
package com.alttd.chat.handler;
import com.alttd.chat.ChatPlugin;
import com.alttd.chat.commands.ChatChannel;
import com.alttd.chat.config.Config;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.Channel;
import com.alttd.chat.objects.channels.CustomChannel;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.objects.Party;
import com.alttd.chat.util.GalaxyUtility;
import com.alttd.chat.util.Utility;
import com.google.common.io.ByteArrayDataOutput;
@@ -17,12 +17,10 @@ import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
@@ -124,7 +122,7 @@ public class ChatHandler {
sendPluginMessage(player, "globalchat", component);
}
public void chatChannel(Player player, Channel channel, String message) {
public void chatChannel(Player player, CustomChannel channel, String message) {
if (!player.hasPermission(channel.getPermission())) {
player.sendMessage(MiniMessage.get().parse("<red>You don't have permission to use this channel.</red>"));
return;
@@ -137,7 +135,7 @@ public class ChatHandler {
String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message);
if(updatedMessage == null) {
GalaxyUtility.sendBlockedNotification("GC Language", player, message, "");
GalaxyUtility.sendBlockedNotification(channel.getChannelName() + " Language", player, message, "");
return; // the message was blocked
}
@@ -163,7 +161,35 @@ public class ChatHandler {
}
}
private void sendChatChannelMessage(Channel chatChannel, UUID uuid, Component component) {
public void partyMessage(Party party, Player player, String message) {
if (isMuted(player, message, "[" + party.getPartyName() + " Muted] ")) return;
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
Component senderName = user.getDisplayName();
String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message);
if(updatedMessage == null) {
GalaxyUtility.sendBlockedNotification("Party Language", player, message, "");
return; // the message was blocked
}
if(!player.hasPermission("chat.format")) {
updatedMessage = miniMessage.stripTokens(updatedMessage);
}
if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replace("[i]", "<[i]>");
List<Template> templates = new ArrayList<>(List.of(
Template.of("sender", senderName),
Template.of("message", updatedMessage),
Template.of("server", Bukkit.getServerName()),
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
Component component = miniMessage.parse(Config.PARTY_FORMAT, templates);
sendPartyMessage(player, party.getPartyId(), component);
}
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, Component component) {
if (!chatChannel.getServers().contains(Bukkit.getServerName())) return;
Bukkit.getServer().getOnlinePlayers().stream()
@@ -197,6 +223,16 @@ public class ChatHandler {
out.writeUTF(GsonComponentSerializer.gson().serialize(component));
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
}
private void sendPartyMessage(Player player, int partyId, Component component) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("party");
out.writeUTF(String.valueOf(partyId));
out.writeUTF(player.getUniqueId().toString());
out.writeUTF(GsonComponentSerializer.gson().serialize(component));
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
}
// Start - move these to util
private boolean isMuted(Player player, String message, String prefix) {