2021-01-03 07:21:15 +00:00
package dev.plex.command.impl ;
2020-10-31 08:55:27 +00:00
2022-01-27 09:00:50 +00:00
import com.google.common.collect.ImmutableList ;
2022-01-04 03:04:39 +00:00
import dev.plex.command.PlexCommand ;
2021-01-03 07:21:15 +00:00
import dev.plex.command.annotation.CommandParameters ;
import dev.plex.command.annotation.CommandPermissions ;
2022-02-04 08:18:07 +00:00
import dev.plex.command.exception.CommandFailException ;
2021-01-03 07:21:15 +00:00
import dev.plex.command.source.RequiredCommandSource ;
2022-03-06 01:04:34 +00:00
import dev.plex.module.PlexModule ;
import dev.plex.module.PlexModuleFile ;
2021-01-03 07:21:15 +00:00
import dev.plex.rank.enums.Rank ;
2022-01-27 09:00:50 +00:00
import net.kyori.adventure.text.Component ;
2022-03-06 01:04:34 +00:00
import net.kyori.adventure.text.minimessage.MiniMessage ;
import org.apache.commons.lang.StringUtils ;
2021-06-20 08:02:07 +00:00
import org.bukkit.ChatColor ;
2022-01-27 09:00:50 +00:00
import org.bukkit.command.CommandSender ;
2022-02-04 04:01:30 +00:00
import org.bukkit.entity.Player ;
2022-01-27 09:00:50 +00:00
import org.jetbrains.annotations.NotNull ;
2022-02-04 04:49:05 +00:00
import org.jetbrains.annotations.Nullable ;
2020-10-31 08:55:27 +00:00
2022-03-06 01:04:34 +00:00
import java.util.List ;
import java.util.stream.Collectors ;
2022-01-30 01:31:10 +00:00
@CommandPermissions ( level = Rank . OP , permission = " plex.plex " , source = RequiredCommandSource . ANY )
2022-03-06 01:04:34 +00:00
@CommandParameters ( name = " plex " , usage = " /<command> [reload | redis | modules] [reload] " , aliases = " plexhelp " , description = " Show information about Plex or reload it " )
public class PlexCMD extends PlexCommand {
2022-03-01 01:44:10 +00:00
// Don't modify this command
2020-10-31 08:55:27 +00:00
@Override
2022-03-06 01:04:34 +00:00
protected Component execute ( @NotNull CommandSender sender , @Nullable Player playerSender , String [ ] args ) {
if ( args . length = = 0 ) {
2022-02-04 20:13:56 +00:00
send ( sender , ChatColor . LIGHT_PURPLE + " Plex - A new freedom plugin. " ) ;
2022-03-01 01:44:10 +00:00
send ( sender , ChatColor . LIGHT_PURPLE + " Plugin version: " + plugin . getDescription ( ) . getVersion ( ) ) ;
return componentFromString ( ChatColor . LIGHT_PURPLE + " Authors: " + ChatColor . GOLD + " Telesphoreo, Taahh " ) ;
2022-01-04 03:04:39 +00:00
}
2022-03-06 01:04:34 +00:00
if ( args [ 0 ] . equalsIgnoreCase ( " reload " ) ) {
2022-01-30 20:56:08 +00:00
checkRank ( sender , Rank . SENIOR_ADMIN , " plex.reload " ) ;
2022-03-01 01:44:10 +00:00
plugin . config . load ( ) ;
2022-01-27 09:00:50 +00:00
send ( sender , " Reloaded config file " ) ;
2022-03-01 01:44:10 +00:00
plugin . messages . load ( ) ;
2022-01-27 09:00:50 +00:00
send ( sender , " Reloaded messages file " ) ;
2022-03-05 23:44:38 +00:00
plugin . indefBans . load ( false ) ;
2022-03-01 01:44:10 +00:00
plugin . getPunishmentManager ( ) . mergeIndefiniteBans ( ) ;
2022-02-28 06:28:00 +00:00
send ( sender , " Reloaded indefinite bans " ) ;
2022-03-01 01:44:10 +00:00
plugin . getRankManager ( ) . importDefaultRanks ( ) ;
2022-01-27 09:00:50 +00:00
send ( sender , " Imported ranks " ) ;
send ( sender , " Plex successfully reloaded. " ) ;
2022-03-06 01:04:34 +00:00
} else if ( args [ 0 ] . equalsIgnoreCase ( " redis " ) ) {
2022-02-04 08:18:07 +00:00
checkRank ( sender , Rank . SENIOR_ADMIN , " plex.redis " ) ;
2022-03-06 01:04:34 +00:00
if ( ! plugin . getRedisConnection ( ) . isEnabled ( ) ) {
2022-02-04 08:18:07 +00:00
throw new CommandFailException ( " &cRedis is not enabled. " ) ;
}
plugin . getRedisConnection ( ) . getJedis ( ) . set ( " test " , " 123 " ) ;
send ( sender , " Set test to 123. Now outputting key test... " ) ;
send ( sender , plugin . getRedisConnection ( ) . getJedis ( ) . get ( " test " ) ) ;
2022-02-04 19:30:05 +00:00
plugin . getRedisConnection ( ) . getJedis ( ) . close ( ) ;
2022-02-04 08:18:07 +00:00
}
2022-03-06 01:04:34 +00:00
if ( args [ 0 ] . equalsIgnoreCase ( " modules " ) ) {
if ( args . length = = 1 ) {
return MiniMessage . miniMessage ( ) . deserialize ( " <gold>Modules ( " + plugin . getModuleManager ( ) . getModules ( ) . size ( ) + " ): <yellow> " + StringUtils . join ( plugin . getModuleManager ( ) . getModules ( ) . stream ( ) . map ( PlexModule : : getPlexModuleFile ) . map ( PlexModuleFile : : getName ) . collect ( Collectors . toList ( ) ) , " , " ) ) ;
}
if ( args [ 1 ] . equalsIgnoreCase ( " reload " ) ) {
plugin . getModuleManager ( ) . unloadModules ( ) ;
plugin . getModuleManager ( ) . loadAllModules ( ) ;
plugin . getModuleManager ( ) . loadModules ( ) ;
plugin . getModuleManager ( ) . enableModules ( ) ;
}
} else {
2022-02-14 05:55:50 +00:00
return usage ( ) ;
2022-01-04 03:04:39 +00:00
}
2022-01-27 09:00:50 +00:00
return null ;
2020-10-31 08:55:27 +00:00
}
@Override
2022-03-06 01:04:34 +00:00
public @NotNull List < String > tabComplete ( @NotNull CommandSender sender , @NotNull String alias , @NotNull String [ ] args ) throws IllegalArgumentException {
2022-02-04 08:18:07 +00:00
return ImmutableList . of ( " reload " , " redis " ) ;
2020-10-31 08:55:27 +00:00
}
2020-11-06 03:50:16 +00:00
}