Added all the commands and added configurable messages for everything

This commit is contained in:
Teriuihi 2022-01-30 17:50:18 +01:00
parent 5fcf9da6b9
commit 4f4f48e847
16 changed files with 552 additions and 63 deletions

View File

@ -247,7 +247,6 @@ 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 PARTY_HELP = "";
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: " +
@ -255,16 +254,28 @@ public final class Config {
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);
PARTY_HELP = getString("party.messages.help", PARTY_HELP);
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);
@ -276,6 +287,37 @@ public final class Config {
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() {

View File

@ -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;
}
}

View File

@ -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,7 +113,7 @@ 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() +

View File

@ -1,15 +1,13 @@
package com.alttd.velocitychat.commands;
import com.alttd.chat.config.Config;
import com.alttd.velocitychat.commands.partysubcommands.Create;
import com.alttd.velocitychat.commands.partysubcommands.Invite;
import com.alttd.velocitychat.commands.partysubcommands.Join;
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.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import java.util.ArrayList;
@ -18,13 +16,19 @@ import java.util.List;
public class Party implements SimpleCommand {
private final List<SubCommand> subCommands;
private final MiniMessage miniMessage;
public Party() {
subCommands = Arrays.asList(new Create(),
subCommands = Arrays.asList(
new Help(this),
new Create(),
new Info(),
new Invite(),
new Join());
miniMessage = MiniMessage.get();
new Join(),
new Leave(),
new Name(),
new Owner(),
new Password(),
new Remove());
}
@Override
@ -34,19 +38,23 @@ public class Party implements SimpleCommand {
if (args.length < 1) {
if (!source.hasPermission("party.use"))
source.sendMessage(miniMessage.parse(Config.NO_PERMISSION));
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
else if (source instanceof Player)
source.sendMessage(miniMessage.parse(Config.PARTY_HELP));
source.sendMessage(getHelpMessage(source));
else
source.sendMessage(miniMessage.parse(Config.NO_CONSOLE));
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
return;
}
subCommands.stream()
.filter(subCommand -> subCommand.getName().equalsIgnoreCase(args[0]))
.findFirst()
.ifPresentOrElse(subCommand -> subCommand.execute(args, source),
() -> source.sendMessage(getHelpMessage(source)));
.ifPresentOrElse(subCommand -> {
if (source.hasPermission(subCommand.getPermission()))
subCommand.execute(args, source);
else
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
}, () -> source.sendMessage(getHelpMessage(source)));
}
@Override
@ -58,7 +66,7 @@ public class Party implements SimpleCommand {
subCommands.stream()
.filter(subCommand -> invocation.source().hasPermission(subCommand.getPermission()))
.forEach(subCommand -> suggest.add(subCommand.getName()));
} else if (args.length <= 1) {
} else if (args.length == 1) {
subCommands.stream()
.filter(subCommand -> invocation.source().hasPermission(subCommand.getPermission()))
.filter(subCommand -> subCommand.getName().startsWith(args[0].toLowerCase()))
@ -68,7 +76,7 @@ public class Party implements SimpleCommand {
.filter(subCommand -> invocation.source().hasPermission(subCommand.getPermission()))
.filter(subCommand -> subCommand.getName().equalsIgnoreCase(args[0]))
.findFirst()
.ifPresent(subCommand -> suggest.addAll(subCommand.suggest(args)));
.ifPresent(subCommand -> suggest.addAll(subCommand.suggest(args, invocation.source())));
}
if (args.length == 0)
@ -89,7 +97,7 @@ public class Party implements SimpleCommand {
return finalValues;
}
private Component getHelpMessage(CommandSource source) {
public Component getHelpMessage(CommandSource source) {
StringBuilder stringBuilder = new StringBuilder();
subCommands.stream()
@ -98,6 +106,12 @@ public class Party implements SimpleCommand {
if (stringBuilder.length() != 0)
stringBuilder.replace(stringBuilder.length() - 1, stringBuilder.length(), "");
return miniMessage.parse(Config.PARTY_HELP, Template.of("commands", stringBuilder.toString()));
return Utility.parseMiniMessage(Config.PARTY_HELP_WRAPPER, List.of(
Template.template("commands", stringBuilder.toString())
));
}
public List<SubCommand> getSubCommands() {
return subCommands;
}
}

View File

@ -14,7 +14,7 @@ public interface SubCommand {
void execute(String[] args, CommandSource source);
List<String> suggest(String[] args);
List<String> suggest(String[] args, CommandSource source);
String getHelpMessage();

View File

@ -12,6 +12,7 @@ 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 {
@ -32,7 +33,9 @@ public class Create implements SubCommand {
return;
}
if (PartyManager.getParty(args[1]) != null) {
source.sendMessage(Utility.parseMiniMessage("<red>A chat party with this name already exists.</red>"));
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]);
@ -45,12 +48,12 @@ public class Create implements SubCommand {
}
@Override
public List<String> suggest(String[] args) {
return null;
public List<String> suggest(String[] args, CommandSource source) {
return new ArrayList<>();
}
@Override
public String getHelpMessage() {
return null;
return Config.PARTY_HELP_CREATE;
}
}

View File

@ -0,0 +1,39 @@
package com.alttd.velocitychat.commands.partysubcommands;
import com.alttd.chat.config.Config;
import com.alttd.velocitychat.commands.Party;
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 Party partyCommand;
public Help(Party 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;
}
}

View File

@ -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;
}
}

View File

@ -3,6 +3,7 @@ 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;
@ -10,8 +11,11 @@ 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 {
@ -61,12 +65,19 @@ public class Invite implements SubCommand {
}
@Override
public List<String> suggest(String[] args) {
return null;
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 null;
return Config.PARTY_HELP_INVITE;
}
}

View File

@ -10,6 +10,7 @@ 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 {
@ -47,12 +48,12 @@ public class Join implements SubCommand {
}
@Override
public List<String> suggest(String[] args) {
return null;
public List<String> suggest(String[] args, CommandSource source) {
return new ArrayList<>();
}
@Override
public String getHelpMessage() {
return null;
return Config.PARTY_HELP_JOIN;
}
}

View File

@ -9,7 +9,9 @@ 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;
@ -39,12 +41,13 @@ public class Leave implements SubCommand {
party.removeUser(player.getUniqueId());
if (party.getOwnerUuid().equals(player.getUniqueId())) {
if (party.getPartyUsers().size() > 0) {
UUID uuid = party.newOwner();
UUID uuid = party.setNewOwner();
source.sendMessage(Utility.parseMiniMessage(Config.NOTIFY_FINDING_NEW_OWNER));
VelocityChat.getPlugin().getChatHandler().partyMessage(party, player, "<dark_aqua>" +
player.getUsername() +
" left the chat party, the new party owner is " + party.getPartyUser(uuid).getPlayerName(),
currentServer.get());
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())
)));
} else {
party.delete();
}
@ -54,12 +57,12 @@ public class Leave implements SubCommand {
}
@Override
public List<String> suggest(String[] args) {
return null;
public List<String> suggest(String[] args, CommandSource source) {
return new ArrayList<>();
}
@Override
public String getHelpMessage() {
return null;
return Config.PARTY_HELP_LEAVE;
}
}

View File

@ -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;
}
}

View File

@ -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())
)));
}
@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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -17,7 +17,6 @@ import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
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;
@ -85,7 +84,18 @@ public class ChatHandler {
// player2.sendMessage(receiverMessage);
}
public void partyMessage(Party party, Player player, String message, ServerConnection serverConnection) {
public void sendPartyMessage(Party party, Component message)
{
VelocityChat.getPlugin().getProxy().getAllPlayers().stream()
.filter(pl -> {
UUID uuid = pl.getUniqueId();
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());
Component senderName = user.getDisplayName();
@ -113,13 +123,7 @@ public class ChatHandler {
));
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, templates);
VelocityChat.getPlugin().getProxy().getAllPlayers().stream()
.filter(pl -> {
UUID uuid = pl.getUniqueId();
return party.getPartyUsers().stream().anyMatch(pu -> pu.getUuid().equals(uuid));
}).forEach(pl -> {
pl.sendMessage(partyMessage);
});
sendPartyMessage(party, partyMessage);
Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, templates);
for(Player pl : serverConnection.getServer().getPlayersConnected()) {