2022-05-06 02:28:39 +00:00
|
|
|
package dev.plex.guild;
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
2022-05-09 05:39:47 +00:00
|
|
|
import com.google.common.collect.Maps;
|
2022-05-07 22:49:50 +00:00
|
|
|
import dev.plex.guild.data.Member;
|
2022-05-06 02:28:39 +00:00
|
|
|
|
2022-05-09 05:39:47 +00:00
|
|
|
import java.util.*;
|
2022-05-06 02:28:39 +00:00
|
|
|
|
|
|
|
public class GuildHolder
|
|
|
|
{
|
2022-05-09 05:39:47 +00:00
|
|
|
public static final Map<UUID, List<Guild>> PENDING_INVITES = Maps.newHashMap();
|
2022-05-06 02:28:39 +00:00
|
|
|
private static final List<Guild> GUILDS = Lists.newArrayList();
|
|
|
|
|
2022-05-09 05:39:47 +00:00
|
|
|
public static boolean sendInvite(UUID uuid, Guild guild)
|
|
|
|
{
|
|
|
|
if (PENDING_INVITES.containsKey(uuid) && PENDING_INVITES.get(uuid).stream().anyMatch(guild1 -> guild1.getGuildUuid().equals(guild.getGuildUuid())))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (PENDING_INVITES.containsKey(uuid))
|
|
|
|
{
|
|
|
|
PENDING_INVITES.get(uuid).add(guild);
|
|
|
|
} else {
|
|
|
|
PENDING_INVITES.put(uuid, Lists.newArrayList(guild));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-06 02:28:39 +00:00
|
|
|
public void addGuild(Guild guild)
|
|
|
|
{
|
|
|
|
GUILDS.add(guild);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void deleteGuild(UUID owner)
|
|
|
|
{
|
2022-05-08 23:34:03 +00:00
|
|
|
GUILDS.removeIf(guild -> guild.getOwner().getUuid().equals(owner));
|
2022-05-06 02:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Optional<Guild> getGuild(UUID uuid)
|
|
|
|
{
|
2022-05-08 23:34:03 +00:00
|
|
|
return GUILDS.stream().filter(guild -> (guild.getOwner() != null && guild.getOwner().getUuid().equals(uuid)) || guild.getMembers().stream().map(Member::getUuid).toList().contains(uuid)).findFirst();
|
2022-05-08 05:54:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Guild> getGuilds()
|
|
|
|
{
|
|
|
|
return GUILDS.stream().toList();
|
2022-05-06 02:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|