Added all the commands and added configurable messages for everything

This commit is contained in:
2022-01-30 17:50:18 +01:00
parent 5fcf9da6b9
commit 4f4f48e847
16 changed files with 552 additions and 63 deletions
@@ -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;
}
}
@@ -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();
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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())
)));
}
@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;
}
}
@@ -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()) {