Added party disband command and a way to remove all users from a party
This commit is contained in:
parent
032d0e2bef
commit
0c8a4a97d3
|
|
@ -275,6 +275,9 @@ public final class Config {
|
|||
public static String PARTY_MEMBER_LOGGED_OFF = "<dark_aqua>[ChatParty] <player> left Altitude...</dark_aqua>";
|
||||
public static String RENAMED_PARTY = "<dark_aqua>[ChatParty] <owner> changed the party name from <old_name> to <new_name>!</dark_aqua>";
|
||||
public static String CHANGED_PASSWORD = "<green>Password was set to <password></green>";
|
||||
public static String DISBAND_PARTY_CONFIRM = "<green><bold>Are you sure you want to disband your party?</bold> " +
|
||||
"Type <gold>/party disband confirm <party></gold> to confirm.";
|
||||
public static String DISBANDED_PARTY = "<dark_aqua>[ChatParty] <owner> has disbanded <party>, everyone has been removed.</dark_aqua>";
|
||||
public static String PARTY_INFO = """
|
||||
<gold><bold>Chat party info</bold>:
|
||||
</gold><green>Name: <dark_aqua><party></dark_aqua>
|
||||
|
|
@ -306,6 +309,8 @@ public final class Config {
|
|||
PARTY_MEMBER_LOGGED_OFF = getString("party.messages.party-member-logged-off", PARTY_MEMBER_LOGGED_OFF);
|
||||
RENAMED_PARTY = getString("party.messages.renamed-party", RENAMED_PARTY);
|
||||
CHANGED_PASSWORD = getString("party.messages.changed-password", CHANGED_PASSWORD);
|
||||
DISBAND_PARTY_CONFIRM = getString("party.messages.disband-party-confirm", DISBAND_PARTY_CONFIRM);
|
||||
DISBANDED_PARTY = getString("party.messages.disbanded-party", DISBANDED_PARTY);
|
||||
PARTY_INFO = getString("party.messages.party-info", PARTY_INFO);
|
||||
}
|
||||
|
||||
|
|
@ -320,6 +325,7 @@ public final class Config {
|
|||
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>";
|
||||
public static String PARTY_HELP_DISBAND = "<green>Remove everyone from your party and disband it: <gold>/party disband</gold></green>";
|
||||
public static String PARTY_HELP_CHAT = "<green>Talk in party chat: <gold>/p <message></gold></green>";
|
||||
private static void partyHelp() {
|
||||
PARTY_HELP_WRAPPER = getString("party.help.wrapper", PARTY_HELP_WRAPPER);
|
||||
|
|
|
|||
|
|
@ -316,6 +316,24 @@ public class Queries {
|
|||
}
|
||||
}
|
||||
|
||||
public static void removeAllPartyUsers(ArrayList<PartyUser> partyUsers) {
|
||||
String query = "UPDATE chat_users SET party_id = -1 WHERE uuid = ?";
|
||||
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
PreparedStatement statement = connection.prepareStatement(query);
|
||||
|
||||
for (PartyUser partyUser : partyUsers) {
|
||||
statement.setString(1, partyUser.getUuid().toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void removePartyUser(UUID uuid) {
|
||||
String query = "UPDATE chat_users SET party_id = -1 WHERE uuid = ?";
|
||||
|
||||
|
|
|
|||
|
|
@ -98,6 +98,9 @@ public class Party {
|
|||
}
|
||||
|
||||
public void delete() {
|
||||
if (partyUsers.size() != 0) {
|
||||
Queries.removeAllPartyUsers(partyUsers);
|
||||
}
|
||||
Queries.removeParty(partyId);
|
||||
PartyManager.removeParty(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ public class PartyCommand implements SimpleCommand {
|
|||
subCommands = Arrays.asList(
|
||||
new Help(this),
|
||||
new Create(),
|
||||
new Disband(),
|
||||
new Info(),
|
||||
new Invite(),
|
||||
new 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 net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Disband implements SubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "disband";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String[] args, CommandSource source) {
|
||||
if (!(source instanceof Player player)) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return;
|
||||
}
|
||||
if (args.length != 1 && args.length != 3) {
|
||||
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.length == 1) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.DISBAND_PARTY_CONFIRM, List.of(
|
||||
Template.template("party", party.getPartyName())
|
||||
)));
|
||||
return;
|
||||
}
|
||||
if (!args[1].equalsIgnoreCase("confirm") || !args[2].equals(party.getPartyName())) {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.DISBANDED_PARTY, List.of(
|
||||
Template.template("owner", player.getUsername()),
|
||||
Template.template("party", party.getPartyName())
|
||||
)), null);
|
||||
party.delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.PARTY_HELP_DISBAND;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user