2020-08-04 22:16:11 +00:00
package me.totalfreedom.totalfreedommod.command ;
import me.totalfreedom.totalfreedommod.rank.Rank ;
import net.dean.jraw.ApiException ;
import org.bukkit.ChatColor ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
@CommandPermissions ( level = Rank . OP , source = SourceType . ONLY_IN_GAME )
@CommandParameters ( description = " Link your reddit account " , usage = " /<command> <username | code <code>> " )
public class Command_linkreddit extends FreedomCommand
{
public boolean run ( final CommandSender sender , final Player playerSender , final Command cmd , final String commandLabel , final String [ ] args , final boolean senderIsConsole )
{
if ( ! plugin . rd . enabled )
{
2020-08-05 07:01:21 +00:00
msg ( " The Reddit system is currently disabled. " , ChatColor . RED ) ;
2020-08-04 22:16:11 +00:00
return true ;
}
if ( getData ( playerSender ) . getRedditUsername ( ) ! = null )
{
2020-08-05 07:01:21 +00:00
msg ( " Your Reddit account is already linked. " ) ;
2020-08-04 22:16:11 +00:00
return true ;
}
if ( args . length = = 0 )
{
return false ;
}
if ( args . length = = 1 & & ! args [ 0 ] . equals ( " code " ) )
{
String username = args [ 0 ] ;
String code = plugin . rd . addLinkCode ( getData ( playerSender ) , username ) ;
try
{
2020-08-05 07:01:21 +00:00
plugin . rd . sendModMessage ( username , " Link Code " , " Please run the following in-game to link your Reddit account: /linkreddit code " + code ) ;
2020-08-04 22:16:11 +00:00
}
catch ( ApiException e )
{
2020-08-05 07:01:21 +00:00
msg ( " Could not find a Reddit account by the name of " + args [ 0 ] , ChatColor . RED ) ;
2020-08-04 22:16:11 +00:00
return true ;
}
msg ( " A linking code has been sent to " + username + " . Please check your mod mail at " + ChatColor . AQUA + " https://www.reddit.com/message/moderator " , ChatColor . GREEN ) ;
return true ;
}
String code = args [ 1 ] ;
String username = plugin . rd . checkLinkCode ( code ) ;
if ( username = = null )
{
msg ( code + " is not a valid code " , ChatColor . RED ) ;
return true ;
}
2020-08-05 07:01:21 +00:00
msg ( " Successfully linked the Reddit account " + username + " to your Minecraft account. " , ChatColor . GREEN ) ;
2020-08-04 22:16:11 +00:00
if ( plugin . rd . updateFlair ( playerSender ) )
{
msg ( " Your flair has been updated. " , ChatColor . GREEN ) ;
}
return true ;
}
}