commit
70d26a2255
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -209,13 +209,6 @@ public final class Config {
|
|||
GCCOOLDOWN = getInt("commands.globalchat.cooldown", GCCOOLDOWN);
|
||||
}
|
||||
|
||||
public static String PARTY_FORMAT = "<dark_aqua>(<gray><sender></gray> <hover:show_text:on <server>> → Party</hover>) <message>";
|
||||
public static String PARTY_SPY = "<i><gray>PC:</gray><dark_gray> <dark_gray><sendername></dark_gray>: <dark_gray><partyname></dark_gray> <message></dark_gray></i>";
|
||||
private static void party() {
|
||||
PARTY_FORMAT = getString("party.format", PARTY_FORMAT);
|
||||
PARTY_SPY = getString("party.spy", PARTY_SPY);
|
||||
}
|
||||
|
||||
public static String CHATFORMAT = "<white><light_purple><prefixall> <gray><hover:show_text:Click to message <sendername>><click:suggest_command:/msg <sendername> ><sender></hover>: <white><message>";
|
||||
public static String URLFORMAT = "<click:OPEN_URL:<clickurl>><url></click>";
|
||||
private static void Chat() {
|
||||
|
|
@ -252,6 +245,81 @@ public final class Config {
|
|||
|
||||
}
|
||||
|
||||
public static String PARTY_FORMAT = "<dark_aqua>(<gray><sender></gray> <hover:show_text:on <server>> → Party</hover>) <message>";
|
||||
public static String PARTY_SPY = "<i><gray>PC:</gray><dark_gray> <dark_gray><sendername></dark_gray>: <dark_gray><partyname></dark_gray> <message></dark_gray></i>";
|
||||
public static String NO_PERMISSION = "<red>You don't have permission to use this command.</red>";
|
||||
public static String NO_CONSOLE = "<red>This command can not be used by console</red>";
|
||||
public static String CREATED_PARTY = "<green>You created a chat party called: " +
|
||||
"'<gold><party_name></gold>' with the password: '<gold><party_password></gold>'</green>";
|
||||
public static String NOT_IN_A_PARTY = "<red>You're not in a chat party.</red>";
|
||||
public static String NOT_YOUR_PARTY = "<red>You don't own this chat party.</red>";
|
||||
public static String NOT_A_PARTY = "<red>This chat party does not exist.</red>";
|
||||
public static String PARTY_EXISTS = "<red>A chat party called <party> already exists.</red>";
|
||||
public static String INVALID_PLAYER = "<red>Invalid player.</red>";
|
||||
public static String NOT_ONLINE = "<red><player> must be online to receive an invite.</red>";
|
||||
public static String INVALID_PASSWORD = "<red>Invalid password.</red>";
|
||||
public static String JOINED_PARTY = "<green>You joined <party_name>!</green>";
|
||||
public static String NOTIFY_FINDING_NEW_OWNER = "<dark_aqua>Since you own this chat party a new party owner will be chosen.<dark_aqua>";
|
||||
public static String LEFT_PARTY = "<green>You have left the chat party!</green>";
|
||||
public static String OWNER_LEFT_PARTY = "<dark_aqua>[ChatParty]: <old_owner> left the chat party, the new party owner is <new_owner>";
|
||||
public static String NEW_PARTY_OWNER = "<dark_aqua>[ChatParty]: <old_owner> transferred the party to <new_owner>!";
|
||||
public static String CANT_REMOVE_PARTY_OWNER = "<red>You can't remove yourself, please leave instead.</red>";
|
||||
public static String REMOVED_FROM_PARTY = "<red>You were removed from the '<party>' chat party.</red>";
|
||||
public static String REMOVED_USER_FROM_PARTY = "<green>You removed <player> from the chat party!</green>";
|
||||
public static String NOT_A_PARTY_MEMBER = "<player> is not a member of your party!";
|
||||
public static String PARTY_INFO = """
|
||||
<gold><bold>Chat party info</bold>:
|
||||
</gold><green>Name: <dark_aqua><party></dark_aqua>
|
||||
Password: <dark_aqua><password></dark_aqua>
|
||||
Owner: <owner>
|
||||
Members: <members>""";
|
||||
private static void party() {
|
||||
PARTY_FORMAT = getString("party.format", PARTY_FORMAT);
|
||||
PARTY_SPY = getString("party.spy", PARTY_SPY);
|
||||
NO_PERMISSION = getString("party.messages.no-permission", NO_PERMISSION);
|
||||
NO_CONSOLE = getString("party.messages.no-console", NO_CONSOLE);
|
||||
CREATED_PARTY = getString("party.messages.created-party", CREATED_PARTY);
|
||||
NOT_IN_A_PARTY = getString("party.messages.not-in-a-party", NOT_IN_A_PARTY);
|
||||
NOT_YOUR_PARTY = getString("party.messages.not-your-party", NOT_YOUR_PARTY);
|
||||
NOT_A_PARTY = getString("party.messages.not-a-party", NOT_A_PARTY);
|
||||
INVALID_PLAYER = getString("party.messages.invalid-player", INVALID_PLAYER);
|
||||
NOT_ONLINE = getString("party.messages.not-online", NOT_ONLINE);
|
||||
INVALID_PASSWORD = getString("party.messages.invalid-password", INVALID_PASSWORD);
|
||||
NOTIFY_FINDING_NEW_OWNER = getString("party.messages.notify-finding-new-owner", NOTIFY_FINDING_NEW_OWNER);
|
||||
LEFT_PARTY = getString("party.messages.left-party", LEFT_PARTY);
|
||||
OWNER_LEFT_PARTY = getString("party.messages.owner-left-party", OWNER_LEFT_PARTY);
|
||||
NEW_PARTY_OWNER = getString("party.messages.new-owner", NEW_PARTY_OWNER);
|
||||
CANT_REMOVE_PARTY_OWNER = getString("party.messages.cant-remove-owner", CANT_REMOVE_PARTY_OWNER);
|
||||
REMOVED_FROM_PARTY = getString("party.messages.removed-from-party", REMOVED_FROM_PARTY);
|
||||
NOT_A_PARTY_MEMBER = getString("party.messages.not-a-party-member", NOT_A_PARTY_MEMBER);
|
||||
PARTY_INFO = getString("party.messages.party-info", PARTY_INFO);
|
||||
}
|
||||
|
||||
public static String PARTY_HELP_WRAPPER = "<gold>ChatParty help:\n<commands></gold>";
|
||||
public static String PARTY_HELP_HELP = "<green>Show this menu: <gold>/party help</gold></green>";
|
||||
public static String PARTY_HELP_CREATE = "<green>Create a party: <gold>/party create <party_name> <party_password></gold></green>";
|
||||
public static String PARTY_HELP_INFO = "<green>Show info about your current party: <gold>/party info</gold></green>";
|
||||
public static String PARTY_HELP_INVITE = "<green>Invite a user to your party: <gold>/party invite <username></gold></green>";
|
||||
public static String PARTY_HELP_JOIN = "<green>Join a party: <gold>/party join <party_name> <party_password></gold></green>";
|
||||
public static String PARTY_HELP_LEAVE = "<green>Leave your current party: <gold>/party leave</gold></green>";
|
||||
public static String PARTY_HELP_NAME = "<green>Change the name of your party: <gold>/party name <new_name></gold></green>";
|
||||
public static String PARTY_HELP_OWNER = "<green>Change the owner of your party: <gold>/party owner <new_owner_name></gold></green>";
|
||||
public static String PARTY_HELP_PASSWORD = "<green>Change the password of your party: <gold>/party password <new_password></gold></green>";
|
||||
public static String PARTY_HELP_REMOVE = "<green>Remove a member from your party: <gold>/party remove <member_name></gold></green>";
|
||||
private static void partyHelp() {
|
||||
PARTY_HELP_WRAPPER = getString("party.help.wrapper", PARTY_HELP_WRAPPER);
|
||||
PARTY_HELP_HELP = getString("party.help.help", PARTY_HELP_HELP);
|
||||
PARTY_HELP_CREATE = getString("party.help.create", PARTY_HELP_CREATE);
|
||||
PARTY_HELP_INFO = getString("party.help.info", PARTY_HELP_INFO);
|
||||
PARTY_HELP_INVITE = getString("party.help.invite", PARTY_HELP_INVITE);
|
||||
PARTY_HELP_JOIN = getString("party.help.join", PARTY_HELP_JOIN);
|
||||
PARTY_HELP_LEAVE = getString("party.help.leave", PARTY_HELP_LEAVE);
|
||||
PARTY_HELP_NAME = getString("party.help.name", PARTY_HELP_NAME);
|
||||
PARTY_HELP_OWNER = getString("party.help.owner", PARTY_HELP_OWNER);
|
||||
PARTY_HELP_PASSWORD = getString("party.help.password", PARTY_HELP_PASSWORD);
|
||||
PARTY_HELP_REMOVE = getString("party.help.remove", PARTY_HELP_REMOVE);
|
||||
}
|
||||
|
||||
private static void chatChannels() {
|
||||
ConfigurationNode node = getNode("chat-channels");
|
||||
if (node.empty()) {
|
||||
|
|
|
|||
|
|
@ -54,6 +54,6 @@ public class PartyManager {
|
|||
}
|
||||
|
||||
public static void loadParties() {
|
||||
//Queries.loadParties();
|
||||
Queries.loadParties();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class Party {
|
|||
private UUID ownerUuid;
|
||||
private String partyName;
|
||||
private String partyPassword;
|
||||
private static ArrayList<PartyUser> partyUsers; //TODO might need to be a map?
|
||||
private static ArrayList<PartyUser> partyUsers;
|
||||
|
||||
public Party(int partyId, UUID ownerUuid, String partyName, String partyPassword) {
|
||||
this.partyId = partyId;
|
||||
|
|
@ -29,9 +29,6 @@ public class Party {
|
|||
}
|
||||
|
||||
public void addUser(ChatUser chatUser, String playerName) {
|
||||
// this.partyUsers.put(partyUser.getUuid(), PlainComponentSerializer.plain().serialize(partyUser.getDisplayName()));
|
||||
// partyUser.setPartyId(getPartyId());
|
||||
// Queries.addPartyUser(partyUser);
|
||||
partyUsers.add(new PartyUser(chatUser.getUuid(), chatUser.getDisplayName(), playerName));
|
||||
chatUser.setPartyId(getPartyId());
|
||||
Queries.addPartyUser(chatUser);
|
||||
|
|
@ -41,9 +38,14 @@ public class Party {
|
|||
removeUser(ChatUserManager.getChatUser(uuid));
|
||||
}
|
||||
|
||||
public void removeUser(ChatUser partyUser) {
|
||||
partyUsers.remove(partyUser.getUuid());
|
||||
Queries.removePartyUser(partyUser.getUuid());
|
||||
public void removeUser(ChatUser chatUser) {
|
||||
UUID uuid = chatUser.getUuid();
|
||||
Optional<PartyUser> first = partyUsers.stream()
|
||||
.filter(partyUser -> partyUser.getUuid().equals(uuid))
|
||||
.findFirst();
|
||||
if (first.isEmpty()) return;
|
||||
partyUsers.remove(first.get());
|
||||
Queries.removePartyUser(uuid);
|
||||
}
|
||||
|
||||
public int getPartyId() {
|
||||
|
|
@ -54,7 +56,11 @@ public class Party {
|
|||
return ownerUuid;
|
||||
}
|
||||
|
||||
public UUID newOwner() {
|
||||
public void setNewOwner(UUID uuid) {
|
||||
setOwnerUuid(uuid);
|
||||
}
|
||||
|
||||
public UUID setNewOwner() {
|
||||
UUID uuid = partyUsers.iterator().next().getUuid();
|
||||
setOwnerUuid(uuid);
|
||||
return uuid;
|
||||
|
|
@ -62,7 +68,7 @@ public class Party {
|
|||
|
||||
public void setOwnerUuid(UUID ownerUuid) {
|
||||
this.ownerUuid = ownerUuid;
|
||||
Queries.setPartyOwner(ownerUuid, partyId); //TODO: Async pls
|
||||
Queries.setPartyOwner(ownerUuid, partyId);
|
||||
}
|
||||
|
||||
public String getPartyName() {
|
||||
|
|
@ -71,7 +77,7 @@ public class Party {
|
|||
|
||||
public void setPartyName(String partyName) {
|
||||
this.partyName = partyName;
|
||||
Queries.setPartyName(partyName, partyId); //TODO: Async pls
|
||||
Queries.setPartyName(partyName, partyId);
|
||||
}
|
||||
|
||||
public String getPartyPassword() {
|
||||
|
|
@ -80,7 +86,7 @@ public class Party {
|
|||
|
||||
public void setPartyPassword(String partyPassword) {
|
||||
this.partyPassword = partyPassword;
|
||||
Queries.setPartyPassword(partyPassword, partyId); //TODO: Async pls
|
||||
Queries.setPartyPassword(partyPassword, partyId);
|
||||
}
|
||||
|
||||
public boolean hasPartyPassword() {
|
||||
|
|
@ -112,4 +118,13 @@ public class Party {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PartyUser getPartyUser(String name) {
|
||||
for(PartyUser user : partyUsers) {
|
||||
if(name.equalsIgnoreCase(user.getPlayerName())) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -5,16 +5,13 @@ import com.alttd.chat.config.Config;
|
|||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
|
|
@ -27,7 +24,6 @@ import org.jetbrains.annotations.NotNull;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ChatParty implements CommandExecutor, TabCompleter {
|
||||
|
||||
|
|
@ -117,11 +113,11 @@ public class ChatParty implements CommandExecutor, TabCompleter {
|
|||
party.removeUser(player.getUniqueId());
|
||||
if (party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||
if (party.getPartyUsers().size() > 0) {
|
||||
UUID uuid = party.newOwner();
|
||||
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) {
|
||||
|
|
@ -238,15 +248,6 @@ public class ChatHandler {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,118 @@
|
|||
package com.alttd.velocitychat.commands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.commands.partysubcommands.*;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PartyCommand implements SimpleCommand {
|
||||
private final List<SubCommand> subCommands;
|
||||
|
||||
public PartyCommand() {
|
||||
subCommands = Arrays.asList(
|
||||
new Help(this),
|
||||
new Create(),
|
||||
new Info(),
|
||||
new Invite(),
|
||||
new Join(),
|
||||
new Leave(),
|
||||
new Name(),
|
||||
new Owner(),
|
||||
new Password(),
|
||||
new Remove());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(SimpleCommand.Invocation invocation) {
|
||||
String[] args = invocation.arguments();
|
||||
CommandSource source = invocation.source();
|
||||
|
||||
if (args.length < 1) {
|
||||
if (!source.hasPermission("party.use"))
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
||||
else if (source instanceof Player)
|
||||
source.sendMessage(getHelpMessage(source));
|
||||
else
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
|
||||
subCommands.stream()
|
||||
.filter(subCommand -> subCommand.getName().equalsIgnoreCase(args[0]))
|
||||
.findFirst()
|
||||
.ifPresentOrElse(subCommand -> {
|
||||
if (source.hasPermission(subCommand.getPermission()))
|
||||
subCommand.execute(args, source);
|
||||
else
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
||||
}, () -> source.sendMessage(getHelpMessage(source)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(SimpleCommand.Invocation invocation) {
|
||||
String[] args = invocation.arguments();
|
||||
List<String> suggest = new ArrayList<>();
|
||||
|
||||
if (args.length == 0) {
|
||||
subCommands.stream()
|
||||
.filter(subCommand -> invocation.source().hasPermission(subCommand.getPermission()))
|
||||
.forEach(subCommand -> suggest.add(subCommand.getName()));
|
||||
} else if (args.length == 1) {
|
||||
subCommands.stream()
|
||||
.filter(subCommand -> invocation.source().hasPermission(subCommand.getPermission()))
|
||||
.filter(subCommand -> subCommand.getName().startsWith(args[0].toLowerCase()))
|
||||
.forEach(subCommand -> suggest.add(subCommand.getName()));
|
||||
} else {
|
||||
subCommands.stream()
|
||||
.filter(subCommand -> invocation.source().hasPermission(subCommand.getPermission()))
|
||||
.filter(subCommand -> subCommand.getName().equalsIgnoreCase(args[0]))
|
||||
.findFirst()
|
||||
.ifPresent(subCommand -> suggest.addAll(subCommand.suggest(args, invocation.source())));
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
return suggest;
|
||||
else
|
||||
return finalizeSuggest(suggest, args[args.length - 1]);
|
||||
}
|
||||
|
||||
public List<String> finalizeSuggest(List<String> possibleValues, String remaining) {
|
||||
List<String> finalValues = new ArrayList<>();
|
||||
|
||||
for (String str : possibleValues) {
|
||||
if (str.toLowerCase().startsWith(remaining)) {
|
||||
finalValues.add(StringArgumentType.escapeIfRequired(str));
|
||||
}
|
||||
}
|
||||
|
||||
return finalValues;
|
||||
}
|
||||
|
||||
public Component getHelpMessage(CommandSource source) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
subCommands.stream()
|
||||
.filter(subCommand -> source.hasPermission(subCommand.getPermission()))
|
||||
.forEach(subCommand -> stringBuilder.append(subCommand.getHelpMessage()).append("\n"));
|
||||
if (stringBuilder.length() != 0)
|
||||
stringBuilder.replace(stringBuilder.length() - 1, stringBuilder.length(), "");
|
||||
|
||||
return Utility.parseMiniMessage(Config.PARTY_HELP_WRAPPER, List.of(
|
||||
Template.template("commands", stringBuilder.toString())
|
||||
));
|
||||
}
|
||||
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.alttd.velocitychat.commands;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SubCommand {
|
||||
|
||||
String getName();
|
||||
|
||||
default String getPermission() {
|
||||
return "party." + getName();
|
||||
}
|
||||
|
||||
void execute(String[] args, CommandSource source);
|
||||
|
||||
List<String> suggest(String[] args, CommandSource source);
|
||||
|
||||
String getHelpMessage();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Create implements SubCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "create";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
if (args.length < 3 || !args[1].matches("[\\w]{3,16}") || !args[2].matches("[\\w]{3,16}")) {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
if (PartyManager.getParty(args[1]) != null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_EXISTS, List.of(
|
||||
Template.template("party", args[1])
|
||||
)));
|
||||
return;
|
||||
}
|
||||
Party party = Queries.addParty(player.getUniqueId(), args[1], args[2]);
|
||||
// party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly
|
||||
party.addUser(ChatUserManager.getChatUser(player.getUniqueId()), player.getUsername());
|
||||
PartyManager.addParty(party);
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.CREATED_PARTY,
|
||||
List.of(Template.template("party_name", party.getPartyName()),
|
||||
Template.template("party_password", party.getPartyPassword()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_CREATE;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.velocitychat.commands.PartyCommand;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Help implements SubCommand {
|
||||
|
||||
private final PartyCommand partyCommand;
|
||||
|
||||
public Help(PartyCommand partyCommand)
|
||||
{
|
||||
this.partyCommand = partyCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
source.sendMessage(partyCommand.getHelpMessage(source));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_HELP;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Info implements SubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "info";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
Party party = PartyManager.getParty(player.getUniqueId());
|
||||
if (party == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||
return;
|
||||
}
|
||||
|
||||
List<Component> displayNames = new ArrayList<>();
|
||||
for (PartyUser partyUser : party.getPartyUsers()) {
|
||||
displayNames.add(partyUser.getDisplayName());
|
||||
}
|
||||
|
||||
List<Template> templates = new ArrayList<>(List.of(
|
||||
Template.template("party", party.getPartyName()),
|
||||
Template.template("password", party.getPartyPassword()),
|
||||
Template.template("owner", party.getPartyUser(party.getOwnerUuid()).getDisplayName()),
|
||||
Template.template("members", Component.join(Component.text(", "), displayNames))
|
||||
));
|
||||
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_INFO, templates));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_INFO;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Invite implements SubCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "invite";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
Party party = PartyManager.getParty(player.getUniqueId());
|
||||
if (party == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||
return;
|
||||
}
|
||||
if (!party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_YOUR_PARTY));
|
||||
return;
|
||||
}
|
||||
Optional<Player> optional = VelocityChat.getPlugin().getProxy().getPlayer(args[1]);
|
||||
if (optional.isEmpty()) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.INVALID_PLAYER));
|
||||
return;
|
||||
}
|
||||
Player target = optional.get();
|
||||
|
||||
if (!target.isActive()) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_ONLINE, List.of(
|
||||
Template.template("player", target.getUsername())
|
||||
)));
|
||||
return;
|
||||
}
|
||||
|
||||
target.sendMessage(Utility.parseMiniMessage("<click:run_command:'/chatparty join " + party.getPartyName() + " " + party.getPartyPassword() +
|
||||
"'><dark_aqua>You received an invite to join " + party.getPartyName() + " click this message to accept.</dark_aqua></click>"));
|
||||
source.sendMessage(Utility.parseMiniMessage("<green>You send a chat party invite to <player>!</green>", List.of(
|
||||
Template.template("player", target.getUsername())
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
ArrayList<String> suggest = new ArrayList<>();
|
||||
if (!(source instanceof Player))
|
||||
return suggest;
|
||||
if (args.length == 1 || args.length == 2)
|
||||
suggest.addAll(VelocityChat.getPlugin().getProxy().getAllPlayers().stream()
|
||||
.map(Player::getUsername)
|
||||
.collect(Collectors.toList()));
|
||||
return suggest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_INVITE;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Join implements SubCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "join";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
if (args.length < 3 || !args[1].matches("[\\w]{3,16}") || !args[2].matches("[\\w]{3,16}")) {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
|
||||
Party party = PartyManager.getParty(args[1]);
|
||||
if (party == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY));
|
||||
return;
|
||||
}
|
||||
if (!party.getPartyPassword().equals(args[2])) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.INVALID_PASSWORD));
|
||||
return;
|
||||
}
|
||||
|
||||
// party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly
|
||||
party.addUser(ChatUserManager.getChatUser(player.getUniqueId()), player.getUsername());
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.JOINED_PARTY, List.of(
|
||||
Template.template("party_name", party.getPartyName()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_JOIN;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Leave implements SubCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "leave";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
Party party = PartyManager.getParty(player.getUniqueId());
|
||||
if (party == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||
return;
|
||||
}
|
||||
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||
if (currentServer.isEmpty())
|
||||
return;
|
||||
|
||||
party.removeUser(player.getUniqueId());
|
||||
if (party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||
if (party.getPartyUsers().size() > 0) {
|
||||
UUID uuid = party.setNewOwner();
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOTIFY_FINDING_NEW_OWNER));
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
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();
|
||||
}
|
||||
} else {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.LEFT_PARTY));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_LEAVE;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Name implements SubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
Party party = PartyManager.getParty(player.getUniqueId());
|
||||
if (party == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||
return;
|
||||
}
|
||||
if (!party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_YOUR_PARTY));
|
||||
return;
|
||||
}
|
||||
if (!args[1].matches("[\\w]{3,16}")) {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
if (PartyManager.getParty(args[1]) != null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_EXISTS, List.of(
|
||||
Template.template("party", args[1])
|
||||
)));
|
||||
return;
|
||||
}
|
||||
party.setPartyName(args[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_NAME;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Owner implements SubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "owner";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
Party party = PartyManager.getParty(player.getUniqueId());
|
||||
if (party == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||
return;
|
||||
}
|
||||
if (!party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_YOUR_PARTY));
|
||||
return;
|
||||
}
|
||||
PartyUser partyUser = party.getPartyUser(args[1]);
|
||||
if (partyUser == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY_MEMBER, List.of(
|
||||
Template.template("player", args[1])
|
||||
)));
|
||||
return;
|
||||
}
|
||||
party.setNewOwner(partyUser.getUuid());
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.NEW_PARTY_OWNER, List.of(
|
||||
Template.template("old_owner", player.getUsername()),
|
||||
Template.template("new_owner", partyUser.getPlayerName())
|
||||
)), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
ArrayList<String> suggest = new ArrayList<>();
|
||||
if (!(source instanceof Player player))
|
||||
return suggest;
|
||||
UUID uuid = player.getUniqueId();
|
||||
Party party = PartyManager.getParty(uuid);
|
||||
if (party == null)
|
||||
return suggest;
|
||||
if (args.length == 1 || args.length == 2)
|
||||
suggest.addAll(party.getPartyUsers().stream()
|
||||
.filter(partyUser -> !partyUser.getUuid().equals(uuid))
|
||||
.map(PartyUser::getPlayerName).collect(Collectors.toList()));
|
||||
return suggest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_OWNER;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Password implements SubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "password";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
Party party = PartyManager.getParty(player.getUniqueId());
|
||||
if (party == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||
return;
|
||||
}
|
||||
if (!party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_YOUR_PARTY));
|
||||
return;
|
||||
}
|
||||
if (!args[1].matches("[\\w]{3,16}")) {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
party.setPartyPassword(args[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_PASSWORD;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package com.alttd.velocitychat.commands.partysubcommands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
import com.alttd.velocitychat.commands.SubCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Remove implements SubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "remove";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
Party party = PartyManager.getParty(player.getUniqueId());
|
||||
if (party == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||
return;
|
||||
}
|
||||
if (!party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_YOUR_PARTY));
|
||||
return;
|
||||
}
|
||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(args[1]);
|
||||
PartyUser partyUser;
|
||||
Player onlinePlayer = null;
|
||||
if (optionalPlayer.isEmpty()) {
|
||||
partyUser = party.getPartyUser(args[1]);
|
||||
if (partyUser == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY_MEMBER, List.of(
|
||||
Template.template("player", args[1])
|
||||
)));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
onlinePlayer = optionalPlayer.get();
|
||||
partyUser = party.getPartyUser(onlinePlayer.getUniqueId());
|
||||
if (partyUser == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY_MEMBER, List.of(
|
||||
Template.template("player", onlinePlayer.getUsername())
|
||||
)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
party.removeUser(ChatUserManager.getChatUser(partyUser.getUuid()));
|
||||
|
||||
if (partyUser.getUuid().equals(party.getOwnerUuid())) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.CANT_REMOVE_PARTY_OWNER));
|
||||
return;
|
||||
}
|
||||
|
||||
if (onlinePlayer != null && onlinePlayer.isActive()) {
|
||||
onlinePlayer.sendMessage(Utility.parseMiniMessage(Config.REMOVED_FROM_PARTY, List.of(
|
||||
Template.template("party", party.getPartyName())
|
||||
)));
|
||||
}
|
||||
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.REMOVED_USER_FROM_PARTY, List.of(
|
||||
Template.template("player", onlinePlayer == null ? partyUser.getPlayerName() : onlinePlayer.getUsername())
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
ArrayList<String> suggest = new ArrayList<>();
|
||||
if (!(source instanceof Player player))
|
||||
return suggest;
|
||||
UUID uuid = player.getUniqueId();
|
||||
Party party = PartyManager.getParty(uuid);
|
||||
if (party == null)
|
||||
return suggest;
|
||||
if (args.length == 1 || args.length == 2)
|
||||
suggest.addAll(party.getPartyUsers().stream()
|
||||
.filter(partyUser -> !partyUser.getUuid().equals(uuid))
|
||||
.map(PartyUser::getPlayerName).collect(Collectors.toList()));
|
||||
return suggest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_REMOVE;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import com.alttd.chat.config.Config;
|
|||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Mail;
|
||||
import com.alttd.chat.objects.Party;
|
||||
|
|
@ -18,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.*;
|
||||
|
||||
|
|
@ -83,6 +85,83 @@ public class ChatHandler {
|
|||
// player2.sendMessage(receiverMessage);
|
||||
}
|
||||
|
||||
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(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(), uuid, message);
|
||||
if(updatedMessage == null) {
|
||||
sendBlockedNotification("Party Language", player, message, "", serverConnection);
|
||||
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", serverConnection.getServer().getServerInfo().getName()),
|
||||
Template.template("[i]", item)
|
||||
));
|
||||
|
||||
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, templates);
|
||||
sendPartyMessage(party, partyMessage, user.getIgnoredBy());
|
||||
|
||||
Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, templates);
|
||||
for(Player pl : serverConnection.getServer().getPlayersConnected()) {
|
||||
if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||
pl.sendMessage(spyMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void globalAdminChat(String message) {
|
||||
Component component = GsonComponentSerializer.gson().deserialize(message);
|
||||
|
||||
|
|
|
|||
|
|
@ -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