add a check to make sure a user is already in the guild

This commit is contained in:
Taah 2022-05-09 18:58:05 -07:00
parent 3a7ac3603b
commit 18a36d45f2
3 changed files with 22 additions and 2 deletions

View File

@ -60,6 +60,7 @@ public class Guilds extends PlexModule
this.addDefaultMessage("guildsCommandDisplay", "<gold>{0} <yellow>{1}", "0 - The command name", "1 - The command description"); this.addDefaultMessage("guildsCommandDisplay", "<gold>{0} <yellow>{1}", "0 - The command name", "1 - The command description");
this.addDefaultMessage("guildCommandNotFound", "<red>'<gold>{0}</gold>'<red> is not a valid sub command!", "0 - The sub command"); this.addDefaultMessage("guildCommandNotFound", "<red>'<gold>{0}</gold>'<red> is not a valid sub command!", "0 - The sub command");
this.addDefaultMessage("guildNotFound", "<red>You're currently not a part of a guild!"); this.addDefaultMessage("guildNotFound", "<red>You're currently not a part of a guild!");
this.addDefaultMessage("guildInThis", "<red>You're currently a part of this guild!");
this.addDefaultMessage("alreadyInGuild", "<red>You're currently in a guild. Please do <gold>/guild leave<red> if you're a member, or if you're an owner with members, <gold>/guild promote <player><red> then <gold>/guild leave<red>, or just an owner, <gold>/guild disband<red>."); this.addDefaultMessage("alreadyInGuild", "<red>You're currently in a guild. Please do <gold>/guild leave<red> if you're a member, or if you're an owner with members, <gold>/guild promote <player><red> then <gold>/guild leave<red>, or just an owner, <gold>/guild disband<red>.");
this.addDefaultMessage("guildNotOwner", "<red>You're not the owner of this guild!"); this.addDefaultMessage("guildNotOwner", "<red>You're not the owner of this guild!");
this.addDefaultMessage("guildMemberNotFound", "<red>This guild member could not be found!"); this.addDefaultMessage("guildMemberNotFound", "<red>This guild member could not be found!");
@ -85,7 +86,7 @@ public class Guilds extends PlexModule
this.addDefaultMessage("guildNotValidInvite", "<red>You don't have an invite from this guild!"); this.addDefaultMessage("guildNotValidInvite", "<red>You don't have an invite from this guild!");
this.addDefaultMessage("guildInviteExists", "<red>You've already sent an invite to this person!"); this.addDefaultMessage("guildInviteExists", "<red>You've already sent an invite to this person!");
this.addDefaultMessage("guildInviteSent", "<green>You have sent an invite to <dark_green>{0}", "0 - The invitee"); this.addDefaultMessage("guildInviteSent", "<green>You have sent an invite to <dark_green>{0}", "0 - The invitee");
this.addDefaultMessage("guildInviteReceived", "<green>You have received an invite from <dark_green>{0}<green> for the guild <dark_green>{1}", "0 - The inviter", "1 - The guild name"); this.addDefaultMessage("guildInviteReceived", "<gold>You have received an invite from <yellow>{0}<gold> for the guild <yellow>{1}<newline><newline><green><bold><click:run_command:/guild invite accept {1}>[ACCEPT]<newline><newline><!bold><gold>You may also run <yellow>/guild invite accept {1}<gold> to accept this invite. It will expire in 5 minutes", "0 - The inviter", "1 - The guild name");
this.addDefaultMessage("guildMemberJoined", "<green>{0} has joined the guild!", "0 - The player who joined"); this.addDefaultMessage("guildMemberJoined", "<green>{0} has joined the guild!", "0 - The player who joined");
this.addDefaultMessage("guildMemberLeft", "<green>{0} has left the guild!", "0 - The player who left"); this.addDefaultMessage("guildMemberLeft", "<green>{0} has left the guild!", "0 - The player who left");
this.addDefaultMessage("guildDisbandNeeded", "<red>You need to disband your guild using <gold>/guild disband<red> or promote a new owner using <gold>/guild owner <player>"); this.addDefaultMessage("guildDisbandNeeded", "<red>You need to disband your guild using <gold>/guild disband<red> or promote a new owner using <gold>/guild owner <player>");

View File

@ -15,7 +15,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@CommandParameters(name = "info", aliases = "information", usage = "/guild <command>", description = "Shows the guild's information") @CommandParameters(name = "info", aliases = "information", usage = "/guild <command>", description = "Shows the guild's information")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.info") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.info")
@ -45,7 +47,8 @@ public class InfoSubCommand extends PlexCommand
{ {
send(player, mmString("<gold>Owner: <yellow>Unable to load cache...")); send(player, mmString("<gold>Owner: <yellow>Unable to load cache..."));
} }
send(player, mmString("<gold>Members (" + guild.getMembers().size() + "): " + StringUtils.join(guild.getMembers().stream().map(member -> DataUtils.getPlayer(member.getUuid(), false).getName()).toList(), ", "))); List<String> members = guild.getMembers().stream().filter(member -> !member.getUuid().equals(guild.getOwner().getUuid())).map(member -> DataUtils.getPlayer(member.getUuid(), false).getName()).toList();
send(player, mmString("<gold>Members (" + members.size() + "): " + StringUtils.join(members, ", ")));
send(player, mmString("<gold>Moderators (" + guild.getModerators().size() + "): " + StringUtils.join(guild.getModerators().stream().map(uuid -> DataUtils.getPlayer(uuid, false).getName()).toList(), ", "))); send(player, mmString("<gold>Moderators (" + guild.getModerators().size() + "): " + StringUtils.join(guild.getModerators().stream().map(uuid -> DataUtils.getPlayer(uuid, false).getName()).toList(), ", ")));
send(player, mmString("<gold>Prefix: " + (guild.getPrefix() == null ? "N/A" : guild.getPrefix()))); send(player, mmString("<gold>Prefix: " + (guild.getPrefix() == null ? "N/A" : guild.getPrefix())));
send(player, mmString("<gold>Created At: " + formatter.format(guild.getCreatedAt()))); send(player, mmString("<gold>Created At: " + formatter.format(guild.getCreatedAt())));

View File

@ -20,7 +20,11 @@ import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors; import java.util.stream.Collectors;
// TODO: 5/9/2022 5 minute timeout for invites
// TODO: 5/9/2022 deny command maybe?
// TODO: 5/9/2022 deny members from inviting themselves or existing members in the current guild
@CommandParameters(name = "invite", aliases = "inv", usage = "/guild <command> <player name>", description = "Invites a player to the guild") @CommandParameters(name = "invite", aliases = "inv", usage = "/guild <command> <player name>", description = "Invites a player to the guild")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.invite") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.invite")
@ -48,13 +52,21 @@ public class InviteSubCommand extends PlexCommand
String guildName = StringUtils.join(args, " ", 1, args.length); String guildName = StringUtils.join(args, " ", 1, args.length);
GuildHolder.PENDING_INVITES.get(player.getUniqueId()).stream().filter(guild -> guild.getName().equalsIgnoreCase(guildName)).findFirst().ifPresentOrElse(guild -> GuildHolder.PENDING_INVITES.get(player.getUniqueId()).stream().filter(guild -> guild.getName().equalsIgnoreCase(guildName)).findFirst().ifPresentOrElse(guild ->
{ {
AtomicBoolean continueCheck = new AtomicBoolean(true);
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresent(guild1 -> Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresent(guild1 ->
{ {
if (guild1.getGuildUuid().equals(guild.getGuildUuid()))
{
send(player, messageComponent("guildInThis"));
continueCheck.set(false);
return;
}
if (guild1.getOwner().getUuid().equals(player.getUniqueId())) if (guild1.getOwner().getUuid().equals(player.getUniqueId()))
{ {
if (guild1.getMembers().size() - 1 > 0) if (guild1.getMembers().size() - 1 > 0)
{ {
send(player, messageComponent("guildDisbandNeeded")); send(player, messageComponent("guildDisbandNeeded"));
continueCheck.set(false);
return; return;
} else } else
{ {
@ -70,6 +82,10 @@ public class InviteSubCommand extends PlexCommand
}); });
guild1.getMembers().removeIf(member -> member.getUuid().equals(player.getUniqueId())); guild1.getMembers().removeIf(member -> member.getUuid().equals(player.getUniqueId()));
}); });
if (!continueCheck.get())
{
return;
}
GuildHolder.PENDING_INVITES.remove(player.getUniqueId()); GuildHolder.PENDING_INVITES.remove(player.getUniqueId());
guild.addMember(player.getUniqueId()); guild.addMember(player.getUniqueId());
guild.getMembers().stream().map(Member::getPlayer).filter(Objects::nonNull).forEach(player1 -> guild.getMembers().stream().map(Member::getPlayer).filter(Objects::nonNull).forEach(player1 ->