Renamed partycommand and made party chat work from galaxy to proxy
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -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()) {
|
||||
|
||||
+48
-51
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user