2022-05-06 02:28:39 +00:00
package dev.plex ;
import dev.plex.command.GuildCommand ;
2022-05-08 23:34:03 +00:00
import dev.plex.config.ModuleConfig ;
2022-05-06 02:28:39 +00:00
import dev.plex.data.SQLGuildManager ;
import dev.plex.data.SQLManager ;
import dev.plex.guild.Guild ;
import dev.plex.guild.GuildHolder ;
2022-05-07 22:52:04 +00:00
import dev.plex.handler.ChatHandlerImpl ;
2022-05-07 22:49:50 +00:00
import dev.plex.listener.impl.ChatListener ;
2022-05-06 02:28:39 +00:00
import dev.plex.module.PlexModule ;
import dev.plex.storage.StorageType ;
import dev.plex.util.PlexLog ;
2022-05-07 22:49:50 +00:00
import io.papermc.paper.event.player.AsyncChatEvent ;
2022-05-06 02:28:39 +00:00
import lombok.Getter ;
import java.util.Arrays ;
//TODO: Implement mongodb
@Getter
public class Guilds extends PlexModule
{
private static Guilds module ;
2022-05-07 22:49:50 +00:00
private final GuildHolder guildHolder = new GuildHolder ( ) ;
2022-05-06 02:28:39 +00:00
private SQLGuildManager sqlGuildManager ;
2022-05-08 23:34:03 +00:00
private ModuleConfig config ;
2022-05-06 02:28:39 +00:00
@Override
public void load ( )
{
module = this ;
2022-05-08 23:34:03 +00:00
config = new ModuleConfig ( this , " data/config.yml " , " config.yml " ) ;
config . load ( ) ;
2022-05-06 02:28:39 +00:00
}
@Override
public void enable ( )
{
if ( getPlex ( ) . getStorageType ( ) = = StorageType . MONGODB )
{
getPlex ( ) . getMongoConnection ( ) . getDatastore ( ) . getMapper ( ) . map ( Guild . class ) ;
getPlex ( ) . getMongoConnection ( ) . getDatastore ( ) . ensureIndexes ( ) ;
2022-05-19 05:20:58 +00:00
}
else
{
2022-05-06 02:28:39 +00:00
SQLManager . makeTables ( ) ;
sqlGuildManager = new SQLGuildManager ( ) ;
2022-05-19 05:20:58 +00:00
sqlGuildManager . getGuilds ( ) . whenComplete ( ( guilds , throwable ) - >
{
PlexLog . debug ( " Finished loading {0} guilds " , guilds . size ( ) ) ;
guilds . forEach ( guildHolder : : addGuild ) ;
this . registerCommand ( new GuildCommand ( ) ) ;
2022-05-06 02:28:39 +00:00
} ) ;
}
2022-05-07 22:52:04 +00:00
this . getPlex ( ) . setChatHandler ( new ChatHandlerImpl ( ) ) ;
2022-05-06 02:28:39 +00:00
2022-05-09 00:52:08 +00:00
this . addDefaultMessage ( " guildsHelpCommand " , " <gradient:gold:yellow>======</gradient>Guild Menu<gradient:gold:yellow>======</gradient><newline><newline>{0} " , " 0 - The commands list " ) ;
this . addDefaultMessage ( " guildsCommandDisplay " , " <gold>{0} <yellow>{1} " , " 0 - The command name " , " 1 - The command description " ) ;
2022-05-08 23:34:03 +00:00
this . addDefaultMessage ( " guildCommandNotFound " , " <red>'<gold>{0}</gold>'<red> is not a valid sub command! " , " 0 - The sub command " ) ;
2022-05-06 02:28:39 +00:00
this . addDefaultMessage ( " guildNotFound " , " <red>You're currently not a part of a guild! " ) ;
2022-05-10 01:58:05 +00:00
this . addDefaultMessage ( " guildInThis " , " <red>You're currently a part of this guild! " ) ;
2022-05-06 02:28:39 +00:00
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>. " ) ;
2022-05-08 05:54:22 +00:00
this . addDefaultMessage ( " guildNotOwner " , " <red>You're not the owner of this guild! " ) ;
2022-05-09 01:14:23 +00:00
this . addDefaultMessage ( " guildMemberNotFound " , " <red>This guild member could not be found! " ) ;
this . addDefaultMessage ( " guildOwnerSet " , " <green>You have successfully promoted <dark_green>{0}<green> to be the new guild owner. You have been set to a default guild member. " ) ;
2022-05-09 00:15:22 +00:00
2022-05-08 23:34:03 +00:00
this . addDefaultMessage ( " guildPrefixSet " , " <green>You have changed the guild prefix to '<gold>{0}</gold><green>' " , " 0 - The new prefix " ) ;
2022-05-08 05:54:22 +00:00
this . addDefaultMessage ( " guildPrefixCleared " , " <green>Your guild's prefix has been cleared. " ) ;
2022-05-09 00:15:22 +00:00
2022-05-08 23:59:03 +00:00
this . addDefaultMessage ( " guildWarpAlphanumeric " , " <red>Warp names may only contain alphabetical and/or numerical characters. " ) ;
2022-05-08 23:34:03 +00:00
this . addDefaultMessage ( " guildWarpExists " , " <red>'<gold>{0}</gold>'<red> is already an existing warp! " , " 0 - The warp name " ) ;
this . addDefaultMessage ( " guildWarpNotFound " , " <red>'<gold>{0}</gold>'<red> is not a valid warp! " , " 0 - The warp name " ) ;
this . addDefaultMessage ( " guildWarpCreated " , " <green>You have created a warp called '<dark_green>{0}</dark_green><green>' " , " 0 - The warp name " ) ;
2022-05-09 00:15:22 +00:00
this . addDefaultMessage ( " guildHomeRemoved " , " <green>You have removed the guild's home! " ) ;
this . addDefaultMessage ( " guildHomeSet " , " <green>You have changed the guild's home! " ) ;
this . addDefaultMessage ( " guildHomeNotFound " , " <red>This guild currently has no home set. " ) ;
2022-05-08 23:34:03 +00:00
this . addDefaultMessage ( " guildChatMessage " , " <blue>[GUILD] <aqua>{0} <yellow>{1} " , " 0 - The player name " , " 1 - The message " ) ;
this . addDefaultMessage ( " guildChatToggled " , " <green>Your chat has been toggled {0} " , " 0 - On / Off " ) ;
this . addDefaultMessage ( " guildChatConsoleLog " , " <blue>[GUILD - {0}:{1}] <aqua>{2} <yellow>{3} " , " 0 - The guild name " , " 1 - The guild unique identifier " , " 2 - The player name " , " 3 - The message " ) ;
2022-05-09 05:39:47 +00:00
this . addDefaultMessage ( " guildNoInvite " , " <red>You don't have any pending invitations! " ) ;
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 ( " guildInviteSent " , " <green>You have sent an invite to <dark_green>{0} " , " 0 - The invitee " ) ;
2022-05-10 01:58:05 +00:00
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 " ) ;
2022-05-09 05:39:47 +00:00
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 ( " 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 ( " guildAutoDisbanded " , " <green>Auto-disbanding your guild since there were no members " ) ;
2022-05-06 02:28:39 +00:00
}
@Override
public void disable ( )
{
// Unregistering listeners / commands is handled by Plex
2022-05-08 05:54:22 +00:00
this . getGuildHolder ( ) . getGuilds ( ) . forEach ( sqlGuildManager : : updateGuild ) ;
this . getPlex ( ) . setChatHandler ( new ChatListener . ChatHandlerImpl ( ) ) ;
2022-05-06 02:28:39 +00:00
}
private void addDefaultMessage ( String message , Object initValue )
{
if ( Plex . get ( ) . messages . getString ( message ) = = null )
{
Plex . get ( ) . messages . set ( message , initValue ) ;
Plex . get ( ) . messages . save ( ) ;
PlexLog . debug ( " '{0}' message added from TFMExtras module " , message ) ;
}
}
private void addDefaultMessage ( String message , Object initValue , String . . . comments )
{
if ( Plex . get ( ) . messages . getString ( message ) = = null )
{
Plex . get ( ) . messages . set ( message , initValue ) ;
Plex . get ( ) . messages . save ( ) ;
Plex . get ( ) . messages . setComments ( message , Arrays . asList ( comments ) ) ;
Plex . get ( ) . messages . save ( ) ;
PlexLog . debug ( " '{0}' message added from Plex-Guilds module " , message ) ;
}
}
public static Guilds get ( )
{
return module ;
}
}