Renamed partycommand and made party chat work from galaxy to proxy
This commit is contained in:
parent
4f4f48e847
commit
2acebc6c16
|
|
@ -34,7 +34,6 @@ public class ChatImplementation implements ChatAPI{
|
|||
|
||||
ChatUserManager.initialize(); // loads all the users from the db and adds them.
|
||||
RegexManager.initialize(); // load the filters and regexes from config
|
||||
PartyManager.initialize(); // load the parties from the db and add the previously loaded users to them
|
||||
}
|
||||
|
||||
public static ChatAPI get() {
|
||||
|
|
|
|||
|
|
@ -54,6 +54,6 @@ public class PartyManager {
|
|||
}
|
||||
|
||||
public static void loadParties() {
|
||||
//Queries.loadParties();
|
||||
Queries.loadParties();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ public class ChatPlugin extends JavaPlugin {
|
|||
registerCommand("unignore", new Unignore());
|
||||
registerCommand("muteserver", new MuteServer());
|
||||
registerCommand("spy", new Spy());
|
||||
registerCommand("chatparty", new ChatParty());
|
||||
registerCommand("pc", new PartyChat());
|
||||
// registerCommand("chatparty", new ChatParty());
|
||||
registerCommand("p", new PartyChat());
|
||||
for (Channel channel : Channel.getChannels()) {
|
||||
if (!(channel instanceof CustomChannel customChannel)) continue;
|
||||
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(customChannel));
|
||||
|
|
|
|||
|
|
@ -115,9 +115,9 @@ public class ChatParty implements CommandExecutor, TabCompleter {
|
|||
if (party.getPartyUsers().size() > 0) {
|
||||
UUID uuid = party.setNewOwner();
|
||||
sender.sendMessage(Utility.parseMiniMessage("<dark_aqua>Since you own this chat party a new party owner will be chosen.<dark_aqua>"));
|
||||
ChatPlugin.getInstance().getChatHandler().partyMessage(party, player, "<dark_aqua>" +
|
||||
player.getName() +
|
||||
" left the chat party, the new party owner is " + party.getPartyUser(uuid).getPlayerName());
|
||||
// ChatPlugin.getInstance().getChatHandler().partyMessage(party, player, "<dark_aqua>" +
|
||||
// player.getName() +
|
||||
// " left the chat party, the new party owner is " + party.getPartyUser(uuid).getPlayerName());
|
||||
} else {
|
||||
party.delete();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,11 +20,6 @@ public class PartyChat implements CommandExecutor {
|
|||
if(!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
Party party = PartyManager.getParty(player.getUniqueId());
|
||||
if (party == null) {
|
||||
sender.sendMessage(Utility.parseMiniMessage("<red>You are not in a party. For more info do <gold>/party</gold>.</red>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args.length == 0) {
|
||||
// TODO: 08/08/2021 lock into party chat
|
||||
|
|
@ -36,7 +31,7 @@ public class PartyChat implements CommandExecutor {
|
|||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatPlugin.getInstance().getChatHandler().partyMessage(party, player, message);
|
||||
ChatPlugin.getInstance().getChatHandler().partyMessage(player, message); //TODO send over proxy
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
|
||||
|
|
|
|||
|
|
@ -164,43 +164,53 @@ public class ChatHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public void partyMessage(Party party, Player player, String message) {
|
||||
if (isMuted(player, message, "[" + party.getPartyName() + " Muted] ")) return;
|
||||
public void partyMessage(Player player, String message) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("party");
|
||||
out.writeUTF(player.getUniqueId().toString());
|
||||
out.writeUTF(message);
|
||||
out.writeUTF(GsonComponentSerializer.gson().serialize(
|
||||
itemComponent(player.getInventory().getItemInMainHand())
|
||||
));
|
||||
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||
|
||||
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 = Utility.stripTokens(updatedMessage);
|
||||
}
|
||||
|
||||
if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replace("[i]", "<[i]>");
|
||||
|
||||
updatedMessage = Utility.formatText(updatedMessage);
|
||||
|
||||
List<Template> templates = new ArrayList<>(List.of(
|
||||
Template.template("sender", senderName),
|
||||
Template.template("sendername", senderName),
|
||||
Template.template("partyname", party.getPartyName()),
|
||||
Template.template("message", updatedMessage),
|
||||
Template.template("server", Bukkit.getServerName()),
|
||||
Template.template("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||
|
||||
Component component = Utility.parseMiniMessage(Config.PARTY_FORMAT, templates);
|
||||
// sendPartyMessage(player, party.getPartyId(), component);
|
||||
|
||||
Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, templates);
|
||||
for(Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||
pl.sendMessage(spyMessage);
|
||||
}
|
||||
}
|
||||
// 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 = Utility.stripTokens(updatedMessage);
|
||||
// }
|
||||
//
|
||||
// if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replace("[i]", "<[i]>");
|
||||
//
|
||||
// updatedMessage = Utility.formatText(updatedMessage);
|
||||
//
|
||||
// List<Template> templates = new ArrayList<>(List.of(
|
||||
// Template.template("sender", senderName),
|
||||
// Template.template("sendername", senderName),
|
||||
// Template.template("partyname", party.getPartyName()),
|
||||
// Template.template("message", updatedMessage),
|
||||
// Template.template("server", Bukkit.getServerName()),
|
||||
// Template.template("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||
//
|
||||
// Component component = Utility.parseMiniMessage(Config.PARTY_FORMAT, templates);
|
||||
//// sendPartyMessage(player, party.getPartyId(), component);
|
||||
//
|
||||
// Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, templates);
|
||||
// for(Player pl : Bukkit.getOnlinePlayers()) {
|
||||
// if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||
// pl.sendMessage(spyMessage);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, Component component) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,5 @@ commands:
|
|||
permission: command.chat.mute-server
|
||||
spy:
|
||||
permission: command.chat.togglespy
|
||||
chatparty:
|
||||
permission: command.chat.chatparty
|
||||
pc:
|
||||
permission: command.chat.pc
|
||||
p:
|
||||
permission: command.chat.p
|
||||
|
|
@ -3,10 +3,11 @@ package com.alttd.velocitychat;
|
|||
import com.alttd.chat.ChatAPI;
|
||||
import com.alttd.chat.ChatImplementation;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.commands.GlobalAdminChat;
|
||||
import com.alttd.velocitychat.commands.MailCommand;
|
||||
import com.alttd.velocitychat.commands.PartyCommand;
|
||||
import com.alttd.velocitychat.commands.Reload;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
|
|
@ -65,6 +66,7 @@ public class VelocityChat {
|
|||
|
||||
chatAPI = new ChatImplementation();
|
||||
DatabaseConnection.initialize();
|
||||
PartyManager.initialize(); // load the parties from the db and add the previously loaded users to them
|
||||
|
||||
serverHandler = new ServerHandler();
|
||||
chatHandler = new ChatHandler();
|
||||
|
|
@ -112,6 +114,7 @@ public class VelocityChat {
|
|||
new GlobalAdminChat(server);
|
||||
new Reload(server);
|
||||
new MailCommand(server);
|
||||
server.getCommandManager().register("party", new PartyCommand());
|
||||
// all (proxy)commands go here
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Party implements SimpleCommand {
|
||||
public class PartyCommand implements SimpleCommand {
|
||||
private final List<SubCommand> subCommands;
|
||||
|
||||
public Party() {
|
||||
public PartyCommand() {
|
||||
subCommands = Arrays.asList(
|
||||
new Help(this),
|
||||
new Create(),
|
||||
|
|
@ -29,6 +29,7 @@ public class Party implements SimpleCommand {
|
|||
new Owner(),
|
||||
new Password(),
|
||||
new Remove());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.velocitychat.commands.Party;
|
||||
import com.alttd.velocitychat.commands.PartyCommand;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
|
|
@ -10,9 +10,9 @@ import java.util.List;
|
|||
|
||||
public class Help implements SubCommand {
|
||||
|
||||
private final Party partyCommand;
|
||||
private final PartyCommand partyCommand;
|
||||
|
||||
public Help(Party partyCommand)
|
||||
public Help(PartyCommand partyCommand)
|
||||
{
|
||||
this.partyCommand = partyCommand;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class Leave implements SubCommand {
|
|||
Utility.parseMiniMessage(Config.OWNER_LEFT_PARTY, List.of(
|
||||
Template.template("old_owner", player.getUsername()),
|
||||
Template.template("new_owner", party.getPartyUser(uuid).getPlayerName())
|
||||
)));
|
||||
)), null);
|
||||
} else {
|
||||
party.delete();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class Owner implements SubCommand {
|
|||
Utility.parseMiniMessage(Config.NEW_PARTY_OWNER, List.of(
|
||||
Template.template("old_owner", player.getUsername()),
|
||||
Template.template("new_owner", partyUser.getPlayerName())
|
||||
)));
|
||||
)), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import com.velocitypowered.api.proxy.ServerConnection;
|
|||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -84,24 +85,52 @@ public class ChatHandler {
|
|||
// player2.sendMessage(receiverMessage);
|
||||
}
|
||||
|
||||
public void sendPartyMessage(Party party, Component message)
|
||||
public static void sendBlockedNotification(String prefix, Player player, String input, String target, ServerConnection serverConnection) {
|
||||
List<Template> templates = new ArrayList<>(List.of(
|
||||
Template.template("prefix", prefix),
|
||||
Template.template("displayname", Utility.getDisplayName(player.getUniqueId(), player.getUsername())),
|
||||
Template.template("target", (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")),
|
||||
Template.template("input", input)
|
||||
));
|
||||
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, templates);
|
||||
|
||||
serverConnection.getServer().getPlayersConnected().forEach(pl ->{
|
||||
if (pl.hasPermission("chat.alert-blocked")) {
|
||||
pl.sendMessage(blockedNotification);
|
||||
}
|
||||
});
|
||||
player.sendMessage(Utility.parseMiniMessage("<red>The language you used in your message is not allowed, " +
|
||||
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
|
||||
}
|
||||
|
||||
public void sendPartyMessage(Party party, Component message, @Nullable List<UUID> ignoredPlayers)
|
||||
{
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream()
|
||||
.filter(pl -> {
|
||||
UUID uuid = pl.getUniqueId();
|
||||
if (ignoredPlayers != null && ignoredPlayers.contains(uuid))
|
||||
return false;
|
||||
return party.getPartyUsers().stream().anyMatch(pu -> pu.getUuid().equals(uuid));
|
||||
}).forEach(pl -> {
|
||||
pl.sendMessage(message);
|
||||
});
|
||||
}
|
||||
|
||||
public void sendPartyMessage(Party party, Player player, String message, ServerConnection serverConnection) {
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
public void sendPartyMessage(UUID uuid, String message, Component item, ServerConnection serverConnection) {
|
||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(uuid);
|
||||
if (optionalPlayer.isEmpty()) return;
|
||||
Player player = optionalPlayer.get();
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
Party party = PartyManager.getParty(user.getPartyId());
|
||||
if (party == null) {
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||
return;
|
||||
}
|
||||
Component senderName = user.getDisplayName();
|
||||
|
||||
String updatedMessage = RegexManager.replaceText(player.getUsername(), player.getUniqueId(), message);
|
||||
String updatedMessage = RegexManager.replaceText(player.getUsername(), uuid, message);
|
||||
if(updatedMessage == null) {
|
||||
// GalaxyUtility.sendBlockedNotification("Party Language", player, message, "");
|
||||
sendBlockedNotification("Party Language", player, message, "", serverConnection);
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
|
|
@ -119,11 +148,11 @@ public class ChatHandler {
|
|||
Template.template("partyname", party.getPartyName()),
|
||||
Template.template("message", updatedMessage),
|
||||
Template.template("server", serverConnection.getServer().getServerInfo().getName()),
|
||||
Template.template("[i]", "item")
|
||||
Template.template("[i]", item)
|
||||
));
|
||||
|
||||
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, templates);
|
||||
sendPartyMessage(party, partyMessage);
|
||||
sendPartyMessage(party, partyMessage, user.getIgnoredBy());
|
||||
|
||||
Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, templates);
|
||||
for(Player pl : serverConnection.getServer().getPlayersConnected()) {
|
||||
|
|
|
|||
|
|
@ -28,61 +28,58 @@ public class PluginMessageListener {
|
|||
|
||||
@Subscribe
|
||||
public void onPluginMessageEvent(PluginMessageEvent event){
|
||||
if(event.getIdentifier().equals(identifier)){
|
||||
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||
if (!event.getIdentifier().equals(identifier)) return;
|
||||
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||
|
||||
if(event.getSource() instanceof Player){
|
||||
// if this happens there's an oopsie
|
||||
}
|
||||
if(event.getSource() instanceof ServerConnection){
|
||||
// Read the data written to the message
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
||||
String channel = in.readUTF();
|
||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
switch (channel) {
|
||||
case "globalchat":
|
||||
VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF(), in.readUTF());
|
||||
break;
|
||||
case "globaladminchat":
|
||||
VelocityChat.getPlugin().getChatHandler().globalAdminChat(in.readUTF());
|
||||
break;
|
||||
case "privatemessage":
|
||||
VelocityChat.getPlugin().getChatHandler().privateMessage(in.readUTF(), in.readUTF(), in.readUTF());
|
||||
break;
|
||||
case "chatchannel": {
|
||||
String channelName = in.readUTF();
|
||||
CustomChannel chatChannel = (CustomChannel) CustomChannel.getChatChannel(channelName);
|
||||
if(event.getSource() instanceof Player) {
|
||||
ALogger.warn("Received plugin message from a player");
|
||||
return;
|
||||
}
|
||||
if (!(event.getSource() instanceof ServerConnection serverConnection)) return;
|
||||
// Read the data written to the message
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
||||
String channel = in.readUTF();
|
||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
switch (channel) {
|
||||
case "globalchat":
|
||||
VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF(), in.readUTF());
|
||||
break;
|
||||
case "globaladminchat":
|
||||
VelocityChat.getPlugin().getChatHandler().globalAdminChat(in.readUTF());
|
||||
break;
|
||||
case "privatemessage":
|
||||
VelocityChat.getPlugin().getChatHandler().privateMessage(in.readUTF(), in.readUTF(), in.readUTF());
|
||||
break;
|
||||
case "chatchannel": {
|
||||
String channelName = in.readUTF();
|
||||
CustomChannel chatChannel = (CustomChannel) CustomChannel.getChatChannel(channelName);
|
||||
|
||||
if (chatChannel == null) {
|
||||
ALogger.warn("Received non existent channel" + channelName +".");
|
||||
break;
|
||||
}
|
||||
|
||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
chatChannel.getServers().forEach(server -> proxy.getServer(server).ifPresent(registeredServer ->
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData())));
|
||||
break;
|
||||
}
|
||||
case "party": {
|
||||
VelocityChat.getPlugin().getChatHandler().partyChat(in.readUTF(), UUID.fromString(in.readUTF()), GsonComponentSerializer.gson().deserialize(in.readUTF()));
|
||||
break;
|
||||
}
|
||||
case "tmppartyupdate": {
|
||||
int id = Integer.parseInt(in.readUTF());
|
||||
Queries.loadPartyUsers(id);
|
||||
VelocityChat.getPlugin().getProxy().getAllServers().forEach(registeredServer -> registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData()));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
|
||||
for (RegisteredServer registeredServer : proxy.getAllServers()) {
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData());
|
||||
}
|
||||
break;
|
||||
if (chatChannel == null) {
|
||||
ALogger.warn("Received non existent channel" + channelName +".");
|
||||
break;
|
||||
}
|
||||
|
||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
chatChannel.getServers().forEach(server -> proxy.getServer(server).ifPresent(registeredServer ->
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData())));
|
||||
break;
|
||||
}
|
||||
case "party": {
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(
|
||||
UUID.fromString(in.readUTF()),
|
||||
in.readUTF(),
|
||||
GsonComponentSerializer.gson().deserialize(in.readUTF()),
|
||||
serverConnection);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||
|
||||
for (RegisteredServer registeredServer : proxy.getAllServers()) {
|
||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user