started migrating party to proxy
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
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.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;
|
||||
import java.util.Arrays;
|
||||
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(),
|
||||
new Invite(),
|
||||
new Join());
|
||||
miniMessage = MiniMessage.get();
|
||||
}
|
||||
|
||||
@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(miniMessage.parse(Config.NO_PERMISSION));
|
||||
else if (source instanceof Player)
|
||||
source.sendMessage(miniMessage.parse(Config.PARTY_HELP));
|
||||
else
|
||||
source.sendMessage(miniMessage.parse(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
|
||||
subCommands.stream()
|
||||
.filter(subCommand -> subCommand.getName().equalsIgnoreCase(args[0]))
|
||||
.findFirst()
|
||||
.ifPresentOrElse(subCommand -> subCommand.execute(args, source),
|
||||
() -> 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)));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private 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 miniMessage.parse(Config.PARTY_HELP, Template.of("commands", stringBuilder.toString()));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
String getHelpMessage();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
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.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("<red>A chat party with this name already exists.</red>"));
|
||||
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()))));
|
||||
// update(player, party.getPartyId());
|
||||
//TODO put party in active party list
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
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 net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -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.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()))));
|
||||
// update(player, party.getPartyId()); TODO update party
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
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 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.newOwner();
|
||||
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());
|
||||
} else {
|
||||
party.delete();
|
||||
}
|
||||
} else {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.LEFT_PARTY));
|
||||
}
|
||||
// update(player, party.getPartyId()); TODO update party
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user